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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebKit/chromium/src/PinchViewports.h ('k') | Source/WebKit/chromium/src/WebViewImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7020cc2c5e75ec46545fcf5c6fdc1f9ebb258144
--- /dev/null
+++ b/Source/WebKit/chromium/src/PinchViewports.cpp
@@ -0,0 +1,258 @@
+/*
+ * 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;
+
+WTF::PassOwnPtr<PinchViewports> PinchViewports::create(WebViewImpl* owner)
+{
+ return adoptPtr(new PinchViewports(owner));
+}
+
+PinchViewports::PinchViewports(WebViewImpl* owner)
+ : m_owner(owner) { }
+
+// Implement destructor here as it needs access to the definition of WebScrollbar
+// to create the OwnPtr destructors.
+PinchViewports::~PinchViewports() { }
+
+void PinchViewports::setViewportSizes()
+{
+ if (m_innerViewportClipLayer) {
+ ASSERT(m_owner->page());
+ IntRect frameRect = m_owner->page()->mainFrame()->view()->frameRect();
+
+ m_innerViewportClipLayer->setSize(frameRect.size());
+ // Use bounds of scroll layer to communicate size of scrollbars.
+ m_innerViewportScrollLayer->setSize(frameRect.size());
+ reparentScrollbars();
+ 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):
+//
+// overflowControlsHostLayer (root layer)
+// *innerViewportClipLayer (fixed pos container)
+// *pageScaleLayer
+// *innerViewportScrollLayer
+// 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) [only added when existing scrollbars are non-overlay]
enne (OOO) 2013/06/12 21:43:53 Is this incorrect? I was under the impression tha
+// *verticalScrollbarLayer (overlay)
+//
+void PinchViewports::insertViewportLayers()
trchen 2013/06/12 21:38:00 I feel this is too intrusive. I can't see a good r
+{
+ RenderLayerCompositor* compositor = m_owner->compositor();
+ if (!compositor)
+ return;
+
+ GraphicsLayer* rootLayer = compositor->rootGraphicsLayer();
+ GraphicsLayer* clipLayer = compositor->clipLayer();
+
+ if (!rootLayer || !clipLayer)
+ return;
+
+ if (!m_innerViewportClipLayer) {
+ m_innerViewportClipLayer = GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0);
+ m_innerViewportClipLayer->platformLayer()->setIsContainerForFixedPositionLayers(true);
+#ifndef NDEBUG
+ m_innerViewportClipLayer->setName("inner viewport clip layer");
+#endif
+ }
+ if (!m_innerViewportScrollLayer) {
+ m_innerViewportScrollLayer = GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0);
+#ifndef NDEBUG
+ m_innerViewportScrollLayer->setName("inner viewport scroll layer");
+#endif
+ }
+ if (!m_pageScaleLayer) {
+ m_pageScaleLayer = GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0);
+#ifndef NDEBUG
+ m_pageScaleLayer->setName("page scale layer");
+#endif
+ }
+
+ m_innerViewportClipLayer->addChild(m_pageScaleLayer.get());
+ m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());
+ m_innerViewportScrollLayer->addChild(clipLayer);
+
+ // FIXME: Should we put in an ASSERT to verify that we don't have overhang
+ // layers floating around when we do this?
+ rootLayer->addChild(m_innerViewportClipLayer.get());
+
+ m_innerViewportClipLayer->setMasksToBounds(true);
+ m_innerViewportScrollLayer->platformLayer()->setScrollable(true);
+ setViewportSizes();
+}
+
+// Restores the graphics layer tree rooted at m_innerViewportClipLayer->parent()
+// to the state it was in prior to the viewport layers being inserted.
+// FIXME: Things seem to run fine whether or not we do this restoration, so
+// perhaps it isn't necessary to restore the tree? At present this is included
+// to 'be safe'.
+void PinchViewports::detachViewportLayers()
+{
+ if (!m_innerViewportClipLayer)
+ return;
+
+ ASSERT(m_innerViewportScrollLayer && m_innerViewportScrollLayer->children().size());
+ ASSERT(m_pageScaleLayer);
+
+ GraphicsLayer* frameClipLayer = m_innerViewportScrollLayer->children()[0];
+ GraphicsLayer* rootLayer = m_innerViewportClipLayer->parent();
+ if (!rootLayer || !frameClipLayer)
+ return;
+
+ rootLayer->addChild(frameClipLayer);
+
+ // If the inner viewport scroll layer still has children, they must be the
+ // original main frame scrollbars, and so we need to restore them to their
+ // former location, attached to the root graphics layer.
+ // FIXME: if RenderLayerCompositor is modified to attach the main frame
+ // scrollbars to the frame clip layer, then the following code can be
+ // removed.
+ while (m_innerViewportScrollLayer->children().size())
+ rootLayer->addChild(m_innerViewportScrollLayer->children()[0]);
+}
+
+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;
+
+ if (!scrollbarGraphicsLayer) {
+ scrollbarGraphicsLayer = GraphicsLayer::create(m_owner->graphicsLayerFactory(), 0);
+#if NDEBUG
+ scrollbarGraphicsLayer->setName(
+ isHorizontal(orientation) ? "overlay scrollbar horizontal" : "overlay scrollbar vertical");
+#endif
+ }
+
+ 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();
+}
+
+void PinchViewports::reparentScrollbars()
+{
+ Page* page = m_owner->page();
+
+ // We only need to create overlay scrollbars for the frame and move the
+ // existing ones if the existing ones are not already overlay.
+ if (!page || page->mainFrame()->view()->hasOverlayScrollbars())
+ return;
+
+ RenderLayerCompositor* compositor = m_owner->compositor();
+
+ GraphicsLayer* scrollbarHorizontal = compositor->layerForHorizontalScrollbar();
+ GraphicsLayer* scrollbarVertical = compositor->layerForVerticalScrollbar();
+ GraphicsLayer* scrollbarCorner = compositor->layerForScrollCorner();
+
+ ASSERT(m_innerViewportClipLayer);
+ ASSERT(m_innerViewportScrollLayer);
+
+ // Move existing mainframe scrollbars.
+ // FIXME: We would ultimately like to attach the mainframe scrollbars to the
+ // frame clip layer, but this should be done in RenderLayerCompositor (so
+ // all frames are treated the same). Once that happens, this code can be
+ // removed.
+ if (scrollbarHorizontal && scrollbarHorizontal->parent() != m_innerViewportScrollLayer.get())
+ m_innerViewportScrollLayer->addChild(scrollbarHorizontal);
+ if (scrollbarVertical && scrollbarVertical->parent() != m_innerViewportScrollLayer.get())
+ m_innerViewportScrollLayer->addChild(scrollbarVertical);
+ if (scrollbarCorner && scrollbarCorner->parent() != m_innerViewportScrollLayer.get())
+ m_innerViewportScrollLayer->addChild(scrollbarCorner);
+
+ // Setup the pinch overlay scrollbars.
+ setupScrollbar(WebScrollbar::Horizontal);
+ setupScrollbar(WebScrollbar::Vertical);
+ m_innerViewportClipLayer->addChild(m_overlayScrollbarHorizontal.get());
+ m_innerViewportClipLayer->addChild(m_overlayScrollbarVertical.get());
+}
+
+void PinchViewports::showGraphicsLayers()
+{
+ return;
+#ifndef NDEBUG
+ if (m_innerViewportClipLayer) {
+ GraphicsLayer* root = m_innerViewportClipLayer.get();
+ while (root->parent())
+ root = root->parent();
+
+ showGraphicsLayerTree(root);
+ }
+#endif
+}
+
+} // namespace WebKit
« no previous file with comments | « Source/WebKit/chromium/src/PinchViewports.h ('k') | Source/WebKit/chromium/src/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698