| 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/public/cpp/shelf_item.h" | 9 #include "ash/public/cpp/shelf_item.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 11 #include "ash/public/cpp/window_properties.h" |
| 11 #include "ash/shelf/shelf_model.h" | 12 #include "ash/shelf/shelf_model.h" |
| 12 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "ash/shell/window_watcher_shelf_item_delegate.h" | 15 #include "ash/shell/window_watcher_shelf_item_delegate.h" |
| 15 #include "ash/shell_port.h" | 16 #include "ash/shell_port.h" |
| 16 #include "ash/wm/window_properties.h" | |
| 17 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
| 18 #include "ash/wm_window.h" | 18 #include "ash/wm_window.h" |
| 19 #include "base/strings/string_number_conversions.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" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 namespace shell { | 25 namespace shell { |
| 25 | 26 |
| 26 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { | 27 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { |
| 27 public: | 28 public: |
| 28 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) {} | 29 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 79 } |
| 79 | 80 |
| 80 WindowWatcher::~WindowWatcher() { | 81 WindowWatcher::~WindowWatcher() { |
| 81 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 82 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 82 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 83 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
| 83 iter != root_windows.end(); ++iter) { | 84 iter != root_windows.end(); ++iter) { |
| 84 workspace_window_watcher_->RootWindowRemoved(*iter); | 85 workspace_window_watcher_->RootWindowRemoved(*iter); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 aura::Window* WindowWatcher::GetWindowByID(ash::ShelfID id) { | 89 aura::Window* WindowWatcher::GetWindowByID(const ash::ShelfID& id) { |
| 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::Get()->shelf_model(); | 100 ShelfModel* model = Shell::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_APP; | 104 : ash::TYPE_APP; |
| 104 ash::ShelfID id = model->next_id(); | 105 static int shelf_id = 0; |
| 105 id_to_window_[id] = new_window; | 106 item.id = ShelfID(base::IntToString(shelf_id++)); |
| 107 id_to_window_[item.id] = new_window; |
| 106 | 108 |
| 107 SkBitmap icon_bitmap; | 109 SkBitmap icon_bitmap; |
| 108 icon_bitmap.allocN32Pixels(16, 16); | 110 icon_bitmap.allocN32Pixels(16, 16); |
| 109 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0, | 111 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0, |
| 110 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0); | 112 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0); |
| 111 image_count = (image_count + 1) % 3; | 113 image_count = (image_count + 1) % 3; |
| 112 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); | 114 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); |
| 113 item.title = new_window->GetTitle(); | 115 item.title = new_window->GetTitle(); |
| 114 | 116 |
| 115 model->Add(item); | 117 model->Add(item); |
| 116 | 118 |
| 117 model->SetShelfItemDelegate( | 119 model->SetShelfItemDelegate( |
| 118 id, base::MakeUnique<WindowWatcherShelfItemDelegate>(id, this)); | 120 item.id, base::MakeUnique<WindowWatcherShelfItemDelegate>(item.id, this)); |
| 119 new_window->SetProperty(kShelfIDKey, id); | 121 new_window->SetProperty(kShelfIDKey, new ShelfID(item.id)); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 124 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
| 123 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); | 125 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); |
| 124 ++i) { | 126 ++i) { |
| 125 if (i->second == window) { | 127 if (i->second == window) { |
| 126 ShelfModel* model = Shell::Get()->shelf_model(); | 128 ShelfModel* model = Shell::Get()->shelf_model(); |
| 127 int index = model->ItemIndexByID(i->first); | 129 int index = model->ItemIndexByID(i->first); |
| 128 DCHECK_NE(-1, index); | 130 DCHECK_NE(-1, index); |
| 129 model->RemoveItemAt(index); | 131 model->RemoveItemAt(index); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { | 144 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { |
| 143 // 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 |
| 144 // remove observers. | 146 // remove observers. |
| 145 } | 147 } |
| 146 | 148 |
| 147 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { | 149 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { |
| 148 } | 150 } |
| 149 | 151 |
| 150 } // namespace shell | 152 } // namespace shell |
| 151 } // namespace ash | 153 } // namespace ash |
| OLD | NEW |