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

Unified Diff: cc/layer_tree_impl.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: Revision as per comments, animate scrollbars, fix slow-path PZ scrolling. 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_impl.cc
diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc
index f16ec0035e93d2d3e7b66be833c00fdac28fa69e..19dc2e092a22d3eaeba374689a71a24dc1f6e245 100644
--- a/cc/layer_tree_impl.cc
+++ b/cc/layer_tree_impl.cc
@@ -5,9 +5,14 @@
#include "cc/layer_tree_impl.h"
#include "base/debug/trace_event.h"
+#include "cc/animation.h"
+#include "cc/animation_id_provider.h"
#include "cc/heads_up_display_layer_impl.h"
+#include "cc/keyframed_animation_curve.h"
#include "cc/layer_tree_host_common.h"
#include "cc/layer_tree_host_impl.h"
+#include "cc/pinch_zoom_scrollbar.h"
+#include "cc/scrollbar_layer_impl.h"
#include "ui/gfx/vector2d_conversions.h"
namespace cc {
@@ -116,6 +121,9 @@ void LayerTreeImpl::pushPropertiesTo(LayerTreeImpl* target_tree) {
target_tree->RootLayer(), hud_layer()->id())));
else
target_tree->set_hud_layer(NULL);
+
+ target_tree->SetPinchZoomHorizontalLayerId(pinch_zoom_scrollbar_horizontal_layer_id);
+ target_tree->SetPinchZoomVerticalLayerId(pinch_zoom_scrollbar_vertical_layer_id);
}
LayerImpl* LayerTreeImpl::RootScrollLayer() {
@@ -334,6 +342,9 @@ void LayerTreeImpl::DidBecomeActive() {
DidBecomeActiveRecursive(RootLayer());
FindRootScrollLayer();
UpdateMaxScrollOffset();
+ // When becoming active there may not be a currently scrolling layer so we
+ // need to force the update.
+ UpdatePinchZoomScrollbarsIfNeeded(true /* force update */);
jamesr 2013/03/02 03:19:14 If you need a comment for a bool parameter, that p
wjmaclean 2013/03/04 15:53:10 Done.
}
bool LayerTreeImpl::ContentsTexturesPurged() const {
@@ -486,4 +497,86 @@ scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
return state.PassAs<base::Value>();
}
+void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
+ pinch_zoom_scrollbar_horizontal_layer_id = layer_id;
+}
+
+ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
+ return static_cast<ScrollbarLayerImpl*>(LayerById(
+ pinch_zoom_scrollbar_horizontal_layer_id));
+}
+
+void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
+ pinch_zoom_scrollbar_vertical_layer_id = layer_id;
+}
+
+ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
+ return static_cast<ScrollbarLayerImpl*>(LayerById(
+ pinch_zoom_scrollbar_vertical_layer_id));
+}
+
+void LayerTreeImpl::UpdatePinchZoomScrollbarsIfNeeded(bool force_update) {
+ LayerImpl* root_scroll_layer = RootScrollLayer();
+ if (!root_scroll_layer ||
+ (!force_update && root_scroll_layer != CurrentlyScrollingLayer()))
+ return;
+
+ if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
+ scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().x());
+ scrollbar->setTotalSize(root_scroll_layer->bounds().width());
+ scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().x());
+ }
+ if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
+ scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().y());
+ scrollbar->setTotalSize(root_scroll_layer->bounds().height());
+ scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().y());
+ }
+}
+
+static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
+ float start_opacity, float end_opacity) {
+ scoped_ptr<KeyframedFloatAnimationCurve> curve =
+ KeyframedFloatAnimationCurve::create();
+ curve->addKeyframe(FloatKeyframe::create(
+ 0, start_opacity, EaseInTimingFunction::create()));
+ curve->addKeyframe(FloatKeyframe::create(
+ PinchZoomScrollbar::kFadeDuration, end_opacity,
+ EaseInTimingFunction::create()));
+
+ scoped_ptr<Animation> animation = Animation::create(curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(), 0, Animation::Opacity);
+ animation->setIsImplAnimationOnly(true);
+
+ return animation.Pass();
+}
+
+void LayerTreeImpl::FadeInPinchZoomScrollbars() {
+ if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
+ return;
+
+ animationRegistrar()->GetAnimationControllerForId(
+ pinch_zoom_scrollbar_horizontal_layer_id)->addAnimation(
+ MakePinchZoomFadeAnimation(0.01, PinchZoomScrollbar::kDefaultOpacity));
+
+ animationRegistrar()->GetAnimationControllerForId(
+ pinch_zoom_scrollbar_vertical_layer_id)->addAnimation(
+ MakePinchZoomFadeAnimation(0.01, PinchZoomScrollbar::kDefaultOpacity));
+}
+
+void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
+ if (!HasPinchZoomScrollbars())
+ return;
+
+ if (PinchZoomScrollbarHorizontal()->opacity() == 0 &&
+ PinchZoomScrollbarVertical()->opacity() == 0)
+ return;
+
+ animationRegistrar()->GetAnimationControllerForId(
+ pinch_zoom_scrollbar_horizontal_layer_id)->addAnimation(
+ MakePinchZoomFadeAnimation(PinchZoomScrollbar::kDefaultOpacity, 0));
+
+ animationRegistrar()->GetAnimationControllerForId(
+ pinch_zoom_scrollbar_vertical_layer_id)->addAnimation(
+ MakePinchZoomFadeAnimation(PinchZoomScrollbar::kDefaultOpacity, 0));
+}
+
} // namespace cc
« cc/layer_tree_host.cc ('K') | « cc/layer_tree_impl.h ('k') | cc/layer_tree_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698