| 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" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 std::unique_ptr<easing::Easing> ParseEasing( | 145 std::unique_ptr<easing::Easing> ParseEasing( |
| 146 const base::DictionaryValue& dict) { | 146 const base::DictionaryValue& dict) { |
| 147 easing::EasingType easingType; | 147 easing::EasingType easingType; |
| 148 CHECK(dict.GetInteger("type", reinterpret_cast<int*>(&easingType))); | 148 CHECK(dict.GetInteger("type", reinterpret_cast<int*>(&easingType))); |
| 149 std::unique_ptr<easing::Easing> result; | 149 std::unique_ptr<easing::Easing> result; |
| 150 | 150 |
| 151 switch (easingType) { | 151 switch (easingType) { |
| 152 case easing::EasingType::LINEAR: { | 152 case easing::EasingType::LINEAR: { |
| 153 result.reset(new easing::Linear()); | 153 result = base::MakeUnique<easing::Linear>(); |
| 154 break; | 154 break; |
| 155 } | 155 } |
| 156 case easing::EasingType::CUBICBEZIER: { | 156 case easing::EasingType::CUBICBEZIER: { |
| 157 double p1x, p1y, p2x, p2y; | 157 double p1x, p1y, p2x, p2y; |
| 158 CHECK(dict.GetDouble("p1x", &p1x)); | 158 CHECK(dict.GetDouble("p1x", &p1x)); |
| 159 CHECK(dict.GetDouble("p1y", &p1y)); | 159 CHECK(dict.GetDouble("p1y", &p1y)); |
| 160 CHECK(dict.GetDouble("p2x", &p2x)); | 160 CHECK(dict.GetDouble("p2x", &p2x)); |
| 161 CHECK(dict.GetDouble("p2y", &p2y)); | 161 CHECK(dict.GetDouble("p2y", &p2y)); |
| 162 result.reset(new easing::CubicBezier(p1x, p1y, p2x, p2y)); | 162 result = base::MakeUnique<easing::CubicBezier>(p1x, p1y, p2x, p2y); |
| 163 break; | 163 break; |
| 164 } | 164 } |
| 165 case easing::EasingType::EASEIN: { | 165 case easing::EasingType::EASEIN: { |
| 166 double pow; | 166 double pow; |
| 167 CHECK(dict.GetDouble("pow", &pow)); | 167 CHECK(dict.GetDouble("pow", &pow)); |
| 168 result.reset(new easing::EaseIn(pow)); | 168 result = base::MakeUnique<easing::EaseIn>(pow); |
| 169 break; | 169 break; |
| 170 } | 170 } |
| 171 case easing::EasingType::EASEOUT: { | 171 case easing::EasingType::EASEOUT: { |
| 172 double pow; | 172 double pow; |
| 173 CHECK(dict.GetDouble("pow", &pow)); | 173 CHECK(dict.GetDouble("pow", &pow)); |
| 174 result.reset(new easing::EaseOut(pow)); | 174 result = base::MakeUnique<easing::EaseOut>(pow); |
| 175 break; |
| 176 } |
| 177 case easing::EasingType::EASEINOUT: { |
| 178 double pow; |
| 179 CHECK(dict.GetDouble("pow", &pow)); |
| 180 result = base::MakeUnique<easing::EaseInOut>(pow); |
| 175 break; | 181 break; |
| 176 } | 182 } |
| 177 } | 183 } |
| 178 return result; | 184 return result; |
| 179 } | 185 } |
| 180 | 186 |
| 181 void ApplyAnchoring(const ContentRectangle& parent, XAnchoring x_anchoring, | 187 void ApplyAnchoring(const ContentRectangle& parent, XAnchoring x_anchoring, |
| 182 YAnchoring y_anchoring, ReversibleTransform* transform) { | 188 YAnchoring y_anchoring, ReversibleTransform* transform) { |
| 183 // To anchor a child, use the parent's size to find its edge. | 189 // To anchor a child, use the parent's size to find its edge. |
| 184 float x_offset; | 190 float x_offset; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 CHECK_EQ(element->y_anchoring, YAnchoring::YNONE); | 226 CHECK_EQ(element->y_anchoring, YAnchoring::YNONE); |
| 221 } | 227 } |
| 222 ui_elements_.push_back(std::move(element)); | 228 ui_elements_.push_back(std::move(element)); |
| 223 } | 229 } |
| 224 | 230 |
| 225 void UiScene::AddUiElementFromDict(const base::DictionaryValue& dict) { | 231 void UiScene::AddUiElementFromDict(const base::DictionaryValue& dict) { |
| 226 int id; | 232 int id; |
| 227 CHECK(dict.GetInteger("id", &id)); | 233 CHECK(dict.GetInteger("id", &id)); |
| 228 CHECK_EQ(GetUiElementById(id), nullptr); | 234 CHECK_EQ(GetUiElementById(id), nullptr); |
| 229 | 235 |
| 230 std::unique_ptr<ContentRectangle> element(new ContentRectangle); | 236 auto element = base::MakeUnique<ContentRectangle>(); |
| 231 element->id = id; | 237 element->id = id; |
| 232 | 238 |
| 233 ApplyDictToElement(dict, element.get()); | 239 ApplyDictToElement(dict, element.get()); |
| 234 ui_elements_.push_back(std::move(element)); | 240 ui_elements_.push_back(std::move(element)); |
| 235 } | 241 } |
| 236 | 242 |
| 237 void UiScene::UpdateUiElementFromDict(const base::DictionaryValue& dict) { | 243 void UiScene::UpdateUiElementFromDict(const base::DictionaryValue& dict) { |
| 238 int id; | 244 int id; |
| 239 CHECK(dict.GetInteger("id", &id)); | 245 CHECK(dict.GetInteger("id", &id)); |
| 240 ContentRectangle* element = GetUiElementById(id); | 246 ContentRectangle* element = GetUiElementById(id); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 dict.GetDictionary("from", &from_dict); | 301 dict.GetDictionary("from", &from_dict); |
| 296 if (from_dict != nullptr) { | 302 if (from_dict != nullptr) { |
| 297 ParseEndpointToFloats(property, *from_dict, &from); | 303 ParseEndpointToFloats(property, *from_dict, &from); |
| 298 } | 304 } |
| 299 | 305 |
| 300 int64_t start = time_in_micro + (start_time_ms * 1000.0); | 306 int64_t start = time_in_micro + (start_time_ms * 1000.0); |
| 301 int64_t duration = duration_ms * 1000.0; | 307 int64_t duration = duration_ms * 1000.0; |
| 302 | 308 |
| 303 ContentRectangle* element = GetUiElementById(element_id); | 309 ContentRectangle* element = GetUiElementById(element_id); |
| 304 CHECK_NE(element, nullptr); | 310 CHECK_NE(element, nullptr); |
| 305 element->animations.emplace_back(std::unique_ptr<Animation>( | 311 element->animations.emplace_back(base::MakeUnique<Animation>( |
| 306 new Animation( | 312 animation_id, static_cast<Animation::Property>(property), |
| 307 animation_id, static_cast<Animation::Property>(property), | 313 std::move(easing), from, to, start, duration)); |
| 308 std::move(easing), from, to, start, duration))); | |
| 309 } | 314 } |
| 310 | 315 |
| 311 void UiScene::RemoveAnimation(int element_id, int animation_id) { | 316 void UiScene::RemoveAnimation(int element_id, int animation_id) { |
| 312 ContentRectangle* element = GetUiElementById(element_id); | 317 ContentRectangle* element = GetUiElementById(element_id); |
| 313 CHECK_NE(element, nullptr); | 318 CHECK_NE(element, nullptr); |
| 314 auto& animations = element->animations; | 319 auto& animations = element->animations; |
| 315 for (auto it = animations.begin(); it != animations.end(); ++it) { | 320 for (auto it = animations.begin(); it != animations.end(); ++it) { |
| 316 const Animation& existing_animation = **it; | 321 const Animation& existing_animation = **it; |
| 317 if (existing_animation.id == animation_id) { | 322 if (existing_animation.id == animation_id) { |
| 318 animations.erase(it); | 323 animations.erase(it); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 content_element_ = element; | 488 content_element_ = element; |
| 484 break; | 489 break; |
| 485 default: | 490 default: |
| 486 element->fill = Fill::NONE; | 491 element->fill = Fill::NONE; |
| 487 break; | 492 break; |
| 488 } | 493 } |
| 489 } | 494 } |
| 490 } | 495 } |
| 491 | 496 |
| 492 } // namespace vr_shell | 497 } // namespace vr_shell |
| OLD | NEW |