This source file includes following definitions.
- ShouldStayInSameRootWindow
- MoveAllTransientChildrenToNewRoot
- GetRootWindowRelativeToWindow
- ConvertPointToScreen
- ConvertPointFromScreen
- ConvertHostPointToScreen
- SetBounds
#include "ash/display/screen_position_controller.h"
#include "ash/display/display_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/system_modal_container_layout_manager.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_state.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tracker.h"
#include "ui/compositor/dip_util.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_client.h"
namespace ash {
namespace {
bool ShouldStayInSameRootWindow(const aura::Window* window) {
return window && (window->GetProperty(kStayInSameRootWindowKey) ||
ShouldStayInSameRootWindow(window->parent()));
}
void MoveAllTransientChildrenToNewRoot(const gfx::Display& display,
aura::Window* window) {
aura::Window* dst_root = Shell::GetInstance()->display_controller()->
GetRootWindowForDisplayId(display.id());
aura::Window::Windows transient_children =
::wm::GetTransientChildren(window);
for (aura::Window::Windows::iterator iter = transient_children.begin();
iter != transient_children.end(); ++iter) {
aura::Window* transient_child = *iter;
int container_id = transient_child->parent()->id();
DCHECK_GE(container_id, 0);
aura::Window* container = Shell::GetContainer(dst_root, container_id);
gfx::Rect parent_bounds_in_screen = transient_child->GetBoundsInScreen();
container->AddChild(transient_child);
transient_child->SetBoundsInScreen(parent_bounds_in_screen, display);
MoveAllTransientChildrenToNewRoot(display, transient_child);
}
aura::Window::Windows children = window->children();
for (aura::Window::Windows::iterator iter = children.begin();
iter != children.end(); ++iter)
MoveAllTransientChildrenToNewRoot(display, *iter);
}
std::pair<aura::Window*, gfx::Point> GetRootWindowRelativeToWindow(
aura::Window* window,
const gfx::Point& location) {
aura::Window* root_window = window->GetRootWindow();
gfx::Point location_in_root(location);
aura::Window::ConvertPointToTarget(window, root_window, &location_in_root);
#if defined(USE_X11)
if (!root_window->ContainsPointInRoot(location_in_root)) {
gfx::Point location_in_native(location_in_root);
root_window->GetHost()->ConvertPointToNativeScreen(&location_in_native);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
for (size_t i = 0; i < root_windows.size(); ++i) {
aura::WindowTreeHost* host = root_windows[i]->GetHost();
const gfx::Rect native_bounds = host->GetBounds();
if (native_bounds.Contains(location_in_native)) {
root_window = root_windows[i];
location_in_root = location_in_native;
host->ConvertPointFromNativeScreen(&location_in_root);
break;
}
}
}
#else
#endif
return std::make_pair(root_window, location_in_root);
}
}
void ScreenPositionController::ConvertPointToScreen(
const aura::Window* window,
gfx::Point* point) {
const aura::Window* root = window->GetRootWindow();
aura::Window::ConvertPointToTarget(window, root, point);
const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow(
const_cast<aura::Window*>(root)).bounds().origin();
point->Offset(display_origin.x(), display_origin.y());
}
void ScreenPositionController::ConvertPointFromScreen(
const aura::Window* window,
gfx::Point* point) {
const aura::Window* root = window->GetRootWindow();
const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow(
const_cast<aura::Window*>(root)).bounds().origin();
point->Offset(-display_origin.x(), -display_origin.y());
aura::Window::ConvertPointToTarget(root, window, point);
}
void ScreenPositionController::ConvertHostPointToScreen(
aura::Window* root_window,
gfx::Point* point) {
aura::Window* root = root_window->GetRootWindow();
root->GetHost()->ConvertPointFromHost(point);
std::pair<aura::Window*, gfx::Point> pair =
GetRootWindowRelativeToWindow(root, *point);
*point = pair.second;
ConvertPointToScreen(pair.first, point);
}
void ScreenPositionController::SetBounds(aura::Window* window,
const gfx::Rect& bounds,
const gfx::Display& display) {
DCHECK_NE(-1, display.id());
if (!window->parent()->GetProperty(kUsesScreenCoordinatesKey)) {
window->SetBounds(bounds);
return;
}
if (!::wm::GetTransientParent(window) &&
!ShouldStayInSameRootWindow(window)) {
aura::Window* dst_root =
Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId(
display.id());
DCHECK(dst_root);
aura::Window* dst_container = NULL;
if (dst_root != window->GetRootWindow()) {
int container_id = window->parent()->id();
DCHECK_GE(container_id, 0);
if (!SystemModalContainerLayoutManager::IsModalBackground(window))
dst_container = Shell::GetContainer(dst_root, container_id);
}
if (dst_container && window->parent() != dst_container) {
aura::Window* focused = aura::client::GetFocusClient(window)->
GetFocusedWindow();
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(window->GetRootWindow());
aura::Window* active = activation_client->GetActiveWindow();
aura::WindowTracker tracker;
if (focused)
tracker.Add(focused);
if (active && focused != active)
tracker.Add(active);
gfx::Point origin = bounds.origin();
const gfx::Point display_origin = display.bounds().origin();
origin.Offset(-display_origin.x(), -display_origin.y());
gfx::Rect new_bounds = gfx::Rect(origin, bounds.size());
window->SetBounds(new_bounds);
dst_container->AddChild(window);
MoveAllTransientChildrenToNewRoot(display, window);
if (tracker.Contains(focused)) {
aura::client::GetFocusClient(window)->FocusWindow(focused);
ash::Shell::GetInstance()->set_target_root_window(
focused->GetRootWindow());
} else if (tracker.Contains(active)) {
activation_client->ActivateWindow(active);
}
}
}
gfx::Point origin(bounds.origin());
const gfx::Point display_origin = Shell::GetScreen()->GetDisplayNearestWindow(
window).bounds().origin();
origin.Offset(-display_origin.x(), -display_origin.y());
window->SetBounds(gfx::Rect(origin, bounds.size()));
}
}