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/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
9 #include "ash/shelf/shelf_item_delegate_manager.h" | 9 #include "ash/shelf/shelf_item_delegate_manager.h" |
10 #include "ash/shelf/shelf_model.h" | 10 #include "ash/shelf/shelf_model.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 WindowWatcher::~WindowWatcher() { | 81 WindowWatcher::~WindowWatcher() { |
82 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 82 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
83 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 83 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
84 iter != root_windows.end(); ++ iter) { | 84 iter != root_windows.end(); ++ iter) { |
85 workspace_window_watcher_->RootWindowRemoved(*iter); | 85 workspace_window_watcher_->RootWindowRemoved(*iter); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { | 89 aura::Window* WindowWatcher::GetWindowByID(ash::ShelfID id) { |
90 IDToWindow::const_iterator i = id_to_window_.find(id); | 90 IDToWindow::const_iterator i = id_to_window_.find(id); |
91 return i != id_to_window_.end() ? i->second : NULL; | 91 return i != id_to_window_.end() ? i->second : NULL; |
92 } | 92 } |
93 | 93 |
94 // aura::WindowObserver overrides: | 94 // aura::WindowObserver overrides: |
95 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { | 95 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { |
96 if (new_window->type() != ui::wm::WINDOW_TYPE_NORMAL && | 96 if (new_window->type() != ui::wm::WINDOW_TYPE_NORMAL && |
97 new_window->type() != ui::wm::WINDOW_TYPE_PANEL) | 97 new_window->type() != ui::wm::WINDOW_TYPE_PANEL) |
98 return; | 98 return; |
99 | 99 |
100 static int image_count = 0; | 100 static int image_count = 0; |
101 ShelfModel* model = Shell::GetInstance()->shelf_model(); | 101 ShelfModel* model = Shell::GetInstance()->shelf_model(); |
102 LauncherItem item; | 102 ShelfItem item; |
103 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL | 103 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL |
104 ? ash::TYPE_APP_PANEL | 104 ? ash::TYPE_APP_PANEL |
105 : ash::TYPE_PLATFORM_APP; | 105 : ash::TYPE_PLATFORM_APP; |
106 ash::LauncherID id = model->next_id(); | 106 ash::ShelfID id = model->next_id(); |
107 id_to_window_[id] = new_window; | 107 id_to_window_[id] = new_window; |
108 | 108 |
109 SkBitmap icon_bitmap; | 109 SkBitmap icon_bitmap; |
110 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 110 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
111 icon_bitmap.allocPixels(); | 111 icon_bitmap.allocPixels(); |
112 icon_bitmap.eraseARGB(255, | 112 icon_bitmap.eraseARGB(255, |
113 image_count == 0 ? 255 : 0, | 113 image_count == 0 ? 255 : 0, |
114 image_count == 1 ? 255 : 0, | 114 image_count == 1 ? 255 : 0, |
115 image_count == 2 ? 255 : 0); | 115 image_count == 2 ? 255 : 0); |
116 image_count = (image_count + 1) % 3; | 116 image_count = (image_count + 1) % 3; |
117 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); | 117 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); |
118 | 118 |
119 model->Add(item); | 119 model->Add(item); |
120 | 120 |
121 ShelfItemDelegateManager* manager = | 121 ShelfItemDelegateManager* manager = |
122 Shell::GetInstance()->shelf_item_delegate_manager(); | 122 Shell::GetInstance()->shelf_item_delegate_manager(); |
123 scoped_ptr<ShelfItemDelegate> delegate( | 123 scoped_ptr<ShelfItemDelegate> delegate( |
124 new WindowWatcherShelfItemDelegate(id, this)); | 124 new WindowWatcherShelfItemDelegate(id, this)); |
125 manager->SetShelfItemDelegate(id, delegate.Pass()); | 125 manager->SetShelfItemDelegate(id, delegate.Pass()); |
126 SetLauncherIDForWindow(id, new_window); | 126 SetShelfIDForWindow(id, new_window); |
127 } | 127 } |
128 | 128 |
129 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 129 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
130 for (IDToWindow::iterator i = id_to_window_.begin(); | 130 for (IDToWindow::iterator i = id_to_window_.begin(); |
131 i != id_to_window_.end(); ++i) { | 131 i != id_to_window_.end(); ++i) { |
132 if (i->second == window) { | 132 if (i->second == window) { |
133 ShelfModel* model = Shell::GetInstance()->shelf_model(); | 133 ShelfModel* model = Shell::GetInstance()->shelf_model(); |
134 int index = model->ItemIndexByID(i->first); | 134 int index = model->ItemIndexByID(i->first); |
135 DCHECK_NE(-1, index); | 135 DCHECK_NE(-1, index); |
136 model->RemoveItemAt(index); | 136 model->RemoveItemAt(index); |
(...skipping 12 matching lines...) Expand all Loading... |
149 workspace_window_watcher_->RootWindowAdded(root); | 149 workspace_window_watcher_->RootWindowAdded(root); |
150 } | 150 } |
151 | 151 |
152 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { | 152 void WindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { |
153 // All windows in the display has already been removed, so no need to | 153 // All windows in the display has already been removed, so no need to |
154 // remove observers. | 154 // remove observers. |
155 } | 155 } |
156 | 156 |
157 } // namespace shell | 157 } // namespace shell |
158 } // namespace ash | 158 } // namespace ash |
OLD | NEW |