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

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

Issue 260263002: Merge three implementations for getting the topmost x11 window at a point (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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_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.
11 #undef RootWindow 11 #undef RootWindow
12 12
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
19 #include "ui/display/util/display_util.h" 19 #include "ui/display/util/display_util.h"
20 #include "ui/display/util/x11/edid_parser_x11.h" 20 #include "ui/display/util/x11/edid_parser_x11.h"
21 #include "ui/events/platform/platform_event_source.h" 21 #include "ui/events/platform/platform_event_source.h"
22 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
23 #include "ui/gfx/display_observer.h" 23 #include "ui/gfx/display_observer.h"
24 #include "ui/gfx/native_widget_types.h" 24 #include "ui/gfx/native_widget_types.h"
25 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/gfx/x/x11_types.h" 26 #include "ui/gfx/x/x11_types.h"
27 #include "ui/views/widget/desktop_aura/desktop_screen.h" 27 #include "ui/views/widget/desktop_aura/desktop_screen.h"
28 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 28 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
29 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
29 30
30 namespace { 31 namespace {
31 32
32 // The delay to perform configuration after RRNotify. See the comment 33 // The delay to perform configuration after RRNotify. See the comment
33 // in |Dispatch()|. 34 // in |Dispatch()|.
34 const int64 kConfigureDelayMs = 500; 35 const int64 kConfigureDelayMs = 500;
35 36
36 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) { 37 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) {
37 const int kCSSDefaultDPI = 96; 38 const int kCSSDefaultDPI = 96;
38 const float kInchInMm = 25.4f; 39 const float kInchInMm = 25.4f;
(...skipping 18 matching lines...) Expand all
57 !ui::IsDisplaySizeBlackListed(physical_size)) { 58 !ui::IsDisplaySizeBlackListed(physical_size)) {
58 float device_scale_factor = GetDeviceScaleFactor( 59 float device_scale_factor = GetDeviceScaleFactor(
59 width, physical_size.width()); 60 width, physical_size.width());
60 DCHECK_LE(1.0f, device_scale_factor); 61 DCHECK_LE(1.0f, device_scale_factor);
61 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); 62 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels);
62 } 63 }
63 64
64 return std::vector<gfx::Display>(1, gfx_display); 65 return std::vector<gfx::Display>(1, gfx_display);
65 } 66 }
66 67
67 // Helper class to GetWindowAtScreenPoint() which returns the topmost window at
68 // the location passed to FindAt(). NULL is returned if a window which does not
69 // belong to Chromium is topmost at the passed in location.
70 class ToplevelWindowFinder : public ui::EnumerateWindowsDelegate {
71 public:
72 ToplevelWindowFinder() : toplevel_(NULL) {
73 }
74
75 virtual ~ToplevelWindowFinder() {
76 }
77
78 aura::Window* FindAt(const gfx::Point& screen_loc) {
79 screen_loc_ = screen_loc;
80 ui::EnumerateTopLevelWindows(this);
81 return toplevel_;
82 }
83
84 protected:
85 virtual bool ShouldStopIterating(XID xid) OVERRIDE {
86 if (!ui::IsWindowVisible(xid))
87 return false;
88
89 aura::Window* window =
90 views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid);
91 if (window) {
92 // Currently |window|->IsVisible() always returns true.
93 // TODO(pkotwicz): Fix this. crbug.com/353038
94 if (window->IsVisible() &&
95 window->GetBoundsInScreen().Contains(screen_loc_)) {
96 toplevel_ = window;
97 return true;
98 }
99 return false;
100 }
101
102 if (ui::WindowContainsPoint(xid, screen_loc_)) {
103 // toplevel_ = NULL
104 return true;
105 }
106 return false;
107 }
108
109 gfx::Point screen_loc_;
110 aura::Window* toplevel_;
111
112 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowFinder);
113 };
114
115 } // namespace 68 } // namespace
116 69
117 namespace views { 70 namespace views {
118 71
119 //////////////////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////////////////
120 // DesktopScreenX11, public: 73 // DesktopScreenX11, public:
121 74
122 DesktopScreenX11::DesktopScreenX11() 75 DesktopScreenX11::DesktopScreenX11()
123 : xdisplay_(gfx::GetXDisplay()), 76 : xdisplay_(gfx::GetXDisplay()),
124 x_root_window_(DefaultRootWindow(xdisplay_)), 77 x_root_window_(DefaultRootWindow(xdisplay_)),
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 182
230 return gfx::Point(root_x, root_y); 183 return gfx::Point(root_x, root_y);
231 } 184 }
232 185
233 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() { 186 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() {
234 return GetWindowAtScreenPoint(GetCursorScreenPoint()); 187 return GetWindowAtScreenPoint(GetCursorScreenPoint());
235 } 188 }
236 189
237 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( 190 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint(
238 const gfx::Point& point) { 191 const gfx::Point& point) {
239 ToplevelWindowFinder finder; 192 X11TopmostWindowFinder finder;
240 return finder.FindAt(point); 193 return finder.FindLocalProcessWindowAt(point, std::set<aura::Window*>());
241 } 194 }
242 195
243 int DesktopScreenX11::GetNumDisplays() const { 196 int DesktopScreenX11::GetNumDisplays() const {
244 return displays_.size(); 197 return displays_.size();
245 } 198 }
246 199
247 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const { 200 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const {
248 return displays_; 201 return displays_;
249 } 202 }
250 203
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 ProcessDisplayChange(new_displays); 388 ProcessDisplayChange(new_displays);
436 } 389 }
437 390
438 //////////////////////////////////////////////////////////////////////////////// 391 ////////////////////////////////////////////////////////////////////////////////
439 392
440 gfx::Screen* CreateDesktopScreen() { 393 gfx::Screen* CreateDesktopScreen() {
441 return new DesktopScreenX11; 394 return new DesktopScreenX11;
442 } 395 }
443 396
444 } // namespace views 397 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698