OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/widget/desktop_screen_position_client.h" | |
6 | |
7 #include "ui/aura/root_window.h" | |
8 #include "ui/views/widget/desktop_native_widget_aura.h" | |
9 | |
10 namespace views { | |
11 | |
12 DesktopScreenPositionClient::DesktopScreenPositionClient() { | |
13 } | |
14 | |
15 DesktopScreenPositionClient::~DesktopScreenPositionClient() { | |
16 } | |
17 | |
18 void DesktopScreenPositionClient::ConvertPointToScreen( | |
19 const aura::Window* window, gfx::Point* point) { | |
20 const aura::RootWindow* root_window = window->GetRootWindow(); | |
21 aura::Window::ConvertPointToTarget(window, root_window, point); | |
22 gfx::Point origin = root_window->GetHostOrigin(); | |
23 point->Offset(origin.x(), origin.y()); | |
24 } | |
25 | |
26 void DesktopScreenPositionClient::ConvertPointFromScreen( | |
27 const aura::Window* window, gfx::Point* point) { | |
28 const aura::RootWindow* root_window = window->GetRootWindow(); | |
29 gfx::Point origin = root_window->GetHostOrigin(); | |
30 point->Offset(-origin.x(), -origin.y()); | |
31 aura::Window::ConvertPointToTarget(root_window, window, point); | |
32 } | |
33 | |
34 void DesktopScreenPositionClient::ConvertNativePointToScreen( | |
35 aura::Window* window, gfx::Point* point) { | |
36 ConvertPointToScreen(window, point); | |
37 } | |
38 | |
39 void DesktopScreenPositionClient::SetBounds( | |
40 aura::Window* window, | |
41 const gfx::Rect& bounds, | |
42 const gfx::Display& display) { | |
43 // TODO: Use the 3rd parameter, |display|. | |
44 gfx::Point origin = bounds.origin(); | |
45 aura::RootWindow* root = window->GetRootWindow(); | |
46 aura::Window::ConvertPointToTarget(window->parent(), root, &origin); | |
47 | |
48 if (window->type() == aura::client::WINDOW_TYPE_CONTROL) { | |
49 window->SetBounds(gfx::Rect(origin, bounds.size())); | |
50 return; | |
51 } else if (window->type() == aura::client::WINDOW_TYPE_POPUP) { | |
52 // The caller expects windows we consider "embedded" to be placed in the | |
53 // screen coordinate system. So we need to offset the root window's | |
54 // position (which is in screen coordinates) from these bounds. | |
55 gfx::Point host_origin = root->GetHostOrigin(); | |
56 origin.Offset(-host_origin.x(), -host_origin.y()); | |
57 window->SetBounds(gfx::Rect(origin, bounds.size())); | |
58 return; | |
59 } | |
60 DesktopNativeWidgetAura* desktop_native_widget = | |
61 DesktopNativeWidgetAura::ForWindow(window); | |
62 if (desktop_native_widget) { | |
63 root->SetHostBounds(bounds); | |
64 // Setting bounds of root resizes |window|. | |
65 } else { | |
66 window->SetBounds(bounds); | |
67 } | |
68 } | |
69 | |
70 } // namespace views | |
OLD | NEW |