Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/x11_topmost_window_finder.h" | 5 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
| 6 | 6 |
| 7 #include <X11/Xutil.h> | 7 #include <X11/Xutil.h> |
| 8 | 8 |
| 9 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/gfx/screen.h" | |
| 11 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 12 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 12 | 13 |
| 13 namespace views { | 14 namespace views { |
| 14 | 15 |
| 16 float GetDeviceScaleFactor() { | |
| 17 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
| 18 return display.device_scale_factor(); | |
| 19 } | |
| 20 | |
| 21 gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { | |
| 22 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); | |
| 23 } | |
| 24 | |
| 25 gfx::Point DIPToScreenPoint(const gfx::Point& dip_point) { | |
| 26 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); | |
| 27 } | |
| 28 | |
| 15 X11TopmostWindowFinder::X11TopmostWindowFinder() : toplevel_(None) { | 29 X11TopmostWindowFinder::X11TopmostWindowFinder() : toplevel_(None) { |
| 16 } | 30 } |
| 17 | 31 |
| 18 X11TopmostWindowFinder::~X11TopmostWindowFinder() { | 32 X11TopmostWindowFinder::~X11TopmostWindowFinder() { |
| 19 } | 33 } |
| 20 | 34 |
| 21 aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt( | 35 aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt( |
| 22 const gfx::Point& screen_loc, | 36 const gfx::Point& screen_loc, |
| 23 const std::set<aura::Window*>& ignore) { | 37 const std::set<aura::Window*>& ignore) { |
| 24 screen_loc_ = screen_loc; | 38 screen_loc_ = DIPToScreenPoint(screen_loc); |
| 25 ignore_ = ignore; | 39 ignore_ = ignore; |
| 26 | 40 |
| 27 std::vector<aura::Window*> local_process_windows = | 41 std::vector<aura::Window*> local_process_windows = |
| 28 DesktopWindowTreeHostX11::GetAllOpenWindows(); | 42 DesktopWindowTreeHostX11::GetAllOpenWindows(); |
| 29 bool found_local_process_window = false; | 43 bool found_local_process_window = false; |
| 30 for (size_t i = 0; i < local_process_windows.size(); ++i) { | 44 for (size_t i = 0; i < local_process_windows.size(); ++i) { |
| 31 if (ShouldStopIteratingAtLocalProcessWindow(local_process_windows[i])) { | 45 if (ShouldStopIteratingAtLocalProcessWindow(local_process_windows[i])) { |
| 32 found_local_process_window = true; | 46 found_local_process_window = true; |
| 33 break; | 47 break; |
| 34 } | 48 } |
| 35 } | 49 } |
| 36 if (!found_local_process_window) | 50 if (!found_local_process_window) |
| 37 return NULL; | 51 return NULL; |
| 38 | 52 |
| 39 ui::EnumerateTopLevelWindows(this); | 53 ui::EnumerateTopLevelWindows(this); |
| 40 return DesktopWindowTreeHostX11::GetContentWindowForXID(toplevel_); | 54 return DesktopWindowTreeHostX11::GetContentWindowForXID(toplevel_); |
| 41 } | 55 } |
| 42 | 56 |
| 43 XID X11TopmostWindowFinder::FindWindowAt(const gfx::Point& screen_loc) { | 57 XID X11TopmostWindowFinder::FindWindowAt(const gfx::Point& screen_loc) { |
| 44 screen_loc_ = screen_loc; | 58 screen_loc_ = DIPToScreenPoint(screen_loc); |
|
sadrul
2015/03/17 15:56:06
From some of the callsites, the |screen_loc| looks
stapelberg
2015/03/19 08:25:44
You’re right. Reverted that part of the change.
| |
| 45 ui::EnumerateTopLevelWindows(this); | 59 ui::EnumerateTopLevelWindows(this); |
| 46 return toplevel_; | 60 return toplevel_; |
| 47 } | 61 } |
| 48 | 62 |
| 49 bool X11TopmostWindowFinder::ShouldStopIterating(XID xid) { | 63 bool X11TopmostWindowFinder::ShouldStopIterating(XID xid) { |
| 50 if (!ui::IsWindowVisible(xid)) | 64 if (!ui::IsWindowVisible(xid)) |
| 51 return false; | 65 return false; |
| 52 | 66 |
| 53 aura::Window* window = | 67 aura::Window* window = |
| 54 views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid); | 68 views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 return true; | 102 return true; |
| 89 | 103 |
| 90 aura::client::ScreenPositionClient* screen_position_client = | 104 aura::client::ScreenPositionClient* screen_position_client = |
| 91 aura::client::GetScreenPositionClient(window->GetRootWindow()); | 105 aura::client::GetScreenPositionClient(window->GetRootWindow()); |
| 92 gfx::Point window_loc(screen_loc_); | 106 gfx::Point window_loc(screen_loc_); |
| 93 screen_position_client->ConvertPointFromScreen(window, &window_loc); | 107 screen_position_client->ConvertPointFromScreen(window, &window_loc); |
| 94 return XPointInRegion(shape, window_loc.x(), window_loc.y()) == True; | 108 return XPointInRegion(shape, window_loc.x(), window_loc.y()) == True; |
| 95 } | 109 } |
| 96 | 110 |
| 97 } // namespace views | 111 } // namespace views |
| OLD | NEW |