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/textures/ui_texture.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" | 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" | 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" | 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" | 12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
13 #include "chrome/browser/android/vr_shell/ui_scene.h" | 13 #include "chrome/browser/android/vr_shell/ui_scene.h" |
14 | 14 |
15 namespace vr_shell { | 15 namespace vr_shell { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 static constexpr int kWarningTimeoutSeconds = 30; | 19 static constexpr int kWarningTimeoutSeconds = 30; |
20 static constexpr float kWarningDistance = 0.7; | 20 static constexpr float kWarningDistance = 0.7; |
21 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; | 21 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; |
22 | 22 |
| 23 static constexpr float kPermanentWarningHeight = 0.226; |
| 24 static constexpr float kPermanentWarningWidth = 0.078; |
| 25 static constexpr float kTransientWarningHeight = 0.512; |
| 26 static constexpr float kTransientWarningWidth = 0.160; |
| 27 |
| 28 static constexpr float kContentHeight = 2.4; |
| 29 static constexpr float kContentWidth = 1.6; |
| 30 static constexpr float kContentDistance = 2.5; |
| 31 static constexpr float kContentVerticalOffset = -0.26; |
| 32 |
23 } // namespace | 33 } // namespace |
24 | 34 |
25 UiSceneManager::UiSceneManager(UiScene* scene) | 35 UiSceneManager::UiSceneManager(UiScene* scene) |
26 : scene_(scene), weak_ptr_factory_(this) { | 36 : scene_(scene), weak_ptr_factory_(this) { |
27 std::unique_ptr<UiElement> element; | 37 std::unique_ptr<UiElement> element; |
28 | 38 |
29 // For now, use an ID range that does not conflict with the HTML UI. | 39 // For now, use an ID range that does not conflict with the HTML UI. |
30 int id = 1000; | 40 int id = 1000; |
31 | 41 |
32 // Permanent WebVR security warning. | 42 // Permanent WebVR security warning. |
33 // TODO(mthiesse): Programatically compute the proper texture size for these | 43 // TODO(mthiesse): Programatically compute the proper texture size for these |
34 // textured UI elements. | 44 // textured UI elements. |
35 element = base::MakeUnique<PermanentSecurityWarning>(512); | 45 element = base::MakeUnique<PermanentSecurityWarning>(512); |
36 element->id = id++; | 46 element->id = id++; |
37 element->name = "Permanent security warning"; | 47 element->name = "Permanent security warning"; |
38 element->fill = vr_shell::Fill::NONE; | 48 element->fill = vr_shell::Fill::NONE; |
39 element->size = {0.226f, 0.078f, 1}; | 49 element->size = {kPermanentWarningWidth, kPermanentWarningHeight, 1}; |
40 element->scale = {kWarningDistance, kWarningDistance, 1}; | 50 element->scale = {kWarningDistance, kWarningDistance, 1}; |
41 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), | 51 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), |
42 -kWarningDistance * cos(kWarningAngleRadians)}; | 52 -kWarningDistance * cos(kWarningAngleRadians)}; |
43 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; | 53 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; |
44 element->visible = false; | 54 element->visible = false; |
45 element->hit_testable = false; | 55 element->hit_testable = false; |
46 element->lock_to_fov = true; | 56 element->lock_to_fov = true; |
47 permanent_security_warning_ = element.get(); | 57 permanent_security_warning_ = element.get(); |
48 scene_->AddUiElement(std::move(element)); | 58 scene_->AddUiElement(std::move(element)); |
49 | 59 |
50 // Transient WebVR security warning. | 60 // Transient WebVR security warning. |
51 element = base::MakeUnique<TransientSecurityWarning>(1024); | 61 element = base::MakeUnique<TransientSecurityWarning>(1024); |
52 element->id = id++; | 62 element->id = id++; |
53 element->name = "Transient security warning"; | 63 element->name = "Transient security warning"; |
54 element->fill = vr_shell::Fill::NONE; | 64 element->fill = vr_shell::Fill::NONE; |
55 element->size = {0.512f, 0.160f, 1}; | 65 element->size = {kTransientWarningWidth, kTransientWarningHeight, 1}; |
56 element->scale = {kWarningDistance, kWarningDistance, 1}; | 66 element->scale = {kWarningDistance, kWarningDistance, 1}; |
57 element->translation = {0, 0, -kWarningDistance}; | 67 element->translation = {0, 0, -kWarningDistance}; |
58 element->visible = false; | 68 element->visible = false; |
59 element->hit_testable = false; | 69 element->hit_testable = false; |
60 element->lock_to_fov = true; | 70 element->lock_to_fov = true; |
61 transient_security_warning_ = element.get(); | 71 transient_security_warning_ = element.get(); |
62 scene_->AddUiElement(std::move(element)); | 72 scene_->AddUiElement(std::move(element)); |
63 | 73 |
64 // Main web content quad. | 74 // Main web content quad. |
65 element = base::MakeUnique<UiElement>(); | 75 element = base::MakeUnique<UiElement>(); |
66 element->id = id++; | 76 element->id = id++; |
67 element->name = "Content"; | 77 element->name = "Content"; |
68 element->fill = vr_shell::Fill::CONTENT; | 78 element->fill = vr_shell::Fill::CONTENT; |
69 element->size = {2.4f, 1.6f, 1}; | 79 element->size = {kContentWidth, kContentHeight, 1}; |
70 element->translation = {0, -0.1f, -2.5f}; | 80 element->translation = {0, kContentVerticalOffset, -kContentDistance}; |
71 element->visible = false; | 81 element->visible = false; |
72 main_content_ = element.get(); | 82 main_content_ = element.get(); |
73 scene_->AddUiElement(std::move(element)); | 83 scene_->AddUiElement(std::move(element)); |
74 } | 84 } |
75 | 85 |
76 UiSceneManager::~UiSceneManager() {} | 86 UiSceneManager::~UiSceneManager() {} |
77 | 87 |
78 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 88 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
79 return weak_ptr_factory_.GetWeakPtr(); | 89 return weak_ptr_factory_.GetWeakPtr(); |
80 } | 90 } |
(...skipping 20 matching lines...) Expand all Loading... |
101 } else { | 111 } else { |
102 security_warning_timer_.Stop(); | 112 security_warning_timer_.Stop(); |
103 } | 113 } |
104 } | 114 } |
105 | 115 |
106 void UiSceneManager::OnSecurityWarningTimer() { | 116 void UiSceneManager::OnSecurityWarningTimer() { |
107 transient_security_warning_->visible = false; | 117 transient_security_warning_->visible = false; |
108 } | 118 } |
109 | 119 |
110 } // namespace vr_shell | 120 } // namespace vr_shell |
OLD | NEW |