Chromium Code Reviews| Index: ui/base/x/x11_util.cc |
| diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc |
| index 8a1d5e6697e46b61d9d2641c9a7e6c5e9973dda1..d47a7b71a49302240646f2a8872e0a61f831dee8 100644 |
| --- a/ui/base/x/x11_util.cc |
| +++ b/ui/base/x/x11_util.cc |
| @@ -19,6 +19,7 @@ |
| #include <X11/extensions/Xrandr.h> |
| #include <X11/extensions/randr.h> |
| +#include <X11/extensions/shape.h> |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| @@ -612,6 +613,44 @@ bool GetWindowRect(XID window, gfx::Rect* rect) { |
| return true; |
| } |
| + |
| +bool WindowContainsPoint(XID window, gfx::Point screen_loc) { |
| + gfx::Rect window_rect; |
| + if (!GetWindowRect(window, &window_rect)) |
| + return false; |
| + |
| + if (!window_rect.Contains(screen_loc)) |
| + return false; |
| + |
| + // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, |
| + // if an X display supports the shape extension the bounds of a window are |
| + // defined as the intersection of the window bounds and the interior |
| + // rectangles. This means to determine if a point is inside a window for the |
| + // purpose of input handling we have to check the rectangles in the ShapeInput |
| + // list. |
| + int dummy; |
| + if (XShapeQueryExtension(ui::GetXDisplay(), &dummy, &dummy)) { |
|
sadrul
2012/09/24 23:39:24
It would make sense to cache the return value of X
|
| + int input_rects_size = 0; |
| + XRectangle* input_rects = XShapeGetRectangles( |
| + ui::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy); |
| + bool is_in_input_rects = false; |
| + for (int i = 0; i < input_rects_size; ++i) { |
| + gfx::Rect input_rect = |
| + gfx::Rect(input_rects[i].x, input_rects[i].y, |
| + input_rects[i].width, input_rects[i].height); |
| + if (input_rect.Contains(screen_loc)) { |
| + is_in_input_rects = true; |
| + break; |
| + } |
| + } |
|
Elliot Glaysher
2012/09/24 23:35:05
You'll need an XFree(input_rects); here.
|
| + if (!is_in_input_rects) |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| + |
| bool PropertyExists(XID window, const std::string& property_name) { |
| Atom type = None; |
| int format = 0; // size in bits of each item in 'property' |