OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/wm/core/default_screen_position_client.h" | |
6 | |
7 #include "ui/aura/window_tree_host.h" | |
8 #include "ui/gfx/display.h" | |
9 #include "ui/gfx/point_conversions.h" | |
10 #include "ui/gfx/screen.h" | |
11 | |
12 namespace wm { | |
13 | |
14 DefaultScreenPositionClient::DefaultScreenPositionClient() { | |
15 } | |
16 | |
17 DefaultScreenPositionClient::~DefaultScreenPositionClient() { | |
18 } | |
19 | |
20 gfx::Point DefaultScreenPositionClient::GetOriginInScreen( | |
21 const aura::Window* root_window) { | |
22 gfx::Point origin_in_pixels = root_window->GetHost()->GetBounds().origin(); | |
23 aura::Window* window = const_cast<aura::Window*>(root_window); | |
24 float scale = gfx::Screen::GetScreenFor(window)-> | |
25 GetDisplayNearestWindow(window).device_scale_factor(); | |
26 return gfx::ToFlooredPoint(gfx::ScalePoint(origin_in_pixels, 1 / scale)); | |
oshima
2014/11/03 21:40:25
i prefer to use float on both side (1.0f)
| |
27 } | |
28 | |
29 void DefaultScreenPositionClient::ConvertPointToScreen( | |
30 const aura::Window* window, | |
31 gfx::Point* point) { | |
32 const aura::Window* root_window = window->GetRootWindow(); | |
33 aura::Window::ConvertPointToTarget(window, root_window, point); | |
34 gfx::Point origin = GetOriginInScreen(root_window); | |
35 point->Offset(origin.x(), origin.y()); | |
36 } | |
37 | |
38 void DefaultScreenPositionClient::ConvertPointFromScreen( | |
39 const aura::Window* window, | |
40 gfx::Point* point) { | |
41 const aura::Window* root_window = window->GetRootWindow(); | |
42 gfx::Point origin = GetOriginInScreen(root_window); | |
43 point->Offset(-origin.x(), -origin.y()); | |
44 aura::Window::ConvertPointToTarget(root_window, window, point); | |
45 } | |
46 | |
47 void DefaultScreenPositionClient::ConvertHostPointToScreen(aura::Window* window, | |
48 gfx::Point* point) { | |
49 aura::Window* root_window = window->GetRootWindow(); | |
50 ConvertPointToScreen(root_window, point); | |
51 } | |
52 | |
53 void DefaultScreenPositionClient::SetBounds(aura::Window* window, | |
54 const gfx::Rect& bounds, | |
55 const gfx::Display& display) { | |
56 window->SetBounds(bounds); | |
57 } | |
58 | |
59 } // namespace wm | |
OLD | NEW |