OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (!gfx::Display::HasForceDeviceScaleFactor() && | 56 if (!gfx::Display::HasForceDeviceScaleFactor() && |
57 !ui::IsXDisplaySizeBlackListed(mm_width, mm_height)) { | 57 !ui::IsXDisplaySizeBlackListed(mm_width, mm_height)) { |
58 float device_scale_factor = GetDeviceScaleFactor(width, mm_width); | 58 float device_scale_factor = GetDeviceScaleFactor(width, mm_width); |
59 DCHECK_LE(1.0f, device_scale_factor); | 59 DCHECK_LE(1.0f, device_scale_factor); |
60 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); | 60 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); |
61 } | 61 } |
62 | 62 |
63 return std::vector<gfx::Display>(1, gfx_display); | 63 return std::vector<gfx::Display>(1, gfx_display); |
64 } | 64 } |
65 | 65 |
| 66 // Helper class to GetWindowAtScreenPoint() which returns the topmost window at |
| 67 // the location passed to FindAt(). NULL is returned if a window which does not |
| 68 // belong to Chromium is topmost at the passed in location. |
| 69 class ToplevelWindowFinder : public ui::EnumerateWindowsDelegate { |
| 70 public: |
| 71 ToplevelWindowFinder() : toplevel_(NULL) { |
| 72 } |
| 73 |
| 74 virtual ~ToplevelWindowFinder() { |
| 75 } |
| 76 |
| 77 aura::Window* FindAt(const gfx::Point& screen_loc) { |
| 78 screen_loc_ = screen_loc; |
| 79 ui::EnumerateTopLevelWindows(this); |
| 80 return toplevel_; |
| 81 } |
| 82 |
| 83 protected: |
| 84 virtual bool ShouldStopIterating(XID xid) OVERRIDE { |
| 85 aura::Window* window = |
| 86 views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid); |
| 87 if (window) { |
| 88 if (window->IsVisible() && |
| 89 window->GetBoundsInScreen().Contains(screen_loc_)) { |
| 90 toplevel_ = window; |
| 91 return true; |
| 92 } |
| 93 return false; |
| 94 } |
| 95 |
| 96 if (ui::IsWindowVisible(xid) && |
| 97 ui::WindowContainsPoint(xid, screen_loc_)) { |
| 98 // toplevel_ = NULL |
| 99 return true; |
| 100 } |
| 101 return false; |
| 102 } |
| 103 |
| 104 gfx::Point screen_loc_; |
| 105 aura::Window* toplevel_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowFinder); |
| 108 }; |
| 109 |
66 } // namespace | 110 } // namespace |
67 | 111 |
68 namespace views { | 112 namespace views { |
69 | 113 |
70 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
71 // DesktopScreenX11, public: | 115 // DesktopScreenX11, public: |
72 | 116 |
73 DesktopScreenX11::DesktopScreenX11() | 117 DesktopScreenX11::DesktopScreenX11() |
74 : xdisplay_(base::MessagePumpX11::GetDefaultXDisplay()), | 118 : xdisplay_(base::MessagePumpX11::GetDefaultXDisplay()), |
75 x_root_window_(DefaultRootWindow(xdisplay_)), | 119 x_root_window_(DefaultRootWindow(xdisplay_)), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 219 |
176 return gfx::Point(root_x, root_y); | 220 return gfx::Point(root_x, root_y); |
177 } | 221 } |
178 | 222 |
179 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() { | 223 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() { |
180 return GetWindowAtScreenPoint(GetCursorScreenPoint()); | 224 return GetWindowAtScreenPoint(GetCursorScreenPoint()); |
181 } | 225 } |
182 | 226 |
183 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( | 227 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( |
184 const gfx::Point& point) { | 228 const gfx::Point& point) { |
185 std::vector<aura::Window*> windows = | 229 ToplevelWindowFinder finder; |
186 DesktopWindowTreeHostX11::GetAllOpenWindows(); | 230 return finder.FindAt(point); |
187 | |
188 for (std::vector<aura::Window*>::const_iterator it = windows.begin(); | |
189 it != windows.end(); ++it) { | |
190 if ((*it)->GetBoundsInScreen().Contains(point)) | |
191 return *it; | |
192 } | |
193 | |
194 return NULL; | |
195 } | 231 } |
196 | 232 |
197 int DesktopScreenX11::GetNumDisplays() const { | 233 int DesktopScreenX11::GetNumDisplays() const { |
198 return displays_.size(); | 234 return displays_.size(); |
199 } | 235 } |
200 | 236 |
201 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const { | 237 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const { |
202 return displays_; | 238 return displays_; |
203 } | 239 } |
204 | 240 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 ProcessDisplayChange(new_displays); | 418 ProcessDisplayChange(new_displays); |
383 } | 419 } |
384 | 420 |
385 //////////////////////////////////////////////////////////////////////////////// | 421 //////////////////////////////////////////////////////////////////////////////// |
386 | 422 |
387 gfx::Screen* CreateDesktopScreen() { | 423 gfx::Screen* CreateDesktopScreen() { |
388 return new DesktopScreenX11; | 424 return new DesktopScreenX11; |
389 } | 425 } |
390 | 426 |
391 } // namespace views | 427 } // namespace views |
OLD | NEW |