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

Side by Side Diff: ash/display/screen_position_controller.cc

Issue 10836065: Improve WorkspaceWindowResizer::CompleteDrag() so that the function moves the window to a root windo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final rebase Created 8 years, 4 months 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/display/screen_position_controller.h ('k') | ash/extended_desktop_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 (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/display/screen_position_controller.h" 5 #include "ash/display/screen_position_controller.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/coordinate_conversion.h"
11 #include "ash/wm/system_modal_container_layout_manager.h" 10 #include "ash/wm/system_modal_container_layout_manager.h"
12 #include "ash/wm/window_properties.h" 11 #include "ash/wm/window_properties.h"
13 #include "ui/aura/client/activation_client.h" 12 #include "ui/aura/client/activation_client.h"
14 #include "ui/aura/client/capture_client.h" 13 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/stacking_client.h" 14 #include "ui/aura/client/stacking_client.h"
16 #include "ui/aura/focus_manager.h" 15 #include "ui/aura/focus_manager.h"
17 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
18 #include "ui/aura/window_tracker.h" 17 #include "ui/aura/window_tracker.h"
19 #include "ui/gfx/display.h" 18 #include "ui/gfx/display.h"
20 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
21 20
22 namespace ash { 21 namespace ash {
23 namespace { 22 namespace {
24 23
25 // Move all transient children to |dst_root|, including the ones in 24 // Move all transient children to |dst_root|, including the ones in
26 // the child windows and transient children of the transient children. 25 // the child windows and transient children of the transient children.
27 void MoveAllTransientChildrenToNewRoot(aura::RootWindow* dst_root, 26 void MoveAllTransientChildrenToNewRoot(const gfx::Display& display,
28 aura::Window* window) { 27 aura::Window* window) {
28 aura::RootWindow* dst_root = Shell::GetInstance()->display_controller()->
29 GetRootWindowForDisplayId(display.id());
29 aura::Window::Windows transient_children = window->transient_children(); 30 aura::Window::Windows transient_children = window->transient_children();
30 for (aura::Window::Windows::iterator iter = transient_children.begin(); 31 for (aura::Window::Windows::iterator iter = transient_children.begin();
31 iter != transient_children.end(); ++iter) { 32 iter != transient_children.end(); ++iter) {
32 aura::Window* transient_child = *iter; 33 aura::Window* transient_child = *iter;
33 int container_id = transient_child->parent()->id(); 34 int container_id = transient_child->parent()->id();
34 DCHECK_GE(container_id, 0); 35 DCHECK_GE(container_id, 0);
35 aura::Window* container = Shell::GetContainer(dst_root, container_id); 36 aura::Window* container = Shell::GetContainer(dst_root, container_id);
36 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen(); 37 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen();
37 container->AddChild(transient_child); 38 container->AddChild(transient_child);
38 transient_child->SetBoundsInScreen(parent_bounds_in_screen); 39 transient_child->SetBoundsInScreen(parent_bounds_in_screen, display);
39 40
40 // Transient children may have transient children. 41 // Transient children may have transient children.
41 MoveAllTransientChildrenToNewRoot(dst_root, 42 MoveAllTransientChildrenToNewRoot(display, transient_child);
42 transient_child);
43 } 43 }
44 // Move transient children of the child windows if any. 44 // Move transient children of the child windows if any.
45 aura::Window::Windows children = window->children(); 45 aura::Window::Windows children = window->children();
46 for (aura::Window::Windows::iterator iter = children.begin(); 46 for (aura::Window::Windows::iterator iter = children.begin();
47 iter != children.end(); ++iter) 47 iter != children.end(); ++iter)
48 MoveAllTransientChildrenToNewRoot(dst_root, *iter); 48 MoveAllTransientChildrenToNewRoot(display, *iter);
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 namespace internal { 53 namespace internal {
54 54
55 void ScreenPositionController::ConvertPointToScreen( 55 void ScreenPositionController::ConvertPointToScreen(
56 const aura::Window* window, 56 const aura::Window* window,
57 gfx::Point* point) { 57 gfx::Point* point) {
58 const aura::RootWindow* root = window->GetRootWindow(); 58 const aura::RootWindow* root = window->GetRootWindow();
(...skipping 12 matching lines...) Expand all
71 const aura::RootWindow* root = window->GetRootWindow(); 71 const aura::RootWindow* root = window->GetRootWindow();
72 if (DisplayController::IsExtendedDesktopEnabled()) { 72 if (DisplayController::IsExtendedDesktopEnabled()) {
73 const gfx::Point display_origin = 73 const gfx::Point display_origin =
74 gfx::Screen::GetDisplayNearestWindow( 74 gfx::Screen::GetDisplayNearestWindow(
75 const_cast<aura::RootWindow*>(root)).bounds().origin(); 75 const_cast<aura::RootWindow*>(root)).bounds().origin();
76 point->Offset(-display_origin.x(), -display_origin.y()); 76 point->Offset(-display_origin.x(), -display_origin.y());
77 } 77 }
78 aura::Window::ConvertPointToTarget(root, window, point); 78 aura::Window::ConvertPointToTarget(root, window, point);
79 } 79 }
80 80
81 void ScreenPositionController::SetBounds( 81 void ScreenPositionController::SetBounds(aura::Window* window,
82 aura::Window* window, 82 const gfx::Rect& bounds,
83 const gfx::Rect& bounds) { 83 const gfx::Display& display) {
84 DCHECK_NE(-1, display.id());
84 if (!DisplayController::IsExtendedDesktopEnabled() || 85 if (!DisplayController::IsExtendedDesktopEnabled() ||
85 !window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { 86 !window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) {
86 window->SetBounds(bounds); 87 window->SetBounds(bounds);
87 return; 88 return;
88 } 89 }
89 90
90 // Don't move a transient windows to other root window. 91 // Don't move a transient windows to other root window.
91 // It moves when its transient_parent moves. 92 // It moves when its transient_parent moves.
92 if (!window->transient_parent()) { 93 if (!window->transient_parent()) {
93 aura::RootWindow* dst_root = wm::GetRootWindowMatching(bounds); 94 aura::RootWindow* dst_root =
95 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId(
96 display.id());
94 aura::Window* dst_container = NULL; 97 aura::Window* dst_container = NULL;
95 if (dst_root != window->GetRootWindow()) { 98 if (dst_root != window->GetRootWindow()) {
96 int container_id = window->parent()->id(); 99 int container_id = window->parent()->id();
97 // All containers that uses screen coordinates must have valid 100 // All containers that uses screen coordinates must have valid
98 // window ids. 101 // window ids.
99 DCHECK_GE(container_id, 0); 102 DCHECK_GE(container_id, 0);
100 // Don't move modal screen. 103 // Don't move modal screen.
101 if (!SystemModalContainerLayoutManager::IsModalScreen(window)) 104 if (!SystemModalContainerLayoutManager::IsModalScreen(window))
102 dst_container = Shell::GetContainer(dst_root, container_id); 105 dst_container = Shell::GetContainer(dst_root, container_id);
103 } 106 }
104 107
105 if (dst_container && window->parent() != dst_container) { 108 if (dst_container && window->parent() != dst_container) {
106 aura::Window* focused = window->GetFocusManager()->GetFocusedWindow(); 109 aura::Window* focused = window->GetFocusManager()->GetFocusedWindow();
107 aura::client::ActivationClient* activation_client = 110 aura::client::ActivationClient* activation_client =
108 aura::client::GetActivationClient(window->GetRootWindow()); 111 aura::client::GetActivationClient(window->GetRootWindow());
109 aura::Window* active = activation_client->GetActiveWindow(); 112 aura::Window* active = activation_client->GetActiveWindow();
110 113
111 aura::WindowTracker tracker; 114 aura::WindowTracker tracker;
112 if (focused) 115 if (focused)
113 tracker.Add(focused); 116 tracker.Add(focused);
114 if (active && focused != active) 117 if (active && focused != active)
115 tracker.Add(active); 118 tracker.Add(active);
116 119
117 dst_container->AddChild(window); 120 dst_container->AddChild(window);
118 121
119 MoveAllTransientChildrenToNewRoot(dst_root, window); 122 MoveAllTransientChildrenToNewRoot(display, window);
120 123
121 // Restore focused/active window. 124 // Restore focused/active window.
122 if (tracker.Contains(focused)) 125 if (tracker.Contains(focused))
123 window->GetFocusManager()->SetFocusedWindow(focused, NULL); 126 window->GetFocusManager()->SetFocusedWindow(focused, NULL);
124 else if (tracker.Contains(active)) 127 else if (tracker.Contains(active))
125 activation_client->ActivateWindow(active); 128 activation_client->ActivateWindow(active);
126 } 129 }
127 } 130 }
128 131
129 gfx::Point origin(bounds.origin()); 132 gfx::Point origin(bounds.origin());
130 const gfx::Point display_origin = 133 const gfx::Point display_origin =
131 gfx::Screen::GetDisplayNearestWindow(window).bounds().origin(); 134 gfx::Screen::GetDisplayNearestWindow(window).bounds().origin();
132 origin.Offset(-display_origin.x(), -display_origin.y()); 135 origin.Offset(-display_origin.x(), -display_origin.y());
133 window->SetBounds(gfx::Rect(origin, bounds.size())); 136 window->SetBounds(gfx::Rect(origin, bounds.size()));
134 } 137 }
135 138
136 } // internal 139 } // internal
137 } // ash 140 } // ash
OLDNEW
« no previous file with comments | « ash/display/screen_position_controller.h ('k') | ash/extended_desktop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698