| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/android/vr_shell/ui_scene.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/android/vr_shell/animation.h" | 8 #include "chrome/browser/android/vr_shell/animation.h" |
| 9 #include "chrome/browser/android/vr_shell/easing.h" | 9 #include "chrome/browser/android/vr_shell/easing.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_elements.h" | 10 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 11 | 11 |
| 12 namespace vr_shell { | 12 namespace vr_shell { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 void ParseRecti(const base::DictionaryValue& dict, const std::string& key, | 16 bool ParseRecti(const base::DictionaryValue& dict, |
| 17 const std::string& key, |
| 17 Recti* output) { | 18 Recti* output) { |
| 18 const base::DictionaryValue* item_dict; | 19 const base::DictionaryValue* item_dict; |
| 19 if (dict.GetDictionary(key, &item_dict)) { | 20 if (dict.GetDictionary(key, &item_dict)) { |
| 20 CHECK(item_dict->GetInteger("x", &output->x)); | 21 CHECK(item_dict->GetInteger("x", &output->x)); |
| 21 CHECK(item_dict->GetInteger("y", &output->y)); | 22 CHECK(item_dict->GetInteger("y", &output->y)); |
| 22 CHECK(item_dict->GetInteger("width", &output->width)); | 23 CHECK(item_dict->GetInteger("width", &output->width)); |
| 23 CHECK(item_dict->GetInteger("height", &output->height)); | 24 CHECK(item_dict->GetInteger("height", &output->height)); |
| 25 return true; |
| 26 } else { |
| 27 return false; |
| 24 } | 28 } |
| 25 } | 29 } |
| 26 | 30 |
| 27 void Parse2DVec3f(const base::DictionaryValue& dict, const std::string& key, | 31 bool Parse2DVec3f(const base::DictionaryValue& dict, |
| 32 const std::string& key, |
| 28 gvr::Vec3f* output) { | 33 gvr::Vec3f* output) { |
| 29 const base::DictionaryValue* item_dict; | 34 const base::DictionaryValue* item_dict; |
| 30 if (dict.GetDictionary(key, &item_dict)) { | 35 if (dict.GetDictionary(key, &item_dict)) { |
| 31 double value; | 36 double value; |
| 32 CHECK(item_dict->GetDouble("x", &value)); | 37 CHECK(item_dict->GetDouble("x", &value)); |
| 33 output->x = value; | 38 output->x = value; |
| 34 CHECK(item_dict->GetDouble("y", &value)); | 39 CHECK(item_dict->GetDouble("y", &value)); |
| 35 output->y = value; | 40 output->y = value; |
| 36 output->z = 1.0f; | 41 output->z = 1.0f; |
| 42 return true; |
| 43 } else { |
| 44 return false; |
| 37 } | 45 } |
| 38 } | 46 } |
| 39 | 47 |
| 40 void ParseVec3f(const base::DictionaryValue& dict, const std::string& key, | 48 bool ParseVec3f(const base::DictionaryValue& dict, |
| 49 const std::string& key, |
| 41 gvr::Vec3f* output) { | 50 gvr::Vec3f* output) { |
| 42 const base::DictionaryValue* item_dict; | 51 const base::DictionaryValue* item_dict; |
| 43 if (dict.GetDictionary(key, &item_dict)) { | 52 if (dict.GetDictionary(key, &item_dict)) { |
| 44 double value; | 53 double value; |
| 45 CHECK(item_dict->GetDouble("x", &value)); | 54 CHECK(item_dict->GetDouble("x", &value)); |
| 46 output->x = value; | 55 output->x = value; |
| 47 CHECK(item_dict->GetDouble("y", &value)); | 56 CHECK(item_dict->GetDouble("y", &value)); |
| 48 output->y = value; | 57 output->y = value; |
| 49 CHECK(item_dict->GetDouble("z", &value)); | 58 CHECK(item_dict->GetDouble("z", &value)); |
| 50 output->z = value; | 59 output->z = value; |
| 60 return true; |
| 61 } else { |
| 62 return false; |
| 51 } | 63 } |
| 52 } | 64 } |
| 53 | 65 |
| 54 void ParseRotationAxisAngle(const base::DictionaryValue& dict, | 66 bool ParseColorf(const base::DictionaryValue& dict, |
| 55 const std::string& key, RotationAxisAngle* output) { | 67 const std::string& key, |
| 68 Colorf* output) { |
| 56 const base::DictionaryValue* item_dict; | 69 const base::DictionaryValue* item_dict; |
| 57 if (dict.GetDictionary(key, &item_dict)) { | 70 if (dict.GetDictionary(key, &item_dict)) { |
| 58 double value; | 71 double value; |
| 72 CHECK(item_dict->GetDouble("r", &value)); |
| 73 output->r = value; |
| 74 CHECK(item_dict->GetDouble("g", &value)); |
| 75 output->g = value; |
| 76 CHECK(item_dict->GetDouble("b", &value)); |
| 77 output->b = value; |
| 78 CHECK(item_dict->GetDouble("a", &value)); |
| 79 output->a = value; |
| 80 return true; |
| 81 } else { |
| 82 return false; |
| 83 } |
| 84 } |
| 85 |
| 86 bool ParseRotationAxisAngle(const base::DictionaryValue& dict, |
| 87 const std::string& key, |
| 88 RotationAxisAngle* output) { |
| 89 const base::DictionaryValue* item_dict; |
| 90 if (dict.GetDictionary(key, &item_dict)) { |
| 91 double value; |
| 59 CHECK(item_dict->GetDouble("x", &value)); | 92 CHECK(item_dict->GetDouble("x", &value)); |
| 60 output->x = value; | 93 output->x = value; |
| 61 CHECK(item_dict->GetDouble("y", &value)); | 94 CHECK(item_dict->GetDouble("y", &value)); |
| 62 output->y = value; | 95 output->y = value; |
| 63 CHECK(item_dict->GetDouble("z", &value)); | 96 CHECK(item_dict->GetDouble("z", &value)); |
| 64 output->z = value; | 97 output->z = value; |
| 65 CHECK(item_dict->GetDouble("a", &value)); | 98 CHECK(item_dict->GetDouble("a", &value)); |
| 66 output->angle = value; | 99 output->angle = value; |
| 100 return true; |
| 101 } else { |
| 102 return false; |
| 67 } | 103 } |
| 68 } | 104 } |
| 69 | 105 |
| 70 void ParseFloats(const base::DictionaryValue& dict, | 106 void ParseFloats(const base::DictionaryValue& dict, |
| 71 const std::vector<std::string>& keys, | 107 const std::vector<std::string>& keys, |
| 72 std::vector<float>* vec) { | 108 std::vector<float>* vec) { |
| 73 for (const auto& key : keys) { | 109 for (const auto& key : keys) { |
| 74 double value; | 110 double value; |
| 75 CHECK(dict.GetDouble(key, &value)) << "parsing tag " << key; | 111 CHECK(dict.GetDouble(key, &value)) << "parsing tag " << key; |
| 76 vec->push_back(value); | 112 vec->push_back(value); |
| 77 } | 113 } |
| 78 } | 114 } |
| 79 | 115 |
| 80 void ParseEndpointToFloats(Animation::Property property, | 116 bool ParseEndpointToFloats(Animation::Property property, |
| 81 const base::DictionaryValue& dict, | 117 const base::DictionaryValue& dict, |
| 82 std::vector<float>* vec) { | 118 std::vector<float>* vec) { |
| 83 switch (property) { | 119 switch (property) { |
| 84 case Animation::Property::COPYRECT: | 120 case Animation::Property::COPYRECT: |
| 85 ParseFloats(dict, {"x", "y", "width", "height"}, vec); | 121 ParseFloats(dict, {"x", "y", "width", "height"}, vec); |
| 86 break; | 122 return true; |
| 87 case Animation::Property::SIZE: | 123 case Animation::Property::SIZE: |
| 88 ParseFloats(dict, {"x", "y"}, vec); | 124 ParseFloats(dict, {"x", "y"}, vec); |
| 89 break; | 125 return true; |
| 90 case Animation::Property::SCALE: | 126 case Animation::Property::SCALE: |
| 91 ParseFloats(dict, {"x", "y", "z"}, vec); | 127 ParseFloats(dict, {"x", "y", "z"}, vec); |
| 92 break; | 128 return true; |
| 93 case Animation::Property::ROTATION: | 129 case Animation::Property::ROTATION: |
| 94 ParseFloats(dict, {"x", "y", "z", "a"}, vec); | 130 ParseFloats(dict, {"x", "y", "z", "a"}, vec); |
| 95 break; | 131 return true; |
| 96 case Animation::Property::TRANSLATION: | 132 case Animation::Property::TRANSLATION: |
| 97 ParseFloats(dict, {"x", "y", "z"}, vec); | 133 ParseFloats(dict, {"x", "y", "z"}, vec); |
| 98 break; | 134 return true; |
| 99 case Animation::Property::OPACITY: | 135 case Animation::Property::OPACITY: |
| 100 ParseFloats(dict, {"x"}, vec); | 136 ParseFloats(dict, {"x"}, vec); |
| 101 break; | 137 return true; |
| 102 } | 138 } |
| 139 return false; |
| 103 } | 140 } |
| 104 | 141 |
| 105 std::unique_ptr<easing::Easing> ParseEasing( | 142 std::unique_ptr<easing::Easing> ParseEasing( |
| 106 const base::DictionaryValue& dict) { | 143 const base::DictionaryValue& dict) { |
| 107 easing::EasingType easingType; | 144 easing::EasingType easingType; |
| 108 CHECK(dict.GetInteger("type", reinterpret_cast<int*>(&easingType))); | 145 CHECK(dict.GetInteger("type", reinterpret_cast<int*>(&easingType))); |
| 109 std::unique_ptr<easing::Easing> result; | 146 std::unique_ptr<easing::Easing> result; |
| 110 | 147 |
| 111 switch (easingType) { | 148 switch (easingType) { |
| 112 case easing::EasingType::LINEAR: { | 149 case easing::EasingType::LINEAR: { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 int id; | 235 int id; |
| 199 CHECK(dict.GetInteger("id", &id)); | 236 CHECK(dict.GetInteger("id", &id)); |
| 200 ContentRectangle* element = GetUiElementById(id); | 237 ContentRectangle* element = GetUiElementById(id); |
| 201 CHECK_NE(element, nullptr); | 238 CHECK_NE(element, nullptr); |
| 202 ApplyDictToElement(dict, element); | 239 ApplyDictToElement(dict, element); |
| 203 } | 240 } |
| 204 | 241 |
| 205 void UiScene::RemoveUiElement(int element_id) { | 242 void UiScene::RemoveUiElement(int element_id) { |
| 206 for (auto it = ui_elements_.begin(); it != ui_elements_.end(); ++it) { | 243 for (auto it = ui_elements_.begin(); it != ui_elements_.end(); ++it) { |
| 207 if ((*it)->id == element_id) { | 244 if ((*it)->id == element_id) { |
| 208 if ((*it)->content_quad) { | 245 if ((*it)->fill == Fill::CONTENT) { |
| 209 content_element_ = nullptr; | 246 content_element_ = nullptr; |
| 210 } | 247 } |
| 211 ui_elements_.erase(it); | 248 ui_elements_.erase(it); |
| 212 return; | 249 return; |
| 213 } | 250 } |
| 214 } | 251 } |
| 215 } | 252 } |
| 216 | 253 |
| 217 void UiScene::AddAnimation(int element_id, | 254 void UiScene::AddAnimation(int element_id, |
| 218 std::unique_ptr<Animation>& animation) { | 255 std::unique_ptr<Animation>& animation) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 int parent_id; | 417 int parent_id; |
| 381 if (dict.GetInteger("parentId", &parent_id)) { | 418 if (dict.GetInteger("parentId", &parent_id)) { |
| 382 CHECK_GE(parent_id, 0); | 419 CHECK_GE(parent_id, 0); |
| 383 CHECK_NE(GetUiElementById(parent_id), nullptr); | 420 CHECK_NE(GetUiElementById(parent_id), nullptr); |
| 384 element->parent_id = parent_id; | 421 element->parent_id = parent_id; |
| 385 } | 422 } |
| 386 | 423 |
| 387 dict.GetBoolean("visible", &element->visible); | 424 dict.GetBoolean("visible", &element->visible); |
| 388 dict.GetBoolean("hitTestable", &element->hit_testable); | 425 dict.GetBoolean("hitTestable", &element->hit_testable); |
| 389 dict.GetBoolean("lockToFov", &element->lock_to_fov); | 426 dict.GetBoolean("lockToFov", &element->lock_to_fov); |
| 390 ParseRecti(dict, "copyRect", &element->copy_rect); | |
| 391 Parse2DVec3f(dict, "size", &element->size); | 427 Parse2DVec3f(dict, "size", &element->size); |
| 392 ParseVec3f(dict, "scale", &element->scale); | 428 ParseVec3f(dict, "scale", &element->scale); |
| 393 ParseRotationAxisAngle(dict, "rotation", &element->rotation); | 429 ParseRotationAxisAngle(dict, "rotation", &element->rotation); |
| 394 ParseVec3f(dict, "translation", &element->translation); | 430 ParseVec3f(dict, "translation", &element->translation); |
| 395 double opacity; | 431 double opacity; |
| 396 if (dict.GetDouble("opacity", &opacity)) { | 432 if (dict.GetDouble("opacity", &opacity)) { |
| 397 element->opacity = opacity; | 433 element->opacity = opacity; |
| 398 } | 434 } |
| 399 | 435 |
| 400 if (dict.GetBoolean("contentQuad", &element->content_quad)) { | |
| 401 if (element->content_quad) { | |
| 402 CHECK_EQ(content_element_, nullptr); | |
| 403 content_element_ = element; | |
| 404 } else { | |
| 405 if (content_element_ == element) { | |
| 406 content_element_ = nullptr; | |
| 407 } | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 if (dict.GetInteger("xAnchoring", | 436 if (dict.GetInteger("xAnchoring", |
| 412 reinterpret_cast<int*>(&element->x_anchoring))) { | 437 reinterpret_cast<int*>(&element->x_anchoring))) { |
| 413 CHECK_GE(element->parent_id, 0); | 438 CHECK_GE(element->parent_id, 0); |
| 414 } | 439 } |
| 415 if (dict.GetInteger("yAnchoring", | 440 if (dict.GetInteger("yAnchoring", |
| 416 reinterpret_cast<int*>(&element->y_anchoring))) { | 441 reinterpret_cast<int*>(&element->y_anchoring))) { |
| 417 CHECK_GE(element->parent_id, 0); | 442 CHECK_GE(element->parent_id, 0); |
| 418 } | 443 } |
| 444 |
| 445 // Parse the element fill. |
| 446 if (dict.GetInteger("fillType", reinterpret_cast<int*>(&element->fill))) { |
| 447 // If the previous content element has a new filling now make sure this is |
| 448 // tracked correctly. |
| 449 if (content_element_ == element && element->fill != Fill::CONTENT) { |
| 450 content_element_ = nullptr; |
| 451 } |
| 452 |
| 453 switch (element->fill) { |
| 454 case Fill::SPRITE: |
| 455 CHECK(ParseRecti(dict, "copyRect", &element->copy_rect)); |
| 456 break; |
| 457 case Fill::OPAQUE_GRADIENT: |
| 458 CHECK(ParseColorf(dict, "edgeColor", &element->edge_color)); |
| 459 CHECK(ParseColorf(dict, "centerColor", &element->center_color)); |
| 460 break; |
| 461 case Fill::GRID_GRADIENT: |
| 462 CHECK(ParseColorf(dict, "edgeColor", &element->edge_color)); |
| 463 CHECK(ParseColorf(dict, "centerColor", &element->center_color)); |
| 464 CHECK(dict.GetInteger("gridlineCount", &element->gridline_count)); |
| 465 CHECK_GE(element->gridline_count, 0); |
| 466 break; |
| 467 case Fill::CONTENT: |
| 468 CHECK_EQ(content_element_, nullptr); |
| 469 content_element_ = element; |
| 470 break; |
| 471 default: |
| 472 element->fill = Fill::NONE; |
| 473 break; |
| 474 } |
| 475 } |
| 419 } | 476 } |
| 420 | 477 |
| 421 } // namespace vr_shell | 478 } // namespace vr_shell |
| OLD | NEW |