[Bug 857884] Use dom::EventTarget more instead of nsIDOMEventTarget Part 5 r=Ms2ger

This commit is contained in:
David Zbarsky 2013-04-19 00:48:02 -04:00
Родитель ba6096be66
Коммит 1d6bf834be
14 изменённых файлов: 79 добавлений и 85 удалений

Просмотреть файл

@ -20,6 +20,7 @@
#include "nsCURILoader.h"
#include "nsDocShellLoadTypes.h"
#include "nsDOMEvent.h"
#include "nsIChannel.h"
#include "nsIContentViewer.h"
#include "nsIDOMDocument.h"
@ -252,10 +253,8 @@ 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;

Просмотреть файл

@ -27,6 +27,8 @@
#include "nsXULTemplateResultXML.h"
#include "nsXULSortService.h"
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS1(nsXMLQuery, nsXMLQuery)
//----------------------------------------------------------------------
@ -175,7 +177,7 @@ nsXULTemplateQueryProcessorXML::GetDatasource(nsIArray* aDataSources,
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);
@ -184,7 +186,7 @@ nsXULTemplateQueryProcessorXML::GetDatasource(nsIArray* aDataSources,
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);

Просмотреть файл

@ -1787,11 +1787,11 @@ 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;
@ -1801,8 +1801,8 @@ 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;
}

Просмотреть файл

@ -751,7 +751,7 @@ protected:
// For that reasons don't use nsCOMPtr.
nsIDocShellTreeOwner * mTreeOwner; // Weak Reference
nsIDOMEventTarget * mChromeEventHandler; //Weak Reference
mozilla::dom::EventTarget* mChromeEventHandler; //Weak Reference
eCharsetReloadState mCharsetReloadState;

Просмотреть файл

@ -8,6 +8,7 @@
#include "nsImageMap.h"
#include "nsString.h"
#include "nsDOMEvent.h"
#include "nsReadableUtils.h"
#include "nsRenderingContext.h"
#include "nsPresContext.h"
@ -969,23 +970,22 @@ nsImageMap::HandleEvent(nsIDOMEvent* aEvent)
"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;

Просмотреть файл

@ -343,7 +343,7 @@ nsPrintEngine::InstallPrintPreviewListener()
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();
}

Просмотреть файл

@ -7,6 +7,7 @@
#include "nsPrintPreviewListener.h"
#include "mozilla/dom/Element.h"
#include "nsDOMEvent.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMElement.h"
@ -19,6 +20,7 @@
#include "nsLiteralString.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS1(nsPrintPreviewListener, nsIDOMEventListener)
@ -26,7 +28,7 @@ NS_IMPL_ISUPPORTS1(nsPrintPreviewListener, nsIDOMEventListener)
//
// nsPrintPreviewListener ctor
//
nsPrintPreviewListener::nsPrintPreviewListener (nsIDOMEventTarget* aTarget)
nsPrintPreviewListener::nsPrintPreviewListener(EventTarget* aTarget)
: mEventTarget(aTarget)
{
NS_ADDREF_THIS();
@ -138,10 +140,8 @@ GetActionForEvent(nsIDOMEvent* aEvent)
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) {
@ -185,5 +185,5 @@ nsPrintPreviewListener::HandleEvent(nsIDOMEvent* aEvent)
break;
}
}
return NS_OK;
return NS_OK;
}

Просмотреть файл

@ -9,7 +9,7 @@
// 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"
@ -28,8 +28,8 @@ 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.
@ -38,7 +38,7 @@ public:
private:
nsCOMPtr<nsIDOMEventTarget> mEventTarget;
nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
}; // class nsPrintPreviewListener

Просмотреть файл

@ -716,7 +716,7 @@ protected:
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;

Просмотреть файл

@ -72,21 +72,19 @@ nsMenuBarFrame::Init(nsIContent* aContent,
// 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

Просмотреть файл

@ -12,6 +12,7 @@
#include "nsMenuBarListener.h"
#include "nsContentUtils.h"
#include "nsIDOMDocument.h"
#include "nsDOMEvent.h"
#include "nsIDOMEvent.h"
#include "nsIDOMXULElement.h"
#include "nsIXULDocument.h"
@ -39,6 +40,7 @@
#include "mozilla/Services.h"
using namespace mozilla;
using namespace mozilla::dom;
const nsNavigationDirection DirectionFromKeyCodeTable[2][6] = {
{
@ -447,11 +449,9 @@ nsXULPopupManager::InitTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup,
*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);
}
}
@ -1597,16 +1597,16 @@ nsXULPopupManager::SetCaptureState(nsIContent* aOldPopup)
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;
}
@ -1634,7 +1634,7 @@ 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;

Просмотреть файл

@ -5,6 +5,7 @@
#include "nsXULTooltipListener.h"
#include "nsDOMEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMXULDocument.h"
@ -31,8 +32,8 @@
#include "mozilla/LookAndFeel.h"
#include "mozilla/dom/Element.h"
using namespace mozilla;
using namespace mozilla::dom;
nsXULTooltipListener* nsXULTooltipListener::mInstance = nullptr;
@ -101,9 +102,8 @@ nsXULTooltipListener::MouseOut(nsIDOMEvent* aEvent)
// 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) {
@ -156,10 +156,8 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aEvent)
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;
@ -176,8 +174,7 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aEvent)
// 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
@ -672,16 +669,14 @@ nsXULTooltipListener::DestroyTooltip()
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;

Просмотреть файл

@ -344,14 +344,13 @@ nsresult nsMenuItemX::DispatchDOMEvent(const nsString &eventName, bool *preventD
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
@ -362,7 +361,7 @@ void nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
inCheckedContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, myGroupName);
if (!myGroupName.Length()) // no groupname, nothing to do
return;
nsCOMPtr<nsIContent> parent = inCheckedContent->GetParent();
if (!parent)
return;

Просмотреть файл

@ -11,6 +11,7 @@
#include "nsObjCExceptions.h"
#include "nsCocoaUtils.h"
#include "nsCocoaWindow.h"
#include "nsDOMEvent.h"
#include "nsGkAtoms.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
@ -18,18 +19,18 @@
#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
@ -41,7 +42,7 @@ void nsMenuUtilsX::DispatchCommandTo(nsIContent* aTargetContent)
false, nullptr))) {
event->SetTrusted(true);
bool dummy;
target->DispatchEvent(event, &dummy);
aTargetContent->DispatchEvent(event, &dummy);
}
}
}