Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: chrome/browser/android/vr_shell/ui_scene_manager.cc

Issue 2955023002: VR: Factor transient timing out of UiSceneManager. (Closed)
Patch Set: Get rid of EndVisibility(). Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 element->set_fill(vr_shell::Fill::NONE); 399 element->set_fill(vr_shell::Fill::NONE);
400 element->set_size({kExitPromptBackplaneSize, kExitPromptBackplaneSize, 1.0}); 400 element->set_size({kExitPromptBackplaneSize, kExitPromptBackplaneSize, 1.0});
401 element->set_translation({0.0, 0.0, -kTextureOffset}); 401 element->set_translation({0.0, 0.0, -kTextureOffset});
402 element->set_parent_id(exit_prompt_->id()); 402 element->set_parent_id(exit_prompt_->id());
403 exit_prompt_backplane_ = element.get(); 403 exit_prompt_backplane_ = element.get();
404 content_elements_.push_back(element.get()); 404 content_elements_.push_back(element.get());
405 scene_->AddUiElement(std::move(element)); 405 scene_->AddUiElement(std::move(element));
406 } 406 }
407 407
408 void UiSceneManager::CreateToasts() { 408 void UiSceneManager::CreateToasts() {
409 std::unique_ptr<UiElement> element = base::MakeUnique<PresentationToast>(512); 409 auto element = base::MakeUnique<PresentationToast>(
410 512, base::TimeDelta::FromSeconds(kToastTimeoutSeconds));
410 element->set_debug_id(kPresentationToast); 411 element->set_debug_id(kPresentationToast);
411 element->set_id(AllocateId()); 412 element->set_id(AllocateId());
412 element->set_fill(vr_shell::Fill::NONE); 413 element->set_fill(vr_shell::Fill::NONE);
413 element->set_size({kToastWidth, kToastHeight, 1}); 414 element->set_size({kToastWidth, kToastHeight, 1});
414 element->set_translation({0, 0, -kToastDistance}); 415 element->set_translation({0, 0, -kToastDistance});
415 element->set_visible(false); 416 element->set_visible(false);
416 element->set_hit_testable(false); 417 element->set_hit_testable(false);
417 element->set_lock_to_fov(true); 418 element->set_lock_to_fov(true);
418 presentation_toast_ = element.get(); 419 presentation_toast_ = element.get();
419 scene_->AddUiElement(std::move(element)); 420 scene_->AddUiElement(std::move(element));
420 } 421 }
421 422
422 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { 423 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() {
423 return weak_ptr_factory_.GetWeakPtr(); 424 return weak_ptr_factory_.GetWeakPtr();
424 } 425 }
425 426
426 void UiSceneManager::SetWebVrMode(bool web_vr, 427 void UiSceneManager::SetWebVrMode(bool web_vr,
427 bool auto_presented, 428 bool auto_presented,
428 bool show_toast) { 429 bool show_toast) {
429 if (web_vr_mode_ == web_vr && web_vr_autopresented_ == auto_presented && 430 if (web_vr_mode_ == web_vr && web_vr_autopresented_ == auto_presented &&
430 web_vr_show_toast_ == show_toast) { 431 web_vr_show_toast_ == show_toast) {
431 return; 432 return;
432 } 433 }
434 // If leaving WebVR, disable the toast. ConfigureScene will re-enable it if
435 // necessary.
436 if (!web_vr)
437 presentation_toast_->SetEnabled(false);
bshe 2017/06/27 14:57:09 Do you need this? Isn't ConfigureScene set enable
cjgrant 2017/06/28 19:00:55 See the reworked version, where we need the few li
438
433 web_vr_mode_ = web_vr; 439 web_vr_mode_ = web_vr;
434 web_vr_autopresented_ = auto_presented; 440 web_vr_autopresented_ = auto_presented;
435 web_vr_show_toast_ = show_toast; 441 web_vr_show_toast_ = show_toast;
436 toast_state_ = SET_FOR_WEB_VR;
437 ConfigureScene(); 442 ConfigureScene();
438 ConfigureSecurityWarnings(); 443 ConfigureSecurityWarnings();
439 ConfigureTransientUrlBar(); 444 ConfigureTransientUrlBar();
440 ConfigurePresentationToast(); 445
446 if (web_vr)
bshe 2017/06/27 14:57:09 Should this be if (web_vr && show_toast)? It still
cjgrant 2017/06/28 19:00:55 I think, as it is, this is better. It's more clea
447 presentation_toast_->transience()->KickVisibility();
441 } 448 }
442 449
443 void UiSceneManager::ConfigureScene() { 450 void UiSceneManager::ConfigureScene() {
444 exit_warning_->SetEnabled(scene_->is_exiting()); 451 exit_warning_->SetEnabled(scene_->is_exiting());
445 screen_dimmer_->SetEnabled(scene_->is_exiting()); 452 screen_dimmer_->SetEnabled(scene_->is_exiting());
446 453
447 // Controls (URL bar, loading progress, etc). 454 // Controls (URL bar, loading progress, etc).
448 bool controls_visible = !web_vr_mode_ && !fullscreen_; 455 bool controls_visible = !web_vr_mode_ && !fullscreen_;
449 for (UiElement* element : control_elements_) { 456 for (UiElement* element : control_elements_) {
450 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); 457 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 -kCloseButtonDistance)); 499 -kCloseButtonDistance));
493 close_button_->set_size( 500 close_button_->set_size(
494 gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1)); 501 gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1));
495 } 502 }
496 503
497 scene_->SetMode(mode()); 504 scene_->SetMode(mode());
498 scene_->SetBackgroundDistance(main_content_->translation().z() * 505 scene_->SetBackgroundDistance(main_content_->translation().z() *
499 -kBackgroundDistanceMultiplier); 506 -kBackgroundDistanceMultiplier);
500 UpdateBackgroundColor(); 507 UpdateBackgroundColor();
501 508
509 presentation_toast_->SetEnabled((fullscreen_ && !web_vr_mode_) ||
510 (web_vr_mode_ && web_vr_show_toast_));
511
502 // Configure other subsystems here as well. Ultimately, it would be nice if we 512 // Configure other subsystems here as well. Ultimately, it would be nice if we
503 // could configure all elements through ConfigureScene(), as the exact 513 // could configure all elements through ConfigureScene(), as the exact
504 // conditions that control each element are getting complicated. More systems 514 // conditions that control each element are getting complicated. More systems
505 // should move in here, such that a single method call can update the entire 515 // should move in here, such that a single method call can update the entire
506 // scene. The drawback is slightly more overhead for individual scene 516 // scene. The drawback is slightly more overhead for individual scene
507 // reconfigurations. 517 // reconfigurations.
508 ConfigureIndicators(); 518 ConfigureIndicators();
509 } 519 }
510 520
511 void UiSceneManager::UpdateBackgroundColor() { 521 void UiSceneManager::UpdateBackgroundColor() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 browser_->ExitFullscreen(); 572 browser_->ExitFullscreen();
563 } 573 }
564 574
565 void UiSceneManager::OnAppButtonGesturePerformed( 575 void UiSceneManager::OnAppButtonGesturePerformed(
566 UiInterface::Direction direction) {} 576 UiInterface::Direction direction) {}
567 577
568 void UiSceneManager::SetFullscreen(bool fullscreen) { 578 void UiSceneManager::SetFullscreen(bool fullscreen) {
569 if (fullscreen_ == fullscreen) 579 if (fullscreen_ == fullscreen)
570 return; 580 return;
571 fullscreen_ = fullscreen; 581 fullscreen_ = fullscreen;
572 toast_state_ = SET_FOR_FULLSCREEN;
573 ConfigureScene(); 582 ConfigureScene();
574 ConfigurePresentationToast(); 583 presentation_toast_->transience()->KickVisibility();
575 } 584 }
576 585
577 void UiSceneManager::ConfigureSecurityWarnings() { 586 void UiSceneManager::ConfigureSecurityWarnings() {
578 bool enabled = web_vr_mode_ && !secure_origin_; 587 bool enabled = web_vr_mode_ && !secure_origin_;
579 permanent_security_warning_->set_visible(enabled); 588 permanent_security_warning_->set_visible(enabled);
580 transient_security_warning_->set_visible(enabled); 589 transient_security_warning_->set_visible(enabled);
581 if (enabled) { 590 if (enabled) {
591 security_warning_timer_.Stop();
bshe 2017/06/27 14:57:09 Stop shouldn't be necessary I believe. Start would
cjgrant 2017/06/28 19:00:55 Done.
582 security_warning_timer_.Start( 592 security_warning_timer_.Start(
583 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, 593 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this,
584 &UiSceneManager::OnSecurityWarningTimer); 594 &UiSceneManager::OnSecurityWarningTimer);
585 } else { 595 } else {
586 security_warning_timer_.Stop(); 596 security_warning_timer_.Stop();
587 } 597 }
588 } 598 }
589 599
590 void UiSceneManager::ConfigureIndicators() { 600 void UiSceneManager::ConfigureIndicators() {
591 bool allowed = !web_vr_mode_ && !fullscreen_; 601 bool allowed = !web_vr_mode_ && !fullscreen_;
592 audio_capture_indicator_->set_visible(allowed && audio_capturing_); 602 audio_capture_indicator_->set_visible(allowed && audio_capturing_);
593 video_capture_indicator_->set_visible(allowed && video_capturing_); 603 video_capture_indicator_->set_visible(allowed && video_capturing_);
594 screen_capture_indicator_->set_visible(allowed && screen_capturing_); 604 screen_capture_indicator_->set_visible(allowed && screen_capturing_);
595 location_access_indicator_->set_visible(allowed && location_access_); 605 location_access_indicator_->set_visible(allowed && location_access_);
596 606
597 if (!allowed) 607 if (!allowed)
598 return; 608 return;
599 609
600 // Position elements dynamically relative to each other, based on which 610 // Position elements dynamically relative to each other, based on which
601 // indicators are showing, and how big each one is. 611 // indicators are showing, and how big each one is.
602 float total_width = 0; 612 float total_width = 0;
603 for (const UiElement* indicator : system_indicators_) { 613 for (const UiElement* indicator : system_indicators_) {
604 if (indicator->visible()) { 614 if (indicator->visible()) {
605 if (total_width > 0) 615 if (total_width > 0)
606 total_width += kIndicatorGap; 616 total_width += kIndicatorGap;
607 total_width += indicator->size().x(); 617 total_width += indicator->size().x();
608 } 618 }
609 } 619 }
620
610 float x_position = -total_width / 2; 621 float x_position = -total_width / 2;
611 for (UiElement* indicator : system_indicators_) { 622 for (UiElement* indicator : system_indicators_) {
612 if (!indicator->visible()) 623 if (!indicator->visible())
613 continue; 624 continue;
614 float width = indicator->size().x(); 625 float width = indicator->size().x();
615 indicator->set_translation({x_position + width / 2, 626 indicator->set_translation({x_position + width / 2,
616 kIndicatorVerticalOffset, 627 kIndicatorVerticalOffset,
617 kIndicatorDistanceOffset}); 628 kIndicatorDistanceOffset});
618 x_position += width + kIndicatorGap; 629 x_position += width + kIndicatorGap;
619 } 630 }
620 } 631 }
621 632
622 void UiSceneManager::ConfigurePresentationToast() {
623 bool toast_visible = false;
624 switch (toast_state_) {
625 case SET_FOR_WEB_VR:
626 toast_visible = web_vr_show_toast_;
627 break;
628 case SET_FOR_FULLSCREEN:
629 toast_visible = fullscreen_;
630 break;
631 case UNCHANGED:
632 return;
633 }
634 presentation_toast_->set_visible(toast_visible);
635 if (toast_visible) {
636 presentation_toast_timer_.Start(
637 FROM_HERE, base::TimeDelta::FromSeconds(kToastTimeoutSeconds), this,
638 &UiSceneManager::OnPresentationToastTimer);
639 } else {
640 presentation_toast_timer_.Stop();
641 }
642 toast_state_ = UNCHANGED;
643 }
644
645 void UiSceneManager::OnSecurityWarningTimer() { 633 void UiSceneManager::OnSecurityWarningTimer() {
634 // TODO: Also do this one!
bshe 2017/06/27 14:57:09 Add ldap or create a crbug?
cjgrant 2017/06/27 15:15:55 I'm planning to do this before submitting. I post
cjgrant 2017/06/28 19:00:55 Done.
646 transient_security_warning_->set_visible(false); 635 transient_security_warning_->set_visible(false);
647 } 636 }
648 637
649 void UiSceneManager::ConfigureTransientUrlBar() { 638 void UiSceneManager::ConfigureTransientUrlBar() {
650 bool enabled = web_vr_mode_ && web_vr_autopresented_; 639 bool enabled = web_vr_mode_ && web_vr_autopresented_;
651 transient_url_bar_->set_visible(enabled); 640 transient_url_bar_->set_visible(enabled);
652 if (enabled) { 641 if (enabled) {
653 transient_url_bar_timer_.Start( 642 transient_url_bar_timer_.Start(
654 FROM_HERE, base::TimeDelta::FromSeconds(kTransientUrlBarTimeoutSeconds), 643 FROM_HERE, base::TimeDelta::FromSeconds(kTransientUrlBarTimeoutSeconds),
655 this, &UiSceneManager::OnTransientUrlBarTimer); 644 this, &UiSceneManager::OnTransientUrlBarTimer);
656 } else { 645 } else {
657 transient_url_bar_timer_.Stop(); 646 transient_url_bar_timer_.Stop();
658 } 647 }
659 } 648 }
660 649
661 void UiSceneManager::OnTransientUrlBarTimer() { 650 void UiSceneManager::OnTransientUrlBarTimer() {
662 transient_url_bar_->set_visible(false); 651 transient_url_bar_->set_visible(false);
663 } 652 }
664 653
665 void UiSceneManager::OnPresentationToastTimer() {
666 presentation_toast_->set_visible(false);
667 }
668
669 void UiSceneManager::OnBackButtonClicked() { 654 void UiSceneManager::OnBackButtonClicked() {
670 browser_->NavigateBack(); 655 browser_->NavigateBack();
671 } 656 }
672 657
673 void UiSceneManager::OnSecurityIconClickedForTesting() { 658 void UiSceneManager::OnSecurityIconClickedForTesting() {
674 OnSecurityIconClicked(); 659 OnSecurityIconClicked();
675 } 660 }
676 661
677 void UiSceneManager::OnExitPromptPrimaryButtonClickedForTesting() { 662 void UiSceneManager::OnExitPromptPrimaryButtonClickedForTesting() {
678 OnExitPromptPrimaryButtonClicked(); 663 OnExitPromptPrimaryButtonClicked();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 if (fullscreen_) 743 if (fullscreen_)
759 return ColorScheme::kModeFullscreen; 744 return ColorScheme::kModeFullscreen;
760 return ColorScheme::kModeNormal; 745 return ColorScheme::kModeNormal;
761 } 746 }
762 747
763 const ColorScheme& UiSceneManager::color_scheme() const { 748 const ColorScheme& UiSceneManager::color_scheme() const {
764 return ColorScheme::GetColorScheme(mode()); 749 return ColorScheme::GetColorScheme(mode());
765 } 750 }
766 751
767 } // namespace vr_shell 752 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698