зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1351783 part 15 - Hook up APZC for scrolling based on a KeyboardScrollAction. r=kats,botond
This commit adds code for keyboard scroll animations and computing the delta needed for a keyboard scroll action. Keyboard scrolling behavior is more complex with scroll snapping, so we don't support async keyboard scrolling when we have scroll snap points. MozReview-Commit-ID: 97CpprCBp2A --HG-- extra : rebase_source : 154b2c6b5a6c587fca011ab885c8d46ba6b4d80a extra : histedit_source : 87ba53fe89069a47751d9ce25fc344011fb0f4de
This commit is contained in:
Родитель
285770048d
Коммит
c24e099b23
|
@ -18,6 +18,7 @@ namespace mozilla {
|
|||
namespace layers {
|
||||
|
||||
class WheelScrollAnimation;
|
||||
class KeyboardScrollAnimation;
|
||||
class SmoothScrollAnimation;
|
||||
|
||||
class AsyncPanZoomAnimation {
|
||||
|
@ -50,6 +51,9 @@ public:
|
|||
return Move(mDeferredTasks);
|
||||
}
|
||||
|
||||
virtual KeyboardScrollAnimation* AsKeyboardScrollAnimation() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual WheelScrollAnimation* AsWheelScrollAnimation() {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@
|
|||
#include "SharedMemoryBasic.h" // for SharedMemoryBasic
|
||||
#include "ScrollSnap.h" // for ScrollSnapUtils
|
||||
#include "WheelScrollAnimation.h"
|
||||
#include "KeyboardScrollAnimation.h"
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
#include "AndroidAPZ.h"
|
||||
#include "mozilla/layers/AndroidDynamicToolbarAnimator.h"
|
||||
|
@ -1005,6 +1006,11 @@ nsEventStatus AsyncPanZoomController::HandleInputEvent(const InputData& aEvent,
|
|||
rv = HandleGestureEvent(tapInput);
|
||||
break;
|
||||
}
|
||||
case KEYBOARD_INPUT: {
|
||||
KeyboardInput keyInput = aEvent.AsKeyboardInput();
|
||||
rv = OnKeyboard(keyInput);
|
||||
break;
|
||||
}
|
||||
case SENTINEL_INPUT: {
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid value");
|
||||
break;
|
||||
|
@ -1067,6 +1073,7 @@ nsEventStatus AsyncPanZoomController::OnTouchStart(const MultiTouchInput& aEvent
|
|||
case SMOOTH_SCROLL:
|
||||
case OVERSCROLL_ANIMATION:
|
||||
case WHEEL_SCROLL:
|
||||
case KEYBOARD_SCROLL:
|
||||
case PAN_MOMENTUM:
|
||||
MOZ_ASSERT(GetCurrentTouchBlock());
|
||||
GetCurrentTouchBlock()->GetOverscrollHandoffChain()->CancelAnimations(ExcludeOverscroll);
|
||||
|
@ -1142,6 +1149,7 @@ nsEventStatus AsyncPanZoomController::OnTouchMove(const MultiTouchInput& aEvent)
|
|||
return nsEventStatus_eIgnore;
|
||||
|
||||
case WHEEL_SCROLL:
|
||||
case KEYBOARD_SCROLL:
|
||||
case OVERSCROLL_ANIMATION:
|
||||
// Should not receive a touch-move in the OVERSCROLL_ANIMATION state
|
||||
// as touch blocks that begin in an overscrolled state cancel the
|
||||
|
@ -1222,6 +1230,7 @@ nsEventStatus AsyncPanZoomController::OnTouchEnd(const MultiTouchInput& aEvent)
|
|||
return nsEventStatus_eIgnore;
|
||||
|
||||
case WHEEL_SCROLL:
|
||||
case KEYBOARD_SCROLL:
|
||||
case OVERSCROLL_ANIMATION:
|
||||
// Should not receive a touch-end in the OVERSCROLL_ANIMATION state
|
||||
// as touch blocks that begin in an overscrolled state cancel the
|
||||
|
@ -1656,6 +1665,117 @@ AsyncPanZoomController::GetScrollWheelDelta(const ScrollWheelInput& aEvent) cons
|
|||
return delta;
|
||||
}
|
||||
|
||||
nsEventStatus
|
||||
AsyncPanZoomController::OnKeyboard(const KeyboardInput& aEvent)
|
||||
{
|
||||
// Calculate the destination for this keyboard scroll action
|
||||
nsPoint destination = CSSPoint::ToAppUnits(GetKeyboardDestination(aEvent.mAction));
|
||||
|
||||
// The lock must be held across the entire update operation, so the
|
||||
// compositor doesn't end the animation before we get a chance to
|
||||
// update it.
|
||||
ReentrantMonitorAutoEnter lock(mMonitor);
|
||||
|
||||
// Use a keyboard scroll animation to scroll, reusing an existing one if it exists
|
||||
if (mState != KEYBOARD_SCROLL) {
|
||||
CancelAnimation();
|
||||
SetState(KEYBOARD_SCROLL);
|
||||
|
||||
nsPoint initialPosition = CSSPoint::ToAppUnits(mFrameMetrics.GetScrollOffset());
|
||||
StartAnimation(new KeyboardScrollAnimation(*this, initialPosition, aEvent.mAction.mType));
|
||||
}
|
||||
|
||||
// Cast velocity from ParentLayerPoints/ms to CSSPoints/ms then convert to
|
||||
// appunits/second. We perform a cast to ParentLayerPoints/ms without a
|
||||
// conversion so that the scroll duration isn't affected by zoom
|
||||
nsPoint velocity =
|
||||
CSSPoint::ToAppUnits(CSSPoint(mX.GetVelocity(), mY.GetVelocity())) * 1000.0f;
|
||||
|
||||
KeyboardScrollAnimation* animation = mAnimation->AsKeyboardScrollAnimation();
|
||||
MOZ_ASSERT(animation);
|
||||
|
||||
animation->UpdateDestination(aEvent.mTimeStamp, destination, nsSize(velocity.x, velocity.y));
|
||||
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
|
||||
CSSPoint
|
||||
AsyncPanZoomController::GetKeyboardDestination(const KeyboardScrollAction& aAction) const
|
||||
{
|
||||
CSSSize lineScrollSize;
|
||||
CSSSize pageScrollSize;
|
||||
CSSPoint scrollOffset;
|
||||
CSSRect scrollRect;
|
||||
|
||||
{
|
||||
// Grab the lock to access the frame metrics.
|
||||
ReentrantMonitorAutoEnter lock(mMonitor);
|
||||
|
||||
lineScrollSize = mScrollMetadata.GetLineScrollAmount() /
|
||||
mFrameMetrics.GetDevPixelsPerCSSPixel();
|
||||
pageScrollSize = mScrollMetadata.GetPageScrollAmount() /
|
||||
mFrameMetrics.GetDevPixelsPerCSSPixel();
|
||||
|
||||
if (mState == WHEEL_SCROLL) {
|
||||
scrollOffset = mAnimation->AsWheelScrollAnimation()->GetDestination();
|
||||
} else if (mState == SMOOTH_SCROLL) {
|
||||
scrollOffset = mAnimation->AsSmoothScrollAnimation()->GetDestination();
|
||||
} else if (mState == KEYBOARD_SCROLL) {
|
||||
scrollOffset = mAnimation->AsKeyboardScrollAnimation()->GetDestination();
|
||||
} else {
|
||||
scrollOffset = mFrameMetrics.GetScrollOffset();
|
||||
}
|
||||
|
||||
scrollRect = mFrameMetrics.GetScrollableRect();
|
||||
}
|
||||
|
||||
// Calculate the scroll destination based off of the scroll type and direction
|
||||
CSSPoint scrollDestination = scrollOffset;
|
||||
|
||||
switch (aAction.mType) {
|
||||
case KeyboardScrollAction::eScrollCharacter: {
|
||||
int32_t scrollDistance = gfxPrefs::ToolkitHorizontalScrollDistance();
|
||||
|
||||
if (aAction.mForward) {
|
||||
scrollDestination.x += scrollDistance * lineScrollSize.width;
|
||||
} else {
|
||||
scrollDestination.x -= scrollDistance * lineScrollSize.width;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eScrollLine: {
|
||||
int32_t scrollDistance = gfxPrefs::ToolkitVerticalScrollDistance();
|
||||
|
||||
if (aAction.mForward) {
|
||||
scrollDestination.y += scrollDistance * lineScrollSize.height;
|
||||
} else {
|
||||
scrollDestination.y -= scrollDistance * lineScrollSize.height;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eScrollPage: {
|
||||
if (aAction.mForward) {
|
||||
scrollDestination.y += pageScrollSize.height;
|
||||
} else {
|
||||
scrollDestination.y -= pageScrollSize.height;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eScrollComplete: {
|
||||
if (aAction.mForward) {
|
||||
scrollDestination.y = scrollRect.YMost();
|
||||
} else {
|
||||
scrollDestination.y = scrollRect.y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eSentinel:
|
||||
MOZ_ASSERT_UNREACHABLE("unexpected keyboard delta type");
|
||||
}
|
||||
|
||||
return scrollDestination;
|
||||
}
|
||||
|
||||
// Return whether or not the underlying layer can be scrolled on either axis.
|
||||
bool
|
||||
AsyncPanZoomController::CanScroll(const InputData& aEvent) const
|
||||
|
@ -1822,6 +1942,8 @@ nsEventStatus AsyncPanZoomController::OnScrollWheel(const ScrollWheelInput& aEve
|
|||
startPosition = mAnimation->AsWheelScrollAnimation()->GetDestination();
|
||||
} else if (mState == SMOOTH_SCROLL) {
|
||||
startPosition = mAnimation->AsSmoothScrollAnimation()->GetDestination();
|
||||
} else if (mState == KEYBOARD_SCROLL) {
|
||||
startPosition = mAnimation->AsKeyboardScrollAnimation()->GetDestination();
|
||||
}
|
||||
if (MaybeAdjustDeltaForScrollSnapping(aEvent, delta, startPosition)) {
|
||||
// If we're scroll snapping, use a smooth scroll animation to get
|
||||
|
@ -1845,7 +1967,8 @@ nsEventStatus AsyncPanZoomController::OnScrollWheel(const ScrollWheelInput& aEve
|
|||
nsPoint deltaInAppUnits =
|
||||
CSSPoint::ToAppUnits(delta / mFrameMetrics.GetZoom());
|
||||
// Cast velocity from ParentLayerPoints/ms to CSSPoints/ms then convert to
|
||||
// appunits/second
|
||||
// appunits/second. We perform a cast to ParentLayerPoints/ms without a
|
||||
// conversion so that the scroll duration isn't affected by zoom
|
||||
nsPoint velocity =
|
||||
CSSPoint::ToAppUnits(CSSPoint(mX.GetVelocity(), mY.GetVelocity())) * 1000.0f;
|
||||
|
||||
|
@ -2608,7 +2731,8 @@ void AsyncPanZoomController::SmoothScrollTo(const CSSPoint& aDestination) {
|
|||
SetState(SMOOTH_SCROLL);
|
||||
nsPoint initialPosition = CSSPoint::ToAppUnits(mFrameMetrics.GetScrollOffset());
|
||||
// Cast velocity from ParentLayerPoints/ms to CSSPoints/ms then convert to
|
||||
// appunits/second
|
||||
// appunits/second. We perform a cast to ParentLayerPoints/ms without a
|
||||
// conversion so that the scroll duration isn't affected by zoom
|
||||
nsPoint initialVelocity = CSSPoint::ToAppUnits(CSSPoint(mX.GetVelocity(),
|
||||
mY.GetVelocity())) * 1000.0f;
|
||||
nsPoint destination = CSSPoint::ToAppUnits(aDestination);
|
||||
|
|
|
@ -61,6 +61,7 @@ class OverscrollEffectBase;
|
|||
class WidgetOverscrollEffect;
|
||||
class GenericOverscrollEffect;
|
||||
class AndroidSpecificState;
|
||||
struct KeyboardScrollAction;
|
||||
|
||||
// Base class for grouping platform-specific APZC state variables.
|
||||
class PlatformSpecificStateBase {
|
||||
|
@ -482,6 +483,13 @@ protected:
|
|||
|
||||
ParentLayerPoint GetScrollWheelDelta(const ScrollWheelInput& aEvent) const;
|
||||
|
||||
/**
|
||||
* Helper methods for handling keyboard events.
|
||||
*/
|
||||
nsEventStatus OnKeyboard(const KeyboardInput& aEvent);
|
||||
|
||||
CSSPoint GetKeyboardDestination(const KeyboardScrollAction& aAction) const;
|
||||
|
||||
/**
|
||||
* Helper methods for long press gestures.
|
||||
*/
|
||||
|
@ -839,7 +847,8 @@ protected:
|
|||
the finger is lifted. */
|
||||
SMOOTH_SCROLL, /* Smooth scrolling to destination. Used by
|
||||
CSSOM-View smooth scroll-behavior */
|
||||
WHEEL_SCROLL /* Smooth scrolling to a destination for a wheel event. */
|
||||
WHEEL_SCROLL, /* Smooth scrolling to a destination for a wheel event. */
|
||||
KEYBOARD_SCROLL /* Smooth scrolling to a destination for a keyboard event. */
|
||||
};
|
||||
|
||||
// This is in theory protected by |mMonitor|; that is, it should be held whenever
|
||||
|
@ -938,6 +947,7 @@ private:
|
|||
friend class SmoothScrollAnimation;
|
||||
friend class GenericScrollAnimation;
|
||||
friend class WheelScrollAnimation;
|
||||
friend class KeyboardScrollAnimation;
|
||||
|
||||
friend class GenericOverscrollEffect;
|
||||
friend class WidgetOverscrollEffect;
|
||||
|
|
|
@ -24,13 +24,27 @@ GenericScrollAnimation::GenericScrollAnimation(AsyncPanZoomController& aApzc,
|
|||
|
||||
void
|
||||
GenericScrollAnimation::UpdateDelta(TimeStamp aTime, nsPoint aDelta, const nsSize& aCurrentVelocity)
|
||||
{
|
||||
mFinalDestination += aDelta;
|
||||
|
||||
Update(aTime, aCurrentVelocity);
|
||||
}
|
||||
|
||||
void
|
||||
GenericScrollAnimation::UpdateDestination(TimeStamp aTime, nsPoint aDestination, const nsSize& aCurrentVelocity)
|
||||
{
|
||||
mFinalDestination = aDestination;
|
||||
|
||||
Update(aTime, aCurrentVelocity);
|
||||
}
|
||||
|
||||
void
|
||||
GenericScrollAnimation::Update(TimeStamp aTime, const nsSize& aCurrentVelocity)
|
||||
{
|
||||
if (mIsFirstIteration) {
|
||||
InitializeHistory(aTime);
|
||||
}
|
||||
|
||||
mFinalDestination += aDelta;
|
||||
|
||||
// Clamp the final destination to the scrollable area.
|
||||
CSSPoint clamped = CSSPoint::FromAppUnits(mFinalDestination);
|
||||
clamped.x = mApzc.mX.ClampOriginToScrollableRect(clamped.x);
|
||||
|
|
|
@ -24,12 +24,17 @@ public:
|
|||
const nsPoint& aInitialPosition);
|
||||
|
||||
bool DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta) override;
|
||||
|
||||
void UpdateDelta(TimeStamp aTime, nsPoint aDelta, const nsSize& aCurrentVelocity);
|
||||
void UpdateDestination(TimeStamp aTime, nsPoint aDestination, const nsSize& aCurrentVelocity);
|
||||
|
||||
CSSPoint GetDestination() const {
|
||||
return CSSPoint::FromAppUnits(mFinalDestination);
|
||||
}
|
||||
|
||||
private:
|
||||
void Update(TimeStamp aTime, const nsSize& aCurrentVelocity);
|
||||
|
||||
protected:
|
||||
AsyncPanZoomController& mApzc;
|
||||
nsPoint mFinalDestination;
|
||||
|
|
|
@ -10,36 +10,6 @@
|
|||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
/* static */ nsIScrollableFrame::ScrollUnit
|
||||
KeyboardScrollAction::GetScrollUnit(KeyboardScrollAction::KeyboardScrollActionType aDeltaType)
|
||||
{
|
||||
switch (aDeltaType) {
|
||||
case KeyboardScrollAction::eScrollCharacter:
|
||||
return nsIScrollableFrame::LINES;
|
||||
case KeyboardScrollAction::eScrollLine:
|
||||
return nsIScrollableFrame::LINES;
|
||||
case KeyboardScrollAction::eScrollPage:
|
||||
return nsIScrollableFrame::PAGES;
|
||||
case KeyboardScrollAction::eScrollComplete:
|
||||
return nsIScrollableFrame::WHOLE;
|
||||
case KeyboardScrollAction::eSentinel:
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid KeyboardScrollActionType.");
|
||||
return nsIScrollableFrame::WHOLE;
|
||||
}
|
||||
}
|
||||
|
||||
KeyboardScrollAction::KeyboardScrollAction()
|
||||
: mType(KeyboardScrollAction::eScrollCharacter)
|
||||
, mForward(false)
|
||||
{
|
||||
}
|
||||
|
||||
KeyboardScrollAction::KeyboardScrollAction(KeyboardScrollActionType aType, bool aForward)
|
||||
: mType(aType)
|
||||
, mForward(aForward)
|
||||
{
|
||||
}
|
||||
|
||||
KeyboardShortcut::KeyboardShortcut()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "nsIScrollableFrame.h" // for nsIScrollableFrame::ScrollUnit
|
||||
#include "nsTArray.h" // for nsTArray
|
||||
#include "mozilla/Maybe.h" // for mozilla::Maybe
|
||||
#include "KeyboardScrollAction.h" // for KeyboardScrollAction
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -21,35 +22,6 @@ namespace layers {
|
|||
|
||||
class KeyboardMap;
|
||||
|
||||
/**
|
||||
* This class represents a scrolling action to be performed on a scrollable layer.
|
||||
*/
|
||||
struct KeyboardScrollAction final
|
||||
{
|
||||
public:
|
||||
enum KeyboardScrollActionType : uint8_t
|
||||
{
|
||||
eScrollCharacter,
|
||||
eScrollLine,
|
||||
eScrollPage,
|
||||
eScrollComplete,
|
||||
|
||||
// Used as an upper bound for ContiguousEnumSerializer
|
||||
eSentinel,
|
||||
};
|
||||
|
||||
static nsIScrollableFrame::ScrollUnit
|
||||
GetScrollUnit(KeyboardScrollActionType aDeltaType);
|
||||
|
||||
KeyboardScrollAction();
|
||||
KeyboardScrollAction(KeyboardScrollActionType aType, bool aForward);
|
||||
|
||||
// The type of scroll to perform for this action
|
||||
KeyboardScrollActionType mType;
|
||||
// Whether to scroll forward or backward along the axis of this action type
|
||||
bool mForward;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is an off main-thread <xul:handler> for scrolling commands.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/layers/KeyboardScrollAction.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
/* static */ nsIScrollableFrame::ScrollUnit
|
||||
KeyboardScrollAction::GetScrollUnit(KeyboardScrollAction::KeyboardScrollActionType aDeltaType)
|
||||
{
|
||||
switch (aDeltaType) {
|
||||
case KeyboardScrollAction::eScrollCharacter:
|
||||
return nsIScrollableFrame::LINES;
|
||||
case KeyboardScrollAction::eScrollLine:
|
||||
return nsIScrollableFrame::LINES;
|
||||
case KeyboardScrollAction::eScrollPage:
|
||||
return nsIScrollableFrame::PAGES;
|
||||
case KeyboardScrollAction::eScrollComplete:
|
||||
return nsIScrollableFrame::WHOLE;
|
||||
case KeyboardScrollAction::eSentinel:
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid KeyboardScrollActionType.");
|
||||
return nsIScrollableFrame::WHOLE;
|
||||
}
|
||||
|
||||
// Silence an overzealous warning
|
||||
return nsIScrollableFrame::WHOLE;
|
||||
}
|
||||
|
||||
KeyboardScrollAction::KeyboardScrollAction()
|
||||
: mType(KeyboardScrollAction::eScrollCharacter)
|
||||
, mForward(false)
|
||||
{
|
||||
}
|
||||
|
||||
KeyboardScrollAction::KeyboardScrollAction(KeyboardScrollActionType aType, bool aForward)
|
||||
: mType(aType)
|
||||
, mForward(aForward)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_layers_KeyboardScrollAction_h
|
||||
#define mozilla_layers_KeyboardScrollAction_h
|
||||
|
||||
#include "nsIScrollableFrame.h" // for nsIScrollableFrame::ScrollUnit
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
/**
|
||||
* This class represents a scrolling action to be performed on a scrollable layer.
|
||||
*/
|
||||
struct KeyboardScrollAction final
|
||||
{
|
||||
public:
|
||||
enum KeyboardScrollActionType : uint8_t
|
||||
{
|
||||
eScrollCharacter,
|
||||
eScrollLine,
|
||||
eScrollPage,
|
||||
eScrollComplete,
|
||||
|
||||
// Used as an upper bound for ContiguousEnumSerializer
|
||||
eSentinel,
|
||||
};
|
||||
|
||||
static nsIScrollableFrame::ScrollUnit
|
||||
GetScrollUnit(KeyboardScrollActionType aDeltaType);
|
||||
|
||||
KeyboardScrollAction();
|
||||
KeyboardScrollAction(KeyboardScrollActionType aType, bool aForward);
|
||||
|
||||
// The type of scroll to perform for this action
|
||||
KeyboardScrollActionType mType;
|
||||
// Whether to scroll forward or backward along the axis of this action type
|
||||
bool mForward;
|
||||
};
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_layers_KeyboardScrollAction_h
|
|
@ -0,0 +1,47 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et tw=80 : */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "KeyboardScrollAnimation.h"
|
||||
|
||||
#include "gfxPrefs.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
KeyboardScrollAnimation::KeyboardScrollAnimation(AsyncPanZoomController& aApzc,
|
||||
const nsPoint& aInitialPosition,
|
||||
KeyboardScrollAction::KeyboardScrollActionType aType)
|
||||
: GenericScrollAnimation(aApzc, aInitialPosition)
|
||||
{
|
||||
switch (aType) {
|
||||
case KeyboardScrollAction::eScrollCharacter:
|
||||
case KeyboardScrollAction::eScrollLine: {
|
||||
mOriginMaxMS = clamped(gfxPrefs::LineSmoothScrollMaxDurationMs(), 0, 10000);
|
||||
mOriginMinMS = clamped(gfxPrefs::LineSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eScrollPage: {
|
||||
mOriginMaxMS = clamped(gfxPrefs::PageSmoothScrollMaxDurationMs(), 0, 10000);
|
||||
mOriginMinMS = clamped(gfxPrefs::PageSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eScrollComplete: {
|
||||
mOriginMaxMS = clamped(gfxPrefs::OtherSmoothScrollMaxDurationMs(), 0, 10000);
|
||||
mOriginMinMS = clamped(gfxPrefs::OtherSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
|
||||
break;
|
||||
}
|
||||
case KeyboardScrollAction::eSentinel: {
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid KeyboardScrollActionType.");
|
||||
}
|
||||
}
|
||||
|
||||
// The pref is 100-based int percentage, while mIntervalRatio is 1-based ratio
|
||||
mIntervalRatio = ((double)gfxPrefs::SmoothScrollDurationToIntervalRatio()) / 100.0;
|
||||
mIntervalRatio = std::max(1.0, mIntervalRatio);
|
||||
}
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et tw=80 : */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_layers_KeyboardScrollAnimation_h_
|
||||
#define mozilla_layers_KeyboardScrollAnimation_h_
|
||||
|
||||
#include "GenericScrollAnimation.h"
|
||||
#include "mozilla/layers/Keyboard.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class AsyncPanZoomController;
|
||||
|
||||
class KeyboardScrollAnimation
|
||||
: public GenericScrollAnimation
|
||||
{
|
||||
public:
|
||||
KeyboardScrollAnimation(AsyncPanZoomController& aApzc,
|
||||
const nsPoint& aInitialPosition,
|
||||
KeyboardScrollAction::KeyboardScrollActionType aType);
|
||||
|
||||
KeyboardScrollAnimation* AsKeyboardScrollAnimation() override {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_layers_KeyboardScrollAnimation_h_
|
|
@ -105,6 +105,7 @@ EXPORTS.mozilla.layers += [
|
|||
'apz/src/FocusState.h',
|
||||
'apz/src/FocusTarget.h',
|
||||
'apz/src/Keyboard.h',
|
||||
'apz/src/KeyboardScrollAction.h',
|
||||
'apz/src/TouchCounter.h',
|
||||
'apz/testutil/APZTestData.h',
|
||||
'apz/util/ActiveElementManager.h',
|
||||
|
@ -298,6 +299,8 @@ UNIFIED_SOURCES += [
|
|||
'apz/src/InputBlockState.cpp',
|
||||
'apz/src/InputQueue.cpp',
|
||||
'apz/src/Keyboard.cpp',
|
||||
'apz/src/KeyboardScrollAction.cpp',
|
||||
'apz/src/KeyboardScrollAnimation.cpp',
|
||||
'apz/src/OverscrollHandoffState.cpp',
|
||||
'apz/src/PotentialCheckerboardDurationTracker.cpp',
|
||||
'apz/src/QueuedInput.cpp',
|
||||
|
|
|
@ -366,11 +366,20 @@ private:
|
|||
SmoothScrollCurrentVelocityWeighting, float, 0.25);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.durationToIntervalRatio",
|
||||
SmoothScrollDurationToIntervalRatio, int32_t, 200);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.lines", LineSmoothScrollEnabled, bool, true);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.lines.durationMaxMS",
|
||||
LineSmoothScrollMaxDurationMs, int32_t, 150);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.lines.durationMinMS",
|
||||
LineSmoothScrollMinDurationMs, int32_t, 150);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.mouseWheel", WheelSmoothScrollEnabled, bool, true);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.mouseWheel.durationMaxMS",
|
||||
WheelSmoothScrollMaxDurationMs, int32_t, 400);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.mouseWheel.durationMinMS",
|
||||
WheelSmoothScrollMinDurationMs, int32_t, 200);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.other.durationMaxMS",
|
||||
OtherSmoothScrollMaxDurationMs, int32_t, 150);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.other.durationMinMS",
|
||||
OtherSmoothScrollMinDurationMs, int32_t, 150);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.pages", PageSmoothScrollEnabled, bool, true);
|
||||
DECL_GFX_PREF(Live, "general.smoothScroll.pages.durationMaxMS",
|
||||
PageSmoothScrollMaxDurationMs, int32_t, 150);
|
||||
|
@ -660,6 +669,9 @@ private:
|
|||
DECL_GFX_PREF(Live, "test.events.async.enabled", TestEventsAsyncEnabled, bool, false);
|
||||
DECL_GFX_PREF(Live, "test.mousescroll", MouseScrollTestingEnabled, bool, false);
|
||||
|
||||
DECL_GFX_PREF(Live, "toolkit.scrollbox.horizontalScrollDistance", ToolkitHorizontalScrollDistance, int32_t, 5);
|
||||
DECL_GFX_PREF(Live, "toolkit.scrollbox.verticalScrollDistance", ToolkitVerticalScrollDistance, int32_t, 3);
|
||||
|
||||
DECL_GFX_PREF(Live, "ui.click_hold_context_menus.delay", UiClickHoldContextMenusDelay, int32_t, 500);
|
||||
|
||||
// WebGL (for pref access from Worker threads)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "mozilla/EventForwards.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/gfx/MatrixFwd.h"
|
||||
#include "mozilla/layers/KeyboardScrollAction.h"
|
||||
|
||||
template<class E> struct already_AddRefed;
|
||||
class nsIWidget;
|
||||
|
@ -623,6 +624,8 @@ public:
|
|||
class KeyboardInput : public InputData
|
||||
{
|
||||
public:
|
||||
typedef mozilla::layers::KeyboardScrollAction KeyboardScrollAction;
|
||||
|
||||
enum KeyboardEventType
|
||||
{
|
||||
KEY_DOWN,
|
||||
|
@ -647,6 +650,10 @@ public:
|
|||
|
||||
bool mHandledByAPZ;
|
||||
|
||||
// The scroll action to perform on a layer for this keyboard input. This is
|
||||
// only used in APZ and is NOT serialized over IPC.
|
||||
KeyboardScrollAction mAction;
|
||||
|
||||
protected:
|
||||
friend mozilla::layers::PAPZCTreeManagerParent;
|
||||
friend mozilla::layers::APZCTreeManagerChild;
|
||||
|
|
Загрузка…
Ссылка в новой задаче