Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/android/vr_shell/animation.h" | 11 #include "chrome/browser/android/vr_shell/animation.h" |
| 12 #include "chrome/browser/android/vr_shell/easing.h" | 12 #include "chrome/browser/android/vr_shell/easing.h" |
| 13 #include "chrome/browser/android/vr_shell/ui_elements.h" | 13 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 14 | 14 |
| 15 namespace vr_shell { | 15 namespace vr_shell { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 bool ParseNumber(const base::DictionaryValue& dict, | |
| 20 const std::string& key, | |
| 21 float* output) { | |
| 22 double number; | |
| 23 if (!dict.GetDouble(key, &number)) { | |
| 24 return false; | |
| 25 } | |
| 26 *output = number; | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 19 bool ParseRecti(const base::DictionaryValue& dict, | 30 bool ParseRecti(const base::DictionaryValue& dict, |
| 20 const std::string& key, | 31 const std::string& key, |
| 21 Recti* output) { | 32 Recti* output) { |
| 22 const base::DictionaryValue* item_dict; | 33 const base::DictionaryValue* item_dict; |
| 23 if (dict.GetDictionary(key, &item_dict)) { | 34 if (dict.GetDictionary(key, &item_dict)) { |
| 24 CHECK(item_dict->GetInteger("x", &output->x)); | 35 CHECK(item_dict->GetInteger("x", &output->x)); |
| 25 CHECK(item_dict->GetInteger("y", &output->y)); | 36 CHECK(item_dict->GetInteger("y", &output->y)); |
| 26 CHECK(item_dict->GetInteger("width", &output->width)); | 37 CHECK(item_dict->GetInteger("width", &output->width)); |
| 27 CHECK(item_dict->GetInteger("height", &output->height)); | 38 CHECK(item_dict->GetInteger("height", &output->height)); |
| 28 return true; | 39 return true; |
| 29 } else { | 40 } else { |
| 30 return false; | 41 return false; |
| 31 } | 42 } |
| 32 } | 43 } |
| 33 | 44 |
| 45 #if 0 | |
| 34 bool Parse2DVec3f(const base::DictionaryValue& dict, | 46 bool Parse2DVec3f(const base::DictionaryValue& dict, |
| 35 const std::string& key, | 47 const std::string& key, |
| 36 gvr::Vec3f* output) { | 48 gvr::Vec3f* output) { |
| 37 const base::DictionaryValue* item_dict; | 49 const base::DictionaryValue* item_dict; |
| 38 if (dict.GetDictionary(key, &item_dict)) { | 50 if (dict.GetDictionary(key, &item_dict)) { |
| 39 double value; | 51 double value; |
| 40 CHECK(item_dict->GetDouble("x", &value)); | 52 CHECK(item_dict->GetDouble("x", &value)); |
| 41 output->x = value; | 53 output->x = value; |
| 42 CHECK(item_dict->GetDouble("y", &value)); | 54 CHECK(item_dict->GetDouble("y", &value)); |
| 43 output->y = value; | 55 output->y = value; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 58 output->x = value; | 70 output->x = value; |
| 59 CHECK(item_dict->GetDouble("y", &value)); | 71 CHECK(item_dict->GetDouble("y", &value)); |
| 60 output->y = value; | 72 output->y = value; |
| 61 CHECK(item_dict->GetDouble("z", &value)); | 73 CHECK(item_dict->GetDouble("z", &value)); |
| 62 output->z = value; | 74 output->z = value; |
| 63 return true; | 75 return true; |
| 64 } else { | 76 } else { |
| 65 return false; | 77 return false; |
| 66 } | 78 } |
| 67 } | 79 } |
| 80 #endif | |
| 68 | 81 |
| 69 bool ParseColorf(const base::DictionaryValue& dict, | 82 bool ParseColorf(const base::DictionaryValue& dict, |
| 70 const std::string& key, | 83 const std::string& key, |
| 71 Colorf* output) { | 84 Colorf* output) { |
| 72 const base::DictionaryValue* item_dict; | 85 const base::DictionaryValue* item_dict; |
| 73 if (dict.GetDictionary(key, &item_dict)) { | 86 if (dict.GetDictionary(key, &item_dict)) { |
| 74 double value; | 87 double value; |
| 75 CHECK(item_dict->GetDouble("r", &value)); | 88 CHECK(item_dict->GetDouble("r", &value)); |
| 76 output->r = value; | 89 output->r = value; |
| 77 CHECK(item_dict->GetDouble("g", &value)); | 90 CHECK(item_dict->GetDouble("g", &value)); |
| 78 output->g = value; | 91 output->g = value; |
| 79 CHECK(item_dict->GetDouble("b", &value)); | 92 CHECK(item_dict->GetDouble("b", &value)); |
| 80 output->b = value; | 93 output->b = value; |
| 81 CHECK(item_dict->GetDouble("a", &value)); | 94 CHECK(item_dict->GetDouble("a", &value)); |
| 82 output->a = value; | 95 output->a = value; |
| 83 return true; | 96 return true; |
| 84 } else { | 97 } else { |
| 85 return false; | 98 return false; |
| 86 } | 99 } |
| 87 } | 100 } |
| 88 | 101 |
| 102 #if 0 | |
| 89 bool ParseRotationAxisAngle(const base::DictionaryValue& dict, | 103 bool ParseRotationAxisAngle(const base::DictionaryValue& dict, |
| 90 const std::string& key, | 104 const std::string& key, |
| 91 RotationAxisAngle* output) { | 105 RotationAxisAngle* output) { |
| 92 const base::DictionaryValue* item_dict; | 106 const base::DictionaryValue* item_dict; |
| 93 if (dict.GetDictionary(key, &item_dict)) { | 107 if (dict.GetDictionary(key, &item_dict)) { |
| 94 double value; | 108 double value; |
| 95 CHECK(item_dict->GetDouble("x", &value)); | 109 CHECK(item_dict->GetDouble("x", &value)); |
| 96 output->x = value; | 110 output->x = value; |
| 97 CHECK(item_dict->GetDouble("y", &value)); | 111 CHECK(item_dict->GetDouble("y", &value)); |
| 98 output->y = value; | 112 output->y = value; |
| 99 CHECK(item_dict->GetDouble("z", &value)); | 113 CHECK(item_dict->GetDouble("z", &value)); |
| 100 output->z = value; | 114 output->z = value; |
| 101 CHECK(item_dict->GetDouble("a", &value)); | 115 CHECK(item_dict->GetDouble("a", &value)); |
| 102 output->angle = value; | 116 output->angle = value; |
| 103 return true; | 117 return true; |
| 104 } else { | 118 } else { |
| 105 return false; | 119 return false; |
| 106 } | 120 } |
| 107 } | 121 } |
| 122 #endif | |
| 108 | 123 |
| 109 void ParseFloats(const base::DictionaryValue& dict, | 124 void ParseFloats(const base::DictionaryValue& dict, |
| 110 const std::vector<std::string>& keys, | 125 const std::vector<std::string>& keys, |
| 111 std::vector<float>* vec) { | 126 std::vector<float>* vec) { |
| 112 for (const auto& key : keys) { | 127 for (const auto& key : keys) { |
| 113 double value; | 128 double value; |
| 114 CHECK(dict.GetDouble(key, &value)) << "parsing tag " << key; | 129 CHECK(dict.GetDouble(key, &value)) << "parsing tag " << key; |
| 115 vec->push_back(value); | 130 vec->push_back(value); |
| 116 } | 131 } |
| 117 } | 132 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 CHECK(parent != nullptr); | 437 CHECK(parent != nullptr); |
| 423 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, | 438 ApplyAnchoring(*parent, element.x_anchoring, element.y_anchoring, |
| 424 transform); | 439 transform); |
| 425 ApplyRecursiveTransforms(*parent, transform, opacity); | 440 ApplyRecursiveTransforms(*parent, transform, opacity); |
| 426 } | 441 } |
| 427 } | 442 } |
| 428 | 443 |
| 429 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, | 444 void UiScene::ApplyDictToElement(const base::DictionaryValue& dict, |
| 430 ContentRectangle *element) { | 445 ContentRectangle *element) { |
| 431 int parent_id; | 446 int parent_id; |
| 447 //const base::DictionaryValue* item_dict; | |
| 448 | |
| 432 if (dict.GetInteger("parentId", &parent_id)) { | 449 if (dict.GetInteger("parentId", &parent_id)) { |
| 433 CHECK_GE(parent_id, 0); | 450 CHECK_GE(parent_id, 0); |
| 434 CHECK_NE(GetUiElementById(parent_id), nullptr); | 451 CHECK_NE(GetUiElementById(parent_id), nullptr); |
| 435 element->parent_id = parent_id; | 452 element->parent_id = parent_id; |
| 436 } | 453 } |
| 437 | 454 |
| 438 dict.GetBoolean("visible", &element->visible); | 455 dict.GetBoolean("visible", &element->visible); |
| 439 dict.GetBoolean("hitTestable", &element->hit_testable); | 456 dict.GetBoolean("hitTestable", &element->hit_testable); |
| 440 dict.GetBoolean("lockToFov", &element->lock_to_fov); | 457 dict.GetBoolean("lockToFov", &element->lock_to_fov); |
| 441 Parse2DVec3f(dict, "size", &element->size); | |
| 442 ParseVec3f(dict, "scale", &element->scale); | |
| 443 ParseRotationAxisAngle(dict, "rotation", &element->rotation); | |
| 444 ParseVec3f(dict, "translation", &element->translation); | |
| 445 double opacity; | |
| 446 if (dict.GetDouble("opacity", &opacity)) { | |
| 447 element->opacity = opacity; | |
| 448 } | |
| 449 | 458 |
| 459 ParseNumber(dict, "sizeX", &element->size.x); | |
|
cjgrant
2017/02/15 16:34:27
Independent of CSS custom properties, I'd like to
tiborg
2017/02/15 18:36:11
+1, this is a good idea.
cjgrant
2017/03/03 15:11:07
For the record, this change landed in ToT, and is
| |
| 460 ParseNumber(dict, "sizeY", &element->size.y); | |
| 461 ParseNumber(dict, "scaleX", &element->scale.x); | |
| 462 ParseNumber(dict, "scaleY", &element->scale.y); | |
| 463 ParseNumber(dict, "scaleZ", &element->scale.z); | |
| 464 ParseNumber(dict, "rotationX", &element->rotation.x); | |
| 465 ParseNumber(dict, "rotationY", &element->rotation.y); | |
| 466 ParseNumber(dict, "rotationZ", &element->rotation.z); | |
| 467 ParseNumber(dict, "rotationAngle", &element->rotation.angle); | |
| 468 ParseNumber(dict, "translationX", &element->translation.x); | |
| 469 ParseNumber(dict, "translationY", &element->translation.y); | |
| 470 ParseNumber(dict, "translationZ", &element->translation.z); | |
| 471 | |
| 472 ParseNumber(dict, "opacity", &element->opacity); | |
| 450 if (dict.GetInteger("xAnchoring", | 473 if (dict.GetInteger("xAnchoring", |
| 451 reinterpret_cast<int*>(&element->x_anchoring))) { | 474 reinterpret_cast<int*>(&element->x_anchoring))) { |
| 452 CHECK_GE(element->parent_id, 0); | 475 CHECK_GE(element->parent_id, 0); |
| 453 } | 476 } |
| 454 if (dict.GetInteger("yAnchoring", | 477 if (dict.GetInteger("yAnchoring", |
| 455 reinterpret_cast<int*>(&element->y_anchoring))) { | 478 reinterpret_cast<int*>(&element->y_anchoring))) { |
| 456 CHECK_GE(element->parent_id, 0); | 479 CHECK_GE(element->parent_id, 0); |
| 457 } | 480 } |
| 458 | 481 |
| 459 // Parse the element fill. | 482 // Parse the element fill. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 483 content_element_ = element; | 506 content_element_ = element; |
| 484 break; | 507 break; |
| 485 default: | 508 default: |
| 486 element->fill = Fill::NONE; | 509 element->fill = Fill::NONE; |
| 487 break; | 510 break; |
| 488 } | 511 } |
| 489 } | 512 } |
| 490 } | 513 } |
| 491 | 514 |
| 492 } // namespace vr_shell | 515 } // namespace vr_shell |
| OLD | NEW |