From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- gfx/layers/apz/src/APZPublicUtils.cpp | 111 ++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 gfx/layers/apz/src/APZPublicUtils.cpp (limited to 'gfx/layers/apz/src/APZPublicUtils.cpp') diff --git a/gfx/layers/apz/src/APZPublicUtils.cpp b/gfx/layers/apz/src/APZPublicUtils.cpp new file mode 100644 index 0000000000..6902e0738c --- /dev/null +++ b/gfx/layers/apz/src/APZPublicUtils.cpp @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 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 "mozilla/layers/APZPublicUtils.h" + +#include "AsyncPanZoomController.h" +#include "mozilla/HelperMacros.h" +#include "mozilla/StaticPrefs_general.h" + +namespace mozilla { +namespace layers { + +namespace apz { + +/*static*/ void InitializeGlobalState() { + MOZ_ASSERT(NS_IsMainThread()); + AsyncPanZoomController::InitializeGlobalState(); +} + +/*static*/ const ScreenMargin CalculatePendingDisplayPort( + const FrameMetrics& aFrameMetrics, const ParentLayerPoint& aVelocity) { + return AsyncPanZoomController::CalculatePendingDisplayPort( + aFrameMetrics, aVelocity, AsyncPanZoomController::ZoomInProgress::No); +} + +/*static*/ gfx::IntSize GetDisplayportAlignmentMultiplier( + const ScreenSize& aBaseSize) { + return AsyncPanZoomController::GetDisplayportAlignmentMultiplier(aBaseSize); +} + +ScrollAnimationBezierPhysicsSettings ComputeBezierAnimationSettingsForOrigin( + ScrollOrigin aOrigin) { + int32_t minMS = 0; + int32_t maxMS = 0; + bool isOriginSmoothnessEnabled = false; + +#define READ_DURATIONS(prefbase) \ + isOriginSmoothnessEnabled = StaticPrefs::general_smoothScroll() && \ + StaticPrefs::general_smoothScroll_##prefbase(); \ + if (isOriginSmoothnessEnabled) { \ + minMS = StaticPrefs::general_smoothScroll_##prefbase##_durationMinMS(); \ + maxMS = StaticPrefs::general_smoothScroll_##prefbase##_durationMaxMS(); \ + } + + switch (aOrigin) { + case ScrollOrigin::Pixels: + READ_DURATIONS(pixels) + break; + case ScrollOrigin::Lines: + READ_DURATIONS(lines) + break; + case ScrollOrigin::Pages: + READ_DURATIONS(pages) + break; + case ScrollOrigin::MouseWheel: + READ_DURATIONS(mouseWheel) + break; + case ScrollOrigin::Scrollbars: + READ_DURATIONS(scrollbars) + break; + default: + READ_DURATIONS(other) + break; + } + +#undef READ_DURATIONS + + if (isOriginSmoothnessEnabled) { + static const int32_t kSmoothScrollMaxAllowedAnimationDurationMS = 10000; + maxMS = clamped(maxMS, 0, kSmoothScrollMaxAllowedAnimationDurationMS); + minMS = clamped(minMS, 0, maxMS); + } + + // Keep the animation duration longer than the average event intervals + // (to "connect" consecutive scroll animations before the scroll comes to a + // stop). + double intervalRatio = + ((double)StaticPrefs::general_smoothScroll_durationToIntervalRatio()) / + 100.0; + + // Duration should be at least as long as the intervals -> ratio is at least 1 + intervalRatio = std::max(1.0, intervalRatio); + + return ScrollAnimationBezierPhysicsSettings{minMS, maxMS, intervalRatio}; +} + +ScrollMode GetScrollModeForOrigin(ScrollOrigin origin) { + if (!StaticPrefs::general_smoothScroll()) return ScrollMode::Instant; + switch (origin) { + case ScrollOrigin::Lines: + return StaticPrefs::general_smoothScroll_lines() ? ScrollMode::Smooth + : ScrollMode::Instant; + case ScrollOrigin::Pages: + return StaticPrefs::general_smoothScroll_pages() ? ScrollMode::Smooth + : ScrollMode::Instant; + case ScrollOrigin::Other: + return StaticPrefs::general_smoothScroll_other() ? ScrollMode::Smooth + : ScrollMode::Instant; + default: + MOZ_ASSERT(false, "Unknown keyboard scroll origin"); + return StaticPrefs::general_smoothScroll() ? ScrollMode::Smooth + : ScrollMode::Instant; + } +} + +} // namespace apz +} // namespace layers +} // namespace mozilla -- cgit v1.2.3