OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/trace_event/trace_event_argument.h" |
| 6 #include "cc/animation/element_id.h" |
| 7 #include "cc/base/math_util.h" |
| 8 #include "cc/input/main_thread_scrolling_reason.h" |
| 9 #include "cc/proto/gfx_conversions.h" |
| 10 #include "cc/proto/property_tree.pb.h" |
| 11 #include "cc/trees/scroll_node.h" |
| 12 |
| 13 namespace cc { |
| 14 |
| 15 ScrollNode::ScrollNode() |
| 16 : id(-1), |
| 17 parent_id(-1), |
| 18 owner_id(-1), |
| 19 scrollable(false), |
| 20 main_thread_scrolling_reasons( |
| 21 MainThreadScrollingReason::kNotScrollingOnMain), |
| 22 contains_non_fast_scrollable_region(false), |
| 23 max_scroll_offset_affected_by_page_scale(false), |
| 24 is_inner_viewport_scroll_layer(false), |
| 25 is_outer_viewport_scroll_layer(false), |
| 26 should_flatten(false), |
| 27 user_scrollable_horizontal(false), |
| 28 user_scrollable_vertical(false), |
| 29 transform_id(0), |
| 30 num_drawn_descendants(0) {} |
| 31 |
| 32 ScrollNode::ScrollNode(const ScrollNode& other) = default; |
| 33 |
| 34 bool ScrollNode::operator==(const ScrollNode& other) const { |
| 35 return id == other.id && parent_id == other.parent_id && |
| 36 owner_id == other.owner_id && scrollable == other.scrollable && |
| 37 main_thread_scrolling_reasons == other.main_thread_scrolling_reasons && |
| 38 contains_non_fast_scrollable_region == |
| 39 other.contains_non_fast_scrollable_region && |
| 40 scroll_clip_layer_bounds == other.scroll_clip_layer_bounds && |
| 41 bounds == other.bounds && |
| 42 max_scroll_offset_affected_by_page_scale == |
| 43 other.max_scroll_offset_affected_by_page_scale && |
| 44 is_inner_viewport_scroll_layer == |
| 45 other.is_inner_viewport_scroll_layer && |
| 46 is_outer_viewport_scroll_layer == |
| 47 other.is_outer_viewport_scroll_layer && |
| 48 offset_to_transform_parent == other.offset_to_transform_parent && |
| 49 should_flatten == other.should_flatten && |
| 50 user_scrollable_horizontal == other.user_scrollable_horizontal && |
| 51 user_scrollable_vertical == other.user_scrollable_vertical && |
| 52 element_id == other.element_id && transform_id == other.transform_id; |
| 53 } |
| 54 |
| 55 void ScrollNode::ToProtobuf(proto::TreeNode* proto) const { |
| 56 proto->set_id(id); |
| 57 proto->set_parent_id(parent_id); |
| 58 proto->set_owner_id(owner_id); |
| 59 |
| 60 DCHECK(!proto->has_scroll_node_data()); |
| 61 proto::ScrollNodeData* data = proto->mutable_scroll_node_data(); |
| 62 data->set_scrollable(scrollable); |
| 63 data->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons); |
| 64 data->set_contains_non_fast_scrollable_region( |
| 65 contains_non_fast_scrollable_region); |
| 66 SizeToProto(scroll_clip_layer_bounds, |
| 67 data->mutable_scroll_clip_layer_bounds()); |
| 68 SizeToProto(bounds, data->mutable_bounds()); |
| 69 data->set_max_scroll_offset_affected_by_page_scale( |
| 70 max_scroll_offset_affected_by_page_scale); |
| 71 data->set_is_inner_viewport_scroll_layer(is_inner_viewport_scroll_layer); |
| 72 data->set_is_outer_viewport_scroll_layer(is_outer_viewport_scroll_layer); |
| 73 Vector2dFToProto(offset_to_transform_parent, |
| 74 data->mutable_offset_to_transform_parent()); |
| 75 data->set_should_flatten(should_flatten); |
| 76 data->set_user_scrollable_horizontal(user_scrollable_horizontal); |
| 77 data->set_user_scrollable_vertical(user_scrollable_vertical); |
| 78 element_id.ToProtobuf(data->mutable_element_id()); |
| 79 data->set_transform_id(transform_id); |
| 80 } |
| 81 |
| 82 void ScrollNode::FromProtobuf(const proto::TreeNode& proto) { |
| 83 id = proto.id(); |
| 84 parent_id = proto.parent_id(); |
| 85 owner_id = proto.owner_id(); |
| 86 |
| 87 DCHECK(proto.has_scroll_node_data()); |
| 88 const proto::ScrollNodeData& data = proto.scroll_node_data(); |
| 89 |
| 90 scrollable = data.scrollable(); |
| 91 main_thread_scrolling_reasons = data.main_thread_scrolling_reasons(); |
| 92 contains_non_fast_scrollable_region = |
| 93 data.contains_non_fast_scrollable_region(); |
| 94 scroll_clip_layer_bounds = ProtoToSize(data.scroll_clip_layer_bounds()); |
| 95 bounds = ProtoToSize(data.bounds()); |
| 96 max_scroll_offset_affected_by_page_scale = |
| 97 data.max_scroll_offset_affected_by_page_scale(); |
| 98 is_inner_viewport_scroll_layer = data.is_inner_viewport_scroll_layer(); |
| 99 is_outer_viewport_scroll_layer = data.is_outer_viewport_scroll_layer(); |
| 100 offset_to_transform_parent = |
| 101 ProtoToVector2dF(data.offset_to_transform_parent()); |
| 102 should_flatten = data.should_flatten(); |
| 103 user_scrollable_horizontal = data.user_scrollable_horizontal(); |
| 104 user_scrollable_vertical = data.user_scrollable_vertical(); |
| 105 element_id.FromProtobuf(data.element_id()); |
| 106 transform_id = data.transform_id(); |
| 107 } |
| 108 |
| 109 void ScrollNode::AsValueInto(base::trace_event::TracedValue* value) const { |
| 110 value->SetInteger("id", id); |
| 111 value->SetInteger("parent_id", parent_id); |
| 112 value->SetInteger("owner_id", owner_id); |
| 113 value->SetBoolean("scrollable", scrollable); |
| 114 MathUtil::AddToTracedValue("scroll_clip_layer_bounds", |
| 115 scroll_clip_layer_bounds, value); |
| 116 MathUtil::AddToTracedValue("bounds", bounds, value); |
| 117 MathUtil::AddToTracedValue("offset_to_transform_parent", |
| 118 offset_to_transform_parent, value); |
| 119 value->SetBoolean("should_flatten", should_flatten); |
| 120 value->SetBoolean("user_scrollable_horizontal", user_scrollable_horizontal); |
| 121 value->SetBoolean("user_scrollable_vertical", user_scrollable_vertical); |
| 122 |
| 123 element_id.AddToTracedValue(value); |
| 124 value->SetInteger("transform_id", transform_id); |
| 125 } |
| 126 |
| 127 } // namespace cc |
OLD | NEW |