scroll_utils.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CC_INPUT_SCROLL_UTILS_H_
  5. #define CC_INPUT_SCROLL_UTILS_H_
  6. #include "cc/cc_export.h"
  7. namespace gfx {
  8. class Vector2dF;
  9. class SizeF;
  10. } // namespace gfx
  11. namespace cc {
  12. static constexpr int kPixelsPerLineStep = 40;
  13. static constexpr float kMinFractionToStepWhenPaging = 0.875f;
  14. // Each directional scroll for percentage-based units should scroll 1/8th of
  15. // the scrollable area.
  16. static constexpr float kPercentDeltaForDirectionalScroll = 0.125f;
  17. // Class for scroll helper methods in cc and blink.
  18. class CC_EXPORT ScrollUtils {
  19. public:
  20. // Transforms a |scroll_delta| in percent units to pixel units based in its
  21. // |scroller_size|. Limits it by a maximum of 12.5% of |viewport_size| to
  22. // avoid too large deltas. Inputs and output must be in physical pixels.
  23. static gfx::Vector2dF ResolveScrollPercentageToPixels(
  24. const gfx::Vector2dF& scroll_delta,
  25. const gfx::SizeF& scroller_size,
  26. const gfx::SizeF& viewport_size);
  27. // Transforms a pixel delta into a percentage. Used for when a test needs to
  28. // work with percent based scrolling and non percent based scrolling.
  29. static gfx::Vector2dF ResolvePixelScrollToPercentageForTesting(
  30. const gfx::Vector2dF& pixel_scroll_delta,
  31. const gfx::SizeF& scroller_size,
  32. const gfx::SizeF& viewport_size);
  33. };
  34. } // namespace cc
  35. #endif // CC_INPUT_SCROLL_UTILS_H_