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

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: 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 }
433 web_vr_mode_ = web_vr; 434 web_vr_mode_ = web_vr;
434 web_vr_autopresented_ = auto_presented; 435 web_vr_autopresented_ = auto_presented;
435 web_vr_show_toast_ = show_toast; 436 web_vr_show_toast_ = show_toast;
436 toast_state_ = SET_FOR_WEB_VR;
437 ConfigureScene(); 437 ConfigureScene();
438 ConfigureSecurityWarnings(); 438 ConfigureSecurityWarnings();
439 ConfigureTransientUrlBar(); 439 ConfigureTransientUrlBar();
440 ConfigurePresentationToast(); 440
441 if (!web_vr) {
442 // We may be returning to fullscreen, but we don't want to show the toast.
443 presentation_toast_->transience()->EndVisibility();
cjgrant 2017/06/26 20:39:35 Biao, please note the logic here. Basically, when
bshe 2017/06/27 14:57:09 It was previously hided I believe and I agree with
444 } else {
445 presentation_toast_->transience()->KickVisibility();
446 }
441 } 447 }
442 448
443 void UiSceneManager::ConfigureScene() { 449 void UiSceneManager::ConfigureScene() {
444 exit_warning_->SetEnabled(scene_->is_exiting()); 450 exit_warning_->SetEnabled(scene_->is_exiting());
445 screen_dimmer_->SetEnabled(scene_->is_exiting()); 451 screen_dimmer_->SetEnabled(scene_->is_exiting());
446 452
447 // Controls (URL bar, loading progress, etc). 453 // Controls (URL bar, loading progress, etc).
448 bool controls_visible = !web_vr_mode_ && !fullscreen_; 454 bool controls_visible = !web_vr_mode_ && !fullscreen_;
449 for (UiElement* element : control_elements_) { 455 for (UiElement* element : control_elements_) {
450 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit()); 456 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 -kCloseButtonDistance)); 498 -kCloseButtonDistance));
493 close_button_->set_size( 499 close_button_->set_size(
494 gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1)); 500 gfx::Vector3dF(kCloseButtonWidth, kCloseButtonHeight, 1));
495 } 501 }
496 502
497 scene_->SetMode(mode()); 503 scene_->SetMode(mode());
498 scene_->SetBackgroundDistance(main_content_->translation().z() * 504 scene_->SetBackgroundDistance(main_content_->translation().z() *
499 -kBackgroundDistanceMultiplier); 505 -kBackgroundDistanceMultiplier);
500 UpdateBackgroundColor(); 506 UpdateBackgroundColor();
501 507
508 presentation_toast_->SetEnabled((fullscreen_ && !web_vr_mode_) ||
509 (web_vr_mode_ && web_vr_show_toast_));
510
502 // Configure other subsystems here as well. Ultimately, it would be nice if we 511 // Configure other subsystems here as well. Ultimately, it would be nice if we
503 // could configure all elements through ConfigureScene(), as the exact 512 // could configure all elements through ConfigureScene(), as the exact
504 // conditions that control each element are getting complicated. More systems 513 // 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 514 // 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 515 // scene. The drawback is slightly more overhead for individual scene
507 // reconfigurations. 516 // reconfigurations.
508 ConfigureIndicators(); 517 ConfigureIndicators();
509 } 518 }
510 519
511 void UiSceneManager::UpdateBackgroundColor() { 520 void UiSceneManager::UpdateBackgroundColor() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 browser_->ExitFullscreen(); 571 browser_->ExitFullscreen();
563 } 572 }
564 573
565 void UiSceneManager::OnAppButtonGesturePerformed( 574 void UiSceneManager::OnAppButtonGesturePerformed(
566 UiInterface::Direction direction) {} 575 UiInterface::Direction direction) {}
567 576
568 void UiSceneManager::SetFullscreen(bool fullscreen) { 577 void UiSceneManager::SetFullscreen(bool fullscreen) {
569 if (fullscreen_ == fullscreen) 578 if (fullscreen_ == fullscreen)
570 return; 579 return;
571 fullscreen_ = fullscreen; 580 fullscreen_ = fullscreen;
572 toast_state_ = SET_FOR_FULLSCREEN;
573 ConfigureScene(); 581 ConfigureScene();
574 ConfigurePresentationToast(); 582 presentation_toast_->transience()->KickVisibility();
575 } 583 }
576 584
577 void UiSceneManager::ConfigureSecurityWarnings() { 585 void UiSceneManager::ConfigureSecurityWarnings() {
578 bool enabled = web_vr_mode_ && !secure_origin_; 586 bool enabled = web_vr_mode_ && !secure_origin_;
579 permanent_security_warning_->set_visible(enabled); 587 permanent_security_warning_->set_visible(enabled);
580 transient_security_warning_->set_visible(enabled); 588 transient_security_warning_->set_visible(enabled);
581 if (enabled) { 589 if (enabled) {
590 security_warning_timer_.Stop();
582 security_warning_timer_.Start( 591 security_warning_timer_.Start(
583 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, 592 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this,
584 &UiSceneManager::OnSecurityWarningTimer); 593 &UiSceneManager::OnSecurityWarningTimer);
585 } else { 594 } else {
586 security_warning_timer_.Stop(); 595 security_warning_timer_.Stop();
587 } 596 }
588 } 597 }
589 598
590 void UiSceneManager::ConfigureIndicators() { 599 void UiSceneManager::ConfigureIndicators() {
591 bool allowed = !web_vr_mode_ && !fullscreen_; 600 bool allowed = !web_vr_mode_ && !fullscreen_;
592 audio_capture_indicator_->set_visible(allowed && audio_capturing_); 601 audio_capture_indicator_->set_visible(allowed && audio_capturing_);
593 video_capture_indicator_->set_visible(allowed && video_capturing_); 602 video_capture_indicator_->set_visible(allowed && video_capturing_);
594 screen_capture_indicator_->set_visible(allowed && screen_capturing_); 603 screen_capture_indicator_->set_visible(allowed && screen_capturing_);
595 location_access_indicator_->set_visible(allowed && location_access_); 604 location_access_indicator_->set_visible(allowed && location_access_);
596 605
597 if (!allowed) 606 if (!allowed)
598 return; 607 return;
599 608
600 // Position elements dynamically relative to each other, based on which 609 // Position elements dynamically relative to each other, based on which
601 // indicators are showing, and how big each one is. 610 // indicators are showing, and how big each one is.
602 float total_width = 0; 611 float total_width = 0;
603 for (const UiElement* indicator : system_indicators_) { 612 for (const UiElement* indicator : system_indicators_) {
604 if (indicator->visible()) { 613 if (indicator->visible()) {
605 if (total_width > 0) 614 if (total_width > 0)
606 total_width += kIndicatorGap; 615 total_width += kIndicatorGap;
607 total_width += indicator->size().x(); 616 total_width += indicator->size().x();
608 } 617 }
609 } 618 }
619
610 float x_position = -total_width / 2; 620 float x_position = -total_width / 2;
611 for (UiElement* indicator : system_indicators_) { 621 for (UiElement* indicator : system_indicators_) {
612 if (!indicator->visible()) 622 if (!indicator->visible())
613 continue; 623 continue;
614 float width = indicator->size().x(); 624 float width = indicator->size().x();
615 indicator->set_translation({x_position + width / 2, 625 indicator->set_translation({x_position + width / 2,
616 kIndicatorVerticalOffset, 626 kIndicatorVerticalOffset,
617 kIndicatorDistanceOffset}); 627 kIndicatorDistanceOffset});
618 x_position += width + kIndicatorGap; 628 x_position += width + kIndicatorGap;
619 } 629 }
620 } 630 }
621 631
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() { 632 void UiSceneManager::OnSecurityWarningTimer() {
633 // TODO: Also do this one!
646 transient_security_warning_->set_visible(false); 634 transient_security_warning_->set_visible(false);
647 } 635 }
648 636
649 void UiSceneManager::ConfigureTransientUrlBar() { 637 void UiSceneManager::ConfigureTransientUrlBar() {
650 bool enabled = web_vr_mode_ && web_vr_autopresented_; 638 bool enabled = web_vr_mode_ && web_vr_autopresented_;
651 transient_url_bar_->set_visible(enabled); 639 transient_url_bar_->set_visible(enabled);
652 if (enabled) { 640 if (enabled) {
653 transient_url_bar_timer_.Start( 641 transient_url_bar_timer_.Start(
654 FROM_HERE, base::TimeDelta::FromSeconds(kTransientUrlBarTimeoutSeconds), 642 FROM_HERE, base::TimeDelta::FromSeconds(kTransientUrlBarTimeoutSeconds),
655 this, &UiSceneManager::OnTransientUrlBarTimer); 643 this, &UiSceneManager::OnTransientUrlBarTimer);
656 } else { 644 } else {
657 transient_url_bar_timer_.Stop(); 645 transient_url_bar_timer_.Stop();
658 } 646 }
659 } 647 }
660 648
661 void UiSceneManager::OnTransientUrlBarTimer() { 649 void UiSceneManager::OnTransientUrlBarTimer() {
662 transient_url_bar_->set_visible(false); 650 transient_url_bar_->set_visible(false);
663 } 651 }
664 652
665 void UiSceneManager::OnPresentationToastTimer() {
666 presentation_toast_->set_visible(false);
667 }
668
669 void UiSceneManager::OnBackButtonClicked() { 653 void UiSceneManager::OnBackButtonClicked() {
670 browser_->NavigateBack(); 654 browser_->NavigateBack();
671 } 655 }
672 656
673 void UiSceneManager::OnSecurityIconClickedForTesting() { 657 void UiSceneManager::OnSecurityIconClickedForTesting() {
674 OnSecurityIconClicked(); 658 OnSecurityIconClicked();
675 } 659 }
676 660
677 void UiSceneManager::OnExitPromptPrimaryButtonClickedForTesting() { 661 void UiSceneManager::OnExitPromptPrimaryButtonClickedForTesting() {
678 OnExitPromptPrimaryButtonClicked(); 662 OnExitPromptPrimaryButtonClicked();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 if (fullscreen_) 742 if (fullscreen_)
759 return ColorScheme::kModeFullscreen; 743 return ColorScheme::kModeFullscreen;
760 return ColorScheme::kModeNormal; 744 return ColorScheme::kModeNormal;
761 } 745 }
762 746
763 const ColorScheme& UiSceneManager::color_scheme() const { 747 const ColorScheme& UiSceneManager::color_scheme() const {
764 return ColorScheme::GetColorScheme(mode()); 748 return ColorScheme::GetColorScheme(mode());
765 } 749 }
766 750
767 } // namespace vr_shell 751 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.h ('k') | chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698