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/base/gtk/gtk_screen_util.h" | 5 #include "ui/base/gtk/gtk_screen_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace ui { | 9 namespace ui { |
10 | 10 |
11 bool IsScreenComposited() { | 11 bool IsScreenComposited() { |
12 GdkScreen* screen = gdk_screen_get_default(); | 12 GdkScreen* screen = gdk_screen_get_default(); |
13 return gdk_screen_is_composited(screen) == TRUE; | 13 return gdk_screen_is_composited(screen) == TRUE; |
14 } | 14 } |
15 | 15 |
16 gfx::Point ScreenPoint(GtkWidget* widget) { | 16 gfx::Point ScreenPoint(GtkWidget* widget) { |
17 int x, y; | 17 int x, y; |
18 gdk_display_get_pointer(gtk_widget_get_display(widget), NULL, &x, &y, | 18 gdk_display_get_pointer(gtk_widget_get_display(widget), NULL, &x, &y, |
19 NULL); | 19 NULL); |
20 return gfx::Point(x, y); | 20 return gfx::Point(x, y); |
21 } | 21 } |
22 | 22 |
23 gfx::Point ClientPoint(GtkWidget* widget) { | 23 gfx::Point ClientPoint(GtkWidget* widget) { |
24 int x, y; | 24 int x, y; |
25 gtk_widget_get_pointer(widget, &x, &y); | 25 gtk_widget_get_pointer(widget, &x, &y); |
26 return gfx::Point(x, y); | 26 return gfx::Point(x, y); |
27 } | 27 } |
28 | 28 |
29 gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { | 29 gfx::Vector2d GetWidgetScreenOffset(GtkWidget* widget) { |
30 GdkWindow* window = gtk_widget_get_window(widget); | 30 GdkWindow* window = gtk_widget_get_window(widget); |
31 | 31 |
32 if (!window) { | 32 if (!window) { |
33 NOTREACHED() << "Must only be called on realized widgets."; | 33 NOTREACHED() << "Must only be called on realized widgets."; |
34 return gfx::Point(0, 0); | 34 return gfx::Vector2d(0, 0); |
35 } | 35 } |
36 | 36 |
37 gint x, y; | 37 gint x, y; |
38 gdk_window_get_origin(window, &x, &y); | 38 gdk_window_get_origin(window, &x, &y); |
39 | 39 |
40 if (!gtk_widget_get_has_window(widget)) { | 40 if (!gtk_widget_get_has_window(widget)) { |
41 GtkAllocation allocation; | 41 GtkAllocation allocation; |
42 gtk_widget_get_allocation(widget, &allocation); | 42 gtk_widget_get_allocation(widget, &allocation); |
43 x += allocation.x; | 43 x += allocation.x; |
44 y += allocation.y; | 44 y += allocation.y; |
45 } | 45 } |
46 | 46 |
47 return gfx::Point(x, y); | 47 return gfx::Vector2d(x, y); |
48 } | 48 } |
49 | 49 |
50 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { | 50 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { |
51 gfx::Point position = GetWidgetScreenPosition(widget); | 51 gfx::Point position = PointAtOffsetFromOrigin(GetWidgetScreenOffset(widget)); |
Peter Kasting
2012/10/30 01:14:14
Nit: Seems like we don't need to convert to a poin
danakj
2012/10/30 19:21:21
ya, the latter sounds nice. i had done that elsewh
| |
52 | 52 |
53 GtkAllocation allocation; | 53 GtkAllocation allocation; |
54 gtk_widget_get_allocation(widget, &allocation); | 54 gtk_widget_get_allocation(widget, &allocation); |
55 | 55 |
56 return gfx::Rect(position.x(), position.y(), | 56 return gfx::Rect(position.x(), position.y(), |
57 allocation.width, allocation.height); | 57 allocation.width, allocation.height); |
58 } | 58 } |
59 | 59 |
60 } // namespace ui | 60 } // namespace ui |
OLD | NEW |