APZPublicUtils.h (3558B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_layers_APZPublicUtils_h 8 #define mozilla_layers_APZPublicUtils_h 9 10 // This file is for APZ-related utilities that need to be consumed from outside 11 // of gfx/layers. For internal utilities, prefer APZUtils.h. 12 13 #include <stdint.h> 14 #include "ScrollAnimationBezierPhysics.h" 15 #include "Units.h" 16 #include "mozilla/DefineEnum.h" 17 #include "mozilla/ScrollOrigin.h" 18 #include "mozilla/gfx/Point.h" 19 #include "mozilla/ScrollTypes.h" 20 21 namespace mozilla { 22 23 namespace layers { 24 25 struct FrameMetrics; 26 27 // clang-format off 28 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(APZWheelAction, uint8_t, ( 29 Scroll, 30 PinchZoom 31 )) 32 // clang-format on 33 34 enum class DispatchToContent : bool { No, Yes }; 35 36 namespace apz { 37 38 /** 39 * Initializes the global state used in AsyncPanZoomController. 40 * This is normally called when it is first needed in the constructor 41 * of APZCTreeManager, but can be called manually to force it to be 42 * initialized earlier. 43 */ 44 void InitializeGlobalState(); 45 46 /** 47 * See AsyncPanZoomController::CalculatePendingDisplayPort. This 48 * function simply delegates to that one, so that non-layers code 49 * never needs to include AsyncPanZoomController.h 50 */ 51 const ScreenMargin CalculatePendingDisplayPort( 52 const FrameMetrics& aFrameMetrics, const ParentLayerPoint& aVelocity); 53 54 /** 55 * Returns a width and height multiplier, each of which between 1 and 8 56 * inclusive. The multiplier is chosen based on the provided base size, such 57 * that multiplier is larger when the base size is larger. 58 * We use a large displayport alignment because moving the displayport is 59 * relatively expensive with WebRender. 60 */ 61 gfx::Size GetDisplayportAlignmentMultiplier(const ScreenSize& aBaseSize); 62 63 /** 64 * Calculate the physics parameters for smooth scroll animations for the 65 * given origin, based on pref values. 66 */ 67 ScrollAnimationBezierPhysicsSettings ComputeBezierAnimationSettingsForOrigin( 68 ScrollOrigin aOrigin); 69 70 /** 71 * Calculate if the scrolling should be instant or smooth based based on 72 * preferences and the origin 73 */ 74 ScrollMode GetScrollModeForOrigin(ScrollOrigin origin); 75 76 /** 77 * The kind of an APZ smooth scroll animation. 78 * This needs to be in APZPublicUtils.h because it's used by 79 * layout/generic/ScrollAnimationMSDPhysics{h.cpp} as well. 80 */ 81 enum class ScrollAnimationKind : uint8_t { 82 // Scroll animation in response to programmatic scrolling performed 83 // by the page or otherwise triggered by the main thread (e.g. for 84 // scroll-to-anchor, or certain scrollbar interactions). This may 85 // use Bezier or MSD physics depending on pref values. 86 Smooth, 87 // Scroll animation used to perform scroll snapping, or other 88 // operations triggered by the main thread using ScrollMode::SmoothMsd. 89 // This always uses MSD physics, and the parameter may be different 90 // than when using MSD physics for other ScrollAnimationKinds. 91 SmoothMsd, 92 // Scroll animation in response to user keyboard input. 93 // Uses the same scroll physics as ScrollAnimationKind::Smooth. 94 Keyboard, 95 // Scroll animation in response to user wheel input. 96 // Uses the same scroll physics as ScrollAnimationKind::Smooth. 97 Wheel 98 }; 99 100 } // namespace apz 101 102 } // namespace layers 103 } // namespace mozilla 104 105 #endif // mozilla_layers_APZPublicUtils_h