| 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h" | 9 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h" |
| 10 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" | 10 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" |
| 11 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h" | 11 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h" |
| 12 #include "chrome/browser/android/vr_shell/ui_elements/button.h" | 12 #include "chrome/browser/android/vr_shell/ui_elements/button.h" |
| 13 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" | 13 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" |
| 14 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt_backplane.h" |
| 14 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" | 15 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" |
| 15 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" | 16 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" |
| 16 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" | 17 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" |
| 17 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h
" | 18 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h
" |
| 18 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" | 19 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" |
| 19 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" | 20 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" |
| 20 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" | 21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" | 22 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" |
| 22 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" | 23 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" |
| 23 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" | 24 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 static constexpr float kContentDistance = 2.5; | 44 static constexpr float kContentDistance = 2.5; |
| 44 static constexpr float kContentWidth = 0.96 * kContentDistance; | 45 static constexpr float kContentWidth = 0.96 * kContentDistance; |
| 45 static constexpr float kContentHeight = 0.64 * kContentDistance; | 46 static constexpr float kContentHeight = 0.64 * kContentDistance; |
| 46 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; | 47 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; |
| 47 static constexpr float kBackplaneSize = 1000.0; | 48 static constexpr float kBackplaneSize = 1000.0; |
| 48 static constexpr float kBackgroundDistanceMultiplier = 1.414; | 49 static constexpr float kBackgroundDistanceMultiplier = 1.414; |
| 49 | 50 |
| 50 static constexpr float kExitPromptWidth = 0.672 * kContentDistance; | 51 static constexpr float kExitPromptWidth = 0.672 * kContentDistance; |
| 51 static constexpr float kExitPromptHeight = 0.2 * kContentDistance; | 52 static constexpr float kExitPromptHeight = 0.2 * kContentDistance; |
| 53 static constexpr float kExitPromptBackplaneSize = 1000.0; |
| 52 | 54 |
| 53 static constexpr float kUrlBarDistance = 2.4; | 55 static constexpr float kUrlBarDistance = 2.4; |
| 54 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; | 56 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; |
| 55 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; | 57 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; |
| 56 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; | 58 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; |
| 57 static constexpr float kUrlBarRotationRad = -0.175; | 59 static constexpr float kUrlBarRotationRad = -0.175; |
| 58 | 60 |
| 59 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; | 61 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; |
| 60 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; | 62 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; |
| 61 static constexpr float kLoadingIndicatorVerticalOffset = | 63 static constexpr float kLoadingIndicatorVerticalOffset = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 89 web_vr_mode_(in_web_vr), | 91 web_vr_mode_(in_web_vr), |
| 90 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
| 91 CreateBackground(); | 93 CreateBackground(); |
| 92 CreateContentQuad(); | 94 CreateContentQuad(); |
| 93 CreateSecurityWarnings(); | 95 CreateSecurityWarnings(); |
| 94 CreateSystemIndicators(); | 96 CreateSystemIndicators(); |
| 95 CreateUrlBar(); | 97 CreateUrlBar(); |
| 96 if (in_cct_) | 98 if (in_cct_) |
| 97 CreateCloseButton(); | 99 CreateCloseButton(); |
| 98 CreateScreenDimmer(); | 100 CreateScreenDimmer(); |
| 101 CreateExitPrompt(); |
| 99 | 102 |
| 100 ConfigureScene(); | 103 ConfigureScene(); |
| 101 ConfigureSecurityWarnings(); | 104 ConfigureSecurityWarnings(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 UiSceneManager::~UiSceneManager() {} | 107 UiSceneManager::~UiSceneManager() {} |
| 105 | 108 |
| 106 void UiSceneManager::CreateScreenDimmer() { | 109 void UiSceneManager::CreateScreenDimmer() { |
| 107 std::unique_ptr<UiElement> element; | 110 std::unique_ptr<UiElement> element; |
| 108 element = base::MakeUnique<ScreenDimmer>(); | 111 element = base::MakeUnique<ScreenDimmer>(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 216 |
| 214 // Place an invisible but hittable plane behind the content quad, to keep the | 217 // Place an invisible but hittable plane behind the content quad, to keep the |
| 215 // reticle roughly planar with the content if near content. | 218 // reticle roughly planar with the content if near content. |
| 216 element = base::MakeUnique<UiElement>(); | 219 element = base::MakeUnique<UiElement>(); |
| 217 element->set_debug_id(kBackplane); | 220 element->set_debug_id(kBackplane); |
| 218 element->set_id(AllocateId()); | 221 element->set_id(AllocateId()); |
| 219 element->set_fill(vr_shell::Fill::NONE); | 222 element->set_fill(vr_shell::Fill::NONE); |
| 220 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); | 223 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); |
| 221 element->set_translation({0.0, 0.0, -kTextureOffset}); | 224 element->set_translation({0.0, 0.0, -kTextureOffset}); |
| 222 element->set_parent_id(main_content_->id()); | 225 element->set_parent_id(main_content_->id()); |
| 223 main_content_backplane_ = element.get(); | |
| 224 content_elements_.push_back(element.get()); | 226 content_elements_.push_back(element.get()); |
| 225 scene_->AddUiElement(std::move(element)); | 227 scene_->AddUiElement(std::move(element)); |
| 226 | 228 |
| 227 element = base::MakeUnique<ExitPrompt>( | |
| 228 512, | |
| 229 base::Bind(&UiSceneManager::OnExitPromptPrimaryButtonClicked, | |
| 230 base::Unretained(this)), | |
| 231 base::Bind(&UiSceneManager::OnExitPromptSecondaryButtonClicked, | |
| 232 base::Unretained(this))); | |
| 233 element->set_debug_id(kExitPrompt); | |
| 234 element->set_id(AllocateId()); | |
| 235 element->set_fill(vr_shell::Fill::NONE); | |
| 236 element->set_size({kExitPromptWidth, kExitPromptHeight, 1}); | |
| 237 element->set_translation({0.0, 0.0, kTextureOffset}); | |
| 238 element->set_parent_id(main_content_->id()); | |
| 239 element->set_visible(false); | |
| 240 exit_prompt_ = element.get(); | |
| 241 scene_->AddUiElement(std::move(element)); | |
| 242 | |
| 243 // Limit reticle distance to a sphere based on content distance. | 229 // Limit reticle distance to a sphere based on content distance. |
| 244 scene_->SetBackgroundDistance(main_content_->translation().z() * | 230 scene_->SetBackgroundDistance(main_content_->translation().z() * |
| 245 -kBackgroundDistanceMultiplier); | 231 -kBackgroundDistanceMultiplier); |
| 246 } | 232 } |
| 247 | 233 |
| 248 void UiSceneManager::CreateBackground() { | 234 void UiSceneManager::CreateBackground() { |
| 249 std::unique_ptr<UiElement> element; | 235 std::unique_ptr<UiElement> element; |
| 250 | 236 |
| 251 // Floor. | 237 // Floor. |
| 252 element = base::MakeUnique<UiElement>(); | 238 element = base::MakeUnique<UiElement>(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 element->set_id(AllocateId()); | 302 element->set_id(AllocateId()); |
| 317 element->set_fill(vr_shell::Fill::NONE); | 303 element->set_fill(vr_shell::Fill::NONE); |
| 318 element->set_translation( | 304 element->set_translation( |
| 319 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, | 305 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, |
| 320 -kContentDistance + 0.4)); | 306 -kContentDistance + 0.4)); |
| 321 element->set_size(gfx::Vector3dF(0.2, 0.2, 1)); | 307 element->set_size(gfx::Vector3dF(0.2, 0.2, 1)); |
| 322 control_elements_.push_back(element.get()); | 308 control_elements_.push_back(element.get()); |
| 323 scene_->AddUiElement(std::move(element)); | 309 scene_->AddUiElement(std::move(element)); |
| 324 } | 310 } |
| 325 | 311 |
| 312 void UiSceneManager::CreateExitPrompt() { |
| 313 std::unique_ptr<UiElement> element = base::MakeUnique<ExitPrompt>( |
| 314 512, |
| 315 base::Bind(&UiSceneManager::OnExitPromptPrimaryButtonClicked, |
| 316 base::Unretained(this)), |
| 317 base::Bind(&UiSceneManager::OnExitPromptSecondaryButtonClicked, |
| 318 base::Unretained(this))); |
| 319 element->set_debug_id(kExitPrompt); |
| 320 element->set_id(AllocateId()); |
| 321 element->set_fill(vr_shell::Fill::NONE); |
| 322 element->set_size({kExitPromptWidth, kExitPromptHeight, 1}); |
| 323 element->set_translation({0.0, 0.0, kTextureOffset}); |
| 324 element->set_parent_id(main_content_->id()); |
| 325 element->set_visible(false); |
| 326 exit_prompt_ = element.get(); |
| 327 scene_->AddUiElement(std::move(element)); |
| 328 |
| 329 // Place an invisible but hittable plane behind the exit prompt, to keep the |
| 330 // reticle roughly planar with the content if near content. |
| 331 element = base::MakeUnique<ExitPromptBackplane>(base::Bind( |
| 332 &UiSceneManager::OnExitPromptBackplaneClicked, base::Unretained(this))); |
| 333 element->set_debug_id(kExitPromptBackplane); |
| 334 element->set_id(AllocateId()); |
| 335 element->set_fill(vr_shell::Fill::NONE); |
| 336 element->set_size({kExitPromptBackplaneSize, kExitPromptBackplaneSize, 1.0}); |
| 337 element->set_translation({0.0, 0.0, -kTextureOffset}); |
| 338 element->set_parent_id(exit_prompt_->id()); |
| 339 exit_prompt_backplane_ = element.get(); |
| 340 content_elements_.push_back(element.get()); |
| 341 scene_->AddUiElement(std::move(element)); |
| 342 } |
| 343 |
| 326 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 344 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
| 327 return weak_ptr_factory_.GetWeakPtr(); | 345 return weak_ptr_factory_.GetWeakPtr(); |
| 328 } | 346 } |
| 329 | 347 |
| 330 void UiSceneManager::SetWebVrMode(bool web_vr) { | 348 void UiSceneManager::SetWebVrMode(bool web_vr) { |
| 331 if (web_vr_mode_ == web_vr) | 349 if (web_vr_mode_ == web_vr) |
| 332 return; | 350 return; |
| 333 web_vr_mode_ = web_vr; | 351 web_vr_mode_ = web_vr; |
| 334 ConfigureScene(); | 352 ConfigureScene(); |
| 335 ConfigureSecurityWarnings(); | 353 ConfigureSecurityWarnings(); |
| 336 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); | 354 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); |
| 337 video_capture_indicator_->set_visible(!web_vr && video_capturing_); | 355 video_capture_indicator_->set_visible(!web_vr && video_capturing_); |
| 338 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); | 356 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); |
| 339 } | 357 } |
| 340 | 358 |
| 341 void UiSceneManager::ConfigureScene() { | 359 void UiSceneManager::ConfigureScene() { |
| 342 exit_warning_->SetEnabled(scene_->is_exiting()); | 360 exit_warning_->SetEnabled(scene_->is_exiting()); |
| 343 exit_prompt_->SetEnabled(scene_->is_prompting_to_exit()); | |
| 344 screen_dimmer_->SetEnabled(scene_->is_exiting()); | 361 screen_dimmer_->SetEnabled(scene_->is_exiting()); |
| 345 | 362 |
| 346 // Controls (URL bar, loading progress, etc). | 363 // Controls (URL bar, loading progress, etc). |
| 347 bool controls_visible = !web_vr_mode_ && !fullscreen_; | 364 bool controls_visible = !web_vr_mode_ && !fullscreen_; |
| 348 for (UiElement* element : control_elements_) { | 365 for (UiElement* element : control_elements_) { |
| 349 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); | 366 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); |
| 350 } | 367 } |
| 351 | 368 |
| 352 // Content elements. | 369 // Content elements. |
| 353 main_content_->SetEnabled(!web_vr_mode_ && !scene_->is_prompting_to_exit()); | 370 for (UiElement* element : content_elements_) { |
| 354 main_content_backplane_->SetEnabled(!web_vr_mode_); | 371 element->SetEnabled(!web_vr_mode_ && !scene_->is_prompting_to_exit()); |
| 372 } |
| 373 |
| 355 // Background elements. | 374 // Background elements. |
| 356 for (UiElement* element : background_elements_) { | 375 for (UiElement* element : background_elements_) { |
| 357 element->SetEnabled(!web_vr_mode_); | 376 element->SetEnabled(!web_vr_mode_); |
| 358 } | 377 } |
| 359 | 378 |
| 379 // Exit prompt. |
| 380 bool showExitPrompt = !web_vr_mode_ && scene_->is_prompting_to_exit(); |
| 381 exit_prompt_->SetEnabled(showExitPrompt); |
| 382 exit_prompt_backplane_->SetEnabled(showExitPrompt); |
| 383 |
| 360 // Update content quad parameters depending on fullscreen. | 384 // Update content quad parameters depending on fullscreen. |
| 361 // TODO(http://crbug.com/642937): Animate fullscreen transitions. | 385 // TODO(http://crbug.com/642937): Animate fullscreen transitions. |
| 362 if (fullscreen_) { | 386 if (fullscreen_) { |
| 363 main_content_->set_translation( | 387 main_content_->set_translation( |
| 364 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); | 388 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); |
| 365 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); | 389 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); |
| 366 } else { | 390 } else { |
| 367 // Note that main_content_ is already visible in this case. | 391 // Note that main_content_ is already visible in this case. |
| 368 main_content_->set_translation( | 392 main_content_->set_translation( |
| 369 {0, kContentVerticalOffset, -kContentDistance}); | 393 {0, kContentVerticalOffset, -kContentDistance}); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 browser_->NavigateBack(); | 474 browser_->NavigateBack(); |
| 451 } | 475 } |
| 452 | 476 |
| 453 void UiSceneManager::OnSecurityIconClicked() { | 477 void UiSceneManager::OnSecurityIconClicked() { |
| 454 if (scene_->is_prompting_to_exit()) | 478 if (scene_->is_prompting_to_exit()) |
| 455 return; | 479 return; |
| 456 scene_->set_is_prompting_to_exit(true); | 480 scene_->set_is_prompting_to_exit(true); |
| 457 ConfigureScene(); | 481 ConfigureScene(); |
| 458 } | 482 } |
| 459 | 483 |
| 460 void UiSceneManager::OnExitPromptPrimaryButtonClicked() { | 484 void UiSceneManager::OnExitPromptBackplaneClicked() { |
| 485 CloseExitPrompt(); |
| 486 } |
| 487 |
| 488 void UiSceneManager::CloseExitPrompt() { |
| 461 if (!scene_->is_prompting_to_exit()) | 489 if (!scene_->is_prompting_to_exit()) |
| 462 return; | 490 return; |
| 463 scene_->set_is_prompting_to_exit(false); | 491 scene_->set_is_prompting_to_exit(false); |
| 464 ConfigureScene(); | 492 ConfigureScene(); |
| 465 } | 493 } |
| 466 | 494 |
| 495 void UiSceneManager::OnExitPromptPrimaryButtonClicked() { |
| 496 CloseExitPrompt(); |
| 497 } |
| 498 |
| 467 void UiSceneManager::OnExitPromptSecondaryButtonClicked() { | 499 void UiSceneManager::OnExitPromptSecondaryButtonClicked() { |
| 468 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo); | 500 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo); |
| 469 } | 501 } |
| 470 | 502 |
| 471 void UiSceneManager::SetURL(const GURL& gurl) { | 503 void UiSceneManager::SetURL(const GURL& gurl) { |
| 472 url_bar_->SetURL(gurl); | 504 url_bar_->SetURL(gurl); |
| 473 } | 505 } |
| 474 | 506 |
| 475 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { | 507 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { |
| 476 url_bar_->SetSecurityLevel(level); | 508 url_bar_->SetSecurityLevel(level); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 if (fullscreen_) | 546 if (fullscreen_) |
| 515 return ColorScheme::kModeFullscreen; | 547 return ColorScheme::kModeFullscreen; |
| 516 return ColorScheme::kModeNormal; | 548 return ColorScheme::kModeNormal; |
| 517 } | 549 } |
| 518 | 550 |
| 519 const ColorScheme& UiSceneManager::color_scheme() const { | 551 const ColorScheme& UiSceneManager::color_scheme() const { |
| 520 return ColorScheme::GetColorScheme(mode()); | 552 return ColorScheme::GetColorScheme(mode()); |
| 521 } | 553 } |
| 522 | 554 |
| 523 } // namespace vr_shell | 555 } // namespace vr_shell |
| OLD | NEW |