tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ScrollSnap.h (3900B)


      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_layout_ScrollSnap_h_
      8 #define mozilla_layout_ScrollSnap_h_
      9 
     10 #include "mozilla/Maybe.h"
     11 #include "mozilla/ScrollSnapTargetId.h"
     12 #include "mozilla/ScrollTypes.h"
     13 
     14 class nsIContent;
     15 class nsIFrame;
     16 struct nsPoint;
     17 struct nsRect;
     18 struct nsSize;
     19 
     20 namespace mozilla {
     21 
     22 struct ScrollSnapInfo;
     23 
     24 struct ScrollSnapUtils {
     25  /**
     26   * GetSnapPointForDestination determines which point to snap to after
     27   * scrolling. |aStartPos| gives the position before scrolling and
     28   * |aDestination| gives the position after scrolling, with no snapping.
     29   * Behaviour is dependent on the value of |aUnit|.
     30   * |aSnapInfo| and |aScrollRange| are characteristics of the scroll frame for
     31   * which snapping is being performed.
     32   * If a suitable snap point could be found, it is returned. Otherwise, an
     33   * empty Maybe is returned.
     34   * IMPORTANT NOTE: This function is designed to be called both on and off
     35   *                 the main thread. If modifying its implementation, be sure
     36   *                 not to touch main-thread-only data structures without
     37   *                 appropriate locking.
     38   */
     39  static Maybe<SnapDestination> GetSnapPointForDestination(
     40      const ScrollSnapInfo& aSnapInfo, ScrollUnit aUnit,
     41      ScrollSnapFlags aSnapFlags, const nsRect& aScrollRange,
     42      const nsPoint& aStartPos, const nsPoint& aDestination);
     43 
     44  /**
     45   * Similar to above GetSnapPointForDestination but for re-snapping.
     46   *
     47   * |aCurrentPosition| are the snap point(s) last time when we scrolled.
     48   * |aLastSnapTargetIds| are the snap point(s) last time when we scrolled if
     49   * exists.
     50   * |aFocusedContent| is the focused content in the document if exists.
     51   * Other parameters are same as GetSnapPointForDestination.
     52   */
     53 
     54  static mozilla::Maybe<SnapDestination> GetSnapPointForResnap(
     55      const ScrollSnapInfo& aSnapInfo, const nsRect& aScrollRange,
     56      const nsPoint& aCurrentPosition,
     57      const UniquePtr<ScrollSnapTargetIds>& aLastSnapTargetIds,
     58      const nsIContent* aFocusedContent);
     59 
     60  static ScrollSnapTargetId GetTargetIdFor(const nsIFrame* aFrame);
     61 
     62  // Post a pending re-snap request if the given |aFrame| is one of the snap
     63  // points on the last scroll operation.
     64  static void PostPendingResnapIfNeededFor(nsIFrame* aFrame);
     65 
     66  // Similar to above PostPendingResnapIfNeededFor but post a pending re-snap
     67  // request even if the given |aFrame| is not one of the last snap point.
     68  // This is basically used for cases there was no valid snap point on the last
     69  // scroll operation but the given |aFrame| might be a valid snap point now,
     70  // e.g changing the scroll-snap-align property from `none` to something.
     71  static void PostPendingResnapFor(nsIFrame* aFrame);
     72 
     73  // Returns true if the writing-mode of the snap target element needs to be
     74  // respected to resolve scroll-snap-align property.
     75  // Note that usually the scroll container's writing-mode is used for resolving
     76  // the property but there's a special case defined in the CSS scroll snap
     77  // spec.
     78  static bool NeedsToRespectTargetWritingMode(const nsSize& aSnapAreaSize,
     79                                              const nsSize& aSnapportSize);
     80 
     81  // Returns the scroll snap area for the snap target frame |aFrame| inside the
     82  // nearest scroll container |aScrolledFrame| and its scrolled rect
     83  // |aScrolledRect|.
     84  static nsRect GetSnapAreaFor(const nsIFrame* aFrame,
     85                               const nsIFrame* aScrolledFrame,
     86                               const nsRect& aScrolledRect);
     87 };
     88 
     89 }  // namespace mozilla
     90 
     91 #endif  // mozilla_layout_ScrollSnap_h_