From 62dee43850c6921a9d90ef730503db22a54b2b50 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Fri, 27 Feb 2004 17:17:37 +0000 Subject: [PATCH] deCOMtaminate nsIPresContext::GetEventStateManager. Bug 229371, r+sr=roc. git-svn-id: svn://10.0.0.236/trunk@153335 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsContentCID.h | 4 - mozilla/content/base/src/nsDocument.cpp | 8 +- mozilla/content/base/src/nsGenericElement.cpp | 12 +-- mozilla/content/events/src/nsDOMEvent.cpp | 33 +++----- .../events/src/nsEventListenerManager.cpp | 7 +- .../events/src/nsEventStateManager.cpp | 76 ++++++----------- .../content/events/src/nsEventStateManager.h | 3 - .../html/content/src/nsGenericHTMLElement.cpp | 33 +++----- .../html/content/src/nsHTMLAnchorElement.cpp | 39 ++++----- .../html/content/src/nsHTMLAreaElement.cpp | 36 ++++---- .../html/content/src/nsHTMLButtonElement.cpp | 40 ++++----- .../html/content/src/nsHTMLInputElement.cpp | 47 ++++------- .../html/content/src/nsHTMLLabelElement.cpp | 5 +- .../html/content/src/nsHTMLSelectElement.cpp | 16 ++-- .../content/src/nsHTMLTextAreaElement.cpp | 25 ++---- .../html/style/src/nsCSSStyleSheet.cpp | 7 +- .../content/xml/content/src/nsXMLElement.cpp | 8 +- .../content/xul/content/src/nsXULElement.cpp | 14 +--- .../xul/content/src/nsXULPopupListener.cpp | 3 +- mozilla/docshell/base/nsDocShell.cpp | 5 +- mozilla/dom/src/base/nsFocusController.cpp | 7 +- mozilla/dom/src/base/nsGlobalWindow.cpp | 47 ++++------- .../dom/src/base/nsGlobalWindowCommands.cpp | 6 +- mozilla/dom/src/base/nsWindowRoot.cpp | 9 +- .../libeditor/text/nsEditorEventListeners.cpp | 8 +- .../components/find/src/nsWebBrowserFind.cpp | 10 +-- .../inspector/base/src/inLayoutUtils.cpp | 5 +- .../typeaheadfind/src/nsTypeAheadFind.cpp | 17 ++-- mozilla/gfx/src/gtk/nsNativeThemeGTK.cpp | 4 +- mozilla/gfx/src/shared/nsNativeTheme.cpp | 4 +- mozilla/gfx/src/windows/nsNativeThemeWin.cpp | 4 +- mozilla/layout/base/nsPresContext.cpp | 38 +++------ mozilla/layout/base/nsPresContext.h | 5 +- mozilla/layout/base/nsPresShell.cpp | 61 +++++--------- mozilla/layout/base/public/nsIPresContext.h | 5 +- mozilla/layout/base/public/nsPresContext.h | 5 +- mozilla/layout/base/src/Makefile.in | 2 +- mozilla/layout/base/src/nsPresContext.cpp | 38 +++------ mozilla/layout/base/src/nsPresContext.h | 5 -- mozilla/layout/build/nsLayoutModule.cpp | 7 -- .../layout/forms/nsComboboxControlFrame.cpp | 47 +++++------ mozilla/layout/forms/nsFormControlFrame.cpp | 12 ++- mozilla/layout/forms/nsListControlFrame.cpp | 29 +++---- mozilla/layout/generic/nsAreaFrame.cpp | 18 ++-- mozilla/layout/generic/nsFrame.cpp | 6 +- mozilla/layout/generic/nsHTMLFrame.cpp | 84 +++++++++---------- mozilla/layout/html/base/src/nsAreaFrame.cpp | 18 ++-- mozilla/layout/html/base/src/nsFrame.cpp | 6 +- mozilla/layout/html/base/src/nsHTMLFrame.cpp | 84 +++++++++---------- mozilla/layout/html/base/src/nsPresShell.cpp | 61 +++++--------- .../html/forms/src/nsComboboxControlFrame.cpp | 47 +++++------ .../html/forms/src/nsFormControlFrame.cpp | 12 ++- .../html/forms/src/nsListControlFrame.cpp | 29 +++---- mozilla/layout/style/nsCSSStyleSheet.cpp | 7 +- mozilla/layout/xul/base/src/nsBoxFrame.cpp | 23 ++--- .../layout/xul/base/src/nsButtonBoxFrame.cpp | 11 ++- mozilla/layout/xul/base/src/nsMenuFrame.cpp | 6 +- .../layout/xul/base/src/nsTextBoxFrame.cpp | 17 ++-- 58 files changed, 452 insertions(+), 773 deletions(-) diff --git a/mozilla/content/base/public/nsContentCID.h b/mozilla/content/base/public/nsContentCID.h index fb3801d230f..4ea4adc59ce 100644 --- a/mozilla/content/base/public/nsContentCID.h +++ b/mozilla/content/base/public/nsContentCID.h @@ -187,10 +187,6 @@ #define NS_EVENTLISTENERMANAGER_CID \ { 0x9f689e0, 0xb4da, 0x11d2, { 0xa6, 0x8b, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } -// {A1FDE862-E802-11d4-9885-00C04FA0CF4B} -#define NS_EVENTSTATEMANAGER_CID \ -{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } } - // {66856477-6596-40eb-bb87-59ca2dabb6f7} #define NS_DOMEVENTGROUP_CID \ { 0x66856477, 0x6596, 0x40eb, { 0xbb, 0x87, 0x59, 0xca, 0x2d, 0xab, 0xb6, 0xf7 } } diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 3c9b9d8e0b4..8b1539cc2a3 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -3725,12 +3725,8 @@ nsDocument::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval) nsCOMPtr presContext; shell->GetPresContext(getter_AddRefs(presContext)); - nsCOMPtr esm; - nsresult rv = presContext->GetEventStateManager(getter_AddRefs(esm)); - NS_ENSURE_SUCCESS(rv, rv); - - return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDOMDocument *, this), aEvent, - _retval); + return presContext->EventStateManager()-> + DispatchNewEvent(NS_STATIC_CAST(nsIDOMDocument*, this), aEvent, _retval); } NS_IMETHODIMP diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index b7262d516c0..5f23715bbc1 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -2370,15 +2370,9 @@ nsGenericElement::GetRangeList() const void nsGenericElement::SetFocus(nsIPresContext* aPresContext) { - if (HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) { - return; - } - - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); + if (!HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) { + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); } } diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 991fcf0d161..0624bc59300 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -297,11 +297,11 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget) *aTarget = nsnull; - nsCOMPtr manager; nsCOMPtr targetContent; - if (mPresContext && NS_OK == mPresContext->GetEventStateManager(getter_AddRefs(manager)) && manager) { - manager->GetEventTargetContent(mEvent, getter_AddRefs(targetContent)); + if (mPresContext) { + mPresContext->EventStateManager()-> + GetEventTargetContent(mEvent, getter_AddRefs(targetContent)); } if (targetContent) { @@ -346,11 +346,8 @@ nsDOMEvent::GetTargetFromFrame() if (!mPresContext) { return nsnull; } // Get the target frame (have to get the ESM first) - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - nsIFrame* targetFrame = nsnull; - esm->GetEventTarget(&targetFrame); + mPresContext->EventStateManager()->GetEventTarget(&targetFrame); if (!targetFrame) { return nsnull; } // get the real content @@ -906,14 +903,9 @@ NS_METHOD nsDOMEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) return NS_OK; } - nsCOMPtr manager; - mPresContext->GetEventStateManager(getter_AddRefs(manager)); - if (!manager) { - return NS_OK; - } - nsCOMPtr relatedContent; - manager->GetEventRelatedContent(getter_AddRefs(relatedContent)); + mPresContext->EventStateManager()-> + GetEventRelatedContent(getter_AddRefs(relatedContent)); if (!relatedContent) { return NS_OK; } @@ -1069,11 +1061,9 @@ NS_METHOD nsDOMEvent::GetRangeParent(nsIDOMNode** aRangeParent) { NS_ENSURE_ARG_POINTER(aRangeParent); nsIFrame* targetFrame = nsnull; - nsCOMPtr manager; - if (mPresContext && - (NS_OK == mPresContext->GetEventStateManager(getter_AddRefs(manager)))) { - manager->GetEventTarget(&targetFrame); + if (mPresContext) { + mPresContext->EventStateManager()->GetEventTarget(&targetFrame); } *aRangeParent = nsnull; @@ -1101,12 +1091,9 @@ NS_METHOD nsDOMEvent::GetRangeOffset(PRInt32* aRangeOffset) { NS_ENSURE_ARG_POINTER(aRangeOffset); nsIFrame* targetFrame = nsnull; - nsIEventStateManager* manager; - if (mPresContext && - (NS_OK == mPresContext->GetEventStateManager(&manager))) { - manager->GetEventTarget(&targetFrame); - NS_RELEASE(manager); + if (mPresContext) { + mPresContext->EventStateManager()->GetEventTarget(&targetFrame); } if (targetFrame) { diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index abe803517fd..f80c8266182 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -1807,11 +1807,8 @@ nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval) nsCOMPtr aPresContext; shell->GetPresContext(getter_AddRefs(aPresContext)); - nsCOMPtr esm; - nsresult rv = aPresContext->GetEventStateManager(getter_AddRefs(esm)); - NS_ENSURE_SUCCESS(rv, rv); - - return esm->DispatchNewEvent(mTarget, aEvent, _retval); + return aPresContext->EventStateManager()->DispatchNewEvent(mTarget, aEvent, + _retval); } // nsIDOM3EventTarget interface diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index c306e0ba859..9f932b64835 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -524,7 +524,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, shell->GetPresContext(getter_AddRefs(oldPresContext)); nsCOMPtr esm; - oldPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm = oldPresContext->EventStateManager(); esm->SetFocusedContent(gLastFocusedContent); gLastFocusedContent->HandleDOMEvent(oldPresContext, &blurevent, nsnull, @@ -658,7 +658,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, shell->GetPresContext(getter_AddRefs(oldPresContext)); nsCOMPtr esm; - oldPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm = oldPresContext->GetEventStateManager(); esm->SetFocusedContent(gLastFocusedContent); gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, @@ -816,7 +816,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, focusController->GetFocusedElement(getter_AddRefs(focusedElement)); nsCOMPtr esm; - oldPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm = oldPresContext->EventStateManager(); esm->SetFocusedContent(gLastFocusedContent); nsCOMPtr focusedContent = do_QueryInterface(focusedElement); @@ -1003,8 +1003,6 @@ nsEventStateManager::HandleAccessKey(nsIPresContext* aPresContext, nsCOMPtr subShellItem; nsCOMPtr subPS; nsCOMPtr subPC; - nsCOMPtr subESM; - docShell->GetChildAt(counter, getter_AddRefs(subShellItem)); nsCOMPtr subDS = do_QueryInterface(subShellItem); @@ -1021,9 +1019,9 @@ nsEventStateManager::HandleAccessKey(nsIPresContext* aPresContext, subPS->GetPresContext(getter_AddRefs(subPC)); NS_ASSERTION(subPC, "PresShell without PresContext"); - subPC->GetEventStateManager(getter_AddRefs(subESM)); + nsEventStateManager* esm = + NS_STATIC_CAST(nsEventStateManager *, subPC->EventStateManager()); - nsEventStateManager* esm = NS_STATIC_CAST(nsEventStateManager *, NS_STATIC_CAST(nsIEventStateManager *, subESM.get())); if (esm) esm->HandleAccessKey(subPC, aEvent, aStatus, -1, eAccessKeyProcessingDown); @@ -1050,7 +1048,6 @@ nsEventStateManager::HandleAccessKey(nsIPresContext* aPresContext, nsCOMPtr parentPS; nsCOMPtr parentPC; - nsCOMPtr parentESM; parentDS->GetPresShell(getter_AddRefs(parentPS)); NS_ASSERTION(parentPS, "Our PresShell exists but the parent's does not?"); @@ -1058,9 +1055,9 @@ nsEventStateManager::HandleAccessKey(nsIPresContext* aPresContext, parentPS->GetPresContext(getter_AddRefs(parentPC)); NS_ASSERTION(parentPC, "PresShell without PresContext"); - parentPC->GetEventStateManager(getter_AddRefs(parentESM)); + nsEventStateManager* esm = + NS_STATIC_CAST(nsEventStateManager *, parentPC->EventStateManager()); - nsEventStateManager* esm = NS_STATIC_CAST(nsEventStateManager *, NS_STATIC_CAST(nsIEventStateManager *, parentESM.get())); if (esm) esm->HandleAccessKey(parentPC, aEvent, aStatus, myOffset, eAccessKeyProcessingUp); } @@ -2947,13 +2944,12 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel) if (vm) { vm->GetWidget(getter_AddRefs(widget)); } - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); printf("DS %p Type %s Cnt %d Doc %p DW %p EM %p\n", parentAsDocShell.get(), type==nsIDocShellTreeItem::typeChrome?"Chrome":"Content", - childWebshellCount, doc.get(), domwin.get(), esm.get()); + childWebshellCount, doc.get(), domwin.get(), + presContext->EventStateManager()); if (childWebshellCount > 0) { for (PRInt32 i=0;i parentPC; parentShell->GetPresContext(getter_AddRefs(parentPC)); - nsCOMPtr parentESM; - parentPC->GetEventStateManager(getter_AddRefs(parentESM)); + nsIEventStateManager *parentESM = parentPC->EventStateManager(); SetContentState(nsnull, NS_EVENT_STATE_FOCUS); @@ -4097,7 +4092,7 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, } nsCOMPtr esm; - oldPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm = oldPresContext->EventStateManager(); esm->SetFocusedContent(gLastFocusedContent); nsCOMPtr temp = gLastFocusedContent; NS_RELEASE(gLastFocusedContent); @@ -4151,9 +4146,7 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch #2"); } - nsCOMPtr esm; - gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); - esm->SetFocusedContent(nsnull); + gLastFocusedPresContext->EventStateManager()->SetFocusedContent(nsnull); nsCOMPtr temp = gLastFocusedDocument; NS_RELEASE(gLastFocusedDocument); gLastFocusedDocument = nsnull; @@ -4500,25 +4493,6 @@ nsEventStateManager::FlushPendingEvents(nsIPresContext* aPresContext) } } -nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult) -{ - nsresult rv; - - NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIEventStateManager* manager = new nsEventStateManager(); - if (nsnull == manager) { - return NS_ERROR_OUT_OF_MEMORY; - } - rv = CallQueryInterface(manager, aInstancePtrResult); - if (NS_FAILED(rv)) return rv; - - return manager->Init(); -} - - nsresult nsEventStateManager::GetDocSelectionLocation(nsIContent **aStartContent, nsIContent **aEndContent, @@ -5163,21 +5137,19 @@ nsEventStateManager::TabIntoDocument(nsIDocShell* aDocShell, nsCOMPtr pc; aDocShell->GetPresContext(getter_AddRefs(pc)); if (pc) { - nsCOMPtr docESM; - pc->GetEventStateManager(getter_AddRefs(docESM)); - if (docESM) { - // we are about to shift focus to aDocShell - // keep track of the document, so we don't try to go back into it. - mTabbingFromDocShells.AppendObject(aDocShell); - - // clear out any existing focus state - docESM->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); - // now focus the first (or last) focusable content - docESM->ShiftFocus(aForward, nsnull); + nsIEventStateManager *docESM = pc->EventStateManager(); - // remove the document from the list - mTabbingFromDocShells.RemoveObject(aDocShell); - } + // we are about to shift focus to aDocShell + // keep track of the document, so we don't try to go back into it. + mTabbingFromDocShells.AppendObject(aDocShell); + + // clear out any existing focus state + docESM->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + // now focus the first (or last) focusable content + docESM->ShiftFocus(aForward, nsnull); + + // remove the document from the list + mTabbingFromDocShells.RemoveObject(aDocShell); } } } diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 5cc096903f3..8774f9843ee 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -356,7 +356,4 @@ protected: }; -nsresult -NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult); - #endif // nsEventStateManager_h__ diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 103b68eb510..c0b284f7fac 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1359,18 +1359,12 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsIPresContext* aPresContext, //the event on that map or on a link farther up the tree. If we're on a //link farther up, do nothing. if (NS_SUCCEEDED(ret)) { - PRBool targetIsArea = PR_FALSE; + nsCOMPtr target; - nsCOMPtr esm; - if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm))) && esm) { - nsCOMPtr target; - esm->GetEventTargetContent(aEvent, getter_AddRefs(target)); - if (target && IsArea(target)) { - targetIsArea = PR_TRUE; - } - } + aPresContext->EventStateManager()-> + GetEventTargetContent(aEvent, getter_AddRefs(target)); - if (targetIsArea && !IsArea(this)) { + if (target && IsArea(target) && !IsArea(this)) { // We are over an area and our element is not one. Return without // running anchor code. return ret; @@ -1417,11 +1411,10 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsIPresContext* aPresContext, break; } - nsCOMPtr stateManager; - if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(stateManager))) { - stateManager->SetContentState(this, NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()-> + SetContentState(this, + NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); + } } break; @@ -3535,11 +3528,7 @@ nsGenericHTMLElement::SetElementFocus(PRBool aDoFocus) if (aDoFocus) { SetFocus(presContext); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->MoveCaretToFocus(); - } + presContext->EventStateManager()->MoveCaretToFocus(); return; } @@ -3561,9 +3550,7 @@ nsresult nsGenericHTMLElement::RegUnRegAccessKey(PRBool aDoReg) GetPresContext(this, getter_AddRefs(presContext)); NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - NS_ENSURE_TRUE(esm, NS_ERROR_FAILURE); + nsIEventStateManager *esm = presContext->EventStateManager(); // Register or unregister as appropriate. if (aDoReg) { diff --git a/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp b/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp index 4b72a9c5a20..c0d4dcf6816 100644 --- a/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp @@ -265,27 +265,22 @@ nsHTMLAnchorElement::SetFocus(nsIPresContext* aPresContext) // don't make the link grab the focus if there is no link handler nsILinkHandler *handler = aPresContext->GetLinkHandler(); if (handler) { - nsCOMPtr stateManager; + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); - aPresContext->GetEventStateManager(getter_AddRefs(stateManager)); + // Make sure the presentation is up-to-date + if (mDocument) { + mDocument->FlushPendingNotifications(); + } - if (stateManager) { - stateManager->SetContentState(this, NS_EVENT_STATE_FOCUS); + nsIPresShell *presShell = aPresContext->GetPresShell(); - // Make sure the presentation is up-to-date - if (mDocument) { - mDocument->FlushPendingNotifications(); - } - - nsIPresShell *presShell = aPresContext->GetPresShell(); - - if (presShell) { - nsIFrame* frame = nsnull; - presShell->GetPrimaryFrameFor(this, &frame); - if (frame) { - presShell->ScrollFrameIntoView(frame, NS_PRESSHELL_SCROLL_ANYWHERE, - NS_PRESSHELL_SCROLL_ANYWHERE); - } + if (presShell) { + nsIFrame* frame = nsnull; + presShell->GetPrimaryFrameFor(this, &frame); + if (frame) { + presShell->ScrollFrameIntoView(frame, NS_PRESSHELL_SCROLL_ANYWHERE, + NS_PRESSHELL_SCROLL_ANYWHERE); } } } @@ -301,11 +296,9 @@ nsHTMLAnchorElement::RemoveFocus(nsIPresContext* aPresContext) // If we are disabled, we probably shouldn't have focus in the // first place, so allow it to be removed. - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm && mDocument) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + if (mDocument) { + aPresContext->EventStateManager()->SetContentState(nsnull, + NS_EVENT_STATE_FOCUS); } } diff --git a/mozilla/content/html/content/src/nsHTMLAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLAreaElement.cpp index b08232d5a11..bec1a795ea6 100644 --- a/mozilla/content/html/content/src/nsHTMLAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLAreaElement.cpp @@ -248,25 +248,22 @@ nsHTMLAreaElement::SetFocus(nsIPresContext* aPresContext) if (!aPresContext) return; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); - // Make sure the presentation is up-to-date - if (mDocument) { - mDocument->FlushPendingNotifications(); - } + // Make sure the presentation is up-to-date + if (mDocument) { + mDocument->FlushPendingNotifications(); + } - nsIPresShell *presShell = aPresContext->GetPresShell(); + nsIPresShell *presShell = aPresContext->GetPresShell(); - if (presShell) { - nsIFrame* frame = nsnull; - presShell->GetPrimaryFrameFor(this, &frame); - if (frame) { - presShell->ScrollFrameIntoView(frame, NS_PRESSHELL_SCROLL_ANYWHERE, - NS_PRESSHELL_SCROLL_ANYWHERE); - } + if (presShell) { + nsIFrame* frame = nsnull; + presShell->GetPrimaryFrameFor(this, &frame); + if (frame) { + presShell->ScrollFrameIntoView(frame, NS_PRESSHELL_SCROLL_ANYWHERE, + NS_PRESSHELL_SCROLL_ANYWHERE); } } } @@ -277,11 +274,8 @@ nsHTMLAreaElement::RemoveFocus(nsIPresContext* aPresContext) if (!aPresContext) return; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()->SetContentState(nsnull, + NS_EVENT_STATE_FOCUS); } void diff --git a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp index fd031d331ea..9908d952473 100644 --- a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp @@ -278,11 +278,8 @@ nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext) return; } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE); @@ -306,10 +303,9 @@ nsHTMLButtonElement::RemoveFocus(nsIPresContext* aPresContext) formControlFrame->SetFocus(PR_FALSE, PR_FALSE); } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm && mDocument) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + if (mDocument) { + aPresContext->EventStateManager()->SetContentState(nsnull, + NS_EVENT_STATE_FOCUS); } } @@ -468,12 +464,10 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext, case NS_MOUSE_LEFT_BUTTON_DOWN: { - nsIEventStateManager *stateManager; - if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) { - stateManager->SetContentState(this, NS_EVENT_STATE_ACTIVE | - NS_EVENT_STATE_FOCUS); - NS_RELEASE(stateManager); - } + aPresContext->EventStateManager()-> + SetContentState(this, + NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); + *aEventStatus = nsEventStatus_eConsumeNoDefault; } break; @@ -503,11 +497,9 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext, case NS_MOUSE_ENTER_SYNTH: { - nsIEventStateManager *stateManager; - if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) { - stateManager->SetContentState(this, NS_EVENT_STATE_HOVER); - NS_RELEASE(stateManager); - } + aPresContext->EventStateManager()-> + SetContentState(this, NS_EVENT_STATE_HOVER); + *aEventStatus = nsEventStatus_eConsumeNoDefault; } break; @@ -515,11 +507,9 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext, // XXX this doesn't seem to do anything yet case NS_MOUSE_EXIT_SYNTH: { - nsIEventStateManager *stateManager; - if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) { - stateManager->SetContentState(nsnull, NS_EVENT_STATE_HOVER); - NS_RELEASE(stateManager); - } + aPresContext->EventStateManager()-> + SetContentState(nsnull, NS_EVENT_STATE_HOVER); + *aEventStatus = nsEventStatus_eConsumeNoDefault; } break; diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 46cee39ae0e..798cfdaa680 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -1104,12 +1104,8 @@ nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext) return; } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE); @@ -1136,11 +1132,9 @@ nsHTMLInputElement::RemoveFocus(nsIPresContext* aPresContext) formControlFrame->SetFocus(PR_FALSE, PR_FALSE); } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm && mDocument) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + if (mDocument) { + aPresContext->EventStateManager()->SetContentState(nsnull, + NS_EVENT_STATE_FOCUS); } } @@ -1198,18 +1192,15 @@ nsHTMLInputElement::Select() // returning false) if (status == nsEventStatus_eIgnore) { if (presContext) { - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - // XXX Fix for bug 135345 - ESM currently does not check to see if we - // have focus before attempting to set focus again and may cause - // infinite recursion. For now check if we have focus and do not set - // focus again if already focused. - PRInt32 currentState; - esm->GetContentState(this, currentState); - if (!(currentState & NS_EVENT_STATE_FOCUS)) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - } + nsIEventStateManager *esm = presContext->EventStateManager(); + // XXX Fix for bug 135345 - ESM currently does not check to see if we + // have focus before attempting to set focus again and may cause + // infinite recursion. For now check if we have focus and do not set + // focus again if already focused. + PRInt32 currentState; + esm->GetContentState(this, currentState); + if (!(currentState & NS_EVENT_STATE_FOCUS)) { + esm->SetContentState(this, NS_EVENT_STATE_FOCUS); } } @@ -2038,13 +2029,11 @@ nsHTMLInputElement::FireEventForAccessibility(nsIPresContext* aPresContext, if (manager && NS_SUCCEEDED(manager->CreateEvent(aPresContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(aEventType, PR_TRUE, PR_TRUE); + PRBool noDefault; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - nsCOMPtr target(do_QueryInterface(NS_STATIC_CAST(nsIDOMHTMLInputElement *, this))); - esm->DispatchNewEvent(target, event, &noDefault); - } + nsISupports *target = NS_STATIC_CAST(nsIDOMHTMLInputElement*, this); + aPresContext->EventStateManager()->DispatchNewEvent(target, event, + &noDefault); } return NS_OK; diff --git a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp index 2ed7539ca44..9e8db26fa97 100644 --- a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp @@ -226,10 +226,9 @@ static PRBool EventTargetIn(nsIPresContext *aPresContext, nsEvent *aEvent, nsIContent *aChild, nsIContent *aStop) { - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); nsCOMPtr c; - esm->GetEventTargetContent(aEvent, getter_AddRefs(c)); + aPresContext->EventStateManager()->GetEventTargetContent(aEvent, + getter_AddRefs(c)); nsIContent *content = c; while (content) { if (content == aChild) { diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index 55affbf5e02..03473d2d7a2 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -1662,12 +1662,8 @@ nsHTMLSelectElement::SetFocus(nsIPresContext* aPresContext) return; } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE); @@ -1694,11 +1690,9 @@ nsHTMLSelectElement::RemoveFocus(nsIPresContext* aPresContext) formControlFrame->SetFocus(PR_FALSE, PR_FALSE); } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm && mDocument) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + if (mDocument) { + aPresContext->EventStateManager()->SetContentState(nsnull, + NS_EVENT_STATE_FOCUS); } } diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index 76d1a094deb..ce00b14cef9 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -294,12 +294,8 @@ nsHTMLTextAreaElement::SetFocus(nsIPresContext* aPresContext) return; } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE); @@ -326,11 +322,9 @@ nsHTMLTextAreaElement::RemoveFocus(nsIPresContext* aPresContext) formControlFrame->SetFocus(PR_FALSE, PR_FALSE); } - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm && mDocument) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + if (mDocument) { + aPresContext->EventStateManager()->SetContentState(nsnull, + NS_EVENT_STATE_FOCUS); } } @@ -361,13 +355,8 @@ nsHTMLTextAreaElement::Select() // If the DOM event was not canceled (e.g. by a JS event handler // returning false) if (status == nsEventStatus_eIgnore) { - nsCOMPtr esm; - - presContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - } + presContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE); diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index 488c3d3c034..b7d82ccb23f 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -3128,12 +3128,7 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext, mParentContent = aContent->GetParent(); // get the event state - nsIEventStateManager* eventStateManager = nsnull; - mPresContext->GetEventStateManager(&eventStateManager); - if(eventStateManager) { - eventStateManager->GetContentState(aContent, mEventState); - NS_RELEASE(eventStateManager); - } + mPresContext->EventStateManager()->GetContentState(aContent, mEventState); // get the styledcontent interface and the ID if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&mStyledContent))) { diff --git a/mozilla/content/xml/content/src/nsXMLElement.cpp b/mozilla/content/xml/content/src/nsXMLElement.cpp index d999bdb66d7..61a7d2046d9 100644 --- a/mozilla/content/xml/content/src/nsXMLElement.cpp +++ b/mozilla/content/xml/content/src/nsXMLElement.cpp @@ -323,11 +323,9 @@ nsXMLElement::HandleDOMEvent(nsIPresContext* aPresContext, switch (aEvent->message) { case NS_MOUSE_LEFT_BUTTON_DOWN: { - nsIEventStateManager *stateManager; - if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) { - stateManager->SetContentState(this, NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); - NS_RELEASE(stateManager); - } + aPresContext->EventStateManager()-> + SetContentState(this, NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); + *aEventStatus = nsEventStatus_eConsumeDoDefault; } break; diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index 7092238af97..563e3fc8ae2 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -2072,11 +2072,9 @@ nsXULElement::UnregisterAccessKey(const nsAString& aOldValue) nsCOMPtr presContext; shell->GetPresContext(getter_AddRefs(presContext)); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - nsIContent* content = NS_STATIC_CAST(nsIContent*, this); - esm->UnregisterAccessKey(content, aOldValue.First()); + presContext->EventStateManager()-> + UnregisterAccessKey(content, aOldValue.First()); } } } @@ -3970,12 +3968,8 @@ nsXULElement::SetFocus(nsIPresContext* aPresContext) if (disabled == NS_LITERAL_STRING("true")) return; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - esm->SetContentState((nsIStyledContent*)this, NS_EVENT_STATE_FOCUS); - } + aPresContext->EventStateManager()->SetContentState(this, + NS_EVENT_STATE_FOCUS); } void diff --git a/mozilla/content/xul/content/src/nsXULPopupListener.cpp b/mozilla/content/xul/content/src/nsXULPopupListener.cpp index ad7826af621..7accd1b160d 100644 --- a/mozilla/content/xul/content/src/nsXULPopupListener.cpp +++ b/mozilla/content/xul/content/src/nsXULPopupListener.cpp @@ -340,8 +340,7 @@ XULPopupListenerImpl::FireFocusOnTargetContent(nsIDOMNode* aTargetNode) currFrame = currFrame->GetParent(); } nsCOMPtr focusableContent = do_QueryInterface(element); - nsCOMPtr esm; - context->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = context->EventStateManager(); if (focusableContent) focusableContent->SetFocus(context); diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 5a1750c41e4..f0fb39adfac 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -1888,15 +1888,14 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel) if (vm) { vm->GetWidget(getter_AddRefs(widget)); } - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); nsCOMPtr rootContent; doc->GetRootContent(getter_AddRefs(rootContent)); printf("DS %p Ty %s Doc %p DW %p EM %p CN %p\n", parentAsDocShell.get(), type==nsIDocShellTreeItem::typeChrome?"Chr":"Con", - doc.get(), domwin.get(), esm.get(), rootContent.get()); + doc.get(), domwin.get(), + presContext->EventStateManager(), rootContent.get()); if (childWebshellCount > 0) { for (PRInt32 i=0;i presContext; shell->GetPresContext(getter_AddRefs(presContext)); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - // Make this ESM shift the focus per our instructions. - esm->ShiftFocus(aForward, content); + // Make this ESM shift the focus per our instructions. + presContext->EventStateManager()->ShiftFocus(aForward, content); return NS_OK; } diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index ac4db4960d4..44773e33696 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -3054,12 +3054,8 @@ GlobalWindowImpl::CheckForAbusePoint() if (presShell) { nsCOMPtr presContext; presShell->GetPresContext(getter_AddRefs(presContext)); - if (presContext) { - nsCOMPtr esManager; - presContext->GetEventStateManager(getter_AddRefs(esManager)); - if (esManager) - esManager->GetCurrentEvent(¤tEvent); - } + if (presContext) + presContext->EventStateManager()->GetCurrentEvent(¤tEvent); } } @@ -4170,13 +4166,9 @@ GlobalWindowImpl::DispatchEvent(nsIDOMEvent* aEvent, PRBool* _retval) // Retrieve the context nsCOMPtr aPresContext; shell->GetPresContext(getter_AddRefs(aPresContext)); - - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - return esm->DispatchNewEvent(NS_STATIC_CAST(nsIScriptGlobalObject *, - this), aEvent, _retval); - } + aPresContext->EventStateManager()-> + DispatchNewEvent(NS_STATIC_CAST(nsIScriptGlobalObject*, this), + aEvent, _retval); } return NS_ERROR_FAILURE; @@ -5853,26 +5845,23 @@ nsGlobalChromeWindow::SetCursor(const nsAString& aCursor) nsCOMPtr presContext; mDocShell->GetPresContext(getter_AddRefs(presContext)); if (presContext) { - nsCOMPtr esm; - if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) { - // Need root widget. - nsCOMPtr presShell; - mDocShell->GetPresShell(getter_AddRefs(presShell)); - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + // Need root widget. + nsCOMPtr presShell; + mDocShell->GetPresShell(getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - nsIViewManager* vm = presShell->GetViewManager(); - NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); + nsIViewManager* vm = presShell->GetViewManager(); + NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView; - vm->GetRootView(rootView); - NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + nsIView *rootView; + vm->GetRootView(rootView); + NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); - nsIWidget* widget = rootView->GetWidget(); - NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE); + nsIWidget* widget = rootView->GetWidget(); + NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE); - // Call esm and set cursor. - rv = esm->SetCursor(cursor, widget, PR_TRUE); - } + // Call esm and set cursor. + rv = presContext->EventStateManager()->SetCursor(cursor, widget, PR_TRUE); } return rv; diff --git a/mozilla/dom/src/base/nsGlobalWindowCommands.cpp b/mozilla/dom/src/base/nsGlobalWindowCommands.cpp index 92187a8412d..a251787020c 100644 --- a/mozilla/dom/src/base/nsGlobalWindowCommands.cpp +++ b/mozilla/dom/src/base/nsGlobalWindowCommands.cpp @@ -237,8 +237,10 @@ nsSelectionCommandsBase::GetEventStateManagerForWindow(nsIDOMWindow *aWindow, { nsCOMPtr presContext; presShell->GetPresContext(getter_AddRefs(presContext)); - if (presContext) - return presContext->GetEventStateManager(aEventStateManager); + if (presContext) { + NS_ADDREF(*aEventStateManager = presContext->EventStateManager()); + return NS_OK; + } } return NS_ERROR_FAILURE; } diff --git a/mozilla/dom/src/base/nsWindowRoot.cpp b/mozilla/dom/src/base/nsWindowRoot.cpp index c6b784c7125..de6ba310627 100644 --- a/mozilla/dom/src/base/nsWindowRoot.cpp +++ b/mozilla/dom/src/base/nsWindowRoot.cpp @@ -88,12 +88,9 @@ nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, PRBool *_retval) nsCOMPtr aPresContext; shell->GetPresContext(getter_AddRefs(aPresContext)); - nsCOMPtr esm; - if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) { - return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDOMEventReceiver*,this), aEvt, _retval); - } - - return NS_ERROR_FAILURE; + return aPresContext->EventStateManager()-> + DispatchNewEvent(NS_STATIC_CAST(nsIDOMEventReceiver*, this), + aEvt, _retval); } NS_IMETHODIMP diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index 553bbf7e012..79ce2e85ae6 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -977,13 +977,9 @@ IsTargetFocused(nsIDOMEventTarget* aTarget) if (!presContext) return PR_FALSE; - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - if (!esm) - return PR_FALSE; - nsCOMPtr focusedContent; - esm->GetFocusedContent(getter_AddRefs(focusedContent)); + presContext->EventStateManager()-> + GetFocusedContent(getter_AddRefs(focusedContent)); // focusedContent will be null in the case where the document has focus, // and so will content. diff --git a/mozilla/embedding/components/find/src/nsWebBrowserFind.cpp b/mozilla/embedding/components/find/src/nsWebBrowserFind.cpp index 98eedbf41a0..43b67ee1adb 100644 --- a/mozilla/embedding/components/find/src/nsWebBrowserFind.cpp +++ b/mozilla/embedding/components/find/src/nsWebBrowserFind.cpp @@ -629,13 +629,9 @@ void nsWebBrowserFind::MoveFocusToCaret(nsIDOMWindow *aWindow) if (!presContext) return; - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - - if (esm) { - PRBool isSelectionWithFocus; - esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); - } + PRBool isSelectionWithFocus; + presContext->EventStateManager()->MoveFocusToCaret(PR_TRUE, + &isSelectionWithFocus); } /* diff --git a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp index 71ba3466a36..46125fb4d64 100644 --- a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp +++ b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp @@ -130,10 +130,7 @@ inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) shell->GetPresContext(getter_AddRefs(presContext)); NS_ASSERTION(presContext, "No pres context"); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); - - return esm; + return presContext->EventStateManager(); } nsPoint diff --git a/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index 9ab53d5f25c..c98622faca4 100644 --- a/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -935,8 +935,8 @@ nsTypeAheadFind::HandleChar(PRUnichar aChar) NS_ENSURE_TRUE(presShell, NS_OK); presShell->GetPresContext(getter_AddRefs(presContext)); NS_ENSURE_TRUE(presContext, NS_OK); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); + + nsIEventStateManager *esm = presContext->EventStateManager(); esm->GetFocusedContent(getter_AddRefs(focusedContent)); if (focusedContent) { mIsFindingText = PR_TRUE; // prevent selection listener from calling CancelFind() @@ -1362,14 +1362,13 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, SetSelectionLook(presShell, PR_TRUE, mRepeatingMode != eRepeatingForward && mRepeatingMode != eRepeatingReverse); - nsCOMPtr esm; - presContext->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = presContext->EventStateManager(); + + PRBool isSelectionWithFocus; + esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); + nsCOMPtr focusedContent; - if (esm) { - PRBool isSelectionWithFocus; - esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); - esm->GetFocusedContent(getter_AddRefs(focusedContent)); - } + esm->GetFocusedContent(getter_AddRefs(focusedContent)); DisplayStatus(PR_TRUE, focusedContent, PR_FALSE); diff --git a/mozilla/gfx/src/gtk/nsNativeThemeGTK.cpp b/mozilla/gfx/src/gtk/nsNativeThemeGTK.cpp index 5a1c2641410..5fd6ffce0a5 100644 --- a/mozilla/gfx/src/gtk/nsNativeThemeGTK.cpp +++ b/mozilla/gfx/src/gtk/nsNativeThemeGTK.cpp @@ -154,10 +154,8 @@ static PRInt32 GetContentState(nsIFrame* aFrame) nsCOMPtr context; shell->GetPresContext(getter_AddRefs(context)); - nsCOMPtr esm; - shell->GetPresContext()->GetEventStateManager(getter_AddRefs(esm)); PRInt32 flags = 0; - esm->GetContentState(aFrame->GetContent(), flags); + context->EventStateManager()->GetContentState(aFrame->GetContent(), flags); return flags; } diff --git a/mozilla/gfx/src/shared/nsNativeTheme.cpp b/mozilla/gfx/src/shared/nsNativeTheme.cpp index 352dad60744..a6894c2893b 100644 --- a/mozilla/gfx/src/shared/nsNativeTheme.cpp +++ b/mozilla/gfx/src/shared/nsNativeTheme.cpp @@ -103,10 +103,8 @@ nsNativeTheme::GetContentState(nsIFrame* aFrame, PRUint8 aWidgetType) nsCOMPtr context; shell->GetPresContext(getter_AddRefs(context)); - nsCOMPtr esm; - context->GetEventStateManager(getter_AddRefs(esm)); PRInt32 flags = 0; - esm->GetContentState(aFrame->GetContent(), flags); + context->EventStateManager()->GetContentState(aFrame->GetContent(), flags); if (isXULCheckboxRadio && aWidgetType == NS_THEME_RADIO) { if (IsFocused(aFrame)) diff --git a/mozilla/gfx/src/windows/nsNativeThemeWin.cpp b/mozilla/gfx/src/windows/nsNativeThemeWin.cpp index 646aed2cfeb..d78e7d776d6 100644 --- a/mozilla/gfx/src/windows/nsNativeThemeWin.cpp +++ b/mozilla/gfx/src/windows/nsNativeThemeWin.cpp @@ -328,10 +328,8 @@ static PRInt32 GetContentState(nsIFrame* aFrame) nsCOMPtr context; shell->GetPresContext(getter_AddRefs(context)); - nsCOMPtr esm; - context->GetEventStateManager(getter_AddRefs(esm)); PRInt32 flags = 0; - esm->GetContentState(aFrame->GetContent(), flags); + context->EventStateManager()->GetContentState(aFrame->GetContent(), flags); return flags; } diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index b007a1cfcaa..32dd45fc70c 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -68,6 +68,7 @@ #include "nsIScriptGlobalObject.h" #include "nsIDOMDocument.h" #include "nsAutoPtr.h" +#include "nsEventStateManager.h" #ifdef IBMBIDI #include "nsBidiPresUtils.h" #endif // IBMBIDI @@ -131,7 +132,6 @@ PR_STATIC_CALLBACK(PRBool) destroy_loads(nsHashKey *aKey, void *aData, void* clo static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #include "nsContentCID.h" -static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID); static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); @@ -622,6 +622,15 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) GetUserPreferences(); } + mEventManager = new nsEventStateManager(); + if (!mEventManager) + return NS_ERROR_OUT_OF_MEMORY; + + rv = mEventManager->Init(); + NS_ENSURE_SUCCESS(rv, rv); + + mEventManager->SetPresContext(this); + #ifdef DEBUG mInitialized = PR_TRUE; #endif @@ -1024,33 +1033,6 @@ nsPresContext::GetContainer() return result; } -nsIEventStateManager* -nsIPresContext::GetEventStateManager() -{ - if (!mEventManager) { - nsresult rv = CallCreateInstance(kEventStateManagerCID, &mEventManager); - if (NS_FAILED(rv)) { - return nsnull; - } - - //Not refcnted, set null in destructor - mEventManager->SetPresContext(this); - } - return mEventManager; -} - -NS_IMETHODIMP -nsPresContext::GetEventStateManager(nsIEventStateManager** aManager) -{ - NS_PRECONDITION(aManager, "null ptr"); - - *aManager = GetEventStateManager(); - if (!*aManager) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*aManager); - return NS_OK; -} - #ifdef IBMBIDI //ahmed NS_IMETHODIMP diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index c8f3d3ebd29..8da273ad8ce 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -344,10 +344,7 @@ public: NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; nsIDeviceContext* DeviceContext() { return mDeviceContext; } - - NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; - nsIEventStateManager* GetEventStateManager(); - + nsIEventStateManager* EventStateManager() { return mEventManager; } nsILanguageAtom* GetLanguage() { return mLanguage; } /** diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 8caf5a4bc69..cfefbd9b1ee 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -3834,11 +3834,7 @@ PresShell::RecreateFramesFor(nsIContent* aContent) NS_IMETHODIMP PresShell::ClearFrameRefs(nsIFrame* aFrame) { - nsIEventStateManager *manager; - if (NS_SUCCEEDED (mPresContext->GetEventStateManager(&manager))) { - manager->ClearFrameRefs(aFrame); - NS_RELEASE(manager); - } + mPresContext->EventStateManager()->ClearFrameRefs(aFrame); if (mCaret) { mCaret->ClearFrameRefs(aFrame); @@ -3905,13 +3901,12 @@ PresShell::CantRenderReplacedElement(nsIFrame* aFrame) NS_IMETHODIMP PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) { - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); + // Hold a reference to the ESM in case event dispatch tears us down. + nsCOMPtr esm = mPresContext->EventStateManager(); + if (aAnchorName.IsEmpty()) { NS_ASSERTION(!aScroll, "can't scroll to empty anchor name"); - if (esm) { - esm->SetContentState(nsnull, NS_EVENT_STATE_URLTARGET); - } + esm->SetContentState(nsnull, NS_EVENT_STATE_URLTARGET); return NS_OK; } @@ -4026,9 +4021,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) } } - if (esm) { - esm->SetContentState(content, NS_EVENT_STATE_URLTARGET); - } + esm->SetContentState(content, NS_EVENT_STATE_URLTARGET); if (content) { // Flush notifications so we scroll to the right place @@ -4085,10 +4078,8 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) } } - if (esm) { - PRBool isSelectionWithFocus; - esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); - } + PRBool isSelectionWithFocus; + esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); } } } else { @@ -5254,10 +5245,7 @@ PresShell::ContentReplaced(nsIDocument* aDocument, { // Notify the ESM that the content has been removed, so that // it can clean up any state related to the content. - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->ContentRemoved(aOldChild); + mPresContext->EventStateManager()->ContentRemoved(aOldChild); WillCauseReflow(); mFrameConstructor->ContentReplaced(mPresContext, aContainer, aOldChild, @@ -5274,10 +5262,7 @@ PresShell::ContentRemoved(nsIDocument *aDocument, { // Notify the ESM that the content has been removed, so that // it can clean up any state related to the content. - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->ContentRemoved(aChild); + mPresContext->EventStateManager()->ContentRemoved(aChild); WillCauseReflow(); mFrameConstructor->ContentRemoved(mPresContext, aContainer, aChild, @@ -5688,13 +5673,13 @@ nsresult PresShell::RetargetEventToParent(nsIView *aView, // docshell, until the newly loading document is displayed. nsCOMPtr kungFuDeathGrip(this); - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); - esm->SetFocusedContent(nsnull); - ContentStatesChanged(mDocument, aZombieFocusedContent, nsnull, NS_EVENT_STATE_FOCUS); - } + // hold a reference to the ESM across event dispatch + nsCOMPtr esm = mPresContext->EventStateManager(); + + esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + esm->SetFocusedContent(nsnull); + ContentStatesChanged(mDocument, aZombieFocusedContent, + nsnull, NS_EVENT_STATE_FOCUS); // Next, update the display so the old focus ring is no longer visible @@ -5795,10 +5780,9 @@ PresShell::HandleEvent(nsIView *aView, // key and IME events go to the focused frame nsCOMPtr manager; if ((NS_IS_KEY_EVENT(aEvent) || NS_IS_IME_EVENT(aEvent) || - aEvent->message == NS_CONTEXTMENU_KEY) && - NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(manager)))) { + aEvent->message == NS_CONTEXTMENU_KEY)) { - manager->GetFocusedFrame(&mCurrentEventFrame); + mPresContext->EventStateManager()->GetFocusedFrame(&mCurrentEventFrame); if (!mCurrentEventFrame) { #if defined(MOZ_X11) if (NS_IS_IME_EVENT(aEvent)) { @@ -6021,11 +6005,10 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, } #endif - nsCOMPtr manager; - nsresult rv = mPresContext->GetEventStateManager(getter_AddRefs(manager)); + nsCOMPtr manager = mPresContext->EventStateManager(); + nsresult rv = NS_OK; - if (NS_SUCCEEDED(rv) && - (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame())) { + if (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame()) { // 1. Give event to event manager for pre event state changes and // generation of synthetic events. diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index c8f3d3ebd29..8da273ad8ce 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -344,10 +344,7 @@ public: NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; nsIDeviceContext* DeviceContext() { return mDeviceContext; } - - NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; - nsIEventStateManager* GetEventStateManager(); - + nsIEventStateManager* EventStateManager() { return mEventManager; } nsILanguageAtom* GetLanguage() { return mLanguage; } /** diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index c8f3d3ebd29..8da273ad8ce 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -344,10 +344,7 @@ public: NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; nsIDeviceContext* DeviceContext() { return mDeviceContext; } - - NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; - nsIEventStateManager* GetEventStateManager(); - + nsIEventStateManager* EventStateManager() { return mEventManager; } nsILanguageAtom* GetLanguage() { return mLanguage; } /** diff --git a/mozilla/layout/base/src/Makefile.in b/mozilla/layout/base/src/Makefile.in index c0da1932296..f479cbcfb4d 100644 --- a/mozilla/layout/base/src/Makefile.in +++ b/mozilla/layout/base/src/Makefile.in @@ -79,7 +79,7 @@ FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk LOCAL_INCLUDES = \ - -I$(srcdir)/../../events/src \ + -I$(topsrcdir)/content/events/src \ -I$(srcdir)/../../html/base/src \ -I$(srcdir)/../../html/style/src \ -I$(srcdir)/../../xul/base/src \ diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index b007a1cfcaa..32dd45fc70c 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -68,6 +68,7 @@ #include "nsIScriptGlobalObject.h" #include "nsIDOMDocument.h" #include "nsAutoPtr.h" +#include "nsEventStateManager.h" #ifdef IBMBIDI #include "nsBidiPresUtils.h" #endif // IBMBIDI @@ -131,7 +132,6 @@ PR_STATIC_CALLBACK(PRBool) destroy_loads(nsHashKey *aKey, void *aData, void* clo static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #include "nsContentCID.h" -static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID); static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); @@ -622,6 +622,15 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) GetUserPreferences(); } + mEventManager = new nsEventStateManager(); + if (!mEventManager) + return NS_ERROR_OUT_OF_MEMORY; + + rv = mEventManager->Init(); + NS_ENSURE_SUCCESS(rv, rv); + + mEventManager->SetPresContext(this); + #ifdef DEBUG mInitialized = PR_TRUE; #endif @@ -1024,33 +1033,6 @@ nsPresContext::GetContainer() return result; } -nsIEventStateManager* -nsIPresContext::GetEventStateManager() -{ - if (!mEventManager) { - nsresult rv = CallCreateInstance(kEventStateManagerCID, &mEventManager); - if (NS_FAILED(rv)) { - return nsnull; - } - - //Not refcnted, set null in destructor - mEventManager->SetPresContext(this); - } - return mEventManager; -} - -NS_IMETHODIMP -nsPresContext::GetEventStateManager(nsIEventStateManager** aManager) -{ - NS_PRECONDITION(aManager, "null ptr"); - - *aManager = GetEventStateManager(); - if (!*aManager) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*aManager); - return NS_OK; -} - #ifdef IBMBIDI //ahmed NS_IMETHODIMP diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index 27fc0fcb731..9c6ec120897 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -47,7 +47,6 @@ #include "nsICharsetConverterManager.h" #include "nsILanguageAtomService.h" #include "nsIURL.h" -#include "nsIEventStateManager.h" #include "nsIObserver.h" #ifdef IBMBIDI #include "nsBidiUtils.h" @@ -94,10 +93,6 @@ public: virtual void SetPageDim(nsRect* aRect) = 0; NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const; NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const; - NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager); - nsIEventStateManager* GetEventStateManager() { - return nsIPresContext::GetEventStateManager(); - } NS_IMETHOD GetLanguageSpecificTransformType( nsLanguageSpecificTransformType* aType); diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 522fbeb94b2..424ec177574 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -51,7 +51,6 @@ #include "nsDOMCID.h" #include "nsCSSOMFactory.h" #include "nsInspectorCSSUtils.h" -#include "nsEventStateManager.h" #include "nsEventListenerManager.h" #include "nsGenericElement.h" #include "nsHTMLAtoms.h" @@ -537,7 +536,6 @@ MAKE_CTOR(CreateCaret, nsICaret, NS_NewCaret) MAKE_CTOR(CreateNameSpaceManager, nsINameSpaceManager, NS_GetNameSpaceManager) MAKE_CTOR(CreateEventListenerManager, nsIEventListenerManager, NS_NewEventListenerManager) -MAKE_CTOR(CreateEventStateManager, nsIEventStateManager, NS_NewEventStateManager) MAKE_CTOR(CreateDOMEventGroup, nsIDOMEventGroup, NS_NewDOMEventGroup) MAKE_CTOR(CreateDocumentViewer, nsIDocumentViewer, NS_NewDocumentViewer) MAKE_CTOR(CreateHTMLStyleSheet, nsIHTMLStyleSheet, NS_NewHTMLStyleSheet) @@ -925,11 +923,6 @@ static const nsModuleComponentInfo gComponents[] = { nsnull, CreateEventListenerManager }, - { "Event state manager", - NS_EVENTSTATEMANAGER_CID, - nsnull, - CreateEventStateManager }, - { "DOM Event group", NS_DOMEVENTGROUP_CID, nsnull, diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 8811bf89536..e21e65af6f5 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -2377,33 +2377,28 @@ nsComboboxControlFrame::Paint(nsIPresContext* aPresContext, // XXX This is only temporary // Only paint the focus if we're visible if (GetStyleVisibility()->IsVisible()) { - nsCOMPtr stateManager; - nsresult rv = mPresContext->GetEventStateManager(getter_AddRefs(stateManager)); - if (NS_SUCCEEDED(rv)) { - if (!nsFormControlHelper::GetDisabled(mContent) && mFocused == this) { - aRenderingContext.SetLineStyle(nsLineStyle_kDotted); - aRenderingContext.SetColor(0); - } else { - aRenderingContext.SetColor(GetStyleBackground()->mBackgroundColor); - aRenderingContext.SetLineStyle(nsLineStyle_kSolid); - } - //aRenderingContext.DrawRect(clipRect); - float p2t; - p2t = aPresContext->PixelsToTwips(); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - clipRect.width -= onePixel; - clipRect.height -= onePixel; - aRenderingContext.DrawLine(clipRect.x, clipRect.y, - clipRect.x+clipRect.width, clipRect.y); - aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y, - clipRect.x+clipRect.width, clipRect.y+clipRect.height); - aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height, - clipRect.x, clipRect.y+clipRect.height); - aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, - clipRect.x, clipRect.y); - aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, - clipRect.x, clipRect.y); + if (!nsFormControlHelper::GetDisabled(mContent) && mFocused == this) { + aRenderingContext.SetLineStyle(nsLineStyle_kDotted); + aRenderingContext.SetColor(0); + } else { + aRenderingContext.SetColor(GetStyleBackground()->mBackgroundColor); + aRenderingContext.SetLineStyle(nsLineStyle_kSolid); } + //aRenderingContext.DrawRect(clipRect); + float p2t = aPresContext->PixelsToTwips(); + nscoord onePixel = NSIntPixelsToTwips(1, p2t); + clipRect.width -= onePixel; + clipRect.height -= onePixel; + aRenderingContext.DrawLine(clipRect.x, clipRect.y, + clipRect.x+clipRect.width, clipRect.y); + aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y, + clipRect.x+clipRect.width, clipRect.y+clipRect.height); + aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height, + clipRect.x, clipRect.y+clipRect.height); + aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, + clipRect.x, clipRect.y); + aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, + clipRect.x, clipRect.y); } ///////////////////// aRenderingContext.PopState(clipEmpty); diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 7913ec9f131..a87cab24a9a 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -605,13 +605,11 @@ nsFormControlFrame::RegUnRegAccessKey(nsIPresContext* aPresContext, nsIFrame * a } if (NS_CONTENT_ATTR_NOT_THERE != rv) { - nsCOMPtr stateManager; - if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(stateManager)))) { - if (aDoReg) { - return stateManager->RegisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); - } else { - return stateManager->UnregisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); - } + nsIEventStateManager *stateManager = aPresContext->EventStateManager(); + if (aDoReg) { + return stateManager->RegisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); + } else { + return stateManager->UnregisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); } } return NS_ERROR_FAILURE; diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 059a63683ce..1bc02a88c50 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -2865,10 +2865,8 @@ nsListControlFrame::FireMenuItemActiveEvent() NS_SUCCEEDED(manager->CreateEvent(mPresContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(NS_LITERAL_STRING("DOMMenuItemActive"), PR_TRUE, PR_TRUE); PRBool noDefault; - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->DispatchNewEvent(mContent, event, &noDefault); + mPresContext->EventStateManager()->DispatchNewEvent(mContent, event, + &noDefault); } } #endif @@ -2897,18 +2895,21 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, printf("-->\n"); #endif - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr stateManager; - if (NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(stateManager)))) { - nsCOMPtr content; - stateManager->GetEventTargetContent(nsnull, getter_AddRefs(content)); + nsresult rv; + + nsCOMPtr content; + mPresContext->EventStateManager()-> + GetEventTargetContent(nsnull, getter_AddRefs(content)); - nsCOMPtr optionContent = GetOptionFromContent(content); - if (optionContent) { - aCurIndex = GetIndexFromContent(optionContent); - rv = NS_OK; - } + nsCOMPtr optionContent = GetOptionFromContent(content); + if (optionContent) { + aCurIndex = GetIndexFromContent(optionContent); + rv = NS_OK; + } else { + rv = NS_ERROR_FAILURE; } + + return rv; } diff --git a/mozilla/layout/generic/nsAreaFrame.cpp b/mozilla/layout/generic/nsAreaFrame.cpp index 753ebd3c33b..7af797c3bd0 100644 --- a/mozilla/layout/generic/nsAreaFrame.cpp +++ b/mozilla/layout/generic/nsAreaFrame.cpp @@ -110,18 +110,14 @@ nsAreaFrame::RegUnregAccessKey(nsIPresContext* aPresContext, // With a valid PresContext we can get the ESM // and register the access key - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = aPresContext->EventStateManager(); + nsresult rv; - nsresult rv = NS_OK; - - if (esm) { - PRUint32 key = accessKey.First(); - if (aDoReg) - rv = esm->RegisterAccessKey(mContent, key); - else - rv = esm->UnregisterAccessKey(mContent, key); - } + PRUint32 key = accessKey.First(); + if (aDoReg) + rv = esm->RegisterAccessKey(mContent, key); + else + rv = esm->UnregisterAccessKey(mContent, key); return rv; } diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index a0c19f1784e..3eefd27d9b0 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -1286,12 +1286,8 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, //We often get out of sync state issues with mousedown events that //get interrupted by alerts/dialogs. //Check with the ESM to see if we should process this one - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (!esm) - return NS_ERROR_FAILURE; PRBool eventOK; - esm->EventStatusOK(aEvent, &eventOK); + aPresContext->EventStateManager()->EventStatusOK(aEvent, &eventOK); if (!eventOK) return NS_OK; diff --git a/mozilla/layout/generic/nsHTMLFrame.cpp b/mozilla/layout/generic/nsHTMLFrame.cpp index 0c1a4cfea44..30fd460c50a 100644 --- a/mozilla/layout/generic/nsHTMLFrame.cpp +++ b/mozilla/layout/generic/nsHTMLFrame.cpp @@ -396,11 +396,8 @@ CanvasFrame::Paint(nsIPresContext* aPresContext, #ifdef DEBUG_CANVAS_FOCUS nsCOMPtr focusContent; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->GetFocusedContent(getter_AddRefs(focusContent)); - } + aPresContext->EventStateManager()-> + GetFocusedContent(getter_AddRefs(focusContent)); PRBool hasFocus = PR_FALSE; nsCOMPtr container; @@ -424,49 +421,44 @@ CanvasFrame::Paint(nsIPresContext* aPresContext, const nsStyleVisibility* vis = (const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility); // Only paint the focus if we're visible if (vis->IsVisible()) { - nsCOMPtr stateManager; - nsresult rv = aPresContext->GetEventStateManager(getter_AddRefs(stateManager)); - if (NS_SUCCEEDED(rv)) { - nsIFrame * parentFrame = GetParent(); - nsIView* parentView = parentFrame->GetView(); + nsIFrame * parentFrame = GetParent(); + nsIView* parentView = parentFrame->GetView(); - nsIScrollableView* scrollableView; - if (NS_SUCCEEDED(CallQueryInterface(parentView, &scrollableView))) { - nscoord width, height; - scrollableView->GetContainerSize(&width, &height); - const nsIView* clippedView; - scrollableView->GetClipView(&clippedView); - nsRect vcr = clippedView->GetBounds(); - focusRect.width = vcr.width; - focusRect.height = vcr.height; - nscoord x,y; - scrollableView->GetScrollPosition(x, y); - focusRect.x += x; - focusRect.y += y; - } - - nsStyleOutline outlineStyle(aPresContext); - outlineStyle.SetOutlineStyle(NS_STYLE_BORDER_STYLE_DOTTED); - outlineStyle.SetOutlineInvert(); - - float p2t; - p2t = aPresContext->PixelsToTwips(); - // XXX the CSS border for links is specified as 2px, but it - // is only drawn as 1px. Match this here. - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - - nsRect borderInside(focusRect.x + onePixel, - focusRect.y + onePixel, - focusRect.width - 2 * onePixel, - focusRect.height - 2 * onePixel); - - nsCSSRendering::DrawDashedSides(0, aRenderingContext, - focusRect, nsnull, - nsnull, &outlineStyle, - PR_TRUE, focusRect, - borderInside, 0, - nsnull); + nsIScrollableView* scrollableView; + if (NS_SUCCEEDED(CallQueryInterface(parentView, &scrollableView))) { + nscoord width, height; + scrollableView->GetContainerSize(&width, &height); + const nsIView* clippedView; + scrollableView->GetClipView(&clippedView); + nsRect vcr = clippedView->GetBounds(); + focusRect.width = vcr.width; + focusRect.height = vcr.height; + nscoord x,y; + scrollableView->GetScrollPosition(x, y); + focusRect.x += x; + focusRect.y += y; } + + nsStyleOutline outlineStyle(aPresContext); + outlineStyle.SetOutlineStyle(NS_STYLE_BORDER_STYLE_DOTTED); + outlineStyle.SetOutlineInvert(); + + float p2t = aPresContext->PixelsToTwips(); + // XXX the CSS border for links is specified as 2px, but it + // is only drawn as 1px. Match this here. + nscoord onePixel = NSIntPixelsToTwips(1, p2t); + + nsRect borderInside(focusRect.x + onePixel, + focusRect.y + onePixel, + focusRect.width - 2 * onePixel, + focusRect.height - 2 * onePixel); + + nsCSSRendering::DrawDashedSides(0, aRenderingContext, + focusRect, nsnull, + nsnull, &outlineStyle, + PR_TRUE, focusRect, + borderInside, 0, + nsnull); } } } diff --git a/mozilla/layout/html/base/src/nsAreaFrame.cpp b/mozilla/layout/html/base/src/nsAreaFrame.cpp index 753ebd3c33b..7af797c3bd0 100644 --- a/mozilla/layout/html/base/src/nsAreaFrame.cpp +++ b/mozilla/layout/html/base/src/nsAreaFrame.cpp @@ -110,18 +110,14 @@ nsAreaFrame::RegUnregAccessKey(nsIPresContext* aPresContext, // With a valid PresContext we can get the ESM // and register the access key - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = aPresContext->EventStateManager(); + nsresult rv; - nsresult rv = NS_OK; - - if (esm) { - PRUint32 key = accessKey.First(); - if (aDoReg) - rv = esm->RegisterAccessKey(mContent, key); - else - rv = esm->UnregisterAccessKey(mContent, key); - } + PRUint32 key = accessKey.First(); + if (aDoReg) + rv = esm->RegisterAccessKey(mContent, key); + else + rv = esm->UnregisterAccessKey(mContent, key); return rv; } diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index a0c19f1784e..3eefd27d9b0 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -1286,12 +1286,8 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, //We often get out of sync state issues with mousedown events that //get interrupted by alerts/dialogs. //Check with the ESM to see if we should process this one - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (!esm) - return NS_ERROR_FAILURE; PRBool eventOK; - esm->EventStatusOK(aEvent, &eventOK); + aPresContext->EventStateManager()->EventStatusOK(aEvent, &eventOK); if (!eventOK) return NS_OK; diff --git a/mozilla/layout/html/base/src/nsHTMLFrame.cpp b/mozilla/layout/html/base/src/nsHTMLFrame.cpp index 0c1a4cfea44..30fd460c50a 100644 --- a/mozilla/layout/html/base/src/nsHTMLFrame.cpp +++ b/mozilla/layout/html/base/src/nsHTMLFrame.cpp @@ -396,11 +396,8 @@ CanvasFrame::Paint(nsIPresContext* aPresContext, #ifdef DEBUG_CANVAS_FOCUS nsCOMPtr focusContent; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->GetFocusedContent(getter_AddRefs(focusContent)); - } + aPresContext->EventStateManager()-> + GetFocusedContent(getter_AddRefs(focusContent)); PRBool hasFocus = PR_FALSE; nsCOMPtr container; @@ -424,49 +421,44 @@ CanvasFrame::Paint(nsIPresContext* aPresContext, const nsStyleVisibility* vis = (const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility); // Only paint the focus if we're visible if (vis->IsVisible()) { - nsCOMPtr stateManager; - nsresult rv = aPresContext->GetEventStateManager(getter_AddRefs(stateManager)); - if (NS_SUCCEEDED(rv)) { - nsIFrame * parentFrame = GetParent(); - nsIView* parentView = parentFrame->GetView(); + nsIFrame * parentFrame = GetParent(); + nsIView* parentView = parentFrame->GetView(); - nsIScrollableView* scrollableView; - if (NS_SUCCEEDED(CallQueryInterface(parentView, &scrollableView))) { - nscoord width, height; - scrollableView->GetContainerSize(&width, &height); - const nsIView* clippedView; - scrollableView->GetClipView(&clippedView); - nsRect vcr = clippedView->GetBounds(); - focusRect.width = vcr.width; - focusRect.height = vcr.height; - nscoord x,y; - scrollableView->GetScrollPosition(x, y); - focusRect.x += x; - focusRect.y += y; - } - - nsStyleOutline outlineStyle(aPresContext); - outlineStyle.SetOutlineStyle(NS_STYLE_BORDER_STYLE_DOTTED); - outlineStyle.SetOutlineInvert(); - - float p2t; - p2t = aPresContext->PixelsToTwips(); - // XXX the CSS border for links is specified as 2px, but it - // is only drawn as 1px. Match this here. - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - - nsRect borderInside(focusRect.x + onePixel, - focusRect.y + onePixel, - focusRect.width - 2 * onePixel, - focusRect.height - 2 * onePixel); - - nsCSSRendering::DrawDashedSides(0, aRenderingContext, - focusRect, nsnull, - nsnull, &outlineStyle, - PR_TRUE, focusRect, - borderInside, 0, - nsnull); + nsIScrollableView* scrollableView; + if (NS_SUCCEEDED(CallQueryInterface(parentView, &scrollableView))) { + nscoord width, height; + scrollableView->GetContainerSize(&width, &height); + const nsIView* clippedView; + scrollableView->GetClipView(&clippedView); + nsRect vcr = clippedView->GetBounds(); + focusRect.width = vcr.width; + focusRect.height = vcr.height; + nscoord x,y; + scrollableView->GetScrollPosition(x, y); + focusRect.x += x; + focusRect.y += y; } + + nsStyleOutline outlineStyle(aPresContext); + outlineStyle.SetOutlineStyle(NS_STYLE_BORDER_STYLE_DOTTED); + outlineStyle.SetOutlineInvert(); + + float p2t = aPresContext->PixelsToTwips(); + // XXX the CSS border for links is specified as 2px, but it + // is only drawn as 1px. Match this here. + nscoord onePixel = NSIntPixelsToTwips(1, p2t); + + nsRect borderInside(focusRect.x + onePixel, + focusRect.y + onePixel, + focusRect.width - 2 * onePixel, + focusRect.height - 2 * onePixel); + + nsCSSRendering::DrawDashedSides(0, aRenderingContext, + focusRect, nsnull, + nsnull, &outlineStyle, + PR_TRUE, focusRect, + borderInside, 0, + nsnull); } } } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 8caf5a4bc69..cfefbd9b1ee 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -3834,11 +3834,7 @@ PresShell::RecreateFramesFor(nsIContent* aContent) NS_IMETHODIMP PresShell::ClearFrameRefs(nsIFrame* aFrame) { - nsIEventStateManager *manager; - if (NS_SUCCEEDED (mPresContext->GetEventStateManager(&manager))) { - manager->ClearFrameRefs(aFrame); - NS_RELEASE(manager); - } + mPresContext->EventStateManager()->ClearFrameRefs(aFrame); if (mCaret) { mCaret->ClearFrameRefs(aFrame); @@ -3905,13 +3901,12 @@ PresShell::CantRenderReplacedElement(nsIFrame* aFrame) NS_IMETHODIMP PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) { - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); + // Hold a reference to the ESM in case event dispatch tears us down. + nsCOMPtr esm = mPresContext->EventStateManager(); + if (aAnchorName.IsEmpty()) { NS_ASSERTION(!aScroll, "can't scroll to empty anchor name"); - if (esm) { - esm->SetContentState(nsnull, NS_EVENT_STATE_URLTARGET); - } + esm->SetContentState(nsnull, NS_EVENT_STATE_URLTARGET); return NS_OK; } @@ -4026,9 +4021,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) } } - if (esm) { - esm->SetContentState(content, NS_EVENT_STATE_URLTARGET); - } + esm->SetContentState(content, NS_EVENT_STATE_URLTARGET); if (content) { // Flush notifications so we scroll to the right place @@ -4085,10 +4078,8 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) } } - if (esm) { - PRBool isSelectionWithFocus; - esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); - } + PRBool isSelectionWithFocus; + esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus); } } } else { @@ -5254,10 +5245,7 @@ PresShell::ContentReplaced(nsIDocument* aDocument, { // Notify the ESM that the content has been removed, so that // it can clean up any state related to the content. - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->ContentRemoved(aOldChild); + mPresContext->EventStateManager()->ContentRemoved(aOldChild); WillCauseReflow(); mFrameConstructor->ContentReplaced(mPresContext, aContainer, aOldChild, @@ -5274,10 +5262,7 @@ PresShell::ContentRemoved(nsIDocument *aDocument, { // Notify the ESM that the content has been removed, so that // it can clean up any state related to the content. - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->ContentRemoved(aChild); + mPresContext->EventStateManager()->ContentRemoved(aChild); WillCauseReflow(); mFrameConstructor->ContentRemoved(mPresContext, aContainer, aChild, @@ -5688,13 +5673,13 @@ nsresult PresShell::RetargetEventToParent(nsIView *aView, // docshell, until the newly loading document is displayed. nsCOMPtr kungFuDeathGrip(this); - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) { - esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); - esm->SetFocusedContent(nsnull); - ContentStatesChanged(mDocument, aZombieFocusedContent, nsnull, NS_EVENT_STATE_FOCUS); - } + // hold a reference to the ESM across event dispatch + nsCOMPtr esm = mPresContext->EventStateManager(); + + esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + esm->SetFocusedContent(nsnull); + ContentStatesChanged(mDocument, aZombieFocusedContent, + nsnull, NS_EVENT_STATE_FOCUS); // Next, update the display so the old focus ring is no longer visible @@ -5795,10 +5780,9 @@ PresShell::HandleEvent(nsIView *aView, // key and IME events go to the focused frame nsCOMPtr manager; if ((NS_IS_KEY_EVENT(aEvent) || NS_IS_IME_EVENT(aEvent) || - aEvent->message == NS_CONTEXTMENU_KEY) && - NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(manager)))) { + aEvent->message == NS_CONTEXTMENU_KEY)) { - manager->GetFocusedFrame(&mCurrentEventFrame); + mPresContext->EventStateManager()->GetFocusedFrame(&mCurrentEventFrame); if (!mCurrentEventFrame) { #if defined(MOZ_X11) if (NS_IS_IME_EVENT(aEvent)) { @@ -6021,11 +6005,10 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, } #endif - nsCOMPtr manager; - nsresult rv = mPresContext->GetEventStateManager(getter_AddRefs(manager)); + nsCOMPtr manager = mPresContext->EventStateManager(); + nsresult rv = NS_OK; - if (NS_SUCCEEDED(rv) && - (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame())) { + if (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame()) { // 1. Give event to event manager for pre event state changes and // generation of synthetic events. diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 8811bf89536..e21e65af6f5 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -2377,33 +2377,28 @@ nsComboboxControlFrame::Paint(nsIPresContext* aPresContext, // XXX This is only temporary // Only paint the focus if we're visible if (GetStyleVisibility()->IsVisible()) { - nsCOMPtr stateManager; - nsresult rv = mPresContext->GetEventStateManager(getter_AddRefs(stateManager)); - if (NS_SUCCEEDED(rv)) { - if (!nsFormControlHelper::GetDisabled(mContent) && mFocused == this) { - aRenderingContext.SetLineStyle(nsLineStyle_kDotted); - aRenderingContext.SetColor(0); - } else { - aRenderingContext.SetColor(GetStyleBackground()->mBackgroundColor); - aRenderingContext.SetLineStyle(nsLineStyle_kSolid); - } - //aRenderingContext.DrawRect(clipRect); - float p2t; - p2t = aPresContext->PixelsToTwips(); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - clipRect.width -= onePixel; - clipRect.height -= onePixel; - aRenderingContext.DrawLine(clipRect.x, clipRect.y, - clipRect.x+clipRect.width, clipRect.y); - aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y, - clipRect.x+clipRect.width, clipRect.y+clipRect.height); - aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height, - clipRect.x, clipRect.y+clipRect.height); - aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, - clipRect.x, clipRect.y); - aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, - clipRect.x, clipRect.y); + if (!nsFormControlHelper::GetDisabled(mContent) && mFocused == this) { + aRenderingContext.SetLineStyle(nsLineStyle_kDotted); + aRenderingContext.SetColor(0); + } else { + aRenderingContext.SetColor(GetStyleBackground()->mBackgroundColor); + aRenderingContext.SetLineStyle(nsLineStyle_kSolid); } + //aRenderingContext.DrawRect(clipRect); + float p2t = aPresContext->PixelsToTwips(); + nscoord onePixel = NSIntPixelsToTwips(1, p2t); + clipRect.width -= onePixel; + clipRect.height -= onePixel; + aRenderingContext.DrawLine(clipRect.x, clipRect.y, + clipRect.x+clipRect.width, clipRect.y); + aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y, + clipRect.x+clipRect.width, clipRect.y+clipRect.height); + aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height, + clipRect.x, clipRect.y+clipRect.height); + aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, + clipRect.x, clipRect.y); + aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, + clipRect.x, clipRect.y); } ///////////////////// aRenderingContext.PopState(clipEmpty); diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 7913ec9f131..a87cab24a9a 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -605,13 +605,11 @@ nsFormControlFrame::RegUnRegAccessKey(nsIPresContext* aPresContext, nsIFrame * a } if (NS_CONTENT_ATTR_NOT_THERE != rv) { - nsCOMPtr stateManager; - if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(stateManager)))) { - if (aDoReg) { - return stateManager->RegisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); - } else { - return stateManager->UnregisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); - } + nsIEventStateManager *stateManager = aPresContext->EventStateManager(); + if (aDoReg) { + return stateManager->RegisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); + } else { + return stateManager->UnregisterAccessKey(aFrame->GetContent(), (PRUint32)accessKey.First()); } } return NS_ERROR_FAILURE; diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 059a63683ce..1bc02a88c50 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -2865,10 +2865,8 @@ nsListControlFrame::FireMenuItemActiveEvent() NS_SUCCEEDED(manager->CreateEvent(mPresContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(NS_LITERAL_STRING("DOMMenuItemActive"), PR_TRUE, PR_TRUE); PRBool noDefault; - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->DispatchNewEvent(mContent, event, &noDefault); + mPresContext->EventStateManager()->DispatchNewEvent(mContent, event, + &noDefault); } } #endif @@ -2897,18 +2895,21 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, printf("-->\n"); #endif - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr stateManager; - if (NS_SUCCEEDED(mPresContext->GetEventStateManager(getter_AddRefs(stateManager)))) { - nsCOMPtr content; - stateManager->GetEventTargetContent(nsnull, getter_AddRefs(content)); + nsresult rv; + + nsCOMPtr content; + mPresContext->EventStateManager()-> + GetEventTargetContent(nsnull, getter_AddRefs(content)); - nsCOMPtr optionContent = GetOptionFromContent(content); - if (optionContent) { - aCurIndex = GetIndexFromContent(optionContent); - rv = NS_OK; - } + nsCOMPtr optionContent = GetOptionFromContent(content); + if (optionContent) { + aCurIndex = GetIndexFromContent(optionContent); + rv = NS_OK; + } else { + rv = NS_ERROR_FAILURE; } + + return rv; } diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index 488c3d3c034..b7d82ccb23f 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -3128,12 +3128,7 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext, mParentContent = aContent->GetParent(); // get the event state - nsIEventStateManager* eventStateManager = nsnull; - mPresContext->GetEventStateManager(&eventStateManager); - if(eventStateManager) { - eventStateManager->GetContentState(aContent, mEventState); - NS_RELEASE(eventStateManager); - } + mPresContext->EventStateManager()->GetContentState(aContent, mEventState); // get the styledcontent interface and the ID if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&mStyledContent))) { diff --git a/mozilla/layout/xul/base/src/nsBoxFrame.cpp b/mozilla/layout/xul/base/src/nsBoxFrame.cpp index 71267d954b2..8f6046e143a 100644 --- a/mozilla/layout/xul/base/src/nsBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsBoxFrame.cpp @@ -2587,18 +2587,15 @@ nsBoxFrame::RegUnregAccessKey(nsIPresContext* aPresContext, PRBool aDoReg) // With a valid PresContext we can get the ESM // and register the access key - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = aPresContext->EventStateManager(); - nsresult rv = NS_OK; + nsresult rv; - if (esm) { - PRUint32 key = accessKey.First(); - if (aDoReg) - rv = esm->RegisterAccessKey(mContent, key); - else - rv = esm->UnregisterAccessKey(mContent, key); - } + PRUint32 key = accessKey.First(); + if (aDoReg) + rv = esm->RegisterAccessKey(mContent, key); + else + rv = esm->UnregisterAccessKey(mContent, key); return rv; } @@ -2616,10 +2613,8 @@ nsBoxFrame::FireDOMEvent(nsIPresContext *aPresContext, const nsAString& aDOMEven NS_SUCCEEDED(manager->CreateEvent(aPresContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(aDOMEventName, PR_TRUE, PR_TRUE); PRBool noDefault; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - if (esm) - esm->DispatchNewEvent(mContent, event, &noDefault); + aPresContext->EventStateManager()->DispatchNewEvent(mContent, event, + &noDefault); } } } diff --git a/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp b/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp index 0a0b893aad7..0e6f211c419 100644 --- a/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp @@ -105,10 +105,10 @@ nsButtonBoxFrame::HandleEvent(nsIPresContext* aPresContext, if (NS_KEY_EVENT == aEvent->eventStructType) { nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; if (NS_VK_SPACE == keyEvent->keyCode) { - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); - esm->SetContentState(mContent, NS_EVENT_STATE_HOVER | - NS_EVENT_STATE_ACTIVE); // :hover:active state + nsIEventStateManager *esm = aPresContext->EventStateManager(); + // :hover:active state + esm->SetContentState(mContent, + NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE); } } break; @@ -132,8 +132,7 @@ nsButtonBoxFrame::HandleEvent(nsIPresContext* aPresContext, // only activate on keyup if we're already in the :hover:active state PRInt32 buttonState; const PRInt32 activeHover = NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER; - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = aPresContext->EventStateManager(); esm->GetContentState(mContent, buttonState); if ((buttonState & activeHover) == activeHover) { esm->SetContentState(nsnull, activeHover); // return to normal state diff --git a/mozilla/layout/xul/base/src/nsMenuFrame.cpp b/mozilla/layout/xul/base/src/nsMenuFrame.cpp index 28b1ddad0ae..219cacd8922 100644 --- a/mozilla/layout/xul/base/src/nsMenuFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuFrame.cpp @@ -875,10 +875,12 @@ nsMenuFrame::OpenMenuInternal(PRBool aActivateFlag) // XXX, bug 137033, In Windows, if mouse is outside the window when the menupopup closes, no // mouse_enter/mouse_exit event will be fired to clear current hover state, we should clear it manually. // This code may not the best solution, but we can leave it here untill we find the better approach. - nsCOMPtr esm; - mPresContext->GetEventStateManager(getter_AddRefs(esm)); + + nsIEventStateManager *esm = mPresContext->EventStateManager(); + PRInt32 state; esm->GetContentState(menuPopup->GetContent(), state); + if (state & NS_EVENT_STATE_HOVER) esm->SetContentState(nsnull, NS_EVENT_STATE_HOVER); } diff --git a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp index ecf1d9fcc96..05d144ab4ba 100644 --- a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp @@ -910,20 +910,17 @@ nsTextBoxFrame::RegUnregAccessKey(nsIPresContext* aPresContext, if (accessKey.IsEmpty()) return NS_OK; - nsresult rv = NS_OK; + nsresult rv; // With a valid PresContext we can get the ESM // and (un)register the access key - nsCOMPtr esm; - aPresContext->GetEventStateManager(getter_AddRefs(esm)); + nsIEventStateManager *esm = aPresContext->EventStateManager(); - if (esm) { - PRUint32 key = accessKey.First(); - if (aDoReg) - rv = esm->RegisterAccessKey(mContent, key); - else - rv = esm->UnregisterAccessKey(mContent, key); - } + PRUint32 key = accessKey.First(); + if (aDoReg) + rv = esm->RegisterAccessKey(mContent, key); + else + rv = esm->UnregisterAccessKey(mContent, key); return rv; }