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/FloatSize.h" | |
| 38 #include "core/platform/graphics/GraphicsLayer.h" | |
| 39 #include "core/rendering/RenderLayerCompositor.h" | |
| 40 #include "public/platform/Platform.h" | |
| 41 #include "public/platform/WebCompositorSupport.h" | |
| 42 #include "public/platform/WebLayerTreeView.h" | |
| 43 #include "public/platform/WebScrollbarLayer.h" | |
| 44 | |
| 45 using WebCore::GraphicsLayer; | |
| 46 | |
| 47 namespace WebKit { | |
| 48 | |
| 49 PassOwnPtr<PinchViewports> PinchViewports::create(WebViewImpl* owner) | |
| 50 { | |
| 51 return adoptPtr(new PinchViewports(owner)); | |
| 52 } | |
| 53 | |
| 54 PinchViewports::PinchViewports(WebViewImpl* owner) | |
| 55 : m_owner(owner) | |
| 56 , m_innerViewportClipLayer(GraphicsLayer::create(m_owner->graphicsLayerFacto ry(), this)) | |
| 57 , m_pageScaleLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), th is)) | |
| 58 , m_innerViewportScrollLayer(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), this)) | |
| 59 , m_overlayScrollbarHorizontal(GraphicsLayer::create(m_owner->graphicsLayerF actory(), this)) | |
| 60 , m_overlayScrollbarVertical(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), this)) | |
| 61 { | |
| 62 m_innerViewportClipLayer->setMasksToBounds(true); | |
| 63 m_innerViewportClipLayer->platformLayer()->setIsContainerForFixedPositionLay ers(true); | |
| 64 | |
| 65 m_innerViewportScrollLayer->platformLayer()->setScrollable(true); | |
| 66 | |
| 67 #ifndef NDEBUG | |
| 68 m_innerViewportClipLayer->setName("inner viewport clip layer"); | |
| 69 m_pageScaleLayer->setName("page scale layer"); | |
| 70 m_innerViewportScrollLayer->setName("inner viewport scroll layer"); | |
| 71 m_overlayScrollbarHorizontal->setName("overlay scrollbar horizontal"); | |
| 72 m_overlayScrollbarVertical->setName("overlay scrollbar vertical"); | |
| 73 #endif | |
| 74 | |
| 75 m_innerViewportClipLayer->addChild(m_pageScaleLayer.get()); | |
| 76 m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get()); | |
| 77 m_innerViewportClipLayer->addChild(m_overlayScrollbarHorizontal.get()); | |
| 78 m_innerViewportClipLayer->addChild(m_overlayScrollbarVertical.get()); | |
| 79 | |
| 80 // Setup the inner viewport overlay scrollbars. | |
| 81 setupScrollbar(WebScrollbar::Horizontal); | |
| 82 setupScrollbar(WebScrollbar::Vertical); | |
| 83 } | |
| 84 | |
| 85 PinchViewports::~PinchViewports() { } | |
| 86 | |
| 87 void PinchViewports::setViewportSize(const WebCore::IntSize& newSize) | |
| 88 { | |
| 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 | |
| 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 WebCore::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 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForHorizontalScro llbar()) | |
| 134 scrollbar->setDrawsContent(false); | |
| 135 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForVerticalScroll bar()) | |
| 136 scrollbar->setDrawsContent(false); | |
| 137 } | |
| 138 | |
| 139 void PinchViewports::setupScrollbar(WebScrollbar::Orientation orientation) | |
| 140 { | |
| 141 bool isHorizontal = orientation == WebScrollbar::Horizontal; | |
| 142 GraphicsLayer* scrollbarGraphicsLayer = isHorizontal ? | |
| 143 m_overlayScrollbarHorizontal.get() : m_overlayScrollbarVertical.get(); | |
| 144 | |
| 145 const int kOverlayScrollbarThickness = m_owner->settingsImpl()->pinchOverlay ScrollbarThickness(); | |
|
jamesr
2013/06/18 20:21:58
this isn't a static constant so it shouldn't get a
wjmaclean
2013/06/18 20:42:46
Done.
| |
| 146 | |
| 147 int xPosition = isHorizontal ? 0 : m_innerViewportClipLayer->size().width() - kOverlayScrollbarThickness; | |
| 148 int yPosition = isHorizontal ? m_innerViewportClipLayer->size().height() - k OverlayScrollbarThickness : 0; | |
| 149 int width = isHorizontal ? m_innerViewportClipLayer->size().width() - kOverl ayScrollbarThickness : kOverlayScrollbarThickness; | |
| 150 int height = isHorizontal ? kOverlayScrollbarThickness : m_innerViewportClip Layer->size().height() - kOverlayScrollbarThickness; | |
| 151 | |
| 152 scrollbarGraphicsLayer->setPosition(WebCore::IntPoint(xPosition, yPosition)) ; | |
| 153 scrollbarGraphicsLayer->setSize(WebCore::IntSize(width, height)); | |
| 154 } | |
| 155 | |
| 156 void PinchViewports::registerViewportLayersWithTreeView(WebLayerTreeView* layerT reeView) const | |
| 157 { | |
| 158 if (!layerTreeView) | |
| 159 return; | |
| 160 | |
| 161 WebCore::RenderLayerCompositor* compositor = m_owner->compositor(); | |
| 162 ASSERT(compositor); | |
| 163 layerTreeView->registerPinchViewportLayers( | |
| 164 m_innerViewportClipLayer->platformLayer(), | |
| 165 m_pageScaleLayer->platformLayer(), | |
| 166 m_innerViewportScrollLayer->platformLayer(), | |
| 167 compositor->scrollLayer()->platformLayer(), | |
| 168 m_overlayScrollbarHorizontal->platformLayer(), | |
| 169 m_overlayScrollbarVertical->platformLayer()); | |
| 170 } | |
| 171 | |
| 172 void PinchViewports::clearViewportLayersForTreeView(WebLayerTreeView* layerTreeV iew) const | |
| 173 { | |
| 174 if (!layerTreeView) | |
| 175 return; | |
| 176 | |
| 177 layerTreeView->clearPinchViewportLayers(); | |
| 178 } | |
| 179 | |
| 180 void PinchViewports::notifyAnimationStarted(const GraphicsLayer*, double time) | |
| 181 { | |
| 182 } | |
| 183 | |
| 184 void PinchViewports::paintContents(const GraphicsLayer*, WebCore::GraphicsContex t&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& inClip) | |
| 185 { | |
| 186 } | |
| 187 | |
| 188 } // namespace WebKit | |
| OLD | NEW |