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

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: Revise for Ian's changes. 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"
16 #include "cc/scrollbar_layer_impl.h"
11 #include "ui/gfx/vector2d_conversions.h" 17 #include "ui/gfx/vector2d_conversions.h"
12 18
13 namespace cc { 19 namespace cc {
14 20
15 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) 21 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
16 : layer_tree_host_impl_(layer_tree_host_impl), 22 : layer_tree_host_impl_(layer_tree_host_impl),
17 source_frame_number_(-1), 23 source_frame_number_(-1),
18 hud_layer_(0), 24 hud_layer_(0),
19 root_scroll_layer_(0), 25 root_scroll_layer_(0),
20 currently_scrolling_layer_(0), 26 currently_scrolling_layer_(0),
21 background_color_(0), 27 background_color_(0),
22 has_transparent_background_(false), 28 has_transparent_background_(false),
29 pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID),
30 pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID),
23 page_scale_factor_(1), 31 page_scale_factor_(1),
24 page_scale_delta_(1), 32 page_scale_delta_(1),
25 sent_page_scale_delta_(1), 33 sent_page_scale_delta_(1),
26 min_page_scale_factor_(0), 34 min_page_scale_factor_(0),
27 max_page_scale_factor_(0), 35 max_page_scale_factor_(0),
28 scrolling_layer_id_from_previous_tree_(0), 36 scrolling_layer_id_from_previous_tree_(0),
29 contents_textures_purged_(false), 37 contents_textures_purged_(false),
30 viewport_size_invalid_(false), 38 viewport_size_invalid_(false),
31 needs_update_draw_properties_(true), 39 needs_update_draw_properties_(true),
32 needs_full_tree_sync_(true) { 40 needs_full_tree_sync_(true) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 target_tree->SetViewportSizeInvalid(); 117 target_tree->SetViewportSizeInvalid();
110 else 118 else
111 target_tree->ResetViewportSizeInvalid(); 119 target_tree->ResetViewportSizeInvalid();
112 120
113 if (hud_layer()) 121 if (hud_layer())
114 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( 122 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
115 LayerTreeHostCommon::findLayerInSubtree( 123 LayerTreeHostCommon::findLayerInSubtree(
116 target_tree->RootLayer(), hud_layer()->id()))); 124 target_tree->RootLayer(), hud_layer()->id())));
117 else 125 else
118 target_tree->set_hud_layer(NULL); 126 target_tree->set_hud_layer(NULL);
127
128 target_tree->SetPinchZoomHorizontalLayerId(
129 pinch_zoom_scrollbar_horizontal_layer_id_);
130 target_tree->SetPinchZoomVerticalLayerId(
131 pinch_zoom_scrollbar_vertical_layer_id_);
119 } 132 }
120 133
121 LayerImpl* LayerTreeImpl::RootScrollLayer() { 134 LayerImpl* LayerTreeImpl::RootScrollLayer() {
122 DCHECK(IsActiveTree()); 135 DCHECK(IsActiveTree());
123 return root_scroll_layer_; 136 return root_scroll_layer_;
124 } 137 }
125 138
126 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { 139 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() {
127 DCHECK(IsActiveTree()); 140 DCHECK(IsActiveTree());
128 return currently_scrolling_layer_; 141 return currently_scrolling_layer_;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 layer->DidBecomeActive(); 340 layer->DidBecomeActive();
328 for (size_t i = 0; i < layer->children().size(); ++i) 341 for (size_t i = 0; i < layer->children().size(); ++i)
329 DidBecomeActiveRecursive(layer->children()[i]); 342 DidBecomeActiveRecursive(layer->children()[i]);
330 } 343 }
331 344
332 void LayerTreeImpl::DidBecomeActive() { 345 void LayerTreeImpl::DidBecomeActive() {
333 if (RootLayer()) 346 if (RootLayer())
334 DidBecomeActiveRecursive(RootLayer()); 347 DidBecomeActiveRecursive(RootLayer());
335 FindRootScrollLayer(); 348 FindRootScrollLayer();
336 UpdateMaxScrollOffset(); 349 UpdateMaxScrollOffset();
350 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
351 // each commit (and after the root scroll layer has its max scroll offset
352 // set), we need to update pinch zoom scrollbars.
353 UpdatePinchZoomScrollbars();
337 } 354 }
338 355
339 bool LayerTreeImpl::ContentsTexturesPurged() const { 356 bool LayerTreeImpl::ContentsTexturesPurged() const {
340 return contents_textures_purged_; 357 return contents_textures_purged_;
341 } 358 }
342 359
343 void LayerTreeImpl::SetContentsTexturesPurged() { 360 void LayerTreeImpl::SetContentsTexturesPurged() {
344 contents_textures_purged_ = true; 361 contents_textures_purged_ = true;
345 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); 362 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this);
346 } 363 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); 496 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
480 for (LayerIteratorType it = LayerIteratorType::begin( 497 for (LayerIteratorType it = LayerIteratorType::begin(
481 &render_surface_layer_list_); it != end; ++it) { 498 &render_surface_layer_list_); it != end; ++it) {
482 if (!it.representsItself()) 499 if (!it.representsItself())
483 continue; 500 continue;
484 state->Append((*it)->AsValue().release()); 501 state->Append((*it)->AsValue().release());
485 } 502 }
486 return state.PassAs<base::Value>(); 503 return state.PassAs<base::Value>();
487 } 504 }
488 505
506 void LayerTreeImpl::DidBeginScroll() {
507 if (HasPinchZoomScrollbars())
508 FadeInPinchZoomScrollbars();
509 }
510
511 void LayerTreeImpl::DidUpdateScroll() {
512 if (HasPinchZoomScrollbars())
513 UpdatePinchZoomScrollbars();
514 }
515
516 void LayerTreeImpl::DidEndScroll() {
517 if (HasPinchZoomScrollbars())
518 FadeOutPinchZoomScrollbars();
519 }
520
521 void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
522 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
523 }
524
525 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
526 return static_cast<ScrollbarLayerImpl*>(LayerById(
527 pinch_zoom_scrollbar_horizontal_layer_id_));
528 }
529
530 void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
531 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
532 }
533
534 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
535 return static_cast<ScrollbarLayerImpl*>(LayerById(
536 pinch_zoom_scrollbar_vertical_layer_id_));
537 }
538
539 void LayerTreeImpl::UpdatePinchZoomScrollbars() {
540 LayerImpl* root_scroll_layer = RootScrollLayer();
541 if (!root_scroll_layer)
542 return;
543
544 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
545 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
546 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
547 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
548 }
549 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
550 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
551 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
552 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
553 }
554 }
555
556 static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
557 float start_opacity, float end_opacity) {
558 scoped_ptr<KeyframedFloatAnimationCurve> curve =
559 KeyframedFloatAnimationCurve::Create();
560 curve->AddKeyframe(FloatKeyframe::Create(
561 0, start_opacity, EaseInTimingFunction::create()));
562 curve->AddKeyframe(FloatKeyframe::Create(
563 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
564 EaseInTimingFunction::create()));
565
566 scoped_ptr<Animation> animation = Animation::Create(
567 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
568 0, Animation::Opacity);
569 animation->set_is_impl_only(true);
570
571 return animation.Pass();
572 }
573
574 static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
575 // 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.
576 // painted at the start of the animation, otherwise they never display.
577 DCHECK(layer);
578 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.
579 LayerAnimationController* controller = layer->layer_animation_controller();
580 // TODO() It shouldn't be necessary to manually remove the old animation.
581 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
582 controller->RemoveAnimation(animation->id());
583 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
584 PinchZoomScrollbar::kDefaultOpacity));
585 }
586
587 void LayerTreeImpl::FadeInPinchZoomScrollbars() {
588 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
589 return;
590
591 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
592 StartFadeInAnimation(PinchZoomScrollbarVertical());
593 }
594
595 static void StartFadeOutAnimation(LayerImpl* layer) {
596 float opacity = layer->opacity();
597 if (!opacity)
598 return;
599
600 LayerAnimationController* controller = layer->layer_animation_controller();
601 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
602 // animation.
603 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
604 controller->RemoveAnimation(animation->id());
605 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
606 }
607
608 void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
609 if (!HasPinchZoomScrollbars())
610 return;
611
612 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
613 StartFadeOutAnimation(PinchZoomScrollbarVertical());
614 }
615
616 bool LayerTreeImpl::HasPinchZoomScrollbars() const {
617 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
618 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
619 }
620
621
489 } // namespace cc 622 } // 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