summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/gtk_util.cc18
-rw-r--r--chrome/common/gtk_util.h3
2 files changed, 21 insertions, 0 deletions
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index 1a07831..1a89b9b 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -257,4 +257,22 @@ int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds) {
return widget->allocation.width - bounds.x() - bounds.width();
}
+bool WidgetContainsCursor(GtkWidget* widget) {
+ gint x = 0;
+ gint y = 0;
+ gtk_widget_get_pointer(widget, &x, &y);
+
+ // To quote the gtk docs:
+ //
+ // Widget coordinates are a bit odd; for historical reasons, they are
+ // defined as widget->window coordinates for widgets that are not
+ // GTK_NO_WINDOW widgets, and are relative to widget->allocation.x,
+ // widget->allocation.y for widgets that are GTK_NO_WINDOW widgets.
+ //
+ // So the base is always (0,0).
+ gfx::Rect widget_allocation(0, 0, widget->allocation.width,
+ widget->allocation.height);
+ return widget_allocation.Contains(x, y);
+}
+
} // namespace gtk_util
diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h
index a8aa205..e4e7da3 100644
--- a/chrome/common/gtk_util.h
+++ b/chrome/common/gtk_util.h
@@ -101,6 +101,9 @@ void SetButtonTriggersNavigation(GtkWidget* button);
// the original value is returned unchanged.
int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds);
+// Returns true if the pointer is currently inside the widget.
+bool WidgetContainsCursor(GtkWidget* widget);
+
} // namespace gtk_util
#endif // CHROME_COMMON_GTK_UTIL_H_