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

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: Handle re-parenting not to default_container 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
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 145
140 void ShelfWindowWatcher::OnWindowActivated(aura::Window* gained_active, 146 void ShelfWindowWatcher::OnWindowActivated(aura::Window* gained_active,
141 aura::Window* lost_active) { 147 aura::Window* lost_active) {
142 if (gained_active && HasLauncherItemForWindow(gained_active)) 148 if (gained_active && HasLauncherItemForWindow(gained_active))
143 UpdateLauncherItemStatus(gained_active, true); 149 UpdateLauncherItemStatus(gained_active, true);
144 if (lost_active && HasLauncherItemForWindow(lost_active)) 150 if (lost_active && HasLauncherItemForWindow(lost_active))
145 UpdateLauncherItemStatus(lost_active, false); 151 UpdateLauncherItemStatus(lost_active, false);
146 } 152 }
147 153
148 void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) { 154 void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) {
149 observed_windows_.Add(window); 155 // |window| can be already observed after finishing the dragging of |window|.
156 if (!observed_windows_.IsObserving(window))
157 observed_windows_.Add(window);
158
150 // Add LauncherItem if |window| already has a LauncherItemDetails when it is 159 // 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 160 // created. Don't make a new LauncherItem for the re-parented |window| that
152 // already has a LauncherItem. 161 // already has a LauncherItem.
153 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID && 162 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID &&
154 GetLauncherItemDetailsForWindow(window)) 163 GetLauncherItemDetailsForWindow(window))
155 AddLauncherItem(window); 164 AddLauncherItem(window);
156 } 165 }
157 166
158 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { 167 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) {
159 // Remove a child window of default container and its item if it has. 168 // When |window| is being dragged, its parent Window is changed from default
169 // container to docked container. To handle deleting a |window| during the
170 // dragging, it is not removed from observer here. In that case, |window| will
171 // be removed from observer and its item is removed at OnWindowDestroying().
172 if (HasLauncherItemForWindow(window) && IsDragging(window))
173 return;
174
175 // Remove a child window of default container.
160 if (observed_windows_.IsObserving(window)) 176 if (observed_windows_.IsObserving(window))
161 observed_windows_.Remove(window); 177 observed_windows_.Remove(window);
162 178
163 if (HasLauncherItemForWindow(window)) 179 if (HasLauncherItemForWindow(window))
164 RemoveLauncherItem(window); 180 RemoveLauncherItem(window);
165 } 181 }
166 182
183 void ShelfWindowWatcher::OnWindowParentChanged(aura::Window* window,
184 aura::Window* parent) {
185 if (!parent || !HasLauncherItemForWindow(window))
186 return;
187
188 aura::Window* root_window = window->GetRootWindow();
189 aura::Window* default_container = Shell::GetContainer(
190 root_window,
191 kShellWindowId_DefaultContainer);
192 aura::Window* docked_container = Shell::GetContainer(
193 root_window,
194 kShellWindowId_DockedContainer);
195
196 // When |parent| is |default_container|, this re-parenting is already handled
197 // by OnWindowAdded().
198 // When |parent| is |docked_container|, |window| is in the process of being
199 // dragged. This case is also already handled by OnWillRemoveWindow().
200 if (parent == default_container ||
201 (parent == docked_container && IsDragging(window)))
sky 2013/12/17 15:49:57 Can you just check IsDragging here and not care ab
202 return;
203
204 // Remove an item when |window|'s new parent is not a docked container or
205 // a default container.
206 observed_windows_.Remove(window);
207 RemoveLauncherItem(window);
208 }
209
167 void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) { 210 void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) {
168 // Remove the default container. 211 // Remove the default container.
169 if (observed_windows_.IsObserving(window)) 212 if (observed_windows_.IsObserving(window))
170 observed_windows_.Remove(window); 213 observed_windows_.Remove(window);
214
215 // Handle removing of |window| during its dragging. See the comment in
216 // OnWillRemoveWindow().
217 if (IsDragging(window)) {
218 DCHECK(HasLauncherItemForWindow(window));
sky 2013/12/17 15:49:57 Why the DCHECK here?
219 RemoveLauncherItem(window);
220 }
171 } 221 }
172 222
173 void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window, 223 void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window,
174 const void* key, 224 const void* key,
175 intptr_t old) { 225 intptr_t old) {
176 if (key != kLauncherItemDetailsKey) 226 if (key != kLauncherItemDetailsKey)
177 return; 227 return;
178 228
179 if (GetLauncherItemDetailsForWindow(window) == NULL) { 229 if (GetLauncherItemDetailsForWindow(window) == NULL) {
180 // Removes LauncherItem for |window| when it has a LauncherItem. 230 // Removes LauncherItem for |window| when it has a LauncherItem.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 265
216 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { 266 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) {
217 // When this is called, RootWindow of |old_display| is already removed. 267 // When this is called, RootWindow of |old_display| is already removed.
218 // Instead, we remove an observer from RootWindow and ActivationClient in the 268 // Instead, we remove an observer from RootWindow and ActivationClient in the
219 // OnRootWindowDestroyed(). 269 // OnRootWindowDestroyed().
220 // Do nothing here. 270 // Do nothing here.
221 } 271 }
222 272
223 } // namespace internal 273 } // namespace internal
224 } // namespace ash 274 } // 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