]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-webkit-utils.c
Center the 'smiley images' inside the menu items
[empathy.git] / libempathy-gtk / empathy-webkit-utils.c
index cac9af9d89160e98e611e0144a9c22fe11812dca..90dc28c17344c2fed4a7912afcac21164fd2f972 100644 (file)
  */
 
 #include "config.h"
+#include "empathy-webkit-utils.h"
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 
-#include "empathy-webkit-utils.h"
 #include "empathy-smiley-manager.h"
+#include "empathy-string-parser.h"
+#include "empathy-theme-adium.h"
 #include "empathy-ui-utils.h"
 
 #define BORING_DPI_DEFAULT 96
@@ -31,8 +33,8 @@
 static void
 empathy_webkit_match_newline (const gchar *text,
     gssize len,
-    EmpathyStringReplace replace_func,
-    EmpathyStringParser *sub_parsers,
+    TpawStringReplace replace_func,
+    TpawStringParser *sub_parsers,
     gpointer user_data)
 {
   GString *string = user_data;
@@ -47,14 +49,14 @@ empathy_webkit_match_newline (const gchar *text,
     {
       if (text[i] == '\n')
         {
-          empathy_string_parser_substr (text + prev, i - prev,
+          tpaw_string_parser_substr (text + prev, i - prev,
               sub_parsers, user_data);
           g_string_append (string, "<br/>");
           prev = i + 1;
         }
     }
 
-  empathy_string_parser_substr (text + prev, i - prev,
+  tpaw_string_parser_substr (text + prev, i - prev,
               sub_parsers, user_data);
 }
 
@@ -73,22 +75,22 @@ empathy_webkit_replace_smiley (const gchar *text,
       hit->path, (int)len, text, (int)len, text);
 }
 
-static EmpathyStringParser string_parsers[] = {
-  { empathy_string_match_link, empathy_string_replace_link },
+static TpawStringParser string_parsers[] = {
+  { tpaw_string_match_link, tpaw_string_replace_link },
   { empathy_webkit_match_newline, NULL },
-  { empathy_string_match_all, empathy_string_replace_escaped },
+  { tpaw_string_match_all, tpaw_string_replace_escaped },
   { NULL, NULL}
 };
 
-static EmpathyStringParser string_parsers_with_smiley[] = {
-  { empathy_string_match_link, empathy_string_replace_link },
+static TpawStringParser string_parsers_with_smiley[] = {
+  { tpaw_string_match_link, tpaw_string_replace_link },
   { empathy_string_match_smiley, empathy_webkit_replace_smiley },
   { empathy_webkit_match_newline, NULL },
-  { empathy_string_match_all, empathy_string_replace_escaped },
+  { tpaw_string_match_all, tpaw_string_replace_escaped },
   { NULL, NULL }
 };
 
-EmpathyStringParser *
+TpawStringParser *
 empathy_webkit_get_string_parser (gboolean smileys)
 {
   if (smileys)
@@ -160,6 +162,7 @@ empathy_webkit_bind_font_setting (WebKitWebView *webview,
       webkit_get_font_family,
       NULL,
       NULL, NULL);
+
   g_settings_bind_with_mapping (gsettings, key,
       settings, "default-font-size",
       G_SETTINGS_BIND_GET,
@@ -170,11 +173,11 @@ empathy_webkit_bind_font_setting (WebKitWebView *webview,
 
 static void
 empathy_webkit_copy_address_cb (GtkMenuItem *menuitem,
-    gpointer     user_data)
+    gpointer user_data)
 {
-  WebKitHitTestResult   *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
-  gchar                 *uri;
-  GtkClipboard          *clipboard;
+  WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
+  gchar *uri;
+  GtkClipboard *clipboard;
 
   g_object_get (G_OBJECT (hit_test_result),
       "link-uri", &uri,
@@ -193,8 +196,8 @@ static void
 empathy_webkit_open_address_cb (GtkMenuItem *menuitem,
     gpointer     user_data)
 {
-  WebKitHitTestResult   *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
-  gchar                 *uri;
+  WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
+  gchar *uri;
 
   g_object_get (G_OBJECT (hit_test_result),
       "link-uri", &uri,
@@ -205,6 +208,13 @@ empathy_webkit_open_address_cb (GtkMenuItem *menuitem,
   g_free (uri);
 }
 
+static void
+empathy_webkit_inspect_cb (GtkMenuItem *menuitem,
+    WebKitWebView *view)
+{
+  empathy_webkit_show_inspector (view);
+}
+
 static void
 empathy_webkit_context_menu_selection_done_cb (GtkMenuShell *menu,
     gpointer user_data)
@@ -214,17 +224,15 @@ empathy_webkit_context_menu_selection_done_cb (GtkMenuShell *menu,
   g_object_unref (hit_test_result);
 }
 
-void
-empathy_webkit_context_menu_for_event (WebKitWebView *view,
-    GdkEventButton *event,
+GtkWidget *
+empathy_webkit_create_context_menu (WebKitWebView *view,
+    WebKitHitTestResult *hit_test_result,
     EmpathyWebKitMenuFlags flags)
 {
-  WebKitHitTestResult        *hit_test_result;
-  WebKitHitTestResultContext  context;
-  GtkWidget                  *menu;
-  GtkWidget                  *item;
+  WebKitHitTestResultContext context;
+  GtkWidget *menu;
+  GtkWidget *item;
 
-  hit_test_result = webkit_web_view_get_hit_test_result (view, event);
   g_object_get (G_OBJECT (hit_test_result),
       "context", &context,
       NULL);
@@ -261,7 +269,7 @@ empathy_webkit_context_menu_for_event (WebKitWebView *view,
       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
 
       g_signal_connect_swapped (item, "activate",
-          G_CALLBACK (empathy_chat_view_clear),
+          G_CALLBACK (empathy_theme_adium_clear),
           view);
     }
 
@@ -288,13 +296,53 @@ empathy_webkit_context_menu_for_event (WebKitWebView *view,
       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
     }
 
+  if ((flags & EMPATHY_WEBKIT_MENU_INSPECT) != 0)
+    {
+      /* Separator */
+      item = gtk_separator_menu_item_new ();
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+      /* Inspector */
+      item = gtk_menu_item_new_with_mnemonic (_("Inspect HTML"));
+      g_signal_connect (item, "activate",
+          G_CALLBACK (empathy_webkit_inspect_cb), view);
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+    }
+
   g_signal_connect (GTK_MENU_SHELL (menu), "selection-done",
       G_CALLBACK (empathy_webkit_context_menu_selection_done_cb),
-      hit_test_result);
+      g_object_ref (hit_test_result));
+
+  return menu;
+}
+
+void
+empathy_webkit_context_menu_for_event (WebKitWebView *view,
+    GdkEventButton *event,
+    EmpathyWebKitMenuFlags flags)
+{
+  GtkWidget *menu;
+  WebKitHitTestResult *hit_test_result;
+
+  hit_test_result = webkit_web_view_get_hit_test_result (view, event);
+
+  menu = empathy_webkit_create_context_menu (view, hit_test_result, flags);
 
-  /* Display the menu */
   gtk_widget_show_all (menu);
   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
       event->button, event->time);
+
+  g_object_unref (hit_test_result);
 }
 
+void
+empathy_webkit_show_inspector (WebKitWebView *view)
+{
+  WebKitWebInspector *inspector;
+
+  g_object_set (G_OBJECT (webkit_web_view_get_settings (view)),
+      "enable-developer-extras", TRUE, NULL);
+
+  inspector = webkit_web_view_get_inspector (view);
+  webkit_web_inspector_show (inspector);
+}