2008-12-11 Robert Carr <racarr@svn.gnome.org>
Reviewed by Holger Freyther.
https://bugs.webkit.org/show_bug.cgi?id=22560
Code in PlatformScreenGtk for screenDepth and screenRect can not
assume that the platformWindow for the widget has a valid "window"
member. For example in the case of, a new browser view opening as a
child of a GtkNotebook, but never being switched to, or manually
realized. Solve by using the toplevel window of the widget, rather
than the widget itself.
* platform/gtk/PlatformScreenGtk.cpp:
(WebCore::screenDepth):
(WebCore::screenRect):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@39203 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/platform/gtk/PlatformScreenGtk.cpp b/WebCore/platform/gtk/PlatformScreenGtk.cpp
index 9788253..3512be1 100644
--- a/WebCore/platform/gtk/PlatformScreenGtk.cpp
+++ b/WebCore/platform/gtk/PlatformScreenGtk.cpp
@@ -47,10 +47,20 @@
int screenDepth(Widget* widget)
{
GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformWindow());
+
if (!container)
return 24;
- GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->root()->hostWindow()->platformWindow())->window));
+ if (!GTK_WIDGET_REALIZED(container)) {
+ GtkWidget* toplevel = gtk_widget_get_toplevel(container);
+ if (GTK_WIDGET_TOPLEVEL(toplevel))
+ container = toplevel;
+ else
+ return 24;
+ }
+
+
+ GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(container->window));
return visual->depth;
}
@@ -75,8 +85,8 @@
FloatRect screenRect(Widget* widget)
{
- GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformWindow());
- if (!container)
+ GtkWidget* container = gtk_widget_get_toplevel(GTK_WIDGET(widget->root()->hostWindow()->platformWindow()));
+ if (!GTK_WIDGET_TOPLEVEL(container))
return FloatRect();
GdkScreen* screen = gtk_widget_has_screen(container) ? gtk_widget_get_screen(container) : gdk_screen_get_default();