OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SnapCoordinator_h | 5 #ifndef SnapCoordinator_h |
6 #define SnapCoordinator_h | 6 #define SnapCoordinator_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/css/CSSPrimitiveValueMappings.h" | 9 #include "core/css/CSSPrimitiveValueMappings.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 class ComputedStyle; | 15 class ComputedStyle; |
16 class ContainerNode; | 16 class ContainerNode; |
17 class Element; | 17 class Element; |
18 class LayoutBox; | 18 class LayoutBox; |
19 struct LengthPoint; | 19 struct LengthPoint; |
| 20 class SnapManager; |
| 21 |
| 22 struct SnapOffsets { |
| 23 Vector<double> horizontal; |
| 24 Vector<double> vertical; |
| 25 }; |
20 | 26 |
21 // Snap Coordinator keeps track of snap containers and all of their associated | 27 // Snap Coordinator keeps track of snap containers and all of their associated |
22 // snap areas. It also contains the logic to generate the list of valid snap | 28 // snap areas. It also contains the logic to generate the list of valid snap |
23 // positions for a given snap container. | 29 // positions for a given snap container. |
24 // | 30 // |
25 // Snap container: | 31 // Snap container: |
26 // An scroll container that has 'scroll-snap-type' value other | 32 // An scroll container that has 'scroll-snap-type' value other |
27 // than 'none'. | 33 // than 'none'. |
28 // Snap area: | 34 // Snap area: |
29 // A snap container's descendant that contributes snap positions. An element | 35 // A snap container's descendant that contributes snap positions. An element |
30 // only contributes snap positions to its nearest ancestor (on the element’s | 36 // only contributes snap positions to its nearest ancestor (on the element’s |
31 // containing block chain) scroll container. | 37 // containing block chain) scroll container. |
32 // | 38 // |
33 // For more information see spec: https://drafts.csswg.org/css-snappoints/ | 39 // For more information see spec: https://drafts.csswg.org/css-snappoints/ |
34 class CORE_EXPORT SnapCoordinator final : public GarbageCollectedFinalized<SnapC
oordinator> { | 40 class CORE_EXPORT SnapCoordinator final : public GarbageCollectedFinalized<SnapC
oordinator> { |
35 WTF_MAKE_NONCOPYABLE(SnapCoordinator); | 41 WTF_MAKE_NONCOPYABLE(SnapCoordinator); |
| 42 public: |
| 43 class Client { |
| 44 public: |
| 45 virtual void didUpdateSnapOffsets(const LayoutBox&, SnapOffsets) = 0; |
| 46 }; |
36 | 47 |
37 public: | 48 static SnapCoordinator* create(Client*); |
38 static SnapCoordinator* create(); | |
39 ~SnapCoordinator(); | 49 ~SnapCoordinator(); |
40 DEFINE_INLINE_TRACE() {} | 50 DEFINE_INLINE_TRACE() {} |
41 | 51 |
42 void snapContainerDidChange(LayoutBox&, ScrollSnapType); | 52 void snapContainerDidChange(LayoutBox&, ScrollSnapType); |
43 void snapAreaDidChange(LayoutBox&, const Vector<LengthPoint>& snapCoordinate
s); | 53 void snapAreaDidChange(LayoutBox&, const Vector<LengthPoint>& snapCoordinate
s); |
44 | 54 |
| 55 void notifyLayoutUpdated(); |
| 56 void clear(); |
| 57 |
45 #ifndef NDEBUG | 58 #ifndef NDEBUG |
46 void showSnapAreaMap(); | 59 void showSnapAreaMap(); |
47 void showSnapAreasFor(const LayoutBox*); | 60 void showSnapAreasFor(const LayoutBox*); |
48 #endif | 61 #endif |
49 | 62 |
50 private: | 63 private: |
51 friend class SnapCoordinatorTest; | 64 friend class SnapCoordinatorTest; |
52 explicit SnapCoordinator(); | 65 explicit SnapCoordinator(Client*); |
53 | 66 |
54 Vector<double> snapOffsets(const ContainerNode&, ScrollbarOrientation); | 67 Vector<double> snapOffsets(const ContainerNode&, ScrollbarOrientation); |
55 | 68 |
56 HashSet<const LayoutBox*> m_snapContainers; | 69 HashSet<const LayoutBox*> m_snapContainers; |
| 70 HashMap<const LayoutBox*, SnapOffsets> m_offsetMap; |
| 71 Client* m_client; |
| 72 |
57 }; | 73 }; |
58 | 74 |
| 75 bool operator==(const SnapOffsets&, const SnapOffsets&); |
| 76 |
59 } // namespace blink | 77 } // namespace blink |
60 | 78 |
61 #endif // SnapCoordinator_h | 79 #endif // SnapCoordinator_h |
OLD | NEW |