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

Side by Side Diff: ui/wm/core/default_screen_position_client.cc

Issue 686513004: Creating default implementation for aura::client::ScreenPositionClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing unwanted change. Created 6 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
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/wm/core/default_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"
12 11
13 namespace views { 12 namespace wm {
14 13
15 namespace { 14 namespace {
16 15
17 gfx::Point GetOrigin(const aura::Window* root_window) { 16 gfx::Point GetOrigin(const aura::Window* root_window) {
18 gfx::Point origin_in_pixels = root_window->GetHost()->GetBounds().origin(); 17 gfx::Point origin_in_pixels = root_window->GetHost()->GetBounds().origin();
19 aura::Window* window = const_cast<aura::Window*>(root_window); 18 aura::Window* window = const_cast<aura::Window*>(root_window);
20 float scale = gfx::Screen::GetScreenFor(window)-> 19 float scale = gfx::Screen::GetScreenFor(window)->
21 GetDisplayNearestWindow(window).device_scale_factor(); 20 GetDisplayNearestWindow(window).device_scale_factor();
22 return gfx::ToFlooredPoint(gfx::ScalePoint(origin_in_pixels, 1 / scale)); 21 return gfx::ToFlooredPoint(gfx::ScalePoint(origin_in_pixels, 1 / scale));
23 } 22 }
24 23
25 // Returns true if bounds passed to window are treated as though they are in
26 // screen coordinates.
27 bool PositionWindowInScreenCoordinates(aura::Window* window) {
28 if (window->type() == ui::wm::WINDOW_TYPE_POPUP)
29 return true;
30
31 Widget* widget = Widget::GetWidgetForNativeView(window);
32 return widget && widget->is_top_level();
33 }
34
35 } // namespace 24 } // namespace
36 25
37 DesktopScreenPositionClient::DesktopScreenPositionClient( 26 DefaultScreenPositionClient::DefaultScreenPositionClient() {
38 aura::Window* root_window)
39 : root_window_(root_window) {
40 aura::client::SetScreenPositionClient(root_window_, this);
41 } 27 }
42 28
43 DesktopScreenPositionClient::~DesktopScreenPositionClient() { 29 DefaultScreenPositionClient::~DefaultScreenPositionClient() {
44 aura::client::SetScreenPositionClient(root_window_, NULL);
45 } 30 }
46 31
47 void DesktopScreenPositionClient::ConvertPointToScreen( 32 bool DefaultScreenPositionClient::PositionWindowInScreenCoordinates(
33 aura::Window* window) {
34 return window->type() == ui::wm::WINDOW_TYPE_POPUP;
sadrul 2014/10/30 16:09:11 Why special case POPUP here?
mfomitchev 2014/10/30 20:12:53 I just copied this code from desktop_native_widget
sadrul 2014/10/30 20:20:07 Yeah. I think we can do without PositionWindowInSc
mfomitchev 2014/10/30 22:02:12 Done.
35 }
36
37 void DefaultScreenPositionClient::ConvertPointToScreen(
48 const aura::Window* window, 38 const aura::Window* window,
49 gfx::Point* point) { 39 gfx::Point* point) {
50 const aura::Window* root_window = window->GetRootWindow(); 40 const aura::Window* root_window = window->GetRootWindow();
51 aura::Window::ConvertPointToTarget(window, root_window, point); 41 aura::Window::ConvertPointToTarget(window, root_window, point);
52 gfx::Point origin = GetOrigin(root_window); 42 gfx::Point origin = GetOrigin(root_window);
53 point->Offset(origin.x(), origin.y()); 43 point->Offset(origin.x(), origin.y());
54 } 44 }
55 45
56 void DesktopScreenPositionClient::ConvertPointFromScreen( 46 void DefaultScreenPositionClient::ConvertPointFromScreen(
57 const aura::Window* window, 47 const aura::Window* window,
58 gfx::Point* point) { 48 gfx::Point* point) {
59 const aura::Window* root_window = window->GetRootWindow(); 49 const aura::Window* root_window = window->GetRootWindow();
60 gfx::Point origin = GetOrigin(root_window); 50 gfx::Point origin = GetOrigin(root_window);
61 point->Offset(-origin.x(), -origin.y()); 51 point->Offset(-origin.x(), -origin.y());
62 aura::Window::ConvertPointToTarget(root_window, window, point); 52 aura::Window::ConvertPointToTarget(root_window, window, point);
63 } 53 }
64 54
65 void DesktopScreenPositionClient::ConvertHostPointToScreen(aura::Window* window, 55 void DefaultScreenPositionClient::ConvertHostPointToScreen(aura::Window* window,
66 gfx::Point* point) { 56 gfx::Point* point) {
67 aura::Window* root_window = window->GetRootWindow(); 57 aura::Window* root_window = window->GetRootWindow();
68 ConvertPointToScreen(root_window, point); 58 ConvertPointToScreen(root_window, point);
69 } 59 }
70 60
71 void DesktopScreenPositionClient::SetBounds(aura::Window* window, 61 void DefaultScreenPositionClient::SetBounds(aura::Window* window,
72 const gfx::Rect& bounds, 62 const gfx::Rect& bounds,
73 const gfx::Display& display) { 63 const gfx::Display& display) {
74 // TODO: Use the 3rd parameter, |display|. 64 if (PositionWindowInScreenCoordinates(window)) {
75 aura::Window* root = window->GetRootWindow(); 65 aura::Window* root = window->GetRootWindow();
76 66
77 // This method assumes that |window| does not have an associated
78 // DesktopNativeWidgetAura.
79 internal::NativeWidgetPrivate* desktop_native_widget =
80 DesktopNativeWidgetAura::ForWindow(root);
81 DCHECK(!desktop_native_widget ||
82 desktop_native_widget->GetNativeView() != window);
83
84 if (PositionWindowInScreenCoordinates(window)) {
85 // The caller expects windows we consider "embedded" to be placed in the 67 // 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 68 // screen coordinate system. So we need to offset the root window's
87 // position (which is in screen coordinates) from these bounds. 69 // position (which is in screen coordinates) from these bounds.
88
89 gfx::Point origin = bounds.origin(); 70 gfx::Point origin = bounds.origin();
90 aura::Window::ConvertPointToTarget(window->parent(), root, &origin); 71 aura::Window::ConvertPointToTarget(window->parent(), root, &origin);
91 72
92 gfx::Point host_origin = GetOrigin(root); 73 gfx::Point host_origin = GetOrigin(root);
93 origin.Offset(-host_origin.x(), -host_origin.y()); 74 origin.Offset(-host_origin.x(), -host_origin.y());
94 window->SetBounds(gfx::Rect(origin, bounds.size())); 75 window->SetBounds(gfx::Rect(origin, bounds.size()));
95 return; 76 return;
96 } 77 }
97 78
98 window->SetBounds(bounds); 79 window->SetBounds(bounds);
99 } 80 }
100 81
101 } // namespace views 82 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698