| 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" | |
| 11 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" | 10 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" |
| 12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" | 11 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 12 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" |
| 13 #include "chrome/browser/android/vr_shell/ui_scene.h" | 13 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 14 #include "chrome/browser/android/vr_shell/vr_browser_interface.h" | 14 #include "chrome/browser/android/vr_shell/vr_browser_interface.h" |
| 15 #include "chrome/browser/android/vr_shell/vr_shell.h" | 15 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 16 | 16 |
| 17 namespace vr_shell { | 17 namespace vr_shell { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 static constexpr int kWarningTimeoutSeconds = 30; | 21 static constexpr int kWarningTimeoutSeconds = 30; |
| 22 static constexpr float kWarningDistance = 0.7; | 22 static constexpr float kWarningDistance = 0.7; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 42 // Tiny distance to offset textures that should appear in the same plane. | 42 // Tiny distance to offset textures that should appear in the same plane. |
| 43 static constexpr float kTextureOffset = 0.01; | 43 static constexpr float kTextureOffset = 0.01; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 UiSceneManager::UiSceneManager(VrBrowserInterface* browser, UiScene* scene) | 47 UiSceneManager::UiSceneManager(VrBrowserInterface* browser, UiScene* scene) |
| 48 : browser_(browser), scene_(scene), weak_ptr_factory_(this) { | 48 : browser_(browser), scene_(scene), weak_ptr_factory_(this) { |
| 49 CreateBackground(); | 49 CreateBackground(); |
| 50 CreateContentQuad(); | 50 CreateContentQuad(); |
| 51 CreateSecurityWarnings(); | 51 CreateSecurityWarnings(); |
| 52 CreateUrlBar(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 UiSceneManager::~UiSceneManager() {} | 55 UiSceneManager::~UiSceneManager() {} |
| 55 | 56 |
| 56 void UiSceneManager::CreateSecurityWarnings() { | 57 void UiSceneManager::CreateSecurityWarnings() { |
| 57 std::unique_ptr<UiElement> element; | 58 std::unique_ptr<UiElement> element; |
| 58 | 59 |
| 59 // TODO(mthiesse): Programatically compute the proper texture size for these | 60 // TODO(mthiesse): Programatically compute the proper texture size for these |
| 60 // textured UI elements. | 61 // textured UI elements. |
| 61 element = base::MakeUnique<PermanentSecurityWarning>(512); | 62 element = base::MakeUnique<PermanentSecurityWarning>(512); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 edge_color.a = 0.0; | 158 edge_color.a = 0.0; |
| 158 element->set_edge_color(edge_color); | 159 element->set_edge_color(edge_color); |
| 159 element->set_gridline_count(kFloorGridlineCount); | 160 element->set_gridline_count(kFloorGridlineCount); |
| 160 element->set_draw_phase(0); | 161 element->set_draw_phase(0); |
| 161 browser_ui_elements_.push_back(element.get()); | 162 browser_ui_elements_.push_back(element.get()); |
| 162 scene_->AddUiElement(std::move(element)); | 163 scene_->AddUiElement(std::move(element)); |
| 163 | 164 |
| 164 scene_->SetBackgroundColor(kBackgroundHorizonColor); | 165 scene_->SetBackgroundColor(kBackgroundHorizonColor); |
| 165 } | 166 } |
| 166 | 167 |
| 168 void UiSceneManager::CreateUrlBar() { |
| 169 // TODO(cjgrant): Incorporate final size and position. |
| 170 // TODO(cjgrant): Add the loading progress indicator element. |
| 171 auto element = base::MakeUnique<UrlBar>(512); |
| 172 element->set_id(AllocateId()); |
| 173 element->set_translation({0, -0.9, -1.8}); |
| 174 element->set_size({0.9, 0, 1}); |
| 175 url_bar_ = element.get(); |
| 176 browser_ui_elements_.push_back(element.get()); |
| 177 scene_->AddUiElement(std::move(element)); |
| 178 } |
| 179 |
| 167 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 180 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
| 168 return weak_ptr_factory_.GetWeakPtr(); | 181 return weak_ptr_factory_.GetWeakPtr(); |
| 169 } | 182 } |
| 170 | 183 |
| 171 void UiSceneManager::SetWebVRMode(bool web_vr) { | 184 void UiSceneManager::SetWebVRMode(bool web_vr) { |
| 172 web_vr_mode_ = web_vr; | 185 web_vr_mode_ = web_vr; |
| 173 | 186 |
| 174 // Make all VR scene UI elements visible if not in WebVR. | 187 // Make all VR scene UI elements visible if not in WebVR. |
| 175 for (UiElement* element : browser_ui_elements_) { | 188 for (UiElement* element : browser_ui_elements_) { |
| 176 element->set_visible(!web_vr_mode_); | 189 element->set_visible(!web_vr_mode_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 202 &UiSceneManager::OnSecurityWarningTimer); | 215 &UiSceneManager::OnSecurityWarningTimer); |
| 203 } else { | 216 } else { |
| 204 security_warning_timer_.Stop(); | 217 security_warning_timer_.Stop(); |
| 205 } | 218 } |
| 206 } | 219 } |
| 207 | 220 |
| 208 void UiSceneManager::OnSecurityWarningTimer() { | 221 void UiSceneManager::OnSecurityWarningTimer() { |
| 209 transient_security_warning_->set_visible(false); | 222 transient_security_warning_->set_visible(false); |
| 210 } | 223 } |
| 211 | 224 |
| 225 void UiSceneManager::OnUrlChange(const GURL& gurl) { |
| 226 url_bar_->SetGURL(gurl); |
| 227 } |
| 228 |
| 212 int UiSceneManager::AllocateId() { | 229 int UiSceneManager::AllocateId() { |
| 213 return next_available_id_++; | 230 return next_available_id_++; |
| 214 } | 231 } |
| 215 | 232 |
| 216 } // namespace vr_shell | 233 } // namespace vr_shell |
| OLD | NEW |