diff options
author | Xan Lopez <xan@gnome.org> | 2011-02-11 05:27:40 +0800 |
---|---|---|
committer | Xan Lopez <xan@gnome.org> | 2011-02-11 05:35:09 +0800 |
commit | 87466892eb08ec1f5efd6ea33589355b9bab05d0 (patch) | |
tree | c8627fb43f7706e73d9519b95770608b7186465d /embed | |
parent | cfff1c9b9f901c64645347a712dae702501f6d4e (diff) | |
download | gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.tar gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.tar.gz gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.tar.bz2 gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.tar.lz gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.tar.xz gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.tar.zst gsoc2013-epiphany-87466892eb08ec1f5efd6ea33589355b9bab05d0.zip |
Port floating statusbar to gedit's overlay widget
Works correctly in framed pages, and fixes a few bugs along the way
(not to mention it should be more efficient since it does not redraw
needlessly).
The gedit code has been modified to get rid of the animation stuff we
don't really need atm; we have coordinated with the gedit developers
and hopefully both versions will be in sync again really soon.
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-embed-utils.h | 2 | ||||
-rw-r--r-- | embed/ephy-embed.c | 31 | ||||
-rw-r--r-- | embed/ephy-embed.h | 1 | ||||
-rw-r--r-- | embed/ephy-web-view.c | 99 |
4 files changed, 36 insertions, 97 deletions
diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h index b1ee9adeb..cb7890002 100644 --- a/embed/ephy-embed-utils.h +++ b/embed/ephy-embed-utils.h @@ -36,7 +36,7 @@ G_BEGIN_DECLS #define EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED(embed) (WEBKIT_WEB_VIEW (ephy_embed_get_web_view (embed))) -#define EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW(view) (EPHY_EMBED (gtk_widget_get_parent (gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (view)))))) +#define EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW(view) (EPHY_EMBED (gtk_widget_get_parent (gtk_widget_get_parent (gtk_widget_get_parent (gtk_widget_get_parent ((GTK_WIDGET (view)))))))) #define EPHY_WEBKIT_BACK_FORWARD_LIMIT 100 diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 07e6ed25a..79515cb86 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -43,6 +43,7 @@ #include "ephy-stock-icons.h" #include "ephy-string.h" #include "ephy-web-view.h" +#include "gedit-overlay.h" #include <errno.h> #include <glib/gi18n.h> @@ -72,6 +73,7 @@ struct _EphyEmbedPrivate gboolean inspector_attached; guint is_setting_zoom : 1; GSList *destroy_on_transition_list; + GtkWidget *statusbar_label; }; G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_VBOX) @@ -840,25 +842,52 @@ download_requested_cb (WebKitWebView *web_view, return TRUE; } +/* FIXME: it probably makes sense to move this stuff completely into + * EphyEmbed now, since it's not an integral part of EphyWebView + * anymore. */ +void +_ephy_embed_set_statusbar_label (EphyEmbed *embed, const char *label) +{ + EphyEmbedPrivate *priv = embed->priv; + gtk_label_set_label (GTK_LABEL (priv->statusbar_label), label); + + if (label == NULL || label[0] == '\0') + gtk_widget_hide (priv->statusbar_label); + else + gtk_widget_show (priv->statusbar_label); +} + static void ephy_embed_constructed (GObject *object) { EphyEmbed *embed = (EphyEmbed*)object; + EphyEmbedPrivate *priv = embed->priv; GtkWidget *scrolled_window; GtkWidget *paned; WebKitWebView *web_view; WebKitWebInspector *inspector; + GtkWidget *overlay; + GtkWidget *frame; /* Skeleton */ web_view = WEBKIT_WEB_VIEW (ephy_web_view_new ()); scrolled_window = GTK_WIDGET (embed->priv->scrolled_window); + overlay = gedit_overlay_new (scrolled_window); + + /* statusbar is hidden by default */ + priv->statusbar_label = gtk_label_new (NULL); + frame = gtk_frame_new (NULL); + gtk_widget_show (frame); + gtk_container_add (GTK_CONTAINER (frame), priv->statusbar_label); + gedit_overlay_add (GEDIT_OVERLAY (overlay), frame, GTK_ORIENTATION_HORIZONTAL, GDK_GRAVITY_SOUTH_WEST, 0, TRUE); + paned = GTK_WIDGET (embed->priv->paned); embed->priv->web_view = web_view; gtk_container_add (GTK_CONTAINER (embed->priv->scrolled_window), GTK_WIDGET (web_view)); - gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (scrolled_window), + gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (overlay), TRUE, FALSE); gtk_box_pack_start (GTK_BOX (embed), diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 24d5f2bba..c9fc1a4c8 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -56,6 +56,7 @@ EphyWebView* ephy_embed_get_web_view (EphyEmbed *embed); void ephy_embed_add_top_widget (EphyEmbed *embed, GtkWidget *widget, gboolean destroy_on_transition); void ephy_embed_remove_top_widget (EphyEmbed *embed, GtkWidget *widget); void ephy_embed_auto_download_url (EphyEmbed *embed, const char *url); +void _ephy_embed_set_statusbar_label (EphyEmbed *embed, const char *label); G_END_DECLS diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index e11eab665..bfa45edfa 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -1156,76 +1156,6 @@ ephy_web_view_constructed (GObject *object) } static void -_ephy_web_view_draw_statusbar (GtkWidget *widget, cairo_t *cr) -{ - gint width, height; - guint border_width, statusbar_border_width; - PangoLayout *layout; - GtkAllocation allocation; - GtkStyleContext *context; - EphyWebViewPrivate *priv; - - priv = EPHY_WEB_VIEW (widget)->priv; - - gtk_widget_get_allocation (widget, &allocation); - - layout = gtk_widget_create_pango_layout (widget, priv->text); - pango_layout_set_width (layout, PANGO_SCALE * (allocation.width * 0.9)); - pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); - - pango_layout_get_pixel_size (layout, &width, &height); - - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - - statusbar_border_width = 4; /* FIXME: what should we use here? */ - - priv->text_rectangle.x = border_width; - priv->text_rectangle.y = allocation.height - height - border_width - (statusbar_border_width * 2); - priv->text_rectangle.width = width + (statusbar_border_width * 2); - priv->text_rectangle.height = height + (statusbar_border_width * 2); - - context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - - gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL); - gtk_render_background (context, cr, - priv->text_rectangle.x, - priv->text_rectangle.y, - priv->text_rectangle.width, - priv->text_rectangle.height); - gtk_render_frame (context, cr, - priv->text_rectangle.x, - priv->text_rectangle.y, - priv->text_rectangle.width, - priv->text_rectangle.height); - - gtk_style_context_set_state (context, 0); - gtk_render_layout (context, cr, - priv->text_rectangle.x + statusbar_border_width, - priv->text_rectangle.y + statusbar_border_width, - layout); - - gtk_style_context_restore (context); - - g_object_unref (layout); -} - -static gboolean -ephy_web_view_draw (GtkWidget *widget, cairo_t *cr) -{ - EphyWebViewPrivate *priv; - - GTK_WIDGET_CLASS (ephy_web_view_parent_class)->draw (widget, cr); - - priv = EPHY_WEB_VIEW (widget)->priv; - - if (priv->text && priv->text[0] != '\0') - _ephy_web_view_draw_statusbar (widget, cr); - - return FALSE; -} - -static void ephy_web_view_class_init (EphyWebViewClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); @@ -1239,7 +1169,6 @@ ephy_web_view_class_init (EphyWebViewClass *klass) widget_class->button_press_event = ephy_web_view_button_press_event; widget_class->key_press_event = ephy_web_view_key_press_event; - widget_class->draw = ephy_web_view_draw; /** * EphyWebView:address: @@ -3752,32 +3681,12 @@ ephy_web_view_load_homepage (EphyWebView *view) static void ephy_web_view_statusbar_update (EphyWebView *view, const char *text) { - EphyWebViewPrivate *priv; - GdkWindow *window; - GdkRectangle rect; - - priv = view->priv; - - if (priv->text) - g_free (priv->text); - - priv->text = g_strdup (text); - - /* FIXME: we should invalidate the union of the sizes of the - * rectangles of the previous and next statusbar text */ - window = gtk_widget_get_window (GTK_WIDGET (view)); - if (window) { - GtkAllocation allocation; + EphyEmbed *embed; - gtk_widget_get_allocation (GTK_WIDGET (view), &allocation); + g_return_if_fail (EPHY_IS_WEB_VIEW (view)); - rect = priv->text_rectangle; - rect.width = allocation.width; - if (rect.height == 0) - rect.height = allocation.height; - - gdk_window_invalidate_rect (window, &rect, TRUE); - } + embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view); + _ephy_embed_set_statusbar_label (embed, text); } /* Portions of the following code based on GTK+. |