| 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/memory/ptr_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/android/vr_shell/animation.h" | 12 #include "chrome/browser/android/vr_shell/animation.h" |
| 12 #include "chrome/browser/android/vr_shell/easing.h" | 13 #include "chrome/browser/android/vr_shell/easing.h" |
| 13 #include "chrome/browser/android/vr_shell/ui_elements.h" | 14 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 14 | 15 |
| 15 namespace vr_shell { | 16 namespace vr_shell { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Parse an integer to an int or enum value. | 20 // Parse an integer to an int or enum value. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return false; | 99 return false; |
| 99 } | 100 } |
| 100 | 101 |
| 101 std::unique_ptr<easing::Easing> ParseEasing(const base::DictionaryValue& dict) { | 102 std::unique_ptr<easing::Easing> ParseEasing(const base::DictionaryValue& dict) { |
| 102 easing::EasingType easingType; | 103 easing::EasingType easingType; |
| 103 CHECK(ParseInt(dict, "type", &easingType)); | 104 CHECK(ParseInt(dict, "type", &easingType)); |
| 104 std::unique_ptr<easing::Easing> result; | 105 std::unique_ptr<easing::Easing> result; |
| 105 | 106 |
| 106 switch (easingType) { | 107 switch (easingType) { |
| 107 case easing::EasingType::LINEAR: { | 108 case easing::EasingType::LINEAR: { |
| 108 result.reset(new easing::Linear()); | 109 result = base::MakeUnique<easing::Linear>(); |
| 109 break; | 110 break; |
| 110 } | 111 } |
| 111 case easing::EasingType::CUBICBEZIER: { | 112 case easing::EasingType::CUBICBEZIER: { |
| 112 double p1x, p1y, p2x, p2y; | 113 double p1x, p1y, p2x, p2y; |
| 113 CHECK(dict.GetDouble("p1x", &p1x)); | 114 CHECK(dict.GetDouble("p1x", &p1x)); |
| 114 CHECK(dict.GetDouble("p1y", &p1y)); | 115 CHECK(dict.GetDouble("p1y", &p1y)); |
| 115 CHECK(dict.GetDouble("p2x", &p2x)); | 116 CHECK(dict.GetDouble("p2x", &p2x)); |
| 116 CHECK(dict.GetDouble("p2y", &p2y)); | 117 CHECK(dict.GetDouble("p2y", &p2y)); |
| 117 result.reset(new easing::CubicBezier(p1x, p1y, p2x, p2y)); | 118 result = base::MakeUnique<easing::CubicBezier>(p1x, p1y, p2x, p2y); |
| 118 break; | 119 break; |
| 119 } | 120 } |
| 120 case easing::EasingType::EASEIN: { | 121 case easing::EasingType::EASEIN: { |
| 121 double pow; | 122 double pow; |
| 122 CHECK(dict.GetDouble("pow", &pow)); | 123 CHECK(dict.GetDouble("pow", &pow)); |
| 123 result.reset(new easing::EaseIn(pow)); | 124 result = base::MakeUnique<easing::EaseIn>(pow); |
| 124 break; | 125 break; |
| 125 } | 126 } |
| 126 case easing::EasingType::EASEOUT: { | 127 case easing::EasingType::EASEOUT: { |
| 127 double pow; | 128 double pow; |
| 128 CHECK(dict.GetDouble("pow", &pow)); | 129 CHECK(dict.GetDouble("pow", &pow)); |
| 129 result.reset(new easing::EaseOut(pow)); | 130 result = base::MakeUnique<easing::EaseOut>(pow); |
| 131 break; |
| 132 } |
| 133 case easing::EasingType::EASEINOUT: { |
| 134 double pow; |
| 135 CHECK(dict.GetDouble("pow", &pow)); |
| 136 result = base::MakeUnique<easing::EaseInOut>(pow); |
| 130 break; | 137 break; |
| 131 } | 138 } |
| 132 } | 139 } |
| 133 return result; | 140 return result; |
| 134 } | 141 } |
| 135 | 142 |
| 136 void ApplyAnchoring(const ContentRectangle& parent, | 143 void ApplyAnchoring(const ContentRectangle& parent, |
| 137 XAnchoring x_anchoring, | 144 XAnchoring x_anchoring, |
| 138 YAnchoring y_anchoring, | 145 YAnchoring y_anchoring, |
| 139 ReversibleTransform* transform) { | 146 ReversibleTransform* transform) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 CHECK_EQ(element->y_anchoring, YAnchoring::YNONE); | 184 CHECK_EQ(element->y_anchoring, YAnchoring::YNONE); |
| 178 } | 185 } |
| 179 ui_elements_.push_back(std::move(element)); | 186 ui_elements_.push_back(std::move(element)); |
| 180 } | 187 } |
| 181 | 188 |
| 182 void UiScene::AddUiElementFromDict(const base::DictionaryValue& dict) { | 189 void UiScene::AddUiElementFromDict(const base::DictionaryValue& dict) { |
| 183 int id; | 190 int id; |
| 184 CHECK(ParseInt(dict, "id", &id)); | 191 CHECK(ParseInt(dict, "id", &id)); |
| 185 CHECK_EQ(GetUiElementById(id), nullptr); | 192 CHECK_EQ(GetUiElementById(id), nullptr); |
| 186 | 193 |
| 187 std::unique_ptr<ContentRectangle> element(new ContentRectangle); | 194 auto element = base::MakeUnique<ContentRectangle>(); |
| 188 element->id = id; | 195 element->id = id; |
| 189 | 196 |
| 190 ApplyDictToElement(dict, element.get()); | 197 ApplyDictToElement(dict, element.get()); |
| 191 ui_elements_.push_back(std::move(element)); | 198 ui_elements_.push_back(std::move(element)); |
| 192 } | 199 } |
| 193 | 200 |
| 194 void UiScene::UpdateUiElementFromDict(const base::DictionaryValue& dict) { | 201 void UiScene::UpdateUiElementFromDict(const base::DictionaryValue& dict) { |
| 195 int id; | 202 int id; |
| 196 CHECK(ParseInt(dict, "id", &id)); | 203 CHECK(ParseInt(dict, "id", &id)); |
| 197 ContentRectangle* element = GetUiElementById(id); | 204 ContentRectangle* element = GetUiElementById(id); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 dict.GetDictionary("from", &from_dict); | 259 dict.GetDictionary("from", &from_dict); |
| 253 if (from_dict != nullptr) { | 260 if (from_dict != nullptr) { |
| 254 ParseEndpointToFloats(property, *from_dict, &from); | 261 ParseEndpointToFloats(property, *from_dict, &from); |
| 255 } | 262 } |
| 256 | 263 |
| 257 int64_t start = time_in_micro + (start_time_ms * 1000.0); | 264 int64_t start = time_in_micro + (start_time_ms * 1000.0); |
| 258 int64_t duration = duration_ms * 1000.0; | 265 int64_t duration = duration_ms * 1000.0; |
| 259 | 266 |
| 260 ContentRectangle* element = GetUiElementById(element_id); | 267 ContentRectangle* element = GetUiElementById(element_id); |
| 261 CHECK_NE(element, nullptr); | 268 CHECK_NE(element, nullptr); |
| 262 element->animations.emplace_back(std::unique_ptr<Animation>( | 269 element->animations.emplace_back(base::MakeUnique<Animation>( |
| 263 new Animation(animation_id, static_cast<Animation::Property>(property), | 270 animation_id, static_cast<Animation::Property>(property), |
| 264 std::move(easing), from, to, start, duration))); | 271 std::move(easing), from, to, start, duration)); |
| 265 } | 272 } |
| 266 | 273 |
| 267 void UiScene::RemoveAnimation(int element_id, int animation_id) { | 274 void UiScene::RemoveAnimation(int element_id, int animation_id) { |
| 268 ContentRectangle* element = GetUiElementById(element_id); | 275 ContentRectangle* element = GetUiElementById(element_id); |
| 269 CHECK_NE(element, nullptr); | 276 CHECK_NE(element, nullptr); |
| 270 auto& animations = element->animations; | 277 auto& animations = element->animations; |
| 271 for (auto it = animations.begin(); it != animations.end(); ++it) { | 278 for (auto it = animations.begin(); it != animations.end(); ++it) { |
| 272 const Animation& existing_animation = **it; | 279 const Animation& existing_animation = **it; |
| 273 if (existing_animation.id == animation_id) { | 280 if (existing_animation.id == animation_id) { |
| 274 animations.erase(it); | 281 animations.erase(it); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 content_element_ = element; | 456 content_element_ = element; |
| 450 break; | 457 break; |
| 451 default: | 458 default: |
| 452 element->fill = Fill::NONE; | 459 element->fill = Fill::NONE; |
| 453 break; | 460 break; |
| 454 } | 461 } |
| 455 } | 462 } |
| 456 } | 463 } |
| 457 | 464 |
| 458 } // namespace vr_shell | 465 } // namespace vr_shell |
| OLD | NEW |