Commit 21921b98 authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Introduce status area CollapseState and update visibility of trays.

The CollapseState indicates whether the tray is collapsed or expanded or not
collapsable (default behaviour) at all. Currently, the status area will only be
collapsable in tablet mode and in-app.

The visibility logic for individual tray items is also being cleaned up in this
CL, as this logic is fairly complex. We rename SetVisible() to
SetVisiblePreferred() because the effective visibility also depends on factors
such as the virtual keyboard and status area collapse state.

Future CLs will properly update the CollapseState as well as calculate which
tray items should be visible when collapsed.

TEST=unit tests
BUG=982511

Change-Id: I6f6fed7836d0b1dc4991319fb4ec8e58a522da37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903399
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713694}
parent 21811970
...@@ -500,7 +500,7 @@ void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) { ...@@ -500,7 +500,7 @@ void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) {
new_root_window_controller->GetStatusAreaWidget() new_root_window_controller->GetStatusAreaWidget()
->unified_system_tray(); ->unified_system_tray();
if (old_tray->GetWidget()->IsVisible()) { if (old_tray->GetWidget()->IsVisible()) {
new_tray->SetVisible(true); new_tray->SetVisiblePreferred(true);
new_tray->GetWidget()->Show(); new_tray->GetWidget()->Show();
} }
......
...@@ -384,7 +384,7 @@ TEST_F(ScreenRotationAnimatorSlowAnimationTest, ...@@ -384,7 +384,7 @@ TEST_F(ScreenRotationAnimatorSlowAnimationTest,
// Long duration for hide animation, to allow it to be interrupted. // Long duration for hide animation, to allow it to be interrupted.
ui::ScopedAnimationDurationScaleMode hide_duration( ui::ScopedAnimationDurationScaleMode hide_duration(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
GetTray()->SetVisible(false); GetTray()->SetVisiblePreferred(false);
// ScreenRotationAnimator copies the current layers, and deletes them upon // ScreenRotationAnimator copies the current layers, and deletes them upon
// completion. Allow its animation to complete first. // completion. Allow its animation to complete first.
...@@ -615,7 +615,7 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest, ...@@ -615,7 +615,7 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
// Long duration for hide animation, to allow it to be interrupted. // Long duration for hide animation, to allow it to be interrupted.
ui::ScopedAnimationDurationScaleMode hide_duration( ui::ScopedAnimationDurationScaleMode hide_duration(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
GetTray()->SetVisible(false); GetTray()->SetVisiblePreferred(false);
// Allow ScreenRotationAnimator animation to complete first. // Allow ScreenRotationAnimator animation to complete first.
ui::ScopedAnimationDurationScaleMode rotate_duration( ui::ScopedAnimationDurationScaleMode rotate_duration(
......
...@@ -95,7 +95,7 @@ void DictationButtonTray::UpdateIcon(bool dictation_active) { ...@@ -95,7 +95,7 @@ void DictationButtonTray::UpdateIcon(bool dictation_active) {
void DictationButtonTray::UpdateVisibility() { void DictationButtonTray::UpdateVisibility() {
bool is_visible = bool is_visible =
Shell::Get()->accessibility_controller()->dictation_enabled(); Shell::Get()->accessibility_controller()->dictation_enabled();
SetVisible(is_visible); SetVisiblePreferred(is_visible);
} }
void DictationButtonTray::CheckDictationStatusAndUpdateIcon() { void DictationButtonTray::CheckDictationStatusAndUpdateIcon() {
......
...@@ -89,7 +89,7 @@ void SelectToSpeakTray::UpdateIconsForSession() { ...@@ -89,7 +89,7 @@ void SelectToSpeakTray::UpdateIconsForSession() {
void SelectToSpeakTray::CheckStatusAndUpdateIcon() { void SelectToSpeakTray::CheckStatusAndUpdateIcon() {
if (!Shell::Get()->accessibility_controller()->select_to_speak_enabled()) { if (!Shell::Get()->accessibility_controller()->select_to_speak_enabled()) {
SetVisible(false); SetVisiblePreferred(false);
return; return;
} }
...@@ -111,7 +111,7 @@ void SelectToSpeakTray::CheckStatusAndUpdateIcon() { ...@@ -111,7 +111,7 @@ void SelectToSpeakTray::CheckStatusAndUpdateIcon() {
break; break;
} }
SetVisible(true); SetVisiblePreferred(true);
} }
} // namespace ash } // namespace ash
...@@ -489,7 +489,7 @@ void ImeMenuTray::OnIMERefresh() { ...@@ -489,7 +489,7 @@ void ImeMenuTray::OnIMERefresh() {
} }
void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
SetVisible(is_activated); SetVisiblePreferred(is_activated);
if (is_activated) if (is_activated)
UpdateTrayLabel(); UpdateTrayLabel();
else else
......
...@@ -195,7 +195,7 @@ void OverviewButtonTray::UpdateIconVisibility() { ...@@ -195,7 +195,7 @@ void OverviewButtonTray::UpdateIconVisibility() {
bool should_show = bool should_show =
Shell::Get()->tablet_mode_controller()->ShouldShowOverviewButton(); Shell::Get()->tablet_mode_controller()->ShouldShowOverviewButton();
SetVisible(should_show && active_session && !app_mode); SetVisiblePreferred(should_show && active_session && !app_mode);
} }
} // namespace ash } // namespace ash
...@@ -317,7 +317,7 @@ TEST_F(OverviewButtonTrayTest, ActiveStateOnlyDuringOverviewMode) { ...@@ -317,7 +317,7 @@ TEST_F(OverviewButtonTrayTest, ActiveStateOnlyDuringOverviewMode) {
TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletes) { TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletes) {
TabletModeControllerTestApi().EnterTabletMode(); TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(GetTray()->GetVisible()); EXPECT_TRUE(GetTray()->GetVisible());
GetTray()->SetVisible(false); GetTray()->SetVisiblePreferred(false);
EXPECT_FALSE(GetTray()->GetVisible()); EXPECT_FALSE(GetTray()->GetVisible());
} }
...@@ -330,7 +330,7 @@ TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletesOnDelete) { ...@@ -330,7 +330,7 @@ TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletesOnDelete) {
std::unique_ptr<ui::ScopedAnimationDurationScaleMode> hide_duration( std::unique_ptr<ui::ScopedAnimationDurationScaleMode> hide_duration(
new ui::ScopedAnimationDurationScaleMode( new ui::ScopedAnimationDurationScaleMode(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
GetTray()->SetVisible(false); GetTray()->SetVisiblePreferred(false);
aura::Window* root_window = Shell::GetRootWindowForDisplayId( aura::Window* root_window = Shell::GetRootWindowForDisplayId(
display::Screen::GetScreen()->GetPrimaryDisplay().id()); display::Screen::GetScreen()->GetPrimaryDisplay().id());
......
...@@ -558,7 +558,7 @@ void PaletteTray::OnPaletteEnabledPrefChanged() { ...@@ -558,7 +558,7 @@ void PaletteTray::OnPaletteEnabledPrefChanged() {
prefs::kEnableStylusTools); prefs::kEnableStylusTools);
if (!is_palette_enabled_) { if (!is_palette_enabled_) {
SetVisible(false); SetVisiblePreferred(false);
palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE);
} else { } else {
UpdateIconVisibility(); UpdateIconVisibility();
...@@ -591,9 +591,10 @@ bool PaletteTray::HasSeenStylus() { ...@@ -591,9 +591,10 @@ bool PaletteTray::HasSeenStylus() {
} }
void PaletteTray::UpdateIconVisibility() { void PaletteTray::UpdateIconVisibility() {
SetVisible(HasSeenStylus() && is_palette_enabled_ && SetVisiblePreferred(HasSeenStylus() && is_palette_enabled_ &&
stylus_utils::HasStylusInput() && ShouldShowOnDisplay(this) && stylus_utils::HasStylusInput() &&
palette_utils::IsInUserSession()); ShouldShowOnDisplay(this) &&
palette_utils::IsInUserSession());
} }
} // namespace ash } // namespace ash
...@@ -83,8 +83,7 @@ void StatusAreaWidget::Initialize() { ...@@ -83,8 +83,7 @@ void StatusAreaWidget::Initialize() {
virtual_keyboard_tray_->Initialize(); virtual_keyboard_tray_->Initialize();
ime_menu_tray_->Initialize(); ime_menu_tray_->Initialize();
select_to_speak_tray_->Initialize(); select_to_speak_tray_->Initialize();
if (dictation_button_tray_) dictation_button_tray_->Initialize();
dictation_button_tray_->Initialize();
overview_button_tray_->Initialize(); overview_button_tray_->Initialize();
UpdateAfterShelfAlignmentChange(); UpdateAfterShelfAlignmentChange();
UpdateAfterLoginStatusChange( UpdateAfterLoginStatusChange(
...@@ -116,8 +115,7 @@ void StatusAreaWidget::UpdateAfterShelfAlignmentChange() { ...@@ -116,8 +115,7 @@ void StatusAreaWidget::UpdateAfterShelfAlignmentChange() {
virtual_keyboard_tray_->UpdateAfterShelfAlignmentChange(); virtual_keyboard_tray_->UpdateAfterShelfAlignmentChange();
ime_menu_tray_->UpdateAfterShelfAlignmentChange(); ime_menu_tray_->UpdateAfterShelfAlignmentChange();
select_to_speak_tray_->UpdateAfterShelfAlignmentChange(); select_to_speak_tray_->UpdateAfterShelfAlignmentChange();
if (dictation_button_tray_) dictation_button_tray_->UpdateAfterShelfAlignmentChange();
dictation_button_tray_->UpdateAfterShelfAlignmentChange();
palette_tray_->UpdateAfterShelfAlignmentChange(); palette_tray_->UpdateAfterShelfAlignmentChange();
overview_button_tray_->UpdateAfterShelfAlignmentChange(); overview_button_tray_->UpdateAfterShelfAlignmentChange();
status_area_widget_delegate_->UpdateLayout(); status_area_widget_delegate_->UpdateLayout();
...@@ -135,7 +133,7 @@ void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { ...@@ -135,7 +133,7 @@ void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) {
void StatusAreaWidget::SetSystemTrayVisibility(bool visible) { void StatusAreaWidget::SetSystemTrayVisibility(bool visible) {
TrayBackgroundView* tray = unified_system_tray_.get(); TrayBackgroundView* tray = unified_system_tray_.get();
tray->SetVisible(visible); tray->SetVisiblePreferred(visible);
// Opacity is set to prevent flakiness in kiosk browser tests. See // Opacity is set to prevent flakiness in kiosk browser tests. See
// https://crbug.com/624584. // https://crbug.com/624584.
SetOpacity(visible ? 1.f : 0.f); SetOpacity(visible ? 1.f : 0.f);
...@@ -182,8 +180,7 @@ void StatusAreaWidget::SchedulePaint() { ...@@ -182,8 +180,7 @@ void StatusAreaWidget::SchedulePaint() {
logout_button_tray_->SchedulePaint(); logout_button_tray_->SchedulePaint();
ime_menu_tray_->SchedulePaint(); ime_menu_tray_->SchedulePaint();
select_to_speak_tray_->SchedulePaint(); select_to_speak_tray_->SchedulePaint();
if (dictation_button_tray_) dictation_button_tray_->SchedulePaint();
dictation_button_tray_->SchedulePaint();
palette_tray_->SchedulePaint(); palette_tray_->SchedulePaint();
overview_button_tray_->SchedulePaint(); overview_button_tray_->SchedulePaint();
} }
......
...@@ -35,6 +35,10 @@ class VirtualKeyboardTray; ...@@ -35,6 +35,10 @@ class VirtualKeyboardTray;
// on secondary monitors at the login screen). // on secondary monitors at the login screen).
class ASH_EXPORT StatusAreaWidget : public views::Widget { class ASH_EXPORT StatusAreaWidget : public views::Widget {
public: public:
// Whether the status area is collapsed or expanded. Currently, this is only
// applicable in in-app tablet mode. Otherwise the state is NOT_COLLAPSIBLE.
enum class CollapseState { NOT_COLLAPSIBLE, COLLAPSED, EXPANDED };
StatusAreaWidget(aura::Window* status_container, Shelf* shelf); StatusAreaWidget(aura::Window* status_container, Shelf* shelf);
~StatusAreaWidget() override; ~StatusAreaWidget() override;
...@@ -109,6 +113,8 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { ...@@ -109,6 +113,8 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget {
return virtual_keyboard_tray_.get(); return virtual_keyboard_tray_.get();
} }
CollapseState collapse_state() const { return collapse_state_; }
private: private:
friend class StatusAreaWidgetTestApi; friend class StatusAreaWidgetTestApi;
...@@ -130,6 +136,8 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { ...@@ -130,6 +136,8 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget {
LoginStatus login_status_ = LoginStatus::NOT_LOGGED_IN; LoginStatus login_status_ = LoginStatus::NOT_LOGGED_IN;
CollapseState collapse_state_ = CollapseState::NOT_COLLAPSIBLE;
Shelf* shelf_; Shelf* shelf_;
DISALLOW_COPY_AND_ASSIGN(StatusAreaWidget); DISALLOW_COPY_AND_ASSIGN(StatusAreaWidget);
......
...@@ -43,4 +43,9 @@ void StatusAreaWidgetTestApi::TapSelectToSpeakTray( ...@@ -43,4 +43,9 @@ void StatusAreaWidgetTestApi::TapSelectToSpeakTray(
std::move(callback).Run(); std::move(callback).Run();
} }
void StatusAreaWidgetTestApi::SetCollapseState(
StatusAreaWidget::CollapseState collapse_state) {
widget_->collapse_state_ = collapse_state;
}
} // namespace ash } // namespace ash
...@@ -24,6 +24,8 @@ class StatusAreaWidgetTestApi : public mojom::StatusAreaWidgetTestApi { ...@@ -24,6 +24,8 @@ class StatusAreaWidgetTestApi : public mojom::StatusAreaWidgetTestApi {
// mojom::StatusAreaWidgetTestApi: // mojom::StatusAreaWidgetTestApi:
void TapSelectToSpeakTray(TapSelectToSpeakTrayCallback callback) override; void TapSelectToSpeakTray(TapSelectToSpeakTrayCallback callback) override;
void SetCollapseState(StatusAreaWidget::CollapseState collapse_state);
private: private:
StatusAreaWidget* const widget_; StatusAreaWidget* const widget_;
......
...@@ -14,10 +14,15 @@ ...@@ -14,10 +14,15 @@
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/session/test_session_controller_client.h" #include "ash/session/test_session_controller_client.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/accessibility/dictation_button_tray.h"
#include "ash/system/accessibility/select_to_speak_tray.h"
#include "ash/system/ime_menu/ime_menu_tray.h" #include "ash/system/ime_menu/ime_menu_tray.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/model/virtual_keyboard_model.h"
#include "ash/system/overview/overview_button_tray.h" #include "ash/system/overview/overview_button_tray.h"
#include "ash/system/palette/palette_tray.h" #include "ash/system/palette/palette_tray.h"
#include "ash/system/session/logout_button_tray.h" #include "ash/system/session/logout_button_tray.h"
#include "ash/system/status_area_widget_test_api.h"
#include "ash/system/status_area_widget_test_helper.h" #include "ash/system/status_area_widget_test_helper.h"
#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
...@@ -273,8 +278,8 @@ TEST_F(StatusAreaWidgetVirtualKeyboardTest, ...@@ -273,8 +278,8 @@ TEST_F(StatusAreaWidgetVirtualKeyboardTest,
ClickingVirtualKeyboardTrayHidesShownKeyboard) { ClickingVirtualKeyboardTrayHidesShownKeyboard) {
// Set up the virtual keyboard tray icon along with some other tray icons. // Set up the virtual keyboard tray icon along with some other tray icons.
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
status->virtual_keyboard_tray_for_testing()->SetVisible(true); status->virtual_keyboard_tray_for_testing()->SetVisiblePreferred(true);
status->ime_menu_tray()->SetVisible(true); status->ime_menu_tray()->SetVisiblePreferred(true);
keyboard_ui_controller()->ShowKeyboard(false /* locked */); keyboard_ui_controller()->ShowKeyboard(false /* locked */);
ASSERT_TRUE(keyboard::WaitUntilShown()); ASSERT_TRUE(keyboard::WaitUntilShown());
...@@ -294,8 +299,8 @@ TEST_F(StatusAreaWidgetVirtualKeyboardTest, ...@@ -294,8 +299,8 @@ TEST_F(StatusAreaWidgetVirtualKeyboardTest,
TappingVirtualKeyboardTrayHidesShownKeyboard) { TappingVirtualKeyboardTrayHidesShownKeyboard) {
// Set up the virtual keyboard tray icon along with some other tray icons. // Set up the virtual keyboard tray icon along with some other tray icons.
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
status->virtual_keyboard_tray_for_testing()->SetVisible(true); status->virtual_keyboard_tray_for_testing()->SetVisiblePreferred(true);
status->ime_menu_tray()->SetVisible(true); status->ime_menu_tray()->SetVisiblePreferred(true);
keyboard_ui_controller()->ShowKeyboard(false /* locked */); keyboard_ui_controller()->ShowKeyboard(false /* locked */);
ASSERT_TRUE(keyboard::WaitUntilShown()); ASSERT_TRUE(keyboard::WaitUntilShown());
...@@ -355,4 +360,88 @@ TEST_F(StatusAreaWidgetVirtualKeyboardTest, DoesNotHideLockedVirtualKeyboard) { ...@@ -355,4 +360,88 @@ TEST_F(StatusAreaWidgetVirtualKeyboardTest, DoesNotHideLockedVirtualKeyboard) {
EXPECT_FALSE(keyboard::IsKeyboardHiding()); EXPECT_FALSE(keyboard::IsKeyboardHiding());
} }
class StatusAreaWidgetCollapseStateTest : public AshTestBase {
protected:
void SetUp() override {
AshTestBase::SetUp();
StatusAreaWidget* status_area =
StatusAreaWidgetTestHelper::GetStatusAreaWidget();
virtual_keyboard_ = status_area->virtual_keyboard_tray_for_testing();
ime_menu_ = status_area->ime_menu_tray();
palette_ = status_area->palette_tray();
dictation_button_ = status_area->dictation_button_tray();
select_to_speak_ = status_area->select_to_speak_tray();
virtual_keyboard_->SetVisiblePreferred(true);
ime_menu_->SetVisiblePreferred(true);
palette_->SetVisiblePreferred(true);
dictation_button_->SetVisiblePreferred(true);
select_to_speak_->SetVisiblePreferred(true);
}
void SetCollapseState(StatusAreaWidget::CollapseState collapse_state) {
StatusAreaWidgetTestApi test_api(
StatusAreaWidgetTestHelper::GetStatusAreaWidget());
test_api.SetCollapseState(collapse_state);
virtual_keyboard_->UpdateAfterStatusAreaCollapseChange();
ime_menu_->UpdateAfterStatusAreaCollapseChange();
palette_->UpdateAfterStatusAreaCollapseChange();
dictation_button_->UpdateAfterStatusAreaCollapseChange();
select_to_speak_->UpdateAfterStatusAreaCollapseChange();
}
TrayBackgroundView* virtual_keyboard_;
TrayBackgroundView* ime_menu_;
TrayBackgroundView* palette_;
TrayBackgroundView* dictation_button_;
TrayBackgroundView* select_to_speak_;
};
TEST_F(StatusAreaWidgetCollapseStateTest, TrayVisibility) {
// Initial visibility.
ime_menu_->SetVisiblePreferred(false);
virtual_keyboard_->set_show_when_collapsed(false);
palette_->set_show_when_collapsed(true);
EXPECT_FALSE(ime_menu_->GetVisible());
EXPECT_TRUE(virtual_keyboard_->GetVisible());
EXPECT_TRUE(palette_->GetVisible());
// Post-collapse visibility.
SetCollapseState(StatusAreaWidget::CollapseState::COLLAPSED);
EXPECT_FALSE(ime_menu_->GetVisible());
EXPECT_FALSE(virtual_keyboard_->GetVisible());
EXPECT_TRUE(palette_->GetVisible());
// Expanded visibility.
SetCollapseState(StatusAreaWidget::CollapseState::EXPANDED);
EXPECT_FALSE(ime_menu_->GetVisible());
EXPECT_TRUE(virtual_keyboard_->GetVisible());
EXPECT_TRUE(palette_->GetVisible());
}
TEST_F(StatusAreaWidgetCollapseStateTest, ImeMenuShownWithVirtualKeyboard) {
// Set up tray items.
ime_menu_->set_show_when_collapsed(false);
palette_->set_show_when_collapsed(true);
// Collapsing the status area should hide the IME menu tray item.
SetCollapseState(StatusAreaWidget::CollapseState::COLLAPSED);
EXPECT_FALSE(ime_menu_->GetVisible());
EXPECT_TRUE(palette_->GetVisible());
// But only the IME menu tray item should be shown after showing keyboard,
// simulated here by OnArcInputMethodSurfaceBoundsChanged().
Shell::Get()
->system_tray_model()
->virtual_keyboard()
->OnArcInputMethodSurfaceBoundsChanged(gfx::Rect(0, 0, 100, 100));
EXPECT_TRUE(ime_menu_->GetVisible());
EXPECT_FALSE(palette_->GetVisible());
EXPECT_FALSE(virtual_keyboard_->GetVisible());
EXPECT_FALSE(dictation_button_->GetVisible());
EXPECT_FALSE(select_to_speak_->GetVisible());
}
} // namespace ash } // namespace ash
...@@ -104,7 +104,7 @@ void StatusAreaOverflowButtonTray::Initialize() { ...@@ -104,7 +104,7 @@ void StatusAreaOverflowButtonTray::Initialize() {
// TODO(tengs): Make this tray button visible when the device is in tablet // TODO(tengs): Make this tray button visible when the device is in tablet
// mode and the status area width exceeds the maximum desirable width. // mode and the status area width exceeds the maximum desirable width.
SetVisible(false); SetVisiblePreferred(false);
} }
bool StatusAreaOverflowButtonTray::PerformAction(const ui::Event& event) { bool StatusAreaOverflowButtonTray::PerformAction(const ui::Event& event) {
......
...@@ -149,6 +149,7 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf) ...@@ -149,6 +149,7 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf)
separator_visible_(true), separator_visible_(true),
visible_preferred_(false), visible_preferred_(false),
show_with_virtual_keyboard_(false), show_with_virtual_keyboard_(false),
show_when_collapsed_(true),
widget_observer_(new TrayWidgetObserver(this)) { widget_observer_(new TrayWidgetObserver(this)) {
DCHECK(shelf_); DCHECK(shelf_);
set_notify_enter_exit_on_child(true); set_notify_enter_exit_on_child(true);
...@@ -202,17 +203,12 @@ void TrayBackgroundView::InitializeBubbleAnimations( ...@@ -202,17 +203,12 @@ void TrayBackgroundView::InitializeBubbleAnimations(
window, base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs)); window, base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs));
} }
void TrayBackgroundView::SetVisible(bool visible) { void TrayBackgroundView::SetVisiblePreferred(bool visible_preferred) {
visible_preferred_ = visible; visible_preferred_ = visible_preferred;
SetVisible(GetEffectiveVisibility());
// If virtual keyboard is visible and TrayBackgroundView is hidden because of }
// that, ignore SetVisible() call. |visible_preferred_| will be restored
// in OnVirtualKeyboardVisibilityChanged() when virtual keyboard is hidden.
if (!show_with_virtual_keyboard_ &&
Shell::Get()->system_tray_model()->virtual_keyboard()->visible()) {
return;
}
void TrayBackgroundView::SetVisible(bool visible) {
if (visible == layer()->GetTargetVisibility()) if (visible == layer()->GetTargetVisibility())
return; return;
...@@ -328,21 +324,8 @@ TrayBackgroundView::CreateInkDropHighlight() const { ...@@ -328,21 +324,8 @@ TrayBackgroundView::CreateInkDropHighlight() const {
} }
void TrayBackgroundView::OnVirtualKeyboardVisibilityChanged() { void TrayBackgroundView::OnVirtualKeyboardVisibilityChanged() {
if (show_with_virtual_keyboard_) { // We call the base class' SetVisible to skip animations.
// The view always shows up when virtual keyboard is visible if views::View::SetVisible(GetEffectiveVisibility());
// |show_with_virtual_keyboard| is true.
views::View::SetVisible(
Shell::Get()->system_tray_model()->virtual_keyboard()->visible() ||
visible_preferred_);
return;
}
// If virtual keyboard is hidden and current preferred visibility is true,
// set the visibility to true. We call base class' SetVisible because we don't
// want |visible_preferred_| to be updated here.
views::View::SetVisible(
!Shell::Get()->system_tray_model()->virtual_keyboard()->visible() &&
visible_preferred_);
} }
TrayBubbleView* TrayBackgroundView::GetBubbleView() { TrayBubbleView* TrayBackgroundView::GetBubbleView() {
...@@ -363,6 +346,11 @@ void TrayBackgroundView::UpdateAfterRootWindowBoundsChange( ...@@ -363,6 +346,11 @@ void TrayBackgroundView::UpdateAfterRootWindowBoundsChange(
// Do nothing by default. Child class may do something. // Do nothing by default. Child class may do something.
} }
void TrayBackgroundView::UpdateAfterStatusAreaCollapseChange() {
// We call the base class' SetVisible to skip animations.
views::View::SetVisible(GetEffectiveVisibility());
}
void TrayBackgroundView::BubbleResized(const TrayBubbleView* bubble_view) {} void TrayBackgroundView::BubbleResized(const TrayBubbleView* bubble_view) {}
void TrayBackgroundView::OnImplicitAnimationsCompleted() { void TrayBackgroundView::OnImplicitAnimationsCompleted() {
...@@ -490,4 +478,25 @@ void TrayBackgroundView::UpdateBackground() { ...@@ -490,4 +478,25 @@ void TrayBackgroundView::UpdateBackground() {
layer()->SetClipRect(GetBackgroundBounds()); layer()->SetClipRect(GetBackgroundBounds());
} }
bool TrayBackgroundView::GetEffectiveVisibility() {
// When the virtual keyboard is visible, the effective visibility of the view
// is solely determined by |show_with_virtual_keyboard_|.
if (Shell::Get()->system_tray_model()->virtual_keyboard()->visible())
return show_with_virtual_keyboard_;
if (!visible_preferred_)
return false;
// When the status area is collapsed, the effective visibility of the view is
// determined by |show_when_collapsed_|.
StatusAreaWidget::CollapseState collapse_state =
Shelf::ForWindow(GetWidget()->GetNativeWindow())
->GetStatusAreaWidget()
->collapse_state();
if (collapse_state == StatusAreaWidget::CollapseState::COLLAPSED)
return show_when_collapsed_;
return true;
}
} // namespace ash } // namespace ash
...@@ -42,13 +42,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -42,13 +42,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Initializes animations for the bubble. // Initializes animations for the bubble.
static void InitializeBubbleAnimations(views::Widget* bubble_widget); static void InitializeBubbleAnimations(views::Widget* bubble_widget);
// views::View:
void SetVisible(bool visible) override;
const char* GetClassName() const override;
void AboutToRequestFocusFromTabTraversal(bool reverse) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void ChildPreferredSizeChanged(views::View* child) override;
// ActionableView: // ActionableView:
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
...@@ -76,6 +69,9 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -76,6 +69,9 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
virtual void UpdateAfterRootWindowBoundsChange(const gfx::Rect& old_bounds, virtual void UpdateAfterRootWindowBoundsChange(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds); const gfx::Rect& new_bounds);
// Called whenever the status area's collapse state changes.
virtual void UpdateAfterStatusAreaCollapseChange();
// Called when the anchor (tray or bubble) may have moved or changed. // Called when the anchor (tray or bubble) may have moved or changed.
virtual void AnchorUpdated() {} virtual void AnchorUpdated() {}
...@@ -106,6 +102,11 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -106,6 +102,11 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Updates the visibility of this tray's separator. // Updates the visibility of this tray's separator.
void set_separator_visibility(bool visible) { separator_visible_ = visible; } void set_separator_visibility(bool visible) { separator_visible_ = visible; }
// Sets whether to show the view when the status area is collapsed.
void set_show_when_collapsed(bool show_when_collapsed) {
show_when_collapsed_ = show_when_collapsed;
}
// Gets the anchor for bubbles, which is tray_container(). // Gets the anchor for bubbles, which is tray_container().
views::View* GetBubbleAnchor() const; views::View* GetBubbleAnchor() const;
...@@ -120,6 +121,12 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -120,6 +121,12 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// based on background insets returned from GetBackgroundInsets(). // based on background insets returned from GetBackgroundInsets().
gfx::Rect GetBackgroundBounds() const; gfx::Rect GetBackgroundBounds() const;
// Sets whether the tray item should be shown by default (e.g. it is
// activated). The effective visibility of the tray item is determined by the
// current state of the status tray (i.e. whether the virtual keyboard is
// showing or if it is collapsed).
void SetVisiblePreferred(bool visible_preferred);
protected: protected:
// ActionableView: // ActionableView:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
...@@ -137,6 +144,13 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -137,6 +144,13 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
class HighlightPathGenerator; class HighlightPathGenerator;
class TrayWidgetObserver; class TrayWidgetObserver;
// views::View:
void SetVisible(bool visible) override;
const char* GetClassName() const override;
void AboutToRequestFocusFromTabTraversal(bool reverse) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void ChildPreferredSizeChanged(views::View* child) override;
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override; void OnImplicitAnimationsCompleted() override;
bool RequiresNotificationWhenAnimatorDestroyed() const override; bool RequiresNotificationWhenAnimatorDestroyed() const override;
...@@ -151,6 +165,10 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -151,6 +165,10 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Updates the background layer. // Updates the background layer.
void UpdateBackground(); void UpdateBackground();
// Returns the effective visibility of the tray item based on the current
// state.
bool GetEffectiveVisibility();
// The shelf containing the system tray for this view. // The shelf containing the system tray for this view.
Shelf* shelf_; Shelf* shelf_;
...@@ -173,6 +191,9 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -173,6 +191,9 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// If true, the view always shows up when virtual keyboard is visible. // If true, the view always shows up when virtual keyboard is visible.
bool show_with_virtual_keyboard_; bool show_with_virtual_keyboard_;
// If true, the view is visible when the status area is collapsed.
bool show_when_collapsed_;
std::unique_ptr<TrayWidgetObserver> widget_observer_; std::unique_ptr<TrayWidgetObserver> widget_observer_;
std::unique_ptr<TrayEventFilter> tray_event_filter_; std::unique_ptr<TrayEventFilter> tray_event_filter_;
......
...@@ -270,7 +270,7 @@ gfx::Rect UnifiedSystemTray::GetBubbleBoundsInScreen() const { ...@@ -270,7 +270,7 @@ gfx::Rect UnifiedSystemTray::GetBubbleBoundsInScreen() const {
} }
void UnifiedSystemTray::UpdateAfterLoginStatusChange() { void UnifiedSystemTray::UpdateAfterLoginStatusChange() {
SetVisible(true); SetVisiblePreferred(true);
PreferredSizeChanged(); PreferredSizeChanged();
} }
......
...@@ -90,7 +90,7 @@ bool VirtualKeyboardTray::PerformAction(const ui::Event& event) { ...@@ -90,7 +90,7 @@ bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
void VirtualKeyboardTray::OnAccessibilityStatusChanged() { void VirtualKeyboardTray::OnAccessibilityStatusChanged() {
bool new_enabled = bool new_enabled =
Shell::Get()->accessibility_controller()->virtual_keyboard_enabled(); Shell::Get()->accessibility_controller()->virtual_keyboard_enabled();
SetVisible(new_enabled); SetVisiblePreferred(new_enabled);
} }
void VirtualKeyboardTray::OnKeyboardVisibilityChanged(const bool is_visible) { void VirtualKeyboardTray::OnKeyboardVisibilityChanged(const bool is_visible) {
......
...@@ -40,7 +40,7 @@ class VirtualKeyboardTrayTest : public AshTestBase { ...@@ -40,7 +40,7 @@ class VirtualKeyboardTrayTest : public AshTestBase {
TEST_F(VirtualKeyboardTrayTest, PerformActionTogglesVirtualKeyboard) { TEST_F(VirtualKeyboardTrayTest, PerformActionTogglesVirtualKeyboard) {
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
VirtualKeyboardTray* tray = status->virtual_keyboard_tray_for_testing(); VirtualKeyboardTray* tray = status->virtual_keyboard_tray_for_testing();
tray->SetVisible(true); tray->SetVisiblePreferred(true);
ASSERT_TRUE(tray->GetVisible()); ASSERT_TRUE(tray->GetVisible());
// First tap should show the virtual keyboard. // First tap should show the virtual keyboard.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment