Chromium Code Reviews| 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/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_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/window_properties.h" | 10 #include "ash/wm/window_properties.h" |
| 11 #include "ui/aura/client/activation_client.h" | |
| 12 #include "ui/aura/client/capture_client.h" | |
| 13 #include "ui/aura/client/stacking_client.h" | |
| 14 #include "ui/aura/focus_manager.h" | |
| 10 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/window_tracker.h" | |
| 11 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
| 12 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 13 | 19 |
| 14 namespace ash { | 20 namespace ash { |
| 21 namespace { | |
| 22 | |
| 23 // Move all transient children to |dst_root|, including the ones in | |
| 24 // the child windows and transient children of the transient children. | |
| 25 void MoveAllTransientChildToNewRoot(aura::RootWindow* dst_root, | |
|
sky
2012/07/20 15:06:07
Child->Children or MoveAllTransientsToNewRoot
oshima
2012/07/20 17:03:11
Done.
| |
| 26 aura::Window* window) { | |
| 27 aura::Window::Windows transient_children = window->transient_children(); | |
| 28 for (aura::Window::Windows::iterator iter = transient_children.begin(); | |
|
sky
2012/07/20 15:06:07
I'm worried that all this moving might have side e
oshima
2012/07/20 17:03:11
I do too, but transient children needs to be in th
| |
| 29 iter != transient_children.end(); ++iter) { | |
| 30 aura::Window* transient_child = *iter; | |
| 31 int container_id = transient_child->parent()->id(); | |
| 32 DCHECK_GE(container_id, 0); | |
| 33 aura::Window* container = Shell::GetContainer(dst_root, container_id); | |
| 34 gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen(); | |
| 35 container->AddChild(transient_child); | |
| 36 transient_child->SetBoundsInScreen(parent_bounds_in_screen); | |
| 37 | |
| 38 // Transient children may have transient children. | |
| 39 MoveAllTransientChildToNewRoot(dst_root, | |
| 40 transient_child); | |
| 41 } | |
| 42 // Move transient children of the child wnidows if any. | |
|
sky
2012/07/20 15:06:07
wnidows -> windows
oshima
2012/07/20 17:03:11
Done.
| |
| 43 aura::Window::Windows children = window->children(); | |
| 44 for (aura::Window::Windows::iterator iter = children.begin(); | |
| 45 iter != children.end(); ++iter) | |
| 46 MoveAllTransientChildToNewRoot(dst_root, *iter); | |
| 47 } | |
| 48 | |
| 49 } // namespace | |
| 50 | |
| 15 namespace internal { | 51 namespace internal { |
| 16 | 52 |
| 17 void ScreenPositionController::ConvertPointToScreen( | 53 void ScreenPositionController::ConvertPointToScreen( |
| 18 const aura::Window* window, | 54 const aura::Window* window, |
| 19 gfx::Point* point) { | 55 gfx::Point* point) { |
| 20 const aura::RootWindow* root = window->GetRootWindow(); | 56 const aura::RootWindow* root = window->GetRootWindow(); |
| 21 aura::Window::ConvertPointToWindow(window, root, point); | 57 aura::Window::ConvertPointToWindow(window, root, point); |
| 22 if (DisplayController::IsVirtualScreenCoordinatesEnabled()) { | 58 if (DisplayController::IsVirtualScreenCoordinatesEnabled()) { |
| 23 const gfx::Point display_origin = | 59 const gfx::Point display_origin = |
| 24 gfx::Screen::GetDisplayNearestWindow( | 60 gfx::Screen::GetDisplayNearestWindow( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 37 const_cast<aura::RootWindow*>(root)).bounds().origin(); | 73 const_cast<aura::RootWindow*>(root)).bounds().origin(); |
| 38 point->Offset(-display_origin.x(), -display_origin.y()); | 74 point->Offset(-display_origin.x(), -display_origin.y()); |
| 39 } | 75 } |
| 40 aura::Window::ConvertPointToWindow(root, window, point); | 76 aura::Window::ConvertPointToWindow(root, window, point); |
| 41 } | 77 } |
| 42 | 78 |
| 43 void ScreenPositionController::SetBounds( | 79 void ScreenPositionController::SetBounds( |
| 44 aura::Window* window, | 80 aura::Window* window, |
| 45 const gfx::Rect& bounds) { | 81 const gfx::Rect& bounds) { |
| 46 if (!DisplayController::IsVirtualScreenCoordinatesEnabled() || | 82 if (!DisplayController::IsVirtualScreenCoordinatesEnabled() || |
| 47 !window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { | 83 !window->parent()->GetProperty(internal::kUsesScreenCoordinatesKey)) { |
|
sky
2012/07/20 15:06:07
Are you sure you want to make kUsesScreenCoordinat
oshima
2012/07/20 17:03:11
phantom widgets are in launcher containers, and me
| |
| 48 window->SetBounds(bounds); | 84 window->SetBounds(bounds); |
| 49 return; | 85 return; |
| 50 } | 86 } |
| 51 // TODO(oshima): Pick the new root window that most closely shares | 87 |
| 52 // the bounds. For a new widget, NativeWidgetAura picks the right | 88 // Don't move a transient windows to other root window. |
| 53 // root window. | 89 // It moves when its transient_parent moves. |
| 90 if (!window->transient_parent()) { | |
| 91 aura::RootWindow* dst_root = Shell::GetRootWindowMatching(bounds); | |
| 92 aura::Window* suggested_container = NULL; | |
|
sky
2012/07/20 15:06:07
suggested_container -> dest_container
oshima
2012/07/20 17:03:11
Done.
| |
| 93 if (dst_root != window->GetRootWindow()) { | |
| 94 int container_id = window->parent()->id(); | |
| 95 // All containers that uses screen coordinates must have non zero | |
| 96 // id. | |
| 97 DCHECK_GE(container_id, 0); | |
|
sky
2012/07/20 15:06:07
DCHECK_GT
oshima
2012/07/20 17:03:11
Sorry, comment was wrong. 0 is valid container id.
| |
| 98 suggested_container = Shell::GetContainer(dst_root, container_id); | |
| 99 } | |
| 100 | |
| 101 if (suggested_container && window->parent() != suggested_container) { | |
| 102 aura::Window* focused = window->GetFocusManager()->GetFocusedWindow(); | |
| 103 aura::client::ActivationClient* activation_client = | |
| 104 aura::client::GetActivationClient(window->GetRootWindow()); | |
| 105 aura::Window* active = activation_client->GetActiveWindow(); | |
| 106 | |
| 107 aura::WindowTracker tracker; | |
|
sky
2012/07/20 15:06:07
Why do you need to do this for focus/activation? I
oshima
2012/07/20 17:03:11
Moving window may reset the focus, and focused wid
| |
| 108 if (focused) | |
| 109 tracker.Add(focused); | |
| 110 if (active && focused != active) | |
| 111 tracker.Add(active); | |
| 112 | |
| 113 suggested_container->AddChild(window); | |
| 114 | |
| 115 MoveAllTransientChildToNewRoot(dst_root, window); | |
| 116 | |
| 117 // Restore focused/active window. | |
| 118 if (tracker.Contains(focused)) | |
| 119 window->GetFocusManager()->SetFocusedWindow(focused, NULL); | |
| 120 else if (tracker.Contains(active)) | |
| 121 activation_client->ActivateWindow(active); | |
| 122 } | |
| 123 } | |
| 124 | |
| 54 gfx::Point origin(bounds.origin()); | 125 gfx::Point origin(bounds.origin()); |
| 55 const gfx::Point display_origin = | 126 const gfx::Point display_origin = |
| 56 gfx::Screen::GetDisplayNearestWindow(window).bounds().origin(); | 127 gfx::Screen::GetDisplayNearestWindow(window).bounds().origin(); |
| 57 origin.Offset(-display_origin.x(), -display_origin.y()); | 128 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 58 window->SetBounds(gfx::Rect(origin, bounds.size())); | 129 window->SetBounds(gfx::Rect(origin, bounds.size())); |
| 59 } | 130 } |
| 60 | 131 |
| 61 } // internal | 132 } // internal |
| 62 } // ash | 133 } // ash |
| OLD | NEW |