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 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 } | 829 } |
830 | 830 |
831 void WidgetGtk::ReleaseGrab() { | 831 void WidgetGtk::ReleaseGrab() { |
832 if (has_capture_) { | 832 if (has_capture_) { |
833 has_capture_ = false; | 833 has_capture_ = false; |
834 gtk_grab_remove(window_contents_); | 834 gtk_grab_remove(window_contents_); |
835 } | 835 } |
836 } | 836 } |
837 | 837 |
838 // static | 838 // static |
| 839 RootView* WidgetGtk::GetRootViewForWidget(GtkWidget* widget) { |
| 840 gpointer user_data = g_object_get_data(G_OBJECT(widget), "root-view"); |
| 841 return static_cast<RootView*>(user_data); |
| 842 } |
| 843 |
| 844 // static |
839 int WidgetGtk::GetFlagsForEventButton(const GdkEventButton& event) { | 845 int WidgetGtk::GetFlagsForEventButton(const GdkEventButton& event) { |
840 int flags = Event::GetFlagsFromGdkState(event.state); | 846 int flags = Event::GetFlagsFromGdkState(event.state); |
841 switch (event.button) { | 847 switch (event.button) { |
842 case 1: | 848 case 1: |
843 flags |= Event::EF_LEFT_BUTTON_DOWN; | 849 flags |= Event::EF_LEFT_BUTTON_DOWN; |
844 break; | 850 break; |
845 case 2: | 851 case 2: |
846 flags |= Event::EF_MIDDLE_BUTTON_DOWN; | 852 flags |= Event::EF_MIDDLE_BUTTON_DOWN; |
847 break; | 853 break; |
848 case 3: | 854 case 3: |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 ignore_drag_leave_ = false; | 947 ignore_drag_leave_ = false; |
942 drop_target_.reset(NULL); | 948 drop_target_.reset(NULL); |
943 } | 949 } |
944 | 950 |
945 // static | 951 // static |
946 void WidgetGtk::SetViewForNative(GtkWidget* widget, WidgetGtk* view) { | 952 void WidgetGtk::SetViewForNative(GtkWidget* widget, WidgetGtk* view) { |
947 g_object_set_data(G_OBJECT(widget), "chrome-views", view); | 953 g_object_set_data(G_OBJECT(widget), "chrome-views", view); |
948 } | 954 } |
949 | 955 |
950 // static | 956 // static |
951 RootView* WidgetGtk::GetRootViewForWidget(GtkWidget* widget) { | |
952 gpointer user_data = g_object_get_data(G_OBJECT(widget), "root-view"); | |
953 return static_cast<RootView*>(user_data); | |
954 } | |
955 | |
956 // static | |
957 void WidgetGtk::SetRootViewForWidget(GtkWidget* widget, RootView* root_view) { | 957 void WidgetGtk::SetRootViewForWidget(GtkWidget* widget, RootView* root_view) { |
958 g_object_set_data(G_OBJECT(widget), "root-view", root_view); | 958 g_object_set_data(G_OBJECT(widget), "root-view", root_view); |
959 } | 959 } |
960 | 960 |
961 // static | 961 // static |
962 void WidgetGtk::CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { | 962 void WidgetGtk::CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { |
963 WidgetGtk* widget_gtk = GetViewForNative(widget); | 963 WidgetGtk* widget_gtk = GetViewForNative(widget); |
964 if (!widget_gtk) | 964 if (!widget_gtk) |
965 return; | 965 return; |
966 | 966 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 Widget* Widget::CreatePopupWidget(TransparencyParam transparent, | 1229 Widget* Widget::CreatePopupWidget(TransparencyParam transparent, |
1230 EventsParam /*accept_events*/, | 1230 EventsParam /*accept_events*/, |
1231 DeleteParam delete_on_destroy) { | 1231 DeleteParam delete_on_destroy) { |
1232 WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP); | 1232 WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP); |
1233 popup->set_delete_on_destroy(delete_on_destroy == DeleteOnDestroy); | 1233 popup->set_delete_on_destroy(delete_on_destroy == DeleteOnDestroy); |
1234 if (transparent == Transparent) | 1234 if (transparent == Transparent) |
1235 popup->MakeTransparent(); | 1235 popup->MakeTransparent(); |
1236 return popup; | 1236 return popup; |
1237 } | 1237 } |
1238 | 1238 |
| 1239 // Callback from gtk_container_foreach. Locates the first root view of widget |
| 1240 // or one of it's descendants. |
| 1241 static void RootViewLocatorCallback(GtkWidget* widget, |
| 1242 gpointer root_view_p) { |
| 1243 RootView** root_view = static_cast<RootView**>(root_view_p); |
| 1244 if (!*root_view) { |
| 1245 *root_view = WidgetGtk::GetRootViewForWidget(widget); |
| 1246 if (!*root_view && GTK_IS_CONTAINER(widget)) { |
| 1247 // gtk_container_foreach only iterates over children, not all descendants, |
| 1248 // so we have to recurse here to get all descendants. |
| 1249 gtk_container_foreach(GTK_CONTAINER(widget), RootViewLocatorCallback, |
| 1250 root_view_p); |
| 1251 } |
| 1252 } |
| 1253 } |
| 1254 |
| 1255 // static |
| 1256 RootView* Widget::FindRootView(GtkWindow* window) { |
| 1257 RootView* root_view = WidgetGtk::GetRootViewForWidget(GTK_WIDGET(window)); |
| 1258 if (root_view) |
| 1259 return root_view; |
| 1260 |
| 1261 // Enumerate all children and check if they have a RootView. |
| 1262 gtk_container_foreach(GTK_CONTAINER(window), RootViewLocatorCallback, |
| 1263 static_cast<gpointer>(&root_view)); |
| 1264 return root_view; |
| 1265 } |
| 1266 |
1239 } // namespace views | 1267 } // namespace views |
OLD | NEW |