Commit 61df6c3a authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Send out ShelfConfigUpdated when tablet mode changes

Notify shelf config observers that the shelf config has changed when
tablet mode changes - some shelf dimensions depend on tablet mode
state, so shelf may need relayout when tablet mode changes. This is
generally done when hiding shelf buttons in tablet mode is enabled, but
depending on user settings, that may not be the case.

Also, stop observing tablet mode state in ShelfLayoutManager, as it's
already observing both ShelfConfig, so now that shelf config is updated
when tablet mode changes, it should be enough to observe shelf config
only.

BUG=None

Change-Id: I3c9f84ec9fa4d03bcd2838ea43cd7ae5869f26a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283580Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785847}
parent 8eceb471
...@@ -415,7 +415,7 @@ void ShelfConfig::UpdateConfig(bool new_is_app_list_visible, ...@@ -415,7 +415,7 @@ void ShelfConfig::UpdateConfig(bool new_is_app_list_visible,
? Shell::Get()->system_tray_model()->virtual_keyboard()->visible() ? Shell::Get()->system_tray_model()->virtual_keyboard()->visible()
: false; : false;
if (is_dense_ == new_is_dense && if (!tablet_mode_changed && is_dense_ == new_is_dense &&
shelf_controls_shown_ == new_shelf_controls_shown && shelf_controls_shown_ == new_shelf_controls_shown &&
is_virtual_keyboard_shown_ == new_is_virtual_keyboard_shown && is_virtual_keyboard_shown_ == new_is_virtual_keyboard_shown &&
is_app_list_visible_ == new_is_app_list_visible) { is_app_list_visible_ == new_is_app_list_visible) {
......
...@@ -407,7 +407,6 @@ void ShelfLayoutManager::InitObservers() { ...@@ -407,7 +407,6 @@ void ShelfLayoutManager::InitObservers() {
shell->AddShellObserver(this); shell->AddShellObserver(this);
SplitViewController::Get(shelf_widget_->GetNativeWindow())->AddObserver(this); SplitViewController::Get(shelf_widget_->GetNativeWindow())->AddObserver(this);
ShelfConfig::Get()->AddObserver(this); ShelfConfig::Get()->AddObserver(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
shell->overview_controller()->AddObserver(this); shell->overview_controller()->AddObserver(this);
shell->app_list_controller()->AddObserver(this); shell->app_list_controller()->AddObserver(this);
shell->lock_state_controller()->AddObserver(this); shell->lock_state_controller()->AddObserver(this);
...@@ -435,7 +434,6 @@ void ShelfLayoutManager::PrepareForShutdown() { ...@@ -435,7 +434,6 @@ void ShelfLayoutManager::PrepareForShutdown() {
// Stop observing changes to avoid updating a partially destructed shelf. // Stop observing changes to avoid updating a partially destructed shelf.
Shell::Get()->activation_client()->RemoveObserver(this); Shell::Get()->activation_client()->RemoveObserver(this);
ShelfConfig::Get()->RemoveObserver(this); ShelfConfig::Get()->RemoveObserver(this);
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
// DesksController could be null when virtual desks feature is not enabled. // DesksController could be null when virtual desks feature is not enabled.
if (DesksController::Get()) if (DesksController::Get())
...@@ -1181,16 +1179,6 @@ void ShelfLayoutManager::OnShelfConfigUpdated() { ...@@ -1181,16 +1179,6 @@ void ShelfLayoutManager::OnShelfConfigUpdated() {
UpdateContextualNudges(); UpdateContextualNudges();
} }
void ShelfLayoutManager::OnTabletModeStarted() {
LayoutShelf(/*animate=*/true);
UpdateContextualNudges();
}
void ShelfLayoutManager::OnTabletModeEnded() {
LayoutShelf(/*animate=*/true);
UpdateContextualNudges();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ShelfLayoutManager, private: // ShelfLayoutManager, private:
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "ash/public/cpp/session/session_observer.h" #include "ash/public/cpp/session/session_observer.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/public/cpp/wallpaper_controller.h" #include "ash/public/cpp/wallpaper_controller.h"
#include "ash/public/cpp/wallpaper_controller_observer.h" #include "ash/public/cpp/wallpaper_controller_observer.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
...@@ -83,8 +82,7 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -83,8 +82,7 @@ class ASH_EXPORT ShelfLayoutManager
public LocaleChangeObserver, public LocaleChangeObserver,
public DesksController::Observer, public DesksController::Observer,
public message_center::MessageCenterObserver, public message_center::MessageCenterObserver,
public ShelfConfig::Observer, public ShelfConfig::Observer {
public TabletModeObserver {
public: public:
// Suspend work area updates within its scope. Note that relevant // Suspend work area updates within its scope. Note that relevant
// ShelfLayoutManager must outlive this class. // ShelfLayoutManager must outlive this class.
...@@ -272,10 +270,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -272,10 +270,6 @@ class ASH_EXPORT ShelfLayoutManager
// ShelfConfig::Observer: // ShelfConfig::Observer:
void OnShelfConfigUpdated() override; void OnShelfConfigUpdated() override;
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
float GetOpacity() const; float GetOpacity() const;
bool updating_bounds() const { return phase_ == ShelfLayoutPhase::kMoving; } bool updating_bounds() const { return phase_ == ShelfLayoutPhase::kMoving; }
......
...@@ -67,7 +67,15 @@ gfx::Rect GetSecondButtonBounds() { ...@@ -67,7 +67,15 @@ gfx::Rect GetSecondButtonBounds() {
ShelfConfig::Get()->control_size()); ShelfConfig::Get()->control_size());
} }
bool IsBackButtonShown() { bool IsBackButtonShown(bool horizontal_alignment) {
// Back button should only be shown in horizontal shelf.
// TODO(https://crbug.com/1102648): Horizontal shelf should be implied by
// tablet mode, but this may not be the case during tablet mode transition as
// shelf layout may get updated before the correct shelf alignment is set.
// Remove this when the linked bug is resolved.
if (!horizontal_alignment)
return false;
// TODO(https://crbug.com/1058205): Test this behavior. // TODO(https://crbug.com/1058205): Test this behavior.
if (ShelfConfig::Get()->is_virtual_keyboard_shown()) if (ShelfConfig::Get()->is_virtual_keyboard_shown())
return true; return true;
...@@ -333,7 +341,8 @@ void ShelfNavigationWidget::Delegate::UpdateOpaqueBackground() { ...@@ -333,7 +341,8 @@ void ShelfNavigationWidget::Delegate::UpdateOpaqueBackground() {
opaque_background_.SetColor(ShelfConfig::Get()->GetShelfControlButtonColor()); opaque_background_.SetColor(ShelfConfig::Get()->GetShelfControlButtonColor());
// Hide background if no buttons should be shown. // Hide background if no buttons should be shown.
if (!IsHomeButtonShown() && !IsBackButtonShown()) { if (!IsHomeButtonShown() &&
!IsBackButtonShown(shelf_->IsHorizontalAlignment())) {
opaque_background_.SetVisible(false); opaque_background_.SetVisible(false);
return; return;
} }
...@@ -478,7 +487,8 @@ void ShelfNavigationWidget::Initialize(aura::Window* container) { ...@@ -478,7 +487,8 @@ void ShelfNavigationWidget::Initialize(aura::Window* container) {
gfx::Size ShelfNavigationWidget::GetIdealSize() const { gfx::Size ShelfNavigationWidget::GetIdealSize() const {
const int button_count = const int button_count =
(IsBackButtonShown() ? 1 : 0) + (IsHomeButtonShown() ? 1 : 0); (IsBackButtonShown(shelf_->IsHorizontalAlignment()) ? 1 : 0) +
(IsHomeButtonShown() ? 1 : 0);
if (button_count == 0) if (button_count == 0)
return gfx::Size(); return gfx::Size();
...@@ -546,7 +556,9 @@ void ShelfNavigationWidget::OnGestureEvent(ui::GestureEvent* event) { ...@@ -546,7 +556,9 @@ void ShelfNavigationWidget::OnGestureEvent(ui::GestureEvent* event) {
} }
BackButton* ShelfNavigationWidget::GetBackButton() const { BackButton* ShelfNavigationWidget::GetBackButton() const {
return IsBackButtonShown() ? delegate_->back_button() : nullptr; return IsBackButtonShown(shelf_->IsHorizontalAlignment())
? delegate_->back_button()
: nullptr;
} }
HomeButton* ShelfNavigationWidget::GetHomeButton() const { HomeButton* ShelfNavigationWidget::GetHomeButton() const {
...@@ -577,7 +589,8 @@ gfx::Rect ShelfNavigationWidget::GetTargetBounds() const { ...@@ -577,7 +589,8 @@ gfx::Rect ShelfNavigationWidget::GetTargetBounds() const {
} }
void ShelfNavigationWidget::UpdateLayout(bool animate) { void ShelfNavigationWidget::UpdateLayout(bool animate) {
const bool back_button_shown = IsBackButtonShown(); const bool back_button_shown =
IsBackButtonShown(shelf_->IsHorizontalAlignment());
const bool home_button_shown = IsHomeButtonShown(); const bool home_button_shown = IsHomeButtonShown();
const ShelfLayoutManager* layout_manager = shelf_->shelf_layout_manager(); const ShelfLayoutManager* layout_manager = shelf_->shelf_layout_manager();
......
...@@ -681,7 +681,7 @@ void ShelfWidget::OnTabletModeChanged() { ...@@ -681,7 +681,7 @@ void ShelfWidget::OnTabletModeChanged() {
// Disable login shelf gesture controller, if one is set when leacing tablet // Disable login shelf gesture controller, if one is set when leacing tablet
// mode. // mode.
login_shelf_gesture_controller_.reset(); ClearLoginShelfSwipeHandler();
} }
} }
......
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