Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: ash/shell/window_watcher.cc

Issue 23606016: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for unittest.. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shell/launcher_delegate_impl.cc ('k') | ash/shell/window_watcher_launcher_item_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
9 #include "ash/launcher/launcher_model.h" 10 #include "ash/launcher/launcher_model.h"
10 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell/window_watcher_launcher_item_delegate.h"
12 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
13 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
14 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
15 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
16 18
17 namespace ash { 19 namespace ash {
18 namespace shell { 20 namespace shell {
19 21
20 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { 22 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver {
21 public: 23 public:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { 103 void WindowWatcher::OnWindowAdded(aura::Window* new_window) {
102 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL && 104 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL &&
103 new_window->type() != aura::client::WINDOW_TYPE_PANEL) 105 new_window->type() != aura::client::WINDOW_TYPE_PANEL)
104 return; 106 return;
105 107
106 static int image_count = 0; 108 static int image_count = 0;
107 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); 109 ash::LauncherModel* model = Shell::GetInstance()->launcher_model();
108 ash::LauncherItem item; 110 ash::LauncherItem item;
109 item.type = new_window->type() == aura::client::WINDOW_TYPE_PANEL ? 111 item.type = new_window->type() == aura::client::WINDOW_TYPE_PANEL ?
110 ash::TYPE_APP_PANEL : ash::TYPE_PLATFORM_APP; 112 ash::TYPE_APP_PANEL : ash::TYPE_PLATFORM_APP;
111 id_to_window_[model->next_id()] = new_window; 113 ash::LauncherID id = model->next_id();
114 id_to_window_[id] = new_window;
112 115
113 SkBitmap icon_bitmap; 116 SkBitmap icon_bitmap;
114 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); 117 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
115 icon_bitmap.allocPixels(); 118 icon_bitmap.allocPixels();
116 icon_bitmap.eraseARGB(255, 119 icon_bitmap.eraseARGB(255,
117 image_count == 0 ? 255 : 0, 120 image_count == 0 ? 255 : 0,
118 image_count == 1 ? 255 : 0, 121 image_count == 1 ? 255 : 0,
119 image_count == 2 ? 255 : 0); 122 image_count == 2 ? 255 : 0);
120 image_count = (image_count + 1) % 3; 123 image_count = (image_count + 1) % 3;
121 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); 124 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f));
122 125
123 model->Add(item); 126 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());
124 } 133 }
125 134
126 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { 135 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) {
127 for (IDToWindow::iterator i = id_to_window_.begin(); 136 for (IDToWindow::iterator i = id_to_window_.begin();
128 i != id_to_window_.end(); ++i) { 137 i != id_to_window_.end(); ++i) {
129 if (i->second == window) { 138 if (i->second == window) {
130 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); 139 ash::LauncherModel* model = Shell::GetInstance()->launcher_model();
131 int index = model->ItemIndexByID(i->first); 140 int index = model->ItemIndexByID(i->first);
132 DCHECK_NE(-1, index); 141 DCHECK_NE(-1, index);
133 model->RemoveItemAt(index); 142 model->RemoveItemAt(index);
(...skipping 12 matching lines...) Expand all
146 workspace_window_watcher_->RootWindowAdded(root); 155 workspace_window_watcher_->RootWindowAdded(root);
147 } 156 }
148 157
149 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { 158 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) {
150 // All windows in the display has already been removed, so no need to 159 // All windows in the display has already been removed, so no need to
151 // remove observers. 160 // remove observers.
152 } 161 }
153 162
154 } // namespace shell 163 } // namespace shell
155 } // namespace ash 164 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell/launcher_delegate_impl.cc ('k') | ash/shell/window_watcher_launcher_item_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698