2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef ScrollingCoordinator_h
27 #define ScrollingCoordinator_h
29 #include "core/CoreExport.h"
30 #include "core/paint/LayerHitTestRects.h"
31 #include "platform/PlatformWheelEvent.h"
32 #include "platform/geometry/IntRect.h"
33 #include "platform/heap/Handle.h"
34 #include "platform/scroll/MainThreadScrollingReason.h"
35 #include "platform/scroll/ScrollTypes.h"
36 #include "wtf/Noncopyable.h"
37 #include "wtf/text/WTFString.h"
41 using MainThreadScrollingReasons = uint32_t;
50 class CompositorAnimationTimeline;
51 class WebLayerTreeView;
52 class WebScrollbarLayer;
54 class CORE_EXPORT ScrollingCoordinator final
55 : public GarbageCollectedFinalized<ScrollingCoordinator> {
56 WTF_MAKE_NONCOPYABLE(ScrollingCoordinator);
59 static ScrollingCoordinator* create(Page*);
61 ~ScrollingCoordinator();
64 void layerTreeViewInitialized(WebLayerTreeView&);
65 void willCloseLayerTreeView(WebLayerTreeView&);
67 void willBeDestroyed();
69 // Return whether this scrolling coordinator handles scrolling for the given
71 bool coordinatesScrollingForFrameView(FrameView*) const;
73 // Called when any frame has done its layout or compositing has changed.
74 void notifyGeometryChanged();
75 // Called when any frame recalculates its overflows after style change.
76 void notifyOverflowUpdated();
78 void updateAfterCompositingChangeIfNeeded();
80 // Should be called whenever a frameview visibility is changed.
81 void frameViewVisibilityDidChange();
83 // Should be called whenever a scrollable area is added or removed, or
84 // gains/loses a composited layer.
85 void scrollableAreasDidChange();
87 // Should be called whenever the slow repaint objects counter changes between
89 void frameViewHasBackgroundAttachmentFixedObjectsDidChange(FrameView*);
91 // Should be called whenever the set of fixed objects changes.
92 void frameViewFixedObjectsDidChange(FrameView*);
94 // Should be called whenever the root layer for the given frame view changes.
95 void frameViewRootLayerDidChange(FrameView*);
98 // Dispatched by the scrolling tree during handleWheelEvent. This is required
99 // as long as scrollbars are painted on the main thread.
100 void handleWheelEventPhase(PlatformWheelEventPhase);
103 MainThreadScrollingReasons mainThreadScrollingReasons() const;
104 bool shouldUpdateScrollLayerPositionOnMainThread() const {
105 return mainThreadScrollingReasons() != 0;
108 std::unique_ptr<WebScrollbarLayer> createSolidColorScrollbarLayer(
109 ScrollbarOrientation,
112 bool isLeftSideVerticalScrollbar);
114 void willDestroyScrollableArea(ScrollableArea*);
115 // Returns true if the coordinator handled this change.
116 bool scrollableAreaScrollLayerDidChange(ScrollableArea*);
117 #if defined(TIZEN_VD_NATIVE_SCROLLBARS)
118 void scrollableAreaScrollCornerLayerDidChange(ScrollableArea*);
120 void scrollableAreaScrollbarLayerDidChange(ScrollableArea*,
121 ScrollbarOrientation);
122 void setLayerIsContainerForFixedPositionLayers(GraphicsLayer*, bool);
123 void updateLayerPositionConstraint(PaintLayer*);
124 void touchEventTargetRectsDidChange();
125 void willDestroyLayer(PaintLayer*);
127 void updateScrollParentForGraphicsLayer(GraphicsLayer* child,
128 const PaintLayer* parent);
129 void updateClipParentForGraphicsLayer(GraphicsLayer* child,
130 const PaintLayer* parent);
132 String mainThreadScrollingReasonsAsText() const;
133 Region computeShouldHandleScrollGestureOnMainThreadRegion(
135 const IntPoint& frameLocation) const;
137 void updateTouchEventTargetRectsIfNeeded();
139 CompositorAnimationTimeline* compositorAnimationTimeline() {
140 return m_programmaticScrollAnimatorTimeline.get();
143 // For testing purposes only. This ScrollingCoordinator is reused between
144 // layout test, and must be reset for the results to be valid.
148 explicit ScrollingCoordinator(Page*);
150 bool isForRootLayer(ScrollableArea*) const;
151 bool isForMainFrame(ScrollableArea*) const;
155 // Dirty flags used to idenfity what really needs to be computed after
156 // compositing is updated.
157 bool m_scrollGestureRegionIsDirty;
158 bool m_touchEventTargetRectsAreDirty;
159 bool m_shouldScrollOnMainThreadDirty;
162 bool shouldUpdateAfterCompositingChange() const {
163 return m_scrollGestureRegionIsDirty || m_touchEventTargetRectsAreDirty ||
164 m_shouldScrollOnMainThreadDirty || frameViewIsDirty();
167 void setShouldUpdateScrollLayerPositionOnMainThread(
168 MainThreadScrollingReasons);
170 bool hasVisibleSlowRepaintViewportConstrainedObjects(FrameView*) const;
172 void setShouldHandleScrollGestureOnMainThreadRegion(const Region&);
173 void setTouchEventTargetRects(LayerHitTestRects&);
174 void computeTouchEventTargetRects(LayerHitTestRects&);
176 WebScrollbarLayer* addWebScrollbarLayer(ScrollableArea*,
177 ScrollbarOrientation,
178 std::unique_ptr<WebScrollbarLayer>);
179 WebScrollbarLayer* getWebScrollbarLayer(ScrollableArea*,
180 ScrollbarOrientation);
181 void removeWebScrollbarLayer(ScrollableArea*, ScrollbarOrientation);
183 bool frameViewIsDirty() const;
185 std::unique_ptr<CompositorAnimationTimeline>
186 m_programmaticScrollAnimatorTimeline;
189 HeapHashMap<Member<ScrollableArea>, std::unique_ptr<WebScrollbarLayer>>;
190 ScrollbarMap m_horizontalScrollbars;
191 ScrollbarMap m_verticalScrollbars;
192 HashSet<const PaintLayer*> m_layersWithTouchRects;
193 bool m_wasFrameScrollable;
195 MainThreadScrollingReasons m_lastMainThreadScrollingReasons;
200 #endif // ScrollingCoordinator_h