| 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_warning.h" | 14 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" |
| 14 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" | 15 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" |
| 15 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" | 16 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning
.h" |
| 16 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h
" | 17 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h
" |
| 17 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" | 18 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" |
| 18 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" | 19 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning
.h" |
| 19 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" | 20 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 20 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" | 21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" |
| 21 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" | 22 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" |
| 22 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" | 23 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 static constexpr float kExitWarningHeight = 0.160; | 40 static constexpr float kExitWarningHeight = 0.160; |
| 40 static constexpr float kExitWarningWidth = 0.512; | 41 static constexpr float kExitWarningWidth = 0.512; |
| 41 | 42 |
| 42 static constexpr float kContentDistance = 2.5; | 43 static constexpr float kContentDistance = 2.5; |
| 43 static constexpr float kContentWidth = 0.96 * kContentDistance; | 44 static constexpr float kContentWidth = 0.96 * kContentDistance; |
| 44 static constexpr float kContentHeight = 0.64 * kContentDistance; | 45 static constexpr float kContentHeight = 0.64 * kContentDistance; |
| 45 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; | 46 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; |
| 46 static constexpr float kBackplaneSize = 1000.0; | 47 static constexpr float kBackplaneSize = 1000.0; |
| 47 static constexpr float kBackgroundDistanceMultiplier = 1.414; | 48 static constexpr float kBackgroundDistanceMultiplier = 1.414; |
| 48 | 49 |
| 50 static constexpr float kExitPromptWidth = 0.672 * kContentDistance; |
| 51 static constexpr float kExitPromptHeight = 0.2 * kContentDistance; |
| 52 |
| 49 static constexpr float kUrlBarDistance = 2.4; | 53 static constexpr float kUrlBarDistance = 2.4; |
| 50 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; | 54 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; |
| 51 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; | 55 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; |
| 52 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; | 56 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; |
| 53 static constexpr float kUrlBarRotationRad = -0.175; | 57 static constexpr float kUrlBarRotationRad = -0.175; |
| 54 | 58 |
| 55 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; | 59 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; |
| 56 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; | 60 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; |
| 57 static constexpr float kLoadingIndicatorVerticalOffset = | 61 static constexpr float kLoadingIndicatorVerticalOffset = |
| 58 (-kUrlBarVerticalOffset + kContentVerticalOffset - kContentHeight / 2 - | 62 (-kUrlBarVerticalOffset + kContentVerticalOffset - kContentHeight / 2 - |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 213 |
| 210 // Place an invisible but hittable plane behind the content quad, to keep the | 214 // Place an invisible but hittable plane behind the content quad, to keep the |
| 211 // reticle roughly planar with the content if near content. | 215 // reticle roughly planar with the content if near content. |
| 212 element = base::MakeUnique<UiElement>(); | 216 element = base::MakeUnique<UiElement>(); |
| 213 element->set_debug_id(kBackplane); | 217 element->set_debug_id(kBackplane); |
| 214 element->set_id(AllocateId()); | 218 element->set_id(AllocateId()); |
| 215 element->set_fill(vr_shell::Fill::NONE); | 219 element->set_fill(vr_shell::Fill::NONE); |
| 216 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); | 220 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); |
| 217 element->set_translation({0.0, 0.0, -kTextureOffset}); | 221 element->set_translation({0.0, 0.0, -kTextureOffset}); |
| 218 element->set_parent_id(main_content_->id()); | 222 element->set_parent_id(main_content_->id()); |
| 223 main_content_backplane_ = element.get(); |
| 219 content_elements_.push_back(element.get()); | 224 content_elements_.push_back(element.get()); |
| 220 scene_->AddUiElement(std::move(element)); | 225 scene_->AddUiElement(std::move(element)); |
| 221 | 226 |
| 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 |
| 222 // Limit reticle distance to a sphere based on content distance. | 243 // Limit reticle distance to a sphere based on content distance. |
| 223 scene_->SetBackgroundDistance(main_content_->translation().z() * | 244 scene_->SetBackgroundDistance(main_content_->translation().z() * |
| 224 -kBackgroundDistanceMultiplier); | 245 -kBackgroundDistanceMultiplier); |
| 225 } | 246 } |
| 226 | 247 |
| 227 void UiSceneManager::CreateBackground() { | 248 void UiSceneManager::CreateBackground() { |
| 228 std::unique_ptr<UiElement> element; | 249 std::unique_ptr<UiElement> element; |
| 229 | 250 |
| 230 // Floor. | 251 // Floor. |
| 231 element = base::MakeUnique<UiElement>(); | 252 element = base::MakeUnique<UiElement>(); |
| 232 element->set_debug_id(kFloor); | 253 element->set_debug_id(kFloor); |
| 233 element->set_id(AllocateId()); | 254 element->set_id(AllocateId()); |
| 234 element->set_size({kSceneSize, kSceneSize, 1.0}); | 255 element->set_size({kSceneSize, kSceneSize, 1.0}); |
| 235 element->set_translation({0.0, -kSceneHeight / 2, 0.0}); | 256 element->set_translation({0.0, -kSceneHeight / 2, 0.0}); |
| 236 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0}); | 257 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0}); |
| 237 element->set_fill(vr_shell::Fill::GRID_GRADIENT); | 258 element->set_fill(vr_shell::Fill::GRID_GRADIENT); |
| 238 element->set_draw_phase(0); | 259 element->set_draw_phase(0); |
| 239 element->set_gridline_count(kFloorGridlineCount); | 260 element->set_gridline_count(kFloorGridlineCount); |
| 240 floor_ = element.get(); | 261 floor_ = element.get(); |
| 241 content_elements_.push_back(element.get()); | 262 background_elements_.push_back(element.get()); |
| 242 scene_->AddUiElement(std::move(element)); | 263 scene_->AddUiElement(std::move(element)); |
| 243 | 264 |
| 244 // Ceiling. | 265 // Ceiling. |
| 245 element = base::MakeUnique<UiElement>(); | 266 element = base::MakeUnique<UiElement>(); |
| 246 element->set_debug_id(kCeiling); | 267 element->set_debug_id(kCeiling); |
| 247 element->set_id(AllocateId()); | 268 element->set_id(AllocateId()); |
| 248 element->set_size({kSceneSize, kSceneSize, 1.0}); | 269 element->set_size({kSceneSize, kSceneSize, 1.0}); |
| 249 element->set_translation({0.0, kSceneHeight / 2, 0.0}); | 270 element->set_translation({0.0, kSceneHeight / 2, 0.0}); |
| 250 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2}); | 271 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2}); |
| 251 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); | 272 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); |
| 252 element->set_draw_phase(0); | 273 element->set_draw_phase(0); |
| 253 ceiling_ = element.get(); | 274 ceiling_ = element.get(); |
| 254 content_elements_.push_back(element.get()); | 275 background_elements_.push_back(element.get()); |
| 255 scene_->AddUiElement(std::move(element)); | 276 scene_->AddUiElement(std::move(element)); |
| 256 | 277 |
| 257 UpdateBackgroundColor(); | 278 UpdateBackgroundColor(); |
| 258 } | 279 } |
| 259 | 280 |
| 260 void UiSceneManager::CreateUrlBar() { | 281 void UiSceneManager::CreateUrlBar() { |
| 261 // TODO(cjgrant): Incorporate final size and position. | 282 // TODO(cjgrant): Incorporate final size and position. |
| 262 auto url_bar = base::MakeUnique<UrlBar>( | 283 auto url_bar = base::MakeUnique<UrlBar>( |
| 263 512, | 284 512, |
| 285 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this)), |
| 286 base::Bind(&UiSceneManager::OnSecurityIconClicked, |
| 287 base::Unretained(this)), |
| 264 base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this))); | 288 base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this))); |
| 265 url_bar->set_debug_id(kUrlBar); | 289 url_bar->set_debug_id(kUrlBar); |
| 266 url_bar->set_id(AllocateId()); | 290 url_bar->set_id(AllocateId()); |
| 267 url_bar->set_translation({0, kUrlBarVerticalOffset, -kUrlBarDistance}); | 291 url_bar->set_translation({0, kUrlBarVerticalOffset, -kUrlBarDistance}); |
| 268 url_bar->set_rotation({1.0, 0.0, 0.0, kUrlBarRotationRad}); | 292 url_bar->set_rotation({1.0, 0.0, 0.0, kUrlBarRotationRad}); |
| 269 url_bar->set_size({kUrlBarWidth, kUrlBarHeight, 1}); | 293 url_bar->set_size({kUrlBarWidth, kUrlBarHeight, 1}); |
| 270 url_bar->SetBackButtonCallback( | |
| 271 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this))); | |
| 272 url_bar_ = url_bar.get(); | 294 url_bar_ = url_bar.get(); |
| 273 control_elements_.push_back(url_bar.get()); | 295 control_elements_.push_back(url_bar.get()); |
| 274 scene_->AddUiElement(std::move(url_bar)); | 296 scene_->AddUiElement(std::move(url_bar)); |
| 275 | 297 |
| 276 auto indicator = base::MakeUnique<LoadingIndicator>(256); | 298 auto indicator = base::MakeUnique<LoadingIndicator>(256); |
| 277 indicator->set_debug_id(kLoadingIndicator); | 299 indicator->set_debug_id(kLoadingIndicator); |
| 278 indicator->set_id(AllocateId()); | 300 indicator->set_id(AllocateId()); |
| 279 indicator->set_translation( | 301 indicator->set_translation( |
| 280 {0, kLoadingIndicatorVerticalOffset, kLoadingIndicatorDepthOffset}); | 302 {0, kLoadingIndicatorVerticalOffset, kLoadingIndicatorDepthOffset}); |
| 281 indicator->set_size({kLoadingIndicatorWidth, kLoadingIndicatorHeight, 1}); | 303 indicator->set_size({kLoadingIndicatorWidth, kLoadingIndicatorHeight, 1}); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 311 web_vr_mode_ = web_vr; | 333 web_vr_mode_ = web_vr; |
| 312 ConfigureScene(); | 334 ConfigureScene(); |
| 313 ConfigureSecurityWarnings(); | 335 ConfigureSecurityWarnings(); |
| 314 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); | 336 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); |
| 315 video_capture_indicator_->set_visible(!web_vr && video_capturing_); | 337 video_capture_indicator_->set_visible(!web_vr && video_capturing_); |
| 316 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); | 338 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); |
| 317 } | 339 } |
| 318 | 340 |
| 319 void UiSceneManager::ConfigureScene() { | 341 void UiSceneManager::ConfigureScene() { |
| 320 exit_warning_->SetEnabled(scene_->is_exiting()); | 342 exit_warning_->SetEnabled(scene_->is_exiting()); |
| 343 exit_prompt_->SetEnabled(scene_->is_prompting_to_exit()); |
| 321 screen_dimmer_->SetEnabled(scene_->is_exiting()); | 344 screen_dimmer_->SetEnabled(scene_->is_exiting()); |
| 322 | 345 |
| 323 // Controls (URL bar, loading progress, etc). | 346 // Controls (URL bar, loading progress, etc). |
| 324 bool controls_visible = !web_vr_mode_ && !fullscreen_; | 347 bool controls_visible = !web_vr_mode_ && !fullscreen_; |
| 325 for (UiElement* element : control_elements_) { | 348 for (UiElement* element : control_elements_) { |
| 326 element->SetEnabled(controls_visible); | 349 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); |
| 327 } | 350 } |
| 328 | 351 |
| 329 // Content elements. | 352 // Content elements. |
| 330 for (UiElement* element : content_elements_) { | 353 for (UiElement* element : content_elements_) { |
| 354 // We don't want to show the content elements when the exit prompt is |
| 355 // visible. The only content element visible in this case is the invisible |
| 356 // backplane that we add right behind the content rect so that the reticle |
| 357 // doesn't jump when it transitions between the content rect (and the exit |
| 358 // prompt in this case) and the background. |
| 359 bool disabled_for_exit_prompt = |
| 360 element != main_content_backplane_ && scene_->is_prompting_to_exit(); |
| 361 element->SetEnabled(!web_vr_mode_ && !disabled_for_exit_prompt); |
| 362 } |
| 363 |
| 364 // Background elements. |
| 365 for (UiElement* element : background_elements_) { |
| 331 element->SetEnabled(!web_vr_mode_); | 366 element->SetEnabled(!web_vr_mode_); |
| 332 } | 367 } |
| 333 | 368 |
| 334 // Update content quad parameters depending on fullscreen. | 369 // Update content quad parameters depending on fullscreen. |
| 335 // TODO(http://crbug.com/642937): Animate fullscreen transitions. | 370 // TODO(http://crbug.com/642937): Animate fullscreen transitions. |
| 336 if (fullscreen_) { | 371 if (fullscreen_) { |
| 337 main_content_->set_translation( | 372 main_content_->set_translation( |
| 338 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); | 373 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); |
| 339 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); | 374 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); |
| 340 } else { | 375 } else { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 452 } |
| 418 | 453 |
| 419 void UiSceneManager::OnSecurityWarningTimer() { | 454 void UiSceneManager::OnSecurityWarningTimer() { |
| 420 transient_security_warning_->set_visible(false); | 455 transient_security_warning_->set_visible(false); |
| 421 } | 456 } |
| 422 | 457 |
| 423 void UiSceneManager::OnBackButtonClicked() { | 458 void UiSceneManager::OnBackButtonClicked() { |
| 424 browser_->NavigateBack(); | 459 browser_->NavigateBack(); |
| 425 } | 460 } |
| 426 | 461 |
| 462 void UiSceneManager::OnSecurityIconClicked() { |
| 463 if (scene_->is_prompting_to_exit()) |
| 464 return; |
| 465 scene_->set_is_prompting_to_exit(true); |
| 466 ConfigureScene(); |
| 467 } |
| 468 |
| 469 void UiSceneManager::OnExitPromptPrimaryButtonClicked() { |
| 470 if (!scene_->is_prompting_to_exit()) |
| 471 return; |
| 472 scene_->set_is_prompting_to_exit(false); |
| 473 ConfigureScene(); |
| 474 } |
| 475 |
| 476 void UiSceneManager::OnExitPromptSecondaryButtonClicked() { |
| 477 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo); |
| 478 } |
| 479 |
| 427 void UiSceneManager::SetURL(const GURL& gurl) { | 480 void UiSceneManager::SetURL(const GURL& gurl) { |
| 428 url_bar_->SetURL(gurl); | 481 url_bar_->SetURL(gurl); |
| 429 } | 482 } |
| 430 | 483 |
| 431 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { | 484 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { |
| 432 url_bar_->SetSecurityLevel(level); | 485 url_bar_->SetSecurityLevel(level); |
| 433 } | 486 } |
| 434 | 487 |
| 435 void UiSceneManager::SetLoading(bool loading) { | 488 void UiSceneManager::SetLoading(bool loading) { |
| 436 loading_indicator_->SetLoading(loading); | 489 loading_indicator_->SetLoading(loading); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 if (fullscreen_) | 523 if (fullscreen_) |
| 471 return ColorScheme::kModeFullscreen; | 524 return ColorScheme::kModeFullscreen; |
| 472 return ColorScheme::kModeNormal; | 525 return ColorScheme::kModeNormal; |
| 473 } | 526 } |
| 474 | 527 |
| 475 const ColorScheme& UiSceneManager::color_scheme() const { | 528 const ColorScheme& UiSceneManager::color_scheme() const { |
| 476 return ColorScheme::GetColorScheme(mode()); | 529 return ColorScheme::GetColorScheme(mode()); |
| 477 } | 530 } |
| 478 | 531 |
| 479 } // namespace vr_shell | 532 } // namespace vr_shell |
| OLD | NEW |