From 327addc38ab76901467230fad4577b3ddd9e8938 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Sat, 22 Sep 2007 15:57:03 +0000 Subject: [PATCH] Bug 396652, gecko scrolls on activate event (mouse click) with gtk embeds, r+sr+a=roc, p=iainnicol-mozbugs2007@yahoo.co.uk+me --- content/events/src/nsEventStateManager.cpp | 19 +++-------- .../xul/content/src/nsXULPopupListener.cpp | 14 ++------ dom/public/base/nsIFocusController.h | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 94c64186e2d..2cd1b14bcb5 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1091,13 +1091,14 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, win->GetRootFocusController(); nsCOMPtr focusedElement; nsCOMPtr focusedWindow; + nsFocusScrollSuppressor scrollSuppressor; if (focusController) { // Obtain focus info from the focus controller. focusController->GetFocusedWindow(getter_AddRefs(focusedWindow)); focusController->GetFocusedElement(getter_AddRefs(focusedElement)); - focusController->SetSuppressFocusScroll(PR_TRUE); + scrollSuppressor.Init(focusController); focusController->SetActive(PR_TRUE); } @@ -1151,7 +1152,6 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, focusController->GetSuppressFocus(&isSuppressed); } - focusController->SetSuppressFocusScroll(PR_FALSE); } } break; @@ -3197,13 +3197,9 @@ nsEventStateManager::ChangeFocusWith(nsIContent* aFocusContent, // If this is called from mouse event, we lock to scroll. // Because the part of element is always in view. See bug 105894. - PRBool suppressFocusScroll = - focusController && (aFocusedWith == eEventFocusedByMouse); - if (suppressFocusScroll) { - PRBool currentState = PR_FALSE; - focusController->GetSuppressFocusScroll(¤tState); - NS_ASSERTION(!currentState, "locked scroll already!"); - focusController->SetSuppressFocusScroll(PR_TRUE); + nsFocusScrollSuppressor scrollSuppressor; + if (aFocusedWith == eEventFocusedByMouse) { + scrollSuppressor.Init(focusController); } aFocusContent->SetFocus(mPresContext); @@ -3225,11 +3221,6 @@ nsEventStateManager::ChangeFocusWith(nsIContent* aFocusContent, } } } - - // Unlock scroll - if (suppressFocusScroll) - focusController->SetSuppressFocusScroll(PR_FALSE); - return NS_OK; } diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index 3ff35a52343..77e12ffb73e 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -294,23 +294,13 @@ nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode) if (focusableContent) { // Lock to scroll by SetFocus. See bug 309075. - nsCOMPtr focusController = nsnull; - PRBool isAlreadySuppressed = PR_FALSE; + nsFocusScrollSuppressor scrollSuppressor; nsPIDOMWindow *ourWindow = doc->GetWindow(); if (ourWindow) { - focusController = ourWindow->GetRootFocusController(); - if (focusController) { - focusController->GetSuppressFocusScroll(&isAlreadySuppressed); - if (!isAlreadySuppressed) - focusController->SetSuppressFocusScroll(PR_TRUE); - } + scrollSuppressor.Init(ourWindow->GetRootFocusController()); } focusableContent->SetFocus(context); - - // Unlock scroll if it's needed. - if (focusController && !isAlreadySuppressed) - focusController->SetSuppressFocusScroll(PR_FALSE); } else if (!suppressBlur) esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS); diff --git a/dom/public/base/nsIFocusController.h b/dom/public/base/nsIFocusController.h index b8b930a833d..6670a746a2f 100644 --- a/dom/public/base/nsIFocusController.h +++ b/dom/public/base/nsIFocusController.h @@ -130,4 +130,37 @@ private: const char *mReason; }; +class nsFocusScrollSuppressor +{ +public: + nsFocusScrollSuppressor(nsIFocusController* aController = nsnull) + : mWasSuppressed(PR_FALSE) + { + Init(aController); + } + + ~nsFocusScrollSuppressor() + { + Init(nsnull); + } + + void Init(nsIFocusController* aController) + { + if (mController) { + mController->SetSuppressFocusScroll(mWasSuppressed); + } + + mController = aController; + if (mController) { + mController->GetSuppressFocusScroll(&mWasSuppressed); + if (!mWasSuppressed) { + mController->SetSuppressFocusScroll(PR_TRUE); + } + } + } +private: + nsCOMPtr mController; + PRBool mWasSuppressed; +}; + #endif // nsIFocusController_h__