зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1543439 - Part 1: Move special handling for MouseDown/Up event out of AutoHandlingUserInputStatePusher; r=masayuki
PresShell::EventHandler::HandleEventWithCurrentEventInfo is the only possible place will do such handling; other places pass either a nullptr or a non-MouseDown/Up event. Differential Revision: https://phabricator.services.mozilla.com/D32431 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
17d59d11c8
Коммит
4b1ff2f791
|
@ -742,8 +742,7 @@ void Accessible::TakeFocus() const {
|
|||
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm) {
|
||||
AutoHandlingUserInputStatePusher inputStatePusher(true, nullptr,
|
||||
focusContent->OwnerDoc());
|
||||
AutoHandlingUserInputStatePusher inputStatePusher(true);
|
||||
// XXXbz: Can we actually have a non-element content here?
|
||||
RefPtr<Element> element =
|
||||
focusContent->IsElement() ? focusContent->AsElement() : nullptr;
|
||||
|
|
|
@ -294,8 +294,7 @@ void DocAccessible::TakeFocus() const {
|
|||
// Focus the document.
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
RefPtr<dom::Element> newFocus;
|
||||
AutoHandlingUserInputStatePusher inputStatePusher(true, nullptr,
|
||||
mDocumentNode);
|
||||
AutoHandlingUserInputStatePusher inputStatePusher(true);
|
||||
fm->MoveFocus(mDocumentNode->GetWindow(), nullptr,
|
||||
nsFocusManager::MOVEFOCUS_ROOT, 0, getter_AddRefs(newFocus));
|
||||
}
|
||||
|
|
|
@ -1558,8 +1558,7 @@ void EventStateManager::FireContextClick() {
|
|||
}
|
||||
}
|
||||
|
||||
Document* doc = mGestureDownContent->GetComposedDoc();
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc);
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(true, &event);
|
||||
|
||||
// dispatch to DOM
|
||||
EventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event,
|
||||
|
@ -6257,36 +6256,13 @@ void EventStateManager::Prefs::Init() {
|
|||
/******************************************************************/
|
||||
|
||||
AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher(
|
||||
bool aIsHandlingUserInput, WidgetEvent* aEvent, Document* aDocument)
|
||||
bool aIsHandlingUserInput, WidgetEvent* aEvent)
|
||||
: mMessage(aEvent ? aEvent->mMessage : eVoidEvent),
|
||||
mIsHandlingUserInput(aIsHandlingUserInput) {
|
||||
if (!aIsHandlingUserInput) {
|
||||
return;
|
||||
}
|
||||
EventStateManager::StartHandlingUserInput(mMessage);
|
||||
if (mMessage == eMouseDown) {
|
||||
PresShell::ReleaseCapturingContent();
|
||||
PresShell::AllowMouseCapture(true);
|
||||
}
|
||||
if (!aDocument || !aEvent || !aEvent->IsTrusted()) {
|
||||
return;
|
||||
}
|
||||
if (NeedsToResetFocusManagerMouseButtonHandlingState()) {
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
NS_ENSURE_TRUE_VOID(fm);
|
||||
// If it's in modal state, mouse button event handling may be nested.
|
||||
// E.g., a modal dialog is opened at mousedown or mouseup event handler
|
||||
// and the dialog is clicked. Therefore, we should store current
|
||||
// mouse button event handling document if nsFocusManager already has it.
|
||||
mMouseButtonEventHandlingDocument =
|
||||
fm->SetMouseButtonHandlingDocument(aDocument);
|
||||
}
|
||||
if (NeedsToUpdateCurrentMouseBtnState()) {
|
||||
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
||||
if (mouseEvent) {
|
||||
EventStateManager::sCurrentMouseBtn = mouseEvent->mButton;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher() {
|
||||
|
@ -6294,18 +6270,6 @@ AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher() {
|
|||
return;
|
||||
}
|
||||
EventStateManager::StopHandlingUserInput(mMessage);
|
||||
if (mMessage == eMouseDown) {
|
||||
PresShell::AllowMouseCapture(false);
|
||||
}
|
||||
if (NeedsToResetFocusManagerMouseButtonHandlingState()) {
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
NS_ENSURE_TRUE_VOID(fm);
|
||||
nsCOMPtr<Document> handlingDocument =
|
||||
fm->SetMouseButtonHandlingDocument(mMouseButtonEventHandlingDocument);
|
||||
}
|
||||
if (NeedsToUpdateCurrentMouseBtnState()) {
|
||||
EventStateManager::sCurrentMouseBtn = MouseButton::eNotPressed;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -1286,24 +1286,13 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
|
|||
*/
|
||||
class MOZ_RAII AutoHandlingUserInputStatePusher final {
|
||||
public:
|
||||
AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
|
||||
WidgetEvent* aEvent,
|
||||
dom::Document* aDocument);
|
||||
explicit AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
|
||||
WidgetEvent* aEvent = nullptr);
|
||||
~AutoHandlingUserInputStatePusher();
|
||||
|
||||
protected:
|
||||
RefPtr<dom::Document> mMouseButtonEventHandlingDocument;
|
||||
EventMessage mMessage;
|
||||
bool mIsHandlingUserInput;
|
||||
|
||||
bool NeedsToResetFocusManagerMouseButtonHandlingState() const {
|
||||
return mMessage == eMouseDown || mMessage == eMouseUp;
|
||||
}
|
||||
|
||||
bool NeedsToUpdateCurrentMouseBtnState() const {
|
||||
return mMessage == eMouseDown || mMessage == eMouseUp ||
|
||||
mMessage == ePointerDown || mMessage == ePointerUp;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -698,7 +698,7 @@ nsresult HTMLFormElement::SubmitSubmission(
|
|||
AutoPopupStatePusher popupStatePusher(mSubmitPopupState);
|
||||
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(
|
||||
aFormSubmission->IsInitiatedFromUserInput(), nullptr, doc);
|
||||
aFormSubmission->IsInitiatedFromUserInput());
|
||||
|
||||
nsCOMPtr<nsIInputStream> postDataStream;
|
||||
rv = aFormSubmission->GetEncodedSubmission(
|
||||
|
|
|
@ -2285,7 +2285,7 @@ mozilla::ipc::IPCResult BrowserParent::RecvReplyKeyEvent(
|
|||
NS_ENSURE_TRUE(presContext, IPC_OK());
|
||||
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(localEvent.IsTrusted(),
|
||||
&localEvent, doc);
|
||||
&localEvent);
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
|
||||
|
|
|
@ -7730,6 +7730,67 @@ nsresult PresShell::EventHandler::HandleEventWithTarget(
|
|||
return rv;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class MOZ_RAII AutoEventHandler final {
|
||||
public:
|
||||
AutoEventHandler(WidgetEvent* aEvent, Document* aDocument) : mEvent(aEvent) {
|
||||
MOZ_ASSERT(mEvent);
|
||||
MOZ_ASSERT(mEvent->IsTrusted());
|
||||
|
||||
if (mEvent->mMessage == eMouseDown) {
|
||||
PresShell::ReleaseCapturingContent();
|
||||
PresShell::AllowMouseCapture(true);
|
||||
}
|
||||
if (aDocument && NeedsToResetFocusManagerMouseButtonHandlingState()) {
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
NS_ENSURE_TRUE_VOID(fm);
|
||||
// If it's in modal state, mouse button event handling may be nested.
|
||||
// E.g., a modal dialog is opened at mousedown or mouseup event handler
|
||||
// and the dialog is clicked. Therefore, we should store current
|
||||
// mouse button event handling document if nsFocusManager already has it.
|
||||
mMouseButtonEventHandlingDocument =
|
||||
fm->SetMouseButtonHandlingDocument(aDocument);
|
||||
}
|
||||
if (NeedsToUpdateCurrentMouseBtnState()) {
|
||||
WidgetMouseEvent* mouseEvent = mEvent->AsMouseEvent();
|
||||
if (mouseEvent) {
|
||||
EventStateManager::sCurrentMouseBtn = mouseEvent->mButton;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~AutoEventHandler() {
|
||||
if (mEvent->mMessage == eMouseDown) {
|
||||
PresShell::AllowMouseCapture(false);
|
||||
}
|
||||
if (NeedsToResetFocusManagerMouseButtonHandlingState()) {
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
NS_ENSURE_TRUE_VOID(fm);
|
||||
RefPtr<Document> document =
|
||||
fm->SetMouseButtonHandlingDocument(mMouseButtonEventHandlingDocument);
|
||||
}
|
||||
if (NeedsToUpdateCurrentMouseBtnState()) {
|
||||
EventStateManager::sCurrentMouseBtn = MouseButton::eNotPressed;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool NeedsToResetFocusManagerMouseButtonHandlingState() const {
|
||||
return mEvent->mMessage == eMouseDown || mEvent->mMessage == eMouseUp;
|
||||
}
|
||||
|
||||
bool NeedsToUpdateCurrentMouseBtnState() const {
|
||||
return mEvent->mMessage == eMouseDown || mEvent->mMessage == eMouseUp ||
|
||||
mEvent->mMessage == ePointerDown || mEvent->mMessage == ePointerUp;
|
||||
}
|
||||
|
||||
RefPtr<Document> mMouseButtonEventHandlingDocument;
|
||||
WidgetEvent* mEvent;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
nsresult PresShell::EventHandler::HandleEventWithCurrentEventInfo(
|
||||
WidgetEvent* aEvent, nsEventStatus* aEventStatus,
|
||||
bool aIsHandlingNativeEvent, nsIContent* aOverrideClickTarget) {
|
||||
|
@ -7768,8 +7829,8 @@ nsresult PresShell::EventHandler::HandleEventWithCurrentEventInfo(
|
|||
RecordEventPreparationPerformance(aEvent);
|
||||
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
|
||||
aEvent, GetDocument());
|
||||
|
||||
aEvent);
|
||||
AutoEventHandler eventHandler(aEvent, GetDocument());
|
||||
AutoPopupStatePusher popupStatePusher(
|
||||
PopupBlocker::GetEventPopupControlState(aEvent));
|
||||
|
||||
|
|
|
@ -2667,8 +2667,7 @@ nsXULMenuCommandEvent::Run() {
|
|||
// Deselect ourselves.
|
||||
if (mCloseMenuMode != CloseMenuMode_None) menuFrame->SelectMenu(false);
|
||||
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(
|
||||
mUserInput, nullptr, presShell->GetDocument());
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(mUserInput);
|
||||
RefPtr<Element> menu = mMenu;
|
||||
nsContentUtils::DispatchXULCommand(menu, mIsTrusted, nullptr, presShell,
|
||||
mControl, mAlt, mShift, mMeta);
|
||||
|
|
|
@ -233,7 +233,7 @@ class PromiseJobRunnable final : public MicroTaskRunnable {
|
|||
doc = win->GetExtantDoc();
|
||||
}
|
||||
AutoHandlingUserInputStatePusher userInpStatePusher(
|
||||
mPropagateUserInputEventHandling, nullptr, doc);
|
||||
mPropagateUserInputEventHandling);
|
||||
|
||||
mCallback->Call("promise callback");
|
||||
aAso.CheckForInterrupt();
|
||||
|
|
Загрузка…
Ссылка в новой задаче