Bug 1420589 Part3: Merge PresShell::HandlePositionedEvent to PresShell::HandleEvent. r=smaug.

MozReview-Commit-ID: 9w1DSb5uXME
This commit is contained in:
Stone Shih 2017-12-02 22:25:25 +08:00
parent e169d04d5d
commit edf50a6c24
3 changed files with 44 additions and 67 deletions

View File

@ -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();
}

View File

@ -7275,21 +7275,54 @@ PresShell::HandleEvent(nsIFrame* aFrame,
}
}
}
if (!frame) {
NS_WARNING("Nothing to handle this event!");
return NS_OK;
}
nsCOMPtr<nsIContent> 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<nsIPresShell> 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<nsIContent> 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)

View File

@ -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