Title: [278301] trunk/Source/WebKit
- Revision
- 278301
- Author
- [email protected]
- Date
- 2021-06-01 04:59:21 -0700 (Tue, 01 Jun 2021)
Log Message
[GTK] Try harder to find initial WebKitWebView size
https://bugs.webkit.org/show_bug.cgi?id=226320
Patch by Alexander Mikhaylenko <[email protected]> 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:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (278300 => 278301)
--- trunk/Source/WebKit/ChangeLog 2021-06-01 10:52:26 UTC (rev 278300)
+++ trunk/Source/WebKit/ChangeLog 2021-06-01 11:59:21 UTC (rev 278301)
@@ -1,3 +1,40 @@
+2021-06-01 Alexander Mikhaylenko <[email protected]>
+
+ [GTK] Try harder to find initial WebKitWebView size
+ https://bugs.webkit.org/show_bug.cgi?id=226320
+
+ 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:
+
2021-05-30 Dean Jackson <[email protected]>
[WebXR] Send recommendedResolution using DeviceProxy
Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp (278300 => 278301)
--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp 2021-06-01 10:52:26 UTC (rev 278300)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp 2021-06-01 11:59:21 UTC (rev 278301)
@@ -103,8 +103,7 @@
WebCore::IntSize PageClientImpl::viewSize()
{
- auto* drawingArea = static_cast<DrawingAreaProxyCoordinatedGraphics*>(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_viewWidget))->drawingArea());
- return drawingArea ? drawingArea->size() : IntSize();
+ return webkitWebViewBaseGetViewSize(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
}
bool PageClientImpl::isViewWindowActive()
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (278300 => 278301)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp 2021-06-01 10:52:26 UTC (rev 278300)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp 2021-06-01 11:59:21 UTC (rev 278301)
@@ -263,6 +263,7 @@
#endif
std::unique_ptr<PageClientImpl> pageClient;
RefPtr<WebPageProxy> pageProxy;
+ IntSize viewSize { };
bool shouldForwardNextKeyEvent { false };
bool shouldForwardNextWheelEvent { false };
#if !USE(GTK4)
@@ -891,8 +892,10 @@
}
#endif
+ priv->viewSize = viewRect.size();
+
if (auto* drawingArea = static_cast<DrawingAreaProxyCoordinatedGraphics*>(priv->pageProxy->drawingArea()))
- drawingArea->setSize(viewRect.size());
+ drawingArea->setSize(priv->viewSize);
}
#if USE(GTK4)
@@ -2362,6 +2365,51 @@
webkitWebViewBaseScheduleUpdateActivityState(webViewBase, flagsToUpdate);
}
+IntSize webkitWebViewBaseGetViewSize(WebKitWebViewBase* webViewBase)
+{
+ WebKitWebViewBasePrivate* priv = webViewBase->priv;
+ int width = priv->viewSize.width();
+ int height = priv->viewSize.height();
+
+ // First try the widget's own size. If it's already allocated,
+ // everything is fine and we'll just use that.
+ if (width > 0 || height > 0)
+ return IntSize(width, height);
+
+ GtkWidget* parent = gtk_widget_get_parent(GTK_WIDGET(webViewBase));
+
+ // If it's not allocated, then its size will be 0. This can be a problem
+ // if the web view is loaded in background and the container doesn't
+ // allocate non-visible children: e.g. GtkNotebook in GTK3 does allocate
+ // them, but GtkStack, and so GtkNotebook in GTK4 and HdyTabView don't.
+ // See https://gitlab.gnome.org/GNOME/epiphany/-/issues/1532
+ // In that case we go up through the hierarchy and try to find a parent
+ // with non-0 size.
+ while (parent) {
+#if USE(GTK4)
+ width = gtk_widget_get_width(parent);
+ height = gtk_widget_get_height(parent);
+
+ if (width > 0 || height > 0)
+#else
+ width = gtk_widget_get_allocated_width(parent);
+ height = gtk_widget_get_allocated_height(parent);
+
+ // The default widget size in GTK3 is 1x1, not 0x0.
+ if (width > 1 || height > 1)
+#endif
+ return IntSize(width, height);
+
+ parent = gtk_widget_get_parent(parent);
+ }
+
+ // If there was no such a parent, it's likely the widget widget isn't
+ // in a window, or the whole window isn't mapped. No point in trying
+ // in this case.
+
+ return IntSize();
+}
+
bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase* webViewBase)
{
return webViewBase->priv->activityState.contains(ActivityState::WindowIsActive);
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h (278300 => 278301)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h 2021-06-01 10:52:26 UTC (rev 278300)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h 2021-06-01 11:59:21 UTC (rev 278301)
@@ -64,6 +64,7 @@
void webkitWebViewBaseSetContentsSize(WebKitWebViewBase*, const WebCore::IntSize&);
void webkitWebViewBaseSetFocus(WebKitWebViewBase*, bool focused);
+WebCore::IntSize webkitWebViewBaseGetViewSize(WebKitWebViewBase*);
bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase*);
bool webkitWebViewBaseIsFocused(WebKitWebViewBase*);
bool webkitWebViewBaseIsVisible(WebKitWebViewBase*);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes