OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/shelf_window_watcher.h" | 5 #include "ash/shelf/shelf_window_watcher.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/shelf/shelf_constants.h" |
8 #include "ash/shelf/shelf_item_delegate_manager.h" | 9 #include "ash/shelf/shelf_item_delegate_manager.h" |
9 #include "ash/shelf/shelf_model.h" | 10 #include "ash/shelf/shelf_model.h" |
10 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
11 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 12 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
13 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "ui/aura/client/activation_client.h" | 17 #include "ui/aura/client/activation_client.h" |
17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
(...skipping 10 matching lines...) Expand all Loading... |
28 item->type = details.type; | 29 item->type = details.type; |
29 if (details.image_resource_id != ash::kInvalidImageResourceID) { | 30 if (details.image_resource_id != ash::kInvalidImageResourceID) { |
30 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 31 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
31 item->image = *rb.GetImageSkiaNamed(details.image_resource_id); | 32 item->image = *rb.GetImageSkiaNamed(details.image_resource_id); |
32 } | 33 } |
33 } | 34 } |
34 | 35 |
35 // Returns true if |window| has a LauncherItem added by ShelfWindowWatcher. | 36 // Returns true if |window| has a LauncherItem added by ShelfWindowWatcher. |
36 bool HasLauncherItemForWindow(aura::Window* window) { | 37 bool HasLauncherItemForWindow(aura::Window* window) { |
37 if (ash::GetLauncherItemDetailsForWindow(window) != NULL && | 38 if (ash::GetLauncherItemDetailsForWindow(window) != NULL && |
38 ash::GetLauncherIDForWindow(window) != ash::kInvalidLauncherID) | 39 ash::GetLauncherIDForWindow(window) != ash::kInvalidShelfID) |
39 return true; | 40 return true; |
40 return false; | 41 return false; |
41 } | 42 } |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 namespace ash { | 46 namespace ash { |
46 namespace internal { | 47 namespace internal { |
47 | 48 |
48 ShelfWindowWatcher::RootWindowObserver::RootWindowObserver( | 49 ShelfWindowWatcher::RootWindowObserver::RootWindowObserver( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 SetLauncherIDForWindow(id, window); | 92 SetLauncherIDForWindow(id, window); |
92 scoped_ptr<ShelfItemDelegate> item_delegate( | 93 scoped_ptr<ShelfItemDelegate> item_delegate( |
93 new ShelfWindowWatcherItemDelegate(window)); | 94 new ShelfWindowWatcherItemDelegate(window)); |
94 // |item_delegate| is owned by |item_delegate_manager_|. | 95 // |item_delegate| is owned by |item_delegate_manager_|. |
95 item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass()); | 96 item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass()); |
96 model_->Add(item); | 97 model_->Add(item); |
97 } | 98 } |
98 | 99 |
99 void ShelfWindowWatcher::RemoveLauncherItem(aura::Window* window) { | 100 void ShelfWindowWatcher::RemoveLauncherItem(aura::Window* window) { |
100 model_->RemoveItemAt(model_->ItemIndexByID(GetLauncherIDForWindow(window))); | 101 model_->RemoveItemAt(model_->ItemIndexByID(GetLauncherIDForWindow(window))); |
101 SetLauncherIDForWindow(kInvalidLauncherID, window); | 102 SetLauncherIDForWindow(kInvalidShelfID, window); |
102 } | 103 } |
103 | 104 |
104 void ShelfWindowWatcher::OnRootWindowAdded(aura::Window* root_window) { | 105 void ShelfWindowWatcher::OnRootWindowAdded(aura::Window* root_window) { |
105 // |observed_activation_clients_| can have the same ActivationClient multiple | 106 // |observed_activation_clients_| can have the same ActivationClient multiple |
106 // times - which would be handled by the |observed_activation_clients_|. | 107 // times - which would be handled by the |observed_activation_clients_|. |
107 observed_activation_clients_.Add( | 108 observed_activation_clients_.Add( |
108 aura::client::GetActivationClient(root_window)); | 109 aura::client::GetActivationClient(root_window)); |
109 observed_root_windows_.Add(root_window); | 110 observed_root_windows_.Add(root_window); |
110 | 111 |
111 aura::Window* default_container = Shell::GetContainer( | 112 aura::Window* default_container = Shell::GetContainer( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 UpdateLauncherItemStatus(gained_active, true); | 144 UpdateLauncherItemStatus(gained_active, true); |
144 if (lost_active && HasLauncherItemForWindow(lost_active)) | 145 if (lost_active && HasLauncherItemForWindow(lost_active)) |
145 UpdateLauncherItemStatus(lost_active, false); | 146 UpdateLauncherItemStatus(lost_active, false); |
146 } | 147 } |
147 | 148 |
148 void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) { | 149 void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) { |
149 observed_windows_.Add(window); | 150 observed_windows_.Add(window); |
150 // Add LauncherItem if |window| already has a LauncherItemDetails when it is | 151 // Add LauncherItem if |window| already has a LauncherItemDetails when it is |
151 // created. Don't make a new LauncherItem for the re-parented |window| that | 152 // created. Don't make a new LauncherItem for the re-parented |window| that |
152 // already has a LauncherItem. | 153 // already has a LauncherItem. |
153 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID && | 154 if (GetLauncherIDForWindow(window) == ash::kInvalidShelfID && |
154 GetLauncherItemDetailsForWindow(window)) | 155 GetLauncherItemDetailsForWindow(window)) |
155 AddLauncherItem(window); | 156 AddLauncherItem(window); |
156 } | 157 } |
157 | 158 |
158 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { | 159 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
159 // Remove a child window of default container and its item if it has. | 160 // Remove a child window of default container and its item if it has. |
160 if (observed_windows_.IsObserving(window)) | 161 if (observed_windows_.IsObserving(window)) |
161 observed_windows_.Remove(window); | 162 observed_windows_.Remove(window); |
162 | 163 |
163 if (HasLauncherItemForWindow(window)) | 164 if (HasLauncherItemForWindow(window)) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 216 |
216 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { | 217 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { |
217 // When this is called, RootWindow of |old_display| is already removed. | 218 // When this is called, RootWindow of |old_display| is already removed. |
218 // Instead, we remove an observer from RootWindow and ActivationClient in the | 219 // Instead, we remove an observer from RootWindow and ActivationClient in the |
219 // OnRootWindowDestroyed(). | 220 // OnRootWindowDestroyed(). |
220 // Do nothing here. | 221 // Do nothing here. |
221 } | 222 } |
222 | 223 |
223 } // namespace internal | 224 } // namespace internal |
224 } // namespace ash | 225 } // namespace ash |
OLD | NEW |