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