OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/shell/window_watcher.h" | 5 #include "ash/shell/window_watcher.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
9 #include "ash/launcher/launcher_item_delegate_manager.h" | |
10 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
11 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
13 #include "ash/shell/window_watcher_launcher_item_delegate.h" | |
14 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
15 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
17 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
18 | 16 |
19 namespace ash { | 17 namespace ash { |
20 namespace shell { | 18 namespace shell { |
21 | 19 |
22 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { | 20 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { |
23 public: | 21 public: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { | 101 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { |
104 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL && | 102 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL && |
105 new_window->type() != aura::client::WINDOW_TYPE_PANEL) | 103 new_window->type() != aura::client::WINDOW_TYPE_PANEL) |
106 return; | 104 return; |
107 | 105 |
108 static int image_count = 0; | 106 static int image_count = 0; |
109 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); | 107 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); |
110 ash::LauncherItem item; | 108 ash::LauncherItem item; |
111 item.type = new_window->type() == aura::client::WINDOW_TYPE_PANEL ? | 109 item.type = new_window->type() == aura::client::WINDOW_TYPE_PANEL ? |
112 ash::TYPE_APP_PANEL : ash::TYPE_PLATFORM_APP; | 110 ash::TYPE_APP_PANEL : ash::TYPE_PLATFORM_APP; |
113 ash::LauncherID id = model->next_id(); | 111 id_to_window_[model->next_id()] = new_window; |
114 id_to_window_[id] = new_window; | |
115 | 112 |
116 SkBitmap icon_bitmap; | 113 SkBitmap icon_bitmap; |
117 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 114 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
118 icon_bitmap.allocPixels(); | 115 icon_bitmap.allocPixels(); |
119 icon_bitmap.eraseARGB(255, | 116 icon_bitmap.eraseARGB(255, |
120 image_count == 0 ? 255 : 0, | 117 image_count == 0 ? 255 : 0, |
121 image_count == 1 ? 255 : 0, | 118 image_count == 1 ? 255 : 0, |
122 image_count == 2 ? 255 : 0); | 119 image_count == 2 ? 255 : 0); |
123 image_count = (image_count + 1) % 3; | 120 image_count = (image_count + 1) % 3; |
124 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); | 121 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); |
125 | 122 |
126 model->Add(item); | 123 model->Add(item); |
127 | |
128 ash::LauncherItemDelegateManager* manager = | |
129 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | |
130 scoped_ptr<LauncherItemDelegate> delegate( | |
131 new WindowWatcherLauncherItemDelegate(id, this)); | |
132 manager->SetLauncherItemDelegate(id, delegate.Pass()); | |
133 } | 124 } |
134 | 125 |
135 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 126 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
136 for (IDToWindow::iterator i = id_to_window_.begin(); | 127 for (IDToWindow::iterator i = id_to_window_.begin(); |
137 i != id_to_window_.end(); ++i) { | 128 i != id_to_window_.end(); ++i) { |
138 if (i->second == window) { | 129 if (i->second == window) { |
139 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); | 130 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); |
140 int index = model->ItemIndexByID(i->first); | 131 int index = model->ItemIndexByID(i->first); |
141 DCHECK_NE(-1, index); | 132 DCHECK_NE(-1, index); |
142 model->RemoveItemAt(index); | 133 model->RemoveItemAt(index); |
(...skipping 12 matching lines...) Expand all Loading... |
155 workspace_window_watcher_->RootWindowAdded(root); | 146 workspace_window_watcher_->RootWindowAdded(root); |
156 } | 147 } |
157 | 148 |
158 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { | 149 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { |
159 // All windows in the display has already been removed, so no need to | 150 // All windows in the display has already been removed, so no need to |
160 // remove observers. | 151 // remove observers. |
161 } | 152 } |
162 | 153 |
163 } // namespace shell | 154 } // namespace shell |
164 } // namespace ash | 155 } // namespace ash |
OLD | NEW |