Commit 16f27b21 authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Update status area collapse state when state changes.

The collapse state of the status area should be updated when the shelf state or
bounds change or when a tray item is shown or hidden.

Note that the actual calculation for which trays should be hidden or visible is
unimplemented and will be finished in a future CL.

TEST=unit test
BUG=982511

Change-Id: Ie4a46be7d03435bf8927062af0c7726f5cc090a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904165
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714798}
parent e7256d38
......@@ -58,6 +58,10 @@ const char kAshEnableWaylandServer[] = "enable-wayland-server";
// Enables the stylus tools next to the status area.
const char kAshForceEnableStylusTools[] = "force-enable-stylus-tools";
// Forces the status area to allow collapse/expand regardless of the current
// state.
const char kAshForceStatusAreaCollapsible[] = "force-status-area-collapsible";
// Power button position includes the power button's physical display side and
// the percentage for power button center position to the display's
// width/height in landscape_primary screen orientation. The value is a JSON
......
......@@ -30,6 +30,7 @@ ASH_PUBLIC_EXPORT extern const char kAshEnablePaletteOnAllDisplays[];
ASH_PUBLIC_EXPORT extern const char kAshEnableTabletMode[];
ASH_PUBLIC_EXPORT extern const char kAshEnableWaylandServer[];
ASH_PUBLIC_EXPORT extern const char kAshForceEnableStylusTools[];
ASH_PUBLIC_EXPORT extern const char kAshForceStatusAreaCollapsible[];
ASH_PUBLIC_EXPORT extern const char kAshPowerButtonPosition[];
ASH_PUBLIC_EXPORT extern const char kAshUiMode[];
ASH_PUBLIC_EXPORT extern const char kAshUiModeClamshell[];
......
......@@ -353,6 +353,7 @@ void ShelfWidget::DelegateView::UpdateDragHandle() {
void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) {
UpdateOpaqueBackground();
shelf_widget_->status_area_widget()->UpdateCollapseState();
}
views::View* ShelfWidget::DelegateView::GetDefaultFocusableChild() {
......
......@@ -5,6 +5,8 @@
#include "ash/system/status_area_widget.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
......@@ -18,7 +20,10 @@
#include "ash/system/tray/status_area_overflow_button_tray.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/virtual_keyboard/virtual_keyboard_tray.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "base/i18n/time_formatting.h"
#include "chromeos/constants/chromeos_switches.h"
#include "ui/display/display.h"
#include "ui/native_theme/native_theme_dark_aura.h"
......@@ -145,6 +150,36 @@ void StatusAreaWidget::SetSystemTrayVisibility(bool visible) {
}
}
void StatusAreaWidget::UpdateCollapseState() {
// The status area is only collapsible in tablet mode. Otherwise, we just show
// all trays.
if (!Shell::Get()->tablet_mode_controller())
return;
bool is_collapsible =
chromeos::switches::ShouldShowShelfHotseat() &&
Shell::Get()->tablet_mode_controller()->InTabletMode() &&
ShelfConfig::Get()->is_in_app();
bool force_collapsible = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshForceStatusAreaCollapsible);
is_collapsible |= force_collapsible;
// If the status area is already collapsed/expanded, we should not update the
// state again.
if (is_collapsible && collapse_state_ == CollapseState::NOT_COLLAPSIBLE)
collapse_state_ = CollapseState::COLLAPSED;
else if (!is_collapsible)
collapse_state_ = CollapseState::NOT_COLLAPSIBLE;
// TODO(tengs): Right now we simply show the overflow button in the collpase
// state. The full calculation of which trays overflow will be done in a
// future CL.
overflow_button_tray_->SetVisiblePreferred(
force_collapsible && collapse_state_ != CollapseState::NOT_COLLAPSIBLE);
}
TrayBackgroundView* StatusAreaWidget::GetSystemTrayAnchor() const {
// Use the target visibility of the layer instead of the visibility of the
// view because the view is still visible when fading away, but we do not want
......
......@@ -55,6 +55,10 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget {
// notification tray.
void UpdateAfterLoginStatusChange(LoginStatus login_status);
// Updates the collapse state of the status area after the state of the shelf
// changes.
void UpdateCollapseState();
// Sets system tray visibility. Shows or hides widget if needed.
void SetSystemTrayVisibility(bool visible);
......
......@@ -24,6 +24,7 @@
#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/tray/status_area_overflow_button_tray.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/virtual_keyboard/virtual_keyboard_tray.h"
......@@ -365,13 +366,13 @@ class StatusAreaWidgetCollapseStateTest : public AshTestBase {
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();
status_area_ = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
overflow_button_ = status_area_->overflow_button_tray();
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);
......@@ -381,8 +382,7 @@ class StatusAreaWidgetCollapseStateTest : public AshTestBase {
}
void SetCollapseState(StatusAreaWidget::CollapseState collapse_state) {
StatusAreaWidgetTestApi test_api(
StatusAreaWidgetTestHelper::GetStatusAreaWidget());
StatusAreaWidgetTestApi test_api(status_area_);
test_api.SetCollapseState(collapse_state);
virtual_keyboard_->UpdateAfterStatusAreaCollapseChange();
......@@ -392,6 +392,8 @@ class StatusAreaWidgetCollapseStateTest : public AshTestBase {
select_to_speak_->UpdateAfterStatusAreaCollapseChange();
}
StatusAreaWidget* status_area_;
TrayBackgroundView* overflow_button_;
TrayBackgroundView* virtual_keyboard_;
TrayBackgroundView* ime_menu_;
TrayBackgroundView* palette_;
......@@ -444,4 +446,12 @@ TEST_F(StatusAreaWidgetCollapseStateTest, ImeMenuShownWithVirtualKeyboard) {
EXPECT_FALSE(select_to_speak_->GetVisible());
}
TEST_F(StatusAreaWidgetCollapseStateTest, OverflowButtonShownWhenCollapsible) {
EXPECT_FALSE(overflow_button_->GetVisible());
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshForceStatusAreaCollapsible);
status_area_->UpdateCollapseState();
EXPECT_TRUE(overflow_button_->GetVisible());
}
} // namespace ash
......@@ -204,8 +204,13 @@ void TrayBackgroundView::InitializeBubbleAnimations(
}
void TrayBackgroundView::SetVisiblePreferred(bool visible_preferred) {
if (visible_preferred_ == visible_preferred)
return;
visible_preferred_ = visible_preferred;
SetVisible(GetEffectiveVisibility());
// We need to update which trays overflow after showing or hiding a tray.
shelf_->GetStatusAreaWidget()->UpdateCollapseState();
}
void TrayBackgroundView::SetVisible(bool visible) {
......
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