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_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
10 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 (!wm::IsWindowUserPositionable(new_window)) | 96 if (!wm::IsWindowUserPositionable(new_window)) |
97 return; | 97 return; |
98 | 98 |
99 static int image_count = 0; | 99 static int image_count = 0; |
100 ShelfModel* model = WmShell::Get()->shelf_model(); | 100 ShelfModel* model = Shell::Get()->shelf_model(); |
101 ShelfItem item; | 101 ShelfItem item; |
102 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL | 102 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL |
103 ? ash::TYPE_APP_PANEL | 103 ? ash::TYPE_APP_PANEL |
104 : ash::TYPE_APP; | 104 : ash::TYPE_APP; |
105 ash::ShelfID id = model->next_id(); | 105 ash::ShelfID id = model->next_id(); |
106 id_to_window_[id] = new_window; | 106 id_to_window_[id] = new_window; |
107 | 107 |
108 SkBitmap icon_bitmap; | 108 SkBitmap icon_bitmap; |
109 icon_bitmap.allocN32Pixels(16, 16); | 109 icon_bitmap.allocN32Pixels(16, 16); |
110 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0, | 110 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0, |
111 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0); | 111 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0); |
112 image_count = (image_count + 1) % 3; | 112 image_count = (image_count + 1) % 3; |
113 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); | 113 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); |
114 item.title = new_window->GetTitle(); | 114 item.title = new_window->GetTitle(); |
115 | 115 |
116 model->Add(item); | 116 model->Add(item); |
117 | 117 |
118 model->SetShelfItemDelegate( | 118 model->SetShelfItemDelegate( |
119 id, base::MakeUnique<WindowWatcherShelfItemDelegate>(id, this)); | 119 id, base::MakeUnique<WindowWatcherShelfItemDelegate>(id, this)); |
120 new_window->SetProperty(kShelfIDKey, id); | 120 new_window->SetProperty(kShelfIDKey, id); |
121 } | 121 } |
122 | 122 |
123 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 123 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
124 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); | 124 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); |
125 ++i) { | 125 ++i) { |
126 if (i->second == window) { | 126 if (i->second == window) { |
127 ShelfModel* model = WmShell::Get()->shelf_model(); | 127 ShelfModel* model = Shell::Get()->shelf_model(); |
128 int index = model->ItemIndexByID(i->first); | 128 int index = model->ItemIndexByID(i->first); |
129 DCHECK_NE(-1, index); | 129 DCHECK_NE(-1, index); |
130 model->RemoveItemAt(index); | 130 model->RemoveItemAt(index); |
131 id_to_window_.erase(i); | 131 id_to_window_.erase(i); |
132 break; | 132 break; |
133 } | 133 } |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 void WindowWatcher::OnDisplayAdded(const display::Display& new_display) { | 137 void WindowWatcher::OnDisplayAdded(const display::Display& new_display) { |
138 aura::Window* root = Shell::GetInstance() | 138 aura::Window* root = Shell::GetInstance() |
139 ->window_tree_host_manager() | 139 ->window_tree_host_manager() |
140 ->GetRootWindowForDisplayId(new_display.id()); | 140 ->GetRootWindowForDisplayId(new_display.id()); |
141 workspace_window_watcher_->RootWindowAdded(root); | 141 workspace_window_watcher_->RootWindowAdded(root); |
142 } | 142 } |
143 | 143 |
144 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { | 144 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |
145 // All windows in the display has already been removed, so no need to | 145 // All windows in the display has already been removed, so no need to |
146 // remove observers. | 146 // remove observers. |
147 } | 147 } |
148 | 148 |
149 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { | 149 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { |
150 } | 150 } |
151 | 151 |
152 } // namespace shell | 152 } // namespace shell |
153 } // namespace ash | 153 } // namespace ash |
OLD | NEW |