Index: ash/shelf/shelf_window_watcher.cc |
diff --git a/ash/shelf/shelf_window_watcher.cc b/ash/shelf/shelf_window_watcher.cc |
index b4e65e25a7b2f50761de5c0c524936e86163917c..964a867d9b8e05dce23d6fc83ef6e844a518c0a6 100644 |
--- a/ash/shelf/shelf_window_watcher.cc |
+++ b/ash/shelf/shelf_window_watcher.cc |
@@ -11,6 +11,7 @@ |
#include "ash/shelf/shelf_window_watcher_item_delegate.h" |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
+#include "ash/wm/window_state.h" |
#include "ash/wm/window_util.h" |
#include "base/memory/scoped_ptr.h" |
#include "ui/aura/client/activation_client.h" |
@@ -40,6 +41,11 @@ bool HasLauncherItemForWindow(aura::Window* window) { |
return false; |
} |
+// Returns true if |window| is in the process of being dragged. |
+bool IsDragging(aura::Window* window) { |
+ return ash::wm::GetWindowState(window)->is_dragged(); |
+} |
+ |
} // namespace |
namespace ash { |
@@ -146,7 +152,10 @@ void ShelfWindowWatcher::OnWindowActivated(aura::Window* gained_active, |
} |
void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) { |
- observed_windows_.Add(window); |
+ // |window| can be already observed after finishing the dragging of |window|. |
+ if (!observed_windows_.IsObserving(window)) |
+ observed_windows_.Add(window); |
+ |
// Add LauncherItem if |window| already has a LauncherItemDetails when it is |
// created. Don't make a new LauncherItem for the re-parented |window| that |
// already has a LauncherItem. |
@@ -156,7 +165,14 @@ void ShelfWindowWatcher::OnWindowAdded(aura::Window* window) { |
} |
void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
- // Remove a child window of default container and its item if it has. |
+ // When |window| is being dragged, its parent Window is changed from default |
+ // container to docked container. To handle deleting a |window| during the |
+ // dragging, it is not removed from observer here. In that case, |window| will |
+ // be removed from observer and its item is removed at OnWindowDestroying(). |
+ if (HasLauncherItemForWindow(window) && IsDragging(window)) |
+ return; |
+ |
+ // Remove a child window of default container. |
if (observed_windows_.IsObserving(window)) |
observed_windows_.Remove(window); |
@@ -164,10 +180,44 @@ void ShelfWindowWatcher::OnWillRemoveWindow(aura::Window* window) { |
RemoveLauncherItem(window); |
} |
+void ShelfWindowWatcher::OnWindowParentChanged(aura::Window* window, |
+ aura::Window* parent) { |
+ if (!parent || !HasLauncherItemForWindow(window)) |
+ return; |
+ |
+ aura::Window* root_window = window->GetRootWindow(); |
+ aura::Window* default_container = Shell::GetContainer( |
+ root_window, |
+ kShellWindowId_DefaultContainer); |
+ aura::Window* docked_container = Shell::GetContainer( |
+ root_window, |
+ kShellWindowId_DockedContainer); |
+ |
+ // When |parent| is |default_container|, this re-parenting is already handled |
+ // by OnWindowAdded(). |
+ // When |parent| is |docked_container|, |window| is in the process of being |
+ // dragged. This case is also already handled by OnWillRemoveWindow(). |
+ if (parent == default_container || |
+ (parent == docked_container && IsDragging(window))) |
sky
2013/12/17 15:49:57
Can you just check IsDragging here and not care ab
|
+ return; |
+ |
+ // Remove an item when |window|'s new parent is not a docked container or |
+ // a default container. |
+ observed_windows_.Remove(window); |
+ RemoveLauncherItem(window); |
+} |
+ |
void ShelfWindowWatcher::OnWindowDestroying(aura::Window* window) { |
// Remove the default container. |
if (observed_windows_.IsObserving(window)) |
observed_windows_.Remove(window); |
+ |
+ // Handle removing of |window| during its dragging. See the comment in |
+ // OnWillRemoveWindow(). |
+ if (IsDragging(window)) { |
+ DCHECK(HasLauncherItemForWindow(window)); |
sky
2013/12/17 15:49:57
Why the DCHECK here?
|
+ RemoveLauncherItem(window); |
+ } |
} |
void ShelfWindowWatcher::OnWindowPropertyChanged(aura::Window* window, |