Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_position_client.cc

Issue 37733003: Make GetRootWindow() return a Window instead of a RootWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 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::RootWindow* root_window) { 17 gfx::Point GetOrigin(const aura::Window* root_window) {
18 gfx::Point origin_in_pixels = root_window->GetHostOrigin(); 18 gfx::Point origin_in_pixels = root_window->GetDispatcher()->GetHostOrigin();
19 aura::RootWindow* window = const_cast<aura::RootWindow*>(root_window); 19 aura::Window* window = const_cast<aura::Window*>(root_window);
20 float scale = gfx::Screen::GetScreenFor(window)-> 20 float scale = gfx::Screen::GetScreenFor(window)->
21 GetDisplayNearestWindow(window).device_scale_factor(); 21 GetDisplayNearestWindow(window).device_scale_factor();
22 return gfx::ToFlooredPoint( 22 return gfx::ToFlooredPoint(
23 gfx::ScalePoint(origin_in_pixels, 1 / scale)); 23 gfx::ScalePoint(origin_in_pixels, 1 / scale));
24 } 24 }
25 25
26 // Returns true if bounds passed to window are treated as though they are in 26 // Returns true if bounds passed to window are treated as though they are in
27 // screen coordinates. 27 // screen coordinates.
28 bool PositionWindowInScreenCoordinates(aura::Window* window) { 28 bool PositionWindowInScreenCoordinates(aura::Window* window) {
29 if (window->type() == aura::client::WINDOW_TYPE_POPUP || 29 if (window->type() == aura::client::WINDOW_TYPE_POPUP ||
30 window->type() == aura::client::WINDOW_TYPE_TOOLTIP) 30 window->type() == aura::client::WINDOW_TYPE_TOOLTIP)
31 return true; 31 return true;
32 32
33 Widget* widget = Widget::GetWidgetForNativeView(window); 33 Widget* widget = Widget::GetWidgetForNativeView(window);
34 return widget && widget->is_top_level(); 34 return widget && widget->is_top_level();
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 DesktopScreenPositionClient::DesktopScreenPositionClient() { 39 DesktopScreenPositionClient::DesktopScreenPositionClient() {
40 } 40 }
41 41
42 DesktopScreenPositionClient::~DesktopScreenPositionClient() { 42 DesktopScreenPositionClient::~DesktopScreenPositionClient() {
43 } 43 }
44 44
45 void DesktopScreenPositionClient::ConvertPointToScreen( 45 void DesktopScreenPositionClient::ConvertPointToScreen(
46 const aura::Window* window, gfx::Point* point) { 46 const aura::Window* window, gfx::Point* point) {
47 const aura::RootWindow* root_window = window->GetRootWindow(); 47 const aura::Window* root_window = window->GetRootWindow();
48 aura::Window::ConvertPointToTarget(window, root_window, point); 48 aura::Window::ConvertPointToTarget(window, root_window, point);
49 gfx::Point origin = GetOrigin(root_window); 49 gfx::Point origin = GetOrigin(root_window);
50 point->Offset(origin.x(), origin.y()); 50 point->Offset(origin.x(), origin.y());
51 } 51 }
52 52
53 void DesktopScreenPositionClient::ConvertPointFromScreen( 53 void DesktopScreenPositionClient::ConvertPointFromScreen(
54 const aura::Window* window, gfx::Point* point) { 54 const aura::Window* window, gfx::Point* point) {
55 const aura::RootWindow* root_window = window->GetRootWindow(); 55 const aura::Window* root_window = window->GetRootWindow();
56 gfx::Point origin = GetOrigin(root_window); 56 gfx::Point origin = GetOrigin(root_window);
57 point->Offset(-origin.x(), -origin.y()); 57 point->Offset(-origin.x(), -origin.y());
58 aura::Window::ConvertPointToTarget(root_window, window, point); 58 aura::Window::ConvertPointToTarget(root_window, window, point);
59 } 59 }
60 60
61 void DesktopScreenPositionClient::ConvertHostPointToScreen( 61 void DesktopScreenPositionClient::ConvertHostPointToScreen(
62 aura::Window* window, gfx::Point* point) { 62 aura::Window* window, gfx::Point* point) {
63 aura::RootWindow* root_window = window->GetRootWindow(); 63 aura::Window* root_window = window->GetRootWindow();
64 ConvertPointToScreen(root_window, point); 64 ConvertPointToScreen(root_window, point);
65 } 65 }
66 66
67 void DesktopScreenPositionClient::SetBounds( 67 void DesktopScreenPositionClient::SetBounds(
68 aura::Window* window, 68 aura::Window* window,
69 const gfx::Rect& bounds, 69 const gfx::Rect& bounds,
70 const gfx::Display& display) { 70 const gfx::Display& display) {
71 // TODO: Use the 3rd parameter, |display|. 71 // TODO: Use the 3rd parameter, |display|.
72 aura::RootWindow* root = window->GetRootWindow(); 72 aura::Window* root = window->GetRootWindow();
73 73
74 if (PositionWindowInScreenCoordinates(window)) { 74 if (PositionWindowInScreenCoordinates(window)) {
75 // The caller expects windows we consider "embedded" to be placed in the 75 // The caller expects windows we consider "embedded" to be placed in the
76 // screen coordinate system. So we need to offset the root window's 76 // screen coordinate system. So we need to offset the root window's
77 // position (which is in screen coordinates) from these bounds. 77 // position (which is in screen coordinates) from these bounds.
78 78
79 gfx::Point origin = bounds.origin(); 79 gfx::Point origin = bounds.origin();
80 aura::Window::ConvertPointToTarget(window->parent(), root, &origin); 80 aura::Window::ConvertPointToTarget(window->parent(), root, &origin);
81 81
82 gfx::Point host_origin = GetOrigin(root); 82 gfx::Point host_origin = GetOrigin(root);
83 origin.Offset(-host_origin.x(), -host_origin.y()); 83 origin.Offset(-host_origin.x(), -host_origin.y());
84 window->SetBounds(gfx::Rect(origin, bounds.size())); 84 window->SetBounds(gfx::Rect(origin, bounds.size()));
85 return; 85 return;
86 } 86 }
87 87
88 DesktopNativeWidgetAura* desktop_native_widget = 88 DesktopNativeWidgetAura* desktop_native_widget =
89 DesktopNativeWidgetAura::ForWindow(window); 89 DesktopNativeWidgetAura::ForWindow(window);
90 if (desktop_native_widget) { 90 if (desktop_native_widget) {
91 root->SetHostBounds(bounds); 91 root->GetDispatcher()->SetHostBounds(bounds);
92 // Setting bounds of root resizes |window|. 92 // Setting bounds of root resizes |window|.
93 } else { 93 } else {
94 window->SetBounds(bounds); 94 window->SetBounds(bounds);
95 } 95 }
96 } 96 }
97 97
98 } // namespace views 98 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_win.cc ('k') | ui/views/widget/desktop_aura/desktop_screen_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698