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/nine_patch_layer.h" | 12 #include "cc/layers/nine_patch_layer.h" |
13 #include "cc/layers/picture_layer.h" | 13 #include "cc/layers/picture_layer.h" |
14 #include "cc/layers/solid_color_layer.h" | 14 #include "cc/layers/solid_color_layer.h" |
15 #include "cc/layers/texture_layer.h" | 15 #include "cc/layers/texture_layer.h" |
16 #include "cc/trees/layer_tree_settings.h" | 16 #include "cc/trees/layer_tree_settings.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 scoped_refptr<Layer> ParseTreeFromValue(base::Value* val, | 22 scoped_refptr<Layer> ParseTreeFromValue(const base::Value& val, |
23 ContentLayerClient* content_client) { | 23 ContentLayerClient* content_client) { |
24 base::DictionaryValue* dict; | 24 const base::DictionaryValue* dict; |
25 bool success = true; | 25 bool success = true; |
26 success &= val->GetAsDictionary(&dict); | 26 success &= val.GetAsDictionary(&dict); |
27 std::string layer_type; | 27 std::string layer_type; |
28 success &= dict->GetString("LayerType", &layer_type); | 28 success &= dict->GetString("LayerType", &layer_type); |
29 base::ListValue* list; | 29 const base::ListValue* list; |
30 success &= dict->GetList("Bounds", &list); | 30 success &= dict->GetList("Bounds", &list); |
31 int width, height; | 31 int width, height; |
32 success &= list->GetInteger(0, &width); | 32 success &= list->GetInteger(0, &width); |
33 success &= list->GetInteger(1, &height); | 33 success &= list->GetInteger(1, &height); |
34 success &= dict->GetList("Position", &list); | 34 success &= dict->GetList("Position", &list); |
35 double position_x, position_y; | 35 double position_x, position_y; |
36 success &= list->GetDouble(0, &position_x); | 36 success &= list->GetDouble(0, &position_x); |
37 success &= list->GetDouble(1, &position_y); | 37 success &= list->GetDouble(1, &position_y); |
38 | 38 |
39 bool draws_content; | 39 bool draws_content; |
40 success &= dict->GetBoolean("DrawsContent", &draws_content); | 40 success &= dict->GetBoolean("DrawsContent", &draws_content); |
41 | 41 |
42 scoped_refptr<Layer> new_layer; | 42 scoped_refptr<Layer> new_layer; |
43 if (layer_type == "SolidColorLayer") { | 43 if (layer_type == "SolidColorLayer") { |
44 new_layer = SolidColorLayer::Create(); | 44 new_layer = SolidColorLayer::Create(); |
45 } else if (layer_type == "NinePatchLayer") { | 45 } else if (layer_type == "NinePatchLayer") { |
46 success &= dict->GetList("ImageAperture", &list); | 46 success &= dict->GetList("ImageAperture", &list); |
47 int aperture_x, aperture_y, aperture_width, aperture_height; | 47 int aperture_x, aperture_y, aperture_width, aperture_height; |
48 success &= list->GetInteger(0, &aperture_x); | 48 success &= list->GetInteger(0, &aperture_x); |
49 success &= list->GetInteger(1, &aperture_y); | 49 success &= list->GetInteger(1, &aperture_y); |
50 success &= list->GetInteger(2, &aperture_width); | 50 success &= list->GetInteger(2, &aperture_width); |
51 success &= list->GetInteger(3, &aperture_height); | 51 success &= list->GetInteger(3, &aperture_height); |
52 | 52 |
53 base::ListValue* bounds; | 53 const base::ListValue* bounds; |
54 success &= dict->GetList("ImageBounds", &bounds); | 54 success &= dict->GetList("ImageBounds", &bounds); |
55 double image_width, image_height; | 55 double image_width, image_height; |
56 success &= bounds->GetDouble(0, &image_width); | 56 success &= bounds->GetDouble(0, &image_width); |
57 success &= bounds->GetDouble(1, &image_height); | 57 success &= bounds->GetDouble(1, &image_height); |
58 | 58 |
59 success &= dict->GetList("Border", &list); | 59 success &= dict->GetList("Border", &list); |
60 int border_x, border_y, border_width, border_height; | 60 int border_x, border_y, border_width, border_height; |
61 success &= list->GetInteger(0, &border_x); | 61 success &= list->GetInteger(0, &border_x); |
62 success &= list->GetInteger(1, &border_y); | 62 success &= list->GetInteger(1, &border_y); |
63 success &= list->GetInteger(2, &border_width); | 63 success &= list->GetInteger(2, &border_width); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 success &= dict->GetList("Transform", &list); | 144 success &= dict->GetList("Transform", &list); |
145 double transform[16]; | 145 double transform[16]; |
146 for (int i = 0; i < 16; ++i) | 146 for (int i = 0; i < 16; ++i) |
147 success &= list->GetDouble(i, &transform[i]); | 147 success &= list->GetDouble(i, &transform[i]); |
148 | 148 |
149 gfx::Transform layer_transform; | 149 gfx::Transform layer_transform; |
150 layer_transform.matrix().setColMajord(transform); | 150 layer_transform.matrix().setColMajord(transform); |
151 new_layer->SetTransform(layer_transform); | 151 new_layer->SetTransform(layer_transform); |
152 | 152 |
153 success &= dict->GetList("Children", &list); | 153 success &= dict->GetList("Children", &list); |
154 for (base::ListValue::const_iterator it = list->begin(); | 154 for (const auto& value : *list) { |
155 it != list->end(); ++it) { | 155 new_layer->AddChild(ParseTreeFromValue(*value, content_client)); |
156 new_layer->AddChild(ParseTreeFromValue(*it, content_client)); | |
157 } | 156 } |
158 | 157 |
159 if (!success) | 158 if (!success) |
160 return NULL; | 159 return NULL; |
161 | 160 |
162 return new_layer; | 161 return new_layer; |
163 } | 162 } |
164 | 163 |
165 } // namespace | 164 } // namespace |
166 | 165 |
167 scoped_refptr<Layer> ParseTreeFromJson(std::string json, | 166 scoped_refptr<Layer> ParseTreeFromJson(std::string json, |
168 ContentLayerClient* content_client) { | 167 ContentLayerClient* content_client) { |
169 std::unique_ptr<base::Value> val = base::test::ParseJson(json); | 168 std::unique_ptr<base::Value> val = base::test::ParseJson(json); |
170 return ParseTreeFromValue(val.get(), content_client); | 169 return ParseTreeFromValue(*val, content_client); |
171 } | 170 } |
172 | 171 |
173 } // namespace cc | 172 } // namespace cc |
OLD | NEW |