Bug 1031051: Part 7 - Migrate PageTransitionEvent to the WebIDL code generator. r=smaug
authorKyle Huey <khuey@kylehuey.com>
Mon, 30 Jun 2014 16:02:02 -0700
changeset 191522 e6377ca32f3dd9e7a3e0c28dc48e7e19b0949be6
parent 191521 1f60138bce8d9a9dbd0dc553cd5413872c83b11b
child 191523 528eecdaf3a1f04a87a324e5b571d7cac3f2b666
push id45609
push userkhuey@mozilla.com
push dateMon, 30 Jun 2014 23:03:27 +0000
treeherdermozilla-inbound@51879554acf4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1031051
milestone33.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 1031051: Part 7 - Migrate PageTransitionEvent to the WebIDL code generator. r=smaug
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
dom/events/EventDispatcher.cpp
dom/interfaces/events/moz.build
dom/interfaces/events/nsIDOMPageTransitionEvent.idl
dom/webidl/PageTransitionEvent.webidl
dom/webidl/moz.build
js/xpconnect/src/event_impl_gen.conf.in
toolkit/content/tests/browser/browser_autoscroll_disabled.js
toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js
xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -1397,32 +1397,32 @@ public:
 
   virtual void UnblockDOMContentLoaded() = 0;
 
   /**
    * Notification that the page has been shown, for documents which are loaded
    * into a DOM window.  This corresponds to the completion of document load,
    * or to the page's presentation being restored into an existing DOM window.
    * This notification fires applicable DOM events to the content window.  See
-   * nsIDOMPageTransitionEvent.idl for a description of the |aPersisted|
+   * PageTransitionEvent.webidl for a description of the |aPersisted|
    * parameter. If aDispatchStartTarget is null, the pageshow event is
    * dispatched on the ScriptGlobalObject for this document, otherwise it's
    * dispatched on aDispatchStartTarget.
    * Note: if aDispatchStartTarget isn't null, the showing state of the
    * document won't be altered.
    */
   virtual void OnPageShow(bool aPersisted,
                           mozilla::dom::EventTarget* aDispatchStartTarget) = 0;
 
   /**
    * Notification that the page has been hidden, for documents which are loaded
    * into a DOM window.  This corresponds to the unloading of the document, or
    * to the document's presentation being saved but removed from an existing
    * DOM window.  This notification fires applicable DOM events to the content
-   * window.  See nsIDOMPageTransitionEvent.idl for a description of the
+   * window.  See PageTransitionEvent.webidl for a description of the
    * |aPersisted| parameter. If aDispatchStartTarget is null, the pagehide
    * event is dispatched on the ScriptGlobalObject for this document,
    * otherwise it's dispatched on aDispatchStartTarget.
    * Note: if aDispatchStartTarget isn't null, the showing state of the
    * document won't be altered.
    */
   virtual void OnPageHide(bool aPersisted,
                           mozilla::dom::EventTarget* aDispatchStartTarget) = 0;
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -133,17 +133,17 @@
 #include "nsICategoryManager.h"
 #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 "mozilla/dom/PageTransitionEvent.h"
 #include "nsIDOMStyleRuleChangeEvent.h"
 #include "nsIDOMStyleSheetChangeEvent.h"
 #include "nsIDOMStyleSheetApplicableStateChangeEvent.h"
 #include "nsJSUtils.h"
 #include "nsFrameLoader.h"
 #include "nsEscape.h"
 #include "nsObjectLoadingContent.h"
 #include "nsHtml5TreeOpExecutor.h"
@@ -8685,29 +8685,32 @@ nsDocument::GetContentInThisDocument(nsI
   return nullptr;
 }
 
 void
 nsDocument::DispatchPageTransition(EventTarget* aDispatchTarget,
                                    const nsAString& aType,
                                    bool aPersisted)
 {
-  if (aDispatchTarget) {
-    nsCOMPtr<nsIDOMEvent> event;
-    CreateEvent(NS_LITERAL_STRING("pagetransition"), getter_AddRefs(event));
-    nsCOMPtr<nsIDOMPageTransitionEvent> ptEvent = do_QueryInterface(event);
-    if (ptEvent && NS_SUCCEEDED(ptEvent->InitPageTransitionEvent(aType, true,
-                                                                 true,
-                                                                 aPersisted))) {
-      event->SetTrusted(true);
-      event->SetTarget(this);
-      EventDispatcher::DispatchDOMEvent(aDispatchTarget, nullptr, event,
-                                        nullptr, nullptr);
-    }
-  }
+  if (!aDispatchTarget) {
+    return;
+  }
+
+  PageTransitionEventInit init;
+  init.mBubbles = true;
+  init.mCancelable = true;
+  init.mPersisted = aPersisted;
+
+  nsRefPtr<PageTransitionEvent> event =
+    PageTransitionEvent::Constructor(this, aType, init);
+
+  event->SetTrusted(true);
+  event->SetTarget(this);
+  EventDispatcher::DispatchDOMEvent(aDispatchTarget, nullptr, event,
+                                    nullptr, nullptr);
 }
 
 static bool
 NotifyPageShow(nsIDocument* aDocument, void* aData)
 {
   const bool* aPersistedPtr = static_cast<const bool*>(aData);
   aDocument->OnPageShow(*aPersistedPtr, nullptr);
   return true;
--- a/dom/events/EventDispatcher.cpp
+++ b/dom/events/EventDispatcher.cpp
@@ -13,16 +13,17 @@
 #include "nsINode.h"
 #include "nsPIDOMWindow.h"
 #include "GeckoProfiler.h"
 #include "GeneratedEvents.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/dom/CloseEvent.h"
 #include "mozilla/dom/EventTarget.h"
 #include "mozilla/dom/HashChangeEvent.h"
+#include "mozilla/dom/PageTransitionEvent.h"
 #include "mozilla/dom/PopStateEvent.h"
 #include "mozilla/dom/StorageEvent.h"
 #include "mozilla/dom/TouchEvent.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
@@ -808,18 +809,24 @@ EventDispatcher::CreateEvent(EventTarget
   if (aEventType.LowerCaseEqualsLiteral("messageevent"))
     return NS_NewDOMMessageEvent(aDOMEvent, aOwner, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("notifypaintevent"))
     return NS_NewDOMNotifyPaintEvent(aDOMEvent, aOwner, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("simplegestureevent"))
     return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("beforeunloadevent"))
     return NS_NewDOMBeforeUnloadEvent(aDOMEvent, aOwner, aPresContext, nullptr);
-  if (aEventType.LowerCaseEqualsLiteral("pagetransition"))
-    return NS_NewDOMPageTransitionEvent(aDOMEvent, aOwner, aPresContext, nullptr);
+  // XXXkhuey this is broken
+  if (aEventType.LowerCaseEqualsLiteral("pagetransition")) {
+    PageTransitionEventInit init;
+    nsRefPtr<PageTransitionEvent> event =
+      PageTransitionEvent::Constructor(aOwner, EmptyString(), init);
+    event.forget(aDOMEvent);
+    return NS_OK;
+  }
   if (aEventType.LowerCaseEqualsLiteral("domtransaction"))
     return NS_NewDOMDOMTransactionEvent(aDOMEvent, aOwner, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("scrollareaevent"))
     return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("closeevent")) {
     CloseEventInit init;
     nsRefPtr<CloseEvent> event =
       CloseEvent::Constructor(aOwner, EmptyString(), init);
--- a/dom/interfaces/events/moz.build
+++ b/dom/interfaces/events/moz.build
@@ -22,17 +22,16 @@ XPIDL_SOURCES += [
     'nsIDOMFocusEvent.idl',
     'nsIDOMKeyEvent.idl',
     'nsIDOMMessageEvent.idl',
     'nsIDOMMouseEvent.idl',
     'nsIDOMMouseScrollEvent.idl',
     'nsIDOMMutationEvent.idl',
     'nsIDOMNotifyPaintEvent.idl',
     'nsIDOMNSEvent.idl',
-    'nsIDOMPageTransitionEvent.idl',
     'nsIDOMPaintRequest.idl',
     'nsIDOMRecordErrorEvent.idl',
     'nsIDOMScrollAreaEvent.idl',
     'nsIDOMSimpleGestureEvent.idl',
     'nsIDOMSmartCardEvent.idl',
     'nsIDOMStyleRuleChangeEvent.idl',
     'nsIDOMStyleSheetApplicableStateChangeEvent.idl',
     'nsIDOMStyleSheetChangeEvent.idl',
deleted file mode 100644
--- a/dom/interfaces/events/nsIDOMPageTransitionEvent.idl
+++ /dev/null
@@ -1,29 +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"
-
-/**
- * The nsIDOMPageTransitionEvent interface is used for the pageshow and
- * pagehide events, which are generic events that apply to both page
- * load/unload and saving/restoring a document from session history.
- */
-
-[builtinclass, uuid(8a69a3d6-c7da-4caa-993c-7f9583d9f896)]
-interface nsIDOMPageTransitionEvent : nsIDOMEvent
-{
-  /**
-   * Set to true if the document has been or will be persisted across
-   * firing of the event.  For example, if a document is being cached in
-   * session history, |persisted| is true for the PageHide event.
-   */
-  readonly attribute boolean persisted;
-
-  /* Initialize a new pageshow or pagehide event. */
-  void initPageTransitionEvent(in DOMString typeArg,
-                               in boolean canBubbleArg,
-                               in boolean canCancelArg,
-                               in boolean persisted);
-};
--- a/dom/webidl/PageTransitionEvent.webidl
+++ b/dom/webidl/PageTransitionEvent.webidl
@@ -1,23 +1,16 @@
 /* -*- 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/.
  */
 
-[Constructor(DOMString type, optional PageTransitionEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
+[Constructor(DOMString type, optional PageTransitionEventInit eventInitDict)]
 interface PageTransitionEvent : Event
 {
   readonly attribute boolean persisted;
-
-  // initPageTransitionEvent is a Gecko specific deprecated method.
-  [Throws]
-  void initPageTransitionEvent(DOMString type,
-                               boolean canBubble,
-                               boolean cancelable,
-                               boolean persisted);
 };
 
 dictionary PageTransitionEventInit : EventInit
 {
   boolean persisted = false;
 };
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -642,16 +642,17 @@ GENERATED_EVENTS_WEBIDL_FILES = [
     'MozClirModeEvent.webidl',
     'MozContactChangeEvent.webidl',
     'MozEmergencyCbModeEvent.webidl',
     'MozInterAppMessageEvent.webidl',
     'MozMmsEvent.webidl',
     'MozOtaStatusEvent.webidl',
     'MozSmsEvent.webidl',
     'MozStkCommandEvent.webidl',
+    'PageTransitionEvent.webidl',
     'PopStateEvent.webidl',
     'PopupBlockedEvent.webidl',
     'ProgressEvent.webidl',
     'RTCDataChannelEvent.webidl',
     'RTCPeerConnectionIceEvent.webidl',
     'RTCPeerConnectionIdentityErrorEvent.webidl',
     'RTCPeerConnectionIdentityEvent.webidl',
     'TrackEvent.webidl',
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -5,17 +5,16 @@
 
  The name of the event which real interface should have nsIDOM-prefix,
  and should be in nsIDOM<name>.idl file and which should have
  <name>Init dictionary for the event constructor. """
 
 simple_events = [
     'MozSettingsEvent',
     'CustomEvent',
-    'PageTransitionEvent',
     'DOMTransactionEvent',
     'DeviceOrientationEvent',
     'MozApplicationEvent',
     'SmartCardEvent',
     'StyleRuleChangeEvent',
     'StyleSheetChangeEvent',
     'StyleSheetApplicableStateChangeEvent',
 #ifdef MOZ_WEBSPEECH
--- a/toolkit/content/tests/browser/browser_autoscroll_disabled.js
+++ b/toolkit/content/tests/browser/browser_autoscroll_disabled.js
@@ -50,18 +50,20 @@ function test()
       ok(elem.scrollLeft == 0, "element should not have scrolled horizontally");
 
       endTest();
     };
     EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 },
                                gBrowser.contentWindow);
 
     var iframe = gBrowser.contentDocument.getElementById("iframe");
-    var e = iframe.contentDocument.createEvent("pagetransition");
-    e.initPageTransitionEvent("pagehide", true, true, false);
+    var e = new iframe.contentWindow.PageTransitionEvent("pagehide",
+                                                         { bubbles: true,
+                                                           cancelable: true,
+                                                           persisted: false });
     iframe.contentDocument.dispatchEvent(e);
     iframe.contentDocument.documentElement.dispatchEvent(e);
 
     EventUtils.synthesizeMouse(elem, 100, 100,
                                { type: "mousemove", clickCount: "0" },
                                gBrowser.contentWindow);
     /*
      * if scrolling didn’t work, we wouldn’t do any redraws and thus time out.
--- a/toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js
+++ b/toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js
@@ -102,18 +102,20 @@ function test()
       executeSoon(nextTest);
     };
     EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 },
                                gBrowser.contentWindow);
 
     // This ensures bug 605127 is fixed: pagehide in an unrelated document
     // should not cancel the autoscroll.
     var iframe = gBrowser.contentDocument.getElementById("iframe");
-    var e = iframe.contentDocument.createEvent("pagetransition");
-    e.initPageTransitionEvent("pagehide", true, true, false);
+    var e = new iframe.contentWindow.PageTransitionEvent("pagehide",
+                                                         { bubbles: true,
+                                                           cancelable: true,
+                                                           persisted: false });
     iframe.contentDocument.dispatchEvent(e);
     iframe.contentDocument.documentElement.dispatchEvent(e);
 
     EventUtils.synthesizeMouse(elem, 100, 100,
                                { type: "mousemove", clickCount: "0" },
                                gBrowser.contentWindow);
 
     // Start checking for the scroll.
--- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
@@ -115,17 +115,16 @@
 #include "nsIDOMMozApplicationEvent.h"
 #include "nsIDOMMozNamedAttrMap.h"
 #include "nsIDOMMozSettingsEvent.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMNodeIterator.h"
 #include "nsIDOMNotifyPaintEvent.h"
 #include "nsIDOMNSEvent.h"
 #include "nsIDOMOfflineResourceList.h"
-#include "nsIDOMPageTransitionEvent.h"
 #include "nsIDOMPaintRequest.h"
 #include "nsIDOMParser.h"
 #include "nsIDOMProcessingInstruction.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMRecordErrorEvent.h"
 #include "nsIDOMRect.h"
 #include "nsIDOMScreen.h"
 #include "nsIDOMScrollAreaEvent.h"
@@ -270,17 +269,16 @@
 #include "mozilla/dom/MozApplicationEventBinding.h"
 #include "mozilla/dom/MozNamedAttrMapBinding.h"
 #include "mozilla/dom/MozSettingsEventBinding.h"
 #include "mozilla/dom/NodeIteratorBinding.h"
 #include "mozilla/dom/NodeBinding.h"
 #include "mozilla/dom/NotifyPaintEventBinding.h"
 #include "mozilla/dom/EventBinding.h"
 #include "mozilla/dom/OfflineResourceListBinding.h"
-#include "mozilla/dom/PageTransitionEventBinding.h"
 #include "mozilla/dom/PaintRequestBinding.h"
 #include "mozilla/dom/PositionErrorBinding.h"
 #include "mozilla/dom/ProcessingInstructionBinding.h"
 #include "mozilla/dom/RangeBinding.h"
 #include "mozilla/dom/RecordErrorEventBinding.h"
 #include "mozilla/dom/RectBinding.h"
 #include "mozilla/dom/ScreenBinding.h"
 #include "mozilla/dom/SelectionBinding.h"
@@ -476,17 +474,16 @@ const ComponentsInterfaceShimEntry kComp
   DEFINE_SHIM(MozApplicationEvent),
   DEFINE_SHIM(MozNamedAttrMap),
   DEFINE_SHIM(MozSettingsEvent),
   DEFINE_SHIM(NodeIterator),
   DEFINE_SHIM(Node),
   DEFINE_SHIM(NotifyPaintEvent),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMNSEvent, Event),
   DEFINE_SHIM(OfflineResourceList),
-  DEFINE_SHIM(PageTransitionEvent),
   DEFINE_SHIM(PaintRequest),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMParser, DOMParser),
   DEFINE_SHIM(ProcessingInstruction),
   DEFINE_SHIM(Range),
   DEFINE_SHIM(RecordErrorEvent),
   DEFINE_SHIM(Rect),
   DEFINE_SHIM(Screen),
   DEFINE_SHIM(ScrollAreaEvent),