Bug 1455052 part 1. Switch event dispatch to working with Event, not nsIDOMEvent. r=masayuki
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 20 Apr 2018 12:53:16 -0400
changeset 414769 070eb9701963ab1a00e3cbe6931f21e80f7d6aa5
parent 414768 32b9dbc4159082cadb88f9f87948a867ac41104d
child 414770 00dfc503972c765debc926eb11a093d801617eb4
push id33876
push userdluca@mozilla.com
push dateFri, 20 Apr 2018 23:00:46 +0000
treeherdermozilla-central@39ccabfd7d07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1455052
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 1455052 part 1. Switch event dispatch to working with Event, not nsIDOMEvent. r=masayuki MozReview-Commit-ID: 4vZgmBnTWKH
dom/events/EventDispatcher.cpp
dom/events/EventDispatcher.h
dom/events/EventListenerManager.cpp
dom/events/EventListenerManager.h
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/nsIPresShell.h
--- a/dom/events/EventDispatcher.cpp
+++ b/dom/events/EventDispatcher.cpp
@@ -655,17 +655,17 @@ MayRetargetToChromeIfCanNotHandleEvent(
   }
   return nullptr;
 }
 
 /* static */ nsresult
 EventDispatcher::Dispatch(nsISupports* aTarget,
                           nsPresContext* aPresContext,
                           WidgetEvent* aEvent,
-                          nsIDOMEvent* aDOMEvent,
+                          Event* aDOMEvent,
                           nsEventStatus* aEventStatus,
                           EventDispatchingCallback* aCallback,
                           nsTArray<EventTarget*>* aTargets)
 {
   AUTO_PROFILER_LABEL("EventDispatcher::Dispatch", EVENTS);
 
   NS_ASSERTION(aEvent, "Trying to dispatch without WidgetEvent!");
   NS_ENSURE_TRUE(!aEvent->mFlags.mIsBeingDispatched,
@@ -804,17 +804,17 @@ EventDispatcher::Dispatch(nsISupports* a
   EventTargetChainItem* targetEtci =
     EventTargetChainItem::Create(chain, target->GetTargetForEventTargetChain());
   MOZ_ASSERT(&chain[0] == targetEtci);
   if (!targetEtci->IsValid()) {
     EventTargetChainItem::DestroyLast(chain, targetEtci);
     return NS_ERROR_FAILURE;
   }
 
-  // Make sure that nsIDOMEvent::target and nsIDOMEvent::originalTarget
+  // Make sure that Event::target and Event::originalTarget
   // point to the last item in the chain.
   if (!aEvent->mTarget) {
     // Note, CurrentTarget() points always to the object returned by
     // GetTargetForEventTargetChain().
     aEvent->mTarget = targetEtci->CurrentTarget();
   } else {
     // XXX But if the target is already set, use that. This is a hack
     //     for the 'load', 'beforeunload' and 'unload' events,
@@ -982,30 +982,30 @@ EventDispatcher::Dispatch(nsISupports* a
   }
 
   return rv;
 }
 
 /* static */ nsresult
 EventDispatcher::DispatchDOMEvent(nsISupports* aTarget,
                                   WidgetEvent* aEvent,
-                                  nsIDOMEvent* aDOMEvent,
+                                  Event* aDOMEvent,
                                   nsPresContext* aPresContext,
                                   nsEventStatus* aEventStatus)
 {
   if (aDOMEvent) {
     WidgetEvent* innerEvent = aDOMEvent->WidgetEventPtr();
     NS_ENSURE_TRUE(innerEvent, NS_ERROR_ILLEGAL_VALUE);
 
     bool dontResetTrusted = false;
     if (innerEvent->mFlags.mDispatchedAtLeastOnce) {
       innerEvent->mTarget = nullptr;
       innerEvent->mOriginalTarget = nullptr;
     } else {
-      aDOMEvent->GetIsTrusted(&dontResetTrusted);
+      dontResetTrusted = aDOMEvent->IsTrusted();
     }
 
     if (!dontResetTrusted) {
       //Check security state to determine if dispatcher is trusted
       bool trusted = NS_IsMainThread() ? nsContentUtils::LegacyIsCallerChromeOrNativeCode()
                                        : IsCurrentThreadRunningChromeWorker();
       aDOMEvent->SetTrusted(trusted);
     }
--- a/dom/events/EventDispatcher.h
+++ b/dom/events/EventDispatcher.h
@@ -12,17 +12,16 @@
 #include "mozilla/EventForwards.h"
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 
 // Microsoft's API Name hackery sucks
 #undef CreateEvent
 
 class nsIContent;
-class nsIDOMEvent;
 class nsPresContext;
 
 template<class E> class nsCOMArray;
 
 namespace mozilla {
 namespace dom {
 class Event;
 class EventTarget;
@@ -48,17 +47,17 @@ class EventTarget;
  * is called right after calling event listener for the current event target.
  */
 
 class EventChainVisitor
 {
 public:
   EventChainVisitor(nsPresContext* aPresContext,
                     WidgetEvent* aEvent,
-                    nsIDOMEvent* aDOMEvent,
+                    dom::Event* aDOMEvent,
                     nsEventStatus aEventStatus = nsEventStatus_eIgnore)
     : mPresContext(aPresContext)
     , mEvent(aEvent)
     , mDOMEvent(aDOMEvent)
     , mEventStatus(aEventStatus)
     , mItemFlags(0)
   {
   }
@@ -72,17 +71,17 @@ public:
    * The WidgetEvent which is being dispatched. Never nullptr.
    */
   WidgetEvent* const mEvent;
 
   /**
    * The DOM Event assiciated with the mEvent. Possibly nullptr if a DOM Event
    * is not (yet) created.
    */
-  nsIDOMEvent*          mDOMEvent;
+  dom::Event*           mDOMEvent;
 
   /**
    * The status of the event.
    * @see nsEventStatus.h
    */
   nsEventStatus         mEventStatus;
 
   /**
@@ -108,17 +107,17 @@ public:
   nsCOMPtr<nsISupports> mItemData;
 };
 
 class EventChainPreVisitor : public EventChainVisitor
 {
 public:
   EventChainPreVisitor(nsPresContext* aPresContext,
                        WidgetEvent* aEvent,
-                       nsIDOMEvent* aDOMEvent,
+                       dom::Event* aDOMEvent,
                        nsEventStatus aEventStatus,
                        bool aIsInAnon,
                        dom::EventTarget* aTargetInKnownToBeHandledScope)
     : EventChainVisitor(aPresContext, aEvent, aDOMEvent, aEventStatus)
     , mCanHandle(true)
     , mAutomaticChromeDispatch(true)
     , mForceContentDispatch(false)
     , mRelatedTargetIsInAnon(false)
@@ -322,32 +321,32 @@ public:
    * If aTargets is non-null, event target chain will be created, but
    * event won't be handled. In this case aEvent->mMessage should be
    * eVoidEvent.
    * @note Use this method when dispatching a WidgetEvent.
    */
   static nsresult Dispatch(nsISupports* aTarget,
                            nsPresContext* aPresContext,
                            WidgetEvent* aEvent,
-                           nsIDOMEvent* aDOMEvent = nullptr,
+                           dom::Event* aDOMEvent = nullptr,
                            nsEventStatus* aEventStatus = nullptr,
                            EventDispatchingCallback* aCallback = nullptr,
                            nsTArray<dom::EventTarget*>* aTargets = nullptr);
 
   /**
    * Dispatches an event.
    * If aDOMEvent is not nullptr, it is used for dispatching
    * (aEvent can then be nullptr) and (if aDOMEvent is not |trusted| already),
    * the |trusted| flag is set based on the UniversalXPConnect capability.
    * Otherwise this works like EventDispatcher::Dispatch.
-   * @note Use this method when dispatching nsIDOMEvent.
+   * @note Use this method when dispatching a dom::Event.
    */
   static nsresult DispatchDOMEvent(nsISupports* aTarget,
                                    WidgetEvent* aEvent,
-                                   nsIDOMEvent* aDOMEvent,
+                                   dom::Event* aDOMEvent,
                                    nsPresContext* aPresContext,
                                    nsEventStatus* aEventStatus);
 
   /**
    * Creates a DOM Event.  Returns null if the event type is unsupported.
    */
   static already_AddRefed<dom::Event> CreateEvent(dom::EventTarget* aOwner,
                                                   nsPresContext* aPresContext,
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1088,17 +1088,17 @@ EventListenerManager::CompileEventHandle
     jsEventHandler->SetHandler(handlerCallback);
   }
 
   return result;
 }
 
 nsresult
 EventListenerManager::HandleEventSubType(Listener* aListener,
-                                         nsIDOMEvent* aDOMEvent,
+                                         Event* aDOMEvent,
                                          EventTarget* aCurrentTarget)
 {
   nsresult result = NS_OK;
   // strong ref
   EventListenerHolder listenerHolder(aListener->mListener.Clone());
 
   // If this is a script handler and we haven't yet
   // compiled the event handler itself
@@ -1106,25 +1106,24 @@ EventListenerManager::HandleEventSubType
       aListener->mHandlerIsString) {
     result = CompileEventHandlerInternal(aListener, nullptr, nullptr);
     aListener = nullptr;
   }
 
   if (NS_SUCCEEDED(result)) {
     nsAutoMicroTask mt;
 
-    // nsIDOMEvent::currentTarget is set in EventDispatcher.
+    // Event::currentTarget is set in EventDispatcher.
     if (listenerHolder.HasWebIDLCallback()) {
       ErrorResult rv;
       listenerHolder.GetWebIDLCallback()->
-        HandleEvent(aCurrentTarget, *(aDOMEvent->InternalDOMEvent()), rv);
+        HandleEvent(aCurrentTarget, *aDOMEvent, rv);
       result = rv.StealNSResult();
     } else {
-      result = listenerHolder.GetXPCOMCallback()->
-        HandleEvent(aDOMEvent->InternalDOMEvent());
+      result = listenerHolder.GetXPCOMCallback()-> HandleEvent(aDOMEvent);
     }
   }
 
   return result;
 }
 
 EventMessage
 EventListenerManager::GetLegacyEventMessage(EventMessage aEventMessage) const
@@ -1162,17 +1161,17 @@ EventListenerManager::GetLegacyEventMess
 /**
 * Causes a check for event listeners and processing by them if they exist.
 * @param an event listener
 */
 
 void
 EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
                                           WidgetEvent* aEvent,
-                                          nsIDOMEvent** aDOMEvent,
+                                          Event** aDOMEvent,
                                           EventTarget* aCurrentTarget,
                                           nsEventStatus* aEventStatus)
 {
   //Set the value of the internal PreventDefault flag properly based on aEventStatus
   if (!aEvent->DefaultPrevented() &&
       *aEventStatus == nsEventStatus_eConsumeNoDefault) {
     // Assume that if only aEventStatus claims that the event has already been
     // consumed, the consumer is default event handler.
@@ -1237,18 +1236,17 @@ EventListenerManager::HandleEventInterna
             if (mIsMainThreadELM &&
                 listener->mListenerType != Listener::eNativeListener) {
               docShell = nsContentUtils::GetDocShellForEventTarget(mTarget);
               if (docShell) {
                 if (timelines && timelines->HasConsumer(docShell)) {
                   needsEndEventMarker = true;
                   nsAutoString typeStr;
                   (*aDOMEvent)->GetType(typeStr);
-                  uint16_t phase;
-                  (*aDOMEvent)->GetEventPhase(&phase);
+                  uint16_t phase = (*aDOMEvent)->EventPhase();
                   timelines->AddMarkerForDocShell(docShell, Move(
                     MakeUnique<EventTimelineMarker>(
                       typeStr, phase, MarkerTracingType::START)));
                 }
               }
             }
 
             aEvent->mFlags.mInPassiveListener = listener->mFlags.mPassive;
@@ -1273,18 +1271,17 @@ EventListenerManager::HandleEventInterna
               (*aDOMEvent)->GetType(typeStr);
               AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING(
                 "EventListenerManager::HandleEventInternal", EVENTS, typeStr);
               TimeStamp startTime = TimeStamp::Now();
 
               rv = HandleEventSubType(listener, *aDOMEvent, aCurrentTarget);
 
               TimeStamp endTime = TimeStamp::Now();
-              uint16_t phase;
-              (*aDOMEvent)->GetEventPhase(&phase);
+              uint16_t phase = (*aDOMEvent)->EventPhase();
               profiler_add_marker(
                 "DOMEvent",
                 MakeUnique<DOMEventMarkerPayload>(typeStr, phase,
                                                   aEvent->mTimeStamp,
                                                   startTime, endTime));
             } else
 #endif
             {
--- a/dom/events/EventListenerManager.h
+++ b/dom/events/EventListenerManager.h
@@ -13,31 +13,31 @@
 #include "mozilla/MemoryReporting.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMEventListener.h"
 #include "nsTObserverArray.h"
 
 class nsIDocShell;
-class nsIDOMEvent;
 class nsIEventListenerInfo;
 class nsPIDOMWindowInner;
 class JSTracer;
 
 struct EventTypeData;
 
 template<class T> class nsCOMArray;
 
 namespace mozilla {
 
 class ELMCreationDetector;
 class EventListenerManager;
 
 namespace dom {
+class Event;
 class EventTarget;
 class Element;
 } // namespace dom
 
 typedef dom::CallbackObjectHolder<dom::EventListener,
                                   nsIDOMEventListener> EventListenerHolder;
 
 struct EventListenerFlags
@@ -362,17 +362,17 @@ public:
                            dom::Element* aElement);
   /**
    * Remove the current "inline" event listener for aName.
    */
   void RemoveEventHandler(nsAtom *aName, const nsAString& aTypeString);
 
   void HandleEvent(nsPresContext* aPresContext,
                    WidgetEvent* aEvent,
-                   nsIDOMEvent** aDOMEvent,
+                   dom::Event** aDOMEvent,
                    dom::EventTarget* aCurrentTarget,
                    nsEventStatus* aEventStatus)
   {
     if (mListeners.IsEmpty() || aEvent->PropagationStopped()) {
       return;
     }
 
     if (!mMayHaveCapturingListeners && !aEvent->mFlags.mInBubblingPhase) {
@@ -492,22 +492,22 @@ public:
 
   bool HasApzAwareListeners();
   bool IsApzAwareListener(Listener* aListener);
   bool IsApzAwareEvent(nsAtom* aEvent);
 
 protected:
   void HandleEventInternal(nsPresContext* aPresContext,
                            WidgetEvent* aEvent,
-                           nsIDOMEvent** aDOMEvent,
+                           dom::Event** aDOMEvent,
                            dom::EventTarget* aCurrentTarget,
                            nsEventStatus* aEventStatus);
 
   nsresult HandleEventSubType(Listener* aListener,
-                              nsIDOMEvent* aDOMEvent,
+                              dom::Event* aDOMEvent,
                               dom::EventTarget* aCurrentTarget);
 
   /**
    * If the given EventMessage has a legacy version that we support, then this
    * function returns that legacy version. Otherwise, this function simply
    * returns the passed-in EventMessage.
    */
   EventMessage GetLegacyEventMessage(EventMessage aEventMessage) const;
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -8095,17 +8095,17 @@ PresShell::HandleDOMEventWithTarget(nsIC
 
   PopCurrentEventInfo();
   return rv;
 }
 
 // See the method above.
 nsresult
 PresShell::HandleDOMEventWithTarget(nsIContent* aTargetContent,
-                                    nsIDOMEvent* aEvent,
+                                    Event* aEvent,
                                     nsEventStatus* aStatus)
 {
   nsresult rv = NS_OK;
 
   PushCurrentEventInfo(nullptr, aTargetContent);
   nsCOMPtr<nsISupports> container = mPresContext->GetContainerWeak();
   if (container) {
     rv = EventDispatcher::DispatchDOMEvent(aTargetContent, nullptr, aEvent,
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -232,17 +232,17 @@ public:
   MOZ_CAN_RUN_SCRIPT nsresult HandleEvent(nsIFrame* aFrame,
                                           WidgetGUIEvent* aEvent,
                                           bool aDontRetargetEvents,
                                           nsEventStatus* aEventStatus) override;
   nsresult HandleDOMEventWithTarget(nsIContent* aTargetContent,
                                     WidgetEvent* aEvent,
                                     nsEventStatus* aStatus) override;
   nsresult HandleDOMEventWithTarget(nsIContent* aTargetContent,
-                                    nsIDOMEvent* aEvent,
+                                    dom::Event* aEvent,
                                     nsEventStatus* aStatus) override;
   bool ShouldIgnoreInvalidation() override;
   void WillPaint() override;
   void WillPaintWindow() override;
   void DidPaintWindow() override;
   void ScheduleViewManagerFlush(PaintType aType = PAINT_DEFAULT) override;
   void ClearMouseCaptureOnView(nsView* aView) override;
   bool IsVisible() override;
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -65,17 +65,16 @@ class nsILayoutHistoryState;
 class nsIReflowCallback;
 class nsIDOMNode;
 class nsCSSFrameConstructor;
 class nsISelection;
 template<class E> class nsCOMArray;
 class AutoWeakFrame;
 class WeakFrame;
 class nsIScrollableFrame;
-class nsIDOMEvent;
 class nsDisplayList;
 class nsDisplayListBuilder;
 class nsPIDOMWindowOuter;
 struct nsPoint;
 class nsINode;
 struct nsRect;
 class nsRegion;
 class nsRefreshDriver;
@@ -91,16 +90,17 @@ class DocAccessible;
 #endif
 class nsITimer;
 
 namespace mozilla {
 class EventStates;
 
 namespace dom {
 class Element;
+class Event;
 class HTMLSlotElement;
 class Touch;
 class Selection;
 class ShadowRoot;
 } // namespace dom
 
 namespace layers {
 class LayerManager;
@@ -940,18 +940,18 @@ public:
                                  mozilla::WidgetEvent* aEvent,
                                  nsEventStatus* aStatus) = 0;
 
   /**
    * Dispatch event to content only (NOT full processing)
    * @note The caller must have a strong reference to the PresShell.
    */
   virtual nsresult HandleDOMEventWithTarget(nsIContent* aTargetContent,
-                                                        nsIDOMEvent* aEvent,
-                                                        nsEventStatus* aStatus) = 0;
+                                            mozilla::dom::Event* aEvent,
+                                            nsEventStatus* aStatus) = 0;
 
   /**
    * Return whether or not the event is valid to be dispatched
    */
   virtual bool CanDispatchEvent(
       const mozilla::WidgetGUIEvent* aEvent = nullptr) const = 0;
 
   /**