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

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: Skip creating WebScrollbarLayers, defer to creation in CC. 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 "PinchViewports.h"
jamesr 2013/06/14 20:55:46 please specify paths relative to Source/
wjmaclean 2013/06/17 17:45:27 Done.
33
34 #include "WebSettingsImpl.h"
35 #include "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/WebScrollbarLayer.h"
42
43 namespace WebKit {
44
45 WTF::PassOwnPtr<PinchViewports> PinchViewports::create(WebViewImpl* owner)
46 {
47 return adoptPtr(new PinchViewports(owner));
48 }
49
50 PinchViewports::PinchViewports(WebViewImpl* owner)
51 : m_owner(owner)
52 , m_innerViewportClipLayer(GraphicsLayer::create(m_owner->graphicsLayerFacto ry(), 0))
53 , m_pageScaleLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0) )
54 , m_innerViewportScrollLayer(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), 0))
55 , m_overlayScrollbarHorizontal(GraphicsLayer::create(m_owner->graphicsLayerF actory(), 0))
56 , m_overlayScrollbarVertical(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), 0))
57 {
58 m_innerViewportClipLayer->setMasksToBounds(true);
59 m_innerViewportClipLayer->platformLayer()->setIsContainerForFixedPositionLay ers(true);
60
61 m_innerViewportScrollLayer->platformLayer()->setScrollable(true);
62
63 #ifndef NDEBUG
64 m_innerViewportClipLayer->setName("inner viewport clip layer");
65 m_pageScaleLayer->setName("page scale layer");
66 m_innerViewportScrollLayer->setName("inner viewport scroll layer");
67 m_overlayScrollbarHorizontal->setName("overlay scrollbar horizontal");
68 m_overlayScrollbarVertical->setName("overlay scrollbar vertical");
69 #endif
70
71 m_innerViewportClipLayer->addChild(m_pageScaleLayer.get());
72 m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());
73 m_innerViewportClipLayer->addChild(m_overlayScrollbarHorizontal.get());
74 m_innerViewportClipLayer->addChild(m_overlayScrollbarVertical.get());
75
76 // Setup the inner viewport overlay scrollbars.
77 setupScrollbar(WebScrollbar::Horizontal);
78 setupScrollbar(WebScrollbar::Vertical);
79 }
80
81 PinchViewports::~PinchViewports() { }
82
83 void PinchViewports::setViewportSize(const FloatSize& newSize)
84 {
85 ASSERT(m_innerViewportClipLayer);
86 m_innerViewportClipLayer->setSize(newSize);
87
88 // Need to re-compute sizes for the overlay scrollbars.
89 setupScrollbar(WebScrollbar::Horizontal);
90 setupScrollbar(WebScrollbar::Vertical);
91
92 // DO NOT SUBMIT: this next line will be removed before this CL lands, pleas e ignore for review.
93 showGraphicsLayers();
94 }
95
96 // Modifies the top of the graphics layer tree to add layers needed to support
97 // the inner/outer viewport fixed-position model for pinch zoom. When finished,
98 // the tree will look like this (with * denoting added layers):
99 //
100 // *innerViewportClipLayer (fixed pos container)
101 // +- *pageScaleLayer
102 // | +- *innerViewportScrollLayer
103 // | +-- overflowControlsHostLayer (root layer)
104 // | +-- outerViewportClipLayer (fixed pos container) [frame clip lay er in RenderLayerCompositor]
105 // | | +-- outerViewportScrollLayer [frame scroll layer in RenderLa yerCompositor]
106 // | | +-- content layers ...
107 // | +-- horizontal ScrollbarLayer (non-overlay)
108 // | +-- verticalScrollbarLayer (non-overlay)
109 // | +-- scroll corner (non-overlay)
110 // +- *horizontalScrollbarLayer (overlay)
111 // +- *verticalScrollbarLayer (overlay)
112 //
113 void PinchViewports::setOverflowControlsHostLayer(GraphicsLayer* layer)
114 {
115 if (layer) {
116 ASSERT(!m_innerViewportScrollLayer->children().size());
117 m_innerViewportScrollLayer->addChild(layer);
118 } else {
119 m_innerViewportScrollLayer->removeAllChildren();
120 return;
121 }
122
123 Page* page = m_owner->page();
124 // We only need to disable the existing (outer viewport) scrollbars
125 // if the existing ones are already overlay.
126 if (!page || !page->mainFrame()->view()->hasOverlayScrollbars())
127 return;
128
129 // Disable the existing outer-viewport scrollbars, since we don't need to
130 // display two sets of overlay scrollbars.
131 // FIXME: If we knew in advance before the overflowControlsHostLayer goes
132 // away, we would re-enable the drawing of these scrollbars.
133 // FIXME: When scrollbar existence is no longer tied to scrollability, see
134 // issue crbug.com/247055, inhibit the creation of these scrollbars when the y're not needed.
135 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForHorizontalScro llbar())
136 scrollbar->setDrawsContent(false);
137 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForVerticalScroll bar())
138 scrollbar->setDrawsContent(false);
139
140 // DO NOT SUBMIT: this next line will be removed before this CL lands, pleas e ignore for review.
141 showGraphicsLayers();
142 }
143
144 static inline bool isHorizontal(WebScrollbar::Orientation orientation)
145 {
146 return orientation == WebScrollbar::Horizontal;
147 }
148
149 void PinchViewports::setupScrollbar(WebScrollbar::Orientation orientation)
150 {
151 OwnPtr<GraphicsLayer>& scrollbarGraphicsLayer = isHorizontal(orientation) ?
152 m_overlayScrollbarHorizontal : m_overlayScrollbarVertical;
153
154 const int kOverlayScrollbarThickness = m_owner->settingsImpl()->pinchOverlay ScrollbarThickness();
155
156 ASSERT(scrollbarGraphicsLayer);
157
158 int xPosition = isHorizontal(orientation) ? 0 : m_innerViewportClipLayer->si ze().width() - kOverlayScrollbarThickness;
159 int yPosition = isHorizontal(orientation) ? m_innerViewportClipLayer->size() .height() - kOverlayScrollbarThickness : 0;
160 int width = isHorizontal(orientation) ? m_innerViewportClipLayer->size().wid th() - kOverlayScrollbarThickness : kOverlayScrollbarThickness;
161 int height = isHorizontal(orientation) ? kOverlayScrollbarThickness : m_inne rViewportClipLayer->size().height() - kOverlayScrollbarThickness;
162
163 scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition));
164 scrollbarGraphicsLayer->setSize(IntSize(width, height));
165 }
166
167 // DO NOT SUBMIT: this function will be removed before this CL lands, please ign ore for review.
168 void PinchViewports::showGraphicsLayers()
169 {
170 #ifndef NDEBUG
171 if (m_innerViewportClipLayer) {
172 GraphicsLayer* root = m_innerViewportClipLayer.get();
173 while (root->parent())
174 root = root->parent();
175
176 showGraphicsLayerTree(root);
177 }
178 #endif
179 }
180
181 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698