summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-13 03:21:35 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-13 03:21:35 +0000
commit0af58047ddfc16ea8e5a0f3921b4f45db77de991 (patch)
tree9dd47825cd74c830b94671c434f0af8e912826ca /ash
parent56d8944437d7e1f0d3c1fa65819bca95a7a00bb2 (diff)
downloadchromium_src-0af58047ddfc16ea8e5a0f3921b4f45db77de991.zip
chromium_src-0af58047ddfc16ea8e5a0f3921b4f45db77de991.tar.gz
chromium_src-0af58047ddfc16ea8e5a0f3921b4f45db77de991.tar.bz2
Make Shell::launcher_model() / GetLauncherDelegate private
Move SwitchToWindow impl to Launcher BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/11558031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172803 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/accelerators/accelerator_controller.cc47
-rw-r--r--ash/accelerators/accelerator_controller.h4
-rw-r--r--ash/launcher/launcher.cc40
-rw-r--r--ash/launcher/launcher.h8
-rw-r--r--ash/launcher/launcher_unittest.cc2
-rw-r--r--ash/launcher/launcher_view.h2
-rw-r--r--ash/root_window_controller.cc8
-rw-r--r--ash/shell.h19
-rw-r--r--ash/test/shell_test_api.cc4
-rw-r--r--ash/test/shell_test_api.h2
10 files changed, 79 insertions, 57 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index e68f545..22c0e2c 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -673,31 +673,31 @@ bool AcceleratorController::PerformAction(int action,
return ime_control_delegate_->HandleSwitchIme(accelerator);
break;
case SELECT_WIN_0:
- SwitchToWindow(0);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(0);
return true;
case SELECT_WIN_1:
- SwitchToWindow(1);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(1);
return true;
case SELECT_WIN_2:
- SwitchToWindow(2);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(2);
return true;
case SELECT_WIN_3:
- SwitchToWindow(3);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(3);
return true;
case SELECT_WIN_4:
- SwitchToWindow(4);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(4);
return true;
case SELECT_WIN_5:
- SwitchToWindow(5);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(5);
return true;
case SELECT_WIN_6:
- SwitchToWindow(6);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(6);
return true;
case SELECT_WIN_7:
- SwitchToWindow(7);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(7);
return true;
case SELECT_LAST_WIN:
- SwitchToWindow(-1);
+ Launcher::ForPrimaryDisplay()->SwitchToWindow(-1);
return true;
case WINDOW_SNAP_LEFT:
case WINDOW_SNAP_RIGHT: {
@@ -830,35 +830,6 @@ bool AcceleratorController::AcceleratorPressed(
return PerformAction(static_cast<AcceleratorAction>(it->second), accelerator);
}
-void AcceleratorController::SwitchToWindow(int window) {
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- LauncherModel* launcher_model = Shell::GetInstance()->launcher_model();
- const LauncherItems& items = launcher_model->items();
- int item_count = launcher_model->item_count();
- int indexes_left = window >= 0 ? window : item_count;
- int found_index = -1;
-
- // Iterating until we have hit the index we are interested in which
- // is true once indexes_left becomes negative.
- for (int i = 0; i < item_count && indexes_left >= 0; i++) {
- if (items[i].type != TYPE_APP_LIST &&
- items[i].type != TYPE_BROWSER_SHORTCUT) {
- found_index = i;
- indexes_left--;
- }
- }
-
- // There are two ways how found_index can be valid: a.) the nth item was
- // found (which is true when indexes_left is -1) or b.) the last item was
- // requested (which is true when index was passed in as a negative number).
- if (found_index >= 0 && (indexes_left == -1 || window < 0) &&
- (items[found_index].status == ash::STATUS_RUNNING ||
- items[found_index].status == ash::STATUS_CLOSED)) {
- // Then set this one as active.
- launcher->ActivateLauncherItem(found_index);
- }
-}
-
void AcceleratorController::RegisterAccelerators(
const AcceleratorData accelerators[],
size_t accelerators_length) {
diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h
index ad55e15..468a5bf 100644
--- a/ash/accelerators/accelerator_controller.h
+++ b/ash/accelerators/accelerator_controller.h
@@ -121,10 +121,6 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// Initializes the accelerators this class handles as a target.
void Init();
- // Switches to a 0-indexed (in order of creation) window.
- // A negative index switches to the last window in the list.
- void SwitchToWindow(int window);
-
// Registers the specified accelerators.
void RegisterAccelerators(const AcceleratorData accelerators[],
size_t accelerators_length);
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc
index d9b1a3f..8668879 100644
--- a/ash/launcher/launcher.cc
+++ b/ash/launcher/launcher.cc
@@ -199,14 +199,16 @@ void Launcher::DelegateView::UpdateBackground(int alpha) {
// Launcher --------------------------------------------------------------------
-Launcher::Launcher(aura::Window* window_container,
+Launcher::Launcher(LauncherModel* launcher_model,
+ LauncherDelegate* launcher_delegate,
+ aura::Window* window_container,
internal::ShelfLayoutManager* shelf_layout_manager)
: widget_(NULL),
window_container_(window_container),
delegate_view_(new DelegateView(this)),
launcher_view_(NULL),
alignment_(SHELF_ALIGNMENT_BOTTOM),
- delegate_(Shell::GetInstance()->GetLauncherDelegate()),
+ delegate_(launcher_delegate),
background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha) {
widget_.reset(new views::Widget);
views::Widget::InitParams params(
@@ -217,7 +219,7 @@ Launcher::Launcher(aura::Window* window_container,
window_container_->GetRootWindow(),
ash::internal::kShellWindowId_LauncherContainer);
launcher_view_ = new internal::LauncherView(
- Shell::GetInstance()->launcher_model(), delegate_, shelf_layout_manager);
+ launcher_model, delegate_, shelf_layout_manager);
launcher_view_->Init();
delegate_view_->AddChildView(launcher_view_);
params.delegate = delegate_view_;
@@ -331,13 +333,13 @@ gfx::Rect Launcher::GetScreenBoundsOfItemIconForWindow(aura::Window* window) {
void Launcher::ActivateLauncherItem(int index) {
const ash::LauncherItems& items =
- Shell::GetInstance()->launcher_model()->items();
+ launcher_view_->model()->items();
delegate_->ItemClicked(items[index], ui::EF_NONE);
}
void Launcher::CycleWindowLinear(CycleDirection direction) {
int item_index = GetNextActivatedItemIndex(
- *(Shell::GetInstance()->launcher_model()), direction);
+ *(launcher_view_->model()), direction);
if (item_index >= 0)
ActivateLauncherItem(item_index);
}
@@ -376,6 +378,34 @@ void Launcher::SetWidgetBounds(const gfx::Rect bounds) {
dimmer_->SetBounds(bounds);
}
+void Launcher::SwitchToWindow(int window_index) {
+ LauncherModel* launcher_model = launcher_view_->model();
+ const LauncherItems& items = launcher_model->items();
+ int item_count = launcher_model->item_count();
+ int indexes_left = window_index >= 0 ? window_index : item_count;
+ int found_index = -1;
+
+ // Iterating until we have hit the index we are interested in which
+ // is true once indexes_left becomes negative.
+ for (int i = 0; i < item_count && indexes_left >= 0; i++) {
+ if (items[i].type != TYPE_APP_LIST &&
+ items[i].type != TYPE_BROWSER_SHORTCUT) {
+ found_index = i;
+ indexes_left--;
+ }
+ }
+
+ // There are two ways how found_index can be valid: a.) the nth item was
+ // found (which is true when indexes_left is -1) or b.) the last item was
+ // requested (which is true when index was passed in as a negative number).
+ if (found_index >= 0 && (indexes_left == -1 || window_index < 0) &&
+ (items[found_index].status == ash::STATUS_RUNNING ||
+ items[found_index].status == ash::STATUS_CLOSED)) {
+ // Then set this one as active.
+ ActivateLauncherItem(found_index);
+ }
+}
+
internal::LauncherView* Launcher::GetLauncherViewForTest() {
return launcher_view_;
}
diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h
index 758482a..03de4ec 100644
--- a/ash/launcher/launcher.h
+++ b/ash/launcher/launcher.h
@@ -40,7 +40,9 @@ class LauncherModel;
class ASH_EXPORT Launcher {
public:
- Launcher(aura::Window* window_container,
+ Launcher(LauncherModel* launcher_model,
+ LauncherDelegate* launcher_delegate,
+ aura::Window* window_container,
internal::ShelfLayoutManager* shelf_layout_manager);
virtual ~Launcher();
@@ -106,6 +108,10 @@ class ASH_EXPORT Launcher {
// Sets the bounds of the launcher widget, and the dimmer if visible.
void SetWidgetBounds(const gfx::Rect bounds);
+ // Switches to a 0-indexed (in order of creation) window.
+ // A negative index switches to the last window in the list.
+ void SwitchToWindow(int window_index);
+
// Only to be called for testing. Retrieves the LauncherView.
// TODO(sky): remove this!
internal::LauncherView* GetLauncherViewForTest();
diff --git a/ash/launcher/launcher_unittest.cc b/ash/launcher/launcher_unittest.cc
index 2c6dd58..2c3f8a8 100644
--- a/ash/launcher/launcher_unittest.cc
+++ b/ash/launcher/launcher_unittest.cc
@@ -58,7 +58,7 @@ TEST_F(LauncherTest, OpenBrowser) {
ASSERT_TRUE(launcher);
LauncherView* launcher_view = launcher->GetLauncherViewForTest();
test::LauncherViewTestAPI test(launcher_view);
- LauncherModel* model = Shell::GetInstance()->launcher_model();
+ LauncherModel* model = launcher_view->model();
// Initially we have the app list and chrome icon.
int button_count = test.GetButtonCount();
diff --git a/ash/launcher/launcher_view.h b/ash/launcher/launcher_view.h
index 8b96028..2bb5b91 100644
--- a/ash/launcher/launcher_view.h
+++ b/ash/launcher/launcher_view.h
@@ -59,6 +59,8 @@ class ASH_EXPORT LauncherView : public views::View,
LauncherTooltipManager* tooltip_manager() { return tooltip_.get(); }
+ LauncherModel* model() { return model_; }
+
void Init();
void OnShelfAlignmentChanged();
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc
index b1ea646..f726e21 100644
--- a/ash/root_window_controller.cc
+++ b/ash/root_window_controller.cc
@@ -341,7 +341,13 @@ void RootWindowController::CreateLauncher() {
aura::Window* default_container =
GetContainer(internal::kShellWindowId_DefaultContainer);
- launcher_.reset(new Launcher(default_container, shelf_));
+ // Get the delegate first to make sure the launcher model is created.
+ LauncherDelegate* launcher_delegate =
+ Shell::GetInstance()->GetLauncherDelegate();
+ launcher_.reset(new Launcher(Shell::GetInstance()->launcher_model(),
+ launcher_delegate,
+ default_container,
+ shelf_));
launcher_->SetFocusCycler(Shell::GetInstance()->focus_cycler());
shelf_->SetLauncher(launcher_.get());
diff --git a/ash/shell.h b/ash/shell.h
index 83fe9eb..e8156e0 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -118,6 +118,10 @@ class TouchObserverHUD;
class WorkspaceController;
}
+namespace shell {
+class WindowWatcher;
+}
+
namespace test {
class ShellTestApi;
}
@@ -373,9 +377,6 @@ class ASH_EXPORT Shell
// Returns the system tray on primary display.
SystemTray* GetPrimarySystemTray();
- // Returns the launcher delegate, creating if necesary.
- LauncherDelegate* GetLauncherDelegate();
-
SystemTrayDelegate* system_tray_delegate() {
return system_tray_delegate_.get();
}
@@ -384,10 +385,6 @@ class ASH_EXPORT Shell
return system_tray_notifier_.get();
}
- LauncherModel* launcher_model() {
- return launcher_model_.get();
- }
-
static void set_initially_hide_cursor(bool hide) {
initially_hide_cursor_ = hide;
}
@@ -433,6 +430,7 @@ class ASH_EXPORT Shell
FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
friend class internal::RootWindowController;
friend class test::ShellTestApi;
+ friend class shell::WindowWatcher;
typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
@@ -441,6 +439,13 @@ class ASH_EXPORT Shell
void Init();
+ LauncherModel* launcher_model() {
+ return launcher_model_.get();
+ }
+
+ // Returns the launcher delegate, creating if necesary.
+ LauncherDelegate* GetLauncherDelegate();
+
// Initializes the root window and root window controller so that it
// can host browser windows.
void InitRootWindowController(internal::RootWindowController* root);
diff --git a/ash/test/shell_test_api.cc b/ash/test/shell_test_api.cc
index 34e6535..03dbb3a 100644
--- a/ash/test/shell_test_api.cc
+++ b/ash/test/shell_test_api.cc
@@ -35,5 +35,9 @@ ShellTestApi::screen_position_controller() {
return shell_->screen_position_controller_.get();
}
+LauncherModel* ShellTestApi::launcher_model() {
+ return shell_->launcher_model_.get();
+}
+
} // namespace test
} // namespace ash
diff --git a/ash/test/shell_test_api.h b/ash/test/shell_test_api.h
index 6830a07..9ff7ef2 100644
--- a/ash/test/shell_test_api.h
+++ b/ash/test/shell_test_api.h
@@ -15,6 +15,7 @@ class InputMethodEventFilter;
namespace ash {
class Shell;
+class LauncherModel;
namespace internal {
class RootWindowLayoutManager;
@@ -35,6 +36,7 @@ public:
internal::SystemGestureEventFilter* system_gesture_event_filter();
internal::WorkspaceController* workspace_controller();
internal::ScreenPositionController* screen_position_controller();
+ LauncherModel* launcher_model();
private:
Shell* shell_; // not owned