e8746636cb75585a5011c40cc8c5e77fefbde5b4
[platform/framework/web/crosswalk-tizen.git] /
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #ifndef ScrollingCoordinator_h
27 #define ScrollingCoordinator_h
28
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"
38 #include <memory>
39
40 namespace blink {
41 using MainThreadScrollingReasons = uint32_t;
42
43 class LocalFrame;
44 class FrameView;
45 class GraphicsLayer;
46 class Page;
47 class PaintLayer;
48 class Region;
49 class ScrollableArea;
50 class CompositorAnimationTimeline;
51 class WebLayerTreeView;
52 class WebScrollbarLayer;
53
54 class CORE_EXPORT ScrollingCoordinator final
55     : public GarbageCollectedFinalized<ScrollingCoordinator> {
56   WTF_MAKE_NONCOPYABLE(ScrollingCoordinator);
57
58  public:
59   static ScrollingCoordinator* create(Page*);
60
61   ~ScrollingCoordinator();
62   DECLARE_TRACE();
63
64   void layerTreeViewInitialized(WebLayerTreeView&);
65   void willCloseLayerTreeView(WebLayerTreeView&);
66
67   void willBeDestroyed();
68
69   // Return whether this scrolling coordinator handles scrolling for the given
70   // frame view.
71   bool coordinatesScrollingForFrameView(FrameView*) const;
72
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();
77
78   void updateAfterCompositingChangeIfNeeded();
79
80   // Should be called whenever a frameview visibility is changed.
81   void frameViewVisibilityDidChange();
82
83   // Should be called whenever a scrollable area is added or removed, or
84   // gains/loses a composited layer.
85   void scrollableAreasDidChange();
86
87   // Should be called whenever the slow repaint objects counter changes between
88   // zero and one.
89   void frameViewHasBackgroundAttachmentFixedObjectsDidChange(FrameView*);
90
91   // Should be called whenever the set of fixed objects changes.
92   void frameViewFixedObjectsDidChange(FrameView*);
93
94   // Should be called whenever the root layer for the given frame view changes.
95   void frameViewRootLayerDidChange(FrameView*);
96
97 #if OS(MACOSX)
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);
101 #endif
102
103   MainThreadScrollingReasons mainThreadScrollingReasons() const;
104   bool shouldUpdateScrollLayerPositionOnMainThread() const {
105     return mainThreadScrollingReasons() != 0;
106   }
107
108   std::unique_ptr<WebScrollbarLayer> createSolidColorScrollbarLayer(
109       ScrollbarOrientation,
110       int thumbThickness,
111       int trackStart,
112       bool isLeftSideVerticalScrollbar);
113
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*);
119 #endif
120   void scrollableAreaScrollbarLayerDidChange(ScrollableArea*,
121                                              ScrollbarOrientation);
122   void setLayerIsContainerForFixedPositionLayers(GraphicsLayer*, bool);
123   void updateLayerPositionConstraint(PaintLayer*);
124   void touchEventTargetRectsDidChange();
125   void willDestroyLayer(PaintLayer*);
126
127   void updateScrollParentForGraphicsLayer(GraphicsLayer* child,
128                                           const PaintLayer* parent);
129   void updateClipParentForGraphicsLayer(GraphicsLayer* child,
130                                         const PaintLayer* parent);
131
132   String mainThreadScrollingReasonsAsText() const;
133   Region computeShouldHandleScrollGestureOnMainThreadRegion(
134       const LocalFrame*,
135       const IntPoint& frameLocation) const;
136
137   void updateTouchEventTargetRectsIfNeeded();
138
139   CompositorAnimationTimeline* compositorAnimationTimeline() {
140     return m_programmaticScrollAnimatorTimeline.get();
141   }
142
143   // For testing purposes only. This ScrollingCoordinator is reused between
144   // layout test, and must be reset for the results to be valid.
145   void reset();
146
147  protected:
148   explicit ScrollingCoordinator(Page*);
149
150   bool isForRootLayer(ScrollableArea*) const;
151   bool isForMainFrame(ScrollableArea*) const;
152
153   Member<Page> m_page;
154
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;
160
161  private:
162   bool shouldUpdateAfterCompositingChange() const {
163     return m_scrollGestureRegionIsDirty || m_touchEventTargetRectsAreDirty ||
164            m_shouldScrollOnMainThreadDirty || frameViewIsDirty();
165   }
166
167   void setShouldUpdateScrollLayerPositionOnMainThread(
168       MainThreadScrollingReasons);
169
170   bool hasVisibleSlowRepaintViewportConstrainedObjects(FrameView*) const;
171
172   void setShouldHandleScrollGestureOnMainThreadRegion(const Region&);
173   void setTouchEventTargetRects(LayerHitTestRects&);
174   void computeTouchEventTargetRects(LayerHitTestRects&);
175
176   WebScrollbarLayer* addWebScrollbarLayer(ScrollableArea*,
177                                           ScrollbarOrientation,
178                                           std::unique_ptr<WebScrollbarLayer>);
179   WebScrollbarLayer* getWebScrollbarLayer(ScrollableArea*,
180                                           ScrollbarOrientation);
181   void removeWebScrollbarLayer(ScrollableArea*, ScrollbarOrientation);
182
183   bool frameViewIsDirty() const;
184
185   std::unique_ptr<CompositorAnimationTimeline>
186       m_programmaticScrollAnimatorTimeline;
187
188   using ScrollbarMap =
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;
194
195   MainThreadScrollingReasons m_lastMainThreadScrollingReasons;
196 };
197
198 }  // namespace blink
199
200 #endif  // ScrollingCoordinator_h