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 scroll_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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 | 673 |
673 void Layer::RemoveClipChild(Layer* child) { | 674 void Layer::RemoveClipChild(Layer* child) { |
674 clip_children_->erase(child); | 675 clip_children_->erase(child); |
675 if (clip_children_->empty()) | 676 if (clip_children_->empty()) |
676 clip_children_.reset(); | 677 clip_children_.reset(); |
677 SetNeedsCommit(); | 678 SetNeedsCommit(); |
678 } | 679 } |
679 | 680 |
680 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { | 681 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
681 DCHECK(IsPropertyChangeAllowed()); | 682 DCHECK(IsPropertyChangeAllowed()); |
683 | |
684 if (layer_tree_host()) { | |
685 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( | |
686 scroll_offset, this); | |
687 } | |
688 | |
682 if (scroll_offset_ == scroll_offset) | 689 if (scroll_offset_ == scroll_offset) |
683 return; | 690 return; |
684 scroll_offset_ = scroll_offset; | 691 scroll_offset_ = scroll_offset; |
692 | |
enne (OOO)
2014/01/21 19:00:06
nit: unnecessary whitespace.
wjmaclean
2014/01/21 22:37:27
Done.
| |
685 SetNeedsCommit(); | 693 SetNeedsCommit(); |
686 } | 694 } |
687 | 695 |
688 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { | 696 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { |
689 DCHECK(IsPropertyChangeAllowed()); | 697 DCHECK(IsPropertyChangeAllowed()); |
690 // This function only gets called during a BeginMainFrame, so there | 698 // This function only gets called during a BeginMainFrame, so there |
691 // is no need to call SetNeedsUpdate here. | 699 // is no need to call SetNeedsUpdate here. |
692 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 700 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
693 if (scroll_offset_ == scroll_offset) | 701 if (scroll_offset_ == scroll_offset) |
694 return; | 702 return; |
695 scroll_offset_ = scroll_offset; | 703 scroll_offset_ = scroll_offset; |
696 SetNeedsPushProperties(); | 704 SetNeedsPushProperties(); |
697 if (!did_scroll_callback_.is_null()) | 705 if (!did_scroll_callback_.is_null()) |
698 did_scroll_callback_.Run(); | 706 did_scroll_callback_.Run(); |
699 // The callback could potentially change the layer structure: | 707 // The callback could potentially change the layer structure: |
700 // "this" may have been destroyed during the process. | 708 // "this" may have been destroyed during the process. |
701 } | 709 } |
702 | 710 |
703 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { | 711 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon |
712 // so that both Layer and LayerImpl are using the same code. In order | |
713 // to template it we should avoid calling layer_tree_host() by giving | |
714 // Layer/LayerImpl local accessors for page_scale_layer() and | |
715 // page_scale_factor(). | |
716 gfx::Vector2d Layer::MaxScrollOffset() const { | |
717 if (!scroll_clip_layer_) | |
718 return gfx::Vector2d(); | |
719 | |
720 gfx::Size scaled_scroll_bounds(bounds()); | |
721 Layer const* current_layer = this; | |
722 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); | |
723 float scale_factor = 1.f; | |
724 do { | |
725 if (current_layer == page_scale_layer) { | |
726 scale_factor = layer_tree_host()->page_scale_factor(); | |
727 scaled_scroll_bounds.SetSize( | |
728 scale_factor * scaled_scroll_bounds.width(), | |
729 scale_factor * scaled_scroll_bounds.height()); | |
730 } | |
731 current_layer = current_layer->parent(); | |
732 } while (current_layer && current_layer != scroll_clip_layer_); | |
733 DCHECK(current_layer == scroll_clip_layer_); | |
734 | |
735 gfx::Vector2dF max_offset( | |
736 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), | |
737 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); | |
738 // We need the final scroll offset to be in CSS coords. | |
739 max_offset.Scale(1 / scale_factor); | |
enne (OOO)
2014/01/21 19:00:06
1 => 1.f
wjmaclean
2014/01/21 22:37:27
Done.
| |
740 return gfx::Vector2d(max_offset.x(), max_offset.y()); | |
enne (OOO)
2014/01/21 19:00:06
Is flooring correct here? Use a named function to
wjmaclean
2014/01/21 22:37:27
I think flooring makes sense (since we'd rather st
| |
741 } | |
742 | |
743 void Layer::SetScrollClipLayer(Layer* clip_layer) { | |
704 DCHECK(IsPropertyChangeAllowed()); | 744 DCHECK(IsPropertyChangeAllowed()); |
705 if (max_scroll_offset_ == max_scroll_offset) | 745 if (scroll_clip_layer_ == clip_layer) |
706 return; | 746 return; |
707 max_scroll_offset_ = max_scroll_offset; | 747 scroll_clip_layer_ = clip_layer; |
708 SetNeedsCommit(); | 748 SetNeedsCommit(); |
709 } | 749 } |
710 | 750 |
711 void Layer::SetScrollable(bool scrollable) { | |
712 DCHECK(IsPropertyChangeAllowed()); | |
713 if (scrollable_ == scrollable) | |
714 return; | |
715 scrollable_ = scrollable; | |
716 SetNeedsCommit(); | |
717 } | |
718 | |
719 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | 751 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
720 DCHECK(IsPropertyChangeAllowed()); | 752 DCHECK(IsPropertyChangeAllowed()); |
721 if (user_scrollable_horizontal_ == horizontal && | 753 if (user_scrollable_horizontal_ == horizontal && |
722 user_scrollable_vertical_ == vertical) | 754 user_scrollable_vertical_ == vertical) |
723 return; | 755 return; |
724 user_scrollable_horizontal_ = horizontal; | 756 user_scrollable_horizontal_ = horizontal; |
725 user_scrollable_vertical_ = vertical; | 757 user_scrollable_vertical_ = vertical; |
726 SetNeedsCommit(); | 758 SetNeedsCommit(); |
727 } | 759 } |
728 | 760 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 IsContainerForFixedPositionLayers()); | 936 IsContainerForFixedPositionLayers()); |
905 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 937 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
906 layer->SetPositionConstraint(position_constraint_); | 938 layer->SetPositionConstraint(position_constraint_); |
907 layer->SetPreserves3d(preserves_3d()); | 939 layer->SetPreserves3d(preserves_3d()); |
908 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 940 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
909 layer->SetSublayerTransform(sublayer_transform_); | 941 layer->SetSublayerTransform(sublayer_transform_); |
910 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 942 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
911 layer->SetTransform(transform_); | 943 layer->SetTransform(transform_); |
912 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 944 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
913 | 945 |
914 layer->SetScrollable(scrollable_); | 946 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() |
947 : Layer::INVALID_ID); | |
915 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 948 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
916 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 949 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
917 layer->SetMaxScrollOffset(max_scroll_offset_); | |
918 | 950 |
919 LayerImpl* scroll_parent = NULL; | 951 LayerImpl* scroll_parent = NULL; |
920 if (scroll_parent_) | 952 if (scroll_parent_) |
921 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 953 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
922 | 954 |
923 layer->SetScrollParent(scroll_parent); | 955 layer->SetScrollParent(scroll_parent); |
924 if (scroll_children_) { | 956 if (scroll_children_) { |
925 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 957 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
926 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 958 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
927 it != scroll_children_->end(); ++it) | 959 it != scroll_children_->end(); ++it) |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1166 clip_parent_->RemoveClipChild(this); | 1198 clip_parent_->RemoveClipChild(this); |
1167 | 1199 |
1168 clip_parent_ = NULL; | 1200 clip_parent_ = NULL; |
1169 } | 1201 } |
1170 | 1202 |
1171 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1203 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1172 benchmark->RunOnLayer(this); | 1204 benchmark->RunOnLayer(this); |
1173 } | 1205 } |
1174 | 1206 |
1175 } // namespace cc | 1207 } // namespace cc |
OLD | NEW |