1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PAGE_SCROLLING_SNAP_COORDINATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAGE_SCROLLING_SNAP_COORDINATOR_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/css_primitive_value_mappings.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class LayoutBox;
// Snap Coordinator keeps track of snap containers and all of their associated
// snap areas. It also contains the logic to generate the list of valid snap
// positions for a given snap container.
//
// Snap container:
// An scroll container that has 'scroll-snap-type' value other
// than 'none'.
// Snap area:
// A snap container's descendant that contributes snap positions. An element
// only contributes snap positions to its nearest ancestor (on the element’s
// containing block chain) scroll container.
//
// For more information see spec: https://drafts.csswg.org/css-snappoints/
class CORE_EXPORT SnapCoordinator final
: public GarbageCollectedFinalized<SnapCoordinator> {
public:
static SnapCoordinator* Create();
~SnapCoordinator();
void Trace(blink::Visitor* visitor) {}
void SnapContainerDidChange(LayoutBox&, ScrollSnapType);
void SnapAreaDidChange(LayoutBox&, ScrollSnapAlign);
// Returns the SnapContainerData if the snap container has one.
base::Optional<SnapContainerData> GetSnapContainerData(
const LayoutBox& snap_container) const;
// Calculate the SnapAreaData for the specific snap area in its snap
// container.
SnapAreaData CalculateSnapAreaData(const LayoutBox& snap_area,
const LayoutBox& snap_container);
// Called by LocalFrameView::PerformPostLayoutTasks(), so that the snap data
// are updated whenever a layout happens.
void UpdateAllSnapContainerData();
void UpdateSnapContainerData(const LayoutBox&);
// Called by ScrollManager::HandleGestureScrollEnd() to animate to the snap
// position for the current scroll on the specific direction if there is
// a valid snap position.
void PerformSnapping(const LayoutBox& snap_container,
bool did_scroll_x,
bool did_scroll_y);
base::Optional<FloatPoint> GetSnapPositionForPoint(
const LayoutBox& snap_container,
const FloatPoint& natural_position,
bool did_scroll_x,
bool did_scroll_y);
bool GetSnapFlingInfo(const LayoutBox& snap_container,
const gfx::Vector2dF& natural_displacement,
gfx::Vector2dF* out_initial_offset,
gfx::Vector2dF* out_target_offset);
#ifndef NDEBUG
void ShowSnapAreaMap();
void ShowSnapAreasFor(const LayoutBox*);
void ShowSnapDataFor(const LayoutBox*);
#endif
private:
friend class SnapCoordinatorTest;
explicit SnapCoordinator();
HashMap<const LayoutBox*, SnapContainerData> snap_container_map_;
DISALLOW_COPY_AND_ASSIGN(SnapCoordinator);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAGE_SCROLLING_SNAP_COORDINATOR_H_
|