Bug 839103 - Part 9: Unify nsIDOMStyleSheet{Added,Removed}Event. r=bz
authorCameron McCormack <cam@mcc.id.au>
Thu, 16 May 2013 17:13:36 +1000
changeset 143571 e7b4aa5f253ec4e4ae2060dd695dd7186fde3490
parent 143570 57072c988f1f317023d2e4d0eab8b90f327ae1d3
child 143572 cf13d8dac8d950a48dc82b5262746941afe40ff2
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs839103
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 839103 - Part 9: Unify nsIDOMStyleSheet{Added,Removed}Event. r=bz
browser/base/content/test/browser_bug839103.js
content/base/src/nsDocument.cpp
dom/interfaces/events/moz.build
dom/interfaces/events/nsIDOMStyleSheetAddedEvent.idl
dom/interfaces/events/nsIDOMStyleSheetChangeEvent.idl
dom/interfaces/events/nsIDOMStyleSheetRemovedEvent.idl
dom/tests/mochitest/general/test_interfaces.html
js/xpconnect/src/event_impl_gen.conf.in
--- a/browser/base/content/test/browser_bug839103.js
+++ b/browser/base/content/test/browser_bug839103.js
@@ -8,20 +8,23 @@ function test() {
   gBrowser.addEventListener("StyleSheetAdded", initialStylesheetAdded, true);
   gTab = gBrowser.selectedTab = gBrowser.addTab(gTestRoot + "test_bug839103.html");
   gTab.linkedBrowser.addEventListener("load", tabLoad, true);
 }
 
 function initialStylesheetAdded(evt) {
   gBrowser.removeEventListener("StyleSheetAdded", initialStylesheetAdded, true);
   ok(true, "received initial style sheet event");
+  is(evt.type, "StyleSheetAdded", "evt.type has expected value");
   is(evt.target, gBrowser.contentDocument, "event targets correct document");
   ok(evt.stylesheet, "evt.stylesheet is defined");
   ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
   ok(evt.documentSheet, "style sheet is a document sheet");
+  is(typeof evt.sheetIsApplicable, "boolean", "evt.sheetIsApplicable is a boolean");
+  is(evt.rule, null, "evt.rule is null");
 }
 
 function tabLoad(evt) {
   gTab.linkedBrowser.removeEventListener(evt.type, tabLoad, true);
   executeSoon(continueTest);
 }
 
 var gLinkElement = null;
@@ -49,32 +52,38 @@ function continueTest() {
 
   gBrowser.addEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
   doc.body.appendChild(link);
 }
 
 function dynamicStylesheetAdded(evt) {
   gBrowser.removeEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
   ok(true, "received dynamic style sheet event");
+  is(evt.type, "StyleSheetAdded", "evt.type has expected value");
   is(evt.target, gBrowser.contentDocument, "event targets correct document");
   ok(evt.stylesheet, "evt.stylesheet is defined");
   ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
   ok(evt.documentSheet, "style sheet is a document sheet");
+  is(typeof evt.sheetIsApplicable, "boolean", "evt.sheetIsApplicable is a boolean");
+  is(evt.rule, null, "evt.rule is null");
 
   gBrowser.addEventListener("StyleSheetRemoved", dynamicStylesheetRemoved, true);
   gBrowser.contentDocument.body.removeChild(gLinkElement);
 }
 
 function dynamicStylesheetRemoved(evt) {
   gBrowser.removeEventListener("StyleSheetRemoved", dynamicStylesheetRemoved, true);
   ok(true, "received dynamic style sheet removal");
+  is(evt.type, "StyleSheetRemoved", "evt.type has expected value");
   is(evt.target, gBrowser.contentDocument, "event targets correct document");
   ok(evt.stylesheet, "evt.stylesheet is defined");
   ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
   ok(evt.stylesheet.href.contains(gStyleSheet), "evt.stylesheet is the removed stylesheet");
+  is(typeof evt.sheetIsApplicable, "boolean", "evt.sheetIsApplicable is a boolean");
+  is(evt.rule, null, "evt.rule is null");
   executeSoon(concludeTest);
 }
 
 function concludeTest() {
   let doc = gBrowser.contentDocument;
   doc.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
   doc.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
   doc.defaultView.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -132,18 +132,17 @@
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIDocumentLoader.h"
 #include "nsIContentViewer.h"
 #include "nsIXMLContentSink.h"
 #include "nsIXULDocument.h"
 #include "nsIPrompt.h"
 #include "nsIPropertyBag2.h"
 #include "nsIDOMPageTransitionEvent.h"
-#include "nsIDOMStyleSheetAddedEvent.h"
-#include "nsIDOMStyleSheetRemovedEvent.h"
+#include "nsIDOMStyleSheetChangeEvent.h"
 #include "nsJSUtils.h"
 #include "nsFrameLoader.h"
 #include "nsEscape.h"
 #include "nsObjectLoadingContent.h"
 #include "nsHtml5TreeOpExecutor.h"
 #include "nsIDOMElementReplaceEvent.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #ifdef MOZ_WEBRTC
@@ -3717,62 +3716,67 @@ void
 nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
 {
   nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     shell->StyleSet()->AddDocStyleSheet(aSheet, this);
   }
 }
 
-#define DO_STYLESHEET_NOTIFICATION(createFunc, initMethod, concreteInterface, type) \
+#define DO_STYLESHEET_NOTIFICATION(createFunc, concreteInterface, initMethod, type, ...) \
   do {                                                                  \
-    if (!HasStyleSheetChangeEventsEnabled()) {                          \
-      break;                                                            \
-    }                                                                   \
     nsCOMPtr<nsIDOMEvent> event;                                        \
     nsresult rv = createFunc(getter_AddRefs(event), this,               \
                              mPresShell ?                               \
                              mPresShell->GetPresContext() : nullptr,    \
                              nullptr);                                  \
     if (NS_FAILED(rv)) {                                                \
       return;                                                           \
     }                                                                   \
     nsCOMPtr<nsIDOMCSSStyleSheet> cssSheet(do_QueryInterface(aSheet));  \
     if (!cssSheet) {                                                    \
       return;                                                           \
     }                                                                   \
     nsCOMPtr<concreteInterface> ssEvent(do_QueryInterface(event));      \
     MOZ_ASSERT(ssEvent);                                                \
     ssEvent->initMethod(NS_LITERAL_STRING(type), true, true,            \
-                        cssSheet, aDocumentSheet);                      \
+                        cssSheet, __VA_ARGS__);                         \
     event->SetTrusted(true);                                            \
     event->SetTarget(this);                                             \
     nsRefPtr<nsAsyncDOMEvent> asyncEvent = new nsAsyncDOMEvent(this, event); \
     asyncEvent->mDispatchChromeOnly = true;                             \
     asyncEvent->PostDOMEvent();                                         \
   } while (0);
 
 void
 nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (this, aSheet, aDocumentSheet));
-  DO_STYLESHEET_NOTIFICATION(NS_NewDOMStyleSheetAddedEvent,
-                             InitStyleSheetAddedEvent,
-                             nsIDOMStyleSheetAddedEvent,
-                             "StyleSheetAdded");
+
+  if (StyleSheetChangeEventsEnabled()) {
+    DO_STYLESHEET_NOTIFICATION(NS_NewDOMStyleSheetChangeEvent,
+                               nsIDOMStyleSheetChangeEvent,
+                               InitStyleSheetChangeEvent,
+                               "StyleSheetAdded",
+                               aDocumentSheet);
+  }
 }
 
 void
 nsDocument::NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (this, aSheet, aDocumentSheet));
-  DO_STYLESHEET_NOTIFICATION(NS_NewDOMStyleSheetRemovedEvent,
-                             InitStyleSheetRemovedEvent,
-                             nsIDOMStyleSheetRemovedEvent,
-                             "StyleSheetRemoved");
+
+  if (StyleSheetChangeEventsEnabled()) {
+    DO_STYLESHEET_NOTIFICATION(NS_NewDOMStyleSheetChangeEvent,
+                               nsIDOMStyleSheetChangeEvent,
+                               InitStyleSheetChangeEvent,
+                               "StyleSheetRemoved",
+                               aDocumentSheet);
+  }
 }
 
 #undef DO_STYLESHEET_NOTIFICATION
 
 void
 nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
 {
   NS_PRECONDITION(aSheet, "null arg");
--- a/dom/interfaces/events/moz.build
+++ b/dom/interfaces/events/moz.build
@@ -41,18 +41,17 @@ XPIDL_SOURCES += [
     'nsIDOMPaintRequest.idl',
     'nsIDOMPaintRequestList.idl',
     'nsIDOMPopStateEvent.idl',
     'nsIDOMPopupBlockedEvent.idl',
     'nsIDOMProgressEvent.idl',
     'nsIDOMScrollAreaEvent.idl',
     'nsIDOMSimpleGestureEvent.idl',
     'nsIDOMSmartCardEvent.idl',
-    'nsIDOMStyleSheetAddedEvent.idl',
-    'nsIDOMStyleSheetRemovedEvent.idl',
+    'nsIDOMStyleSheetChangeEvent.idl',
     'nsIDOMTouchEvent.idl',
     'nsIDOMTransitionEvent.idl',
     'nsIDOMUIEvent.idl',
     'nsIDOMUserProximityEvent.idl',
     'nsIDOMWheelEvent.idl',
 ]
 
 XPIDL_MODULE = 'dom_events'
deleted file mode 100644
--- a/dom/interfaces/events/nsIDOMStyleSheetAddedEvent.idl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsIDOMEvent.idl"
-
-interface nsIDOMCSSStyleSheet;
-
-[scriptable, builtinclass, uuid(05a78874-43d7-459d-be32-ba9271527153)]
-interface nsIDOMStyleSheetAddedEvent : nsIDOMEvent
-{
-  readonly attribute nsIDOMCSSStyleSheet stylesheet;
-  readonly attribute boolean documentSheet;
-  [noscript] void initStyleSheetAddedEvent(in DOMString aTypeArg,
-                                           in boolean aCanBubbleArg,
-                                           in boolean aCancelableArg,
-                                           in nsIDOMCSSStyleSheet aStyleSheet,
-                                           in boolean aDocumentSheet);
-};
-
-dictionary StyleSheetAddedEventInit : EventInit
-{
-  nsIDOMCSSStyleSheet stylesheet;
-  boolean documentSheet;
-};
-
new file mode 100644
--- /dev/null
+++ b/dom/interfaces/events/nsIDOMStyleSheetChangeEvent.idl
@@ -0,0 +1,27 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsIDOMEvent.idl"
+
+interface nsIDOMCSSStyleSheet;
+
+[scriptable, builtinclass, uuid(f94c6a47-58f0-4996-b1db-3ea1d14c4ddd)]
+interface nsIDOMStyleSheetChangeEvent : nsIDOMEvent
+{
+  readonly attribute nsIDOMCSSStyleSheet stylesheet;
+  readonly attribute boolean documentSheet;
+  [noscript] void initStyleSheetChangeEvent(in DOMString aTypeArg,
+                                            in boolean aCanBubbleArg,
+                                            in boolean aCancelableArg,
+                                            in nsIDOMCSSStyleSheet aStyleSheet,
+                                            in boolean aDocumentSheet);
+};
+
+dictionary StyleSheetChangeEventInit : EventInit
+{
+  nsIDOMCSSStyleSheet stylesheet;
+  boolean documentSheet;
+};
+
deleted file mode 100644
--- a/dom/interfaces/events/nsIDOMStyleSheetRemovedEvent.idl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsIDOMEvent.idl"
-
-interface nsIDOMCSSStyleSheet;
-
-[scriptable, builtinclass, uuid(76a7afe1-5b7b-48ee-aef0-7e89b5b0b8e6)]
-interface nsIDOMStyleSheetRemovedEvent : nsIDOMEvent
-{
-  readonly attribute nsIDOMCSSStyleSheet stylesheet;
-  readonly attribute boolean documentSheet;
-  [noscript] void initStyleSheetRemovedEvent(in DOMString aTypeArg,
-                                             in boolean aCanBubbleArg,
-                                             in boolean aCancelableArg,
-                                             in nsIDOMCSSStyleSheet aStyleSheet,
-                                             in boolean aDocumentSheet);
-};
-
-dictionary StyleSheetRemovedEventInit : EventInit
-{
-  nsIDOMCSSStyleSheet stylesheet;
-  boolean documentSheet;
-};
-
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -541,18 +541,17 @@ var interfaceNamesInGlobalScope =
     "Gamepad",
     "GamepadEvent",
     "GamepadButtonEvent",
     "GamepadAxisMoveEvent",
     "SpeechRecognitionEvent",
     "SpeechRecognitionError",
     "SpeechSynthesisEvent",
     "PushManager",
-    "StyleSheetAddedEvent",
-    "StyleSheetRemovedEvent",
+    "StyleSheetChangeEvent",
     "MozMobileMessageThread",
     "PaymentRequestInfo",
   ]
 // IMPORTANT: Do not change this list without review from a DOM peer!
 
 // If your interface is named nsIDOMSomeInterface and you don't mean to expose
 // it to every webpage, simply change its name to nsISomeInterface to fix this problem.
 
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -19,18 +19,17 @@ simple_events = [
     'PopStateEvent',
     'HashChangeEvent',
     'CloseEvent',
     'MozContactChangeEvent',
     'DeviceOrientationEvent',
     'DeviceLightEvent',
     'MozApplicationEvent',
     'SmartCardEvent',
-    'StyleSheetAddedEvent',
-    'StyleSheetRemovedEvent',
+    'StyleSheetChangeEvent',
 #ifdef MOZ_B2G_BT
     'BluetoothDeviceEvent',
 #endif
 #ifdef MOZ_B2G_RIL
     'CallEvent',
     'CFStateChangeEvent',
     'DataErrorEvent',
     'ICCCardLockErrorEvent',