Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1128)

Side by Side Diff: ash/shelf/shelf_window_watcher.cc

Issue 108313006: [ash] Don't remove an item when associated window is dragged (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_window_watcher.h ('k') | ash/shelf/shelf_window_watcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_item_delegate_manager.h" 8 #include "ash/shelf/shelf_item_delegate_manager.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/shelf/shelf_util.h" 10 #include "ash/shelf/shelf_util.h"
11 #include "ash/shelf/shelf_window_watcher_item_delegate.h" 11 #include "ash/shelf/shelf_window_watcher_item_delegate.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
14 #include "ash/wm/window_state.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"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/image/image_skia.h" 20 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
21 22
22 namespace { 23 namespace {
23 24
24 // Sets LauncherItem property by using the value of |details|. 25 // Sets LauncherItem property by using the value of |details|.
25 void SetLauncherItemDetailsForLauncherItem( 26 void SetLauncherItemDetailsForLauncherItem(
26 ash::LauncherItem* item, 27 ash::LauncherItem* item,
27 const ash::LauncherItemDetails& details) { 28 const ash::LauncherItemDetails& details) {
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::kInvalidLauncherID)
39 return true; 40 return true;
40 return false; 41 return false;
41 } 42 }
42 43
44 // Returns true if |window| is in the process of being dragged.
45 bool IsDragging(aura::Window* window) {
46 return ash::wm::GetWindowState(window)->is_dragged();
47 }
48
43 } // namespace 49 } // namespace
44 50
45 namespace ash { 51 namespace ash {
46 namespace internal { 52 namespace internal {
47 53
48 ShelfWindowWatcher::RootWindowObserver::RootWindowObserver( 54 ShelfWindowWatcher::RootWindowObserver::RootWindowObserver(
49 ShelfWindowWatcher* window_watcher) 55 ShelfWindowWatcher* window_watcher)
50 : window_watcher_(window_watcher) { 56 : window_watcher_(window_watcher) {
51 } 57 }
52 58
53 ShelfWindowWatcher::RootWindowObserver::~RootWindowObserver() { 59 ShelfWindowWatcher::RootWindowObserver::~RootWindowObserver() {
54 } 60 }
55 61
56 void ShelfWindowWatcher::RootWindowObserver::OnWindowDestroying( 62 void ShelfWindowWatcher::RootWindowObserver::OnWindowDestroying(
57 aura::Window* window) { 63 aura::Window* window) {
58 window_watcher_->OnRootWindowRemoved(window); 64 window_watcher_->OnRootWindowRemoved(window);
59 } 65 }
60 66
67 ShelfWindowWatcher::RemovedWindowObserver::RemovedWindowObserver(
68 ShelfWindowWatcher* window_watcher)
69 : window_watcher_(window_watcher) {
70 }
71
72 ShelfWindowWatcher::RemovedWindowObserver::~RemovedWindowObserver() {
73 }
74
75 void ShelfWindowWatcher::RemovedWindowObserver::OnWindowParentChanged(
76 aura::Window* window,
77 aura::Window* parent) {
78 // When |parent| is NULL, this |window| will be destroyed. In that case, its
79 // item will be removed at OnWindowDestroyed().
80 if (!parent)
81 return;
82
83 aura::Window* root_window = window->GetRootWindow();
84 aura::Window* docked_container = Shell::GetContainer(
85 root_window,
86 kShellWindowId_DockedContainer);
87
88 // When |parent| is changed from default container to |docked_container|
89 // during the dragging, |window|'s item should not be removed. Otherwise,
90 // Remove it.
91 if ((IsDragging(window) && parent == docked_container))
simonhong 2013/12/18 07:13:41 We should check IsDragging() and its parent is |do
92 return;
93
94 // When |window| is re-parented to other containers or |window| is re-parented
95 // not to |docked_container| during the dragging, its item should be removed.
96 window_watcher_->FinalizeItemOfRemovedWindow(window);
97 }
98
99 void ShelfWindowWatcher::RemovedWindowObserver::OnWindowDestroyed(
100 aura::Window* window) {
101 window_watcher_->FinalizeItemOfRemovedWindow(window);
102 }
103
61 ShelfWindowWatcher::ShelfWindowWatcher( 104 ShelfWindowWatcher::ShelfWindowWatcher(
62 ShelfModel* model, 105 ShelfModel* model,
63 ShelfItemDelegateManager* item_delegate_manager) 106 ShelfItemDelegateManager* item_delegate_manager)
64 : model_(model), 107 : model_(model),
65 item_delegate_manager_(item_delegate_manager), 108 item_delegate_manager_(item_delegate_manager),
66 root_window_observer_(this), 109 root_window_observer_(this),
110 removed_window_observer_(this),
67 observed_windows_(this), 111 observed_windows_(this),
68 observed_root_windows_(&root_window_observer_), 112 observed_root_windows_(&root_window_observer_),
113 observed_removed_windows_(&removed_window_observer_),
69 observed_activation_clients_(this) { 114 observed_activation_clients_(this) {
70 // We can't assume all RootWindows have the same ActivationClient. 115 // We can't assume all RootWindows have the same ActivationClient.
71 // Add a RootWindow and its ActivationClient to the observed list. 116 // Add a RootWindow and its ActivationClient to the observed list.
72 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 117 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
73 for (aura::Window::Windows::const_iterator it = root_windows.begin(); 118 for (aura::Window::Windows::const_iterator it = root_windows.begin();
74 it != root_windows.end(); ++it) 119 it != root_windows.end(); ++it)
75 OnRootWindowAdded(*it); 120 OnRootWindowAdded(*it);
76 121
77 Shell::GetScreen()->AddObserver(this); 122 Shell::GetScreen()->AddObserver(this);
78 } 123 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 LauncherItem item = model_->items()[index]; 175 LauncherItem item = model_->items()[index];
131 item.status = is_active ? STATUS_ACTIVE : STATUS_RUNNING; 176 item.status = is_active ? STATUS_ACTIVE : STATUS_RUNNING;
132 model_->Set(index, item); 177 model_->Set(index, item);
133 } 178 }
134 179
135 int ShelfWindowWatcher::GetLauncherItemIndexForWindow( 180 int ShelfWindowWatcher::GetLauncherItemIndexForWindow(
136 aura::Window* window) const { 181 aura::Window* window) const {
137 return model_->ItemIndexByID(GetLauncherIDForWindow(window)); 182 return model_->ItemIndexByID(GetLauncherIDForWindow(window));
138 } 183 }
139 184
185 void ShelfWindowWatcher::FinalizeItemOfRemovedWindow(aura::Window* window) {
186 observed_removed_windows_.Remove(window);
187 RemoveLauncherItem(window);
188 }
189
140 void ShelfWindowWatcher::OnWindowActivated(aura::Window* gained_active, 190 void ShelfWindowWatcher::OnWindowActivated(aura::Window* gained_active,
141 aura::Window* lost_active) { 191 aura::Window* lost_active) {
142 if (gained_active && HasLauncherItemForWindow(gained_active)) 192 if (gained_active && HasLauncherItemForWindow(gained_active))
143 UpdateLauncherItemStatus(gained_active, true); 193 UpdateLauncherItemStatus(gained_active, true);
144 if (lost_active && HasLauncherItemForWindow(lost_active)) 194 if (lost_active && HasLauncherItemForWindow(lost_active))
145 UpdateLauncherItemStatus(lost_active, false); 195 UpdateLauncherItemStatus(lost_active, false);
146 } 196 }
147 197
148 void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) { 198 void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) {
149 observed_windows_.Add(window); 199 observed_windows_.Add(window);
200
201 if (observed_removed_windows_.IsObserving(window)) {
202 // When |window| is added and it is already observed by
203 // |dragged_window_observer_|, |window| already has its item.
204 DCHECK(HasLauncherItemForWindow(window));
205 observed_removed_windows_.Remove(window);
206 return;
207 }
208
150 // Add LauncherItem if |window| already has a LauncherItemDetails when it is 209 // 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 210 // created. Don't make a new LauncherItem for the re-parented |window| that
152 // already has a LauncherItem. 211 // already has a LauncherItem.
153 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID && 212 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID &&
154 GetLauncherItemDetailsForWindow(window)) 213 GetLauncherItemDetailsForWindow(window))
155 AddLauncherItem(window); 214 AddLauncherItem(window);
156 } 215 }
157 216
158 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { 217 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) {
159 // Remove a child window of default container and its item if it has. 218 // Remove a child window of default container.
160 if (observed_windows_.IsObserving(window)) 219 if (observed_windows_.IsObserving(window))
161 observed_windows_.Remove(window); 220 observed_windows_.Remove(window);
162 221
222 // Defer handling of removing |window|'s item to RemovedWindowObserver because
223 // |window| could be added again to default container.
163 if (HasLauncherItemForWindow(window)) 224 if (HasLauncherItemForWindow(window))
164 RemoveLauncherItem(window); 225 observed_removed_windows_.Add(window);
165 } 226 }
166 227
167 void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) { 228 void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) {
168 // Remove the default container. 229 // Remove the default container.
169 if (observed_windows_.IsObserving(window)) 230 if (observed_windows_.IsObserving(window))
170 observed_windows_.Remove(window); 231 observed_windows_.Remove(window);
171 } 232 }
172 233
173 void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window, 234 void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window,
174 const void* key, 235 const void* key,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 276
216 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { 277 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) {
217 // When this is called, RootWindow of |old_display| is already removed. 278 // When this is called, RootWindow of |old_display| is already removed.
218 // Instead, we remove an observer from RootWindow and ActivationClient in the 279 // Instead, we remove an observer from RootWindow and ActivationClient in the
219 // OnRootWindowDestroyed(). 280 // OnRootWindowDestroyed().
220 // Do nothing here. 281 // Do nothing here.
221 } 282 }
222 283
223 } // namespace internal 284 } // namespace internal
224 } // namespace ash 285 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_window_watcher.h ('k') | ash/shelf/shelf_window_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698