Title: [106816] trunk/Source
Revision
106816
Author
[email protected]
Date
2012-02-06 09:59:27 -0800 (Mon, 06 Feb 2012)

Log Message

[GTK] WebKitWebView does a lot of work during size_allocate when not mapped
https://bugs.webkit.org/show_bug.cgi?id=77743

Patch by Martin Robinson <[email protected]> on 2012-02-06
Reviewed by Gustavo Noronha Silva.

Instead of resizing the guts of a WebView when it's not mapped, wait
until it's mapped and do one resize. This prevents unmapped WebViews
from adding to a container's resize cost.

Source/WebKit/gtk:

* webkit/webkitwebview.cpp:
(resizeWebViewFromAllocation): Abstracted out this helper.
(webkit_web_view_size_allocate): Wait until map to resize umapped widgets.
(webkitWebViewMap): Added this vmethod implementation.
(webkit_web_view_class_init): Added vmethod.
* webkit/webkitwebviewprivate.h: Added new needsResizeOnMap member.

Source/WebKit2:

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(_WebKitWebViewBasePrivate): Added a new member needsResizeOnMap.
(resizeWebKitWebViewBaseFromAllocation): Abstracted out this helper.
(webkitWebViewBaseSizeAllocate): Wait until map to resize unmapped WebViews.
(webkitWebViewBaseMap): Added this vmethod implementation.
(webkit_web_view_base_class_init): Added vmethod.

Modified Paths

Diff

Modified: trunk/Source/WebKit/gtk/ChangeLog (106815 => 106816)


--- trunk/Source/WebKit/gtk/ChangeLog	2012-02-06 17:49:59 UTC (rev 106815)
+++ trunk/Source/WebKit/gtk/ChangeLog	2012-02-06 17:59:27 UTC (rev 106816)
@@ -1,3 +1,21 @@
+2012-02-06  Martin Robinson  <[email protected]>
+
+        [GTK] WebKitWebView does a lot of work during size_allocate when not mapped
+        https://bugs.webkit.org/show_bug.cgi?id=77743
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Instead of resizing the guts of a WebView when it's not mapped, wait
+        until it's mapped and do one resize. This prevents unmapped WebViews
+        from adding to a container's resize cost.
+
+        * webkit/webkitwebview.cpp:
+        (resizeWebViewFromAllocation): Abstracted out this helper.
+        (webkit_web_view_size_allocate): Wait until map to resize umapped widgets.
+        (webkitWebViewMap): Added this vmethod implementation.
+        (webkit_web_view_class_init): Added vmethod.
+        * webkit/webkitwebviewprivate.h: Added new needsResizeOnMap member.
+
 2012-02-06  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Update NEWS and configure.ac for 1.7.5 release

Modified: trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp (106815 => 106816)


--- trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp	2012-02-06 17:49:59 UTC (rev 106815)
+++ trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp	2012-02-06 17:59:27 UTC (rev 106816)
@@ -859,18 +859,16 @@
     *allocation = IntRect();
 }
 
-static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
+static void resizeWebViewFromAllocation(WebKitWebView* webView, GtkAllocation* allocation)
 {
-    GTK_WIDGET_CLASS(webkit_web_view_parent_class)->size_allocate(widget, allocation);
-
-    Page* page = core(WEBKIT_WEB_VIEW(widget));
+    Page* page = core(webView);
     IntSize oldSize;
     if (FrameView* frameView = page->mainFrame()->view()) {
         oldSize = frameView->size();
         frameView->resize(allocation->width, allocation->height);
     }
 
-    gtk_container_forall(GTK_CONTAINER(widget), updateChildAllocationFromPendingAllocation, 0);
+    gtk_container_forall(GTK_CONTAINER(webView), updateChildAllocationFromPendingAllocation, 0);
 
     WebKit::ChromeClient* chromeClient = static_cast<WebKit::ChromeClient*>(page->chrome()->client());
     chromeClient->widgetSizeChanged(oldSize, IntSize(allocation->width, allocation->height));
@@ -881,6 +879,32 @@
 #endif
 }
 
+static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
+{
+    GTK_WIDGET_CLASS(webkit_web_view_parent_class)->size_allocate(widget, allocation);
+
+    WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
+    if (!gtk_widget_get_mapped(widget)) {
+        webView->priv->needsResizeOnMap = true;
+        return;
+    }
+    resizeWebViewFromAllocation(webView, allocation);
+}
+
+static void webkitWebViewMap(GtkWidget* widget)
+{
+    GTK_WIDGET_CLASS(webkit_web_view_parent_class)->map(widget);
+
+    WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
+    if (!webView->priv->needsResizeOnMap)
+        return;
+
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(widget, &allocation);
+    resizeWebViewFromAllocation(webView, &allocation);
+    webView->priv->needsResizeOnMap = false;
+}
+
 static void webkit_web_view_grab_focus(GtkWidget* widget)
 {
 
@@ -2767,6 +2791,7 @@
     widgetClass->query_tooltip = webkit_web_view_query_tooltip;
     widgetClass->show_help = webkit_web_view_show_help;
 #endif
+    widgetClass->map = webkitWebViewMap;
 
     GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webViewClass);
     containerClass->add = webkit_web_view_container_add;

Modified: trunk/Source/WebKit/gtk/webkit/webkitwebviewprivate.h (106815 => 106816)


--- trunk/Source/WebKit/gtk/webkit/webkitwebviewprivate.h	2012-02-06 17:49:59 UTC (rev 106815)
+++ trunk/Source/WebKit/gtk/webkit/webkitwebviewprivate.h	2012-02-06 17:59:27 UTC (rev 106816)
@@ -61,6 +61,7 @@
     GRefPtr<GtkIMContext> imContext;
 
     gboolean transparent;
+    bool needsResizeOnMap;
 
 #ifndef GTK_API_VERSION_2
     // GtkScrollablePolicy needs to be checked when

Modified: trunk/Source/WebKit2/ChangeLog (106815 => 106816)


--- trunk/Source/WebKit2/ChangeLog	2012-02-06 17:49:59 UTC (rev 106815)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-06 17:59:27 UTC (rev 106816)
@@ -1,3 +1,21 @@
+2012-02-06  Martin Robinson  <[email protected]>
+
+        [GTK] WebKitWebView does a lot of work during size_allocate when not mapped
+        https://bugs.webkit.org/show_bug.cgi?id=77743
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Instead of resizing the guts of a WebView when it's not mapped, wait
+        until it's mapped and do one resize. This prevents unmapped WebViews
+        from adding to a container's resize cost.
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (_WebKitWebViewBasePrivate): Added a new member needsResizeOnMap.
+        (resizeWebKitWebViewBaseFromAllocation): Abstracted out this helper.
+        (webkitWebViewBaseSizeAllocate): Wait until map to resize unmapped WebViews.
+        (webkitWebViewBaseMap): Added this vmethod implementation.
+        (webkit_web_view_base_class_init): Added vmethod.
+
 2012-02-06  Allan Sandfeld Jensen  <[email protected]>
 
         WebGestureEvent can not encode delta and area.

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp (106815 => 106816)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp	2012-02-06 17:49:59 UTC (rev 106815)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp	2012-02-06 17:59:27 UTC (rev 106816)
@@ -71,6 +71,7 @@
     DragIcon dragIcon;
     IntSize resizerSize;
     GRefPtr<AtkObject> accessible;
+    bool needsResizeOnMap;
 };
 
 G_DEFINE_TYPE(WebKitWebViewBase, webkit_web_view_base, GTK_TYPE_CONTAINER)
@@ -202,20 +203,43 @@
     return FALSE;
 }
 
+static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase, GtkAllocation* allocation)
+{
+    WebKitWebViewBasePrivate* priv = webViewBase->priv;
+
+    if (priv->pageProxy->drawingArea())
+        priv->pageProxy->drawingArea()->setSize(IntSize(allocation->width, allocation->height), IntSize());
+
+    GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(webViewBase));
+    if (widgetIsOnscreenToplevelWindow(toplevel))
+        webkitWebViewBaseNotifyResizerSizeForWindow(webViewBase, GTK_WINDOW(toplevel));
+}
+
 static void webkitWebViewBaseSizeAllocate(GtkWidget* widget, GtkAllocation* allocation)
 {
+    GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation);
+
     WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
-    WebKitWebViewBasePrivate* priv = webViewBase->priv;
+    if (!gtk_widget_get_mapped(GTK_WIDGET(webViewBase)) && !webViewBase->priv->pageProxy->drawingArea()->size().isEmpty()) {
+        webViewBase->priv->needsResizeOnMap = true;
+        return;
+    }
+    resizeWebKitWebViewBaseFromAllocation(webViewBase, allocation);
+}
 
-    if (!priv->pageProxy->drawingArea())
+static void webkitWebViewBaseMap(GtkWidget* widget)
+{
+    GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->map(widget);
+
+    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
+    if (!webViewBase->priv->needsResizeOnMap)
         return;
 
-    GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation);
-    priv->pageProxy->drawingArea()->setSize(IntSize(allocation->width, allocation->height), IntSize());
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(widget, &allocation);
+    resizeWebKitWebViewBaseFromAllocation(webViewBase, &allocation);
+    webViewBase->priv->needsResizeOnMap = false;
 
-    GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
-    if (widgetIsOnscreenToplevelWindow(toplevel))
-        webkitWebViewBaseNotifyResizerSizeForWindow(webViewBase, GTK_WINDOW(toplevel));
 }
 
 static gboolean webkitWebViewBaseFocusInEvent(GtkWidget* widget, GdkEventFocus* event)
@@ -454,6 +478,7 @@
     widgetClass->realize = webkitWebViewBaseRealize;
     widgetClass->draw = webkitWebViewBaseDraw;
     widgetClass->size_allocate = webkitWebViewBaseSizeAllocate;
+    widgetClass->map = webkitWebViewBaseMap;
     widgetClass->focus_in_event = webkitWebViewBaseFocusInEvent;
     widgetClass->focus_out_event = webkitWebViewBaseFocusOutEvent;
     widgetClass->key_press_event = webkitWebViewBaseKeyPressEvent;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to