Index: cc/layer_tree_impl.cc |
diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc |
index 1af316d743da69d39baede19e13dc0d085f48cf3..569f130523dcfe6467fe1e1425daf43b08fdfbff 100644 |
--- a/cc/layer_tree_impl.cc |
+++ b/cc/layer_tree_impl.cc |
@@ -5,9 +5,15 @@ |
#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/vector2d_conversions.h" |
namespace cc { |
@@ -20,6 +26,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), |
@@ -116,6 +124,11 @@ 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 +347,10 @@ void LayerTreeImpl::DidBecomeActive() { |
DidBecomeActiveRecursive(RootLayer()); |
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 { |
@@ -486,4 +503,120 @@ 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) { |
+ // The start opacity value must be > 0 in order that the scrollbars get |
enne (OOO)
2013/03/13 18:46:32
This comment is no longer true.
wjmaclean
2013/03/13 20:09:47
Removed.
|
+ // painted at the start of the animation, otherwise they never display. |
+ DCHECK(layer); |
+ float start_opacity = 0; |
enne (OOO)
2013/03/13 18:46:32
Shouldn't start_opacity be layer->opacity()?
wjmaclean
2013/03/13 20:09:47
Yes, that makes more sense, done.
|
+ 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 |