| 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/root_window.h" | 7 #include "ui/aura/root_window.h" |
| 8 #include "ui/gfx/display.h" |
| 9 #include "ui/gfx/point_conversions.h" |
| 10 #include "ui/gfx/screen.h" |
| 11 |
| 8 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 12 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 9 | 13 |
| 14 namespace { |
| 15 |
| 16 gfx::Point GetOrigin(const aura::RootWindow* root_window) { |
| 17 gfx::Point origin_in_pixels = root_window->GetHostOrigin(); |
| 18 aura::RootWindow* window = const_cast<aura::RootWindow*>(root_window); |
| 19 float scale = gfx::Screen::GetScreenFor(window)-> |
| 20 GetDisplayNearestWindow(window).device_scale_factor(); |
| 21 return gfx::ToFlooredPoint( |
| 22 gfx::ScalePoint(origin_in_pixels, 1 / scale)); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 10 namespace views { | 27 namespace views { |
| 11 | 28 |
| 12 DesktopScreenPositionClient::DesktopScreenPositionClient() { | 29 DesktopScreenPositionClient::DesktopScreenPositionClient() { |
| 13 } | 30 } |
| 14 | 31 |
| 15 DesktopScreenPositionClient::~DesktopScreenPositionClient() { | 32 DesktopScreenPositionClient::~DesktopScreenPositionClient() { |
| 16 } | 33 } |
| 17 | 34 |
| 18 void DesktopScreenPositionClient::ConvertPointToScreen( | 35 void DesktopScreenPositionClient::ConvertPointToScreen( |
| 19 const aura::Window* window, gfx::Point* point) { | 36 const aura::Window* window, gfx::Point* point) { |
| 20 const aura::RootWindow* root_window = window->GetRootWindow(); | 37 const aura::RootWindow* root_window = window->GetRootWindow(); |
| 21 aura::Window::ConvertPointToTarget(window, root_window, point); | 38 aura::Window::ConvertPointToTarget(window, root_window, point); |
| 22 gfx::Point origin = root_window->GetHostOrigin(); | 39 gfx::Point origin = GetOrigin(root_window); |
| 23 point->Offset(origin.x(), origin.y()); | 40 point->Offset(origin.x(), origin.y()); |
| 24 } | 41 } |
| 25 | 42 |
| 26 void DesktopScreenPositionClient::ConvertPointFromScreen( | 43 void DesktopScreenPositionClient::ConvertPointFromScreen( |
| 27 const aura::Window* window, gfx::Point* point) { | 44 const aura::Window* window, gfx::Point* point) { |
| 28 const aura::RootWindow* root_window = window->GetRootWindow(); | 45 const aura::RootWindow* root_window = window->GetRootWindow(); |
| 29 gfx::Point origin = root_window->GetHostOrigin(); | 46 gfx::Point origin = GetOrigin(root_window); |
| 30 point->Offset(-origin.x(), -origin.y()); | 47 point->Offset(-origin.x(), -origin.y()); |
| 31 aura::Window::ConvertPointToTarget(root_window, window, point); | 48 aura::Window::ConvertPointToTarget(root_window, window, point); |
| 32 } | 49 } |
| 33 | 50 |
| 34 void DesktopScreenPositionClient::ConvertHostPointToScreen( | 51 void DesktopScreenPositionClient::ConvertHostPointToScreen( |
| 35 aura::RootWindow* window, gfx::Point* point) { | 52 aura::RootWindow* window, gfx::Point* point) { |
| 36 ConvertPointToScreen(window, point); | 53 ConvertPointToScreen(window, point); |
| 37 } | 54 } |
| 38 | 55 |
| 39 void DesktopScreenPositionClient::SetBounds( | 56 void DesktopScreenPositionClient::SetBounds( |
| 40 aura::Window* window, | 57 aura::Window* window, |
| 41 const gfx::Rect& bounds, | 58 const gfx::Rect& bounds, |
| 42 const gfx::Display& display) { | 59 const gfx::Display& display) { |
| 43 // TODO: Use the 3rd parameter, |display|. | 60 // TODO: Use the 3rd parameter, |display|. |
| 44 gfx::Point origin = bounds.origin(); | 61 gfx::Point origin = bounds.origin(); |
| 45 aura::RootWindow* root = window->GetRootWindow(); | 62 aura::RootWindow* root = window->GetRootWindow(); |
| 46 aura::Window::ConvertPointToTarget(window->parent(), root, &origin); | 63 aura::Window::ConvertPointToTarget(window->parent(), root, &origin); |
| 47 | 64 |
| 48 if (window->type() == aura::client::WINDOW_TYPE_CONTROL) { | 65 if (window->type() == aura::client::WINDOW_TYPE_CONTROL) { |
| 49 window->SetBounds(gfx::Rect(origin, bounds.size())); | 66 window->SetBounds(gfx::Rect(origin, bounds.size())); |
| 50 return; | 67 return; |
| 51 } else if (window->type() == aura::client::WINDOW_TYPE_POPUP || | 68 } else if (window->type() == aura::client::WINDOW_TYPE_POPUP || |
| 52 window->type() == aura::client::WINDOW_TYPE_TOOLTIP) { | 69 window->type() == aura::client::WINDOW_TYPE_TOOLTIP) { |
| 53 // The caller expects windows we consider "embedded" to be placed in the | 70 // The caller expects windows we consider "embedded" to be placed in the |
| 54 // screen coordinate system. So we need to offset the root window's | 71 // screen coordinate system. So we need to offset the root window's |
| 55 // position (which is in screen coordinates) from these bounds. | 72 // position (which is in screen coordinates) from these bounds. |
| 56 gfx::Point host_origin = root->GetHostOrigin(); | 73 gfx::Point host_origin = GetOrigin(root); |
| 57 origin.Offset(-host_origin.x(), -host_origin.y()); | 74 origin.Offset(-host_origin.x(), -host_origin.y()); |
| 58 window->SetBounds(gfx::Rect(origin, bounds.size())); | 75 window->SetBounds(gfx::Rect(origin, bounds.size())); |
| 59 return; | 76 return; |
| 60 } | 77 } |
| 61 DesktopNativeWidgetAura* desktop_native_widget = | 78 DesktopNativeWidgetAura* desktop_native_widget = |
| 62 DesktopNativeWidgetAura::ForWindow(window); | 79 DesktopNativeWidgetAura::ForWindow(window); |
| 63 if (desktop_native_widget) { | 80 if (desktop_native_widget) { |
| 64 root->SetHostBounds(bounds); | 81 root->SetHostBounds(bounds); |
| 65 // Setting bounds of root resizes |window|. | 82 // Setting bounds of root resizes |window|. |
| 66 } else { | 83 } else { |
| 67 window->SetBounds(bounds); | 84 window->SetBounds(bounds); |
| 68 } | 85 } |
| 69 } | 86 } |
| 70 | 87 |
| 71 } // namespace views | 88 } // namespace views |
| OLD | NEW |