Chromium Code Reviews| Index: Source/WebKit/chromium/src/PinchViewports.cpp |
| diff --git a/Source/WebKit/chromium/src/PinchViewports.cpp b/Source/WebKit/chromium/src/PinchViewports.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fc084724a892ef4b70c5a185e44e8900efbdbb5b |
| --- /dev/null |
| +++ b/Source/WebKit/chromium/src/PinchViewports.cpp |
| @@ -0,0 +1,197 @@ |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "PinchViewports.h" |
| + |
| +#include "WebViewImpl.h" |
| +#include "core/page/FrameView.h" |
| +#include "core/platform/graphics/GraphicsLayer.h" |
| +#include "core/rendering/RenderLayerCompositor.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebCompositorSupport.h" |
| +#include "public/platform/WebScrollbarLayer.h" |
| + |
| +namespace WebKit { |
| + |
| +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
|
| + |
| +WTF::PassOwnPtr<PinchViewports> PinchViewports::create(WebViewImpl* owner) |
| +{ |
| + return adoptPtr(new PinchViewports(owner)); |
| +} |
| + |
| +PinchViewports::PinchViewports(WebViewImpl* owner) |
| + : m_owner(owner) |
| + , m_innerViewportClipLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0)) |
| + , m_pageScaleLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0)) |
| + , m_innerViewportScrollLayer(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0)) |
| + , m_overlayScrollbarHorizontal(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0)) |
| + , m_overlayScrollbarVertical(GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0)) |
| +{ |
| + m_innerViewportClipLayer->setMasksToBounds(true); |
| + m_innerViewportClipLayer->platformLayer()->setIsContainerForFixedPositionLayers(true); |
| + |
| + m_innerViewportScrollLayer->platformLayer()->setScrollable(true); |
| + |
| +#ifndef NDEBUG |
| + m_innerViewportClipLayer->setName("inner viewport clip layer"); |
| + m_pageScaleLayer->setName("page scale layer"); |
| + m_innerViewportScrollLayer->setName("inner viewport scroll layer"); |
| + m_overlayScrollbarHorizontal->setName("overlay scrollbar horizontal"); |
| + m_overlayScrollbarVertical->setName("overlay scrollbar vertical"); |
| +#endif |
| + |
| + m_innerViewportClipLayer->addChild(m_pageScaleLayer.get()); |
| + m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get()); |
| + m_innerViewportClipLayer->addChild(m_overlayScrollbarHorizontal.get()); |
| + m_innerViewportClipLayer->addChild(m_overlayScrollbarVertical.get()); |
| + |
| + // Setup the inner viewport overlay scrollbars. |
| + setupScrollbar(WebScrollbar::Horizontal); |
| + setupScrollbar(WebScrollbar::Vertical); |
| +} |
| + |
| +// Implement destructor here as it needs access to the definition of WebScrollbar |
|
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.
|
| +// to create the OwnPtr destructors. |
| +PinchViewports::~PinchViewports() { } |
| + |
| +void PinchViewports::setViewportSize(const FloatSize& newSize) |
| +{ |
| + ASSERT(m_innerViewportClipLayer); |
| + m_innerViewportClipLayer->setSize(newSize); |
| + // 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
|
| + m_innerViewportScrollLayer->setSize(newSize); |
| + |
| + // Need to re-compute sizes for the overlay scrollbars. |
| + setupScrollbar(WebScrollbar::Horizontal); |
| + setupScrollbar(WebScrollbar::Vertical); |
| + |
| + // FIXME: this next line will be removed before this CL lands, please ignore for review. |
| + showGraphicsLayers(); |
| +} |
| + |
| +// Modifies the top of the graphics layer tree to add layers needed to support |
| +// the inner/outer viewport fixed-position model for pinch zoom. When finished, |
| +// the tree will look like this (with * denoting added layers): |
| +// |
| +// *innerViewportClipLayer (fixed pos container) |
| +// +- *pageScaleLayer |
| +// | +- *innerViewportScrollLayer |
| +// | +-- overflowControlsHostLayer (root layer) |
| +// | +-- outerViewportClipLayer (fixed pos container) [frame clip layer in RenderLayerCompositor] |
| +// | | +-- outerViewportScrollLayer [frame scroll layer in RenderLayerCompositor] |
| +// | | +-- content layers ... |
| +// | +-- horizontal ScrollbarLayer (non-overlay) |
| +// | +-- verticalScrollbarLayer (non-overlay) |
| +// | +-- scroll corner (non-overlay) |
| +// +- *horizontalScrollbarLayer (overlay) |
| +// +- *verticalScrollbarLayer (overlay) |
| +// |
| +void PinchViewports::setOverflowControlsHostLayer(GraphicsLayer* layer) |
| +{ |
| + if (layer) { |
| + ASSERT(!m_innerViewportScrollLayer->children().size()); |
| + m_innerViewportScrollLayer->addChild(layer); |
| + } else { |
| + m_innerViewportScrollLayer->removeAllChildren(); |
| + return; |
| + } |
| + |
| + Page* page = m_owner->page(); |
| + // 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.
|
| + // existing ones if the existing ones are not already overlay. |
| + if (!page || !page->mainFrame()->view()->hasOverlayScrollbars()) |
| + return; |
| + |
| + // Disable the existing outer-viewport scrollbars, since we don't need to |
| + // display two sets of overlay scrollbars. |
| + // FIXME: If we knew in advance before the overflowControlsHostLayer goes |
| + // away, we would re-enable the drawing of these scrollbars. |
| + if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForHorizontalScrollbar()) |
|
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
|
| + scrollbar->setDrawsContent(false); |
| + if (GraphicsLayer* scrollbar = m_owner->compositor()->layerForVerticalScrollbar()) |
| + scrollbar->setDrawsContent(false); |
| + |
| + // FIXME: this next line will be removed before this CL lands, please ignore for review. |
| + showGraphicsLayers(); |
| +} |
| + |
| +static inline bool isHorizontal(WebScrollbar::Orientation orientation) |
| +{ |
| + return orientation == WebScrollbar::Horizontal; |
| +} |
| + |
| +void PinchViewports::setupScrollbar(WebScrollbar::Orientation orientation) |
| +{ |
| + OwnPtr<GraphicsLayer>& scrollbarGraphicsLayer = isHorizontal(orientation) ? |
| + m_overlayScrollbarHorizontal : m_overlayScrollbarVertical; |
| + OwnPtr<WebScrollbarLayer>& scrollbarWebLayer = isHorizontal(orientation) ? |
| + m_webScrollbarLayerHorizontal : m_webScrollbarLayerVertical; |
| + |
| + ASSERT(scrollbarGraphicsLayer); |
| + ASSERT(m_innerViewportScrollLayer->platformLayer()); |
| + if (!scrollbarWebLayer) { |
| + scrollbarWebLayer = |
| + adoptPtr(WebKit::Platform::current()->compositorSupport()->createScrollbarLayer( |
| + m_innerViewportScrollLayer->platformLayer(), orientation, kOverlayScrollbarThickness)); |
| + GraphicsLayer::registerContentsLayer(scrollbarWebLayer->layer()); |
| + scrollbarGraphicsLayer->setContentsToPlatformLayer(scrollbarWebLayer->layer()); |
| + } |
| + |
| + int xPosition = isHorizontal(orientation) ? 0 : m_innerViewportClipLayer->size().width() - kOverlayScrollbarThickness; |
| + int yPosition = isHorizontal(orientation) ? m_innerViewportClipLayer->size().height() - kOverlayScrollbarThickness : 0; |
| + int width = isHorizontal(orientation) ? m_innerViewportClipLayer->size().width() - kOverlayScrollbarThickness : kOverlayScrollbarThickness; |
| + int height = isHorizontal(orientation) ? kOverlayScrollbarThickness : m_innerViewportClipLayer->size().height() - kOverlayScrollbarThickness; |
| + |
| + scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition)); |
| + scrollbarGraphicsLayer->setSize(IntSize(width, height)); |
| + |
| + ASSERT(scrollbarGraphicsLayer->hasContentsLayer()); |
| + scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height)); |
| + scrollbarGraphicsLayer->setDrawsContent(true); |
| + 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.
|
| +} |
| + |
| +// 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
|
| +void PinchViewports::showGraphicsLayers() |
| +{ |
| +#ifndef NDEBUG |
| + if (m_innerViewportClipLayer) { |
| + GraphicsLayer* root = m_innerViewportClipLayer.get(); |
| + while (root->parent()) |
| + root = root->parent(); |
| + |
| + showGraphicsLayerTree(root); |
| + } |
| +#endif |
| +} |
| + |
| +} // namespace WebKit |