Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: Source/WebKit/chromium/src/PinchViewports.cpp

Issue 16799005: Insert pinch zoom virtual viewport layers to graphics layer tree. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/WebKit/chromium/src/PinchViewports.h ('k') | Source/WebKit/chromium/src/WebViewImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "PinchViewports.h"
33
34 #include "WebViewImpl.h"
35 #include "core/page/FrameView.h"
36 #include "core/platform/graphics/GraphicsLayer.h"
37 #include "core/rendering/RenderLayerCompositor.h"
38 #include "public/platform/Platform.h"
39 #include "public/platform/WebCompositorSupport.h"
40 #include "public/platform/WebScrollbarLayer.h"
41
42 namespace WebKit {
43
44 const size_t PinchViewports::kOverlayScrollbarThickness = 10;
45
46 WTF::PassOwnPtr<PinchViewports> PinchViewports::create(WebViewImpl* owner)
47 {
48 return adoptPtr(new PinchViewports(owner));
49 }
50
51 PinchViewports::PinchViewports(WebViewImpl* owner)
52 : m_owner(owner) { }
53
54 // Implement destructor here as it needs access to the definition of WebScrollba r
55 // to create the OwnPtr destructors.
56 PinchViewports::~PinchViewports() { }
57
58 void PinchViewports::setViewportSizes()
59 {
60 if (m_innerViewportClipLayer) {
61 ASSERT(m_owner->page());
62 IntRect frameRect = m_owner->page()->mainFrame()->view()->frameRect();
63
64 m_innerViewportClipLayer->setSize(frameRect.size());
65 // Use bounds of scroll layer to communicate size of scrollbars.
66 m_innerViewportScrollLayer->setSize(frameRect.size());
67 reparentScrollbars();
68 showGraphicsLayers();
69 }
70 }
71
72 // Modifies the top of the graphics layer tree to add layers needed to support
73 // the inner/outer viewport fixed-position model for pinch zoom. When finished,
74 // the tree will look like this (with * denoting added layers):
75 //
76 // overflowControlsHostLayer (root layer)
77 // *innerViewportClipLayer (fixed pos container)
78 // *pageScaleLayer
79 // *innerViewportScrollLayer
80 // outerViewportClipLayer (fixed pos container) [frame clip lay er in RenderLayerCompositor]
81 // outerViewportScrollLayer [frame scroll layer in RenderLa yerCompositor]
82 // content layers ...
83 // horizontal ScrollbarLayer (non-overlay)
84 // verticalScrollbarLayer (non-overlay)
85 // scroll corner (non-overlay)
86 // *horizontalScrollbarLayer (overlay) [only added when existing scrollb ars are non-overlay]
enne (OOO) 2013/06/12 21:43:53 Is this incorrect? I was under the impression tha
87 // *verticalScrollbarLayer (overlay)
88 //
89 void PinchViewports::insertViewportLayers()
trchen 2013/06/12 21:38:00 I feel this is too intrusive. I can't see a good r
90 {
91 RenderLayerCompositor* compositor = m_owner->compositor();
92 if (!compositor)
93 return;
94
95 GraphicsLayer* rootLayer = compositor->rootGraphicsLayer();
96 GraphicsLayer* clipLayer = compositor->clipLayer();
97
98 if (!rootLayer || !clipLayer)
99 return;
100
101 if (!m_innerViewportClipLayer) {
102 m_innerViewportClipLayer = GraphicsLayer::create(m_owner->graphicsLayerF actory(), 0);
103 m_innerViewportClipLayer->platformLayer()->setIsContainerForFixedPositio nLayers(true);
104 #ifndef NDEBUG
105 m_innerViewportClipLayer->setName("inner viewport clip layer");
106 #endif
107 }
108 if (!m_innerViewportScrollLayer) {
109 m_innerViewportScrollLayer = GraphicsLayer::create(m_owner->graphicsLaye rFactory(), 0);
110 #ifndef NDEBUG
111 m_innerViewportScrollLayer->setName("inner viewport scroll layer");
112 #endif
113 }
114 if (!m_pageScaleLayer) {
115 m_pageScaleLayer = GraphicsLayer::create(m_owner->graphicsLayerFactory() , 0);
116 #ifndef NDEBUG
117 m_pageScaleLayer->setName("page scale layer");
118 #endif
119 }
120
121 m_innerViewportClipLayer->addChild(m_pageScaleLayer.get());
122 m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());
123 m_innerViewportScrollLayer->addChild(clipLayer);
124
125 // FIXME: Should we put in an ASSERT to verify that we don't have overhang
126 // layers floating around when we do this?
127 rootLayer->addChild(m_innerViewportClipLayer.get());
128
129 m_innerViewportClipLayer->setMasksToBounds(true);
130 m_innerViewportScrollLayer->platformLayer()->setScrollable(true);
131 setViewportSizes();
132 }
133
134 // Restores the graphics layer tree rooted at m_innerViewportClipLayer->parent()
135 // to the state it was in prior to the viewport layers being inserted.
136 // FIXME: Things seem to run fine whether or not we do this restoration, so
137 // perhaps it isn't necessary to restore the tree? At present this is included
138 // to 'be safe'.
139 void PinchViewports::detachViewportLayers()
140 {
141 if (!m_innerViewportClipLayer)
142 return;
143
144 ASSERT(m_innerViewportScrollLayer && m_innerViewportScrollLayer->children(). size());
145 ASSERT(m_pageScaleLayer);
146
147 GraphicsLayer* frameClipLayer = m_innerViewportScrollLayer->children()[0];
148 GraphicsLayer* rootLayer = m_innerViewportClipLayer->parent();
149 if (!rootLayer || !frameClipLayer)
150 return;
151
152 rootLayer->addChild(frameClipLayer);
153
154 // If the inner viewport scroll layer still has children, they must be the
155 // original main frame scrollbars, and so we need to restore them to their
156 // former location, attached to the root graphics layer.
157 // FIXME: if RenderLayerCompositor is modified to attach the main frame
158 // scrollbars to the frame clip layer, then the following code can be
159 // removed.
160 while (m_innerViewportScrollLayer->children().size())
161 rootLayer->addChild(m_innerViewportScrollLayer->children()[0]);
162 }
163
164 static inline bool isHorizontal(WebScrollbar::Orientation orientation)
165 {
166 return orientation == WebScrollbar::Horizontal;
167 }
168
169 void PinchViewports::setupScrollbar(WebScrollbar::Orientation orientation)
170 {
171 OwnPtr<GraphicsLayer>& scrollbarGraphicsLayer = isHorizontal(orientation) ?
172 m_overlayScrollbarHorizontal : m_overlayScrollbarVertical;
173 OwnPtr<WebScrollbarLayer>& scrollbarWebLayer = isHorizontal(orientation) ?
174 m_webScrollbarLayerHorizontal : m_webScrollbarLayerVertical;
175
176 if (!scrollbarGraphicsLayer) {
177 scrollbarGraphicsLayer = GraphicsLayer::create(m_owner->graphicsLayerFac tory(), 0);
178 #if NDEBUG
179 scrollbarGraphicsLayer->setName(
180 isHorizontal(orientation) ? "overlay scrollbar horizontal" : "overla y scrollbar vertical");
181 #endif
182 }
183
184 ASSERT(m_innerViewportScrollLayer->platformLayer());
185 if (!scrollbarWebLayer) {
186 scrollbarWebLayer =
187 adoptPtr(WebKit::Platform::current()->compositorSupport()->createScr ollbarLayer(
188 m_innerViewportScrollLayer->platformLayer(), orientation, kOverl ayScrollbarThickness));
189 GraphicsLayer::registerContentsLayer(scrollbarWebLayer->layer());
190 scrollbarGraphicsLayer->setContentsToPlatformLayer(scrollbarWebLayer->la yer());
191 }
192
193 int xPosition = isHorizontal(orientation) ? 0 : m_innerViewportClipLayer->si ze().width() - kOverlayScrollbarThickness;
194 int yPosition = isHorizontal(orientation) ? m_innerViewportClipLayer->size() .height() - kOverlayScrollbarThickness : 0;
195 int width = isHorizontal(orientation) ? m_innerViewportClipLayer->size().wid th() - kOverlayScrollbarThickness : kOverlayScrollbarThickness;
196 int height = isHorizontal(orientation) ? kOverlayScrollbarThickness : m_inne rViewportClipLayer->size().height() - kOverlayScrollbarThickness;
197
198 scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition));
199 scrollbarGraphicsLayer->setSize(IntSize(width, height));
200
201 ASSERT(scrollbarGraphicsLayer->hasContentsLayer());
202 scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height));
203 scrollbarGraphicsLayer->setDrawsContent(true);
204 scrollbarGraphicsLayer->setNeedsDisplay();
205 }
206
207 void PinchViewports::reparentScrollbars()
208 {
209 Page* page = m_owner->page();
210
211 // We only need to create overlay scrollbars for the frame and move the
212 // existing ones if the existing ones are not already overlay.
213 if (!page || page->mainFrame()->view()->hasOverlayScrollbars())
214 return;
215
216 RenderLayerCompositor* compositor = m_owner->compositor();
217
218 GraphicsLayer* scrollbarHorizontal = compositor->layerForHorizontalScrollbar ();
219 GraphicsLayer* scrollbarVertical = compositor->layerForVerticalScrollbar();
220 GraphicsLayer* scrollbarCorner = compositor->layerForScrollCorner();
221
222 ASSERT(m_innerViewportClipLayer);
223 ASSERT(m_innerViewportScrollLayer);
224
225 // Move existing mainframe scrollbars.
226 // FIXME: We would ultimately like to attach the mainframe scrollbars to the
227 // frame clip layer, but this should be done in RenderLayerCompositor (so
228 // all frames are treated the same). Once that happens, this code can be
229 // removed.
230 if (scrollbarHorizontal && scrollbarHorizontal->parent() != m_innerViewportS crollLayer.get())
231 m_innerViewportScrollLayer->addChild(scrollbarHorizontal);
232 if (scrollbarVertical && scrollbarVertical->parent() != m_innerViewportScrol lLayer.get())
233 m_innerViewportScrollLayer->addChild(scrollbarVertical);
234 if (scrollbarCorner && scrollbarCorner->parent() != m_innerViewportScrollLay er.get())
235 m_innerViewportScrollLayer->addChild(scrollbarCorner);
236
237 // Setup the pinch overlay scrollbars.
238 setupScrollbar(WebScrollbar::Horizontal);
239 setupScrollbar(WebScrollbar::Vertical);
240 m_innerViewportClipLayer->addChild(m_overlayScrollbarHorizontal.get());
241 m_innerViewportClipLayer->addChild(m_overlayScrollbarVertical.get());
242 }
243
244 void PinchViewports::showGraphicsLayers()
245 {
246 return;
247 #ifndef NDEBUG
248 if (m_innerViewportClipLayer) {
249 GraphicsLayer* root = m_innerViewportClipLayer.get();
250 while (root->parent())
251 root = root->parent();
252
253 showGraphicsLayerTree(root);
254 }
255 #endif
256 }
257
258 } // namespace WebKit
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/PinchViewports.h ('k') | Source/WebKit/chromium/src/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698