OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/layer_tree_json_parser.h" | 5 #include "cc/test/layer_tree_json_parser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/test/values_test_util.h" | 9 #include "base/test/values_test_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
12 #include "cc/layers/layer_settings.h" | 12 #include "cc/layers/layer_settings.h" |
13 #include "cc/layers/nine_patch_layer.h" | 13 #include "cc/layers/nine_patch_layer.h" |
14 #include "cc/layers/picture_layer.h" | 14 #include "cc/layers/picture_layer.h" |
15 #include "cc/layers/solid_color_layer.h" | 15 #include "cc/layers/solid_color_layer.h" |
16 #include "cc/layers/texture_layer.h" | 16 #include "cc/layers/texture_layer.h" |
17 #include "cc/trees/layer_tree_settings.h" | 17 #include "cc/trees/layer_tree_settings.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
| 23 bool GetEventListenerProperties(base::DictionaryValue* dict, |
| 24 const char* property, |
| 25 EventListenerProperties* listener_properties) { |
| 26 *listener_properties = EventListenerProperties::NONE; |
| 27 base::ListValue* list; |
| 28 bool success = true; |
| 29 if (dict->HasKey(property)) { |
| 30 success &= dict->GetList(property, &list); |
| 31 std::string str; |
| 32 for (size_t i = 0; i < list->GetSize(); i++) { |
| 33 success &= list->GetString(i, &str); |
| 34 if (str == "Blocking") |
| 35 *listener_properties |= EventListenerProperties::BLOCKING; |
| 36 else if (str == "Passive") |
| 37 *listener_properties |= EventListenerProperties::PASSIVE; |
| 38 else |
| 39 success = false; |
| 40 } |
| 41 } |
| 42 return success; |
| 43 } |
| 44 |
23 scoped_refptr<Layer> ParseTreeFromValue(base::Value* val, | 45 scoped_refptr<Layer> ParseTreeFromValue(base::Value* val, |
24 ContentLayerClient* content_client) { | 46 ContentLayerClient* content_client) { |
25 base::DictionaryValue* dict; | 47 base::DictionaryValue* dict; |
26 bool success = true; | 48 bool success = true; |
27 success &= val->GetAsDictionary(&dict); | 49 success &= val->GetAsDictionary(&dict); |
28 std::string layer_type; | 50 std::string layer_type; |
29 success &= dict->GetString("LayerType", &layer_type); | 51 success &= dict->GetString("LayerType", &layer_type); |
30 base::ListValue* list; | 52 base::ListValue* list; |
31 success &= dict->GetList("Bounds", &list); | 53 success &= dict->GetList("Bounds", &list); |
32 int width, height; | 54 int width, height; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // | 140 // |
119 // For now, we can safely indicate a layer is scrollable by giving it a | 141 // For now, we can safely indicate a layer is scrollable by giving it a |
120 // pointer to itself, something not normally allowed in a working tree. | 142 // pointer to itself, something not normally allowed in a working tree. |
121 // | 143 // |
122 // https://code.google.com/p/chromium/issues/detail?id=330622 | 144 // https://code.google.com/p/chromium/issues/detail?id=330622 |
123 // | 145 // |
124 if (dict->GetBoolean("Scrollable", &scrollable)) | 146 if (dict->GetBoolean("Scrollable", &scrollable)) |
125 new_layer->SetScrollClipLayerId(scrollable ? new_layer->id() | 147 new_layer->SetScrollClipLayerId(scrollable ? new_layer->id() |
126 : Layer::INVALID_ID); | 148 : Layer::INVALID_ID); |
127 | 149 |
128 bool wheel_handler; | 150 EventListenerProperties listener_properties; |
129 if (dict->GetBoolean("WheelHandler", &wheel_handler)) | 151 success &= |
130 new_layer->SetHaveWheelEventHandlers(wheel_handler); | 152 GetEventListenerProperties(dict, "TouchHandler", &listener_properties); |
| 153 new_layer->SetTouchEventProperties(listener_properties); |
| 154 |
| 155 success &= |
| 156 GetEventListenerProperties(dict, "WheelHandler", &listener_properties); |
| 157 new_layer->SetWheelEventProperties(listener_properties); |
131 | 158 |
132 bool scroll_handler; | 159 bool scroll_handler; |
133 if (dict->GetBoolean("ScrollHandler", &scroll_handler)) | 160 if (dict->GetBoolean("ScrollHandler", &scroll_handler)) |
134 new_layer->SetHaveScrollEventHandlers(scroll_handler); | 161 new_layer->SetHaveScrollEventHandlers(scroll_handler); |
135 | 162 |
136 bool is_3d_sorted; | 163 bool is_3d_sorted; |
137 if (dict->GetBoolean("Is3DSorted", &is_3d_sorted)) { | 164 if (dict->GetBoolean("Is3DSorted", &is_3d_sorted)) { |
138 // A non-zero context ID will put the layer into a 3D sorting context | 165 // A non-zero context ID will put the layer into a 3D sorting context |
139 new_layer->Set3dSortingContextId(is_3d_sorted ? 1 : 0); | 166 new_layer->Set3dSortingContextId(is_3d_sorted ? 1 : 0); |
140 } | 167 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 220 |
194 } // namespace | 221 } // namespace |
195 | 222 |
196 scoped_refptr<Layer> ParseTreeFromJson(std::string json, | 223 scoped_refptr<Layer> ParseTreeFromJson(std::string json, |
197 ContentLayerClient* content_client) { | 224 ContentLayerClient* content_client) { |
198 scoped_ptr<base::Value> val = base::test::ParseJson(json); | 225 scoped_ptr<base::Value> val = base::test::ParseJson(json); |
199 return ParseTreeFromValue(val.get(), content_client); | 226 return ParseTreeFromValue(val.get(), content_client); |
200 } | 227 } |
201 | 228 |
202 } // namespace cc | 229 } // namespace cc |
OLD | NEW |