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 "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; | |
|
enne (OOO)
2013/06/13 22:45:07
This seems a little out of place. How do the curr
trchen
2013/06/13 23:10:31
ScrollbarTheme::scrollbarThickness(). Platform imp
wjmaclean
2013/06/14 15:54:16
Done.
Right now I've made an accessor and a defau
| |
| 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 , m_innerViewportClipLayer(GraphicsLayer::create(m_owner->graphicsLayerFacto ry(), 0)) | |
| 54 , m_pageScaleLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0) ) | |
| 55 , m_innerViewportScrollLayer(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), 0)) | |
| 56 , m_overlayScrollbarHorizontal(GraphicsLayer::create(m_owner->graphicsLayerF actory(), 0)) | |
| 57 , m_overlayScrollbarVertical(GraphicsLayer::create(m_owner->graphicsLayerFac tory(), 0)) | |
| 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 // Implement destructor here as it needs access to the definition of WebScrollba r | |
|
enne (OOO)
2013/06/13 22:45:07
I don't think this comment really adds much.
wjmaclean
2013/06/14 15:54:16
Done.
| |
| 83 // to create the OwnPtr destructors. | |
| 84 PinchViewports::~PinchViewports() { } | |
| 85 | |
| 86 void PinchViewports::setViewportSize(const FloatSize& newSize) | |
| 87 { | |
| 88 ASSERT(m_innerViewportClipLayer); | |
| 89 m_innerViewportClipLayer->setSize(newSize); | |
| 90 // Use bounds of scroll layer to communicate size of scrollbars. | |
|
enne (OOO)
2013/06/13 22:45:07
Scroll layers should be the size of the the scroll
wjmaclean
2013/06/14 15:54:16
Hmm, ok. Is it reasonable to have the WebScrollbar
| |
| 91 m_innerViewportScrollLayer->setSize(newSize); | |
| 92 | |
| 93 // Need to re-compute sizes for the overlay scrollbars. | |
| 94 setupScrollbar(WebScrollbar::Horizontal); | |
| 95 setupScrollbar(WebScrollbar::Vertical); | |
| 96 | |
| 97 // FIXME: this next line will be removed before this CL lands, please ignore for review. | |
| 98 showGraphicsLayers(); | |
| 99 } | |
| 100 | |
| 101 // Modifies the top of the graphics layer tree to add layers needed to support | |
| 102 // the inner/outer viewport fixed-position model for pinch zoom. When finished, | |
| 103 // the tree will look like this (with * denoting added layers): | |
| 104 // | |
| 105 // *innerViewportClipLayer (fixed pos container) | |
| 106 // +- *pageScaleLayer | |
| 107 // | +- *innerViewportScrollLayer | |
| 108 // | +-- overflowControlsHostLayer (root layer) | |
| 109 // | +-- outerViewportClipLayer (fixed pos container) [frame clip lay er in RenderLayerCompositor] | |
| 110 // | | +-- outerViewportScrollLayer [frame scroll layer in RenderLa yerCompositor] | |
| 111 // | | +-- content layers ... | |
| 112 // | +-- horizontal ScrollbarLayer (non-overlay) | |
| 113 // | +-- verticalScrollbarLayer (non-overlay) | |
| 114 // | +-- scroll corner (non-overlay) | |
| 115 // +- *horizontalScrollbarLayer (overlay) | |
| 116 // +- *verticalScrollbarLayer (overlay) | |
| 117 // | |
| 118 void PinchViewports::setOverflowControlsHostLayer(GraphicsLayer* layer) | |
| 119 { | |
| 120 if (layer) { | |
| 121 ASSERT(!m_innerViewportScrollLayer->children().size()); | |
| 122 m_innerViewportScrollLayer->addChild(layer); | |
| 123 } else { | |
| 124 m_innerViewportScrollLayer->removeAllChildren(); | |
| 125 return; | |
| 126 } | |
| 127 | |
| 128 Page* page = m_owner->page(); | |
| 129 // We only need to create overlay scrollbars for the frame and move the | |
|
enne (OOO)
2013/06/13 22:45:07
..."move"?
wjmaclean
2013/06/14 15:54:16
Stale comment, fixed.
| |
| 130 // existing ones if the existing ones are not already overlay. | |
| 131 if (!page || !page->mainFrame()->view()->hasOverlayScrollbars()) | |
| 132 return; | |
| 133 | |
| 134 // Disable the existing outer-viewport scrollbars, since we don't need to | |
| 135 // display two sets of overlay scrollbars. | |
| 136 // FIXME: If we knew in advance before the overflowControlsHostLayer goes | |
| 137 // away, we would re-enable the drawing of these scrollbars. | |
| 138 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForHorizontalScro llbar()) | |
|
enne (OOO)
2013/06/13 22:45:07
This seems a little intrusive to go modify some la
trchen
2013/06/13 23:10:31
Currently the scrollability of many objects relies
wjmaclean
2013/06/14 15:54:16
I've added a FIXME with this bug number indicating
| |
| 139 scrollbar->setDrawsContent(false); | |
| 140 if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForVerticalScroll bar()) | |
| 141 scrollbar->setDrawsContent(false); | |
| 142 | |
| 143 // FIXME: this next line will be removed before this CL lands, please ignore for review. | |
| 144 showGraphicsLayers(); | |
| 145 } | |
| 146 | |
| 147 static inline bool isHorizontal(WebScrollbar::Orientation orientation) | |
| 148 { | |
| 149 return orientation == WebScrollbar::Horizontal; | |
| 150 } | |
| 151 | |
| 152 void PinchViewports::setupScrollbar(WebScrollbar::Orientation orientation) | |
| 153 { | |
| 154 OwnPtr<GraphicsLayer>& scrollbarGraphicsLayer = isHorizontal(orientation) ? | |
| 155 m_overlayScrollbarHorizontal : m_overlayScrollbarVertical; | |
| 156 OwnPtr<WebScrollbarLayer>& scrollbarWebLayer = isHorizontal(orientation) ? | |
| 157 m_webScrollbarLayerHorizontal : m_webScrollbarLayerVertical; | |
| 158 | |
| 159 ASSERT(scrollbarGraphicsLayer); | |
| 160 ASSERT(m_innerViewportScrollLayer->platformLayer()); | |
| 161 if (!scrollbarWebLayer) { | |
| 162 scrollbarWebLayer = | |
| 163 adoptPtr(WebKit::Platform::current()->compositorSupport()->createScr ollbarLayer( | |
| 164 m_innerViewportScrollLayer->platformLayer(), orientation, kOverl ayScrollbarThickness)); | |
| 165 GraphicsLayer::registerContentsLayer(scrollbarWebLayer->layer()); | |
| 166 scrollbarGraphicsLayer->setContentsToPlatformLayer(scrollbarWebLayer->la yer()); | |
| 167 } | |
| 168 | |
| 169 int xPosition = isHorizontal(orientation) ? 0 : m_innerViewportClipLayer->si ze().width() - kOverlayScrollbarThickness; | |
| 170 int yPosition = isHorizontal(orientation) ? m_innerViewportClipLayer->size() .height() - kOverlayScrollbarThickness : 0; | |
| 171 int width = isHorizontal(orientation) ? m_innerViewportClipLayer->size().wid th() - kOverlayScrollbarThickness : kOverlayScrollbarThickness; | |
| 172 int height = isHorizontal(orientation) ? kOverlayScrollbarThickness : m_inne rViewportClipLayer->size().height() - kOverlayScrollbarThickness; | |
| 173 | |
| 174 scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition)); | |
| 175 scrollbarGraphicsLayer->setSize(IntSize(width, height)); | |
| 176 | |
| 177 ASSERT(scrollbarGraphicsLayer->hasContentsLayer()); | |
| 178 scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height)); | |
| 179 scrollbarGraphicsLayer->setDrawsContent(true); | |
| 180 scrollbarGraphicsLayer->setNeedsDisplay(); | |
|
enne (OOO)
2013/06/13 22:45:07
Blink invalidates needlessly too often. Can you e
wjmaclean
2013/06/14 15:54:16
Done.
| |
| 181 } | |
| 182 | |
| 183 // FIXME: this function will be removed before this CL lands, please ignore for review. | |
|
enne (OOO)
2013/06/13 22:45:07
Instead of FIXME, I'd recommend using DO NOT SUBMI
wjmaclean
2013/06/14 15:54:16
Did not know about that, will definitely use it fr
| |
| 184 void PinchViewports::showGraphicsLayers() | |
| 185 { | |
| 186 #ifndef NDEBUG | |
| 187 if (m_innerViewportClipLayer) { | |
| 188 GraphicsLayer* root = m_innerViewportClipLayer.get(); | |
| 189 while (root->parent()) | |
| 190 root = root->parent(); | |
| 191 | |
| 192 showGraphicsLayerTree(root); | |
| 193 } | |
| 194 #endif | |
| 195 } | |
| 196 | |
| 197 } // namespace WebKit | |
| OLD | NEW |