[epiphany] Add spelling suggestion to the context menu in WebKit2
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add spelling suggestion to the context menu in WebKit2
- Date: Sun, 17 Mar 2013 11:53:20 +0000 (UTC)
commit 26435511e0a9579257ff97abc9af2e08a14c8103
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Sat Mar 16 11:50:59 2013 +0100
Add spelling suggestion to the context menu in WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=695904
src/ephy-window.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++---
src/popup-commands.c | 4 +--
2 files changed, 57 insertions(+), 7 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 26b9027..ef3a748 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1844,6 +1844,35 @@ find_item_in_context_menu (WebKitContextMenu *context_menu,
return NULL;
}
+static GList *
+find_spelling_guess_context_menu_items (WebKitContextMenu *context_menu)
+{
+ GList *items, *iter;
+ guint i;
+ GList *retval = NULL;
+
+ items = webkit_context_menu_get_items (context_menu);
+ for (iter = items, i = 0; iter && i < MAX_SPELL_CHECK_GUESSES; iter = g_list_next (iter), i++)
+ {
+ WebKitContextMenuItem *item = (WebKitContextMenuItem *)iter->data;
+
+ if (webkit_context_menu_item_get_stock_action (item) ==
WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS)
+ {
+ retval = g_list_prepend (retval, g_object_ref (item));
+ }
+ else
+ {
+ /* Spelling guesses are always at the beginning of the context menu, so
+ * we can break the loop as soon as we find the first item that is not
+ * spelling guess.
+ */
+ break;
+ }
+ }
+
+ return g_list_reverse (retval);
+}
+
static gboolean
populate_context_menu (WebKitWebView *web_view,
WebKitContextMenu *context_menu,
@@ -1852,14 +1881,18 @@ populate_context_menu (WebKitWebView *web_view,
EphyWindow *window)
{
EphyWindowPrivate *priv = window->priv;
- WebKitContextMenuItem *input_methods_item;
- WebKitContextMenuItem *unicode_item;
+ WebKitContextMenuItem *input_methods_item = NULL;
+ WebKitContextMenuItem *unicode_item = NULL;
+ GList *spelling_guess_items = NULL;
EphyEmbedEvent *embed_event;
gboolean is_document = FALSE;
gboolean app_mode;
- input_methods_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
- unicode_item = find_item_in_context_menu (context_menu, WEBKIT_CONTEXT_MENU_ACTION_UNICODE);
+ if (webkit_hit_test_result_context_is_editable (hit_test_result)) {
+ input_methods_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
+ unicode_item = find_item_in_context_menu (context_menu, WEBKIT_CONTEXT_MENU_ACTION_UNICODE);
+ spelling_guess_items = find_spelling_guess_context_menu_items (context_menu);
+ }
webkit_context_menu_remove_all (context_menu);
@@ -1920,6 +1953,25 @@ populate_context_menu (WebKitWebView *web_view,
}
else if (webkit_hit_test_result_context_is_editable (hit_test_result))
{
+ GList *l;
+ gboolean has_guesses = FALSE;
+
+ for (l = spelling_guess_items; l; l = g_list_next (l))
+ {
+ WebKitContextMenuItem *item = WEBKIT_CONTEXT_MENU_ITEM (l->data);
+
+ webkit_context_menu_append (context_menu, item);
+ g_object_unref (item);
+ has_guesses = TRUE;
+ }
+ g_list_free (spelling_guess_items);
+
+ if (has_guesses)
+ {
+ webkit_context_menu_append (context_menu,
+ webkit_context_menu_item_new_separator ());
+ }
+
update_edit_actions_sensitivity (window, FALSE);
add_action_to_context_menu (context_menu,
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 1a1d973..2896fb2 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -491,9 +491,7 @@ void
popup_replace_spelling (GtkAction *action,
EphyWindow *window)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Context Menu, Spellchecker */
-#else
+#ifndef HAVE_WEBKIT2
EphyEmbed *embed;
WebKitWebView *view;
WebKitWebFrame *frame;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]