Backout Bug 495983
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 24 Jun 2009 14:32:50 +0300
changeset 29537 9ab03147fdfec27fd745e5ed6a35d6a908aeb111
parent 29536 5fe89f2c22f0adaa340bc8a57f3e8485165f4646
child 29538 809d4e3b4c5e45902dd72e200ffbc8e72b6bb154
push idunknown
push userunknown
push dateunknown
bugs495983
milestone1.9.2a1pre
Backout Bug 495983
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/events/public/nsIPrivateDOMEvent.h
content/events/src/nsDOMEvent.cpp
content/events/src/nsDOMPageTransitionEvent.cpp
content/events/src/nsDOMPageTransitionEvent.h
content/events/src/nsEventDispatcher.cpp
widget/public/nsGUIEvent.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -163,17 +163,17 @@ static NS_DEFINE_CID(kDOMEventGroupCID, 
 #include "nsICategoryManager.h"
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIContentViewer.h"
 #include "nsIXMLContentSink.h"
 #include "nsContentErrors.h"
 #include "nsIXULDocument.h"
 #include "nsIPrompt.h"
 #include "nsIPropertyBag2.h"
-#include "nsIDOMPageTransitionEvent.h"
+
 #include "nsFrameLoader.h"
 
 #include "mozAutoDocUpdate.h"
 
 #ifdef MOZ_SMIL
 #include "nsSMILAnimationController.h"
 #include "imgIContainer.h"
 #include "nsSVGUtils.h"
@@ -7050,34 +7050,24 @@ nsDocument::CheckAncestryAndGetFrame(nsI
     return nsnull;
   }
 
   NS_ADDREF(frameElement);
   return frameElement;
 }
 
 void
-nsDocument::DispatchPageTransition(nsPIDOMEventTarget* aDispatchTarget,
-                                   const nsAString& aType,
-                                   PRBool aPersisted)
-{
-  if (aDispatchTarget) {
-    nsCOMPtr<nsIDOMEvent> event;
-    CreateEvent(NS_LITERAL_STRING("pagetransition"), getter_AddRefs(event));
-    nsCOMPtr<nsIDOMPageTransitionEvent> ptEvent = do_QueryInterface(event);
-    nsCOMPtr<nsIPrivateDOMEvent> pEvent = do_QueryInterface(ptEvent);
-    if (pEvent && NS_SUCCEEDED(ptEvent->InitPageTransitionEvent(aType, PR_TRUE,
-                                                                PR_TRUE,
-                                                                aPersisted))) {
-      pEvent->SetTrusted(PR_TRUE);
-      pEvent->SetTarget(this);
-      nsEventDispatcher::DispatchDOMEvent(aDispatchTarget, nsnull, event,
-                                          nsnull, nsnull);
-    }
-  }
+nsDocument::DispatchEventToWindow(nsEvent *aEvent)
+{
+  nsPIDOMWindow *window = GetWindow();
+  if (!window)
+    return;
+
+  aEvent->target = static_cast<nsIDocument*>(this);
+  nsEventDispatcher::Dispatch(window, nsnull, aEvent);
 }
 
 void
 nsDocument::OnPageShow(PRBool aPersisted, nsIDOMEventTarget* aDispatchStartTarget)
 {
   mVisible = PR_TRUE;
   UpdateLinkMap();
   
@@ -7106,20 +7096,24 @@ nsDocument::OnPageShow(PRBool aPersisted
     mIsShowing = PR_TRUE;
   }
  
 #ifdef MOZ_SMIL
   if (mAnimationController) {
     mAnimationController->OnPageShow();
   }
 #endif
-  nsCOMPtr<nsPIDOMEventTarget> target =
-    aDispatchStartTarget ? do_QueryInterface(aDispatchStartTarget) :
-                           do_QueryInterface(GetWindow());
-  DispatchPageTransition(target, NS_LITERAL_STRING("pageshow"), aPersisted);
+  
+  nsPageTransitionEvent event(PR_TRUE, NS_PAGE_SHOW, aPersisted);
+  if (aDispatchStartTarget) {
+    event.target = static_cast<nsIDocument*>(this);
+    nsEventDispatcher::Dispatch(aDispatchStartTarget, nsnull, &event);
+  } else {
+    DispatchEventToWindow(&event);
+  }
 }
 
 void
 nsDocument::OnPageHide(PRBool aPersisted, nsIDOMEventTarget* aDispatchStartTarget)
 {
   // Send out notifications that our <link> elements are detached,
   // but only if this is not a full unload.
   nsIContent* root = GetRootContent();
@@ -7148,20 +7142,23 @@ nsDocument::OnPageHide(PRBool aPersisted
 
 #ifdef MOZ_SMIL
   if (mAnimationController) {
     mAnimationController->OnPageHide();
   }
 #endif
   
   // Now send out a PageHide event.
-  nsCOMPtr<nsPIDOMEventTarget> target =
-    aDispatchStartTarget ? do_QueryInterface(aDispatchStartTarget) :
-                           do_QueryInterface(GetWindow());
-  DispatchPageTransition(target, NS_LITERAL_STRING("pagehide"), aPersisted);
+  nsPageTransitionEvent event(PR_TRUE, NS_PAGE_HIDE, aPersisted);
+  if (aDispatchStartTarget) {
+    event.target = static_cast<nsIDocument*>(this);
+    nsEventDispatcher::Dispatch(aDispatchStartTarget, nsnull, &event);
+  } else {
+    DispatchEventToWindow(&event);
+  }
 
   mVisible = PR_FALSE;
 }
 
 void
 nsDocument::WillDispatchMutationEvent(nsINode* aTarget)
 {
   NS_ASSERTION(mSubtreeModifiedDepth != 0 ||
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -1073,19 +1073,18 @@ protected:
   // Return whether all the presshells for this document are safe to flush
   PRBool IsSafeToFlush() const;
   
   virtual PRInt32 GetDefaultNamespaceID() const
   {
     return kNameSpaceID_None;
   }
 
-  void DispatchPageTransition(nsPIDOMEventTarget* aDispatchTarget,
-                              const nsAString& aType,
-                              PRBool aPersisted);
+  // Dispatch an event to the ScriptGlobalObject for this document
+  void DispatchEventToWindow(nsEvent *aEvent);
 
   // nsContentList match functions for GetElementsByClassName
   static PRBool MatchClassNames(nsIContent* aContent, PRInt32 aNamespaceID,
                                 nsIAtom* aAtom, void* aData);
 
   static void DestroyClassNameArray(void* aData);
 
 #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_)                  \
--- a/content/events/public/nsIPrivateDOMEvent.h
+++ b/content/events/public/nsIPrivateDOMEvent.h
@@ -87,17 +87,17 @@ nsresult
 NS_NewDOMMutationEvent(nsIDOMEvent** aResult NS_OUTPARAM, nsPresContext* aPresContext, class nsMutationEvent* aEvent);
 nsresult
 NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
 nsresult
 NS_NewDOMTextEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsTextEvent* aEvent);
 nsresult
 NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
 nsresult
-NS_NewDOMPageTransitionEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
+NS_NewDOMPageTransitionEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsPageTransitionEvent* aEvent);
 #ifdef MOZ_SVG
 nsresult
 NS_NewDOMSVGEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsEvent* aEvent);
 nsresult
 NS_NewDOMSVGZoomEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsGUIEvent* aEvent);
 #endif // MOZ_SVG
 nsresult
 NS_NewDOMXULCommandEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsXULCommandEvent* aEvent);
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -555,20 +555,16 @@ nsDOMEvent::SetEventType(const nsAString
     else if (atom == nsGkAtoms::ononline)
       mEvent->message = NS_ONLINE;
     else if (atom == nsGkAtoms::oncopy)
       mEvent->message = NS_COPY;
     else if (atom == nsGkAtoms::oncut)
       mEvent->message = NS_CUT;
     else if (atom == nsGkAtoms::onpaste)
       mEvent->message = NS_PASTE;
-    else if (atom == nsGkAtoms::onpageshow)
-      mEvent->message = NS_PAGE_SHOW;
-    else if (atom == nsGkAtoms::onpagehide)
-      mEvent->message = NS_PAGE_HIDE;
   } else if (mEvent->eventStructType == NS_MUTATION_EVENT) {
     if (atom == nsGkAtoms::onDOMAttrModified)
       mEvent->message = NS_MUTATION_ATTRMODIFIED;
     else if (atom == nsGkAtoms::onDOMCharacterDataModified)
       mEvent->message = NS_MUTATION_CHARACTERDATAMODIFIED;
     else if (atom == nsGkAtoms::onDOMNodeInserted)
       mEvent->message = NS_MUTATION_NODEINSERTED;
     else if (atom == nsGkAtoms::onDOMNodeRemoved)
@@ -583,16 +579,21 @@ nsDOMEvent::SetEventType(const nsAString
     if (atom == nsGkAtoms::onDOMActivate)
       mEvent->message = NS_UI_ACTIVATE;
     else if (atom == nsGkAtoms::onDOMFocusIn)
       mEvent->message = NS_UI_FOCUSIN;
     else if (atom == nsGkAtoms::onDOMFocusOut)
       mEvent->message = NS_UI_FOCUSOUT;
     else if (atom == nsGkAtoms::oninput)
       mEvent->message = NS_FORM_INPUT;
+  } else if (mEvent->eventStructType == NS_PAGETRANSITION_EVENT) {
+    if (atom == nsGkAtoms::onpageshow)
+      mEvent->message = NS_PAGE_SHOW;
+    else if (atom == nsGkAtoms::onpagehide)
+      mEvent->message = NS_PAGE_HIDE;
   } else if (mEvent->eventStructType == NS_XUL_COMMAND_EVENT) {
     if (atom == nsGkAtoms::oncommand)
       mEvent->message = NS_XUL_COMMAND;
   }
 #ifdef MOZ_SVG
   else if (mEvent->eventStructType == NS_SVG_EVENT) {
     if (atom == nsGkAtoms::onSVGLoad)
       mEvent->message = NS_SVG_LOAD;
@@ -937,16 +938,23 @@ NS_METHOD nsDOMEvent::DuplicatePrivateDa
       break;
     }
     case NS_UI_EVENT:
     {
       newEvent = new nsUIEvent(PR_FALSE, msg,
                                static_cast<nsUIEvent*>(mEvent)->detail);
       break;
     }
+    case NS_PAGETRANSITION_EVENT:
+    {
+      newEvent =
+        new nsPageTransitionEvent(PR_FALSE, msg,
+                                  ((nsPageTransitionEvent*) mEvent)->persisted);
+      break;
+    }
 #ifdef MOZ_SVG
     case NS_SVG_EVENT:
     {
       newEvent = new nsEvent(PR_FALSE, msg);
       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
       newEvent->eventStructType = NS_SVG_EVENT;
       break;
     }
--- a/content/events/src/nsDOMPageTransitionEvent.cpp
+++ b/content/events/src/nsDOMPageTransitionEvent.cpp
@@ -34,47 +34,62 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsDOMPageTransitionEvent.h"
 #include "nsContentUtils.h"
 
+nsDOMPageTransitionEvent::nsDOMPageTransitionEvent(nsPresContext* aPresContext,
+                                                   nsPageTransitionEvent* aEvent)
+  : nsDOMEvent(aPresContext, aEvent ? aEvent :
+               new nsPageTransitionEvent(PR_FALSE, 0, PR_FALSE))
+{  
+  if ( aEvent ) {
+    mEventIsInternal = PR_FALSE;
+  }
+  else
+  {
+    mEventIsInternal = PR_TRUE;
+    mEvent->time = PR_Now();
+  }
+}
+
 NS_INTERFACE_MAP_BEGIN(nsDOMPageTransitionEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMPageTransitionEvent)
   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(PageTransitionEvent)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
 
 NS_IMPL_ADDREF_INHERITED(nsDOMPageTransitionEvent, nsDOMEvent)
 NS_IMPL_RELEASE_INHERITED(nsDOMPageTransitionEvent, nsDOMEvent)
 
 NS_IMETHODIMP
 nsDOMPageTransitionEvent::GetPersisted(PRBool* aPersisted)
 {
-  *aPersisted = mPersisted;
+  *aPersisted = static_cast<nsPageTransitionEvent*>(mEvent)->persisted;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMPageTransitionEvent::InitPageTransitionEvent(const nsAString &aTypeArg,
                                                   PRBool aCanBubbleArg,
                                                   PRBool aCancelableArg,
                                                   PRBool aPersisted)
 {
   nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  mPersisted = aPersisted;
+  static_cast<nsPageTransitionEvent*>(mEvent)->persisted = aPersisted;
   return NS_OK;
 }
 
 nsresult NS_NewDOMPageTransitionEvent(nsIDOMEvent** aInstancePtrResult,
                                       nsPresContext* aPresContext,
-                                      nsEvent *aEvent) 
+                                      nsPageTransitionEvent *aEvent) 
 {
   nsDOMPageTransitionEvent* it =
     new nsDOMPageTransitionEvent(aPresContext, aEvent);
   if (nsnull == it) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return CallQueryInterface(it, aInstancePtrResult);
--- a/content/events/src/nsDOMPageTransitionEvent.h
+++ b/content/events/src/nsDOMPageTransitionEvent.h
@@ -41,22 +41,20 @@
 
 #include "nsIDOMPageTransitionEvent.h"
 #include "nsDOMEvent.h"
 
 class nsDOMPageTransitionEvent : public nsIDOMPageTransitionEvent,
                                  public nsDOMEvent
 {
 public:
-  nsDOMPageTransitionEvent(nsPresContext* aPresContext, nsEvent* aEvent) :
-  nsDOMEvent(aPresContext, aEvent), mPersisted(PR_FALSE) {}
-
+  nsDOMPageTransitionEvent(nsPresContext* aPresContext,
+                           nsPageTransitionEvent* aEvent);
+                     
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_NSIDOMPAGETRANSITIONEVENT
 
   // Forward to base class
   NS_FORWARD_TO_NSDOMEVENT
-protected:
-  PRBool mPersisted;
 };
 
 #endif // nsDOMPageTransitionEvent_h__
--- a/content/events/src/nsEventDispatcher.cpp
+++ b/content/events/src/nsEventDispatcher.cpp
@@ -614,16 +614,20 @@ nsEventDispatcher::CreateEvent(nsPresCon
                                nsIDOMEvent** aDOMEvent)
 {
   *aDOMEvent = nsnull;
 
   if (aEvent) {
     switch(aEvent->eventStructType) {
     case NS_MUTATION_EVENT:
       return NS_NewDOMMutationEvent(aDOMEvent, aPresContext,
+    case NS_PAGETRANSITION_EVENT:
+      return NS_NewDOMPageTransitionEvent(aDOMEvent, aPresContext,
+                                          static_cast<nsPageTransitionEvent*>
+                                                     (aEvent));
                                     static_cast<nsMutationEvent*>(aEvent));
     case NS_GUI_EVENT:
     case NS_COMPOSITION_EVENT:
     case NS_SCROLLPORT_EVENT:
       return NS_NewDOMUIEvent(aDOMEvent, aPresContext,
                               static_cast<nsGUIEvent*>(aEvent));
     case NS_KEY_EVENT:
       return NS_NewDOMKeyboardEvent(aDOMEvent, aPresContext,
@@ -719,11 +723,9 @@ nsEventDispatcher::CreateEvent(nsPresCon
   if (aEventType.LowerCaseEqualsLiteral("notifypaintevent"))
     return NS_NewDOMNotifyPaintEvent(aDOMEvent, aPresContext, nsnull);
   if (aEventType.LowerCaseEqualsLiteral("simplegestureevent"))
     return NS_NewDOMSimpleGestureEvent(aDOMEvent, aPresContext, nsnull);
   if (aEventType.LowerCaseEqualsLiteral("beforeunloadevent"))
     return NS_NewDOMBeforeUnloadEvent(aDOMEvent, aPresContext, nsnull);
 
   return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
-  if (aEventType.LowerCaseEqualsLiteral("pagetransition"))
-    return NS_NewDOMPageTransitionEvent(aDOMEvent, aPresContext, nsnull);
 }
--- a/widget/public/nsGUIEvent.h
+++ b/widget/public/nsGUIEvent.h
@@ -87,16 +87,17 @@ class nsHashKey;
 #define NS_MUTATION_EVENT                 19 // |nsMutationEvent| in content
 #define NS_ACCESSIBLE_EVENT               20
 #define NS_FORM_EVENT                     21
 #define NS_POPUP_EVENT                    23
 #define NS_COMMAND_EVENT                  24
 
 
 #define NS_UI_EVENT                       27
+#define NS_PAGETRANSITION_EVENT           29
 #ifdef MOZ_SVG
 #define NS_SVG_EVENT                      30
 #define NS_SVGZOOM_EVENT                  31
 #endif // MOZ_SVG
 #define NS_XUL_COMMAND_EVENT              32
 #define NS_QUERY_CONTENT_EVENT            33
 #ifdef MOZ_MEDIA
 #define NS_MEDIA_EVENT                    34
@@ -1204,16 +1205,31 @@ public:
       detail(d)
   {
   }
 
   PRInt32 detail;
 };
 
 /**
+ * PageTransition event
+ */
+class nsPageTransitionEvent : public nsEvent
+{
+public:
+  nsPageTransitionEvent(PRBool isTrusted, PRUint32 msg, PRBool p)
+    : nsEvent(isTrusted, msg, NS_PAGETRANSITION_EVENT),
+      persisted(p)
+  {
+  }
+
+  PRBool persisted;
+};
+
+/**
  * XUL command event
  */
 class nsXULCommandEvent : public nsInputEvent
 {
 public:
   nsXULCommandEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w)
     : nsInputEvent(isTrusted, msg, w, NS_XUL_COMMAND_EVENT)
   {