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

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: Rebase to fix collision with solid colour scrollbars patch. Created 7 years, 9 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 | « cc/layer_tree_impl.h ('k') | cc/layer_tree_settings.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layer_tree_impl.cc
diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc
index b0cbfde2d56d67f912d6a6723cb27e4ffcaba056..84436d450ab4dcb21219ea92a36f925191db676d 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.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/size_conversions.h"
#include "ui/gfx/vector2d_conversions.h"
@@ -22,6 +27,8 @@ LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
currently_scrolling_layer_(0),
background_color_(0),
has_transparent_background_(false),
+ pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID),
+ pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID),
page_scale_factor_(1),
page_scale_delta_(1),
sent_page_scale_delta_(1),
@@ -118,6 +125,11 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
target_tree->root_layer(), 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() const {
@@ -369,6 +381,10 @@ void LayerTreeImpl::DidBecomeActive() {
DidBecomeActiveRecursive(root_layer());
FindRootScrollLayer();
UpdateMaxScrollOffset();
+ // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
+ // each commit (and after the root scroll layer has its max scroll offset
+ // set), we need to update pinch zoom scrollbars.
+ UpdatePinchZoomScrollbars();
}
bool LayerTreeImpl::ContentsTexturesPurged() const {
@@ -521,4 +537,118 @@ scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
return state.PassAs<base::Value>();
}
+void LayerTreeImpl::DidBeginScroll() {
+ if (HasPinchZoomScrollbars())
+ FadeInPinchZoomScrollbars();
+}
+
+void LayerTreeImpl::DidUpdateScroll() {
+ if (HasPinchZoomScrollbars())
+ UpdatePinchZoomScrollbars();
+}
+
+void LayerTreeImpl::DidEndScroll() {
+ if (HasPinchZoomScrollbars())
+ FadeOutPinchZoomScrollbars();
+}
+
+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::UpdatePinchZoomScrollbars() {
+ LayerImpl* root_scroll_layer = RootScrollLayer();
+ if (!root_scroll_layer)
+ return;
+
+ if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
+ scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
+ scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
+ scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
+ }
+ if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
+ scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
+ scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
+ scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().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::kFadeDurationInSeconds, end_opacity,
+ EaseInTimingFunction::create()));
+
+ scoped_ptr<Animation> animation = Animation::Create(
+ curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
+ 0, Animation::Opacity);
+ animation->set_is_impl_only(true);
+
+ return animation.Pass();
+}
+
+static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
+ DCHECK(layer);
+ float start_opacity = layer->opacity();
+ LayerAnimationController* controller = layer->layer_animation_controller();
+ // TODO() It shouldn't be necessary to manually remove the old animation.
+ if (Animation* animation = controller->GetAnimation(Animation::Opacity))
+ controller->RemoveAnimation(animation->id());
+ controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
+ PinchZoomScrollbar::kDefaultOpacity));
+}
+
+void LayerTreeImpl::FadeInPinchZoomScrollbars() {
+ if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
+ return;
+
+ StartFadeInAnimation(PinchZoomScrollbarHorizontal());
+ StartFadeInAnimation(PinchZoomScrollbarVertical());
+}
+
+static void StartFadeOutAnimation(LayerImpl* layer) {
+ float opacity = layer->opacity();
+ if (!opacity)
+ return;
+
+ LayerAnimationController* controller = layer->layer_animation_controller();
+ // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
+ // animation.
+ if (Animation* animation = controller->GetAnimation(Animation::Opacity))
+ controller->RemoveAnimation(animation->id());
+ controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
+}
+
+void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
+ if (!HasPinchZoomScrollbars())
+ return;
+
+ StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
+ StartFadeOutAnimation(PinchZoomScrollbarVertical());
+}
+
+bool LayerTreeImpl::HasPinchZoomScrollbars() const {
+ return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
+ pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
+}
+
+
} // namespace cc
« no previous file with comments | « 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