diff options
Diffstat (limited to 'views')
-rw-r--r-- | views/widget/widget.h | 5 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 40 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 4 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 46 |
4 files changed, 65 insertions, 30 deletions
diff --git a/views/widget/widget.h b/views/widget/widget.h index 05e475b..7b08737 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -63,6 +63,11 @@ class Widget { EventsParam accept_events, DeleteParam delete_on_destroy); + // Returns the root view for |native_window|. If |native_window| does not have + // a rootview, this recurses through all of |native_window|'s children until + // one is found. If a root view isn't found, null is returned. + static RootView* FindRootView(gfx::NativeWindow native_window); + // Initialize the Widget with a parent and an initial desired size. // |contents_view| is the view that will be the single child of RootView // within this Widget. As contents_view is inserted into RootView's tree, diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index cee2886..4557286 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -836,6 +836,12 @@ void WidgetGtk::ReleaseGrab() { } // static +RootView* WidgetGtk::GetRootViewForWidget(GtkWidget* widget) { + gpointer user_data = g_object_get_data(G_OBJECT(widget), "root-view"); + return static_cast<RootView*>(user_data); +} + +// static int WidgetGtk::GetFlagsForEventButton(const GdkEventButton& event) { int flags = Event::GetFlagsFromGdkState(event.state); switch (event.button) { @@ -948,12 +954,6 @@ void WidgetGtk::SetViewForNative(GtkWidget* widget, WidgetGtk* view) { } // static -RootView* WidgetGtk::GetRootViewForWidget(GtkWidget* widget) { - gpointer user_data = g_object_get_data(G_OBJECT(widget), "root-view"); - return static_cast<RootView*>(user_data); -} - -// static void WidgetGtk::SetRootViewForWidget(GtkWidget* widget, RootView* root_view) { g_object_set_data(G_OBJECT(widget), "root-view", root_view); } @@ -1236,4 +1236,32 @@ Widget* Widget::CreatePopupWidget(TransparencyParam transparent, return popup; } +// Callback from gtk_container_foreach. Locates the first root view of widget +// or one of it's descendants. +static void RootViewLocatorCallback(GtkWidget* widget, + gpointer root_view_p) { + RootView** root_view = static_cast<RootView**>(root_view_p); + if (!*root_view) { + *root_view = WidgetGtk::GetRootViewForWidget(widget); + if (!*root_view && GTK_IS_CONTAINER(widget)) { + // gtk_container_foreach only iterates over children, not all descendants, + // so we have to recurse here to get all descendants. + gtk_container_foreach(GTK_CONTAINER(widget), RootViewLocatorCallback, + root_view_p); + } + } +} + +// static +RootView* Widget::FindRootView(GtkWindow* window) { + RootView* root_view = WidgetGtk::GetRootViewForWidget(GTK_WIDGET(window)); + if (root_view) + return root_view; + + // Enumerate all children and check if they have a RootView. + gtk_container_foreach(GTK_CONTAINER(window), RootViewLocatorCallback, + static_cast<gpointer>(&root_view)); + return root_view; +} + } // namespace views diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 0e2f818..e97f58e 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -170,6 +170,9 @@ class WidgetGtk // drop is done. void ResetDropTarget(); + // Returns the RootView for |widget|. + static RootView* GetRootViewForWidget(GtkWidget* widget); + protected: // Returns the view::Event::flags for a GdkEventButton. static int GetFlagsForEventButton(const GdkEventButton& event); @@ -259,7 +262,6 @@ class WidgetGtk // Sets the WidgetGtk in the userdata section of the widget. static void SetViewForNative(GtkWidget* widget, WidgetGtk* view); - static RootView* GetRootViewForWidget(GtkWidget* widget); static void SetRootViewForWidget(GtkWidget* widget, RootView* root_view); // A set of static signal handlers that bridge diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index b883edd..e0edee8 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -362,29 +362,6 @@ void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { } } -static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { - RootView* root_view = - reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); - if (root_view) { - *reinterpret_cast<RootView**>(l_param) = root_view; - return FALSE; // Stop enumerating. - } - return TRUE; // Keep enumerating. -} - -// static -RootView* WidgetWin::FindRootView(HWND hwnd) { - RootView* root_view = - reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); - if (root_view) - return root_view; - - // Enumerate all children and check if they have a RootView. - EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); - - return root_view; -} - // static WidgetWin* WidgetWin::GetWidget(HWND hwnd) { return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd)); @@ -1184,4 +1161,27 @@ Widget* Widget::CreatePopupWidget(TransparencyParam transparent, return popup; } +static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { + RootView* root_view = + reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); + if (root_view) { + *reinterpret_cast<RootView**>(l_param) = root_view; + return FALSE; // Stop enumerating. + } + return TRUE; // Keep enumerating. +} + +// static +RootView* Widget::FindRootView(HWND hwnd) { + RootView* root_view = + reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); + if (root_view) + return root_view; + + // Enumerate all children and check if they have a RootView. + EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); + + return root_view; +} + } // namespace views |