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

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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_impl.h ('k') | cc/layer_tree_settings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
12 #include "cc/layer.h"
9 #include "cc/layer_tree_host_common.h" 13 #include "cc/layer_tree_host_common.h"
10 #include "cc/layer_tree_host_impl.h" 14 #include "cc/layer_tree_host_impl.h"
15 #include "cc/pinch_zoom_scrollbar.h"
11 #include "cc/scrollbar_layer_impl.h" 16 #include "cc/scrollbar_layer_impl.h"
12 #include "ui/gfx/size_conversions.h" 17 #include "ui/gfx/size_conversions.h"
13 #include "ui/gfx/vector2d_conversions.h" 18 #include "ui/gfx/vector2d_conversions.h"
14 19
15 namespace cc { 20 namespace cc {
16 21
17 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) 22 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
18 : layer_tree_host_impl_(layer_tree_host_impl), 23 : layer_tree_host_impl_(layer_tree_host_impl),
19 source_frame_number_(-1), 24 source_frame_number_(-1),
20 hud_layer_(0), 25 hud_layer_(0),
21 root_scroll_layer_(0), 26 root_scroll_layer_(0),
22 currently_scrolling_layer_(0), 27 currently_scrolling_layer_(0),
23 background_color_(0), 28 background_color_(0),
24 has_transparent_background_(false), 29 has_transparent_background_(false),
30 pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID),
31 pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID),
25 page_scale_factor_(1), 32 page_scale_factor_(1),
26 page_scale_delta_(1), 33 page_scale_delta_(1),
27 sent_page_scale_delta_(1), 34 sent_page_scale_delta_(1),
28 min_page_scale_factor_(0), 35 min_page_scale_factor_(0),
29 max_page_scale_factor_(0), 36 max_page_scale_factor_(0),
30 scrolling_layer_id_from_previous_tree_(0), 37 scrolling_layer_id_from_previous_tree_(0),
31 contents_textures_purged_(false), 38 contents_textures_purged_(false),
32 viewport_size_invalid_(false), 39 viewport_size_invalid_(false),
33 needs_update_draw_properties_(true), 40 needs_update_draw_properties_(true),
34 needs_full_tree_sync_(true) { 41 needs_full_tree_sync_(true) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 target_tree->SetViewportSizeInvalid(); 118 target_tree->SetViewportSizeInvalid();
112 else 119 else
113 target_tree->ResetViewportSizeInvalid(); 120 target_tree->ResetViewportSizeInvalid();
114 121
115 if (hud_layer()) 122 if (hud_layer())
116 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( 123 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
117 LayerTreeHostCommon::findLayerInSubtree( 124 LayerTreeHostCommon::findLayerInSubtree(
118 target_tree->root_layer(), hud_layer()->id()))); 125 target_tree->root_layer(), hud_layer()->id())));
119 else 126 else
120 target_tree->set_hud_layer(NULL); 127 target_tree->set_hud_layer(NULL);
128
129 target_tree->SetPinchZoomHorizontalLayerId(
130 pinch_zoom_scrollbar_horizontal_layer_id_);
131 target_tree->SetPinchZoomVerticalLayerId(
132 pinch_zoom_scrollbar_vertical_layer_id_);
121 } 133 }
122 134
123 LayerImpl* LayerTreeImpl::RootScrollLayer() const { 135 LayerImpl* LayerTreeImpl::RootScrollLayer() const {
124 DCHECK(IsActiveTree()); 136 DCHECK(IsActiveTree());
125 return root_scroll_layer_; 137 return root_scroll_layer_;
126 } 138 }
127 139
128 LayerImpl* LayerTreeImpl::RootClipLayer() const { 140 LayerImpl* LayerTreeImpl::RootClipLayer() const {
129 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; 141 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
130 } 142 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 layer->DidBecomeActive(); 374 layer->DidBecomeActive();
363 for (size_t i = 0; i < layer->children().size(); ++i) 375 for (size_t i = 0; i < layer->children().size(); ++i)
364 DidBecomeActiveRecursive(layer->children()[i]); 376 DidBecomeActiveRecursive(layer->children()[i]);
365 } 377 }
366 378
367 void LayerTreeImpl::DidBecomeActive() { 379 void LayerTreeImpl::DidBecomeActive() {
368 if (root_layer()) 380 if (root_layer())
369 DidBecomeActiveRecursive(root_layer()); 381 DidBecomeActiveRecursive(root_layer());
370 FindRootScrollLayer(); 382 FindRootScrollLayer();
371 UpdateMaxScrollOffset(); 383 UpdateMaxScrollOffset();
384 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
385 // each commit (and after the root scroll layer has its max scroll offset
386 // set), we need to update pinch zoom scrollbars.
387 UpdatePinchZoomScrollbars();
372 } 388 }
373 389
374 bool LayerTreeImpl::ContentsTexturesPurged() const { 390 bool LayerTreeImpl::ContentsTexturesPurged() const {
375 return contents_textures_purged_; 391 return contents_textures_purged_;
376 } 392 }
377 393
378 void LayerTreeImpl::SetContentsTexturesPurged() { 394 void LayerTreeImpl::SetContentsTexturesPurged() {
379 contents_textures_purged_ = true; 395 contents_textures_purged_ = true;
380 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 396 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
381 } 397 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); 530 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
515 for (LayerIteratorType it = LayerIteratorType::begin( 531 for (LayerIteratorType it = LayerIteratorType::begin(
516 &render_surface_layer_list_); it != end; ++it) { 532 &render_surface_layer_list_); it != end; ++it) {
517 if (!it.representsItself()) 533 if (!it.representsItself())
518 continue; 534 continue;
519 state->Append((*it)->AsValue().release()); 535 state->Append((*it)->AsValue().release());
520 } 536 }
521 return state.PassAs<base::Value>(); 537 return state.PassAs<base::Value>();
522 } 538 }
523 539
540 void LayerTreeImpl::DidBeginScroll() {
541 if (HasPinchZoomScrollbars())
542 FadeInPinchZoomScrollbars();
543 }
544
545 void LayerTreeImpl::DidUpdateScroll() {
546 if (HasPinchZoomScrollbars())
547 UpdatePinchZoomScrollbars();
548 }
549
550 void LayerTreeImpl::DidEndScroll() {
551 if (HasPinchZoomScrollbars())
552 FadeOutPinchZoomScrollbars();
553 }
554
555 void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
556 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
557 }
558
559 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
560 return static_cast<ScrollbarLayerImpl*>(LayerById(
561 pinch_zoom_scrollbar_horizontal_layer_id_));
562 }
563
564 void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
565 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
566 }
567
568 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
569 return static_cast<ScrollbarLayerImpl*>(LayerById(
570 pinch_zoom_scrollbar_vertical_layer_id_));
571 }
572
573 void LayerTreeImpl::UpdatePinchZoomScrollbars() {
574 LayerImpl* root_scroll_layer = RootScrollLayer();
575 if (!root_scroll_layer)
576 return;
577
578 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
579 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
580 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
581 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
582 }
583 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
584 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
585 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
586 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
587 }
588 }
589
590 static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
591 float start_opacity, float end_opacity) {
592 scoped_ptr<KeyframedFloatAnimationCurve> curve =
593 KeyframedFloatAnimationCurve::Create();
594 curve->AddKeyframe(FloatKeyframe::Create(
595 0, start_opacity, EaseInTimingFunction::create()));
596 curve->AddKeyframe(FloatKeyframe::Create(
597 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
598 EaseInTimingFunction::create()));
599
600 scoped_ptr<Animation> animation = Animation::Create(
601 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
602 0, Animation::Opacity);
603 animation->set_is_impl_only(true);
604
605 return animation.Pass();
606 }
607
608 static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
609 DCHECK(layer);
610 float start_opacity = layer->opacity();
611 LayerAnimationController* controller = layer->layer_animation_controller();
612 // TODO() It shouldn't be necessary to manually remove the old animation.
613 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
614 controller->RemoveAnimation(animation->id());
615 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
616 PinchZoomScrollbar::kDefaultOpacity));
617 }
618
619 void LayerTreeImpl::FadeInPinchZoomScrollbars() {
620 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
621 return;
622
623 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
624 StartFadeInAnimation(PinchZoomScrollbarVertical());
625 }
626
627 static void StartFadeOutAnimation(LayerImpl* layer) {
628 float opacity = layer->opacity();
629 if (!opacity)
630 return;
631
632 LayerAnimationController* controller = layer->layer_animation_controller();
633 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
634 // animation.
635 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
636 controller->RemoveAnimation(animation->id());
637 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
638 }
639
640 void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
641 if (!HasPinchZoomScrollbars())
642 return;
643
644 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
645 StartFadeOutAnimation(PinchZoomScrollbarVertical());
646 }
647
648 bool LayerTreeImpl::HasPinchZoomScrollbars() const {
649 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
650 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
651 }
652
653
524 } // namespace cc 654 } // namespace cc
OLDNEW
« 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