[epiphany/webkit2: 5/17] Add support for new windows in WebKit2
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/webkit2: 5/17] Add support for new windows in WebKit2
- Date: Fri, 15 Jun 2012 11:14:34 +0000 (UTC)
commit 2cce106e760c1b71f4c25d489854f8b163d83581
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed May 30 13:02:33 2012 +0200
Add support for new windows in WebKit2
embed/ephy-embed.c | 35 +++++++++++++-
embed/ephy-web-view.c | 14 +++++-
src/ephy-window.c | 118 +++++++++++++++++++++++++++++++++---------------
3 files changed, 124 insertions(+), 43 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 4703a3b..03ecc6a 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -571,7 +571,27 @@ status_message_notify_cb (EphyWebView *view, GParamSpec *pspec, EphyEmbed *embed
}
#ifdef HAVE_WEBKIT2
-/* TODO: WebKitWindowProperties */
+static void
+window_geometry_changed (WebKitWindowProperties *properties, GParamSpec *pspec, EphyEmbed *embed)
+{
+ GtkWidget *window;
+ gboolean is_popup;
+ GdkRectangle geometry;
+
+ window = gtk_widget_get_toplevel (GTK_WIDGET (embed));
+ if (!window || !gtk_widget_is_toplevel (window))
+ return;
+
+ g_object_get (window, "is-popup", &is_popup, NULL);
+ if (!is_popup)
+ return;
+
+ webkit_window_properties_get_geometry (properties, &geometry);
+ if (geometry.x >= 0 && geometry.y >= 0)
+ gtk_window_move (GTK_WINDOW (window), geometry.x, geometry.y);
+ if (geometry.width > 0 && geometry.height > 0)
+ gtk_window_resize (GTK_WINDOW (window), geometry.width, geometry.height);
+}
#else
static void
window_resize_requested (WebKitWebWindowFeatures *features, GParamSpec *pspec, EphyEmbed *embed)
@@ -658,8 +678,13 @@ ephy_embed_constructed (GObject *object)
#endif
GtkWidget *paned;
WebKitWebView *web_view;
-#ifndef HAVE_WEBKIT2
+#ifdef HAVE_WEBKIT2
+ WebKitWindowProperties *window_properties;
+#else
WebKitWebWindowFeatures *window_features;
+#endif
+#ifndef HAVE_WEBKIT2
+ /* TODO: Inspector */
WebKitWebInspector *inspector;
#endif
GtkWidget *overlay;
@@ -742,7 +767,11 @@ ephy_embed_constructed (GObject *object)
#endif
#ifdef HAVE_WEBKIT2
- /* TODO: WebKitWindowProperties */
+ /* Window properties */
+ window_properties = webkit_web_view_get_window_properties (web_view);
+ g_signal_connect (window_properties, "notify::geometry",
+ G_CALLBACK (window_geometry_changed),
+ embed);
#else
/* Window features */
window_features = webkit_web_view_get_window_features (web_view);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 6fed197..f0b807d 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2505,11 +2505,15 @@ load_error_cb (WebKitWebView *web_view,
}
#ifdef HAVE_WEBKIT2
-/* TODO: WebKitWebView::close */
+static void
+close_web_view_cb (WebKitWebView *web_view,
+ gpointer user_data)
+
#else
static gboolean
close_web_view_cb (WebKitWebView *web_view,
gpointer user_data)
+#endif
{
GtkWidget *widget = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
@@ -2521,9 +2525,11 @@ close_web_view_cb (WebKitWebView *web_view,
else
gtk_widget_destroy (widget);
+#ifndef HAVE_WEBKIT2
return TRUE;
-}
#endif
+}
+
static void
zoom_changed_cb (WebKitWebView *web_view,
@@ -2646,7 +2652,9 @@ ephy_web_view_init (EphyWebView *web_view)
#endif
#ifdef HAVE_WEBKIT2
- /* TODO: WebKitWebView::close */
+ g_signal_connect (web_view, "close",
+ G_CALLBACK (close_web_view_cb),
+ NULL);
#else
g_signal_connect (web_view, "close-web-view",
G_CALLBACK (close_web_view_cb),
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8e0bcf3..5ab04eb 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2054,8 +2054,71 @@ ephy_window_set_is_popup (EphyWindow *window,
}
#ifdef HAVE_WEBKIT2
-/* TODO: New WebView */
+static void
+ephy_window_configure_for_view (EphyWindow *window,
+ WebKitWebView *web_view)
+{
+ WebKitWindowProperties *properties;
+ EphyWebViewChrome chrome_mask;
+
+ properties = webkit_web_view_get_window_properties (web_view);
+
+ chrome_mask = window->priv->chrome;
+ if (!webkit_window_properties_get_toolbar_visible (properties))
+ chrome_mask &= ~EPHY_WEB_VIEW_CHROME_TOOLBAR;
+
+ /* We will consider windows with different chrome settings popups. */
+ if (chrome_mask != window->priv->chrome) {
+ GdkRectangle geometry;
+
+ webkit_window_properties_get_geometry (properties, &geometry);
+ gtk_window_set_default_size (GTK_WINDOW (window), geometry.width, geometry.height);
+
+ if (!webkit_window_properties_get_resizable (properties))
+ gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+
+ window->priv->is_popup = TRUE;
+ window->priv->chrome = chrome_mask;
+
+ sync_chromes_visibility (window);
+ }
+}
#else
+static void
+ephy_window_configure_for_view (EphyWindow *window,
+ WebKitWebView *web_view)
+{
+ int width, height;
+ gboolean toolbar_visible;
+ EphyWebViewChrome chrome_mask;
+ WebKitWebWindowFeatures *features;
+
+ toolbar_visible = TRUE;
+ features = webkit_web_view_get_window_features (web_view);
+
+ chrome_mask = window->priv->chrome;
+
+ g_object_get (features,
+ "width", &width,
+ "height", &height,
+ "toolbar-visible", &toolbar_visible,
+ NULL);
+
+ if (!toolbar_visible)
+ chrome_mask &= ~EPHY_WEB_VIEW_CHROME_TOOLBAR;
+
+ /* We will consider windows with different chrome settings popups. */
+ if (chrome_mask != window->priv->chrome) {
+ gtk_window_set_default_size (GTK_WINDOW (window), width, height);
+
+ window->priv->is_popup = TRUE;
+ window->priv->chrome = chrome_mask;
+
+ sync_chromes_visibility (window);
+ }
+}
+#endif
+
static gboolean
web_view_ready_cb (WebKitWebView *web_view,
WebKitWebView *parent_web_view)
@@ -2070,35 +2133,7 @@ web_view_ready_cb (WebKitWebView *web_view,
if (using_new_window)
{
- int width, height;
- gboolean toolbar_visible;
- EphyWebViewChrome chrome_mask;
- WebKitWebWindowFeatures *features;
-
- toolbar_visible = TRUE;
- features = webkit_web_view_get_window_features (web_view);
-
- chrome_mask = window->priv->chrome;
-
- g_object_get (features,
- "width", &width,
- "height", &height,
- "toolbar-visible", &toolbar_visible,
- NULL);
-
- if (!toolbar_visible)
- chrome_mask &= ~EPHY_WEB_VIEW_CHROME_TOOLBAR;
-
- /* We will consider windows with different chrome settings popups. */
- if (chrome_mask != window->priv->chrome) {
- gtk_window_set_default_size (GTK_WINDOW (window), width, height);
-
- window->priv->is_popup = TRUE;
- window->priv->chrome = chrome_mask;
-
- sync_chromes_visibility (window);
- }
-
+ ephy_window_configure_for_view (window, web_view);
g_signal_emit_by_name (parent_web_view, "new-window", web_view);
}
@@ -2107,10 +2142,16 @@ web_view_ready_cb (WebKitWebView *web_view,
return TRUE;
}
-static WebKitWebView*
+#ifdef HAVE_WEBKIT2
+static WebKitWebView *
+create_web_view_cb (WebKitWebView *web_view,
+ EphyWindow *window)
+#else
+static WebKitWebView *
create_web_view_cb (WebKitWebView *web_view,
WebKitWebFrame *frame,
EphyWindow *window)
+#endif
{
EphyEmbed *embed;
WebKitWebView *new_web_view;
@@ -2142,13 +2183,18 @@ create_web_view_cb (WebKitWebView *web_view,
0);
new_web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+#ifdef HAVE_WEBKIT2
+ g_signal_connect (new_web_view, "ready-to-show",
+ G_CALLBACK (web_view_ready_cb),
+ web_view);
+#else
g_signal_connect (new_web_view, "web-view-ready",
G_CALLBACK (web_view_ready_cb),
web_view);
+#endif
return new_web_view;
}
-#endif
#ifdef HAVE_WEBKIT2
static gboolean
@@ -2460,13 +2506,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed)
g_signal_handlers_disconnect_by_func (web_view,
G_CALLBACK (scroll_event_cb),
window);
-#ifdef HAVE_WEBKIT2
- /* TODO: New WebView */
-#else
g_signal_handlers_disconnect_by_func (web_view,
G_CALLBACK (create_web_view_cb),
window);
-#endif
#ifdef HAVE_WEBKIT2
g_signal_handlers_disconnect_by_func (view,
G_CALLBACK (decide_policy_cb),
@@ -2569,7 +2611,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed)
G_CALLBACK (scroll_event_cb),
window, 0);
#ifdef HAVE_WEBKIT2
- /* TODO: New WebView */
+ g_signal_connect_object (web_view, "create",
+ G_CALLBACK (create_web_view_cb),
+ window, 0);
#else
g_signal_connect_object (web_view, "create-web-view",
G_CALLBACK (create_web_view_cb),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]