| 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/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
| 8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ui/aura/root_window.h" |
| 11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 12 | 13 |
| 13 namespace ash { | 14 namespace ash { |
| 14 namespace shell { | 15 namespace shell { |
| 15 | 16 |
| 16 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { | 17 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { |
| 17 public: | 18 public: |
| 18 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) { | 19 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) { |
| 19 watcher_->window_->AddObserver(this); | 20 watcher_->window_->AddObserver(this); |
| 20 for (size_t i = 0; i < watcher_->window_->children().size(); ++i) | 21 for (size_t i = 0; i < watcher_->window_->children().size(); ++i) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 window->RemoveObserver(watcher_); | 37 window->RemoveObserver(watcher_); |
| 37 } | 38 } |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 WindowWatcher* watcher_; | 41 WindowWatcher* watcher_; |
| 41 | 42 |
| 42 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); | 43 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 WindowWatcher::WindowWatcher() | 46 WindowWatcher::WindowWatcher() |
| 46 : window_(ash::Shell::GetInstance()->launcher()->window_container()), | 47 : window_(Launcher::ForPrimaryDisplay()->window_container()), |
| 47 panel_container_(ash::Shell::GetContainer( | 48 panel_container_(ash::Shell::GetContainer( |
| 48 Shell::GetPrimaryRootWindow(), | 49 window_->GetRootWindow(), |
| 49 internal::kShellWindowId_PanelContainer)) { | 50 internal::kShellWindowId_PanelContainer)) { |
| 50 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this)); | 51 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this)); |
| 51 panel_container_->AddObserver(this); | 52 panel_container_->AddObserver(this); |
| 52 } | 53 } |
| 53 | 54 |
| 54 WindowWatcher::~WindowWatcher() { | 55 WindowWatcher::~WindowWatcher() { |
| 55 panel_container_->RemoveObserver(this); | 56 panel_container_->RemoveObserver(this); |
| 56 } | 57 } |
| 57 | 58 |
| 58 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { | 59 aura::Window* WindowWatcher::GetWindowByID(ash::LauncherID id) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 return 0; // TODO: add a constant for this. | 70 return 0; // TODO: add a constant for this. |
| 70 } | 71 } |
| 71 | 72 |
| 72 // aura::WindowObserver overrides: | 73 // aura::WindowObserver overrides: |
| 73 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { | 74 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { |
| 74 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL && | 75 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL && |
| 75 new_window->type() != aura::client::WINDOW_TYPE_PANEL) | 76 new_window->type() != aura::client::WINDOW_TYPE_PANEL) |
| 76 return; | 77 return; |
| 77 | 78 |
| 78 static int image_count = 0; | 79 static int image_count = 0; |
| 79 ash::LauncherModel* model = ash::Shell::GetInstance()->launcher()->model(); | 80 ash::LauncherModel* model = Launcher::ForPrimaryDisplay()->model(); |
| 80 ash::LauncherItem item; | 81 ash::LauncherItem item; |
| 81 item.type = ash::TYPE_TABBED; | 82 item.type = ash::TYPE_TABBED; |
| 82 id_to_window_[model->next_id()] = new_window; | 83 id_to_window_[model->next_id()] = new_window; |
| 83 | 84 |
| 84 SkBitmap icon_bitmap; | 85 SkBitmap icon_bitmap; |
| 85 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 86 icon_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
| 86 icon_bitmap.allocPixels(); | 87 icon_bitmap.allocPixels(); |
| 87 icon_bitmap.eraseARGB(255, | 88 icon_bitmap.eraseARGB(255, |
| 88 image_count == 0 ? 255 : 0, | 89 image_count == 0 ? 255 : 0, |
| 89 image_count == 1 ? 255 : 0, | 90 image_count == 1 ? 255 : 0, |
| 90 image_count == 2 ? 255 : 0); | 91 image_count == 2 ? 255 : 0); |
| 91 image_count = (image_count + 1) % 3; | 92 image_count = (image_count + 1) % 3; |
| 92 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, | 93 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, |
| 93 ui::SCALE_FACTOR_NONE)); | 94 ui::SCALE_FACTOR_NONE)); |
| 94 | 95 |
| 95 model->Add(item); | 96 model->Add(item); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 99 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
| 99 for (IDToWindow::iterator i = id_to_window_.begin(); | 100 for (IDToWindow::iterator i = id_to_window_.begin(); |
| 100 i != id_to_window_.end(); ++i) { | 101 i != id_to_window_.end(); ++i) { |
| 101 if (i->second == window) { | 102 if (i->second == window) { |
| 102 ash::LauncherModel* model = | 103 ash::LauncherModel* model = Launcher::ForPrimaryDisplay()->model(); |
| 103 ash::Shell::GetInstance()->launcher()->model(); | |
| 104 int index = model->ItemIndexByID(i->first); | 104 int index = model->ItemIndexByID(i->first); |
| 105 DCHECK_NE(-1, index); | 105 DCHECK_NE(-1, index); |
| 106 model->RemoveItemAt(index); | 106 model->RemoveItemAt(index); |
| 107 id_to_window_.erase(i); | 107 id_to_window_.erase(i); |
| 108 break; | 108 break; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace shell | 113 } // namespace shell |
| 114 } // namespace ash | 114 } // namespace ash |
| OLD | NEW |