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

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 | « no previous file | 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 observed_windows_.Add(window); 155 observed_windows_.Add(window);
150 // Add LauncherItem if |window| already has a LauncherItemDetails when it is 156 // 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 157 // created. Don't make a new LauncherItem for the re-parented |window| that
152 // already has a LauncherItem. 158 // already has a LauncherItem.
153 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID && 159 if (GetLauncherIDForWindow(window) == ash::kInvalidLauncherID &&
154 GetLauncherItemDetailsForWindow(window)) 160 GetLauncherItemDetailsForWindow(window))
155 AddLauncherItem(window); 161 AddLauncherItem(window);
156 } 162 }
157 163
158 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { 164 void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) {
159 // Remove a child window of default container and its item if it has. 165 // Remove a child window of default container.
160 if (observed_windows_.IsObserving(window)) 166 if (observed_windows_.IsObserving(window))
161 observed_windows_.Remove(window); 167 observed_windows_.Remove(window);
162 168
163 if (HasLauncherItemForWindow(window)) 169 // When |window| is dragged, its item should not be removed.
170 if (HasLauncherItemForWindow(window) && !IsDragging(window))
sky 2013/12/14 00:17:20 If the window is deleted while dragging how does t
simonhong 2013/12/16 02:24:16 When a |window| is dragging its observer and item
164 RemoveLauncherItem(window); 171 RemoveLauncherItem(window);
165 } 172 }
166 173
167 void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) { 174 void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) {
168 // Remove the default container. 175 // Remove the default container.
169 if (observed_windows_.IsObserving(window)) 176 if (observed_windows_.IsObserving(window))
170 observed_windows_.Remove(window); 177 observed_windows_.Remove(window);
171 } 178 }
172 179
173 void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window, 180 void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 222
216 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { 223 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) {
217 // When this is called, RootWindow of |old_display| is already removed. 224 // When this is called, RootWindow of |old_display| is already removed.
218 // Instead, we remove an observer from RootWindow and ActivationClient in the 225 // Instead, we remove an observer from RootWindow and ActivationClient in the
219 // OnRootWindowDestroyed(). 226 // OnRootWindowDestroyed().
220 // Do nothing here. 227 // Do nothing here.
221 } 228 }
222 229
223 } // namespace internal 230 } // namespace internal
224 } // namespace ash 231 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/shelf/shelf_window_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698