summaryrefslogtreecommitdiffstats
path: root/ash/shell
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-24 04:48:06 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-24 04:48:06 +0000
commit04709cd21d245f10011aa32fbaece09abd25e9bc (patch)
tree43081b2b120aff314334682240bca035eb5f1c20 /ash/shell
parentef8c3cf92c861312add2f43c3427eff8ce98ecda (diff)
downloadchromium_src-04709cd21d245f10011aa32fbaece09abd25e9bc.zip
chromium_src-04709cd21d245f10011aa32fbaece09abd25e9bc.tar.gz
chromium_src-04709cd21d245f10011aa32fbaece09abd25e9bc.tar.bz2
Changes the launcher around so that it's up to the shell to populate it
and that each item isn't associated with a window. This allows the chrome side to populate the launcher with items that correspond to app tabs. BUG=110827 TEST=none R=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/9271007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118800 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/shell')
-rw-r--r--ash/shell/shell_main.cc106
1 files changed, 89 insertions, 17 deletions
diff --git a/ash/shell/shell_main.cc b/ash/shell/shell_main.cc
index 7456af1..ea52da8 100644
--- a/ash/shell/shell_main.cc
+++ b/ash/shell/shell_main.cc
@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <map>
+
+#include "ash/launcher/launcher.h"
+#include "ash/launcher/launcher_model.h"
#include "ash/launcher/launcher_types.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
@@ -17,6 +21,7 @@
#include "base/message_loop.h"
#include "grit/ui_resources.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/window_observer.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/gfx/canvas.h"
@@ -42,11 +47,74 @@ class ShellViewsDelegate : public views::TestViewsDelegate {
DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate);
};
-class ShellDelegateImpl : public ash::ShellDelegate {
+// WindowWatcher is responsible for listening for newly created windows and
+// creating items on the Launcher for them.
+class WindowWatcher : public aura::WindowObserver {
public:
- ShellDelegateImpl() {
+ WindowWatcher()
+ : window_(ash::Shell::GetInstance()->launcher()->window_container()) {
+ window_->AddObserver(this);
}
+ virtual ~WindowWatcher() {
+ window_->RemoveObserver(this);
+ }
+
+ aura::Window* GetWindowByID(ash::LauncherID id) {
+ IDToWindow::const_iterator i = id_to_window_.find(id);
+ return i != id_to_window_.end() ? i->second : NULL;
+ }
+
+ // aura::WindowObserver overrides:
+ virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE {
+ static int image_count = 0;
+ ash::LauncherModel* model = ash::Shell::GetInstance()->launcher()->model();
+ ash::LauncherItem item(ash::TYPE_TABBED);
+ id_to_window_[model->next_id()] = new_window;
+ item.num_tabs = image_count + 1;
+ item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ item.image.allocPixels();
+ item.image.eraseARGB(255,
+ image_count == 0 ? 255 : 0,
+ image_count == 1 ? 255 : 0,
+ image_count == 2 ? 255 : 0);
+ image_count = (image_count + 1) % 3;
+ model->Add(model->item_count(), item);
+ }
+
+ virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE {
+ for (IDToWindow::iterator i = id_to_window_.begin();
+ i != id_to_window_.end(); ++i) {
+ if (i->second == window) {
+ ash::LauncherModel* model =
+ ash::Shell::GetInstance()->launcher()->model();
+ int index = model->ItemIndexByID(i->first);
+ DCHECK_NE(-1, index);
+ model->RemoveItemAt(index);
+ id_to_window_.erase(i);
+ break;
+ }
+ }
+ }
+
+ private:
+ typedef std::map<ash::LauncherID, aura::Window*> IDToWindow;
+
+ // Window watching for newly created windows to be added to.
+ aura::Window* window_;
+
+ // Maps from window to the id we gave it.
+ IDToWindow id_to_window_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowWatcher);
+};
+
+class ShellDelegateImpl : public ash::ShellDelegate {
+ public:
+ ShellDelegateImpl() {}
+
+ void set_watcher(WindowWatcher* watcher) { watcher_ = watcher; }
+
virtual void CreateNewWindow() OVERRIDE {
ash::shell::ToplevelWindow::CreateParams create_params;
create_params.can_resize = true;
@@ -89,25 +157,23 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual void LauncherItemClicked(
const ash::LauncherItem& item) OVERRIDE {
- ash::ActivateWindow(item.window);
- }
-
- virtual bool ConfigureLauncherItem(ash::LauncherItem* item) OVERRIDE {
- static int image_count = 0;
- item->num_tabs = image_count + 1;
- item->image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
- item->image.allocPixels();
- item->image.eraseARGB(255,
- image_count == 0 ? 255 : 0,
- image_count == 1 ? 255 : 0,
- image_count == 2 ? 255 : 0);
- image_count = (image_count + 1) % 3;
- return true; // Makes the entry show up in the launcher.
+ ash::ActivateWindow(watcher_->GetWindowByID(item.id));
}
virtual int GetBrowserShortcutResourceId() OVERRIDE {
return IDR_AURA_LAUNCHER_BROWSER_SHORTCUT;
}
+
+ virtual string16 GetLauncherItemTitle(
+ const ash::LauncherItem& item) OVERRIDE {
+ return watcher_->GetWindowByID(item.id)->title();
+ }
+
+ private:
+ // Used to update Launcher. Owned by main.
+ WindowWatcher* watcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl);
};
} // namespace
@@ -136,12 +202,18 @@ int main(int argc, char** argv) {
if (!views::ViewsDelegate::views_delegate)
views::ViewsDelegate::views_delegate = new ShellViewsDelegate;
- ash::Shell::CreateInstance(new ShellDelegateImpl);
+ ShellDelegateImpl* delegate = new ShellDelegateImpl;
+ ash::Shell::CreateInstance(delegate);
+
+ scoped_ptr<WindowWatcher> window_watcher(new WindowWatcher);
+ delegate->set_watcher(window_watcher.get());
ash::shell::InitWindowTypeLauncher();
aura::RootWindow::GetInstance()->Run();
+ window_watcher.reset();
+
ash::Shell::DeleteInstance();
aura::RootWindow::DeleteInstance();