Commit b5ecbcc8 authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

cros: Update shelf background when going to tablet mode

The bug is that when transitioning to tablet mode with a window
(which will expand to fullscreen) open and a shown AppList results in
a stale shelf background.

This is a corner case, where the AppList does not change in visibility,
it remains visible and the shelf does not know to re-evaluate its
background.

Maybe the shelf should observe active windows instead of relying on
AppList visibility state changes?

For now, we fix this corner case by forcing the shelf to re-evaluate
it's background when the launcher stays open during the tablet mode
transition.

Test=automated and manual

Bug: 879591
Change-Id: I71c8d97672824853b0edac77e1a91734ba148af0
Reviewed-on: https://chromium-review.googlesource.com/1200408Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589329}
parent 7ee15a50
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ash/public/cpp/app_list/answer_card_contents_registry.h" #include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "ash/public/cpp/app_list/app_list_features.h" #include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/voice_interaction/voice_interaction_controller.h" #include "ash/voice_interaction/voice_interaction_controller.h"
#include "ash/wallpaper/wallpaper_controller.h" #include "ash/wallpaper/wallpaper_controller.h"
...@@ -540,6 +541,7 @@ void AppListControllerImpl::OnTabletModeStarted() { ...@@ -540,6 +541,7 @@ void AppListControllerImpl::OnTabletModeStarted() {
Show(display::Display::InternalDisplayId(), app_list::kTabletMode, Show(display::Display::InternalDisplayId(), app_list::kTabletMode,
base::TimeTicks()); base::TimeTicks());
UpdateHomeLauncherVisibility(); UpdateHomeLauncherVisibility();
Shelf::ForWindow(presenter_.GetWindow())->MaybeUpdateShelfBackground();
} }
void AppListControllerImpl::OnTabletModeEnded() { void AppListControllerImpl::OnTabletModeEnded() {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "ash/animation/animation_change_type.h"
#include "ash/app_list/app_list_controller_impl.h" #include "ash/app_list/app_list_controller_impl.h"
#include "ash/public/cpp/shelf_item_delegate.h" #include "ash/public/cpp/shelf_item_delegate.h"
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
...@@ -178,6 +179,14 @@ void Shelf::UpdateVisibilityState() { ...@@ -178,6 +179,14 @@ void Shelf::UpdateVisibilityState() {
shelf_layout_manager_->UpdateVisibilityState(); shelf_layout_manager_->UpdateVisibilityState();
} }
void Shelf::MaybeUpdateShelfBackground() {
if (!shelf_layout_manager_)
return;
shelf_layout_manager_->MaybeUpdateShelfBackground(
AnimationChangeType::ANIMATE);
}
ShelfVisibilityState Shelf::GetVisibilityState() const { ShelfVisibilityState Shelf::GetVisibilityState() const {
return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state()
: SHELF_HIDDEN; : SHELF_HIDDEN;
......
...@@ -91,6 +91,8 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver { ...@@ -91,6 +91,8 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver {
void UpdateVisibilityState(); void UpdateVisibilityState();
void MaybeUpdateShelfBackground();
ShelfVisibilityState GetVisibilityState() const; ShelfVisibilityState GetVisibilityState() const;
int GetAccessibilityPanelHeight() const; int GetAccessibilityPanelHeight() const;
......
...@@ -576,6 +576,17 @@ void ShelfLayoutManager::SetDockedMagnifierHeight(int height) { ...@@ -576,6 +576,17 @@ void ShelfLayoutManager::SetDockedMagnifierHeight(int height) {
LayoutShelf(); LayoutShelf();
} }
void ShelfLayoutManager::MaybeUpdateShelfBackground(AnimationChangeType type) {
const ShelfBackgroundType new_background_type(GetShelfBackgroundType());
if (new_background_type == shelf_background_type_)
return;
shelf_background_type_ = new_background_type;
for (auto& observer : observers_)
observer.OnBackgroundUpdated(shelf_background_type_, type);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ShelfLayoutManager, private: // ShelfLayoutManager, private:
...@@ -925,17 +936,6 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -925,17 +936,6 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
} }
} }
void ShelfLayoutManager::MaybeUpdateShelfBackground(AnimationChangeType type) {
const ShelfBackgroundType new_background_type(GetShelfBackgroundType());
if (new_background_type == shelf_background_type_)
return;
shelf_background_type_ = new_background_type;
for (auto& observer : observers_)
observer.OnBackgroundUpdated(shelf_background_type_, type);
}
void ShelfLayoutManager::UpdateAutoHideStateNow() { void ShelfLayoutManager::UpdateAutoHideStateNow() {
SetState(state_.visibility_state); SetState(state_.visibility_state);
......
...@@ -212,6 +212,9 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -212,6 +212,9 @@ class ASH_EXPORT ShelfLayoutManager
// panel height. The Docked Magnifier appears above the ChromeVox panel. // panel height. The Docked Magnifier appears above the ChromeVox panel.
void SetDockedMagnifierHeight(int height); void SetDockedMagnifierHeight(int height);
// Updates the background of the shelf if it has changed.
void MaybeUpdateShelfBackground(AnimationChangeType change_type);
private: private:
class UpdateShelfObserver; class UpdateShelfObserver;
friend class PanelLayoutManagerTest; friend class PanelLayoutManagerTest;
...@@ -275,9 +278,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -275,9 +278,6 @@ class ASH_EXPORT ShelfLayoutManager
// used by |CalculateTargetBounds()|. // used by |CalculateTargetBounds()|.
void UpdateTargetBoundsForGesture(TargetBounds* target_bounds) const; void UpdateTargetBoundsForGesture(TargetBounds* target_bounds) const;
// Updates the background of the shelf if it has changed.
void MaybeUpdateShelfBackground(AnimationChangeType change_type);
// Updates the auto hide state immediately. // Updates the auto hide state immediately.
void UpdateAutoHideStateNow(); void UpdateAutoHideStateNow();
......
...@@ -2017,6 +2017,35 @@ TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColor) { ...@@ -2017,6 +2017,35 @@ TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColor) {
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType()); EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
} }
// Tests that the shelf background gets updated when the AppList stays open
// during the tablet mode transition with a visible window.
TEST_F(ShelfLayoutManagerTest, TabletModeTransitionWithAppListVisible) {
// Home Launcher requires an internal display.
display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
.SetFirstDisplayAsInternalDisplay();
// Show a window, which will later fill the whole screen.
std::unique_ptr<aura::Window> window(
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400)));
window->SetProperty(aura::client::kResizeBehaviorKey,
ws::mojom::kResizeBehaviorCanResize |
ws::mojom::kResizeBehaviorCanMaximize);
wm::ActivateWindow(window.get());
// Show the AppList over |window|.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
// Transition to tablet mode.
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
// |window| should be maximized, and the shelf background should match the
// maximized state.
EXPECT_EQ(
wm::WORKSPACE_WINDOW_STATE_MAXIMIZED,
RootWindowController::ForWindow(window.get())->GetWorkspaceWindowState());
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
}
// Test the background color for split view mode. // Test the background color for split view mode.
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorInSplitView) { TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorInSplitView) {
// Split view is only enabled in tablet mode. // Split view is only enabled in tablet mode.
......
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