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 "ui/views/widget/desktop_aura/desktop_screen_position_client.h" | 5 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" |
6 | 6 |
7 #include "ui/aura/window_event_dispatcher.h" | 7 #include "ui/aura/window_event_dispatcher.h" |
8 #include "ui/gfx/display.h" | 8 #include "ui/gfx/display.h" |
9 #include "ui/gfx/point_conversions.h" | 9 #include "ui/gfx/point_conversions.h" |
10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
11 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 11 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 gfx::Point GetOrigin(const aura::Window* root_window) { | 17 gfx::Point GetOrigin(const aura::Window* root_window) { |
18 gfx::Point origin_in_pixels = | 18 gfx::Point origin_in_pixels = |
19 root_window->GetDispatcher()->host()->GetBounds().origin(); | 19 root_window->GetHost()->GetBounds().origin(); |
20 aura::Window* window = const_cast<aura::Window*>(root_window); | 20 aura::Window* window = const_cast<aura::Window*>(root_window); |
21 float scale = gfx::Screen::GetScreenFor(window)-> | 21 float scale = gfx::Screen::GetScreenFor(window)-> |
22 GetDisplayNearestWindow(window).device_scale_factor(); | 22 GetDisplayNearestWindow(window).device_scale_factor(); |
23 return gfx::ToFlooredPoint( | 23 return gfx::ToFlooredPoint( |
24 gfx::ScalePoint(origin_in_pixels, 1 / scale)); | 24 gfx::ScalePoint(origin_in_pixels, 1 / scale)); |
25 } | 25 } |
26 | 26 |
27 // Returns true if bounds passed to window are treated as though they are in | 27 // Returns true if bounds passed to window are treated as though they are in |
28 // screen coordinates. | 28 // screen coordinates. |
29 bool PositionWindowInScreenCoordinates(aura::Window* window) { | 29 bool PositionWindowInScreenCoordinates(aura::Window* window) { |
30 if (window->type() == ui::wm::WINDOW_TYPE_POPUP || | 30 if (window->type() == ui::wm::WINDOW_TYPE_POPUP || |
31 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP) | 31 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP) |
32 return true; | 32 return true; |
33 | 33 |
34 Widget* widget = Widget::GetWidgetForNativeView(window); | 34 Widget* widget = Widget::GetWidgetForNativeView(window); |
35 return widget && widget->is_top_level(); | 35 return widget && widget->is_top_level(); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 DesktopScreenPositionClient::DesktopScreenPositionClient() { | 40 DesktopScreenPositionClient::DesktopScreenPositionClient( |
| 41 aura::Window* root_window) : root_window_(root_window) { |
| 42 aura::client::SetScreenPositionClient(root_window_, this); |
41 } | 43 } |
42 | 44 |
43 DesktopScreenPositionClient::~DesktopScreenPositionClient() { | 45 DesktopScreenPositionClient::~DesktopScreenPositionClient() { |
| 46 aura::client::SetScreenPositionClient(root_window_, NULL); |
44 } | 47 } |
45 | 48 |
46 void DesktopScreenPositionClient::ConvertPointToScreen( | 49 void DesktopScreenPositionClient::ConvertPointToScreen( |
47 const aura::Window* window, gfx::Point* point) { | 50 const aura::Window* window, gfx::Point* point) { |
48 const aura::Window* root_window = window->GetRootWindow(); | 51 const aura::Window* root_window = window->GetRootWindow(); |
49 aura::Window::ConvertPointToTarget(window, root_window, point); | 52 aura::Window::ConvertPointToTarget(window, root_window, point); |
50 gfx::Point origin = GetOrigin(root_window); | 53 gfx::Point origin = GetOrigin(root_window); |
51 point->Offset(origin.x(), origin.y()); | 54 point->Offset(origin.x(), origin.y()); |
52 } | 55 } |
53 | 56 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 window->SetBounds(gfx::Rect(origin, bounds.size())); | 88 window->SetBounds(gfx::Rect(origin, bounds.size())); |
86 return; | 89 return; |
87 } | 90 } |
88 | 91 |
89 internal::NativeWidgetPrivate* desktop_native_widget = | 92 internal::NativeWidgetPrivate* desktop_native_widget = |
90 DesktopNativeWidgetAura::ForWindow(root); | 93 DesktopNativeWidgetAura::ForWindow(root); |
91 if (desktop_native_widget && | 94 if (desktop_native_widget && |
92 desktop_native_widget->GetNativeView() == window) { | 95 desktop_native_widget->GetNativeView() == window) { |
93 // |window| is the content_window. | 96 // |window| is the content_window. |
94 // Setting bounds of root resizes |window|. | 97 // Setting bounds of root resizes |window|. |
95 root->GetDispatcher()->host()->SetBounds(bounds); | 98 root->GetHost()->SetBounds(bounds); |
96 } else { | 99 } else { |
97 window->SetBounds(bounds); | 100 window->SetBounds(bounds); |
98 } | 101 } |
99 } | 102 } |
100 | 103 |
101 } // namespace views | 104 } // namespace views |
OLD | NEW |