| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 static constexpr float kExitWarningHeight = 0.160; | 39 static constexpr float kExitWarningHeight = 0.160; |
| 40 static constexpr float kExitWarningWidth = 0.512; | 40 static constexpr float kExitWarningWidth = 0.512; |
| 41 | 41 |
| 42 static constexpr float kContentDistance = 2.5; | 42 static constexpr float kContentDistance = 2.5; |
| 43 static constexpr float kContentWidth = 0.96 * kContentDistance; | 43 static constexpr float kContentWidth = 0.96 * kContentDistance; |
| 44 static constexpr float kContentHeight = 0.64 * kContentDistance; | 44 static constexpr float kContentHeight = 0.64 * kContentDistance; |
| 45 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; | 45 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; |
| 46 static constexpr float kBackplaneSize = 1000.0; | 46 static constexpr float kBackplaneSize = 1000.0; |
| 47 static constexpr float kBackgroundDistanceMultiplier = 1.414; | 47 static constexpr float kBackgroundDistanceMultiplier = 1.414; |
| 48 | 48 |
| 49 static constexpr float kFullscreenDistance = 3; |
| 50 static constexpr float kFullscreenHeight = 0.64 * kFullscreenDistance; |
| 51 static constexpr float kFullscreenWidth = 1.138 * kFullscreenDistance; |
| 52 static constexpr float kFullscreenVerticalOffset = -0.1 * kFullscreenDistance; |
| 53 |
| 49 static constexpr float kUrlBarDistance = 2.4; | 54 static constexpr float kUrlBarDistance = 2.4; |
| 50 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; | 55 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; |
| 51 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; | 56 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; |
| 52 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; | 57 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; |
| 53 static constexpr float kUrlBarRotationRad = -0.175; | 58 static constexpr float kUrlBarRotationRad = -0.175; |
| 54 | 59 |
| 60 static constexpr float kCloseButtonDistance = 2.4; |
| 61 static constexpr float kCloseButtonHeight = 0.088 * kCloseButtonDistance; |
| 62 static constexpr float kCloseButtonWidth = 0.088 * kCloseButtonDistance; |
| 63 static constexpr float kCloseButtonFullscreenDistance = 2.9; |
| 64 static constexpr float kCloseButtonFullscreenHeight = |
| 65 0.088 * kCloseButtonDistance; |
| 66 static constexpr float kCloseButtonFullscreenWidth = |
| 67 0.088 * kCloseButtonDistance; |
| 68 |
| 55 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; | 69 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; |
| 56 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; | 70 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; |
| 57 static constexpr float kLoadingIndicatorVerticalOffset = | 71 static constexpr float kLoadingIndicatorVerticalOffset = |
| 58 (-kUrlBarVerticalOffset + kContentVerticalOffset - kContentHeight / 2 - | 72 (-kUrlBarVerticalOffset + kContentVerticalOffset - kContentHeight / 2 - |
| 59 kUrlBarHeight / 2) / | 73 kUrlBarHeight / 2) / |
| 60 2; | 74 2; |
| 61 static constexpr float kLoadingIndicatorDepthOffset = | 75 static constexpr float kLoadingIndicatorDepthOffset = |
| 62 (kUrlBarDistance - kContentDistance) / 2; | 76 (kUrlBarDistance - kContentDistance) / 2; |
| 63 | 77 |
| 64 static constexpr float kSceneSize = 25.0; | 78 static constexpr float kSceneSize = 25.0; |
| 65 static constexpr float kSceneHeight = 4.0; | 79 static constexpr float kSceneHeight = 4.0; |
| 66 static constexpr int kFloorGridlineCount = 40; | 80 static constexpr int kFloorGridlineCount = 40; |
| 67 | 81 |
| 68 static constexpr float kFullscreenDistance = 3; | |
| 69 static constexpr float kFullscreenHeight = 0.64 * kFullscreenDistance; | |
| 70 static constexpr float kFullscreenWidth = 1.138 * kFullscreenDistance; | |
| 71 static constexpr float kFullscreenVerticalOffset = -0.1 * kFullscreenDistance; | |
| 72 | |
| 73 // Tiny distance to offset textures that should appear in the same plane. | 82 // Tiny distance to offset textures that should appear in the same plane. |
| 74 static constexpr float kTextureOffset = 0.01; | 83 static constexpr float kTextureOffset = 0.01; |
| 75 | 84 |
| 76 } // namespace | 85 } // namespace |
| 77 | 86 |
| 78 UiSceneManager::UiSceneManager(UiBrowserInterface* browser, | 87 UiSceneManager::UiSceneManager(UiBrowserInterface* browser, |
| 79 UiScene* scene, | 88 UiScene* scene, |
| 80 bool in_cct, | 89 bool in_cct, |
| 81 bool in_web_vr) | 90 bool in_web_vr) |
| 82 : browser_(browser), | 91 : browser_(browser), |
| 83 scene_(scene), | 92 scene_(scene), |
| 84 in_cct_(in_cct), | 93 in_cct_(in_cct), |
| 85 web_vr_mode_(in_web_vr), | 94 web_vr_mode_(in_web_vr), |
| 86 weak_ptr_factory_(this) { | 95 weak_ptr_factory_(this) { |
| 87 CreateBackground(); | 96 CreateBackground(); |
| 88 CreateContentQuad(); | 97 CreateContentQuad(); |
| 89 CreateSecurityWarnings(); | 98 CreateSecurityWarnings(); |
| 90 CreateSystemIndicators(); | 99 CreateSystemIndicators(); |
| 91 CreateUrlBar(); | 100 CreateUrlBar(); |
| 92 if (in_cct_) | 101 CreateCloseButton(); |
| 93 CreateCloseButton(); | |
| 94 CreateScreenDimmer(); | 102 CreateScreenDimmer(); |
| 95 | 103 |
| 96 ConfigureScene(); | 104 ConfigureScene(); |
| 97 ConfigureSecurityWarnings(); | 105 ConfigureSecurityWarnings(); |
| 98 } | 106 } |
| 99 | 107 |
| 100 UiSceneManager::~UiSceneManager() {} | 108 UiSceneManager::~UiSceneManager() {} |
| 101 | 109 |
| 102 void UiSceneManager::CreateScreenDimmer() { | 110 void UiSceneManager::CreateScreenDimmer() { |
| 103 std::unique_ptr<UiElement> element; | 111 std::unique_ptr<UiElement> element; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 296 |
| 289 void UiSceneManager::CreateCloseButton() { | 297 void UiSceneManager::CreateCloseButton() { |
| 290 std::unique_ptr<Button> element = base::MakeUnique<Button>( | 298 std::unique_ptr<Button> element = base::MakeUnique<Button>( |
| 291 base::Bind(&UiSceneManager::OnCloseButtonClicked, base::Unretained(this)), | 299 base::Bind(&UiSceneManager::OnCloseButtonClicked, base::Unretained(this)), |
| 292 base::MakeUnique<CloseButtonTexture>()); | 300 base::MakeUnique<CloseButtonTexture>()); |
| 293 element->set_debug_id(kCloseButton); | 301 element->set_debug_id(kCloseButton); |
| 294 element->set_id(AllocateId()); | 302 element->set_id(AllocateId()); |
| 295 element->set_fill(vr_shell::Fill::NONE); | 303 element->set_fill(vr_shell::Fill::NONE); |
| 296 element->set_translation( | 304 element->set_translation( |
| 297 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, | 305 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, |
| 298 -kContentDistance + 0.4)); | 306 -kCloseButtonDistance)); |
| 299 element->set_size(gfx::Vector3dF(0.2, 0.2, 1)); | 307 element->set_size(gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1)); |
| 300 control_elements_.push_back(element.get()); | 308 close_button_ = element.get(); |
| 301 scene_->AddUiElement(std::move(element)); | 309 scene_->AddUiElement(std::move(element)); |
| 302 } | 310 } |
| 303 | 311 |
| 304 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 312 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
| 305 return weak_ptr_factory_.GetWeakPtr(); | 313 return weak_ptr_factory_.GetWeakPtr(); |
| 306 } | 314 } |
| 307 | 315 |
| 308 void UiSceneManager::SetWebVrMode(bool web_vr) { | 316 void UiSceneManager::SetWebVrMode(bool web_vr) { |
| 309 if (web_vr_mode_ == web_vr) | 317 if (web_vr_mode_ == web_vr) |
| 310 return; | 318 return; |
| 311 web_vr_mode_ = web_vr; | 319 web_vr_mode_ = web_vr; |
| 312 ConfigureScene(); | 320 ConfigureScene(); |
| 313 ConfigureSecurityWarnings(); | 321 ConfigureSecurityWarnings(); |
| 314 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); | 322 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); |
| 315 video_capture_indicator_->set_visible(!web_vr && video_capturing_); | 323 video_capture_indicator_->set_visible(!web_vr && video_capturing_); |
| 316 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); | 324 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); |
| 317 } | 325 } |
| 318 | 326 |
| 319 void UiSceneManager::ConfigureScene() { | 327 void UiSceneManager::ConfigureScene() { |
| 320 exit_warning_->SetEnabled(scene_->is_exiting()); | 328 exit_warning_->SetEnabled(scene_->is_exiting()); |
| 321 screen_dimmer_->SetEnabled(scene_->is_exiting()); | 329 screen_dimmer_->SetEnabled(scene_->is_exiting()); |
| 322 | 330 |
| 323 // Controls (URL bar, loading progress, etc). | 331 // Controls (URL bar, loading progress, etc). |
| 324 bool controls_visible = !web_vr_mode_ && !fullscreen_; | 332 bool controls_visible = !web_vr_mode_ && !fullscreen_; |
| 325 for (UiElement* element : control_elements_) { | 333 for (UiElement* element : control_elements_) { |
| 326 element->SetEnabled(controls_visible); | 334 element->SetEnabled(controls_visible); |
| 327 } | 335 } |
| 328 | 336 |
| 337 // Close button is a special control element that needs to be hidden when in |
| 338 // WebVR, but it needs to be visible when in cct or fullscreen. |
| 339 close_button_->SetEnabled(!web_vr_mode_ && (fullscreen_ || in_cct_)); |
| 340 |
| 329 // Content elements. | 341 // Content elements. |
| 330 for (UiElement* element : content_elements_) { | 342 for (UiElement* element : content_elements_) { |
| 331 element->SetEnabled(!web_vr_mode_); | 343 element->SetEnabled(!web_vr_mode_); |
| 332 } | 344 } |
| 333 | 345 |
| 334 // Update content quad parameters depending on fullscreen. | 346 // Update content quad parameters depending on fullscreen. |
| 335 // TODO(http://crbug.com/642937): Animate fullscreen transitions. | 347 // TODO(http://crbug.com/642937): Animate fullscreen transitions. |
| 336 if (fullscreen_) { | 348 if (fullscreen_) { |
| 337 main_content_->set_translation( | 349 main_content_->set_translation( |
| 338 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); | 350 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); |
| 339 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); | 351 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); |
| 352 |
| 353 close_button_->set_translation(gfx::Vector3dF( |
| 354 0, kFullscreenVerticalOffset - (kFullscreenHeight / 2) - 0.35, |
| 355 -kCloseButtonFullscreenDistance)); |
| 356 close_button_->set_size(gfx::Vector3dF(kCloseButtonFullscreenWidth, |
| 357 kCloseButtonFullscreenHeight, 1)); |
| 340 } else { | 358 } else { |
| 341 // Note that main_content_ is already visible in this case. | 359 // Note that main_content_ is already visible in this case. |
| 342 main_content_->set_translation( | 360 main_content_->set_translation( |
| 343 {0, kContentVerticalOffset, -kContentDistance}); | 361 {0, kContentVerticalOffset, -kContentDistance}); |
| 344 main_content_->set_size({kContentWidth, kContentHeight, 1}); | 362 main_content_->set_size({kContentWidth, kContentHeight, 1}); |
| 363 |
| 364 close_button_->set_translation( |
| 365 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, |
| 366 -kCloseButtonDistance)); |
| 367 close_button_->set_size( |
| 368 gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1)); |
| 345 } | 369 } |
| 346 | 370 |
| 347 scene_->SetMode(mode()); | 371 scene_->SetMode(mode()); |
| 348 scene_->SetBackgroundDistance(main_content_->translation().z() * | 372 scene_->SetBackgroundDistance(main_content_->translation().z() * |
| 349 -kBackgroundDistanceMultiplier); | 373 -kBackgroundDistanceMultiplier); |
| 350 UpdateBackgroundColor(); | 374 UpdateBackgroundColor(); |
| 351 } | 375 } |
| 352 | 376 |
| 353 void UiSceneManager::UpdateBackgroundColor() { | 377 void UiSceneManager::UpdateBackgroundColor() { |
| 354 // TODO(vollick): it would be nice if ceiling, floor and the grid were | 378 // TODO(vollick): it would be nice if ceiling, floor and the grid were |
| 355 // UiElement subclasses and could respond to the OnSetMode signal. | 379 // UiElement subclasses and could respond to the OnSetMode signal. |
| 356 ceiling_->set_center_color(color_scheme().ceiling); | 380 ceiling_->set_center_color(color_scheme().ceiling); |
| 357 ceiling_->set_edge_color(color_scheme().horizon); | 381 ceiling_->set_edge_color(color_scheme().world_background); |
| 358 floor_->set_center_color(color_scheme().floor); | 382 floor_->set_center_color(color_scheme().floor); |
| 359 floor_->set_edge_color(color_scheme().horizon); | 383 floor_->set_edge_color(color_scheme().world_background); |
| 360 floor_->set_grid_color(color_scheme().floor_grid); | 384 floor_->set_grid_color(color_scheme().floor_grid); |
| 361 } | 385 } |
| 362 | 386 |
| 363 void UiSceneManager::SetAudioCapturingIndicator(bool enabled) { | 387 void UiSceneManager::SetAudioCapturingIndicator(bool enabled) { |
| 364 audio_capturing_ = enabled; | 388 audio_capturing_ = enabled; |
| 365 audio_capture_indicator_->set_visible(enabled && !web_vr_mode_); | 389 audio_capture_indicator_->set_visible(enabled && !web_vr_mode_); |
| 366 } | 390 } |
| 367 | 391 |
| 368 void UiSceneManager::SetVideoCapturingIndicator(bool enabled) { | 392 void UiSceneManager::SetVideoCapturingIndicator(bool enabled) { |
| 369 video_capturing_ = enabled; | 393 video_capturing_ = enabled; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 scene_->set_is_exiting(); | 470 scene_->set_is_exiting(); |
| 447 ConfigureScene(); | 471 ConfigureScene(); |
| 448 } | 472 } |
| 449 | 473 |
| 450 void UiSceneManager::SetHistoryButtonsEnabled(bool can_go_back, | 474 void UiSceneManager::SetHistoryButtonsEnabled(bool can_go_back, |
| 451 bool can_go_forward) { | 475 bool can_go_forward) { |
| 452 url_bar_->SetHistoryButtonsEnabled(can_go_back); | 476 url_bar_->SetHistoryButtonsEnabled(can_go_back); |
| 453 } | 477 } |
| 454 | 478 |
| 455 void UiSceneManager::OnCloseButtonClicked() { | 479 void UiSceneManager::OnCloseButtonClicked() { |
| 456 browser_->ExitCct(); | 480 if (fullscreen_) { |
| 481 browser_->ExitFullscreen(); |
| 482 } |
| 483 if (in_cct_) { |
| 484 browser_->ExitCct(); |
| 485 } |
| 457 } | 486 } |
| 458 | 487 |
| 459 void UiSceneManager::OnUnsupportedMode(UiUnsupportedMode mode) { | 488 void UiSceneManager::OnUnsupportedMode(UiUnsupportedMode mode) { |
| 460 browser_->OnUnsupportedMode(mode); | 489 browser_->OnUnsupportedMode(mode); |
| 461 } | 490 } |
| 462 | 491 |
| 463 int UiSceneManager::AllocateId() { | 492 int UiSceneManager::AllocateId() { |
| 464 return next_available_id_++; | 493 return next_available_id_++; |
| 465 } | 494 } |
| 466 | 495 |
| 467 ColorScheme::Mode UiSceneManager::mode() const { | 496 ColorScheme::Mode UiSceneManager::mode() const { |
| 468 if (incognito_) | 497 if (incognito_) |
| 469 return ColorScheme::kModeIncognito; | 498 return ColorScheme::kModeIncognito; |
| 470 if (fullscreen_) | 499 if (fullscreen_) |
| 471 return ColorScheme::kModeFullscreen; | 500 return ColorScheme::kModeFullscreen; |
| 472 return ColorScheme::kModeNormal; | 501 return ColorScheme::kModeNormal; |
| 473 } | 502 } |
| 474 | 503 |
| 475 const ColorScheme& UiSceneManager::color_scheme() const { | 504 const ColorScheme& UiSceneManager::color_scheme() const { |
| 476 return ColorScheme::GetColorScheme(mode()); | 505 return ColorScheme::GetColorScheme(mode()); |
| 477 } | 506 } |
| 478 | 507 |
| 479 } // namespace vr_shell | 508 } // namespace vr_shell |
| OLD | NEW |