// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CC_INPUT_SNAP_SELECTION_STRATEGY_H_ #define CC_INPUT_SNAP_SELECTION_STRATEGY_H_ #include <memory> #include "cc/input/scroll_snap_data.h" namespace cc { enum class SnapStopAlwaysFilter { … }; enum class SnapTargetsPrioritization { … }; // This class represents an abstract strategy that decide which snap selection // should be considered valid. There are concrete implementations for three core // scrolling types: scroll with end position only, scroll with direction only, // and scroll with end position and direction. class CC_EXPORT SnapSelectionStrategy { … }; // Examples for intended end position scrolls include // - a panning gesture, released without momentum // - manupulating the scrollbar "thumb" explicitly // - programmatically scrolling via APIs such as scrollTo() // - tabbing through the document's focusable elements // - navigating to an anchor within the page // - homing operations such as the Home/End keys // For this type of scrolls, we want to // * Minimize the distance between the snap position and the end position. // * Return the end position if that makes a snap area covers the snapport. class EndPositionStrategy : public SnapSelectionStrategy { … }; // Examples for intended direction scrolls include // - pressing an arrow key on the keyboard // - a swiping gesture interpreted as a fixed (rather than inertial) scroll // For this type of scrolls, we want to // * Minimize the distance between the snap position and the starting position, // so that we stop at the first snap position in that direction. // * Return the default intended position (using the default step) if that makes // a snap area covers the snapport. class DirectionStrategy : public SnapSelectionStrategy { … }; // Examples for intended direction and end position scrolls include // - a “fling” gesture, interpreted with momentum // - programmatically scrolling via APIs such as scrollBy() // - paging operations such as the PgUp/PgDn keys (or equivalent operations on // the scrollbar) // For this type of scrolls, we want to // * Minimize the distance between the snap position and the end position. // * Return the end position if that makes a snap area covers the snapport. class EndAndDirectionStrategy : public SnapSelectionStrategy { … }; } // namespace cc #endif // CC_INPUT_SNAP_SELECTION_STRATEGY_H_