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

Unified Diff: cc/layer_tree_host.cc

Issue 11550035: Implement pinch-zoom scaling for main-frame scrollbars and pinch-zoom overlay scrollbars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix impl-side painting issues. Created 7 years, 10 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
Index: cc/layer_tree_host.cc
diff --git a/cc/layer_tree_host.cc b/cc/layer_tree_host.cc
index bc137893f8abbc4bc8a087dd596c4dd626a9cfcf..af1f4b39170bb5f0a7360aee16191d09a7f5b314 100644
--- a/cc/layer_tree_host.cc
+++ b/cc/layer_tree_host.cc
@@ -23,7 +23,11 @@
#include "cc/math_util.h"
#include "cc/occlusion_tracker.h"
#include "cc/overdraw_metrics.h"
+#include "cc/pinch_zoom_scrollbar.h"
+#include "cc/pinch_zoom_scrollbar_geometry.h"
+#include "cc/pinch_zoom_scrollbar_painter.h"
#include "cc/prioritized_resource_manager.h"
+#include "cc/scrollbar_layer.h"
#include "cc/single_thread_proxy.h"
#include "cc/switches.h"
#include "cc/thread.h"
@@ -328,6 +332,11 @@ void LayerTreeHost::finishCommitOnImplThread(LayerTreeHostImpl* hostImpl)
syncTree->ResetContentsTexturesPurged();
}
+ syncTree->SetPinchZoomHorizontalLayerId(
+ m_pinchZoomScrollbarHorizontal ? m_pinchZoomScrollbarHorizontal->id() : 0);
jamesr 2013/02/26 20:48:46 we use -1 as an invalid id most of the time
wjmaclean 2013/03/01 15:30:32 Fixed.
+ syncTree->SetPinchZoomVerticalLayerId(
+ m_pinchZoomScrollbarVertical ? m_pinchZoomScrollbarVertical->id() : 0);
+
if (!m_settings.implSidePainting) {
// If we're not in impl-side painting, the tree is immediately
// considered active.
@@ -340,6 +349,68 @@ void LayerTreeHost::finishCommitOnImplThread(LayerTreeHostImpl* hostImpl)
m_commitNumber++;
}
+void LayerTreeHost::setPinchZoomScrollbarPropertiesIfNeeded()
+{
+ if (!m_pinchZoomScrollbarHorizontal || !m_pinchZoomScrollbarVertical)
+ return;
+
+ gfx::Size size = layoutViewportSize();
+ int trackWidth = PinchZoomScrollbar::kTrackWidth;
+ Layer* rootScrollLayer = this->rootScrollLayer();
jamesr 2013/02/26 20:48:46 I can't find any uses of this local in this functi
wjmaclean 2013/03/01 15:30:32 Ooops, deleted this, but must have inadvertently r
+
+ m_pinchZoomScrollbarHorizontal->setBounds(gfx::Size(size.width() - trackWidth, trackWidth));
+ m_pinchZoomScrollbarHorizontal->setPosition(gfx::PointF(0, size.height() - trackWidth));
+ m_pinchZoomScrollbarHorizontal->setIsDrawable(true);
+ m_pinchZoomScrollbarHorizontal->setOpacity(0.5);
+ m_pinchZoomScrollbarHorizontal->setNeedsDisplay();
jamesr 2013/02/26 20:48:46 Most of these properties are the same every time,
wjmaclean 2013/03/01 15:30:32 Fixed.
+
+ m_pinchZoomScrollbarVertical->setBounds(gfx::Size(10, size.height() - 10));
jamesr 2013/02/26 20:48:46 What are these "10"s for? Are they supposed to be
wjmaclean 2013/03/01 15:30:32 Fixed. Trackwidth. I had them set correctly for h
+ m_pinchZoomScrollbarVertical->setPosition(gfx::PointF(size.width() - 10, 0));
+ m_pinchZoomScrollbarVertical->setIsDrawable(true);
+ m_pinchZoomScrollbarVertical->setOpacity(0.5);
+ m_pinchZoomScrollbarVertical->setNeedsDisplay();
+}
+
+static ScrollbarLayer* findScrollLayerScrollbar(Layer* layer, int targetScrollLayerId)
+{
+ if (layer->toScrollbarLayer()) {
+ int scrollLayerId = layer->toScrollbarLayer()->scrollLayerId();
+ if (scrollLayerId == targetScrollLayerId)
+ return layer->toScrollbarLayer();
+ }
+
+ const Layer::LayerList& children = layer->children();
+ for (size_t childIndex = 0; childIndex < children.size(); ++childIndex) {
+ ScrollbarLayer* result =
+ findScrollLayerScrollbar(children[childIndex].get(), targetScrollLayerId);
+ if (result)
+ return result;
+ }
+
+ return 0;
+}
+
+bool LayerTreeHost::rootScrollLayerUsesOverlayScrollbars() const
jamesr 2013/02/26 20:48:46 This function doesn't seem helpful. The decision
wjmaclean 2013/03/01 15:30:32 Done.
+{
+ // Use OS-specific defaults for the case where no rootLayer scrollbar is found.
+#if defined(OS_ANDROID)
+ bool usesOverlay = true;
+#else
+ bool usesOverlay = false;
+#endif
+
+ Layer* rootScrollLayer = this->rootScrollLayer();
+ if (!rootScrollLayer)
+ return usesOverlay;
+
+ ScrollbarLayer* rootScrollLayerScrollbar = findScrollLayerScrollbar(m_rootLayer.get(), rootScrollLayer->id());
+
+ if (rootScrollLayerScrollbar)
+ return rootScrollLayerScrollbar->isOverlay();
+ else
+ return usesOverlay;
+}
+
void LayerTreeHost::willCommit()
{
m_client->willCommit();
@@ -354,6 +425,44 @@ void LayerTreeHost::willCommit()
m_hudLayer->removeFromParent();
m_hudLayer = 0;
}
+
+ // Setup pinch-zoom scrollbars if required.
+ if (rootScrollLayer() && !rootScrollLayerUsesOverlayScrollbars()) {
jamesr 2013/02/26 20:48:46 This should check a setting to determine whether t
wjmaclean 2013/03/01 15:30:32 Done.
+ bool needsPropertiesUpdated = false;
+
+ if (!m_pinchZoomScrollbarHorizontal) {
jamesr 2013/02/26 20:48:46 This is way too much code to add to ::willCommit()
wjmaclean 2013/03/01 15:30:32 Done.
+ m_pinchZoomScrollbarHorizontal = ScrollbarLayer::create(
+ make_scoped_ptr(
+ new PinchZoomScrollbar(
+ WebKit::WebScrollbar::Horizontal, this)).PassAs<WebKit::WebScrollbar>(),
+ make_scoped_ptr(new PinchZoomScrollbarPainter).PassAs<ScrollbarThemePainter>(),
+ make_scoped_ptr(new WebKit::PinchZoomScrollbarGeometry).PassAs<WebKit::WebScrollbarThemeGeometry>(),
+ 0);
+ needsPropertiesUpdated = true;
+ }
+
+ DCHECK(m_pinchZoomScrollbarHorizontal);
+ if (!m_pinchZoomScrollbarHorizontal->parent())
+ m_rootLayer->addChild(m_pinchZoomScrollbarHorizontal);
+
+ if (!m_pinchZoomScrollbarVertical) {
+ m_pinchZoomScrollbarVertical = ScrollbarLayer::create(
+ make_scoped_ptr(
+ new PinchZoomScrollbar(
+ WebKit::WebScrollbar::Vertical, this)).PassAs<WebKit::WebScrollbar>(),
+ make_scoped_ptr(new PinchZoomScrollbarPainter).PassAs<ScrollbarThemePainter>(),
+ make_scoped_ptr(new WebKit::PinchZoomScrollbarGeometry).PassAs<WebKit::WebScrollbarThemeGeometry>(),
+ 0);
+ needsPropertiesUpdated = true;
+ }
+
+ DCHECK(m_pinchZoomScrollbarVertical);
+ if (!m_pinchZoomScrollbarVertical->parent())
+ m_rootLayer->addChild(m_pinchZoomScrollbarVertical);
+
+ if (needsPropertiesUpdated)
+ setPinchZoomScrollbarPropertiesIfNeeded();
+ }
}
void LayerTreeHost::commitComplete()
@@ -500,6 +609,7 @@ void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g
m_layoutViewportSize = layoutViewportSize;
m_deviceViewportSize = deviceViewportSize;
+ setPinchZoomScrollbarPropertiesIfNeeded();
setNeedsCommit();
}
@@ -593,6 +703,11 @@ static Layer* findFirstScrollableLayer(Layer* layer)
return 0;
}
+Layer* LayerTreeHost::rootScrollLayer() const
jamesr 2013/02/26 20:48:46 I think this function can completely go away
wjmaclean 2013/03/01 15:30:32 It's still used by PinchZoomScrollbar.
+{
+ return findFirstScrollableLayer(m_rootLayer.get());
+}
+
void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue)
{
TRACE_EVENT0("cc", "LayerTreeHost::updateLayers");
« no previous file with comments | « cc/layer_tree_host.h ('k') | cc/layer_tree_host_impl.cc » ('j') | cc/layer_tree_host_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698