Initial triage pass of css3/selectors3/xhtml for the Chromium ports.
[WebKit-https.git] / Source / WebCore / page / scrolling / chromium / ScrollingCoordinatorChromium.cpp
1 /*
2  * Copyright (C) 2012 Google 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 #include "config.h"
27
28 #include "ScrollingCoordinator.h"
29
30 #include "Frame.h"
31 #include "FrameView.h"
32 #include "LayerChromium.h"
33 #include "Region.h"
34 #include "RenderLayerCompositor.h"
35 #include "RenderView.h"
36 #include "ScrollbarLayerChromium.h"
37 #include "ScrollbarTheme.h"
38 #include "cc/CCProxy.h"
39
40 namespace WebCore {
41
42 class ScrollingCoordinatorPrivate {
43 WTF_MAKE_NONCOPYABLE(ScrollingCoordinatorPrivate);
44 public:
45     ScrollingCoordinatorPrivate() { }
46     ~ScrollingCoordinatorPrivate() { }
47
48     void setScrollLayer(LayerChromium* layer) { m_scrollLayer = layer; }
49     LayerChromium* scrollLayer() const { return m_scrollLayer.get(); }
50
51 private:
52     RefPtr<LayerChromium> m_scrollLayer;
53 };
54
55 PassRefPtr<ScrollingCoordinator> ScrollingCoordinator::create(Page* page)
56 {
57     RefPtr<ScrollingCoordinator> coordinator(adoptRef(new ScrollingCoordinator(page)));
58     coordinator->m_private = new ScrollingCoordinatorPrivate;
59     return coordinator.release();
60 }
61
62 ScrollingCoordinator::~ScrollingCoordinator()
63 {
64     ASSERT(!m_page);
65     delete m_private;
66 }
67
68 static GraphicsLayer* scrollLayerForFrameView(FrameView* frameView)
69 {
70 #if USE(ACCELERATED_COMPOSITING)
71     Frame* frame = frameView->frame();
72     if (!frame)
73         return 0;
74
75     RenderView* renderView = frame->contentRenderer();
76     if (!renderView)
77         return 0;
78     return renderView->compositor()->scrollLayer();
79 #else
80     return 0;
81 #endif
82 }
83
84 static void scrollbarLayerDidChange(Scrollbar* scrollbar, LayerChromium* scrollLayer, GraphicsLayer* scrollbarGraphicsLayer, FrameView* frameView)
85 {
86     ASSERT(scrollbar);
87     ASSERT(scrollbarGraphicsLayer);
88
89     if (!scrollLayer) {
90         // FIXME: sometimes we get called before setScrollLayer, workaround by finding the scroll layout ourselves.
91         scrollLayer = scrollLayerForFrameView(frameView)->platformLayer();
92         ASSERT(scrollLayer);
93     }
94
95     // Root layer non-overlay scrollbars should be marked opaque to disable
96     // blending.
97     bool isOpaqueRootScrollbar = !frameView->parent() && !scrollbar->isOverlayScrollbar();
98     if (!scrollbarGraphicsLayer->contentsOpaque())
99         scrollbarGraphicsLayer->setContentsOpaque(isOpaqueRootScrollbar);
100
101     if (scrollbar->isCustomScrollbar() || !CCProxy::hasImplThread()) {
102         scrollbarGraphicsLayer->setContentsToMedia(0);
103         scrollbarGraphicsLayer->setDrawsContent(true);
104         return;
105     }
106
107     RefPtr<ScrollbarLayerChromium> scrollbarLayer = ScrollbarLayerChromium::create(scrollbar, scrollLayer->id());
108     scrollbarGraphicsLayer->setContentsToMedia(scrollbarLayer.get());
109     scrollbarGraphicsLayer->setDrawsContent(false);
110     scrollbarLayer->setOpaque(scrollbarGraphicsLayer->contentsOpaque());
111 }
112
113 void ScrollingCoordinator::frameViewHorizontalScrollbarLayerDidChange(FrameView* frameView, GraphicsLayer* horizontalScrollbarLayer)
114 {
115     if (!horizontalScrollbarLayer || !coordinatesScrollingForFrameView(frameView))
116         return;
117
118     scrollbarLayerDidChange(frameView->horizontalScrollbar(), m_private->scrollLayer(), horizontalScrollbarLayer, frameView);
119 }
120
121 void ScrollingCoordinator::frameViewVerticalScrollbarLayerDidChange(FrameView* frameView, GraphicsLayer* verticalScrollbarLayer)
122 {
123     if (!verticalScrollbarLayer || !coordinatesScrollingForFrameView(frameView))
124         return;
125
126     scrollbarLayerDidChange(frameView->verticalScrollbar(), m_private->scrollLayer(), verticalScrollbarLayer, frameView);
127 }
128
129 void ScrollingCoordinator::setScrollLayer(GraphicsLayer* scrollLayer)
130 {
131     m_private->setScrollLayer(scrollLayer ? scrollLayer->platformLayer() : 0);
132 }
133
134 void ScrollingCoordinator::setNonFastScrollableRegion(const Region& region)
135 {
136     if (LayerChromium* layer = m_private->scrollLayer())
137         layer->setNonFastScrollableRegion(region);
138 }
139
140 void ScrollingCoordinator::setScrollParameters(ScrollElasticity horizontalScrollElasticity, ScrollElasticity verticalScrollElasticity,
141                                                bool hasEnabledHorizontalScrollbar, bool hasEnabledVerticalScrollbar,
142                                                const IntRect& viewportRect, const IntSize& contentsSize)
143 {
144     // FIXME: Implement!
145 }
146
147 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned wheelEventHandlerCount)
148 {
149     if (LayerChromium* layer = m_private->scrollLayer())
150         layer->setHaveWheelEventHandlers(wheelEventHandlerCount > 0);
151 }
152
153 void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(bool should)
154 {
155     if (LayerChromium* layer = m_private->scrollLayer())
156         layer->setShouldScrollOnMainThread(should);
157 }
158
159 }