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

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: Address comments. 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
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 "WebKit/chromium/src/PinchViewports.h"
33
34 #include "WebKit/chromium/src/WebSettingsImpl.h"
35 #include "WebKit/chromium/src/WebViewImpl.h"
36 #include "core/page/FrameView.h"
37 #include "core/platform/graphics/GraphicsLayer.h"
38 #include "core/rendering/RenderLayerCompositor.h"
39 #include "public/platform/Platform.h"
40 #include "public/platform/WebCompositorSupport.h"
41 #include "public/platform/WebLayerTreeView.h"
42 #include "public/platform/WebScrollbarLayer.h"
43
44 using WebCore::GraphicsLayer;
45
46 namespace WebKit {
47
48 PassOwnPtr<PinchViewports> PinchViewports::create(WebViewImpl* owner)
49 {
50 return adoptPtr(new PinchViewports(owner));
51 }
52
53 PinchViewports::PinchViewports(WebViewImpl* owner)
54 : m_owner(owner)
55 , m_innerViewportClipLayer(GraphicsLayer::create(m_owner->graphicsLayerFacto ry(), this))
56 , m_pageScaleLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), th is))
57 , m_innerViewportScrollLayer(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), this))
58 , m_overlayScrollbarHorizontal(GraphicsLayer::create(m_owner->graphicsLayerF actory(), this))
59 , m_overlayScrollbarVertical(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), this))
60 {
61 m_innerViewportClipLayer->setMasksToBounds(true);
62 m_innerViewportClipLayer->platformLayer()->setIsContainerForFixedPositionLay ers(true);
63
64 m_innerViewportScrollLayer->platformLayer()->setScrollable(true);
65
66 #ifndef NDEBUG
67 m_innerViewportClipLayer->setName("inner viewport clip layer");
68 m_pageScaleLayer->setName("page scale layer");
69 m_innerViewportScrollLayer->setName("inner viewport scroll layer");
70 m_overlayScrollbarHorizontal->setName("overlay scrollbar horizontal");
71 m_overlayScrollbarVertical->setName("overlay scrollbar vertical");
72 #endif
73
74 m_innerViewportClipLayer->addChild(m_pageScaleLayer.get());
75 m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());
76 m_innerViewportClipLayer->addChild(m_overlayScrollbarHorizontal.get());
77 m_innerViewportClipLayer->addChild(m_overlayScrollbarVertical.get());
78
79 // Setup the inner viewport overlay scrollbars.
80 setupScrollbar(WebScrollbar::Horizontal);
81 setupScrollbar(WebScrollbar::Vertical);
82 }
83
84 PinchViewports::~PinchViewports() { }
85
86 void PinchViewports::setViewportSize(const WebCore::FloatSize& newSize)
87 {
88 ASSERT(m_innerViewportClipLayer);
89 m_innerViewportClipLayer->setSize(newSize);
90
91 // Need to re-compute sizes for the overlay scrollbars.
92 setupScrollbar(WebScrollbar::Horizontal);
93 setupScrollbar(WebScrollbar::Vertical);
94
95 // DO NOT SUBMIT: this next line will be removed before this CL lands, pleas e ignore for review.
jamesr 2013/06/17 22:16:34 don't forget this
wjmaclean 2013/06/18 14:10:53 Done.
96 showGraphicsLayers();
97 }
98
99 // Modifies the top of the graphics layer tree to add layers needed to support
100 // the inner/outer viewport fixed-position model for pinch zoom. When finished,
101 // the tree will look like this (with * denoting added layers):
102 //
103 // *innerViewportClipLayer (fixed pos container)
104 // +- *pageScaleLayer
105 // | +- *innerViewportScrollLayer
106 // | +-- overflowControlsHostLayer (root layer)
107 // | +-- outerViewportClipLayer (fixed pos container) [frame clip lay er in RenderLayerCompositor]
108 // | | +-- outerViewportScrollLayer [frame scroll layer in RenderLa yerCompositor]
109 // | | +-- content layers ...
110 // | +-- horizontal ScrollbarLayer (non-overlay)
111 // | +-- verticalScrollbarLayer (non-overlay)
112 // | +-- scroll corner (non-overlay)
113 // +- *horizontalScrollbarLayer (overlay)
114 // +- *verticalScrollbarLayer (overlay)
115 //
116 void PinchViewports::setOverflowControlsHostLayer(GraphicsLayer* layer)
117 {
118 if (layer) {
119 ASSERT(!m_innerViewportScrollLayer->children().size());
120 m_innerViewportScrollLayer->addChild(layer);
121 } else {
122 m_innerViewportScrollLayer->removeAllChildren();
123 return;
124 }
125
126 WebCore::Page* page = m_owner->page();
127 // We only need to disable the existing (outer viewport) scrollbars
128 // if the existing ones are already overlay.
129 if (!page || !page->mainFrame()->view()->hasOverlayScrollbars())
130 return;
131
132 // Disable the existing outer-viewport scrollbars, since we don't need to
133 // display two sets of overlay scrollbars.
134 // FIXME: If we knew in advance before the overflowControlsHostLayer goes
135 // away, we would re-enable the drawing of these scrollbars.
136 // FIXME: When scrollbar existence is no longer tied to scrollability, see
137 // issue crbug.com/247055, inhibit the creation of these scrollbars when the y're not needed.
138 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForHorizontalScro llbar())
139 scrollbar->setDrawsContent(false);
140 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForVerticalScroll bar())
141 scrollbar->setDrawsContent(false);
142
143 // DO NOT SUBMIT: this next line will be removed before this CL lands, pleas e ignore for review.
jamesr 2013/06/17 22:16:34 or this
wjmaclean 2013/06/18 14:10:53 Done.
144 showGraphicsLayers();
145 }
146
147 void PinchViewports::setupScrollbar(WebScrollbar::Orientation orientation)
148 {
149 bool isHorizontal = orientation == WebScrollbar::Horizontal;
150 GraphicsLayer* scrollbarGraphicsLayer = isHorizontal ?
151 m_overlayScrollbarHorizontal.get() : m_overlayScrollbarVertical.get();
152
153 const int kOverlayScrollbarThickness = m_owner->settingsImpl()->pinchOverlay ScrollbarThickness();
154
155 ASSERT(scrollbarGraphicsLayer);
156
157 int xPosition = isHorizontal ? 0 : m_innerViewportClipLayer->size().width() - kOverlayScrollbarThickness;
158 int yPosition = isHorizontal ? m_innerViewportClipLayer->size().height() - k OverlayScrollbarThickness : 0;
159 int width = isHorizontal ? m_innerViewportClipLayer->size().width() - kOverl ayScrollbarThickness : kOverlayScrollbarThickness;
160 int height = isHorizontal ? kOverlayScrollbarThickness : m_innerViewportClip Layer->size().height() - kOverlayScrollbarThickness;
161
162 scrollbarGraphicsLayer->setPosition(WebCore::IntPoint(xPosition, yPosition)) ;
163 scrollbarGraphicsLayer->setSize(WebCore::IntSize(width, height));
164 }
165
166 void PinchViewports::registerViewportLayersWithTreeView(WebLayerTreeView* layerT reeView) const
167 {
168 if (!layerTreeView)
169 return;
170
171 WebCore::RenderLayerCompositor* compositor = m_owner->compositor();
172 ASSERT(compositor);
173 layerTreeView->registerPinchViewportLayers(
174 m_innerViewportClipLayer->platformLayer(),
175 m_pageScaleLayer->platformLayer(),
176 m_innerViewportScrollLayer->platformLayer(),
177 compositor->scrollLayer()->platformLayer(),
178 m_overlayScrollbarHorizontal->platformLayer(),
179 m_overlayScrollbarVertical->platformLayer());
180 }
181
182 void PinchViewports::clearViewportLayersForTreeView(WebLayerTreeView* layerTreeV iew) const
183 {
184 if (!layerTreeView)
185 return;
186
187 layerTreeView->clearPinchViewportLayers();
188 }
189
190 void PinchViewports::notifyAnimationStarted(const GraphicsLayer*, double time)
191 {
192 }
193
194 void PinchViewports::paintContents(const GraphicsLayer*, WebCore::GraphicsContex t&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& inClip)
195 {
196 }
197
198 // DO NOT SUBMIT: this function will be removed before this CL lands, please ign ore for review.
jamesr 2013/06/17 22:16:34 or this
wjmaclean 2013/06/18 14:10:53 Done.
199 void PinchViewports::showGraphicsLayers()
200 {
201 #ifndef NDEBUG
202 if (m_innerViewportClipLayer) {
203 GraphicsLayer* root = m_innerViewportClipLayer.get();
204 while (root->parent())
205 root = root->parent();
206
207 showGraphicsLayerTree(root);
208 }
209 #endif
210 }
211
212 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698