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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 9 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
10 #include "ash/common/shelf/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/wm_shell.h" |
12 #include "ash/display/window_tree_host_manager.h" | 13 #include "ash/display/window_tree_host_manager.h" |
13 #include "ash/shelf/shelf.h" | 14 #include "ash/shelf/shelf.h" |
14 #include "ash/shelf/shelf_util.h" | 15 #include "ash/shelf/shelf_util.h" |
15 #include "ash/shelf/shelf_widget.h" | 16 #include "ash/shelf/shelf_widget.h" |
16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
17 #include "ash/shell/window_watcher_shelf_item_delegate.h" | 18 #include "ash/shell/window_watcher_shelf_item_delegate.h" |
18 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
20 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
21 #include "ui/display/display.h" | 22 #include "ui/display/display.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 IDToWindow::const_iterator i = id_to_window_.find(id); | 90 IDToWindow::const_iterator i = id_to_window_.find(id); |
90 return i != id_to_window_.end() ? i->second : NULL; | 91 return i != id_to_window_.end() ? i->second : NULL; |
91 } | 92 } |
92 | 93 |
93 // aura::WindowObserver overrides: | 94 // aura::WindowObserver overrides: |
94 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { | 95 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { |
95 if (!wm::IsWindowUserPositionable(new_window)) | 96 if (!wm::IsWindowUserPositionable(new_window)) |
96 return; | 97 return; |
97 | 98 |
98 static int image_count = 0; | 99 static int image_count = 0; |
99 ShelfModel* model = Shell::GetInstance()->shelf_model(); | 100 ShelfModel* model = WmShell::Get()->shelf_model(); |
100 ShelfItem item; | 101 ShelfItem item; |
101 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL | 102 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL |
102 ? ash::TYPE_APP_PANEL | 103 ? ash::TYPE_APP_PANEL |
103 : ash::TYPE_PLATFORM_APP; | 104 : ash::TYPE_PLATFORM_APP; |
104 ash::ShelfID id = model->next_id(); | 105 ash::ShelfID id = model->next_id(); |
105 id_to_window_[id] = new_window; | 106 id_to_window_[id] = new_window; |
106 | 107 |
107 SkBitmap icon_bitmap; | 108 SkBitmap icon_bitmap; |
108 icon_bitmap.allocN32Pixels(16, 16); | 109 icon_bitmap.allocN32Pixels(16, 16); |
109 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0, | 110 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0, |
110 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0); | 111 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0); |
111 image_count = (image_count + 1) % 3; | 112 image_count = (image_count + 1) % 3; |
112 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); | 113 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); |
113 | 114 |
114 model->Add(item); | 115 model->Add(item); |
115 | 116 |
116 ShelfItemDelegateManager* manager = | 117 ShelfItemDelegateManager* manager = |
117 Shell::GetInstance()->shelf_item_delegate_manager(); | 118 Shell::GetInstance()->shelf_item_delegate_manager(); |
118 std::unique_ptr<ShelfItemDelegate> delegate( | 119 std::unique_ptr<ShelfItemDelegate> delegate( |
119 new WindowWatcherShelfItemDelegate(id, this)); | 120 new WindowWatcherShelfItemDelegate(id, this)); |
120 manager->SetShelfItemDelegate(id, std::move(delegate)); | 121 manager->SetShelfItemDelegate(id, std::move(delegate)); |
121 SetShelfIDForWindow(id, new_window); | 122 SetShelfIDForWindow(id, new_window); |
122 } | 123 } |
123 | 124 |
124 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 125 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
125 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); | 126 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); |
126 ++i) { | 127 ++i) { |
127 if (i->second == window) { | 128 if (i->second == window) { |
128 ShelfModel* model = Shell::GetInstance()->shelf_model(); | 129 ShelfModel* model = WmShell::Get()->shelf_model(); |
129 int index = model->ItemIndexByID(i->first); | 130 int index = model->ItemIndexByID(i->first); |
130 DCHECK_NE(-1, index); | 131 DCHECK_NE(-1, index); |
131 model->RemoveItemAt(index); | 132 model->RemoveItemAt(index); |
132 id_to_window_.erase(i); | 133 id_to_window_.erase(i); |
133 break; | 134 break; |
134 } | 135 } |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 void WindowWatcher::OnDisplayAdded(const display::Display& new_display) { | 139 void WindowWatcher::OnDisplayAdded(const display::Display& new_display) { |
139 aura::Window* root = Shell::GetInstance() | 140 aura::Window* root = Shell::GetInstance() |
140 ->window_tree_host_manager() | 141 ->window_tree_host_manager() |
141 ->GetRootWindowForDisplayId(new_display.id()); | 142 ->GetRootWindowForDisplayId(new_display.id()); |
142 workspace_window_watcher_->RootWindowAdded(root); | 143 workspace_window_watcher_->RootWindowAdded(root); |
143 } | 144 } |
144 | 145 |
145 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { | 146 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |
146 // All windows in the display has already been removed, so no need to | 147 // All windows in the display has already been removed, so no need to |
147 // remove observers. | 148 // remove observers. |
148 } | 149 } |
149 | 150 |
150 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { | 151 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { |
151 } | 152 } |
152 | 153 |
153 } // namespace shell | 154 } // namespace shell |
154 } // namespace ash | 155 } // namespace ash |
OLD | NEW |