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

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

Issue 1003863005: Fix tab drag and drop with hi-dpi. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename functions for clarity Created 5 years, 9 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
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_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
6 6
7 #include <X11/extensions/Xrandr.h> 7 #include <X11/extensions/Xrandr.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 // It clashes with out RootWindow. 10 // It clashes with out RootWindow.
(...skipping 27 matching lines...) Expand all
38 const int kCSSDefaultDPI = 96; 38 const int kCSSDefaultDPI = 96;
39 const float kInchInMm = 25.4f; 39 const float kInchInMm = 25.4f;
40 40
41 float screen_inches = screen_mm / kInchInMm; 41 float screen_inches = screen_mm / kInchInMm;
42 float screen_dpi = screen_pixels / screen_inches; 42 float screen_dpi = screen_pixels / screen_inches;
43 float scale = screen_dpi / kCSSDefaultDPI; 43 float scale = screen_dpi / kCSSDefaultDPI;
44 44
45 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale)); 45 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale));
46 } 46 }
47 47
48 float GetDeviceScaleFactor() {
49 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
50 return display.device_scale_factor();
51 }
52
53 gfx::Point PixelToDIPPoint(const gfx::Point& pixel_point) {
54 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor()));
55 }
56
57 gfx::Point DIPToPixelPoint(const gfx::Point& dip_point) {
58 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor()));
59 }
60
48 std::vector<gfx::Display> GetFallbackDisplayList() { 61 std::vector<gfx::Display> GetFallbackDisplayList() {
49 ::XDisplay* display = gfx::GetXDisplay(); 62 ::XDisplay* display = gfx::GetXDisplay();
50 ::Screen* screen = DefaultScreenOfDisplay(display); 63 ::Screen* screen = DefaultScreenOfDisplay(display);
51 int width = WidthOfScreen(screen); 64 int width = WidthOfScreen(screen);
52 int height = HeightOfScreen(screen); 65 int height = HeightOfScreen(screen);
53 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); 66 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen));
54 67
55 gfx::Rect bounds_in_pixels(0, 0, width, height); 68 gfx::Rect bounds_in_pixels(0, 0, width, height);
56 gfx::Display gfx_display(0, bounds_in_pixels); 69 gfx::Display gfx_display(0, bounds_in_pixels);
57 if (!gfx::Display::HasForceDeviceScaleFactor() && 70 if (!gfx::Display::HasForceDeviceScaleFactor() &&
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 XQueryPointer(display, 136 XQueryPointer(display,
124 DefaultRootWindow(display), 137 DefaultRootWindow(display),
125 &root, 138 &root,
126 &child, 139 &child,
127 &root_x, 140 &root_x,
128 &root_y, 141 &root_y,
129 &win_x, 142 &win_x,
130 &win_y, 143 &win_y,
131 &mask); 144 &mask);
132 145
133 return gfx::Point(root_x, root_y); 146 return PixelToDIPPoint(gfx::Point(root_x, root_y));
134 } 147 }
135 148
136 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() { 149 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() {
137 return GetWindowAtScreenPoint(GetCursorScreenPoint()); 150 return GetWindowAtScreenPoint(GetCursorScreenPoint());
138 } 151 }
139 152
140 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( 153 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint(
141 const gfx::Point& point) { 154 const gfx::Point& point) {
142 X11TopmostWindowFinder finder; 155 X11TopmostWindowFinder finder;
143 return finder.FindLocalProcessWindowAt(point, std::set<aura::Window*>()); 156 return finder.FindLocalProcessWindowAt(point, std::set<aura::Window*>());
sadrul 2015/03/19 23:46:58 Do we need to changes in X11TopmostWindowFinder if
stapelberg 2015/03/20 08:34:40 Done.
144 } 157 }
145 158
146 int DesktopScreenX11::GetNumDisplays() const { 159 int DesktopScreenX11::GetNumDisplays() const {
147 return displays_.size(); 160 return displays_.size();
148 } 161 }
149 162
150 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const { 163 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const {
151 return displays_; 164 return displays_;
152 } 165 }
153 166
(...skipping 16 matching lines...) Expand all
170 DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID( 183 DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID(
171 host->GetAcceleratedWidget()); 184 host->GetAcceleratedWidget());
172 if (rwh) 185 if (rwh)
173 return GetDisplayMatching(rwh->GetX11RootWindowBounds()); 186 return GetDisplayMatching(rwh->GetX11RootWindowBounds());
174 } 187 }
175 188
176 return GetPrimaryDisplay(); 189 return GetPrimaryDisplay();
177 } 190 }
178 191
179 gfx::Display DesktopScreenX11::GetDisplayNearestPoint( 192 gfx::Display DesktopScreenX11::GetDisplayNearestPoint(
180 const gfx::Point& point) const { 193 const gfx::Point& requested_point) const {
194 const gfx::Point point_in_pixel = DIPToPixelPoint(requested_point);
181 for (std::vector<gfx::Display>::const_iterator it = displays_.begin(); 195 for (std::vector<gfx::Display>::const_iterator it = displays_.begin();
182 it != displays_.end(); ++it) { 196 it != displays_.end(); ++it) {
183 if (it->bounds().Contains(point)) 197 if (it->bounds().Contains(point_in_pixel))
184 return *it; 198 return *it;
185 } 199 }
186 200
187 return GetPrimaryDisplay(); 201 return GetPrimaryDisplay();
188 } 202 }
189 203
190 gfx::Display DesktopScreenX11::GetDisplayMatching( 204 gfx::Display DesktopScreenX11::GetDisplayMatching(
191 const gfx::Rect& match_rect) const { 205 const gfx::Rect& match_rect) const {
192 int max_area = 0; 206 int max_area = 0;
193 const gfx::Display* matching = NULL; 207 const gfx::Display* matching = NULL;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); 372 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
359 } 373 }
360 374
361 //////////////////////////////////////////////////////////////////////////////// 375 ////////////////////////////////////////////////////////////////////////////////
362 376
363 gfx::Screen* CreateDesktopScreen() { 377 gfx::Screen* CreateDesktopScreen() {
364 return new DesktopScreenX11; 378 return new DesktopScreenX11;
365 } 379 }
366 380
367 } // namespace views 381 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698