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

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

Issue 319013002: Reland Fix Views web-modal dialog widget creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert MediaGalleriesScanResultDialogViews::AcceptDialogForTesting. Created 6 years, 6 months 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/window_tree_host.h" 7 #include "ui/aura/window_tree_host.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 = root_window->GetHost()->GetBounds().origin();
19 root_window->GetHost()->GetBounds().origin();
20 aura::Window* window = const_cast<aura::Window*>(root_window); 19 aura::Window* window = const_cast<aura::Window*>(root_window);
21 float scale = gfx::Screen::GetScreenFor(window)-> 20 float scale = gfx::Screen::GetScreenFor(window)->
22 GetDisplayNearestWindow(window).device_scale_factor(); 21 GetDisplayNearestWindow(window).device_scale_factor();
23 return gfx::ToFlooredPoint( 22 return gfx::ToFlooredPoint(gfx::ScalePoint(origin_in_pixels, 1 / scale));
24 gfx::ScalePoint(origin_in_pixels, 1 / scale));
25 } 23 }
26 24
27 // Returns true if bounds passed to window are treated as though they are in 25 // Returns true if bounds passed to window are treated as though they are in
28 // screen coordinates. 26 // screen coordinates.
29 bool PositionWindowInScreenCoordinates(aura::Window* window) { 27 bool PositionWindowInScreenCoordinates(aura::Window* window) {
30 if (window->type() == ui::wm::WINDOW_TYPE_POPUP) 28 if (window->type() == ui::wm::WINDOW_TYPE_POPUP)
31 return true; 29 return true;
32 30
33 Widget* widget = Widget::GetWidgetForNativeView(window); 31 Widget* widget = Widget::GetWidgetForNativeView(window);
34 return widget && widget->is_top_level(); 32 return widget && widget->is_top_level();
35 } 33 }
36 34
37 } // namespace 35 } // namespace
38 36
39 DesktopScreenPositionClient::DesktopScreenPositionClient( 37 DesktopScreenPositionClient::DesktopScreenPositionClient(
40 aura::Window* root_window) : root_window_(root_window) { 38 aura::Window* root_window)
39 : root_window_(root_window) {
41 aura::client::SetScreenPositionClient(root_window_, this); 40 aura::client::SetScreenPositionClient(root_window_, this);
42 } 41 }
43 42
44 DesktopScreenPositionClient::~DesktopScreenPositionClient() { 43 DesktopScreenPositionClient::~DesktopScreenPositionClient() {
45 aura::client::SetScreenPositionClient(root_window_, NULL); 44 aura::client::SetScreenPositionClient(root_window_, NULL);
46 } 45 }
47 46
48 void DesktopScreenPositionClient::ConvertPointToScreen( 47 void DesktopScreenPositionClient::ConvertPointToScreen(
49 const aura::Window* window, gfx::Point* point) { 48 const aura::Window* window,
49 gfx::Point* point) {
50 const aura::Window* root_window = window->GetRootWindow(); 50 const aura::Window* root_window = window->GetRootWindow();
51 aura::Window::ConvertPointToTarget(window, root_window, point); 51 aura::Window::ConvertPointToTarget(window, root_window, point);
52 gfx::Point origin = GetOrigin(root_window); 52 gfx::Point origin = GetOrigin(root_window);
53 point->Offset(origin.x(), origin.y()); 53 point->Offset(origin.x(), origin.y());
54 } 54 }
55 55
56 void DesktopScreenPositionClient::ConvertPointFromScreen( 56 void DesktopScreenPositionClient::ConvertPointFromScreen(
57 const aura::Window* window, gfx::Point* point) { 57 const aura::Window* window,
58 gfx::Point* point) {
58 const aura::Window* root_window = window->GetRootWindow(); 59 const aura::Window* root_window = window->GetRootWindow();
59 gfx::Point origin = GetOrigin(root_window); 60 gfx::Point origin = GetOrigin(root_window);
60 point->Offset(-origin.x(), -origin.y()); 61 point->Offset(-origin.x(), -origin.y());
61 aura::Window::ConvertPointToTarget(root_window, window, point); 62 aura::Window::ConvertPointToTarget(root_window, window, point);
62 } 63 }
63 64
64 void DesktopScreenPositionClient::ConvertHostPointToScreen( 65 void DesktopScreenPositionClient::ConvertHostPointToScreen(aura::Window* window,
65 aura::Window* window, gfx::Point* point) { 66 gfx::Point* point) {
66 aura::Window* root_window = window->GetRootWindow(); 67 aura::Window* root_window = window->GetRootWindow();
67 ConvertPointToScreen(root_window, point); 68 ConvertPointToScreen(root_window, point);
68 } 69 }
69 70
70 void DesktopScreenPositionClient::SetBounds( 71 void DesktopScreenPositionClient::SetBounds(aura::Window* window,
71 aura::Window* window, 72 const gfx::Rect& bounds,
72 const gfx::Rect& bounds, 73 const gfx::Display& display) {
73 const gfx::Display& display) {
74 // TODO: Use the 3rd parameter, |display|. 74 // TODO: Use the 3rd parameter, |display|.
75 aura::Window* root = window->GetRootWindow(); 75 aura::Window* root = window->GetRootWindow();
76 76
77 // This method assumes that |window| does not have an associated 77 // This method assumes that |window| does not have an associated
78 // DesktopNativeWidgetAura. 78 // DesktopNativeWidgetAura.
79 internal::NativeWidgetPrivate* desktop_native_widget = 79 internal::NativeWidgetPrivate* desktop_native_widget =
80 DesktopNativeWidgetAura::ForWindow(root); 80 DesktopNativeWidgetAura::ForWindow(root);
81 DCHECK(!desktop_native_widget || 81 DCHECK(!desktop_native_widget ||
82 desktop_native_widget->GetNativeView() != window); 82 desktop_native_widget->GetNativeView() != window);
83 83
84 if (PositionWindowInScreenCoordinates(window)) { 84 if (PositionWindowInScreenCoordinates(window)) {
85 // The caller expects windows we consider "embedded" to be placed in the 85 // The caller expects windows we consider "embedded" to be placed in the
86 // screen coordinate system. So we need to offset the root window's 86 // screen coordinate system. So we need to offset the root window's
87 // position (which is in screen coordinates) from these bounds. 87 // position (which is in screen coordinates) from these bounds.
88 88
89 gfx::Point origin = bounds.origin(); 89 gfx::Point origin = bounds.origin();
90 aura::Window::ConvertPointToTarget(window->parent(), root, &origin); 90 aura::Window::ConvertPointToTarget(window->parent(), root, &origin);
91 91
92 gfx::Point host_origin = GetOrigin(root); 92 gfx::Point host_origin = GetOrigin(root);
93 origin.Offset(-host_origin.x(), -host_origin.y()); 93 origin.Offset(-host_origin.x(), -host_origin.y());
94 window->SetBounds(gfx::Rect(origin, bounds.size())); 94 window->SetBounds(gfx::Rect(origin, bounds.size()));
95 return; 95 return;
96 } 96 }
97 97
98 window->SetBounds(bounds); 98 window->SetBounds(bounds);
99 } 99 }
100 100
101 } // namespace views 101 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698