OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/desktop_background/desktop_background_widget_controller.h" | 9 #include "ash/desktop_background/desktop_background_widget_controller.h" |
10 #include "ash/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 aura::Window* container = new aura::Window(NULL); | 43 aura::Window* container = new aura::Window(NULL); |
44 container->set_id(window_id); | 44 container->set_id(window_id); |
45 container->SetName(name); | 45 container->SetName(name); |
46 container->Init(ui::LAYER_NOT_DRAWN); | 46 container->Init(ui::LAYER_NOT_DRAWN); |
47 parent->AddChild(container); | 47 parent->AddChild(container); |
48 if (window_id != internal::kShellWindowId_UnparentedControlContainer) | 48 if (window_id != internal::kShellWindowId_UnparentedControlContainer) |
49 container->Show(); | 49 container->Show(); |
50 return container; | 50 return container; |
51 } | 51 } |
52 | 52 |
53 void MoveAllWindows(aura::RootWindow* src, | 53 // Returns all the children of the workspace windows, eg the standard top-level |
54 aura::RootWindow* dst) { | 54 // windows. |
55 // Windows move only from secondary displays to the primary | 55 std::vector<aura::Window*> GetWorkspaceWindows(aura::RootWindow* root) { |
56 // display, so no need to move windows in the containers that are | 56 using aura::Window; |
57 // available only in the primary display (launcher, panels etc) | 57 |
| 58 std::vector<Window*> windows; |
| 59 Window* container = Shell::GetContainer( |
| 60 root, internal::kShellWindowId_DefaultContainer); |
| 61 for (Window::Windows::const_reverse_iterator i = |
| 62 container->children().rbegin(); |
| 63 i != container->children().rend(); ++i) { |
| 64 Window* workspace_window = *i; |
| 65 if (workspace_window->id() == internal::kShellWindowId_WorkspaceContainer) { |
| 66 windows.insert(windows.end(), workspace_window->children().begin(), |
| 67 workspace_window->children().end()); |
| 68 } |
| 69 } |
| 70 return windows; |
| 71 } |
| 72 |
| 73 // Reparents |window| to |new_parent|. |
| 74 void ReparentWindow(aura::Window* window, aura::Window* new_parent) { |
| 75 // Update the restore bounds to make it relative to the display. |
| 76 gfx::Rect restore_bounds(GetRestoreBoundsInParent(window)); |
| 77 new_parent->AddChild(window); |
| 78 if (!restore_bounds.IsEmpty()) |
| 79 SetRestoreBoundsInParent(window, restore_bounds); |
| 80 } |
| 81 |
| 82 // Reparents the appropriate set of windows from |src| to |dst|. |
| 83 void ReparentAllWindows(aura::RootWindow* src, aura::RootWindow* dst) { |
| 84 // Set of windows to move. |
58 const int kContainerIdsToMove[] = { | 85 const int kContainerIdsToMove[] = { |
59 internal::kShellWindowId_DefaultContainer, | 86 internal::kShellWindowId_DefaultContainer, |
60 internal::kShellWindowId_AlwaysOnTopContainer, | 87 internal::kShellWindowId_AlwaysOnTopContainer, |
61 internal::kShellWindowId_SystemModalContainer, | 88 internal::kShellWindowId_SystemModalContainer, |
62 internal::kShellWindowId_LockSystemModalContainer, | 89 internal::kShellWindowId_LockSystemModalContainer, |
63 }; | 90 }; |
| 91 // For Workspace2 we need to manually reparent the windows. This way |
| 92 // Workspace2 can move the windows to the appropriate workspace. |
| 93 if (internal::WorkspaceController::IsWorkspace2Enabled()) { |
| 94 std::vector<aura::Window*> windows(GetWorkspaceWindows(src)); |
| 95 internal::WorkspaceController* workspace_controller = |
| 96 GetRootWindowController(dst)->workspace_controller(); |
| 97 for (size_t i = 0; i < windows.size(); ++i) { |
| 98 aura::Window* new_parent = |
| 99 workspace_controller->GetParentForNewWindow(windows[i]); |
| 100 ReparentWindow(windows[i], new_parent); |
| 101 } |
| 102 } |
64 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) { | 103 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) { |
65 int id = kContainerIdsToMove[i]; | 104 int id = kContainerIdsToMove[i]; |
| 105 if (id == internal::kShellWindowId_DefaultContainer && |
| 106 internal::WorkspaceController::IsWorkspace2Enabled()) |
| 107 continue; |
| 108 |
66 aura::Window* src_container = Shell::GetContainer(src, id); | 109 aura::Window* src_container = Shell::GetContainer(src, id); |
67 aura::Window* dst_container = Shell::GetContainer(dst, id); | 110 aura::Window* dst_container = Shell::GetContainer(dst, id); |
68 aura::Window::Windows children = src_container->children(); | 111 aura::Window::Windows children = src_container->children(); |
69 for (aura::Window::Windows::iterator iter = children.begin(); | 112 for (aura::Window::Windows::iterator iter = children.begin(); |
70 iter != children.end(); ++iter) { | 113 iter != children.end(); ++iter) { |
71 aura::Window* window = *iter; | 114 aura::Window* window = *iter; |
72 // Don't move modal screen. | 115 // Don't move modal screen. |
73 if (internal::SystemModalContainerLayoutManager::IsModalScreen(window)) | 116 if (internal::SystemModalContainerLayoutManager::IsModalScreen(window)) |
74 continue; | 117 continue; |
75 | 118 |
76 // Update the restore bounds to make it relative to the display. | 119 ReparentWindow(window, dst_container); |
77 gfx::Rect restore_bounds(GetRestoreBoundsInParent(window)); | |
78 dst_container->AddChild(window); | |
79 if (!restore_bounds.IsEmpty()) | |
80 SetRestoreBoundsInParent(window, restore_bounds); | |
81 } | 120 } |
82 } | 121 } |
83 } | 122 } |
84 | 123 |
85 // Mark the container window so that a widget added to this container will | 124 // Mark the container window so that a widget added to this container will |
86 // use the virtual screeen coordinates instead of parent. | 125 // use the virtual screeen coordinates instead of parent. |
87 void SetUsesScreenCoordinates(aura::Window* container) { | 126 void SetUsesScreenCoordinates(aura::Window* container) { |
88 container->SetProperty(internal::kUsesScreenCoordinatesKey, true); | 127 container->SetProperty(internal::kUsesScreenCoordinatesKey, true); |
89 } | 128 } |
90 | 129 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 activation_client->DeactivateWindow(active); | 351 activation_client->DeactivateWindow(active); |
313 // Release capture if any. | 352 // Release capture if any. |
314 aura::client::GetCaptureClient(root_window_.get())-> | 353 aura::client::GetCaptureClient(root_window_.get())-> |
315 SetCapture(NULL); | 354 SetCapture(NULL); |
316 aura::WindowTracker tracker; | 355 aura::WindowTracker tracker; |
317 if (focused) | 356 if (focused) |
318 tracker.Add(focused); | 357 tracker.Add(focused); |
319 if (active && focused != active) | 358 if (active && focused != active) |
320 tracker.Add(active); | 359 tracker.Add(active); |
321 | 360 |
322 MoveAllWindows(root_window_.get(), dst); | 361 ReparentAllWindows(root_window_.get(), dst); |
323 | 362 |
324 // Restore focused or active window if it's still alive. | 363 // Restore focused or active window if it's still alive. |
325 if (focused && tracker.Contains(focused) && dst->Contains(focused)) { | 364 if (focused && tracker.Contains(focused) && dst->Contains(focused)) { |
326 dst->GetFocusManager()->SetFocusedWindow(focused, NULL); | 365 dst->GetFocusManager()->SetFocusedWindow(focused, NULL); |
327 } else if (active && tracker.Contains(active) && dst->Contains(active)) { | 366 } else if (active && tracker.Contains(active) && dst->Contains(active)) { |
328 activation_client->ActivateWindow(active); | 367 activation_client->ActivateWindow(active); |
329 } | 368 } |
330 } | 369 } |
331 | 370 |
332 } // namespace internal | 371 } // namespace internal |
333 } // namespace ash | 372 } // namespace ash |
OLD | NEW |