Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/android/vr_shell/ui_scene.cc

Issue 2668093002: VrShell background implemented in JS. (Closed)
Patch Set: Removed superfluous tests from previous patch set Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 double value; 44 double value;
45 CHECK(item_dict->GetDouble("x", &value)); 45 CHECK(item_dict->GetDouble("x", &value));
46 output->x = value; 46 output->x = value;
47 CHECK(item_dict->GetDouble("y", &value)); 47 CHECK(item_dict->GetDouble("y", &value));
48 output->y = value; 48 output->y = value;
49 CHECK(item_dict->GetDouble("z", &value)); 49 CHECK(item_dict->GetDouble("z", &value));
50 output->z = value; 50 output->z = value;
51 } 51 }
52 } 52 }
53 53
54 void ParseColorf(const base::DictionaryValue& dict,
55 const std::string& key,
56 Colorf* output) {
57 const base::DictionaryValue* item_dict;
58 if (dict.GetDictionary(key, &item_dict)) {
59 double value;
60 CHECK(item_dict->GetDouble("r", &value));
61 output->r = value;
62 CHECK(item_dict->GetDouble("g", &value));
63 output->g = value;
64 CHECK(item_dict->GetDouble("b", &value));
65 output->b = value;
66 CHECK(item_dict->GetDouble("a", &value));
67 output->a = value;
68 }
69 }
70
54 void ParseRotationAxisAngle(const base::DictionaryValue& dict, 71 void ParseRotationAxisAngle(const base::DictionaryValue& dict,
55 const std::string& key, RotationAxisAngle* output) { 72 const std::string& key, RotationAxisAngle* output) {
56 const base::DictionaryValue* item_dict; 73 const base::DictionaryValue* item_dict;
57 if (dict.GetDictionary(key, &item_dict)) { 74 if (dict.GetDictionary(key, &item_dict)) {
58 double value; 75 double value;
59 CHECK(item_dict->GetDouble("x", &value)); 76 CHECK(item_dict->GetDouble("x", &value));
60 output->x = value; 77 output->x = value;
61 CHECK(item_dict->GetDouble("y", &value)); 78 CHECK(item_dict->GetDouble("y", &value));
62 output->y = value; 79 output->y = value;
63 CHECK(item_dict->GetDouble("z", &value)); 80 CHECK(item_dict->GetDouble("z", &value));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 int id; 215 int id;
199 CHECK(dict.GetInteger("id", &id)); 216 CHECK(dict.GetInteger("id", &id));
200 ContentRectangle* element = GetUiElementById(id); 217 ContentRectangle* element = GetUiElementById(id);
201 CHECK_NE(element, nullptr); 218 CHECK_NE(element, nullptr);
202 ApplyDictToElement(dict, element); 219 ApplyDictToElement(dict, element);
203 } 220 }
204 221
205 void UiScene::RemoveUiElement(int element_id) { 222 void UiScene::RemoveUiElement(int element_id) {
206 for (auto it = ui_elements_.begin(); it != ui_elements_.end(); ++it) { 223 for (auto it = ui_elements_.begin(); it != ui_elements_.end(); ++it) {
207 if ((*it)->id == element_id) { 224 if ((*it)->id == element_id) {
208 if ((*it)->content_quad) { 225 if ((*it)->fill == Fill::CONTENT) {
209 content_element_ = nullptr; 226 content_element_ = nullptr;
210 } 227 }
211 ui_elements_.erase(it); 228 ui_elements_.erase(it);
212 return; 229 return;
213 } 230 }
214 } 231 }
215 } 232 }
216 233
217 void UiScene::AddAnimation(int element_id, 234 void UiScene::AddAnimation(int element_id,
218 std::unique_ptr<Animation>& animation) { 235 std::unique_ptr<Animation>& animation) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 int parent_id; 397 int parent_id;
381 if (dict.GetInteger("parentId", &parent_id)) { 398 if (dict.GetInteger("parentId", &parent_id)) {
382 CHECK_GE(parent_id, 0); 399 CHECK_GE(parent_id, 0);
383 CHECK_NE(GetUiElementById(parent_id), nullptr); 400 CHECK_NE(GetUiElementById(parent_id), nullptr);
384 element->parent_id = parent_id; 401 element->parent_id = parent_id;
385 } 402 }
386 403
387 dict.GetBoolean("visible", &element->visible); 404 dict.GetBoolean("visible", &element->visible);
388 dict.GetBoolean("hitTestable", &element->hit_testable); 405 dict.GetBoolean("hitTestable", &element->hit_testable);
389 dict.GetBoolean("lockToFov", &element->lock_to_fov); 406 dict.GetBoolean("lockToFov", &element->lock_to_fov);
390 ParseRecti(dict, "copyRect", &element->copy_rect);
391 Parse2DVec3f(dict, "size", &element->size); 407 Parse2DVec3f(dict, "size", &element->size);
392 ParseVec3f(dict, "scale", &element->scale); 408 ParseVec3f(dict, "scale", &element->scale);
393 ParseRotationAxisAngle(dict, "rotation", &element->rotation); 409 ParseRotationAxisAngle(dict, "rotation", &element->rotation);
394 ParseVec3f(dict, "translation", &element->translation); 410 ParseVec3f(dict, "translation", &element->translation);
395 double opacity; 411 double opacity;
396 if (dict.GetDouble("opacity", &opacity)) { 412 if (dict.GetDouble("opacity", &opacity)) {
397 element->opacity = opacity; 413 element->opacity = opacity;
398 } 414 }
399 415
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", 416 if (dict.GetInteger("xAnchoring",
412 reinterpret_cast<int*>(&element->x_anchoring))) { 417 reinterpret_cast<int*>(&element->x_anchoring))) {
413 CHECK_GE(element->parent_id, 0); 418 CHECK_GE(element->parent_id, 0);
414 } 419 }
415 if (dict.GetInteger("yAnchoring", 420 if (dict.GetInteger("yAnchoring",
416 reinterpret_cast<int*>(&element->y_anchoring))) { 421 reinterpret_cast<int*>(&element->y_anchoring))) {
417 CHECK_GE(element->parent_id, 0); 422 CHECK_GE(element->parent_id, 0);
418 } 423 }
424
425 // Parse the element fill.
426 if (dict.GetInteger("fillType", reinterpret_cast<int*>(&element->fill))) {
427 // If the previous content element has a new filling now make sure this is
428 // tracked correctly.
429 if (content_element_ == element && element->fill != Fill::CONTENT) {
430 content_element_ = nullptr;
431 }
432
433 switch (element->fill) {
434 case Fill::SPRITE:
435 ParseRecti(dict, "copyRect", &element->copy_rect);
436 break;
437 case Fill::OPAQUE_GRADIENT:
438 ParseColorf(dict, "edgeColor", &element->edge_color);
439 ParseColorf(dict, "centerColor", &element->center_color);
440 break;
441 case Fill::GRID_GRADIENT:
442 ParseColorf(dict, "edgeColor", &element->edge_color);
443 ParseColorf(dict, "centerColor", &element->center_color);
444 int value;
445 dict.GetInteger("tileNumber", &value);
cjgrant 2017/02/02 14:48:25 - This code is setting tile_number to a random val
tiborg1 2017/02/02 16:52:27 Good call! I changed tile number to unsigned since
cjgrant 2017/02/03 15:58:29 We should also check that the read from the dictio
446 element->tile_number = value;
447 break;
448 case Fill::CONTENT:
449 CHECK_EQ(content_element_, nullptr);
450 content_element_ = element;
451 break;
452 default:
453 element->fill = Fill::NONE;
454 break;
455 }
456 }
419 } 457 }
420 458
421 } // namespace vr_shell 459 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698