Bug 1458063 - Introduce a new wheel action for pinch-zooming. r=kats

MozReview-Commit-ID: 7DWNvQc2pBE

--HG--
extra : rebase_source : 02d3efe180fb1cd6d49ca9b8a49e4051e6e05cac
This commit is contained in:
Botond Ballo 2018-05-02 16:51:27 -04:00
parent 5b8cc7e2fa
commit 9033e3e120
7 changed files with 86 additions and 6 deletions

View File

@ -626,8 +626,9 @@ pref("browser.snapshots.limit", 0);
// 0: Nothing happens
// 1: Scrolling contents
// 2: Go back or go forward, in your history
// 3: Zoom in or out.
// 3: Zoom in or out (reflowing zoom).
// 4: Treat vertical wheel as horizontal scroll
// 5: Zoom in or out (pinch zoom).
#ifdef XP_MACOSX
// On macOS, if the wheel has one axis only, shift+wheel comes through as a
// horizontal scroll event. Thus, we can't assign anything other than normal

View File

@ -6257,6 +6257,8 @@ EventStateManager::APZWheelActionFor(const WidgetWheelEvent* aEvent)
case WheelPrefs::ACTION_SCROLL:
case WheelPrefs::ACTION_HORIZONTALIZED_SCROLL:
return Some(layers::APZWheelAction::Scroll);
case WheelPrefs::ACTION_PINCH_ZOOM:
return Some(layers::APZWheelAction::PinchZoom);
default:
return Nothing();
}

View File

@ -587,7 +587,8 @@ protected:
// original values. For more details, refer to
// mozilla::WheelDeltaAdjustmentStrategy::eHorizontalize
ACTION_HORIZONTALIZED_SCROLL,
ACTION_LAST = ACTION_HORIZONTALIZED_SCROLL,
ACTION_PINCH_ZOOM,
ACTION_LAST = ACTION_PINCH_ZOOM,
// Following actions are used only by internal processing. So, cannot
// specified by prefs.
ACTION_SEND_TO_PLUGIN,

View File

@ -1268,13 +1268,26 @@ APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
return result;
}
MOZ_ASSERT(wheelInput.mAPZAction == APZWheelAction::Scroll);
RefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(wheelInput.mOrigin,
&hitResult);
if (apzc) {
MOZ_ASSERT(hitResult != CompositorHitTestInfo::eInvisibleToHitTest);
if (wheelInput.mAPZAction == APZWheelAction::PinchZoom) {
// The mousewheel may have hit a subframe, but we want to send the
// pinch-zoom events to the root-content APZC.
{
RecursiveMutexAutoLock lock(mTreeLock);
apzc = FindRootContentApzcForLayersId(apzc->GetLayersId());
}
if (apzc) {
SynthesizePinchGestureFromMouseWheel(wheelInput, apzc);
}
return nsEventStatus_eConsumeNoDefault;
}
MOZ_ASSERT(wheelInput.mAPZAction == APZWheelAction::Scroll);
// For wheel events, the call to ReceiveInputEvent below may result in
// scrolling, which changes the async transform. However, the event we
// want to pass to gecko should be the pre-scroll event coordinates,
@ -1835,6 +1848,63 @@ APZCTreeManager::SetupScrollbarDrag(MouseInput& aMouseInput,
}
}
void
APZCTreeManager::SynthesizePinchGestureFromMouseWheel(
const ScrollWheelInput& aWheelInput,
const RefPtr<AsyncPanZoomController>& aTarget)
{
MOZ_ASSERT(aTarget);
ScreenPoint focusPoint = aWheelInput.mOrigin;
// Compute span values based on the wheel delta.
// See the PinchGestureInput constructor called below for why
// it's OK to use ParentLayer coordinates for the span values.
ParentLayerCoord oldSpan = 100;
ParentLayerCoord newSpan = oldSpan + aWheelInput.mDeltaY;
// There's no ambiguity as to the target for pinch gesture events.
TargetConfirmationFlags confFlags{true};
PinchGestureInput pinchStart{
PinchGestureInput::PINCHGESTURE_START,
aWheelInput.mTime,
aWheelInput.mTimeStamp,
focusPoint,
oldSpan,
oldSpan,
aWheelInput.modifiers};
PinchGestureInput pinchScale1{
PinchGestureInput::PINCHGESTURE_SCALE,
aWheelInput.mTime,
aWheelInput.mTimeStamp,
focusPoint,
oldSpan,
oldSpan,
aWheelInput.modifiers};
PinchGestureInput pinchScale2{
PinchGestureInput::PINCHGESTURE_SCALE,
aWheelInput.mTime,
aWheelInput.mTimeStamp,
focusPoint,
oldSpan,
newSpan,
aWheelInput.modifiers};
PinchGestureInput pinchEnd{
PinchGestureInput::PINCHGESTURE_END,
aWheelInput.mTime,
aWheelInput.mTimeStamp,
PinchGestureInput::BothFingersLifted<ScreenPixel>(),
newSpan,
newSpan,
aWheelInput.modifiers};
mInputQueue->ReceiveInputEvent(aTarget, confFlags, pinchStart, nullptr);
mInputQueue->ReceiveInputEvent(aTarget, confFlags, pinchScale1, nullptr);
mInputQueue->ReceiveInputEvent(aTarget, confFlags, pinchScale2, nullptr);
mInputQueue->ReceiveInputEvent(aTarget, confFlags, pinchEnd, nullptr);
}
void
APZCTreeManager::UpdateWheelTransaction(LayoutDeviceIntPoint aRefPoint,
EventMessage aEventMessage)

View File

@ -692,6 +692,10 @@ private:
uint64_t* aOutInputBlockId);
void FlushRepaintsToClearScreenToGeckoTransform();
void SynthesizePinchGestureFromMouseWheel(const ScrollWheelInput& aWheelInput,
const RefPtr<AsyncPanZoomController>& aTarget);
already_AddRefed<HitTestingTreeNode> RecycleOrCreateNode(TreeBuildingState& aState,
AsyncPanZoomController* aApzc,
LayersId aLayersId);

View File

@ -53,7 +53,8 @@ enum class ScrollSource {
};
MOZ_DEFINE_ENUM_CLASS_WITH_BASE(APZWheelAction, uint8_t, (
Scroll
Scroll,
PinchZoom
))
// Epsilon to be used when comparing 'float' coordinate values

View File

@ -2631,11 +2631,12 @@ pref("mousewheel.system_scroll_override_on_root_content.horizontal.factor", 200)
// 0: Nothing happens
// 1: Scrolling contents
// 2: Go back or go forward, in your history
// 3: Zoom in or out.
// 3: Zoom in or out (reflowing zoom).
// 4: Treat vertical wheel as horizontal scroll
// This treats vertical wheel operation (i.e., deltaY) as horizontal
// scroll. deltaX and deltaZ are always ignored. So, only
// "delta_multiplier_y" pref affects the scroll speed.
// 5: Zoom in or out (pinch zoom).
pref("mousewheel.default.action", 1);
pref("mousewheel.with_alt.action", 2);
pref("mousewheel.with_control.action", 3);