Bug 915757: Split GetListenerManager into two functions for more const-correctness. r=smaug

This commit is contained in:
Kyle Huey 2013-10-14 11:10:44 +08:00
parent 40ab109140
commit d9a28b7f74
44 changed files with 264 additions and 155 deletions

View File

@ -329,7 +329,7 @@ DocManager::AddListeners(nsIDocument* aDocument,
{
nsPIDOMWindow* window = aDocument->GetWindow();
EventTarget* target = window->GetChromeEventHandler();
nsEventListenerManager* elm = target->GetListenerManager(true);
nsEventListenerManager* elm = target->GetOrCreateListenerManager();
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
dom::TrustedEventsAtCapture());
@ -359,7 +359,7 @@ DocManager::RemoveListeners(nsIDocument* aDocument)
if (!target)
return;
nsEventListenerManager* elm = target->GetListenerManager(true);
nsEventListenerManager* elm = target->GetOrCreateListenerManager();
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
dom::TrustedEventsAtCapture());

View File

@ -46,7 +46,7 @@ nsCoreUtils::HasClickListener(nsIContent *aContent)
{
NS_ENSURE_TRUE(aContent, false);
nsEventListenerManager* listenerManager =
aContent->GetListenerManager(false);
aContent->GetExistingListenerManager();
return listenerManager &&
(listenerManager->HasListenersFor(nsGkAtoms::onclick) ||

View File

@ -1060,15 +1060,19 @@ public:
nsCycleCollectionTraversalCallback &cb);
/**
* Get the eventlistener manager for aNode. If a new eventlistener manager
* was created, aCreated is set to true.
* Get the eventlistener manager for aNode, creating it if it does not
* already exist.
*
* @param aNode The node for which to get the eventlistener manager.
* @param aCreateIfNotFound If false, returns a listener manager only if
* one already exists.
*/
static nsEventListenerManager* GetListenerManager(nsINode* aNode,
bool aCreateIfNotFound);
static nsEventListenerManager* GetListenerManagerForNode(nsINode* aNode);
/**
* Get the eventlistener manager for aNode, returning null if it does not
* already exist.
*
* @param aNode The node for which to get the eventlistener manager.
*/
static nsEventListenerManager* GetExistingListenerManagerForNode(const nsINode* aNode);
static void UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration);

View File

@ -800,6 +800,12 @@ public:
* See nsIDOMEventTarget
*/
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
using nsIDOMEventTarget::AddEventListener;
virtual void AddEventListener(const nsAString& aType,

View File

@ -1810,7 +1810,7 @@ Element::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
bool* aDefer)
{
*aDefer = true;
return GetListenerManager(true);
return GetOrCreateListenerManager();
}
Element::nsAttrInfo

View File

@ -1225,7 +1225,7 @@ FragmentOrElement::MarkNodeChildren(nsINode* aNode)
JS::ExposeObjectToActiveJS(o);
}
nsEventListenerManager* elm = aNode->GetListenerManager(false);
nsEventListenerManager* elm = aNode->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}

View File

@ -144,7 +144,7 @@ MarkMessageManagers()
continue;
}
static_cast<nsInProcessTabChildGlobal*>(et)->MarkForCC();
nsEventListenerManager* elm = et->GetListenerManager(false);
nsEventListenerManager* elm = et->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}
@ -188,13 +188,13 @@ MarkContentViewer(nsIContentViewer* aViewer, bool aCleanupJS,
doc->GetMarkedCCGeneration() != nsCCUncollectableMarker::sGeneration) {
doc->MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration);
if (aCleanupJS) {
nsEventListenerManager* elm = doc->GetListenerManager(false);
nsEventListenerManager* elm = doc->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}
nsCOMPtr<EventTarget> win = do_QueryInterface(doc->GetInnerWindow());
if (win) {
elm = win->GetListenerManager(false);
elm = win->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}

View File

@ -3630,7 +3630,7 @@ nsContentUtils::HasMutationListeners(nsINode* aNode,
if (aNode->IsInDoc()) {
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(window));
if (piTarget) {
nsEventListenerManager* manager = piTarget->GetListenerManager(false);
nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
if (manager && manager->HasMutationListeners()) {
return true;
}
@ -3641,7 +3641,7 @@ nsContentUtils::HasMutationListeners(nsINode* aNode,
// might not be in our chain. If we don't have a window, we might have a
// mutation listener. Check quickly to see.
while (aNode) {
nsEventListenerManager* manager = aNode->GetListenerManager(false);
nsEventListenerManager* manager = aNode->GetExistingListenerManager();
if (manager && manager->HasMutationListeners()) {
return true;
}
@ -3763,13 +3763,8 @@ nsContentUtils::TraverseListenerManager(nsINode *aNode,
}
nsEventListenerManager*
nsContentUtils::GetListenerManager(nsINode *aNode,
bool aCreateIfNotFound)
nsContentUtils::GetListenerManagerForNode(nsINode *aNode)
{
if (!aCreateIfNotFound && !aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
return nullptr;
}
if (!sEventListenerManagersHash.ops) {
// We're already shut down, don't bother creating an event listener
// manager.
@ -3777,17 +3772,6 @@ nsContentUtils::GetListenerManager(nsINode *aNode,
return nullptr;
}
if (!aCreateIfNotFound) {
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
return entry->mListenerManager;
}
return nullptr;
}
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
@ -3806,6 +3790,31 @@ nsContentUtils::GetListenerManager(nsINode *aNode,
return entry->mListenerManager;
}
nsEventListenerManager*
nsContentUtils::GetExistingListenerManagerForNode(const nsINode *aNode)
{
if (!aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
return nullptr;
}
if (!sEventListenerManagersHash.ops) {
// We're already shut down, don't bother creating an event listener
// manager.
return nullptr;
}
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
return entry->mListenerManager;
}
return nullptr;
}
/* static */
void
nsContentUtils::RemoveListenerManager(nsINode *aNode)

View File

@ -1659,7 +1659,7 @@ nsDocument::DeleteCycleCollectable()
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument)
if (Element::CanSkip(tmp, aRemovingAllowed)) {
nsEventListenerManager* elm = tmp->GetListenerManager(false);
nsEventListenerManager* elm = tmp->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}
@ -6966,9 +6966,9 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
}
nsEventListenerManager*
nsDocument::GetListenerManager(bool aCreateIfNotFound)
nsDocument::GetOrCreateListenerManager()
{
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this));
SetFlags(NODE_HAS_LISTENERMANAGER);
@ -6977,6 +6977,12 @@ nsDocument::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager;
}
nsEventListenerManager*
nsDocument::GetExistingListenerManager() const
{
return mListenerManager;
}
nsresult
nsDocument::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{
@ -7670,8 +7676,7 @@ nsDocument::CanSavePresentation(nsIRequest *aNewRequest)
// Check our event listener manager for unload/beforeunload listeners.
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(mScriptGlobalObject);
if (piTarget) {
nsEventListenerManager* manager =
piTarget->GetListenerManager(false);
nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
if (manager && manager->HasUnloadListeners()) {
return false;
}

View File

@ -773,8 +773,8 @@ public:
// nsIDOMEventTarget
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetListenerManager(bool aCreateIfNotFound) MOZ_OVERRIDE;
virtual nsEventListenerManager* GetOrCreateListenerManager() MOZ_OVERRIDE;
virtual nsEventListenerManager* GetExistingListenerManager() const MOZ_OVERRIDE;
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE;

View File

@ -1038,7 +1038,7 @@ nsINode::AddEventListener(const nsAString& aType,
aWantsUntrusted = true;
}
nsEventListenerManager* listener_manager = GetListenerManager(true);
nsEventListenerManager* listener_manager = GetOrCreateListenerManager();
NS_ENSURE_STATE(listener_manager);
listener_manager->AddEventListener(aType, aListener, aUseCapture,
aWantsUntrusted);
@ -1059,7 +1059,7 @@ nsINode::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value();
}
nsEventListenerManager* listener_manager = GetListenerManager(true);
nsEventListenerManager* listener_manager = GetOrCreateListenerManager();
if (!listener_manager) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -1095,7 +1095,7 @@ nsINode::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
@ -1157,9 +1157,15 @@ nsINode::DispatchDOMEvent(WidgetEvent* aEvent,
}
nsEventListenerManager*
nsINode::GetListenerManager(bool aCreateIfNotFound)
nsINode::GetOrCreateListenerManager()
{
return nsContentUtils::GetListenerManager(this, aCreateIfNotFound);
return nsContentUtils::GetListenerManagerForNode(this);
}
nsEventListenerManager*
nsINode::GetExistingListenerManager() const
{
return nsContentUtils::GetExistingListenerManagerForNode(this);
}
nsIScriptContext*
@ -2164,8 +2170,7 @@ size_t
nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = 0;
nsEventListenerManager* elm =
const_cast<nsINode*>(this)->GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
n += elm->SizeOfIncludingThis(aMallocSizeOf);
}
@ -2183,13 +2188,13 @@ nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
#define EVENT(name_, id_, type_, struct_) \
EventHandlerNonNull* nsINode::GetOn##name_() { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \
} \
void nsINode::SetOn##name_(EventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \
} \

View File

@ -231,7 +231,7 @@ nsNodeUtils::LastRelease(nsINode* aNode)
#ifdef DEBUG
if (nsContentUtils::IsInitialized()) {
nsEventListenerManager* manager =
nsContentUtils::GetListenerManager(aNode, false);
nsContentUtils::GetExistingListenerManagerForNode(aNode);
if (!manager) {
NS_ERROR("Huh, our bit says we have a listener manager list, "
"but there's nothing in the hash!?!!");
@ -480,7 +480,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
nsPIDOMWindow* window = newDoc->GetInnerWindow();
if (window) {
nsEventListenerManager* elm = aNode->GetListenerManager(false);
nsEventListenerManager* elm = aNode->GetExistingListenerManager();
if (elm) {
window->SetMutationListeners(elm->MutationListenerBits());
if (elm->MayHavePaintEventListener()) {

View File

@ -2172,7 +2172,8 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
NS_ASSERTION(!(mState & XML_HTTP_REQUEST_SYNCLOOPING),
"We weren't supposed to support HTML parsing with XHR!");
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(mResponseXML);
nsEventListenerManager* manager = eventTarget->GetListenerManager(true);
nsEventListenerManager* manager =
eventTarget->GetOrCreateListenerManager();
manager->AddEventListenerByType(new nsXHRParseEndListener(this),
NS_LITERAL_STRING("DOMContentLoaded"),
dom::TrustedEventsAtSystemGroupBubble());

View File

@ -26,8 +26,8 @@ template <class T> struct Nullable;
// IID for the dom::EventTarget interface
#define NS_EVENTTARGET_IID \
{ 0x0a5aed21, 0x0bab, 0x48b3, \
{ 0xbe, 0x4b, 0xd4, 0xf9, 0xd4, 0xea, 0xc7, 0xdb } }
{ 0xce3817d0, 0x177b, 0x402f, \
{ 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
class EventTarget : public nsIDOMEventTarget,
public nsWrapperCache
@ -70,6 +70,17 @@ public:
// current inner or if there is no window around at all.
virtual nsIDOMWindow* GetOwnerGlobal() = 0;
/**
* Get the event listener manager, creating it if it does not already exist.
*/
virtual nsEventListenerManager* GetOrCreateListenerManager() = 0;
/**
* Get the event listener manager, returning null if it does not already
* exist.
*/
virtual nsEventListenerManager* GetExistingListenerManager() const = 0;
protected:
EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
const nsAString& aTypeString);

View File

@ -16,7 +16,7 @@ EventTarget::RemoveEventListener(const nsAString& aType,
bool aUseCapture,
ErrorResult& aRv)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
@ -25,7 +25,7 @@ EventTarget::RemoveEventListener(const nsAString& aType,
EventHandlerNonNull*
EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
}
@ -52,7 +52,7 @@ void
EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
EventHandlerNonNull* aHandler)
{
GetListenerManager(true)->SetEventHandler(aType, aTypeString, aHandler);
GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
}
} // namespace dom

View File

@ -154,7 +154,7 @@ nsDOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
@ -181,7 +181,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
NS_ENSURE_SUCCESS(rv, rv);
}
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
NS_ENSURE_STATE(elm);
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK;
@ -205,7 +205,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value();
}
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -319,15 +319,21 @@ nsDOMEventTargetHelper::DispatchDOMEvent(WidgetEvent* aEvent,
}
nsEventListenerManager*
nsDOMEventTargetHelper::GetListenerManager(bool aCreateIfNotFound)
nsDOMEventTargetHelper::GetOrCreateListenerManager()
{
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager = new nsEventListenerManager(this);
}
return mListenerManager;
}
nsEventListenerManager*
nsDOMEventTargetHelper::GetExistingListenerManager() const
{
return mListenerManager;
}
nsIScriptContext*
nsDOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv)
{

View File

@ -44,6 +44,12 @@ public:
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper)
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,
@ -219,8 +225,11 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
virtual nsresult DispatchDOMEvent(mozilla::WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent, nsPresContext* aPresContext, nsEventStatus* aEventStatus) { \
return _to DispatchDOMEvent(aEvent, aDOMEvent, aPresContext, aEventStatus); \
} \
virtual nsEventListenerManager * GetListenerManager(bool aMayCreate) { \
return _to GetListenerManager(aMayCreate); \
virtual nsEventListenerManager * GetOrCreateListenerManager() { \
return _to GetOrCreateListenerManager(); \
} \
virtual nsEventListenerManager * GetExistingListenerManager() const { \
return _to GetExistingListenerManager(); \
} \
virtual nsIScriptContext * GetContextForEventHandlers(nsresult *aRv) { \
return _to GetContextForEventHandlers(aRv); \
@ -232,6 +241,14 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
#define NS_REALLY_FORWARD_NSIDOMEVENTTARGET(_class) \
using _class::AddEventListener; \
using _class::RemoveEventListener; \
NS_FORWARD_NSIDOMEVENTTARGET(_class::)
NS_FORWARD_NSIDOMEVENTTARGET(_class::) \
virtual nsEventListenerManager* \
GetOrCreateListenerManager() { \
return _class::GetOrCreateListenerManager(); \
} \
virtual nsEventListenerManager* \
GetExistingListenerManager() const { \
return _class::GetExistingListenerManager(); \
}
#endif // nsDOMEventTargetHelper_h_

View File

@ -185,8 +185,7 @@ public:
if (!MayHaveListenerManager() && !aCd.MayHaveNewListenerManager()) {
return NS_OK;
}
mManager =
static_cast<nsEventListenerManager*>(mTarget->GetListenerManager(false));
mManager = mTarget->GetExistingListenerManager();
}
if (mManager) {
NS_ASSERTION(aVisitor.mEvent->currentTarget == nullptr,

View File

@ -560,7 +560,8 @@ NS_AddSystemEventListener(mozilla::dom::EventTarget* aTarget,
bool aUseCapture,
bool aWantsUntrusted)
{
nsEventListenerManager* listenerManager = aTarget->GetListenerManager(true);
nsEventListenerManager* listenerManager =
aTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(listenerManager);
mozilla::dom::EventListenerFlags flags;
flags.mInSystemGroup = true;

View File

@ -162,8 +162,11 @@ nsEventListenerService::GetListenerInfoFor(nsIDOMEventTarget* aEventTarget,
*aCount = 0;
*aOutArray = nullptr;
nsCOMArray<nsIEventListenerInfo> listenerInfos;
nsEventListenerManager* elm =
aEventTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aEventTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* elm = eventTarget->GetExistingListenerManager();
if (elm) {
elm->GetListenerInfo(&listenerInfos);
}
@ -221,7 +224,10 @@ nsEventListenerService::HasListenersFor(nsIDOMEventTarget* aEventTarget,
const nsAString& aType,
bool* aRetVal)
{
nsEventListenerManager* elm = aEventTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aEventTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* elm = eventTarget->GetExistingListenerManager();
*aRetVal = elm && elm->HasListenersFor(aType);
return NS_OK;
}
@ -235,7 +241,10 @@ nsEventListenerService::AddSystemEventListener(nsIDOMEventTarget *aTarget,
NS_PRECONDITION(aTarget, "Missing target");
NS_PRECONDITION(aListener, "Missing listener");
nsEventListenerManager* manager = aTarget->GetListenerManager(true);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(manager);
EventListenerFlags flags =
@ -254,7 +263,10 @@ nsEventListenerService::RemoveSystemEventListener(nsIDOMEventTarget *aTarget,
NS_PRECONDITION(aTarget, "Missing target");
NS_PRECONDITION(aListener, "Missing listener");
nsEventListenerManager* manager = aTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetExistingListenerManager();
if (manager) {
EventListenerFlags flags =
aUseCapture ? TrustedEventsAtSystemGroupCapture() :
@ -273,7 +285,11 @@ nsEventListenerService::AddListenerForAllEvents(nsIDOMEventTarget* aTarget,
bool aSystemEventGroup)
{
NS_ENSURE_STATE(aTarget && aListener);
nsEventListenerManager* manager = aTarget->GetListenerManager(true);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(manager);
manager->AddListenerForAllEvents(aListener, aUseCapture, aWantsUntrusted,
aSystemEventGroup);
@ -287,7 +303,11 @@ nsEventListenerService::RemoveListenerForAllEvents(nsIDOMEventTarget* aTarget,
bool aSystemEventGroup)
{
NS_ENSURE_STATE(aTarget && aListener);
nsEventListenerManager* manager = aTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetExistingListenerManager();
if (manager) {
manager->RemoveListenerForAllEvents(aListener, aUseCapture, aSystemEventGroup);
}

View File

@ -842,7 +842,7 @@ nsGenericHTMLElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
if ((win = document->GetInnerWindow())) {
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(win));
return piTarget->GetListenerManager(true);
return piTarget->GetOrCreateListenerManager();
}
return nullptr;
@ -1009,8 +1009,7 @@ nsGenericHTMLElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
UnsetFlags(NODE_HAS_ACCESSKEY);
}
else if (IsEventAttributeName(aAttribute)) {
nsEventListenerManager* manager = GetListenerManager(false);
if (manager) {
if (nsEventListenerManager* manager = GetExistingListenerManager()) {
manager->RemoveEventHandler(aAttribute, EmptyString());
}
}

View File

@ -1562,8 +1562,7 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
mTextListener->SetFrame(nullptr);
nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
nsEventListenerManager* manager =
target->GetListenerManager(false);
nsEventListenerManager* manager = target->GetExistingListenerManager();
if (manager) {
manager->RemoveEventListenerByType(mTextListener,
NS_LITERAL_STRING("keydown"),
@ -1970,7 +1969,7 @@ nsTextEditorState::InitializeKeyboardEventListeners()
{
//register key listeners
nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
nsEventListenerManager* manager = target->GetListenerManager(true);
nsEventListenerManager* manager = target->GetOrCreateListenerManager();
if (manager) {
manager->AddEventListenerByType(mTextListener,
NS_LITERAL_STRING("keydown"),

View File

@ -372,7 +372,7 @@ nsSMILTimeValueSpec::GetEventListenerManager(Element* aTarget)
if (!target)
return nullptr;
return target->GetListenerManager(true);
return target->GetOrCreateListenerManager();
}
void

View File

@ -664,7 +664,7 @@ nsSVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsIAtom* aName,
mContentStyleRule = nullptr;
if (IsEventAttributeName(aName)) {
nsEventListenerManager* manager = GetListenerManager(false);
nsEventListenerManager* manager = GetExistingListenerManager();
if (manager) {
nsIAtom* eventName = GetEventNameForAttr(aName);
manager->RemoveEventHandler(eventName, EmptyString());

View File

@ -498,8 +498,7 @@ nsXBLBinding::InstallEventHandlers()
nsXBLPrototypeHandler* handlerChain = mPrototypeBinding->GetPrototypeHandlers();
if (handlerChain) {
nsEventListenerManager* manager =
mBoundElement->GetListenerManager(true);
nsEventListenerManager* manager = mBoundElement->GetOrCreateListenerManager();
if (!manager)
return;
@ -648,7 +647,7 @@ nsXBLBinding::UnhookEventHandlers()
if (handlerChain) {
nsEventListenerManager* manager =
mBoundElement->GetListenerManager(false);
mBoundElement->GetExistingListenerManager();
if (!manager) {
return;
}

View File

@ -561,7 +561,7 @@ nsXBLService::AttachGlobalKeyHandler(EventTarget* aTarget)
piTarget = doc; // We're a XUL keyset. Attach to our document.
}
nsEventListenerManager* manager = piTarget->GetListenerManager(true);
nsEventListenerManager* manager = piTarget->GetOrCreateListenerManager();
if (!piTarget || !manager)
return NS_ERROR_FAILURE;
@ -611,7 +611,7 @@ nsXBLService::DetachGlobalKeyHandler(EventTarget* aTarget)
if (doc)
piTarget = do_QueryInterface(doc);
nsEventListenerManager* manager = piTarget->GetListenerManager(true);
nsEventListenerManager* manager = piTarget->GetOrCreateListenerManager();
if (!piTarget || !manager)
return NS_ERROR_FAILURE;

View File

@ -496,7 +496,7 @@ nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window);
*aDefer = false;
return piTarget->GetListenerManager(true);
return piTarget->GetOrCreateListenerManager();
}
return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer);
@ -1671,7 +1671,7 @@ nsXULElement::AddPopupListener(nsIAtom* aName)
new nsXULPopupListener(this, isContext);
// Add the popup as a listener on this element.
nsEventListenerManager* manager = GetListenerManager(true);
nsEventListenerManager* manager = GetOrCreateListenerManager();
SetFlags(listenerFlag);
if (isContext) {

View File

@ -1570,8 +1570,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGlobalWindow)
if (tmp->mCachedXBLPrototypeHandlers) {
tmp->mCachedXBLPrototypeHandlers->Enumerate(MarkXBLHandlers, nullptr);
}
nsEventListenerManager* elm = tmp->GetListenerManager(false);
if (elm) {
if (nsEventListenerManager* elm = tmp->GetExistingListenerManager()) {
elm->MarkForCC();
}
tmp->UnmarkGrayTimers();
@ -8065,8 +8064,7 @@ nsGlobalWindow::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture)
{
nsRefPtr<nsEventListenerManager> elm = GetListenerManager(false);
if (elm) {
if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
return NS_OK;
@ -8121,7 +8119,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
aWantsUntrusted = true;
}
nsEventListenerManager* manager = GetListenerManager(true);
nsEventListenerManager* manager = GetOrCreateListenerManager();
NS_ENSURE_STATE(manager);
manager->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK;
@ -8147,7 +8145,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value();
}
nsEventListenerManager* manager = GetListenerManager(true);
nsEventListenerManager* manager = GetOrCreateListenerManager();
if (!manager) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -8182,11 +8180,11 @@ nsGlobalWindow::AddSystemEventListener(const nsAString& aType,
}
nsEventListenerManager*
nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound)
nsGlobalWindow::GetOrCreateListenerManager()
{
FORWARD_TO_INNER_CREATE(GetListenerManager, (aCreateIfNotFound), nullptr);
FORWARD_TO_INNER_CREATE(GetOrCreateListenerManager, (), nullptr);
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this));
}
@ -8194,6 +8192,14 @@ nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager;
}
nsEventListenerManager*
nsGlobalWindow::GetExistingListenerManager() const
{
FORWARD_TO_INNER(GetExistingListenerManager, (), nullptr);
return mListenerManager;
}
nsIScriptContext*
nsGlobalWindow::GetContextForEventHandlers(nsresult* aRv)
{
@ -11541,8 +11547,7 @@ nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this);
if (IsInnerWindow()) {
nsEventListenerManager* elm =
const_cast<nsGlobalWindow*>(this)->GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
aWindowSizes->mDOMOther +=
elm->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
@ -12083,7 +12088,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
#define ERROR_EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
JS::Value *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
if (elm) { \
OnErrorEventHandlerNonNull* h = elm->GetOnErrorEventHandler(); \
if (h) { \
@ -12096,7 +12101,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
} \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const JS::Value &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \
} \
@ -12113,7 +12118,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
JS::Value *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
if (elm) { \
BeforeUnloadEventHandlerNonNull* h = \
elm->GetOnBeforeUnloadEventHandler(); \
@ -12127,7 +12132,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
} \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const JS::Value &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \
} \

View File

@ -371,6 +371,13 @@ public:
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,
@ -552,7 +559,7 @@ public:
return static_cast<nsGlobalWindow *>(GetOuterWindow());
}
nsGlobalWindow *GetCurrentInnerWindowInternal()
nsGlobalWindow *GetCurrentInnerWindowInternal() const
{
return static_cast<nsGlobalWindow *>(mInnerWindow);
}
@ -708,13 +715,13 @@ public:
#define EVENT(name_, id_, type_, struct_) \
mozilla::dom::EventHandlerNonNull* GetOn##name_() \
{ \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \
} \
void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \
} \
@ -722,12 +729,12 @@ public:
#define ERROR_EVENT(name_, id_, type_, struct_) \
mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \
{ \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetOnErrorEventHandler() : nullptr; \
} \
void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(handler); \
} \
@ -735,12 +742,12 @@ public:
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
mozilla::dom::BeforeUnloadEventHandlerNonNull* GetOn##name_() \
{ \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
} \
void SetOn##name_(mozilla::dom::BeforeUnloadEventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(handler); \
} \

View File

@ -64,8 +64,7 @@ NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
NS_IMETHODIMP
nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture)
{
nsRefPtr<nsEventListenerManager> elm = GetListenerManager(false);
if (elm) {
if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
return NS_OK;
@ -105,7 +104,7 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
"aWantsUntrusted to false or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
NS_ENSURE_STATE(elm);
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK;
@ -119,7 +118,7 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
ErrorResult& aRv)
{
bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -145,9 +144,9 @@ nsWindowRoot::AddSystemEventListener(const nsAString& aType,
}
nsEventListenerManager*
nsWindowRoot::GetListenerManager(bool aCreateIfNotFound)
nsWindowRoot::GetOrCreateListenerManager()
{
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this));
}
@ -155,6 +154,12 @@ nsWindowRoot::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager;
}
nsEventListenerManager*
nsWindowRoot::GetExistingListenerManager() const
{
return mListenerManager;
}
nsIScriptContext*
nsWindowRoot::GetContextForEventHandlers(nsresult* aRv)
{

View File

@ -28,6 +28,12 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,

View File

@ -157,6 +157,11 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
virtual void
AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,

View File

@ -3479,9 +3479,15 @@ nsDOMDeviceStorage::DispatchDOMEvent(WidgetEvent* aEvent,
}
nsEventListenerManager *
nsDOMDeviceStorage::GetListenerManager(bool aMayCreate)
nsDOMDeviceStorage::GetOrCreateListenerManager()
{
return nsDOMEventTargetHelper::GetListenerManager(aMayCreate);
return nsDOMEventTargetHelper::GetOrCreateListenerManager();
}
nsEventListenerManager *
nsDOMDeviceStorage::GetExistingListenerManager() const
{
return nsDOMEventTargetHelper::GetExistingListenerManager();
}
nsIScriptContext *

View File

@ -45,7 +45,7 @@ interface nsIScriptContext;
interface nsIDOMEventListener;
interface nsIDOMEvent;
[scriptable, builtinclass, uuid(31e92e56-4d23-4a4a-9cfe-a6d12cf434bc)]
[scriptable, builtinclass, uuid(b128448c-7b53-4769-92cb-cd6eafee676c)]
interface nsIDOMEventTarget : nsISupports
{
/**
@ -267,15 +267,6 @@ interface nsIDOMEventTarget : nsISupports
in nsPresContextPtr aPresContext,
in nsEventStatusPtr aEventStatus);
/**
* Get the event listener manager, the guy you talk to to register for events
* on this node.
* @param aMayCreate If PR_FALSE, returns a listener manager only if
* one already exists.
*/
[notxpcom, nostdcall]
nsEventListenerManagerPtr GetListenerManager(in boolean aMayCreate);
/**
* Get the script context in which the event handlers should be run.
* May return null.
@ -305,7 +296,7 @@ aClass::RemoveSystemEventListener(const nsAString& aType, \
nsIDOMEventListener *aListener, \
bool aUseCapture) \
{ \
nsEventListenerManager* listenerManager = GetListenerManager(false); \
nsEventListenerManager* listenerManager = GetExistingListenerManager(); \
if (!listenerManager) { \
return NS_OK; \
} \

View File

@ -1202,7 +1202,7 @@ TabChild::~TabChild()
mGlobal = nullptr;
if (mTabChildGlobal) {
nsEventListenerManager* elm = mTabChildGlobal->GetListenerManager(false);
nsEventListenerManager* elm = mTabChildGlobal->GetExistingListenerManager();
if (elm) {
elm->Disconnect();
}

View File

@ -73,6 +73,7 @@ class Selection;
namespace dom {
class Element;
class EventTarget;
} // namespace dom
} // namespace mozilla
@ -663,7 +664,7 @@ public:
nsIDOMNode *aEndNode,
int32_t aEndOffset);
virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget() = 0;
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget() = 0;
// Fast non-refcounting editor root element accessor
mozilla::dom::Element *GetRoot();
@ -819,7 +820,7 @@ protected:
nsCOMPtr<mozilla::dom::Element> mRootElement; // cached root node
nsCOMPtr<nsIPrivateTextRangeList> mIMETextRangeList; // IME special selection ranges
nsCOMPtr<nsIDOMCharacterData> mIMETextNode; // current IME text node
nsCOMPtr<nsIDOMEventTarget> mEventTarget; // The form field as an event receiver
nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; // The form field as an event receiver
nsCOMPtr<nsIDOMEventListener> mEventListener;
nsWeakPtr mSelConWeak; // weak reference to the nsISelectionController
nsWeakPtr mPlaceHolderTxn; // weak reference to placeholder for begin/end batch purposes

View File

@ -6,6 +6,7 @@
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Preferences.h" // for Preferences
#include "mozilla/dom/Element.h" // for Element
#include "mozilla/dom/EventTarget.h" // for EventTarget
#include "nsAString.h"
#include "nsCaret.h" // for nsCaret
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
@ -55,6 +56,7 @@
class nsPresContext;
using namespace mozilla;
using mozilla::dom::EventTarget;
nsEditorEventListener::nsEditorEventListener() :
mEditor(nullptr), mCommitText(false),
@ -103,11 +105,11 @@ nsEditorEventListener::InstallToEditor()
{
NS_PRECONDITION(mEditor, "The caller must set mEditor");
nsCOMPtr<nsIDOMEventTarget> piTarget = mEditor->GetDOMEventTarget();
nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
// register the event listeners with the listener manager
nsEventListenerManager* elmP = piTarget->GetListenerManager(true);
nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(elmP);
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
@ -181,13 +183,12 @@ nsEditorEventListener::Disconnect()
void
nsEditorEventListener::UninstallFromEditor()
{
nsCOMPtr<nsIDOMEventTarget> piTarget = mEditor->GetDOMEventTarget();
nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
if (!piTarget) {
return;
}
nsEventListenerManager* elmP =
piTarget->GetListenerManager(true);
nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
if (!elmP) {
return;
}

View File

@ -70,6 +70,7 @@
#include "nsIParserService.h"
#include "mozilla/Selection.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "nsTextFragment.h"
@ -5217,14 +5218,14 @@ nsHTMLEditor::GetActiveEditingHost()
return content->GetEditingHost();
}
already_AddRefed<nsIDOMEventTarget>
already_AddRefed<mozilla::dom::EventTarget>
nsHTMLEditor::GetDOMEventTarget()
{
// Don't use getDocument here, because we have no way of knowing
// whether Init() was ever called. So we need to get the document
// ourselves, if it exists.
NS_PRECONDITION(mDocWeak, "This editor has not been initialized yet");
nsCOMPtr<nsIDOMEventTarget> target = do_QueryReferent(mDocWeak.get());
nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryReferent(mDocWeak);
return target.forget();
}

View File

@ -106,7 +106,7 @@ public:
virtual already_AddRefed<nsIContent> GetFocusedContent();
virtual already_AddRefed<nsIContent> GetFocusedContentForIME();
virtual bool IsActiveInDOMWindow();
virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget();
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
virtual mozilla::dom::Element* GetEditorRoot() MOZ_OVERRIDE;
virtual already_AddRefed<nsIContent> FindSelectionRoot(nsINode *aNode);
virtual bool IsAcceptableInputEvent(nsIDOMEvent* aEvent);

View File

@ -1584,10 +1584,10 @@ nsPlaintextEditor::SelectEntireDocument(nsISelection *aSelection)
return NS_OK;
}
already_AddRefed<nsIDOMEventTarget>
already_AddRefed<mozilla::dom::EventTarget>
nsPlaintextEditor::GetDOMEventTarget()
{
nsCOMPtr<nsIDOMEventTarget> copy = mEventTarget;
nsCOMPtr<mozilla::dom::EventTarget> copy = mEventTarget;
return copy.forget();
}

View File

@ -120,7 +120,7 @@ public:
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget();
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
virtual nsresult BeginIMEComposition();
virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString,

View File

@ -865,7 +865,7 @@ nsDocShellTreeOwner::AddChromeListeners()
nsCOMPtr<EventTarget> target;
GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
nsEventListenerManager* elmP = target->GetListenerManager(true);
nsEventListenerManager* elmP = target->GetOrCreateListenerManager();
if (elmP) {
elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"),
dom::TrustedEventsAtSystemGroupBubble());
@ -895,7 +895,7 @@ nsDocShellTreeOwner::RemoveChromeListeners()
if (!piTarget)
return NS_OK;
nsEventListenerManager* elmP = piTarget->GetListenerManager(true);
nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
if (elmP)
{
elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("dragover"),

View File

@ -118,13 +118,13 @@ GetPrefsFor(nsEventStructType aEventStructType)
static bool
HasMouseListener(nsIContent* aContent)
{
nsEventListenerManager* elm = aContent->GetListenerManager(false);
if (!elm) {
return false;
if (nsEventListenerManager* elm = aContent->GetExistingListenerManager()) {
return elm->HasListenersFor(nsGkAtoms::onclick) ||
elm->HasListenersFor(nsGkAtoms::onmousedown) ||
elm->HasListenersFor(nsGkAtoms::onmouseup);
}
return elm->HasListenersFor(nsGkAtoms::onclick) ||
elm->HasListenersFor(nsGkAtoms::onmousedown) ||
elm->HasListenersFor(nsGkAtoms::onmouseup);
return false;
}
static bool

View File

@ -2208,7 +2208,7 @@ MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
return false;
nsEventListenerManager* manager = nullptr;
if ((manager = parentTarget->GetListenerManager(false)) &&
if ((manager = parentTarget->GetExistingListenerManager()) &&
manager->MayHavePaintEventListener()) {
return true;
}
@ -2236,7 +2236,7 @@ MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow)
EventTarget* tabChildGlobal;
return root &&
(tabChildGlobal = root->GetParentTarget()) &&
(manager = tabChildGlobal->GetListenerManager(false)) &&
(manager = tabChildGlobal->GetExistingListenerManager()) &&
manager->MayHavePaintEventListener();
}