From edf50a6c24e3c36b32b3fe3346977f144b5f3760 Mon Sep 17 00:00:00 2001 From: Stone Shih Date: Sat, 2 Dec 2017 22:25:25 +0800 Subject: [PATCH] Bug 1420589 Part3: Merge PresShell::HandlePositionedEvent to PresShell::HandleEvent. r=smaug. MozReview-Commit-ID: 9w1DSb5uXME --- dom/events/EventStateManager.cpp | 2 +- layout/base/PresShell.cpp | 106 +++++++++++++------------------ layout/base/PresShell.h | 3 - 3 files changed, 44 insertions(+), 67 deletions(-) diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 97ab2c70b525..8d92d8929dd0 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -4924,7 +4924,7 @@ EventStateManager::CheckForAndDispatchClick(WidgetMouseEvent* aEvent, // Click events apply to *elements* not nodes. At this point the target // content may have been reset to some non-element content, and so we need // to walk up the closest ancestor element, just like we do in - // nsPresShell::HandlePositionedEvent. + // nsPresShell::HandleEvent. while (mouseContent && !mouseContent->IsElement()) { mouseContent = mouseContent->GetParent(); } diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index b5beefd2e58a..39ff85d7d133 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -7275,21 +7275,54 @@ PresShell::HandleEvent(nsIFrame* aFrame, } } } + + if (!frame) { + NS_WARNING("Nothing to handle this event!"); + return NS_OK; + } + + nsCOMPtr targetElement; + frame->GetContentForEvent(aEvent, getter_AddRefs(targetElement)); + + // If there is no content for this frame, target it anyway. Some + // frames can be targeted but do not have content, particularly + // windows with scrolling off. + if (targetElement) { + // Bug 103055, bug 185889: mouse events apply to *elements*, not all + // nodes. Thus we get the nearest element parent here. + // XXX we leave the frame the same even if we find an element + // parent, so that the text frame will receive the event (selection + // and friends are the ones who care about that anyway) + // + // We use weak pointers because during this tight loop, the node + // will *not* go away. And this happens on every mousemove. + while (targetElement && !targetElement->IsElement()) { + targetElement = targetElement->GetFlattenedTreeParent(); + } + + // If we found an element, target it. Otherwise, target *nothing*. + if (!targetElement) { + return NS_OK; + } + } + // Prevent deletion until we're done with event handling (bug 336582) and // swap mPointerEventTarget to *aTargetContent nsCOMPtr kungFuDeathGrip(shell); nsresult rv; AutoPointerEventTargetUpdater updater(shell, aEvent, frame, aTargetContent); - if (shell != this) { - // Handle the event in the correct shell. - // We pass the subshell's root frame as the frame to start from. This is - // the only correct alternative; if the event was captured then it - // must have been captured by us or some ancestor shell and we - // now ask the subshell to dispatch it normally. - rv = shell->HandlePositionedEvent(frame, aEvent, aEventStatus); - } else { - rv = HandlePositionedEvent(frame, aEvent, aEventStatus); - } + + // Handle the event in the correct shell. + // We pass the subshell's root frame as the frame to start from. This is + // the only correct alternative; if the event was captured then it + // must have been captured by us or some ancestor shell and we + // now ask the subshell to dispatch it normally. + shell->PushCurrentEventInfo(frame, targetElement); + rv = shell->HandleEventInternal(aEvent, aEventStatus, true); +#ifdef DEBUG + shell->ShowEventTargetDebug(); +#endif + shell->PopCurrentEventInfo(); return rv; } @@ -7438,59 +7471,6 @@ PresShell::ShowEventTargetDebug() } #endif -nsresult -PresShell::HandlePositionedEvent(nsIFrame* aTargetFrame, - WidgetGUIEvent* aEvent, - nsEventStatus* aEventStatus) -{ - nsresult rv = NS_OK; - - PushCurrentEventInfo(nullptr, nullptr); - - mCurrentEventFrame = aTargetFrame; - - if (mCurrentEventFrame) { - nsCOMPtr targetElement; - mCurrentEventFrame->GetContentForEvent(aEvent, - getter_AddRefs(targetElement)); - - // If there is no content for this frame, target it anyway. Some - // frames can be targeted but do not have content, particularly - // windows with scrolling off. - if (targetElement) { - // Bug 103055, bug 185889: mouse events apply to *elements*, not all - // nodes. Thus we get the nearest element parent here. - // XXX we leave the frame the same even if we find an element - // parent, so that the text frame will receive the event (selection - // and friends are the ones who care about that anyway) - // - // We use weak pointers because during this tight loop, the node - // will *not* go away. And this happens on every mousemove. - while (targetElement && !targetElement->IsElement()) { - targetElement = targetElement->GetFlattenedTreeParent(); - } - - // If we found an element, target it. Otherwise, target *nothing*. - if (!targetElement) { - mCurrentEventContent = nullptr; - mCurrentEventFrame = nullptr; - } else if (targetElement != mCurrentEventContent) { - mCurrentEventContent = targetElement; - } - } - } - - if (GetCurrentEventFrame()) { - rv = HandleEventInternal(aEvent, aEventStatus, true); - } - -#ifdef DEBUG - ShowEventTargetDebug(); -#endif - PopCurrentEventInfo(); - return rv; -} - nsresult PresShell::HandleEventWithTarget(WidgetEvent* aEvent, nsIFrame* aFrame, nsIContent* aContent, nsEventStatus* aStatus) diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 372278b2ff49..b66bd64c631a 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -685,9 +685,6 @@ protected: nsresult HandleEventInternal(mozilla::WidgetEvent* aEvent, nsEventStatus* aStatus, bool aIsHandlingNativeEvent); - nsresult HandlePositionedEvent(nsIFrame* aTargetFrame, - mozilla::WidgetGUIEvent* aEvent, - nsEventStatus* aEventStatus); /* * This and the next two helper methods are used to target and position the