OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/widget/widget_gtk.h" | 5 #include "views/widget/widget_gtk.h" |
6 | 6 |
7 #include "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
8 #include "app/gfx/path.h" | 8 #include "app/gfx/path.h" |
9 #include "app/os_exchange_data.h" | 9 #include "app/os_exchange_data.h" |
10 #include "app/os_exchange_data_provider_gtk.h" | 10 #include "app/os_exchange_data_provider_gtk.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 static const char* kWidgetKey = "__VIEWS_WIDGET__"; | 59 static const char* kWidgetKey = "__VIEWS_WIDGET__"; |
60 static const wchar_t* kWidgetWideKey = L"__VIEWS_WIDGET__"; | 60 static const wchar_t* kWidgetWideKey = L"__VIEWS_WIDGET__"; |
61 | 61 |
62 // Returns the position of a widget on screen. | 62 // Returns the position of a widget on screen. |
63 static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) { | 63 static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) { |
64 // First get the root window. | 64 // First get the root window. |
65 GtkWidget* root = widget; | 65 GtkWidget* root = widget; |
66 while (root && !GTK_IS_WINDOW(root)) { | 66 while (root && !GTK_IS_WINDOW(root)) { |
67 root = gtk_widget_get_parent(root); | 67 root = gtk_widget_get_parent(root); |
68 } | 68 } |
69 DCHECK(root); | 69 if (!root) { |
| 70 // If root is null we're not parented. Return 0x0 and assume the caller will |
| 71 // query again when we're parented. |
| 72 *x = *y = 0; |
| 73 return; |
| 74 } |
70 // Translate the coordinate from widget to root window. | 75 // Translate the coordinate from widget to root window. |
71 gtk_widget_translate_coordinates(widget, root, 0, 0, x, y); | 76 gtk_widget_translate_coordinates(widget, root, 0, 0, x, y); |
72 // Then adjust the position with the position of the root window. | 77 // Then adjust the position with the position of the root window. |
73 int window_x, window_y; | 78 int window_x, window_y; |
74 gtk_window_get_position(GTK_WINDOW(root), &window_x, &window_y); | 79 gtk_window_get_position(GTK_WINDOW(root), &window_x, &window_y); |
75 *x += window_x; | 80 *x += window_x; |
76 *y += window_y; | 81 *y += window_y; |
77 } | 82 } |
78 | 83 |
79 // static | 84 // static |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1369 |
1365 // static | 1370 // static |
1366 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { | 1371 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { |
1367 gpointer raw_widget = g_object_get_data(G_OBJECT(native_window), kWidgetKey); | 1372 gpointer raw_widget = g_object_get_data(G_OBJECT(native_window), kWidgetKey); |
1368 if (raw_widget) | 1373 if (raw_widget) |
1369 return reinterpret_cast<Widget*>(raw_widget); | 1374 return reinterpret_cast<Widget*>(raw_widget); |
1370 return NULL; | 1375 return NULL; |
1371 } | 1376 } |
1372 | 1377 |
1373 } // namespace views | 1378 } // namespace views |
OLD | NEW |