Bug 1466208 - part 4: Create PresShell::EventHandler::GetCapturingContentFor() to retrieve capturing content for specific event r=smaug

PresShell::HandleEvent() treats capturing content only when received event is
related to pointing device.  And it's used in 2 purposes.  One is for computing
to target document of coming event.  The other is for handling events using
coordinates.  Therefore, if we create a helper method to retrieve it, we can
move the variable into smaller blocks.

Differential Revision: https://phabricator.services.mozilla.com/D16954

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-01-30 07:17:43 +00:00
Родитель 0c15094a05
Коммит 6a6fca62ba
2 изменённых файлов: 23 добавлений и 7 удалений

Просмотреть файл

@ -6520,12 +6520,6 @@ nsresult PresShell::EventHandler::HandleEvent(nsIFrame* aFrame,
return NS_OK;
}
nsIContent* capturingContent = ((aGUIEvent->mClass == ePointerEventClass ||
aGUIEvent->mClass == eWheelEventClass ||
aGUIEvent->HasMouseEventMessage())
? nsIPresShell::GetCapturingContent()
: nullptr);
RefPtr<Document> retargetEventDoc;
if (!aDontRetargetEvents) {
// key and IME related events should not cross top level window boundary.
@ -6547,7 +6541,8 @@ nsresult PresShell::EventHandler::HandleEvent(nsIFrame* aFrame,
retargetEventDoc = window->GetExtantDoc();
if (!retargetEventDoc) return NS_OK;
} else if (capturingContent) {
} else if (nsIContent* capturingContent =
EventHandler::GetCapturingContentFor(aGUIEvent)) {
// if the mouse is being captured then retarget the mouse event at the
// document that is being captured.
retargetEventDoc = capturingContent->GetComposedDoc();
@ -6611,6 +6606,11 @@ nsresult PresShell::EventHandler::HandleEvent(nsIFrame* aFrame,
nsIFrame* frame = aFrame;
if (aGUIEvent->IsUsingCoordinates()) {
// XXX Retrieving capturing content here. However, some of the following
// methods allow to run script. So, isn't it possible the capturing
// content outdated?
nsIContent* capturingContent =
EventHandler::GetCapturingContentFor(aGUIEvent);
if (GetDocument()) {
if (aGUIEvent->mClass == eTouchEventClass) {
Document::UnlockPointer();
@ -7156,6 +7156,16 @@ bool PresShell::EventHandler::MaybeHandleEventWithAccessibleCaret(
return true;
}
// static
nsIContent* PresShell::EventHandler::GetCapturingContentFor(
WidgetGUIEvent* aGUIEvent) {
return (aGUIEvent->mClass == ePointerEventClass ||
aGUIEvent->mClass == eWheelEventClass ||
aGUIEvent->HasMouseEventMessage())
? nsIPresShell::GetCapturingContent()
: nullptr;
}
Document* PresShell::GetPrimaryContentDocument() {
nsPresContext* context = GetPresContext();
if (!context || !context->IsRoot()) {

Просмотреть файл

@ -574,6 +574,12 @@ class PresShell final : public nsIPresShell,
static already_AddRefed<nsIURI> GetDocumentURIToCompareWithBlacklist(
PresShell& aPresShell);
/**
* GetCapturingContentFor() returns capturing content for aGUIEvent.
* If aGUIEvent is not related to capturing, this returns nullptr.
*/
static nsIContent* GetCapturingContentFor(WidgetGUIEvent* aGUIEvent);
MOZ_CAN_RUN_SCRIPT
nsresult RetargetEventToParent(WidgetGUIEvent* aGUIEvent,
nsEventStatus* aEventStatus);