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