[Bug 857884] Use dom::EventTarget more instead of nsIDOMEventTarget Part 5 r=Ms2ger
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 19 Apr 2013 18:18:32 -0400
changeset 129383 62ec34a45dfdce6853a4c7d0bb268649c84e14c3
parent 129382 16e42f1b8b5833e49e8fc7f21b0c1bdbce172bff
child 129384 dcee2cd3394a2c3e0fbba7304da1abe1a5f7a5b5
push id24572
push userphilringnalda@gmail.com
push dateSun, 21 Apr 2013 16:31:35 +0000
treeherdermozilla-central@a09acc1ed635 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs857884
milestone23.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 857884] Use dom::EventTarget more instead of nsIDOMEventTarget Part 5 r=Ms2ger
accessible/src/base/DocManager.cpp
content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
layout/generic/nsImageMap.cpp
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintPreviewListener.cpp
layout/printing/nsPrintPreviewListener.h
layout/xul/base/public/nsXULPopupManager.h
layout/xul/base/src/nsMenuBarFrame.cpp
layout/xul/base/src/nsXULPopupManager.cpp
layout/xul/base/src/nsXULTooltipListener.cpp
widget/cocoa/nsMenuItemX.mm
widget/cocoa/nsMenuUtilsX.mm
--- a/accessible/src/base/DocManager.cpp
+++ b/accessible/src/base/DocManager.cpp
@@ -15,16 +15,17 @@
 #include "States.h"
 
 #ifdef A11Y_LOG
 #include "Logging.h"
 #endif
 
 #include "nsCURILoader.h"
 #include "nsDocShellLoadTypes.h"
+#include "nsDOMEvent.h"
 #include "nsIChannel.h"
 #include "nsIContentViewer.h"
 #include "nsIDOMDocument.h"
 #include "nsEventListenerManager.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMWindow.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIWebNavigation.h"
@@ -247,20 +248,18 @@ DocManager::OnSecurityChange(nsIWebProgr
 // nsIDOMEventListener
 
 NS_IMETHODIMP
 DocManager::HandleEvent(nsIDOMEvent* aEvent)
 {
   nsAutoString type;
   aEvent->GetType(type);
 
-  nsCOMPtr<nsIDOMEventTarget> target;
-  aEvent->GetTarget(getter_AddRefs(target));
-
-  nsCOMPtr<nsIDocument> document(do_QueryInterface(target));
+  nsCOMPtr<nsIDocument> document =
+    do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
   NS_ASSERTION(document, "pagehide or DOMContentLoaded for non document!");
   if (!document)
     return NS_OK;
 
   if (type.EqualsLiteral("pagehide")) {
     // 'pagehide' event is registered on every DOM document we create an
     // accessible for, process the event for the target. This document
     // accessible and all its sub document accessible are shutdown as result of
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
@@ -22,16 +22,18 @@
 #include "nsPIDOMWindow.h"
 #include "nsXULContentUtils.h"
 #include "nsXMLHttpRequest.h"
 
 #include "nsXULTemplateQueryProcessorXML.h"
 #include "nsXULTemplateResultXML.h"
 #include "nsXULSortService.h"
 
+using namespace mozilla::dom;
+
 NS_IMPL_ISUPPORTS1(nsXMLQuery, nsXMLQuery)
 
 //----------------------------------------------------------------------
 //
 // nsXULTemplateResultSetXML
 //
 
 NS_IMPL_ISUPPORTS1(nsXULTemplateResultSetXML, nsISimpleEnumerator)
@@ -170,26 +172,26 @@ nsXULTemplateQueryProcessorXML::GetDatas
 
     nsIScriptContext *context = scriptObject->GetContext();
     NS_ENSURE_TRUE(context, NS_OK);
 
     nsCOMPtr<nsIXMLHttpRequest> req =
         do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = req->Init(docPrincipal, context, 
+    rv = req->Init(docPrincipal, context,
                    scriptObject ? scriptObject : doc->GetScopeObject(),
                    nullptr);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = req->Open(NS_LITERAL_CSTRING("GET"), uriStr, true,
                    EmptyString(), EmptyString());
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(req));
+    nsCOMPtr<EventTarget> target(do_QueryInterface(req));
     rv = target->AddEventListener(NS_LITERAL_STRING("load"), this, false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = target->AddEventListener(NS_LITERAL_STRING("error"), this, false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = req->Send(nullptr);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -1782,32 +1782,32 @@ nsDocShell::GetContentViewer(nsIContentV
     NS_IF_ADDREF(*aContentViewer);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetChromeEventHandler(nsIDOMEventTarget* aChromeEventHandler)
 {
     // Weak reference. Don't addref.
-    mChromeEventHandler = aChromeEventHandler;
     nsCOMPtr<EventTarget> handler = do_QueryInterface(aChromeEventHandler);
+    mChromeEventHandler = handler.get();
 
     if (mScriptGlobal) {
-        mScriptGlobal->SetChromeEventHandler(handler);
+        mScriptGlobal->SetChromeEventHandler(mChromeEventHandler);
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetChromeEventHandler(nsIDOMEventTarget** aChromeEventHandler)
 {
     NS_ENSURE_ARG_POINTER(aChromeEventHandler);
-    nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mChromeEventHandler);
-    target.swap(*aChromeEventHandler);
+    nsCOMPtr<EventTarget> handler = mChromeEventHandler;
+    handler.forget(aChromeEventHandler);
     return NS_OK;
 }
 
 /* void setCurrentURI (in nsIURI uri); */
 NS_IMETHODIMP
 nsDocShell::SetCurrentURI(nsIURI *aURI)
 {
     // Note that securityUI will set STATE_IS_INSECURE, even if
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -746,17 +746,17 @@ protected:
     // Checked in nsMixedContentBlocker, to see if the channels match.
     nsCOMPtr<nsIChannel>       mMixedContentChannel;
 
     // WEAK REFERENCES BELOW HERE.
     // Note these are intentionally not addrefd.  Doing so will create a cycle.
     // For that reasons don't use nsCOMPtr.
 
     nsIDocShellTreeOwner *     mTreeOwner; // Weak Reference
-    nsIDOMEventTarget *        mChromeEventHandler; //Weak Reference
+    mozilla::dom::EventTarget* mChromeEventHandler; //Weak Reference
 
     eCharsetReloadState        mCharsetReloadState;
 
     // Offset in the parent's child list.
     // -1 if the docshell is added dynamically to the parent shell.
     uint32_t                   mChildOffset;
     uint32_t                   mBusyFlags;
     uint32_t                   mAppType;
--- a/layout/generic/nsImageMap.cpp
+++ b/layout/generic/nsImageMap.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 /* code for HTML client-side image maps */
 
 #include "nsImageMap.h"
 
 #include "nsString.h"
+#include "nsDOMEvent.h"
 #include "nsReadableUtils.h"
 #include "nsRenderingContext.h"
 #include "nsPresContext.h"
 #include "nsIURL.h"
 #include "nsIServiceManager.h"
 #include "nsNetUtil.h"
 #include "nsTextFragment.h"
 #include "mozilla/dom/Element.h"
@@ -964,33 +965,32 @@ nsImageMap::HandleEvent(nsIDOMEvent* aEv
 {
   nsAutoString eventType;
   aEvent->GetType(eventType);
   bool focus = eventType.EqualsLiteral("focus");
   NS_ABORT_IF_FALSE(focus == !eventType.EqualsLiteral("blur"),
                     "Unexpected event type");
 
   //Set which one of our areas changed focus
-  nsCOMPtr<nsIDOMEventTarget> target;
-  if (NS_SUCCEEDED(aEvent->GetTarget(getter_AddRefs(target))) && target) {
-    nsCOMPtr<nsIContent> targetContent(do_QueryInterface(target));
-    if (targetContent) {
-      uint32_t i, n = mAreas.Length();
-      for (i = 0; i < n; i++) {
-        Area* area = mAreas.ElementAt(i);
-        if (area->mArea == targetContent) {
-          //Set or Remove internal focus
-          area->HasFocus(focus);
-          //Now invalidate the rect
-          if (mImageFrame) {
-            mImageFrame->InvalidateFrame();
-          }
-          break;
-        }
+  nsCOMPtr<nsIContent> targetContent = do_QueryInterface(
+    aEvent->InternalDOMEvent()->GetTarget());
+  if (!targetContent) {
+    return NS_OK;
+  }
+  uint32_t i, n = mAreas.Length();
+  for (i = 0; i < n; i++) {
+    Area* area = mAreas.ElementAt(i);
+    if (area->mArea == targetContent) {
+      //Set or Remove internal focus
+      area->HasFocus(focus);
+      //Now invalidate the rect
+      if (mImageFrame) {
+        mImageFrame->InvalidateFrame();
       }
+      break;
     }
   }
   return NS_OK;
 }
 
 void
 nsImageMap::Destroy(void)
 {
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -338,17 +338,17 @@ nsPrintEngine::Cancelled()
 // No return code - if this fails, there isn't much we can do
 void
 nsPrintEngine::InstallPrintPreviewListener()
 {
   if (!mPrt->mPPEventListeners) {
     nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mContainer);
     nsCOMPtr<nsPIDOMWindow> win(do_GetInterface(docShell));
     if (win) {
-      nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(win->GetFrameElementInternal()));
+      nsCOMPtr<EventTarget> target = do_QueryInterface(win->GetFrameElementInternal());
       mPrt->mPPEventListeners = new nsPrintPreviewListener(target);
       mPrt->mPPEventListeners->AddListeners();
     }
   }
 }
 
 //----------------------------------------------------------------------
 nsresult 
--- a/layout/printing/nsPrintPreviewListener.cpp
+++ b/layout/printing/nsPrintPreviewListener.cpp
@@ -2,36 +2,38 @@
  *
  * 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 "nsPrintPreviewListener.h"
 
 #include "mozilla/dom/Element.h"
+#include "nsDOMEvent.h"
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIDOMEvent.h"
 #include "nsIDocument.h"
 #include "nsIDocShell.h"
 #include "nsPresContext.h"
 #include "nsFocusManager.h"
 #include "nsLiteralString.h"
 
 using namespace mozilla;
+using namespace mozilla::dom;
 
 NS_IMPL_ISUPPORTS1(nsPrintPreviewListener, nsIDOMEventListener)
 
 
 //
 // nsPrintPreviewListener ctor
 //
-nsPrintPreviewListener::nsPrintPreviewListener (nsIDOMEventTarget* aTarget)
+nsPrintPreviewListener::nsPrintPreviewListener(EventTarget* aTarget)
   : mEventTarget(aTarget)
 {
   NS_ADDREF_THIS();
 } // ctor
 
 
 //-------------------------------------------------------
 //
@@ -133,20 +135,18 @@ GetActionForEvent(nsIDOMEvent* aEvent)
     }
   }
   return eEventAction_Suppress;
 }
 
 NS_IMETHODIMP
 nsPrintPreviewListener::HandleEvent(nsIDOMEvent* aEvent)
 {
-  nsCOMPtr<nsIDOMEventTarget> target;
-  if (aEvent)
-    aEvent->GetOriginalTarget(getter_AddRefs(target));
-  nsCOMPtr<nsIContent> content(do_QueryInterface(target));
+  nsCOMPtr<nsIContent> content = do_QueryInterface(
+    aEvent ? aEvent->InternalDOMEvent()->GetOriginalTarget() : nullptr);
   if (content && !content->IsXUL()) {
     eEventAction action = ::GetActionForEvent(aEvent);
     switch (action) {
       case eEventAction_Tab:
       case eEventAction_ShiftTab:
       {
         nsAutoString eventString;
         aEvent->GetType(eventString);
@@ -180,10 +180,10 @@ nsPrintPreviewListener::HandleEvent(nsID
         aEvent->StopPropagation();
         aEvent->PreventDefault();
         break;
       case eEventAction_Propagate:
         // intentionally empty
         break;
     }
   }
-  return NS_OK; 
+  return NS_OK;
 }
--- a/layout/printing/nsPrintPreviewListener.h
+++ b/layout/printing/nsPrintPreviewListener.h
@@ -4,17 +4,17 @@
  * 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/. */
 
 #ifndef nsPrintPreviewListener_h__
 #define nsPrintPreviewListener_h__
 
 // Interfaces needed to be included
 #include "nsIDOMEventListener.h"
-#include "nsIDOMEventTarget.h"
+#include "mozilla/dom/EventTarget.h"
 // Helper Classes
 #include "nsCOMPtr.h"
 #include "mozilla/Attributes.h"
 
 //
 // class nsPrintPreviewListener
 //
 // The class that listens to the chrome events and tells the embedding
@@ -23,25 +23,25 @@
 // RemoveChromeListeners().
 //
 class nsPrintPreviewListener MOZ_FINAL : public nsIDOMEventListener
 
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
-  
-  nsPrintPreviewListener(nsIDOMEventTarget* aTarget);
+
+  nsPrintPreviewListener(mozilla::dom::EventTarget* aTarget);
 
   // Add/remove the relevant listeners, based on what interfaces
   // the embedding chrome implements.
   nsresult AddListeners();
   nsresult RemoveListeners();
 
 private:
 
-  nsCOMPtr<nsIDOMEventTarget> mEventTarget;
+  nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
 
 }; // class nsPrintPreviewListener
 
 
 
 #endif /* nsPrintPreviewListener_h__ */
--- a/layout/xul/base/public/nsXULPopupManager.h
+++ b/layout/xul/base/public/nsXULPopupManager.h
@@ -711,17 +711,17 @@ protected:
   void UpdateKeyboardListeners();
 
   /*
    * Returns true if the docshell for aDoc is aExpected or a child of aExpected.
    */
   bool IsChildOfDocShell(nsIDocument* aDoc, nsIDocShellTreeItem* aExpected);
 
   // the document the key event listener is attached to
-  nsCOMPtr<nsIDOMEventTarget> mKeyListener;
+  nsCOMPtr<mozilla::dom::EventTarget> mKeyListener;
 
   // widget that is currently listening to rollup events
   nsCOMPtr<nsIWidget> mWidget;
 
   // range parent and offset set in SetTriggerEvent
   nsCOMPtr<nsIDOMNode> mRangeParent;
   int32_t mRangeOffset;
   // Device pixels relative to the showing popup's presshell's
--- a/layout/xul/base/src/nsMenuBarFrame.cpp
+++ b/layout/xul/base/src/nsMenuBarFrame.cpp
@@ -67,31 +67,29 @@ nsMenuBarFrame::Init(nsIContent*      aC
   nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
 
   // Create the menu bar listener.
   mMenuBarListener = new nsMenuBarListener(this);
   NS_ADDREF(mMenuBarListener);
 
   // Hook up the menu bar as a key listener on the whole document.  It will see every
   // key press that occurs, but after everyone else does.
-  nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aContent->GetDocument());
-  
-  mTarget = target;
+  mTarget = aContent->GetDocument();
 
   // Also hook up the listener to the window listening for focus events. This is so we can keep proper
   // state as the user alt-tabs through processes.
-  
-  target->AddEventListener(NS_LITERAL_STRING("keypress"), mMenuBarListener, false); 
-  target->AddEventListener(NS_LITERAL_STRING("keydown"), mMenuBarListener, false);  
-  target->AddEventListener(NS_LITERAL_STRING("keyup"), mMenuBarListener, false);   
+
+  mTarget->AddEventListener(NS_LITERAL_STRING("keypress"), mMenuBarListener, false);
+  mTarget->AddEventListener(NS_LITERAL_STRING("keydown"), mMenuBarListener, false);
+  mTarget->AddEventListener(NS_LITERAL_STRING("keyup"), mMenuBarListener, false);
 
   // mousedown event should be handled in all phase
-  target->AddEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, true);
-  target->AddEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, false);
-  target->AddEventListener(NS_LITERAL_STRING("blur"), mMenuBarListener, true);   
+  mTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, true);
+  mTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, false);
+  mTarget->AddEventListener(NS_LITERAL_STRING("blur"), mMenuBarListener, true);
 }
 
 NS_IMETHODIMP
 nsMenuBarFrame::SetActive(bool aActiveFlag)
 {
   // If the activity is not changed, there is nothing to do.
   if (mIsActive == aActiveFlag)
     return NS_OK;
--- a/layout/xul/base/src/nsXULPopupManager.cpp
+++ b/layout/xul/base/src/nsXULPopupManager.cpp
@@ -7,16 +7,17 @@
 #include "nsXULPopupManager.h"
 #include "nsMenuFrame.h"
 #include "nsMenuPopupFrame.h"
 #include "nsMenuBarFrame.h"
 #include "nsIPopupBoxObject.h"
 #include "nsMenuBarListener.h"
 #include "nsContentUtils.h"
 #include "nsIDOMDocument.h"
+#include "nsDOMEvent.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMXULElement.h"
 #include "nsIXULDocument.h"
 #include "nsIXULTemplateBuilder.h"
 #include "nsEventDispatcher.h"
 #include "nsEventStateManager.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsLayoutUtils.h"
@@ -34,16 +35,17 @@
 #include "nsPIWindowRoot.h"
 #include "nsFrameManager.h"
 #include "nsIObserverService.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Services.h"
 
 using namespace mozilla;
+using namespace mozilla::dom;
 
 const nsNavigationDirection DirectionFromKeyCodeTable[2][6] = {
   {
     eNavigationDirection_Last,   // NS_VK_END
     eNavigationDirection_First,  // NS_VK_HOME
     eNavigationDirection_Start,  // NS_VK_LEFT
     eNavigationDirection_Before, // NS_VK_UP
     eNavigationDirection_End,    // NS_VK_RIGHT
@@ -442,21 +444,19 @@ nsXULPopupManager::InitTriggerEvent(nsID
                                     nsIContent** aTriggerContent)
 {
   mCachedMousePoint = nsIntPoint(0, 0);
 
   if (aTriggerContent) {
     *aTriggerContent = nullptr;
     if (aEvent) {
       // get the trigger content from the event
-      nsCOMPtr<nsIDOMEventTarget> target;
-      aEvent->GetTarget(getter_AddRefs(target));
-      if (target) {
-        CallQueryInterface(target, aTriggerContent);
-      }
+      nsCOMPtr<nsIContent> target = do_QueryInterface(
+        aEvent->InternalDOMEvent()->GetTarget());
+      target.forget(aTriggerContent);
     }
   }
 
   mCachedModifiers = 0;
 
   nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aEvent);
   if (uiEvent) {
     uiEvent->GetRangeParent(getter_AddRefs(mRangeParent));
@@ -1592,26 +1592,26 @@ nsXULPopupManager::SetCaptureState(nsICo
   }
 
   UpdateKeyboardListeners();
 }
 
 void
 nsXULPopupManager::UpdateKeyboardListeners()
 {
-  nsCOMPtr<nsIDOMEventTarget> newTarget;
+  nsCOMPtr<EventTarget> newTarget;
   bool isForMenu = false;
   nsMenuChainItem* item = GetTopVisibleMenu();
   if (item) {
     if (!item->IgnoreKeys())
-      newTarget = do_QueryInterface(item->Content()->GetDocument());
+      newTarget = item->Content()->GetDocument();
     isForMenu = item->PopupType() == ePopupTypeMenu;
   }
   else if (mActiveMenuBar) {
-    newTarget = do_QueryInterface(mActiveMenuBar->GetContent()->GetDocument());
+    newTarget = mActiveMenuBar->GetContent()->GetDocument();
     isForMenu = true;
   }
 
   if (mKeyListener != newTarget) {
     if (mKeyListener) {
       mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, true);
       mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keydown"), this, true);
       mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keyup"), this, true);
@@ -1629,17 +1629,17 @@ nsXULPopupManager::UpdateKeyboardListene
   }
 }
 
 void
 nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup)
 {
   // Walk all of the menu's children, checking to see if any of them has a
   // command attribute. If so, then several attributes must potentially be updated.
- 
+
   nsCOMPtr<nsIDocument> document = aPopup->GetCurrentDoc();
   if (!document) {
     return;
   }
 
   for (nsCOMPtr<nsIContent> grandChild = aPopup->GetFirstChild();
        grandChild;
        grandChild = grandChild->GetNextSibling()) {
--- a/layout/xul/base/src/nsXULTooltipListener.cpp
+++ b/layout/xul/base/src/nsXULTooltipListener.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; 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 "nsXULTooltipListener.h"
 
+#include "nsDOMEvent.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMXULDocument.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDocument.h"
 #include "nsGkAtoms.h"
 #include "nsIPopupBoxObject.h"
 #include "nsMenuPopupFrame.h"
@@ -26,18 +27,18 @@
 #include "nsXULPopupManager.h"
 #endif
 #include "nsIRootBox.h"
 #include "nsEventDispatcher.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/dom/Element.h"
 
-
 using namespace mozilla;
+using namespace mozilla::dom;
 
 nsXULTooltipListener* nsXULTooltipListener::mInstance = nullptr;
 
 //////////////////////////////////////////////////////////////////////////
 //// nsISupports
 
 nsXULTooltipListener::nsXULTooltipListener()
   : mMouseScreenX(0)
@@ -96,19 +97,18 @@ nsXULTooltipListener::MouseOut(nsIDOMEve
     return;
 #endif
 
 #ifdef MOZ_XUL
   // check to see if the mouse left the targetNode, and if so,
   // hide the tooltip
   if (currentTooltip) {
     // which node did the mouse leave?
-    nsCOMPtr<nsIDOMEventTarget> eventTarget;
-    aEvent->GetTarget(getter_AddRefs(eventTarget));
-    nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(eventTarget));
+    nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(
+      aEvent->InternalDOMEvent()->GetTarget());
 
     nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
     if (pm) {
       nsCOMPtr<nsIDOMNode> tooltipNode =
         pm->GetLastTriggerTooltipNode(currentTooltip->GetCurrentDoc());
       if (tooltipNode == targetNode) {
         // if the target node is the current tooltip target node, the mouse
         // left the node the tooltip appeared on, so close the tooltip.
@@ -151,38 +151,35 @@ nsXULTooltipListener::MouseMove(nsIDOMEv
 
   if ((currentTooltip) &&
       (abs(mMouseScreenX - newMouseX) <= kTooltipMouseMoveTolerance) &&
       (abs(mMouseScreenY - newMouseY) <= kTooltipMouseMoveTolerance))
     return;
   mMouseScreenX = newMouseX;
   mMouseScreenY = newMouseY;
 
-  nsCOMPtr<nsIDOMEventTarget> currentTarget;
-  aEvent->GetCurrentTarget(getter_AddRefs(currentTarget));
-
-  nsCOMPtr<nsIContent> sourceContent = do_QueryInterface(currentTarget);
+  nsCOMPtr<nsIContent> sourceContent = do_QueryInterface(
+    aEvent->InternalDOMEvent()->GetCurrentTarget());
   mSourceNode = do_GetWeakReference(sourceContent);
 #ifdef MOZ_XUL
   mIsSourceTree = sourceContent->Tag() == nsGkAtoms::treechildren;
   if (mIsSourceTree)
     CheckTreeBodyMove(mouseEvent);
 #endif
 
   // as the mouse moves, we want to make sure we reset the timer to show it, 
   // so that the delay is from when the mouse stops moving, not when it enters
   // the node.
   KillTooltipTimer();
 
   // If the mouse moves while the tooltip is up, hide it. If nothing is
   // showing and the tooltip hasn't been displayed since the mouse entered
   // the node, then start the timer to show the tooltip.
   if (!currentTooltip && !mTooltipShownOnce) {
-    nsCOMPtr<nsIDOMEventTarget> eventTarget;
-    aEvent->GetTarget(getter_AddRefs(eventTarget));
+    nsCOMPtr<EventTarget> eventTarget = aEvent->InternalDOMEvent()->GetTarget();
 
     // don't show tooltips attached to elements outside of a menu popup
     // when hovering over an element inside it. The popupsinherittooltip
     // attribute may be used to disable this behaviour, which is useful for
     // large menu hierarchies such as bookmarks.
     if (!sourceContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::popupsinherittooltip,
                                     nsGkAtoms::_true, eCaseMatters)) {
       nsCOMPtr<nsIContent> targetContent = do_QueryInterface(eventTarget);
@@ -667,26 +664,24 @@ nsXULTooltipListener::DestroyTooltip()
       doc->RemoveSystemEventListener(NS_LITERAL_STRING("DOMMouseScroll"), this,
                                      true);
       doc->RemoveSystemEventListener(NS_LITERAL_STRING("mousedown"), this,
                                      true);
       doc->RemoveSystemEventListener(NS_LITERAL_STRING("mouseup"), this, true);
       doc->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"), this, true);
     }
 
-    // remove the popuphidden listener from tooltip
-    nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(currentTooltip));
-
     // release tooltip before removing listener to prevent our destructor from
     // being called recursively (bug 120863)
     mCurrentTooltip = nullptr;
 
-    evtTarget->RemoveEventListener(NS_LITERAL_STRING("popuphiding"), this, false);
+    // remove the popuphidden listener from tooltip
+    currentTooltip->RemoveEventListener(NS_LITERAL_STRING("popuphiding"), this, false);
   }
-  
+
   // kill any ongoing timers
   KillTooltipTimer();
   mSourceNode = nullptr;
 #ifdef MOZ_XUL
   mLastTreeCol = nullptr;
 #endif
 
   return NS_OK;
--- a/widget/cocoa/nsMenuItemX.mm
+++ b/widget/cocoa/nsMenuItemX.mm
@@ -339,35 +339,34 @@ nsresult nsMenuItemX::DispatchDOMEvent(c
     return rv;
   }
   event->InitEvent(eventName, true, true);
 
   // mark DOM event as trusted
   event->SetTrusted(true);
 
   // send DOM event
-  nsCOMPtr<nsIDOMEventTarget> eventTarget = do_QueryInterface(mContent);
-  rv = eventTarget->DispatchEvent(event, preventDefaultCalled);
+  rv = mContent->DispatchEvent(event, preventDefaultCalled);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to send DOM event via nsIDOMEventTarget");
     return rv;
   }
 
-  return NS_OK;  
+  return NS_OK;
 }
 
 // Walk the sibling list looking for nodes with the same name and
 // uncheck them all.
 void nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
 {
   nsAutoString myGroupName;
   inCheckedContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, myGroupName);
   if (!myGroupName.Length()) // no groupname, nothing to do
     return;
-  
+
   nsCOMPtr<nsIContent> parent = inCheckedContent->GetParent();
   if (!parent)
     return;
 
   // loop over siblings
   uint32_t count = parent->GetChildCount();
   for (uint32_t i = 0; i < count; i++) {
     nsIContent *sibling = parent->GetChildAt(i);
--- a/widget/cocoa/nsMenuUtilsX.mm
+++ b/widget/cocoa/nsMenuUtilsX.mm
@@ -6,47 +6,48 @@
 #include "nsMenuUtilsX.h"
 #include "nsMenuBarX.h"
 #include "nsMenuX.h"
 #include "nsMenuItemX.h"
 #include "nsStandaloneNativeMenu.h"
 #include "nsObjCExceptions.h"
 #include "nsCocoaUtils.h"
 #include "nsCocoaWindow.h"
+#include "nsDOMEvent.h"
 #include "nsGkAtoms.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMXULCommandEvent.h"
 #include "nsPIDOMWindow.h"
 
+using namespace mozilla;
+
 void nsMenuUtilsX::DispatchCommandTo(nsIContent* aTargetContent)
 {
   NS_PRECONDITION(aTargetContent, "null ptr");
 
   nsIDocument* doc = aTargetContent->OwnerDoc();
-  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
-  nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aTargetContent);
-  if (domDoc && target) {
-    nsCOMPtr<nsIDOMEvent> event;
-    domDoc->CreateEvent(NS_LITERAL_STRING("xulcommandevent"),
-                        getter_AddRefs(event));
-    nsCOMPtr<nsIDOMXULCommandEvent> command = do_QueryInterface(event);
+  if (doc) {
+    ErrorResult rv;
+    nsRefPtr<nsDOMEvent> event =
+      doc->CreateEvent(NS_LITERAL_STRING("xulcommandevent"), rv);
+    nsCOMPtr<nsIDOMXULCommandEvent> command = do_QueryObject(event);
 
     // FIXME: Should probably figure out how to init this with the actual
     // pressed keys, but this is a big old edge case anyway. -dwh
     if (command &&
         NS_SUCCEEDED(command->InitCommandEvent(NS_LITERAL_STRING("command"),
                                                true, true,
                                                doc->GetWindow(), 0,
                                                false, false, false,
                                                false, nullptr))) {
       event->SetTrusted(true);
       bool dummy;
-      target->DispatchEvent(event, &dummy);
+      aTargetContent->DispatchEvent(event, &dummy);
     }
   }
 }
 
 NSString* nsMenuUtilsX::GetTruncatedCocoaLabel(const nsString& itemLabel)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;