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

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 LauncherTest and observing LauncherModel in DelegateManager Created 7 years, 3 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
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/launcher_item_delegate_impl.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, 124 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap,
122 ui::SCALE_FACTOR_100P)); 125 ui::SCALE_FACTOR_100P));
123 126
124 model->Add(item); 127 model->Add(item);
128
129 ash::LauncherItemDelegateManager* manager =
130 ash::Shell::GetInstance()->launcher_item_delegate_manager();
131 manager->RegisterLauncherItemDelegate(
132 id,
133 new LauncherItemDelegateImpl(id, this));
125 } 134 }
126 135
127 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { 136 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) {
128 for (IDToWindow::iterator i = id_to_window_.begin(); 137 for (IDToWindow::iterator i = id_to_window_.begin();
129 i != id_to_window_.end(); ++i) { 138 i != id_to_window_.end(); ++i) {
130 if (i->second == window) { 139 if (i->second == window) {
131 ash::LauncherModel* model = Shell::GetInstance()->launcher_model(); 140 ash::LauncherModel* model = Shell::GetInstance()->launcher_model();
132 int index = model->ItemIndexByID(i->first); 141 int index = model->ItemIndexByID(i->first);
133 DCHECK_NE(-1, index); 142 DCHECK_NE(-1, index);
134 model->RemoveItemAt(index); 143 model->RemoveItemAt(index);
(...skipping 12 matching lines...) Expand all
147 workspace_window_watcher_->RootWindowAdded(root); 156 workspace_window_watcher_->RootWindowAdded(root);
148 } 157 }
149 158
150 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { 159 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) {
151 // All windows in the display has already been removed, so no need to 160 // All windows in the display has already been removed, so no need to
152 // remove observers. 161 // remove observers.
153 } 162 }
154 163
155 } // namespace shell 164 } // namespace shell
156 } // namespace ash 165 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698