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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layer_tree_impl.h" 5 #include "cc/layer_tree_impl.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/animation.h"
9 #include "cc/animation_id_provider.h"
8 #include "cc/heads_up_display_layer_impl.h" 10 #include "cc/heads_up_display_layer_impl.h"
11 #include "cc/keyframed_animation_curve.h"
9 #include "cc/layer_tree_host_common.h" 12 #include "cc/layer_tree_host_common.h"
10 #include "cc/layer_tree_host_impl.h" 13 #include "cc/layer_tree_host_impl.h"
14 #include "cc/pinch_zoom_scrollbar.h"
15 #include "cc/scrollbar_layer_impl.h"
11 #include "ui/gfx/vector2d_conversions.h" 16 #include "ui/gfx/vector2d_conversions.h"
12 17
13 namespace cc { 18 namespace cc {
14 19
15 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) 20 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
16 : layer_tree_host_impl_(layer_tree_host_impl), 21 : layer_tree_host_impl_(layer_tree_host_impl),
17 source_frame_number_(-1), 22 source_frame_number_(-1),
18 hud_layer_(0), 23 hud_layer_(0),
19 root_scroll_layer_(0), 24 root_scroll_layer_(0),
20 currently_scrolling_layer_(0), 25 currently_scrolling_layer_(0),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 target_tree->SetViewportSizeInvalid(); 114 target_tree->SetViewportSizeInvalid();
110 else 115 else
111 target_tree->ResetViewportSizeInvalid(); 116 target_tree->ResetViewportSizeInvalid();
112 117
113 if (hud_layer()) 118 if (hud_layer())
114 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( 119 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
115 LayerTreeHostCommon::findLayerInSubtree( 120 LayerTreeHostCommon::findLayerInSubtree(
116 target_tree->RootLayer(), hud_layer()->id()))); 121 target_tree->RootLayer(), hud_layer()->id())));
117 else 122 else
118 target_tree->set_hud_layer(NULL); 123 target_tree->set_hud_layer(NULL);
124
125 target_tree->SetPinchZoomHorizontalLayerId(pinch_zoom_scrollbar_horizontal_lay er_id);
126 target_tree->SetPinchZoomVerticalLayerId(pinch_zoom_scrollbar_vertical_layer_i d);
119 } 127 }
120 128
121 LayerImpl* LayerTreeImpl::RootScrollLayer() { 129 LayerImpl* LayerTreeImpl::RootScrollLayer() {
122 DCHECK(IsActiveTree()); 130 DCHECK(IsActiveTree());
123 return root_scroll_layer_; 131 return root_scroll_layer_;
124 } 132 }
125 133
126 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { 134 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() {
127 DCHECK(IsActiveTree()); 135 DCHECK(IsActiveTree());
128 return currently_scrolling_layer_; 136 return currently_scrolling_layer_;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 layer->didBecomeActive(); 335 layer->didBecomeActive();
328 for (size_t i = 0; i < layer->children().size(); ++i) 336 for (size_t i = 0; i < layer->children().size(); ++i)
329 DidBecomeActiveRecursive(layer->children()[i]); 337 DidBecomeActiveRecursive(layer->children()[i]);
330 } 338 }
331 339
332 void LayerTreeImpl::DidBecomeActive() { 340 void LayerTreeImpl::DidBecomeActive() {
333 if (RootLayer()) 341 if (RootLayer())
334 DidBecomeActiveRecursive(RootLayer()); 342 DidBecomeActiveRecursive(RootLayer());
335 FindRootScrollLayer(); 343 FindRootScrollLayer();
336 UpdateMaxScrollOffset(); 344 UpdateMaxScrollOffset();
345 // When becoming active there may not be a currently scrolling layer so we
346 // need to force the update.
347 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.
337 } 348 }
338 349
339 bool LayerTreeImpl::ContentsTexturesPurged() const { 350 bool LayerTreeImpl::ContentsTexturesPurged() const {
340 return contents_textures_purged_; 351 return contents_textures_purged_;
341 } 352 }
342 353
343 void LayerTreeImpl::SetContentsTexturesPurged() { 354 void LayerTreeImpl::SetContentsTexturesPurged() {
344 contents_textures_purged_ = true; 355 contents_textures_purged_ = true;
345 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); 356 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this);
346 } 357 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); 490 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
480 for (LayerIteratorType it = LayerIteratorType::begin( 491 for (LayerIteratorType it = LayerIteratorType::begin(
481 &render_surface_layer_list_); it != end; ++it) { 492 &render_surface_layer_list_); it != end; ++it) {
482 if (!it.representsItself()) 493 if (!it.representsItself())
483 continue; 494 continue;
484 state->Append((*it)->AsValue().release()); 495 state->Append((*it)->AsValue().release());
485 } 496 }
486 return state.PassAs<base::Value>(); 497 return state.PassAs<base::Value>();
487 } 498 }
488 499
500 void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
501 pinch_zoom_scrollbar_horizontal_layer_id = layer_id;
502 }
503
504 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
505 return static_cast<ScrollbarLayerImpl*>(LayerById(
506 pinch_zoom_scrollbar_horizontal_layer_id));
507 }
508
509 void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
510 pinch_zoom_scrollbar_vertical_layer_id = layer_id;
511 }
512
513 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
514 return static_cast<ScrollbarLayerImpl*>(LayerById(
515 pinch_zoom_scrollbar_vertical_layer_id));
516 }
517
518 void LayerTreeImpl::UpdatePinchZoomScrollbarsIfNeeded(bool force_update) {
519 LayerImpl* root_scroll_layer = RootScrollLayer();
520 if (!root_scroll_layer ||
521 (!force_update && root_scroll_layer != CurrentlyScrollingLayer()))
522 return;
523
524 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
525 scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().x());
526 scrollbar->setTotalSize(root_scroll_layer->bounds().width());
527 scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().x());
528 }
529 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
530 scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().y());
531 scrollbar->setTotalSize(root_scroll_layer->bounds().height());
532 scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().y());
533 }
534 }
535
536 static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
537 float start_opacity, float end_opacity) {
538 scoped_ptr<KeyframedFloatAnimationCurve> curve =
539 KeyframedFloatAnimationCurve::create();
540 curve->addKeyframe(FloatKeyframe::create(
541 0, start_opacity, EaseInTimingFunction::create()));
542 curve->addKeyframe(FloatKeyframe::create(
543 PinchZoomScrollbar::kFadeDuration, end_opacity,
544 EaseInTimingFunction::create()));
545
546 scoped_ptr<Animation> animation = Animation::create(curve.PassAs<AnimationCurv e>(), AnimationIdProvider::NextAnimationId(), 0, Animation::Opacity);
547 animation->setIsImplAnimationOnly(true);
548
549 return animation.Pass();
550 }
551
552 void LayerTreeImpl::FadeInPinchZoomScrollbars() {
553 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
554 return;
555
556 animationRegistrar()->GetAnimationControllerForId(
557 pinch_zoom_scrollbar_horizontal_layer_id)->addAnimation(
558 MakePinchZoomFadeAnimation(0.01, PinchZoomScrollbar::kDefaultOpacity));
559
560 animationRegistrar()->GetAnimationControllerForId(
561 pinch_zoom_scrollbar_vertical_layer_id)->addAnimation(
562 MakePinchZoomFadeAnimation(0.01, PinchZoomScrollbar::kDefaultOpacity));
563 }
564
565 void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
566 if (!HasPinchZoomScrollbars())
567 return;
568
569 if (PinchZoomScrollbarHorizontal()->opacity() == 0 &&
570 PinchZoomScrollbarVertical()->opacity() == 0)
571 return;
572
573 animationRegistrar()->GetAnimationControllerForId(
574 pinch_zoom_scrollbar_horizontal_layer_id)->addAnimation(
575 MakePinchZoomFadeAnimation(PinchZoomScrollbar::kDefaultOpacity, 0));
576
577 animationRegistrar()->GetAnimationControllerForId(
578 pinch_zoom_scrollbar_vertical_layer_id)->addAnimation(
579 MakePinchZoomFadeAnimation(PinchZoomScrollbar::kDefaultOpacity, 0));
580 }
581
489 } // namespace cc 582 } // namespace cc
OLDNEW
« 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