OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "cc/animation/animation.h" | 13 #include "cc/animation/animation.h" |
14 #include "cc/animation/animation_events.h" | 14 #include "cc/animation/animation_events.h" |
15 #include "cc/animation/keyframed_animation_curve.h" | 15 #include "cc/animation/keyframed_animation_curve.h" |
16 #include "cc/animation/layer_animation_controller.h" | 16 #include "cc/animation/layer_animation_controller.h" |
17 #include "cc/layers/layer_client.h" | 17 #include "cc/layers/layer_client.h" |
18 #include "cc/layers/layer_impl.h" | 18 #include "cc/layers/layer_impl.h" |
| 19 #include "cc/layers/scrollbar_layer_interface.h" |
19 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
20 #include "cc/output/copy_output_result.h" | 21 #include "cc/output/copy_output_result.h" |
21 #include "cc/trees/layer_tree_host.h" | 22 #include "cc/trees/layer_tree_host.h" |
22 #include "cc/trees/layer_tree_impl.h" | 23 #include "cc/trees/layer_tree_impl.h" |
23 #include "third_party/skia/include/core/SkImageFilter.h" | 24 #include "third_party/skia/include/core/SkImageFilter.h" |
24 #include "ui/gfx/rect_conversions.h" | 25 #include "ui/gfx/rect_conversions.h" |
25 | 26 |
26 namespace cc { | 27 namespace cc { |
27 | 28 |
28 static int s_next_layer_id = 1; | 29 static int s_next_layer_id = 1; |
29 | 30 |
30 scoped_refptr<Layer> Layer::Create() { | 31 scoped_refptr<Layer> Layer::Create() { |
31 return make_scoped_refptr(new Layer()); | 32 return make_scoped_refptr(new Layer()); |
32 } | 33 } |
33 | 34 |
34 Layer::Layer() | 35 Layer::Layer() |
35 : needs_push_properties_(false), | 36 : needs_push_properties_(false), |
36 num_dependents_need_push_properties_(false), | 37 num_dependents_need_push_properties_(false), |
37 stacking_order_changed_(false), | 38 stacking_order_changed_(false), |
38 layer_id_(s_next_layer_id++), | 39 layer_id_(s_next_layer_id++), |
39 ignore_set_needs_commit_(false), | 40 ignore_set_needs_commit_(false), |
40 parent_(NULL), | 41 parent_(NULL), |
41 layer_tree_host_(NULL), | 42 layer_tree_host_(NULL), |
42 scrollable_(false), | 43 clip_layer_(NULL), |
43 should_scroll_on_main_thread_(false), | 44 should_scroll_on_main_thread_(false), |
44 have_wheel_event_handlers_(false), | 45 have_wheel_event_handlers_(false), |
45 user_scrollable_horizontal_(true), | 46 user_scrollable_horizontal_(true), |
46 user_scrollable_vertical_(true), | 47 user_scrollable_vertical_(true), |
47 is_root_for_isolated_group_(false), | 48 is_root_for_isolated_group_(false), |
48 is_container_for_fixed_position_layers_(false), | 49 is_container_for_fixed_position_layers_(false), |
49 is_drawable_(false), | 50 is_drawable_(false), |
50 hide_layer_and_subtree_(false), | 51 hide_layer_and_subtree_(false), |
51 masks_to_bounds_(false), | 52 masks_to_bounds_(false), |
52 contents_opaque_(false), | 53 contents_opaque_(false), |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 SetNeedsCommit(); | 672 SetNeedsCommit(); |
672 } | 673 } |
673 | 674 |
674 void Layer::RemoveClipChild(Layer* child) { | 675 void Layer::RemoveClipChild(Layer* child) { |
675 clip_children_->erase(child); | 676 clip_children_->erase(child); |
676 if (clip_children_->empty()) | 677 if (clip_children_->empty()) |
677 clip_children_.reset(); | 678 clip_children_.reset(); |
678 SetNeedsCommit(); | 679 SetNeedsCommit(); |
679 } | 680 } |
680 | 681 |
| 682 gfx::Vector2d Layer::BlinkScrollOffset() const { |
| 683 if (!layer_tree_host()) |
| 684 return scroll_offset(); |
| 685 |
| 686 return layer_tree_host()->BlinkScrollOffset(this); |
| 687 } |
| 688 |
681 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { | 689 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
682 DCHECK(IsPropertyChangeAllowed()); | 690 DCHECK(IsPropertyChangeAllowed()); |
| 691 |
| 692 if (layer_tree_host()) { |
| 693 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( |
| 694 scroll_offset, this); |
| 695 } |
| 696 |
683 if (scroll_offset_ == scroll_offset) | 697 if (scroll_offset_ == scroll_offset) |
684 return; | 698 return; |
685 scroll_offset_ = scroll_offset; | 699 scroll_offset_ = scroll_offset; |
| 700 |
686 SetNeedsCommit(); | 701 SetNeedsCommit(); |
687 } | 702 } |
688 | 703 |
689 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { | 704 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { |
690 DCHECK(IsPropertyChangeAllowed()); | 705 DCHECK(IsPropertyChangeAllowed()); |
691 // This function only gets called during a BeginMainFrame, so there | 706 // This function only gets called during a BeginMainFrame, so there |
692 // is no need to call SetNeedsUpdate here. | 707 // is no need to call SetNeedsUpdate here. |
693 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 708 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
694 if (scroll_offset_ == scroll_offset) | 709 if (scroll_offset_ == scroll_offset) |
695 return; | 710 return; |
696 scroll_offset_ = scroll_offset; | 711 scroll_offset_ = scroll_offset; |
697 SetNeedsPushProperties(); | 712 SetNeedsPushProperties(); |
698 if (!did_scroll_callback_.is_null()) | 713 if (!did_scroll_callback_.is_null()) |
699 did_scroll_callback_.Run(); | 714 did_scroll_callback_.Run(); |
700 // The callback could potentially change the layer structure: | 715 // The callback could potentially change the layer structure: |
701 // "this" may have been destroyed during the process. | 716 // "this" may have been destroyed during the process. |
702 } | 717 } |
703 | 718 |
704 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { | 719 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon |
| 720 // so that both Layer and LayerImpl are using the same code. In order |
| 721 // to template it we should avoid calling layer_tree_host() by giving |
| 722 // Layer/LayerImpl local accessors for page_scale_layer() and |
| 723 // page_scale_factor(). |
| 724 gfx::Vector2d Layer::MaxScrollOffset() const { |
| 725 if (!clip_layer_) |
| 726 return gfx::Vector2d(); |
| 727 |
| 728 gfx::Size scaled_scroll_bounds(bounds()); |
| 729 Layer const* current_layer = this; |
| 730 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); |
| 731 float scale_factor = 1.f; |
| 732 do { |
| 733 if (current_layer == page_scale_layer) { |
| 734 scale_factor = layer_tree_host()->page_scale_factor(); |
| 735 scaled_scroll_bounds.SetSize( |
| 736 scale_factor * scaled_scroll_bounds.width(), |
| 737 scale_factor * scaled_scroll_bounds.height()); |
| 738 } |
| 739 current_layer = current_layer->parent(); |
| 740 } while (current_layer && current_layer != clip_layer_); |
| 741 DCHECK(current_layer == clip_layer_); |
| 742 |
| 743 gfx::Vector2dF max_offset( |
| 744 scaled_scroll_bounds.width() - clip_layer_->bounds().width(), |
| 745 scaled_scroll_bounds.height() - clip_layer_->bounds().height()); |
| 746 // We need the final scroll offset to be in CSS coords. |
| 747 max_offset.Scale(1 / scale_factor); |
| 748 return gfx::Vector2d(max_offset.x(), max_offset.y()); |
| 749 } |
| 750 |
| 751 void Layer::SetScrollClipLayer(Layer* clip_layer) { |
705 DCHECK(IsPropertyChangeAllowed()); | 752 DCHECK(IsPropertyChangeAllowed()); |
706 if (max_scroll_offset_ == max_scroll_offset) | 753 if (clip_layer_ == clip_layer) |
707 return; | 754 return; |
708 max_scroll_offset_ = max_scroll_offset; | 755 clip_layer_ = clip_layer; |
709 SetNeedsCommit(); | 756 SetNeedsCommit(); |
710 } | 757 } |
711 | 758 |
712 void Layer::SetScrollable(bool scrollable) { | |
713 DCHECK(IsPropertyChangeAllowed()); | |
714 if (scrollable_ == scrollable) | |
715 return; | |
716 scrollable_ = scrollable; | |
717 SetNeedsCommit(); | |
718 } | |
719 | |
720 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | 759 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
721 DCHECK(IsPropertyChangeAllowed()); | 760 DCHECK(IsPropertyChangeAllowed()); |
722 if (user_scrollable_horizontal_ == horizontal && | 761 if (user_scrollable_horizontal_ == horizontal && |
723 user_scrollable_vertical_ == vertical) | 762 user_scrollable_vertical_ == vertical) |
724 return; | 763 return; |
725 user_scrollable_horizontal_ = horizontal; | 764 user_scrollable_horizontal_ = horizontal; |
726 user_scrollable_vertical_ = vertical; | 765 user_scrollable_vertical_ = vertical; |
727 SetNeedsCommit(); | 766 SetNeedsCommit(); |
728 } | 767 } |
729 | 768 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 IsContainerForFixedPositionLayers()); | 949 IsContainerForFixedPositionLayers()); |
911 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 950 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
912 layer->SetPositionConstraint(position_constraint_); | 951 layer->SetPositionConstraint(position_constraint_); |
913 layer->SetPreserves3d(preserves_3d()); | 952 layer->SetPreserves3d(preserves_3d()); |
914 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 953 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
915 layer->SetSublayerTransform(sublayer_transform_); | 954 layer->SetSublayerTransform(sublayer_transform_); |
916 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 955 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
917 layer->SetTransform(transform_); | 956 layer->SetTransform(transform_); |
918 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 957 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
919 | 958 |
920 layer->SetScrollable(scrollable_); | 959 layer->SetScrollClipLayer(clip_layer_ ? clip_layer_->id() |
| 960 : Layer::INVALID_ID); |
921 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 961 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
922 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 962 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
923 layer->SetMaxScrollOffset(max_scroll_offset_); | |
924 | 963 |
925 LayerImpl* scroll_parent = NULL; | 964 LayerImpl* scroll_parent = NULL; |
926 if (scroll_parent_) | 965 if (scroll_parent_) |
927 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 966 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
928 | 967 |
929 layer->SetScrollParent(scroll_parent); | 968 layer->SetScrollParent(scroll_parent); |
930 if (scroll_children_) { | 969 if (scroll_children_) { |
931 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 970 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
932 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 971 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
933 it != scroll_children_->end(); ++it) | 972 it != scroll_children_->end(); ++it) |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 clip_parent_->RemoveClipChild(this); | 1220 clip_parent_->RemoveClipChild(this); |
1182 | 1221 |
1183 clip_parent_ = NULL; | 1222 clip_parent_ = NULL; |
1184 } | 1223 } |
1185 | 1224 |
1186 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1225 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1187 benchmark->RunOnLayer(this); | 1226 benchmark->RunOnLayer(this); |
1188 } | 1227 } |
1189 | 1228 |
1190 } // namespace cc | 1229 } // namespace cc |
OLD | NEW |