Bug 1449631 part 5. Move Will/Pre/PostHandleEvent out of nsIDOMEventTarget. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 05 Apr 2018 13:42:41 -0400
changeset 411927 d05e92371389bf5992a4c96a243b4e3d26fe7e1f
parent 411926 1f824c936c25ac047e2a79aecb737f7095026d73
child 411928 caa5bef6848122d106ad47fc7b2bf104d2d8ce3d
push id101783
push userbzbarsky@mozilla.com
push dateThu, 05 Apr 2018 17:44:01 +0000
treeherdermozilla-inbound@d32c2aed2886 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1449631
milestone61.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 1449631 part 5. Move Will/Pre/PostHandleEvent out of nsIDOMEventTarget. r=smaug MozReview-Commit-ID: K2nOZNPy0XE
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowInner.h
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsGlobalWindowOuter.h
dom/base/nsINode.h
dom/base/nsWindowRoot.h
dom/events/DOMEventTargetHelper.h
dom/events/EventDispatcher.h
dom/events/EventTarget.h
dom/html/HTMLFormElement.cpp
dom/html/HTMLFormElement.h
dom/interfaces/events/nsIDOMEventTarget.idl
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -1949,22 +1949,16 @@ nsGlobalWindowInner::GetTargetForDOMEven
 
 EventTarget*
 nsGlobalWindowInner::GetTargetForEventTargetChain()
 {
   return this;
 }
 
 nsresult
-nsGlobalWindowInner::WillHandleEvent(EventChainPostVisitor& aVisitor)
-{
-  return NS_OK;
-}
-
-nsresult
 nsGlobalWindowInner::GetEventTargetParent(EventChainPreVisitor& aVisitor)
 {
   EventMessage msg = aVisitor.mEvent->mMessage;
 
   aVisitor.mCanHandle = true;
   aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119
   if (msg == eResize && aVisitor.mEvent->IsTrusted()) {
     // QIing to window so that we can keep the old behavior also in case
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -328,16 +328,18 @@ public:
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
 
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
 
+  nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
+
   // nsPIDOMWindow
   virtual nsPIDOMWindowOuter* GetPrivateRoot() override;
 
   // Outer windows only.
   virtual bool IsTopLevelWindowActive() override;
 
   virtual PopupControlState GetPopupControlState() const override;
 
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -2339,22 +2339,16 @@ nsGlobalWindowOuter::GetTargetForDOMEven
 
 EventTarget*
 nsGlobalWindowOuter::GetTargetForEventTargetChain()
 {
   return GetCurrentInnerWindowInternal();
 }
 
 nsresult
-nsGlobalWindowOuter::WillHandleEvent(EventChainPostVisitor& aVisitor)
-{
-  return NS_OK;
-}
-
-nsresult
 nsGlobalWindowOuter::GetEventTargetParent(EventChainPreVisitor& aVisitor)
 {
   MOZ_CRASH("The outer window should not be part of an event path");
 }
 
 bool
 nsGlobalWindowOuter::ShouldPromptToBlockDialogs()
 {
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -285,16 +285,18 @@ public:
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
 
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
 
+  nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
+
   // nsPIDOMWindow
   virtual nsPIDOMWindowOuter* GetPrivateRoot() override;
 
   // Outer windows only.
   virtual void ActivateOrDeactivate(bool aActivate) override;
   virtual void SetActive(bool aActive) override;
   virtual bool IsTopLevelWindowActive() override;
   virtual void SetIsBackground(bool aIsBackground) override;
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -1037,16 +1037,18 @@ public:
                                 mozilla::ErrorResult& aRv) override;
   using nsIDOMEventTarget::AddSystemEventListener;
 
   virtual bool IsApzAware() const override;
 
   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
   virtual nsIGlobalObject* GetOwnerGlobal() const override;
 
+  nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
+
   /**
    * Adds a mutation observer to be notified when this node, or any of its
    * descendants, are modified. The node will hold a weak reference to the
    * observer, which means that it is the responsibility of the observer to
    * remove itself in case it dies before the node.  If an observer is added
    * while observers are being notified, it may also be notified.  In general,
    * adding observers while inside a notification is not a good idea.  An
    * observer that is already observing the node must not be added without
--- a/dom/base/nsWindowRoot.h
+++ b/dom/base/nsWindowRoot.h
@@ -33,16 +33,18 @@ public:
     GetOrCreateListenerManager() override;
 
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) override;
 
+  nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
+
   // nsPIWindowRoot
 
   virtual nsPIDOMWindowOuter* GetWindow() override;
 
   virtual nsresult GetControllers(bool aForVisibleWindow,
                                   nsIControllers** aResult) override;
   virtual nsresult GetControllerForCommand(const char * aCommand,
                                            bool aForVisibleWindow,
--- a/dom/events/DOMEventTargetHelper.h
+++ b/dom/events/DOMEventTargetHelper.h
@@ -75,16 +75,18 @@ public:
 
   using EventTarget::AddEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 dom::EventListener* aListener,
                                 const dom::AddEventListenerOptionsOrBoolean& aOptions,
                                 const dom::Nullable<bool>& aWantsUntrusted,
                                 ErrorResult& aRv) override;
 
+  nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
+
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMEVENTTARGETHELPER_IID)
 
   void GetParentObject(nsIScriptGlobalObject **aParentObject)
   {
     if (mParentObject) {
       CallQueryInterface(mParentObject, aParentObject);
     } else {
       *aParentObject = nullptr;
--- a/dom/events/EventDispatcher.h
+++ b/dom/events/EventDispatcher.h
@@ -207,29 +207,29 @@ public:
 
   /**
    * true if the original target of the event is inside anonymous content.
    * This is set before calling GetEventTargetParent on event targets.
    */
   bool                  mOriginalTargetIsInAnon;
 
   /**
-   * Whether or not nsIDOMEventTarget::WillHandleEvent will be
+   * Whether or not EventTarget::WillHandleEvent will be
    * called. Default is false;
    */
   bool                  mWantsWillHandleEvent;
 
   /**
    * If it is known that the current target doesn't have a listener manager
    * when GetEventTargetParent is called, set this to false.
    */
   bool                  mMayHaveListenerManager;
 
   /**
-   * Whether or not nsIDOMEventTarget::PreHandleEvent will be called. Default is
+   * Whether or not EventTarget::PreHandleEvent will be called. Default is
    * false;
    */
   bool mWantsPreHandleEvent;
 
   /**
    * True if the current target is either closed ShadowRoot or root of
    * chrome only access tree (for example native anonymous content).
    */
--- a/dom/events/EventTarget.h
+++ b/dom/events/EventTarget.h
@@ -14,16 +14,18 @@
 
 class nsPIDOMWindowOuter;
 class nsIGlobalObject;
 
 namespace mozilla {
 
 class AsyncEventDispatcher;
 class ErrorResult;
+class EventChainPostVisitor;
+class EventChainVisitor;
 class EventListenerManager;
 
 namespace dom {
 
 class AddEventListenerOptionsOrBoolean;
 class Event;
 class EventListener;
 class EventListenerOptionsOrBoolean;
@@ -136,16 +138,44 @@ public:
   bool HasNonSystemGroupListenersForUntrustedKeyEvents() const;
 
   // Used by APZ to determine whether this event target has non-chrome and
   // non-passive event listeners for untrusted key events.
   bool HasNonPassiveNonSystemGroupListenersForUntrustedKeyEvents() const;
 
   virtual bool IsApzAware() const;
 
+  /**
+   * Called before the capture phase of the event flow and after event target
+   * chain creation. This is used to handle things that must be executed before
+   * dispatching the event to DOM.
+   */
+  virtual nsresult PreHandleEvent(EventChainVisitor& aVisitor)
+  {
+    return NS_OK;
+  }
+
+  /**
+   * If EventChainPreVisitor.mWantsWillHandleEvent is set true,
+   * called just before possible event handlers on this object will be called.
+   */
+  virtual void WillHandleEvent(EventChainPostVisitor& aVisitor)
+  {
+  }
+
+  /**
+   * Called after the bubble phase of the system event group.
+   * The default handling of the event should happen here.
+   * @param aVisitor the visitor object which is used during post handling.
+   *
+   * @see EventDispatcher.h for documentation about aVisitor.
+   * @note Only EventDispatcher should call this method.
+   */
+  virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) = 0;
+  
 protected:
   EventHandlerNonNull* GetEventHandler(nsAtom* aType,
                                        const nsAString& aTypeString);
   void SetEventHandler(nsAtom* aType, const nsAString& aTypeString,
                        EventHandlerNonNull* aHandler);
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
--- a/dom/html/HTMLFormElement.cpp
+++ b/dom/html/HTMLFormElement.cpp
@@ -462,29 +462,28 @@ HTMLFormElement::GetEventTargetParent(Ev
         return NS_OK;
       }
       mGeneratingReset = true;
     }
   }
   return nsGenericHTMLElement::GetEventTargetParent(aVisitor);
 }
 
-nsresult
+void
 HTMLFormElement::WillHandleEvent(EventChainPostVisitor& aVisitor)
 {
   // If this is the bubble stage and there is a nested form below us which
   // received a submit event we do *not* want to handle the submit event
   // for this form too.
   if ((aVisitor.mEvent->mMessage == eFormSubmit ||
        aVisitor.mEvent->mMessage == eFormReset) &&
       aVisitor.mEvent->mFlags.mInBubblingPhase &&
       aVisitor.mEvent->mOriginalTarget != static_cast<nsIContent*>(this)) {
     aVisitor.mEvent->StopPropagation();
   }
-  return NS_OK;
 }
 
 nsresult
 HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
 {
   if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this)) {
     EventMessage msg = aVisitor.mEvent->mMessage;
     if (msg == eFormSubmit) {
--- a/dom/html/HTMLFormElement.h
+++ b/dom/html/HTMLFormElement.h
@@ -90,18 +90,17 @@ public:
   // nsIContent
   virtual bool ParseAttribute(int32_t aNamespaceID,
                                 nsAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsIPrincipal* aMaybeScriptedPrincipal,
                                 nsAttrValue& aResult) override;
   virtual nsresult GetEventTargetParent(
                      EventChainPreVisitor& aVisitor) override;
-  virtual nsresult WillHandleEvent(
-                     EventChainPostVisitor& aVisitor) override;
+  void WillHandleEvent(EventChainPostVisitor& aVisitor) override;
   virtual nsresult PostHandleEvent(
                      EventChainPostVisitor& aVisitor) override;
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers) override;
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true) override;
--- a/dom/interfaces/events/nsIDOMEventTarget.idl
+++ b/dom/interfaces/events/nsIDOMEventTarget.idl
@@ -8,18 +8,16 @@
 %{C++
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/Nullable.h"
 #include "js/TypeDecls.h"
 
 using mozilla::dom::Nullable;
 
 namespace mozilla {
-class EventChainVisitor;
-class EventChainPostVisitor;
 class EventChainPreVisitor;
 class EventListenerManager;
 namespace dom {
 class EventTarget;
 } // namespace dom
 } // namespace mozilla
 
 class nsPresContext;
@@ -188,48 +186,17 @@ interface nsIDOMEventTarget : nsISupport
    *
    * @param aVisitor the visitor object which is used to create the
    *                 event target chain for event dispatching.
    *
    * @note Only EventDispatcher should call this method.
    */
   [noscript, nostdcall]
   void GetEventTargetParent(in EventChainPreVisitorRef aVisitor);
-
-  /**
-   * Called before the capture phase of the event flow and after event target
-   * chain creation. This is used to handle those stuffs must be executed before
-   * dispatch event to DOM
-   */
-%{C++
-  virtual nsresult PreHandleEvent(mozilla::EventChainVisitor& aVisitor)
-  {
-    return NS_OK;
-  }
-%}
-
-  /**
-   * If EventChainPreVisitor.mWantsWillHandleEvent is set PR_TRUE,
-   * called just before possible event handlers on this object will be called.
-   */
-  [noscript, nostdcall]
-  void WillHandleEvent(in EventChainPostVisitorRef aVisitor);
-
-  /**
-   * Called after the bubble phase of the system event group.
-   * The default handling of the event should happen here.
-   * @param aVisitor the visitor object which is used during post handling.
-   *
-   * @see EventDispatcher.h for documentation about aVisitor.
-   * @note Only EventDispatcher should call this method.
-   */
-  [noscript, nostdcall]
-  void PostHandleEvent(in EventChainPostVisitorRef aVisitor);
 };
 
 %{C++
 
 #define NS_IMPL_DOMTARGET_DEFAULTS(_class) \
 mozilla::dom::EventTarget* _class::GetTargetForDOMEvent() { return this; } \
-mozilla::dom::EventTarget* _class::GetTargetForEventTargetChain() { return this; } \
-nsresult _class::WillHandleEvent(mozilla::EventChainPostVisitor& aVisitor) { return NS_OK; }
+mozilla::dom::EventTarget* _class::GetTargetForEventTargetChain() { return this; }
 
 %}