diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 23db60d8cdcd..ca9a22a17853 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -14,6 +14,7 @@ #include "nsCOMPtr.h" #include "nsEventStateManager.h" +#include "nsFocusManager.h" #include "nsIMEStateManager.h" #include "nsContentEventHandler.h" #include "nsIContent.h" @@ -1955,7 +1956,7 @@ nsEventStateManager::FireContextClick() } nsIDocument* doc = mGestureDownContent->GetCurrentDoc(); - nsAutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc); + AutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc); // dispatch to DOM nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event, @@ -5848,4 +5849,51 @@ nsEventStateManager::Prefs::GetAccessModifierMask(int32_t aItemType) } } +/******************************************************************/ +/* mozilla::AutoHandlingUserInputStatePusher */ +/******************************************************************/ + +AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher( + bool aIsHandlingUserInput, + WidgetEvent* aEvent, + nsIDocument* aDocument) : + mIsHandlingUserInput(aIsHandlingUserInput), + mIsMouseDown(aEvent && aEvent->message == NS_MOUSE_BUTTON_DOWN), + mResetFMMouseDownState(false) +{ + if (!aIsHandlingUserInput) { + return; + } + nsEventStateManager::StartHandlingUserInput(); + if (!mIsMouseDown) { + return; + } + nsIPresShell::SetCapturingContent(nullptr, 0); + nsIPresShell::AllowMouseCapture(true); + if (!aDocument || !aEvent->mFlags.mIsTrusted) { + return; + } + nsFocusManager* fm = nsFocusManager::GetFocusManager(); + NS_ENSURE_TRUE_VOID(fm); + fm->SetMouseButtonDownHandlingDocument(aDocument); + mResetFMMouseDownState = true; +} + +AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher() +{ + if (!mIsHandlingUserInput) { + return; + } + nsEventStateManager::StopHandlingUserInput(); + if (!mIsMouseDown) { + return; + } + nsIPresShell::AllowMouseCapture(false); + if (!mResetFMMouseDownState) { + return; + } + nsFocusManager* fm = nsFocusManager::GetFocusManager(); + NS_ENSURE_TRUE_VOID(fm); + fm->SetMouseButtonDownHandlingDocument(nullptr); +} diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index f8ea957d115a..8128cb48af2f 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -6,7 +6,6 @@ #ifndef nsEventStateManager_h__ #define nsEventStateManager_h__ -#include "mozilla/BasicEvents.h" #include "mozilla/EventForwards.h" #include "mozilla/TypedEnum.h" @@ -15,11 +14,11 @@ #include "nsCOMPtr.h" #include "nsCOMArray.h" #include "nsCycleCollectionParticipant.h" -#include "nsFocusManager.h" #include "mozilla/TimeStamp.h" #include "nsIFrame.h" #include "Units.h" +class nsFrameLoader; class nsIContent; class nsIDocument; class nsIDocShell; @@ -847,51 +846,19 @@ public: static void sClickHoldCallback ( nsITimer* aTimer, void* aESM ) ; }; +namespace mozilla { + /** * This class is used while processing real user input. During this time, popups * are allowed. For mousedown events, mouse capturing is also permitted. */ -class nsAutoHandlingUserInputStatePusher +class AutoHandlingUserInputStatePusher { public: - nsAutoHandlingUserInputStatePusher(bool aIsHandlingUserInput, - mozilla::WidgetEvent* aEvent, - nsIDocument* aDocument) - : mIsHandlingUserInput(aIsHandlingUserInput), - mIsMouseDown(aEvent && aEvent->message == NS_MOUSE_BUTTON_DOWN), - mResetFMMouseDownState(false) - { - if (aIsHandlingUserInput) { - nsEventStateManager::StartHandlingUserInput(); - if (mIsMouseDown) { - nsIPresShell::SetCapturingContent(nullptr, 0); - nsIPresShell::AllowMouseCapture(true); - if (aDocument && aEvent->mFlags.mIsTrusted) { - nsFocusManager* fm = nsFocusManager::GetFocusManager(); - if (fm) { - fm->SetMouseButtonDownHandlingDocument(aDocument); - mResetFMMouseDownState = true; - } - } - } - } - } - - ~nsAutoHandlingUserInputStatePusher() - { - if (mIsHandlingUserInput) { - nsEventStateManager::StopHandlingUserInput(); - if (mIsMouseDown) { - nsIPresShell::AllowMouseCapture(false); - if (mResetFMMouseDownState) { - nsFocusManager* fm = nsFocusManager::GetFocusManager(); - if (fm) { - fm->SetMouseButtonDownHandlingDocument(nullptr); - } - } - } - } - } + AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput, + WidgetEvent* aEvent, + nsIDocument* aDocument); + ~AutoHandlingUserInputStatePusher(); protected: bool mIsHandlingUserInput; @@ -904,6 +871,8 @@ private: static void operator delete(void* /*memory*/) {} }; +} // namespace mozilla + // Click and double-click events need to be handled even for content that // has no frame. This is required for Web compatibility. #define NS_EVENT_NEEDS_FRAME(event) \ diff --git a/content/html/content/src/HTMLFormElement.cpp b/content/html/content/src/HTMLFormElement.cpp index fe85fa24b2b5..4ae6ca35a727 100644 --- a/content/html/content/src/HTMLFormElement.cpp +++ b/content/html/content/src/HTMLFormElement.cpp @@ -807,9 +807,9 @@ HTMLFormElement::SubmitSubmission(nsFormSubmission* aFormSubmission) { nsAutoPopupStatePusher popupStatePusher(mSubmitPopupState); - nsAutoHandlingUserInputStatePusher userInpStatePusher( - mSubmitInitiatedFromUserInput, - nullptr, doc); + AutoHandlingUserInputStatePusher userInpStatePusher( + mSubmitInitiatedFromUserInput, + nullptr, doc); nsCOMPtr postDataStream; rv = aFormSubmission->GetEncodedSubmission(actionURI, diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 678ac1939781..e7174433985f 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6845,8 +6845,8 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) } } - nsAutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput, - aEvent, mDocument); + AutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput, + aEvent, mDocument); if (aEvent->mFlags.mIsTrusted && aEvent->message == NS_MOUSE_MOVE) { nsIPresShell::AllowMouseCapture( diff --git a/layout/xul/base/src/nsXULPopupManager.cpp b/layout/xul/base/src/nsXULPopupManager.cpp index d77021eaf659..fe417a45f97c 100644 --- a/layout/xul/base/src/nsXULPopupManager.cpp +++ b/layout/xul/base/src/nsXULPopupManager.cpp @@ -2354,8 +2354,8 @@ nsXULMenuCommandEvent::Run() if (mCloseMenuMode != CloseMenuMode_None) menuFrame->SelectMenu(false); - nsAutoHandlingUserInputStatePusher userInpStatePusher(mUserInput, nullptr, - shell->GetDocument()); + AutoHandlingUserInputStatePusher userInpStatePusher(mUserInput, nullptr, + shell->GetDocument()); nsContentUtils::DispatchXULCommand(mMenu, mIsTrusted, nullptr, shell, mControl, mAlt, mShift, mMeta); } diff --git a/view/src/nsViewManager.cpp b/view/src/nsViewManager.cpp index 6d3ffcdedccf..490c6b147327 100644 --- a/view/src/nsViewManager.cpp +++ b/view/src/nsViewManager.cpp @@ -27,6 +27,7 @@ #include "nsLayoutUtils.h" #include "Layers.h" #include "gfxPlatform.h" +#include "nsIDocument.h" /** XXX TODO XXX