| Index: cc/layer_tree_impl.cc
|
| diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc
|
| index f16ec0035e93d2d3e7b66be833c00fdac28fa69e..b6034410b334fa6433c1fef128b89afd1a859880 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::s_invalidLayerId),
|
| + pinch_zoom_scrollbar_vertical_layer_id_(Layer::s_invalidLayerId),
|
| page_scale_factor_(1),
|
| page_scale_delta_(1),
|
| sent_page_scale_delta_(1),
|
| @@ -116,6 +124,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 +345,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 +501,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->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::kFadeDurationInSeconds, end_opacity,
|
| + EaseInTimingFunction::create()));
|
| +
|
| + scoped_ptr<Animation> animation = Animation::create(
|
| + curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
|
| + 0, Animation::Opacity);
|
| + animation->setIsImplOnly(true);
|
| +
|
| + return animation.Pass();
|
| +}
|
| +
|
| +static void StartFadeInAnimation(LayerImpl* layer) {
|
| + // The start opacity value must be > 0 in order that the scrollbars get
|
| + // painted at the start of the animation, otherwise they never display.
|
| + float start_opacity = fmax(0.01, layer->opacity());
|
| + LayerAnimationController* controller = layer->layerAnimationController();
|
| + // 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->layerAnimationController();
|
| + // 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(opacity, 0));
|
| +}
|
| +
|
| +void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
|
| + if (!HasPinchZoomScrollbars())
|
| + return;
|
| +
|
| + StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
|
| + StartFadeOutAnimation(PinchZoomScrollbarVertical());
|
| +}
|
| +
|
| +bool LayerTreeImpl::HasPinchZoomScrollbars() const {
|
| + return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::s_invalidLayerId &&
|
| + pinch_zoom_scrollbar_vertical_layer_id_ != Layer::s_invalidLayerId;
|
| +}
|
| +
|
| +
|
| } // namespace cc
|
|
|