summaryrefslogtreecommitdiff
path: root/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp')
-rw-r--r--Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp95
1 files changed, 73 insertions, 22 deletions
diff --git a/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp b/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp
index fd6f8466b..eb0a08d74 100644
--- a/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp
+++ b/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp
@@ -28,13 +28,17 @@
#include "config.h"
#include "PlatformWebView.h"
-#include <WebKit2/WKViewPrivate.h>
+#include <WebKit/WKImageCairo.h>
+#include <WebKit/WKPageConfigurationRef.h>
+#include <WebKit/WKView.h>
+#include <WebKit/WKViewPrivate.h>
#include <gtk/gtk.h>
+#include <wtf/Assertions.h>
namespace WTR {
-PlatformWebView::PlatformWebView(WKContextRef context, WKPageGroupRef pageGroup, WKPageRef /* relatedPage */, WKDictionaryRef options)
- : m_view(WKViewCreate(context, pageGroup))
+PlatformWebView::PlatformWebView(WKPageConfigurationRef configuration, const TestOptions& options)
+ : m_view(WKViewCreate(configuration))
, m_window(gtk_window_new(GTK_WINDOW_POPUP))
, m_windowIsKey(true)
, m_options(options)
@@ -42,7 +46,7 @@ PlatformWebView::PlatformWebView(WKContextRef context, WKPageGroupRef pageGroup,
gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view));
GtkAllocation size = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(m_window, &size);
+ gtk_widget_size_allocate(GTK_WIDGET(m_view), &size);
gtk_window_resize(GTK_WINDOW(m_window), 800, 600);
gtk_widget_show_all(m_window);
@@ -55,14 +59,17 @@ PlatformWebView::~PlatformWebView()
gtk_widget_destroy(m_window);
}
-void PlatformWebView::resizeTo(unsigned width, unsigned height)
+void PlatformWebView::setWindowIsKey(bool isKey)
{
- GtkAllocation size = { 0, 0, static_cast<int>(width), static_cast<int>(height) };
- gtk_widget_size_allocate(m_window, &size);
- gtk_window_resize(GTK_WINDOW(m_window), width, height);
+ m_windowIsKey = isKey;
+}
- while (gtk_events_pending())
- gtk_main_iteration();
+void PlatformWebView::resizeTo(unsigned width, unsigned height, WebViewSizingMode sizingMode)
+{
+ WKRect frame = windowFrame();
+ frame.size.width = width;
+ frame.size.height = height;
+ setWindowFrame(frame, sizingMode);
}
WKPageRef PlatformWebView::page()
@@ -79,14 +86,8 @@ void PlatformWebView::focus()
WKRect PlatformWebView::windowFrame()
{
GtkAllocation geometry;
-#ifdef GTK_API_VERSION_2
- gint depth;
- gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(m_window)),
- &geometry.x, &geometry.y, &geometry.width, &geometry.height, &depth);
-#else
gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(m_window)),
&geometry.x, &geometry.y, &geometry.width, &geometry.height);
-#endif
WKRect frame;
frame.origin.x = geometry.x;
@@ -96,10 +97,15 @@ WKRect PlatformWebView::windowFrame()
return frame;
}
-void PlatformWebView::setWindowFrame(WKRect frame)
+void PlatformWebView::setWindowFrame(WKRect frame, WebViewSizingMode)
{
- gtk_window_move(GTK_WINDOW(m_window), frame.origin.x, frame.origin.y);
- resizeTo(frame.size.width, frame.size.height);
+ gdk_window_move_resize(gtk_widget_get_window(GTK_WIDGET(m_window)),
+ frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
+ GtkAllocation size = { 0, 0, static_cast<int>(frame.size.width), static_cast<int>(frame.size.height) };
+ gtk_widget_size_allocate(GTK_WIDGET(m_view), &size);
+
+ while (gtk_events_pending())
+ gtk_main_iteration();
}
void PlatformWebView::addChromeInputField()
@@ -110,20 +116,65 @@ void PlatformWebView::removeChromeInputField()
{
}
+void PlatformWebView::addToWindow()
+{
+}
+
+void PlatformWebView::removeFromWindow()
+{
+}
+
void PlatformWebView::makeWebViewFirstResponder()
{
}
+void PlatformWebView::changeWindowScaleIfNeeded(float)
+{
+}
+
WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
{
- // FIXME: implement to capture pixels in the UI process,
- // which may be necessary to capture things like 3D transforms.
- return 0;
+ int width = gtk_widget_get_allocated_width(GTK_WIDGET(m_view));
+ int height = gtk_widget_get_allocated_height(GTK_WIDGET(m_view));
+
+ while (gtk_events_pending())
+ gtk_main_iteration();
+
+ cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+
+ cairo_t* context = cairo_create(imageSurface);
+ gtk_widget_draw(GTK_WIDGET(m_view), context);
+ cairo_destroy(context);
+
+ WKRetainPtr<WKImageRef> wkImage = adoptWK(WKImageCreateFromCairoSurface(imageSurface, 0 /* options */));
+
+ cairo_surface_destroy(imageSurface);
+ return wkImage;
}
void PlatformWebView::didInitializeClients()
{
}
+bool PlatformWebView::viewSupportsOptions(const TestOptions&) const
+{
+ return true;
+}
+
+void PlatformWebView::dismissAllPopupMenus()
+{
+ // gtk_menu_popdown doesn't modify the GList of attached menus, so it should
+ // be safe to walk this list while calling it.
+ GList* attachedMenusList = gtk_menu_get_for_attach_widget(GTK_WIDGET(m_view));
+ g_list_foreach(attachedMenusList, [] (void* data, void*) {
+ ASSERT(data);
+ gtk_menu_popdown(GTK_MENU(data));
+ }, nullptr);
+}
+
+void PlatformWebView::setNavigationGesturesEnabled(bool)
+{
+}
+
} // namespace WTR