0

Split Shell::ToggleAppList() into ShowAppList and DismissAppList.

This CL is in preparation for passing a reason for showing the app list.
This split is necessary to pass a reason only when showing and not when
dismissing.

BUG=None

Review URL: https://codereview.chromium.org/460933002

Cr-Commit-Position: refs/heads/master@{#289889}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289889 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
calamity@chromium.org
2014-08-15 16:03:06 +00:00
parent ae56a69f25
commit 1b46780d51
11 changed files with 51 additions and 38 deletions

@ -51,15 +51,11 @@ views::Widget* FirstRunHelperImpl::GetOverlayWidget() {
}
void FirstRunHelperImpl::OpenAppList() {
if (Shell::GetInstance()->GetAppListTargetVisibility())
return;
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
}
void FirstRunHelperImpl::CloseAppList() {
if (!Shell::GetInstance()->GetAppListTargetVisibility())
return;
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->DismissAppList();
}
gfx::Rect FirstRunHelperImpl::GetLauncherBounds() {

@ -1278,13 +1278,13 @@ TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
// Toggle app list to show, and the shelf stays visible.
shell->ToggleAppList(NULL);
// Show app list and the shelf stays visible.
shell->ShowAppList(NULL);
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
// Toggle app list to hide, and the shelf stays visible.
shell->ToggleAppList(NULL);
// Hide app list and the shelf stays visible.
shell->DismissAppList();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
}
@ -1308,8 +1308,8 @@ TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
// Toggle app list to show.
shell->ToggleAppList(NULL);
// Show app list.
shell->ShowAppList(NULL);
// The shelf's auto hide state won't be changed until the timer fires, so
// calling shell->UpdateShelfVisibility() is kind of manually helping it to
// update the state.
@ -1318,8 +1318,8 @@ TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
// Toggle app list to hide.
shell->ToggleAppList(NULL);
// Hide app list.
shell->DismissAppList();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
}
@ -1343,13 +1343,13 @@ TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) {
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
// Toggle app list to show.
shell->ToggleAppList(NULL);
// Show app list.
shell->ShowAppList(NULL);
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
// Toggle app list to hide.
shell->ToggleAppList(NULL);
// Hide app list.
shell->DismissAppList();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
}

@ -1301,7 +1301,7 @@ TEST_F(ShelfViewTest, ShouldHideTooltipTest) {
}
TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) {
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow());
// The tooltip shouldn't hide if the mouse is on normal buttons.

@ -292,13 +292,28 @@ void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
->ShowContextMenu(location_in_screen, source_type);
}
void Shell::ToggleAppList(aura::Window* window) {
void Shell::ShowAppList(aura::Window* window) {
// If the context window is not given, show it on the target root window.
if (!window)
window = GetTargetRootWindow();
if (!app_list_controller_)
app_list_controller_.reset(new AppListController);
app_list_controller_->SetVisible(!app_list_controller_->IsVisible(), window);
app_list_controller_->SetVisible(true, window);
}
void Shell::DismissAppList() {
if (!app_list_controller_)
return;
app_list_controller_->SetVisible(false, GetTargetRootWindow());
}
void Shell::ToggleAppList(aura::Window* window) {
if (GetAppListTargetVisibility()) {
DismissAppList();
return;
}
ShowAppList(window);
}
bool Shell::GetAppListTargetVisibility() const {

@ -231,9 +231,15 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate,
void ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type);
// Toggles the app list. |window| specifies in which display the app
// Shows the app list. |window| specifies in which display the app
// list should be shown. If this is NULL, the active root window
// will be used.
void ShowAppList(aura::Window* anchor);
// Dismisses the app list.
void DismissAppList();
// Shows the app list if it's not visible. Dismisses it otherwise.
void ToggleAppList(aura::Window* anchor);
// Returns app list target visibility.

@ -317,8 +317,7 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
virtual void Dismiss() OVERRIDE {
DCHECK(ash::Shell::HasInstance());
if (Shell::GetInstance()->GetAppListTargetVisibility())
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->DismissAppList();
}
virtual void ViewClosing() OVERRIDE {

@ -55,7 +55,7 @@ bool AppListControllerTest::IsCentered() const {
// Tests that app launcher hides when focus moves to a normal window.
TEST_P(AppListControllerTest, HideOnFocusOut) {
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
@ -67,7 +67,7 @@ TEST_P(AppListControllerTest, HideOnFocusOut) {
// Tests that app launcher remains visible when focus is moved to a different
// window in kShellWindowId_AppListContainer.
TEST_P(AppListControllerTest, RemainVisibleWhenFocusingToApplistContainer) {
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
aura::Window* applist_container = Shell::GetContainer(
@ -82,7 +82,7 @@ TEST_P(AppListControllerTest, RemainVisibleWhenFocusingToApplistContainer) {
// Tests that clicking outside the app-list bubble closes it.
TEST_P(AppListControllerTest, ClickOutsideBubbleClosesBubble) {
Shell* shell = Shell::GetInstance();
shell->ToggleAppList(NULL);
shell->ShowAppList(NULL);
aura::Window* app_window = shell->GetAppListWindow();
ASSERT_TRUE(app_window);
@ -105,7 +105,7 @@ TEST_P(AppListControllerTest, ClickOutsideBubbleClosesBubble) {
// Tests that clicking outside the app-list bubble closes it.
TEST_P(AppListControllerTest, TapOutsideBubbleClosesBubble) {
Shell* shell = Shell::GetInstance();
shell->ToggleAppList(NULL);
shell->ShowAppList(NULL);
aura::Window* app_window = shell->GetAppListWindow();
ASSERT_TRUE(app_window);
@ -139,7 +139,7 @@ TEST_P(AppListControllerTest, NonPrimaryDisplay) {
aura::Window* secondary_window = root_windows[1];
EXPECT_EQ("800,0 800x600", secondary_window->GetBoundsInScreen().ToString());
Shell::GetInstance()->ToggleAppList(secondary_window);
Shell::GetInstance()->ShowAppList(secondary_window);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
// Remove the secondary display. Shouldn't crash (http://crbug.com/368990).
@ -166,7 +166,7 @@ TEST_P(AppListControllerTest, TinyDisplay) {
// Set up a screen with a tiny display (height smaller than the app list).
UpdateDisplay("400x300");
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
// The top of the app list should be on-screen (even if the bottom is not).

@ -439,7 +439,7 @@ TEST_F(WindowSelectorTest, SelectingHidesAppList) {
gfx::Rect bounds(0, 0, 400, 400);
scoped_ptr<aura::Window> window1(CreateWindow(bounds));
scoped_ptr<aura::Window> window2(CreateWindow(bounds));
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
ToggleOverview();
EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());

@ -469,7 +469,7 @@ TEST_F(WindowCycleControllerTest, SelectingHidesAppList) {
scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1));
Shell::GetInstance()->ToggleAppList(NULL);
Shell::GetInstance()->ShowAppList(NULL);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
controller->HandleCycleWindow(WindowCycleController::FORWARD);
EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());

@ -15,8 +15,7 @@ AppListControllerDelegateAsh::~AppListControllerDelegateAsh() {}
void AppListControllerDelegateAsh::DismissView() {
DCHECK(ash::Shell::HasInstance());
if (ash::Shell::GetInstance()->GetAppListTargetVisibility())
ash::Shell::GetInstance()->ToggleAppList(NULL);
ash::Shell::GetInstance()->DismissAppList();
}
gfx::NativeWindow AppListControllerDelegateAsh::GetAppListWindow() {

@ -35,8 +35,7 @@ void AppListServiceAsh::ShowForProfile(Profile* default_profile) {
// This may not work correctly if the profile passed in is different from the
// one the ash Shell is currently using.
// TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
if (!ash::Shell::GetInstance()->GetAppListTargetVisibility())
ash::Shell::GetInstance()->ToggleAppList(NULL);
ash::Shell::GetInstance()->ShowAppList(NULL);
}
bool AppListServiceAsh::IsAppListVisible() const {
@ -44,8 +43,7 @@ bool AppListServiceAsh::IsAppListVisible() const {
}
void AppListServiceAsh::DismissAppList() {
if (IsAppListVisible())
ash::Shell::GetInstance()->ToggleAppList(NULL);
ash::Shell::GetInstance()->DismissAppList();
}
void AppListServiceAsh::EnableAppList(Profile* initial_profile,