⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278301 in webkit


Ignore:
Timestamp:
Jun 1, 2021, 4:59:21 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Try harder to find initial WebKitWebView size
https://bugs.webkit.org/show_bug.cgi?id=226320

Patch by Alexander Mikhaylenko <Alexander Mikhaylenko> on 2021-06-01
Reviewed by Michael Catanzaro.

Currently we base the viewport size on the drawing area size. The
drawing area is created with an initial size based on the viewport
size, which will be (0, 0) because the drawing area is still null
by that point.

Then, later, during the widget allocation, the drawing area receives
its proper size.

There are 2 issues here. First, this approach guarantees that the
initial viewport size will always be (0, 0), and then there's no
guarantee the widget will be allocated any time soon - for example,
while GtkNotebook in GTK3 does allocate children that aren't currently
visible, GtkStack doesn't (and that means that GtkNotebook in GTK4 and
HdyTabView don't either). This leads to a situation where a page opened
in background will load with 0, 0 size and if a page depends on that,
it won't load correctly.

The first issue can be fixed by basing the viewport size on the view
allocation as well, and then if the widget isn't allocated, we instead
try to use the size of a parent as an estimation, so that the initial
size is at least not 0 even if not fully accurate.

See https://gitlab.gnome.org/GNOME/epiphany/-/issues/1532

  • UIProcess/API/gtk/PageClientImpl.cpp:

(WebKit::PageClientImpl::viewSize):

  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseGetViewSize):

  • UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r278258 r278301  
     12021-06-01  Alexander Mikhaylenko  <alexm@gnome.org>
     2
     3        [GTK] Try harder to find initial WebKitWebView size
     4        https://bugs.webkit.org/show_bug.cgi?id=226320
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Currently we base the viewport size on the drawing area size. The
     9        drawing area is created with an initial size based on the viewport
     10        size, which will be (0, 0) because the drawing area is still null
     11        by that point.
     12
     13        Then, later, during the widget allocation, the drawing area receives
     14        its proper size.
     15
     16        There are 2 issues here. First, this approach guarantees that the
     17        initial viewport size will always be (0, 0), and then there's no
     18        guarantee the widget will be allocated any time soon - for example,
     19        while GtkNotebook in GTK3 does allocate children that aren't currently
     20        visible, GtkStack doesn't (and that means that GtkNotebook in GTK4 and
     21        HdyTabView don't either). This leads to a situation where a page opened
     22        in background will load with 0, 0 size and if a page depends on that,
     23        it won't load correctly.
     24
     25        The first issue can be fixed by basing the viewport size on the view
     26        allocation as well, and then if the widget isn't allocated, we instead
     27        try to use the size of a parent as an estimation, so that the initial
     28        size is at least not 0 even if not fully accurate.
     29
     30        See https://gitlab.gnome.org/GNOME/epiphany/-/issues/1532
     31
     32        * UIProcess/API/gtk/PageClientImpl.cpp:
     33        (WebKit::PageClientImpl::viewSize):
     34        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     35        (webkitWebViewBaseGetViewSize):
     36        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
     37
    1382021-05-30  Dean Jackson  <dino@apple.com>
    239
  • trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp

    r278253 r278301  
    104104WebCore::IntSize PageClientImpl::viewSize()
    105105{
    106     auto* drawingArea = static_cast<DrawingAreaProxyCoordinatedGraphics*>(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_viewWidget))->drawingArea());
    107     return drawingArea ? drawingArea->size() : IntSize();
     106    return webkitWebViewBaseGetViewSize(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
    108107}
    109108
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r278253 r278301  
    264264    std::unique_ptr<PageClientImpl> pageClient;
    265265    RefPtr<WebPageProxy> pageProxy;
     266    IntSize viewSize { };
    266267    bool shouldForwardNextKeyEvent { false };
    267268    bool shouldForwardNextWheelEvent { false };
     
    892893#endif
    893894
     895    priv->viewSize = viewRect.size();
     896
    894897    if (auto* drawingArea = static_cast<DrawingAreaProxyCoordinatedGraphics*>(priv->pageProxy->drawingArea()))
    895         drawingArea->setSize(viewRect.size());
     898        drawingArea->setSize(priv->viewSize);
    896899}
    897900
     
    23612364
    23622365    webkitWebViewBaseScheduleUpdateActivityState(webViewBase, flagsToUpdate);
     2366}
     2367
     2368IntSize webkitWebViewBaseGetViewSize(WebKitWebViewBase* webViewBase)
     2369{
     2370    WebKitWebViewBasePrivate* priv = webViewBase->priv;
     2371    int width = priv->viewSize.width();
     2372    int height = priv->viewSize.height();
     2373
     2374    // First try the widget's own size. If it's already allocated,
     2375    // everything is fine and we'll just use that.
     2376    if (width > 0 || height > 0)
     2377        return IntSize(width, height);
     2378
     2379    GtkWidget* parent = gtk_widget_get_parent(GTK_WIDGET(webViewBase));
     2380
     2381    // If it's not allocated, then its size will be 0. This can be a problem
     2382    // if the web view is loaded in background and the container doesn't
     2383    // allocate non-visible children: e.g. GtkNotebook in GTK3 does allocate
     2384    // them, but GtkStack, and so GtkNotebook in GTK4 and HdyTabView don't.
     2385    // See https://gitlab.gnome.org/GNOME/epiphany/-/issues/1532
     2386    // In that case we go up through the hierarchy and try to find a parent
     2387    // with non-0 size.
     2388    while (parent) {
     2389#if USE(GTK4)
     2390        width = gtk_widget_get_width(parent);
     2391        height = gtk_widget_get_height(parent);
     2392
     2393        if (width > 0 || height > 0)
     2394#else
     2395        width = gtk_widget_get_allocated_width(parent);
     2396        height = gtk_widget_get_allocated_height(parent);
     2397
     2398        // The default widget size in GTK3 is 1x1, not 0x0.
     2399        if (width > 1 || height > 1)
     2400#endif
     2401            return IntSize(width, height);
     2402
     2403        parent = gtk_widget_get_parent(parent);
     2404    }
     2405
     2406    // If there was no such a parent, it's likely the widget widget isn't
     2407    // in a window, or the whole window isn't mapped. No point in trying
     2408    // in this case.
     2409
     2410    return IntSize();
    23632411}
    23642412
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h

    r278253 r278301  
    6565
    6666void webkitWebViewBaseSetFocus(WebKitWebViewBase*, bool focused);
     67WebCore::IntSize webkitWebViewBaseGetViewSize(WebKitWebViewBase*);
    6768bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase*);
    6869bool webkitWebViewBaseIsFocused(WebKitWebViewBase*);
Note: See TracChangeset for help on using the changeset viewer.