Bug 1700251 - Move the code to set the LayersId on the event into InputHandlingResult::Finish(). r=tnikkel

This allows that code (and in the future, other code that needs
to run for every input type) to be in just one place.

Depends on D109460

Differential Revision: https://phabricator.services.mozilla.com/D109461
This commit is contained in:
Botond Ballo 2021-03-25 03:41:01 +00:00
parent 5ff95760dc
commit 306c83cbc9
2 changed files with 33 additions and 25 deletions

View File

@ -1462,7 +1462,7 @@ static bool HasNonLockModifier(Modifiers aModifiers) {
APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) { APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
APZThreadUtils::AssertOnControllerThread(); APZThreadUtils::AssertOnControllerThread();
InputHandlingState state; InputHandlingState state{aEvent};
// Use a RAII class for updating the focus sequence number of this event // Use a RAII class for updating the focus sequence number of this event
AutoFocusSequenceNumberSetter focusSetter(mFocusState, aEvent); AutoFocusSequenceNumberSetter focusSetter(mFocusState, aEvent);
@ -1489,7 +1489,6 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
} }
state.mHit = GetTargetAPZC(mouseInput.mOrigin); state.mHit = GetTargetAPZC(mouseInput.mOrigin);
aEvent.mLayersId = state.mHit.mLayersId;
bool hitScrollbar = (bool)state.mHit.mScrollbarNode; bool hitScrollbar = (bool)state.mHit.mScrollbarNode;
// When the mouse is outside the window we still want to handle dragging // When the mouse is outside the window we still want to handle dragging
@ -1567,11 +1566,10 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
// Do this before early return for Fission hit testing. // Do this before early return for Fission hit testing.
ScrollWheelInput& wheelInput = aEvent.AsScrollWheelInput(); ScrollWheelInput& wheelInput = aEvent.AsScrollWheelInput();
state.mHit = GetTargetAPZC(wheelInput.mOrigin); state.mHit = GetTargetAPZC(wheelInput.mOrigin);
aEvent.mLayersId = state.mHit.mLayersId;
wheelInput.mHandledByAPZ = WillHandleInput(wheelInput); wheelInput.mHandledByAPZ = WillHandleInput(wheelInput);
if (!wheelInput.mHandledByAPZ) { if (!wheelInput.mHandledByAPZ) {
return state.mResult; return state.Finish();
} }
mOvershootDetector.Update(wheelInput); mOvershootDetector.Update(wheelInput);
@ -1592,7 +1590,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
state.mHit.mTargetApzc); state.mHit.mTargetApzc);
} }
state.mResult.SetStatusAsConsumeNoDefault(); state.mResult.SetStatusAsConsumeNoDefault();
return state.mResult; return state.Finish();
} }
MOZ_ASSERT(wheelInput.mAPZAction == APZWheelAction::Scroll); MOZ_ASSERT(wheelInput.mAPZAction == APZWheelAction::Scroll);
@ -1611,7 +1609,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
UntransformBy(transformToGecko, wheelInput.mOrigin); UntransformBy(transformToGecko, wheelInput.mOrigin);
if (!untransformedOrigin) { if (!untransformedOrigin) {
return state.mResult; return state.Finish();
} }
state.mResult = mInputQueue->ReceiveInputEvent( state.mResult = mInputQueue->ReceiveInputEvent(
@ -1629,11 +1627,10 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
// Do this before early return for Fission hit testing. // Do this before early return for Fission hit testing.
PanGestureInput& panInput = aEvent.AsPanGestureInput(); PanGestureInput& panInput = aEvent.AsPanGestureInput();
state.mHit = GetTargetAPZC(panInput.mPanStartPoint); state.mHit = GetTargetAPZC(panInput.mPanStartPoint);
aEvent.mLayersId = state.mHit.mLayersId;
panInput.mHandledByAPZ = WillHandleInput(panInput); panInput.mHandledByAPZ = WillHandleInput(panInput);
if (!panInput.mHandledByAPZ) { if (!panInput.mHandledByAPZ) {
return state.mResult; return state.Finish();
} }
// If/when we enable support for pan inputs off-main-thread, we'll need // If/when we enable support for pan inputs off-main-thread, we'll need
@ -1667,7 +1664,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
panInput.mPanStartPoint); panInput.mPanStartPoint);
if (!untransformedStartPoint || !untransformedDisplacement) { if (!untransformedStartPoint || !untransformedDisplacement) {
return state.mResult; return state.Finish();
} }
state.mResult = mInputQueue->ReceiveInputEvent( state.mResult = mInputQueue->ReceiveInputEvent(
@ -1688,11 +1685,10 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
if (HasNonLockModifier(pinchInput.modifiers)) { if (HasNonLockModifier(pinchInput.modifiers)) {
APZCTM_LOG("Discarding pinch input due to modifiers 0x%x\n", APZCTM_LOG("Discarding pinch input due to modifiers 0x%x\n",
pinchInput.modifiers); pinchInput.modifiers);
return state.mResult; return state.Finish();
} }
state.mHit = GetTargetAPZC(pinchInput.mFocusPoint); state.mHit = GetTargetAPZC(pinchInput.mFocusPoint);
aEvent.mLayersId = state.mHit.mLayersId;
// We always handle pinch gestures as pinch zooms. // We always handle pinch gestures as pinch zooms.
pinchInput.mHandledByAPZ = true; pinchInput.mHandledByAPZ = true;
@ -1713,7 +1709,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
UntransformBy(outTransform, pinchInput.mFocusPoint); UntransformBy(outTransform, pinchInput.mFocusPoint);
if (!untransformedFocusPoint) { if (!untransformedFocusPoint) {
return state.mResult; return state.Finish();
} }
state.mResult = mInputQueue->ReceiveInputEvent( state.mResult = mInputQueue->ReceiveInputEvent(
@ -1728,7 +1724,6 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
case TAPGESTURE_INPUT: { // note: no one currently sends these case TAPGESTURE_INPUT: { // note: no one currently sends these
TapGestureInput& tapInput = aEvent.AsTapGestureInput(); TapGestureInput& tapInput = aEvent.AsTapGestureInput();
state.mHit = GetTargetAPZC(tapInput.mPoint); state.mHit = GetTargetAPZC(tapInput.mPoint);
aEvent.mLayersId = state.mHit.mLayersId;
if (state.mHit.mTargetApzc) { if (state.mHit.mTargetApzc) {
MOZ_ASSERT(state.mHit.mHitResult != CompositorHitTestInvisibleToHit); MOZ_ASSERT(state.mHit.mHitResult != CompositorHitTestInvisibleToHit);
@ -1740,7 +1735,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
UntransformBy(outTransform, tapInput.mPoint); UntransformBy(outTransform, tapInput.mPoint);
if (!untransformedPoint) { if (!untransformedPoint) {
return state.mResult; return state.Finish();
} }
state.mResult = mInputQueue->ReceiveInputEvent( state.mResult = mInputQueue->ReceiveInputEvent(
@ -1758,7 +1753,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
if (!StaticPrefs::apz_keyboard_enabled_AtStartup() || if (!StaticPrefs::apz_keyboard_enabled_AtStartup() ||
StaticPrefs::accessibility_browsewithcaret()) { StaticPrefs::accessibility_browsewithcaret()) {
APZ_KEY_LOG("Skipping key input from invalid prefs\n"); APZ_KEY_LOG("Skipping key input from invalid prefs\n");
return state.mResult; return state.Finish();
} }
KeyboardInput& keyInput = aEvent.AsKeyboardInput(); KeyboardInput& keyInput = aEvent.AsKeyboardInput();
@ -1775,14 +1770,14 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
if (mFocusState.CanIgnoreKeyboardShortcutMisses()) { if (mFocusState.CanIgnoreKeyboardShortcutMisses()) {
focusSetter.MarkAsNonFocusChanging(); focusSetter.MarkAsNonFocusChanging();
} }
return state.mResult; return state.Finish();
} }
// Check if this shortcut needs to be dispatched to content. Anything // Check if this shortcut needs to be dispatched to content. Anything
// matching this is assumed to be able to change focus. // matching this is assumed to be able to change focus.
if (shortcut->mDispatchToContent) { if (shortcut->mDispatchToContent) {
APZ_KEY_LOG("Skipping key input with dispatch-to-content shortcut\n"); APZ_KEY_LOG("Skipping key input with dispatch-to-content shortcut\n");
return state.mResult; return state.Finish();
} }
// We know we have an action to execute on whatever is the current focus // We know we have an action to execute on whatever is the current focus
@ -1811,7 +1806,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
// to content. // to content.
if (!targetGuid) { if (!targetGuid) {
APZ_KEY_LOG("Skipping key input with no current focus target\n"); APZ_KEY_LOG("Skipping key input with no current focus target\n");
return state.mResult; return state.Finish();
} }
RefPtr<AsyncPanZoomController> targetApzc = RefPtr<AsyncPanZoomController> targetApzc =
@ -1819,7 +1814,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
if (!targetApzc) { if (!targetApzc) {
APZ_KEY_LOG("Skipping key input with focus target but no APZC\n"); APZ_KEY_LOG("Skipping key input with focus target but no APZC\n");
return state.mResult; return state.Finish();
} }
// Attach the keyboard scroll action to the input event for processing // Attach the keyboard scroll action to the input event for processing
@ -1843,7 +1838,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) {
break; break;
} }
} }
return state.mResult; return state.Finish();
} }
static TouchBehaviorFlags ConvertToTouchBehavior( static TouchBehaviorFlags ConvertToTouchBehavior(
@ -1918,6 +1913,17 @@ APZCTreeManager::HitTestResult APZCTreeManager::GetTouchInputBlockAPZC(
return hit; return hit;
} }
APZEventResult APZCTreeManager::InputHandlingState::Finish() const {
// The validity check here handles both the case where mHit was
// never populated (because this event did not trigger a hit-test),
// and the case where it was populated with an invalid LayersId
// (which can happen e.g. for multi-touch events).
if (mHit.mLayersId.IsValid()) {
mEvent.mLayersId = mHit.mLayersId;
}
return mResult;
}
void APZCTreeManager::ProcessTouchInput(InputHandlingState& aState, void APZCTreeManager::ProcessTouchInput(InputHandlingState& aState,
MultiTouchInput& aInput) { MultiTouchInput& aInput) {
aInput.mHandledByAPZ = true; aInput.mHandledByAPZ = true;
@ -1947,11 +1953,6 @@ void APZCTreeManager::ProcessTouchInput(InputHandlingState& aState,
aState.mHit = GetTouchInputBlockAPZC(aInput, &touchBehaviors); aState.mHit = GetTouchInputBlockAPZC(aInput, &touchBehaviors);
// Repopulate mTouchBlockHitResult with the fields we care about. // Repopulate mTouchBlockHitResult with the fields we care about.
mTouchBlockHitResult = aState.mHit.CopyWithoutScrollbarNode(); mTouchBlockHitResult = aState.mHit.CopyWithoutScrollbarNode();
if (aState.mHit.mLayersId.IsValid()) {
// Check for validity because we won't get a layers id for multi-touch
// events.
aInput.mLayersId = aState.mHit.mLayersId;
}
hitScrollbarNode = std::move(aState.mHit.mScrollbarNode); hitScrollbarNode = std::move(aState.mHit.mScrollbarNode);
// Check if this event starts a scrollbar touch-drag. The conditions // Check if this event starts a scrollbar touch-drag. The conditions

View File

@ -684,6 +684,9 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
* A helper structure for use by ReceiveInputEvent() and its helpers. * A helper structure for use by ReceiveInputEvent() and its helpers.
*/ */
struct InputHandlingState { struct InputHandlingState {
// A reference to the event being handled.
InputData& mEvent;
// The value that will be returned by ReceiveInputEvent(). // The value that will be returned by ReceiveInputEvent().
APZEventResult mResult; APZEventResult mResult;
@ -691,6 +694,10 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
// reused the result of a previous hit-test in the input block, // reused the result of a previous hit-test in the input block,
// this is populated with the result of the hit test. // this is populated with the result of the hit test.
HitTestResult mHit; HitTestResult mHit;
// Called at the end of ReceiveInputEvent() to perform any final
// computations, and then return mResult.
APZEventResult Finish() const;
}; };
void ProcessTouchInput(InputHandlingState& aState, MultiTouchInput& aInput); void ProcessTouchInput(InputHandlingState& aState, MultiTouchInput& aInput);