Commit cba46bfe authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

ShellWindowLauncherItemController::RestoreOrShow -> ShowAndActivate

Depends on: https://codereview.chromium.org/13007002/

BUG=179387

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190495 0039d316-1c4b-4281-b951-d872f2087c98
parent 2cead1f6
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -40,12 +41,25 @@ ...@@ -40,12 +41,25 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/events/event.h"
using extensions::Extension; using extensions::Extension;
using content::WebContents; using content::WebContents;
namespace { namespace {
class TestEvent : public ui::Event {
public:
explicit TestEvent(ui::EventType type)
: ui::Event(type, base::TimeDelta(), 0) {
}
virtual ~TestEvent() {
}
private:
DISALLOW_COPY_AND_ASSIGN(TestEvent);
};
class TestShellWindowRegistryObserver class TestShellWindowRegistryObserver
: public extensions::ShellWindowRegistry::Observer { : public extensions::ShellWindowRegistry::Observer {
public: public:
...@@ -119,7 +133,7 @@ class LauncherPlatformPerAppAppBrowserTest ...@@ -119,7 +133,7 @@ class LauncherPlatformPerAppAppBrowserTest
return launcher_model()->items()[launcher_model()->item_count() - 1]; return launcher_model()->items()[launcher_model()->item_count() - 1];
} }
const LauncherItemController* GetItemController(ash::LauncherID id) { LauncherItemController* GetItemController(ash::LauncherID id) {
return controller_->id_to_item_controller_map_[id]; return controller_->id_to_item_controller_map_[id];
} }
...@@ -537,6 +551,38 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) { ...@@ -537,6 +551,38 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) {
EXPECT_EQ(item_count, launcher_model()->item_count()); EXPECT_EQ(item_count, launcher_model()->item_count());
} }
// Confirm that Click behavior for app windows is correnct.
IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, AppClickBehavior) {
// Launch a platform app and create a window for it.
const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
ShellWindow* window1 = CreateShellWindow(extension1);
EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
// Confirm that a controller item was created and is the correct state.
const ash::LauncherItem& item1 = GetLastLauncherItem();
LauncherItemController* item1_controller = GetItemController(item1.id);
EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
// Minimize the window and confirm that the controller item is updated.
window1->GetBaseWindow()->Minimize();
EXPECT_FALSE(window1->GetNativeWindow()->IsVisible());
EXPECT_FALSE(window1->GetBaseWindow()->IsActive());
EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
// Clicking on the controller should activate the window.
TestEvent default_event(ui::ET_MOUSE_PRESSED);
item1_controller->Clicked(default_event);
EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
// Maximizing a window should preserve state after minimize + click.
window1->GetBaseWindow()->Maximize();
window1->GetBaseWindow()->Minimize();
item1_controller->Clicked(default_event);
EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized());
}
IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest,
BrowserActivation) { BrowserActivation) {
int item_count = launcher_model()->item_count(); int item_count = launcher_model()->item_count();
......
...@@ -142,7 +142,7 @@ void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { ...@@ -142,7 +142,7 @@ void ShellWindowLauncherItemController::Clicked(const ui::Event& event) {
shell_windows_.size() == 1) { shell_windows_.size() == 1) {
ShellWindow* window_to_show = last_active_shell_window_ ? ShellWindow* window_to_show = last_active_shell_window_ ?
last_active_shell_window_ : shell_windows_.front(); last_active_shell_window_ : shell_windows_.front();
RestoreOrShow(window_to_show); ShowAndActivate(window_to_show);
} else { } else {
// TODO(stevenjb): Deprecate // TODO(stevenjb): Deprecate
if (!last_active_shell_window_ || if (!last_active_shell_window_ ||
...@@ -156,7 +156,7 @@ void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { ...@@ -156,7 +156,7 @@ void ShellWindowLauncherItemController::Clicked(const ui::Event& event) {
} }
} }
if (last_active_shell_window_) if (last_active_shell_window_)
RestoreOrShow(last_active_shell_window_); ShowAndActivate(last_active_shell_window_);
} }
} }
...@@ -165,7 +165,7 @@ void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) { ...@@ -165,7 +165,7 @@ void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) {
return; return;
ShellWindowList::iterator it = shell_windows_.begin(); ShellWindowList::iterator it = shell_windows_.begin();
std::advance(it, index); std::advance(it, index);
RestoreOrShow(*it); ShowAndActivate(*it);
} }
ChromeLauncherAppMenuItems ChromeLauncherAppMenuItems
...@@ -206,12 +206,9 @@ void ShellWindowLauncherItemController::OnWindowPropertyChanged( ...@@ -206,12 +206,9 @@ void ShellWindowLauncherItemController::OnWindowPropertyChanged(
} }
} }
void ShellWindowLauncherItemController::RestoreOrShow( void ShellWindowLauncherItemController::ShowAndActivate(
ShellWindow* shell_window) { ShellWindow* shell_window) {
if (shell_window->GetBaseWindow()->IsMinimized())
shell_window->GetBaseWindow()->Restore();
else
shell_window->GetBaseWindow()->Show();
// Always activate windows when shown from the launcher. // Always activate windows when shown from the launcher.
shell_window->GetBaseWindow()->Show();
shell_window->GetBaseWindow()->Activate(); shell_window->GetBaseWindow()->Activate();
} }
...@@ -80,7 +80,7 @@ class ShellWindowLauncherItemController : public LauncherItemController, ...@@ -80,7 +80,7 @@ class ShellWindowLauncherItemController : public LauncherItemController,
private: private:
typedef std::list<ShellWindow*> ShellWindowList; typedef std::list<ShellWindow*> ShellWindowList;
void RestoreOrShow(ShellWindow* shell_window); void ShowAndActivate(ShellWindow* shell_window);
// List of associated shell windows // List of associated shell windows
ShellWindowList shell_windows_; ShellWindowList shell_windows_;
......
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