| 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_browser_interface.h" | 11 #include "chrome/browser/android/vr_shell/ui_browser_interface.h" |
| 12 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h" | 12 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h" |
| 13 #include "chrome/browser/android/vr_shell/ui_elements/button.h" | 13 #include "chrome/browser/android/vr_shell/ui_elements/button.h" |
| 14 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" | 14 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" |
| 15 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt_backplane.h" |
| 15 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" | 16 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" |
| 16 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" | 17 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" |
| 17 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" | 18 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" |
| 18 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h
" | 19 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h
" |
| 19 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" | 20 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" |
| 20 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" | 21 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" |
| 21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" | 22 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 22 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" | 23 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" |
| 23 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" | 24 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" |
| 24 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" | 25 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 48 static constexpr float kBackgroundDistanceMultiplier = 1.414; | 49 static constexpr float kBackgroundDistanceMultiplier = 1.414; |
| 49 | 50 |
| 50 static constexpr float kFullscreenDistance = 3; | 51 static constexpr float kFullscreenDistance = 3; |
| 51 static constexpr float kFullscreenHeight = 0.64 * kFullscreenDistance; | 52 static constexpr float kFullscreenHeight = 0.64 * kFullscreenDistance; |
| 52 static constexpr float kFullscreenWidth = 1.138 * kFullscreenDistance; | 53 static constexpr float kFullscreenWidth = 1.138 * kFullscreenDistance; |
| 53 static constexpr float kFullscreenVerticalOffset = -0.1 * kFullscreenDistance; | 54 static constexpr float kFullscreenVerticalOffset = -0.1 * kFullscreenDistance; |
| 54 | 55 |
| 55 static constexpr float kExitPromptWidth = 0.672 * kContentDistance; | 56 static constexpr float kExitPromptWidth = 0.672 * kContentDistance; |
| 56 static constexpr float kExitPromptHeight = 0.2 * kContentDistance; | 57 static constexpr float kExitPromptHeight = 0.2 * kContentDistance; |
| 57 static constexpr float kExitPromptVerticalOffset = -0.09 * kContentDistance; | 58 static constexpr float kExitPromptVerticalOffset = -0.09 * kContentDistance; |
| 59 static constexpr float kExitPromptBackplaneSize = 1000.0; |
| 58 | 60 |
| 59 static constexpr float kUrlBarDistance = 2.4; | 61 static constexpr float kUrlBarDistance = 2.4; |
| 60 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; | 62 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; |
| 61 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; | 63 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; |
| 62 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; | 64 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; |
| 63 static constexpr float kUrlBarRotationRad = -0.175; | 65 static constexpr float kUrlBarRotationRad = -0.175; |
| 64 | 66 |
| 65 static constexpr float kCloseButtonDistance = 2.4; | 67 static constexpr float kCloseButtonDistance = 2.4; |
| 66 static constexpr float kCloseButtonHeight = 0.088 * kCloseButtonDistance; | 68 static constexpr float kCloseButtonHeight = 0.088 * kCloseButtonDistance; |
| 67 static constexpr float kCloseButtonWidth = 0.088 * kCloseButtonDistance; | 69 static constexpr float kCloseButtonWidth = 0.088 * kCloseButtonDistance; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 98 in_cct_(in_cct), | 100 in_cct_(in_cct), |
| 99 web_vr_mode_(in_web_vr), | 101 web_vr_mode_(in_web_vr), |
| 100 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
| 101 CreateBackground(); | 103 CreateBackground(); |
| 102 CreateContentQuad(); | 104 CreateContentQuad(); |
| 103 CreateSecurityWarnings(); | 105 CreateSecurityWarnings(); |
| 104 CreateSystemIndicators(); | 106 CreateSystemIndicators(); |
| 105 CreateUrlBar(); | 107 CreateUrlBar(); |
| 106 CreateCloseButton(); | 108 CreateCloseButton(); |
| 107 CreateScreenDimmer(); | 109 CreateScreenDimmer(); |
| 110 CreateExitPrompt(); |
| 108 | 111 |
| 109 ConfigureScene(); | 112 ConfigureScene(); |
| 110 ConfigureSecurityWarnings(); | 113 ConfigureSecurityWarnings(); |
| 111 } | 114 } |
| 112 | 115 |
| 113 UiSceneManager::~UiSceneManager() {} | 116 UiSceneManager::~UiSceneManager() {} |
| 114 | 117 |
| 115 void UiSceneManager::CreateScreenDimmer() { | 118 void UiSceneManager::CreateScreenDimmer() { |
| 116 std::unique_ptr<UiElement> element; | 119 std::unique_ptr<UiElement> element; |
| 117 element = base::MakeUnique<ScreenDimmer>(); | 120 element = base::MakeUnique<ScreenDimmer>(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 225 |
| 223 // Place an invisible but hittable plane behind the content quad, to keep the | 226 // Place an invisible but hittable plane behind the content quad, to keep the |
| 224 // reticle roughly planar with the content if near content. | 227 // reticle roughly planar with the content if near content. |
| 225 element = base::MakeUnique<UiElement>(); | 228 element = base::MakeUnique<UiElement>(); |
| 226 element->set_debug_id(kBackplane); | 229 element->set_debug_id(kBackplane); |
| 227 element->set_id(AllocateId()); | 230 element->set_id(AllocateId()); |
| 228 element->set_fill(vr_shell::Fill::NONE); | 231 element->set_fill(vr_shell::Fill::NONE); |
| 229 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); | 232 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); |
| 230 element->set_translation({0.0, 0.0, -kTextureOffset}); | 233 element->set_translation({0.0, 0.0, -kTextureOffset}); |
| 231 element->set_parent_id(main_content_->id()); | 234 element->set_parent_id(main_content_->id()); |
| 232 main_content_backplane_ = element.get(); | |
| 233 content_elements_.push_back(element.get()); | 235 content_elements_.push_back(element.get()); |
| 234 scene_->AddUiElement(std::move(element)); | 236 scene_->AddUiElement(std::move(element)); |
| 235 | 237 |
| 236 element = base::MakeUnique<ExitPrompt>( | |
| 237 512, | |
| 238 base::Bind(&UiSceneManager::OnExitPromptPrimaryButtonClicked, | |
| 239 base::Unretained(this)), | |
| 240 base::Bind(&UiSceneManager::OnExitPromptSecondaryButtonClicked, | |
| 241 base::Unretained(this))); | |
| 242 element->set_debug_id(kExitPrompt); | |
| 243 element->set_id(AllocateId()); | |
| 244 element->set_fill(vr_shell::Fill::NONE); | |
| 245 element->set_size({kExitPromptWidth, kExitPromptHeight, 1}); | |
| 246 element->set_translation({0.0, kExitPromptVerticalOffset, kTextureOffset}); | |
| 247 element->set_parent_id(main_content_->id()); | |
| 248 element->set_visible(false); | |
| 249 exit_prompt_ = element.get(); | |
| 250 scene_->AddUiElement(std::move(element)); | |
| 251 | |
| 252 // Limit reticle distance to a sphere based on content distance. | 238 // Limit reticle distance to a sphere based on content distance. |
| 253 scene_->SetBackgroundDistance(main_content_->translation().z() * | 239 scene_->SetBackgroundDistance(main_content_->translation().z() * |
| 254 -kBackgroundDistanceMultiplier); | 240 -kBackgroundDistanceMultiplier); |
| 255 } | 241 } |
| 256 | 242 |
| 257 void UiSceneManager::CreateBackground() { | 243 void UiSceneManager::CreateBackground() { |
| 258 std::unique_ptr<UiElement> element; | 244 std::unique_ptr<UiElement> element; |
| 259 | 245 |
| 260 // Floor. | 246 // Floor. |
| 261 element = base::MakeUnique<UiElement>(); | 247 element = base::MakeUnique<UiElement>(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 element->set_id(AllocateId()); | 311 element->set_id(AllocateId()); |
| 326 element->set_fill(vr_shell::Fill::NONE); | 312 element->set_fill(vr_shell::Fill::NONE); |
| 327 element->set_translation( | 313 element->set_translation( |
| 328 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, | 314 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, |
| 329 -kCloseButtonDistance)); | 315 -kCloseButtonDistance)); |
| 330 element->set_size(gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1)); | 316 element->set_size(gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1)); |
| 331 close_button_ = element.get(); | 317 close_button_ = element.get(); |
| 332 scene_->AddUiElement(std::move(element)); | 318 scene_->AddUiElement(std::move(element)); |
| 333 } | 319 } |
| 334 | 320 |
| 321 void UiSceneManager::CreateExitPrompt() { |
| 322 std::unique_ptr<UiElement> element = base::MakeUnique<ExitPrompt>( |
| 323 512, |
| 324 base::Bind(&UiSceneManager::OnExitPromptPrimaryButtonClicked, |
| 325 base::Unretained(this)), |
| 326 base::Bind(&UiSceneManager::OnExitPromptSecondaryButtonClicked, |
| 327 base::Unretained(this))); |
| 328 element->set_debug_id(kExitPrompt); |
| 329 element->set_id(AllocateId()); |
| 330 element->set_fill(vr_shell::Fill::NONE); |
| 331 element->set_size({kExitPromptWidth, kExitPromptHeight, 1}); |
| 332 element->set_translation({0.0, kExitPromptVerticalOffset, kTextureOffset}); |
| 333 element->set_parent_id(main_content_->id()); |
| 334 element->set_visible(false); |
| 335 exit_prompt_ = element.get(); |
| 336 scene_->AddUiElement(std::move(element)); |
| 337 |
| 338 // Place an invisible but hittable plane behind the exit prompt, to keep the |
| 339 // reticle roughly planar with the content if near content. |
| 340 element = base::MakeUnique<ExitPromptBackplane>(base::Bind( |
| 341 &UiSceneManager::OnExitPromptBackplaneClicked, base::Unretained(this))); |
| 342 element->set_debug_id(kExitPromptBackplane); |
| 343 element->set_id(AllocateId()); |
| 344 element->set_fill(vr_shell::Fill::NONE); |
| 345 element->set_size({kExitPromptBackplaneSize, kExitPromptBackplaneSize, 1.0}); |
| 346 element->set_translation({0.0, 0.0, -kTextureOffset}); |
| 347 element->set_parent_id(exit_prompt_->id()); |
| 348 exit_prompt_backplane_ = element.get(); |
| 349 content_elements_.push_back(element.get()); |
| 350 scene_->AddUiElement(std::move(element)); |
| 351 } |
| 352 |
| 335 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 353 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
| 336 return weak_ptr_factory_.GetWeakPtr(); | 354 return weak_ptr_factory_.GetWeakPtr(); |
| 337 } | 355 } |
| 338 | 356 |
| 339 void UiSceneManager::SetWebVrMode(bool web_vr) { | 357 void UiSceneManager::SetWebVrMode(bool web_vr) { |
| 340 if (web_vr_mode_ == web_vr) | 358 if (web_vr_mode_ == web_vr) |
| 341 return; | 359 return; |
| 342 web_vr_mode_ = web_vr; | 360 web_vr_mode_ = web_vr; |
| 343 ConfigureScene(); | 361 ConfigureScene(); |
| 344 ConfigureSecurityWarnings(); | 362 ConfigureSecurityWarnings(); |
| 345 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); | 363 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); |
| 346 video_capture_indicator_->set_visible(!web_vr && video_capturing_); | 364 video_capture_indicator_->set_visible(!web_vr && video_capturing_); |
| 347 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); | 365 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); |
| 348 } | 366 } |
| 349 | 367 |
| 350 void UiSceneManager::ConfigureScene() { | 368 void UiSceneManager::ConfigureScene() { |
| 351 exit_warning_->SetEnabled(scene_->is_exiting()); | 369 exit_warning_->SetEnabled(scene_->is_exiting()); |
| 352 exit_prompt_->SetEnabled(scene_->is_prompting_to_exit()); | |
| 353 screen_dimmer_->SetEnabled(scene_->is_exiting()); | 370 screen_dimmer_->SetEnabled(scene_->is_exiting()); |
| 354 | 371 |
| 355 // Controls (URL bar, loading progress, etc). | 372 // Controls (URL bar, loading progress, etc). |
| 356 bool controls_visible = !web_vr_mode_ && !fullscreen_; | 373 bool controls_visible = !web_vr_mode_ && !fullscreen_; |
| 357 for (UiElement* element : control_elements_) { | 374 for (UiElement* element : control_elements_) { |
| 358 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); | 375 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); |
| 359 } | 376 } |
| 360 | 377 |
| 361 // Close button is a special control element that needs to be hidden when in | 378 // Close button is a special control element that needs to be hidden when in |
| 362 // WebVR, but it needs to be visible when in cct or fullscreen. | 379 // WebVR, but it needs to be visible when in cct or fullscreen. |
| 363 close_button_->SetEnabled(!web_vr_mode_ && (fullscreen_ || in_cct_)); | 380 close_button_->SetEnabled(!web_vr_mode_ && (fullscreen_ || in_cct_)); |
| 364 | 381 |
| 365 // Content elements. | 382 // Content elements. |
| 366 main_content_->SetEnabled(!web_vr_mode_ && !scene_->is_prompting_to_exit()); | 383 for (UiElement* element : content_elements_) { |
| 367 main_content_backplane_->SetEnabled(!web_vr_mode_); | 384 element->SetEnabled(!web_vr_mode_ && !scene_->is_prompting_to_exit()); |
| 385 } |
| 386 |
| 368 // Background elements. | 387 // Background elements. |
| 369 for (UiElement* element : background_elements_) { | 388 for (UiElement* element : background_elements_) { |
| 370 element->SetEnabled(!web_vr_mode_); | 389 element->SetEnabled(!web_vr_mode_); |
| 371 } | 390 } |
| 372 | 391 |
| 392 // Exit prompt. |
| 393 bool showExitPrompt = !web_vr_mode_ && scene_->is_prompting_to_exit(); |
| 394 exit_prompt_->SetEnabled(showExitPrompt); |
| 395 exit_prompt_backplane_->SetEnabled(showExitPrompt); |
| 396 |
| 373 // Update content quad parameters depending on fullscreen. | 397 // Update content quad parameters depending on fullscreen. |
| 374 // TODO(http://crbug.com/642937): Animate fullscreen transitions. | 398 // TODO(http://crbug.com/642937): Animate fullscreen transitions. |
| 375 if (fullscreen_) { | 399 if (fullscreen_) { |
| 376 main_content_->set_translation( | 400 main_content_->set_translation( |
| 377 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); | 401 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); |
| 378 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); | 402 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); |
| 379 | 403 |
| 380 close_button_->set_translation(gfx::Vector3dF( | 404 close_button_->set_translation(gfx::Vector3dF( |
| 381 0, kFullscreenVerticalOffset - (kFullscreenHeight / 2) - 0.35, | 405 0, kFullscreenVerticalOffset - (kFullscreenHeight / 2) - 0.35, |
| 382 -kCloseButtonFullscreenDistance)); | 406 -kCloseButtonFullscreenDistance)); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 492 } |
| 469 | 493 |
| 470 void UiSceneManager::OnSecurityWarningTimer() { | 494 void UiSceneManager::OnSecurityWarningTimer() { |
| 471 transient_security_warning_->set_visible(false); | 495 transient_security_warning_->set_visible(false); |
| 472 } | 496 } |
| 473 | 497 |
| 474 void UiSceneManager::OnBackButtonClicked() { | 498 void UiSceneManager::OnBackButtonClicked() { |
| 475 browser_->NavigateBack(); | 499 browser_->NavigateBack(); |
| 476 } | 500 } |
| 477 | 501 |
| 502 void UiSceneManager::OnSecurityIconClickedForTesting() { |
| 503 OnSecurityIconClicked(); |
| 504 } |
| 505 |
| 506 void UiSceneManager::OnExitPromptPrimaryButtonClickedForTesting() { |
| 507 OnExitPromptPrimaryButtonClicked(); |
| 508 } |
| 509 |
| 478 void UiSceneManager::OnSecurityIconClicked() { | 510 void UiSceneManager::OnSecurityIconClicked() { |
| 479 if (scene_->is_prompting_to_exit()) | 511 if (scene_->is_prompting_to_exit()) |
| 480 return; | 512 return; |
| 481 scene_->set_is_prompting_to_exit(true); | 513 scene_->set_is_prompting_to_exit(true); |
| 482 ConfigureScene(); | 514 ConfigureScene(); |
| 483 } | 515 } |
| 484 | 516 |
| 485 void UiSceneManager::OnExitPromptPrimaryButtonClicked() { | 517 void UiSceneManager::OnExitPromptBackplaneClicked() { |
| 518 CloseExitPrompt(); |
| 519 } |
| 520 |
| 521 void UiSceneManager::CloseExitPrompt() { |
| 486 if (!scene_->is_prompting_to_exit()) | 522 if (!scene_->is_prompting_to_exit()) |
| 487 return; | 523 return; |
| 488 scene_->set_is_prompting_to_exit(false); | 524 scene_->set_is_prompting_to_exit(false); |
| 489 ConfigureScene(); | 525 ConfigureScene(); |
| 490 } | 526 } |
| 491 | 527 |
| 528 void UiSceneManager::OnExitPromptPrimaryButtonClicked() { |
| 529 CloseExitPrompt(); |
| 530 } |
| 531 |
| 492 void UiSceneManager::OnExitPromptSecondaryButtonClicked() { | 532 void UiSceneManager::OnExitPromptSecondaryButtonClicked() { |
| 493 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo); | 533 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo); |
| 494 } | 534 } |
| 495 | 535 |
| 496 void UiSceneManager::SetURL(const GURL& gurl) { | 536 void UiSceneManager::SetURL(const GURL& gurl) { |
| 497 url_bar_->SetURL(gurl); | 537 url_bar_->SetURL(gurl); |
| 498 } | 538 } |
| 499 | 539 |
| 500 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { | 540 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { |
| 501 url_bar_->SetSecurityLevel(level); | 541 url_bar_->SetSecurityLevel(level); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (fullscreen_) | 584 if (fullscreen_) |
| 545 return ColorScheme::kModeFullscreen; | 585 return ColorScheme::kModeFullscreen; |
| 546 return ColorScheme::kModeNormal; | 586 return ColorScheme::kModeNormal; |
| 547 } | 587 } |
| 548 | 588 |
| 549 const ColorScheme& UiSceneManager::color_scheme() const { | 589 const ColorScheme& UiSceneManager::color_scheme() const { |
| 550 return ColorScheme::GetColorScheme(mode()); | 590 return ColorScheme::GetColorScheme(mode()); |
| 551 } | 591 } |
| 552 | 592 |
| 553 } // namespace vr_shell | 593 } // namespace vr_shell |
| OLD | NEW |