| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_manager.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/android/vr_shell/ui_element.h" | 8 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_elements/textured_element.h" |
| 11 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" |
| 12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_scene.h" | 13 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 10 | 14 |
| 11 namespace vr_shell { | 15 namespace vr_shell { |
| 12 | 16 |
| 13 namespace { | 17 namespace { |
| 14 | 18 |
| 15 static constexpr int kWarningTimeoutSeconds = 30; | 19 static constexpr int kWarningTimeoutSeconds = 30; |
| 16 static constexpr float kWarningDistance = 0.7; | 20 static constexpr float kWarningDistance = 0.7; |
| 17 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; | 21 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; |
| 18 | 22 |
| 19 } // namespace | 23 } // namespace |
| 20 | 24 |
| 21 UiSceneManager::UiSceneManager(UiScene* scene) | 25 UiSceneManager::UiSceneManager(UiScene* scene) |
| 22 : scene_(scene), weak_ptr_factory_(this) { | 26 : scene_(scene), weak_ptr_factory_(this) { |
| 23 std::unique_ptr<UiElement> element; | 27 std::unique_ptr<UiElement> element; |
| 24 | 28 |
| 25 // For now, use an ID range that does not conflict with the HTML UI. | 29 // For now, use an ID range that does not conflict with the HTML UI. |
| 26 int id = 1000; | 30 int id = 1000; |
| 27 | 31 |
| 28 // Permanent WebVR security warning. | 32 // Permanent WebVR security warning. |
| 29 element = base::MakeUnique<UiElement>(); | 33 // TODO(mthiesse): Programatically compute the proper texture size for these |
| 34 // textured UI elements. |
| 35 element = base::MakeUnique<PermanentSecurityWarning>(512); |
| 30 element->id = id++; | 36 element->id = id++; |
| 31 element->name = "Permanent security warning"; | 37 element->name = "Permanent security warning"; |
| 32 // TODO(cjgrant): Map to Skia-generated texture with correct size. | |
| 33 // element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 34 // element->edge_color = {128, 128, 128, 0.5}; | |
| 35 // element->center_color = {128, 128, 128, 0.5}; | |
| 36 element->fill = vr_shell::Fill::NONE; | 38 element->fill = vr_shell::Fill::NONE; |
| 37 element->size = {0.226f, 0.078f, 1}; | 39 element->size = {0.226f, 0.078f, 1}; |
| 38 element->scale = {kWarningDistance, kWarningDistance, 1}; | 40 element->scale = {kWarningDistance, kWarningDistance, 1}; |
| 39 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), | 41 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), |
| 40 -kWarningDistance * cos(kWarningAngleRadians)}; | 42 -kWarningDistance * cos(kWarningAngleRadians)}; |
| 41 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; | 43 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; |
| 42 element->visible = false; | 44 element->visible = false; |
| 43 element->hit_testable = false; | 45 element->hit_testable = false; |
| 44 element->lock_to_fov = true; | 46 element->lock_to_fov = true; |
| 45 permanent_security_warning_ = element.get(); | 47 permanent_security_warning_ = element.get(); |
| 46 scene_->AddUiElement(std::move(element)); | 48 scene_->AddUiElement(std::move(element)); |
| 47 | 49 |
| 48 // Transient WebVR security warning. | 50 // Transient WebVR security warning. |
| 49 element = base::MakeUnique<UiElement>(); | 51 element = base::MakeUnique<TransientSecurityWarning>(1024); |
| 50 element->id = id++; | 52 element->id = id++; |
| 51 element->name = "Transient security warning"; | 53 element->name = "Transient security warning"; |
| 52 // TODO(cjgrant): Map to Skia-generated texture with correct size. | |
| 53 // element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 54 // element->edge_color = {128, 128, 128, 0.5}; | |
| 55 // element->center_color = {128, 128, 128, 0.5}; | |
| 56 element->fill = vr_shell::Fill::NONE; | 54 element->fill = vr_shell::Fill::NONE; |
| 57 element->size = {0.512f, 0.160f, 1}; | 55 element->size = {0.512f, 0.160f, 1}; |
| 58 element->scale = {kWarningDistance, kWarningDistance, 1}; | 56 element->scale = {kWarningDistance, kWarningDistance, 1}; |
| 59 element->translation = {0, 0, -kWarningDistance}; | 57 element->translation = {0, 0, -kWarningDistance}; |
| 60 element->visible = false; | 58 element->visible = false; |
| 61 element->hit_testable = false; | 59 element->hit_testable = false; |
| 62 element->lock_to_fov = true; | 60 element->lock_to_fov = true; |
| 63 transient_security_warning_ = element.get(); | 61 transient_security_warning_ = element.get(); |
| 64 scene_->AddUiElement(std::move(element)); | 62 scene_->AddUiElement(std::move(element)); |
| 65 | 63 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } else { | 101 } else { |
| 104 security_warning_timer_.Stop(); | 102 security_warning_timer_.Stop(); |
| 105 } | 103 } |
| 106 } | 104 } |
| 107 | 105 |
| 108 void UiSceneManager::OnSecurityWarningTimer() { | 106 void UiSceneManager::OnSecurityWarningTimer() { |
| 109 transient_security_warning_->visible = false; | 107 transient_security_warning_->visible = false; |
| 110 } | 108 } |
| 111 | 109 |
| 112 } // namespace vr_shell | 110 } // namespace vr_shell |
| OLD | NEW |