[GTK] Implement unicode submenu items
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Mar 2012 18:28:53 +0000 (18:28 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Mar 2012 18:28:53 +0000 (18:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81117

Reviewed by Martin Robinson.

Source/WebCore:

* loader/EmptyClients.h:
(WebCore::EmptyEditorClient::shouldShowUnicodeMenu): Just return
false.
* page/ContextMenuController.cpp:
(WebCore::insertUnicodeCharacter): Helper function to insert a
unicode character.
(WebCore::ContextMenuController::contextMenuItemSelected):
Implement unicode menu items using insertUnicodeCharacter() to
insert the apropriate unicode character.
(WebCore::ContextMenuController::createAndAppendUnicodeSubMenu):
Create the unicode submenu.
(WebCore::ContextMenuController::populate): Add unicode submenu
item for editable content.
(WebCore::ContextMenuController::checkOrEnableIfNeeded): Add
unicode submenu items to the switch.
* page/ContextMenuController.h:
* page/EditorClient.h:
(EditorClient): Add shouldShowUnicodeMenu() for GTK platform.
* platform/ContextMenuItem.h:
* platform/LocalizedStrings.h:
* platform/gtk/LocalizedStringsGtk.cpp:
(WebCore::contextMenuItemTagUnicodeInsertLRMMark): Add localized
string for the unicode menu item.
(WebCore::contextMenuItemTagUnicodeInsertRLMMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertLREMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertRLEMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertLROMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertRLOMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertPDFMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertZWSMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertZWJMark): Ditto.
(WebCore::contextMenuItemTagUnicodeInsertZWNJMark): Ditto.

Source/WebKit/gtk:

* WebCoreSupport/ContextMenuClientGtk.cpp:
(WebKit::getUnicodeMenuItemPosition): Helper function to get the
position of the unicode menu item in the default context menu.
(WebKit::ContextMenuClient::getCustomMenuFromDefaultItems): Remove
code to build the unicode menu, since it's now built by WebCore.
* WebCoreSupport/EditorClientGtk.cpp:
(WebKit::EditorClient::shouldShowUnicodeMenu): Check whether
unicode menu should be shown based on gtk-show-unicode-menu GtkSetting.
* WebCoreSupport/EditorClientGtk.h:

Source/WebKit2:

* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::shouldShowUnicodeMenu): Implement
shouldShowUnicodeMenu() returning always true. When ContextMenu
API is implemented for GTK+ the UI process will decide whether to
show the unicode menu or not.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110865 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/ContextMenuController.h
Source/WebCore/page/EditorClient.h
Source/WebCore/platform/ContextMenuItem.h
Source/WebCore/platform/LocalizedStrings.h
Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/WebCoreSupport/ContextMenuClientGtk.cpp
Source/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp
Source/WebKit/gtk/WebCoreSupport/EditorClientGtk.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h
Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp

index f364a18..97607c8 100644 (file)
@@ -1,3 +1,43 @@
+2012-03-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Implement unicode submenu items
+        https://bugs.webkit.org/show_bug.cgi?id=81117
+
+        Reviewed by Martin Robinson.
+
+        * loader/EmptyClients.h:
+        (WebCore::EmptyEditorClient::shouldShowUnicodeMenu): Just return
+        false.
+        * page/ContextMenuController.cpp:
+        (WebCore::insertUnicodeCharacter): Helper function to insert a
+        unicode character.
+        (WebCore::ContextMenuController::contextMenuItemSelected):
+        Implement unicode menu items using insertUnicodeCharacter() to
+        insert the apropriate unicode character.
+        (WebCore::ContextMenuController::createAndAppendUnicodeSubMenu):
+        Create the unicode submenu.
+        (WebCore::ContextMenuController::populate): Add unicode submenu
+        item for editable content.
+        (WebCore::ContextMenuController::checkOrEnableIfNeeded): Add
+        unicode submenu items to the switch.
+        * page/ContextMenuController.h:
+        * page/EditorClient.h:
+        (EditorClient): Add shouldShowUnicodeMenu() for GTK platform.
+        * platform/ContextMenuItem.h:
+        * platform/LocalizedStrings.h:
+        * platform/gtk/LocalizedStringsGtk.cpp:
+        (WebCore::contextMenuItemTagUnicodeInsertLRMMark): Add localized
+        string for the unicode menu item.
+        (WebCore::contextMenuItemTagUnicodeInsertRLMMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertLREMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertRLEMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertLROMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertRLOMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertPDFMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertZWSMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertZWJMark): Ditto.
+        (WebCore::contextMenuItemTagUnicodeInsertZWNJMark): Ditto.
+
 2012-03-15  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: MainScriptMapping should detect snippet scripts by means of sourceURL set before evaluation.
index a65f4f6..33c25d9 100644 (file)
@@ -517,6 +517,9 @@ public:
     virtual bool isAutomaticSpellingCorrectionEnabled() { return false; }
     virtual void toggleAutomaticSpellingCorrection() { }
 #endif
+#if PLATFORM(GTK)
+    virtual bool shouldShowUnicodeMenu() { return false; }
+#endif
     TextCheckerClient* textChecker() { return &m_textCheckerClient; }
 
 #if USE(AUTOCORRECTION_PANEL)
index c515675..2627f6e 100644 (file)
 #include "ResourceRequest.h"
 #include "Settings.h"
 #include "TextIterator.h"
+#include "TypingCommand.h"
 #include "UserTypingGestureIndicator.h"
 #include "WindowFeatures.h"
 #include "markup.h"
 #include <wtf/unicode/Unicode.h>
 
+#if PLATFORM(GTK)
+#include <wtf/gobject/GOwnPtr.h>
+#endif
+
 using namespace WTF;
 using namespace Unicode;
 
@@ -181,6 +186,17 @@ static void openNewWindow(const KURL& urlToLoad, Frame* frame)
     }
 }
 
+#if PLATFORM(GTK)
+static void insertUnicodeCharacter(UChar character, Frame* frame)
+{
+    String text(&character, 1);
+    if (!frame->editor()->shouldInsertText(text, frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped))
+        return;
+
+    TypingCommand::insertText(frame->document(), text, 0, TypingCommand::TextCompositionNone);
+}
+#endif
+
 void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
 {
     ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
@@ -284,6 +300,36 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
     case ContextMenuItemTagDelete:
         frame->editor()->performDelete();
         break;
+    case ContextMenuItemTagUnicodeInsertLRMMark:
+        insertUnicodeCharacter(leftToRightMark, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertRLMMark:
+        insertUnicodeCharacter(rightToLeftMark, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertLREMark:
+        insertUnicodeCharacter(leftToRightEmbed, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertRLEMark:
+        insertUnicodeCharacter(rightToLeftEmbed, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertLROMark:
+        insertUnicodeCharacter(leftToRightOverride, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertRLOMark:
+        insertUnicodeCharacter(rightToLeftOverride, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertPDFMark:
+        insertUnicodeCharacter(popDirectionalFormatting, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertZWSMark:
+        insertUnicodeCharacter(zeroWidthSpace, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertZWJMark:
+        insertUnicodeCharacter(zeroWidthJoiner, frame);
+        break;
+    case ContextMenuItemTagUnicodeInsertZWNJMark:
+        insertUnicodeCharacter(zeroWidthNonJoiner, frame);
+        break;
 #endif
 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
     case ContextMenuItemTagSelectAll:
@@ -530,7 +576,38 @@ void ContextMenuController::createAndAppendSpeechSubMenu(ContextMenuItem& speech
 
 #endif
  
-#if !PLATFORM(GTK)
+#if PLATFORM(GTK)
+
+void ContextMenuController::createAndAppendUnicodeSubMenu(ContextMenuItem& unicodeMenuItem)
+{
+    ContextMenu unicodeMenu;
+
+    ContextMenuItem leftToRightMarkMenuItem(ActionType, ContextMenuItemTagUnicodeInsertLRMMark, contextMenuItemTagUnicodeInsertLRMMark());
+    ContextMenuItem rightToLeftMarkMenuItem(ActionType, ContextMenuItemTagUnicodeInsertRLMMark, contextMenuItemTagUnicodeInsertRLMMark());
+    ContextMenuItem leftToRightEmbedMenuItem(ActionType, ContextMenuItemTagUnicodeInsertLREMark, contextMenuItemTagUnicodeInsertLREMark());
+    ContextMenuItem rightToLeftEmbedMenuItem(ActionType, ContextMenuItemTagUnicodeInsertRLEMark, contextMenuItemTagUnicodeInsertRLEMark());
+    ContextMenuItem leftToRightOverrideMenuItem(ActionType, ContextMenuItemTagUnicodeInsertLROMark, contextMenuItemTagUnicodeInsertLROMark());
+    ContextMenuItem rightToLeftOverrideMenuItem(ActionType, ContextMenuItemTagUnicodeInsertRLOMark, contextMenuItemTagUnicodeInsertRLOMark());
+    ContextMenuItem popDirectionalFormattingMenuItem(ActionType, ContextMenuItemTagUnicodeInsertPDFMark, contextMenuItemTagUnicodeInsertPDFMark());
+    ContextMenuItem zeroWidthSpaceMenuItem(ActionType, ContextMenuItemTagUnicodeInsertZWSMark, contextMenuItemTagUnicodeInsertZWSMark());
+    ContextMenuItem zeroWidthJoinerMenuItem(ActionType, ContextMenuItemTagUnicodeInsertZWJMark, contextMenuItemTagUnicodeInsertZWJMark());
+    ContextMenuItem zeroWidthNonJoinerMenuItem(ActionType, ContextMenuItemTagUnicodeInsertZWNJMark, contextMenuItemTagUnicodeInsertZWNJMark());
+
+    appendItem(leftToRightMarkMenuItem, &unicodeMenu);
+    appendItem(rightToLeftMarkMenuItem, &unicodeMenu);
+    appendItem(leftToRightEmbedMenuItem, &unicodeMenu);
+    appendItem(rightToLeftEmbedMenuItem, &unicodeMenu);
+    appendItem(leftToRightOverrideMenuItem, &unicodeMenu);
+    appendItem(rightToLeftOverrideMenuItem, &unicodeMenu);
+    appendItem(popDirectionalFormattingMenuItem, &unicodeMenu);
+    appendItem(zeroWidthSpaceMenuItem, &unicodeMenu);
+    appendItem(zeroWidthJoinerMenuItem, &unicodeMenu);
+    appendItem(zeroWidthNonJoinerMenuItem, &unicodeMenu);
+
+    unicodeMenuItem.setSubMenu(&unicodeMenu);
+}
+
+#else
 
 void ContextMenuController::createAndAppendWritingDirectionSubMenu(ContextMenuItem& writingDirectionMenuItem)
 {
@@ -943,7 +1020,15 @@ void ContextMenuController::populate()
             createAndAppendSpeechSubMenu(SpeechMenuItem);
             appendItem(SpeechMenuItem, m_contextMenu.get());
 #endif
-#if !PLATFORM(GTK)
+#if PLATFORM(GTK)
+            EditorClient* client = frame->editor()->client();
+            if (client && client->shouldShowUnicodeMenu()) {
+                ContextMenuItem UnicodeMenuItem(SubmenuType, ContextMenuItemTagUnicode, contextMenuItemTagUnicode());
+                createAndAppendUnicodeSubMenu(UnicodeMenuItem);
+                appendItem(*separatorItem(), m_contextMenu.get());
+                appendItem(UnicodeMenuItem, m_contextMenu.get());
+            }
+#else
             ContextMenuItem WritingDirectionMenuItem(SubmenuType, ContextMenuItemTagWritingDirectionMenu, 
                 contextMenuItemTagWritingDirectionMenu());
             createAndAppendWritingDirectionSubMenu(WritingDirectionMenuItem);
@@ -1062,6 +1147,16 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
             break;
         case ContextMenuItemTagInputMethods:
         case ContextMenuItemTagUnicode:
+        case ContextMenuItemTagUnicodeInsertLRMMark:
+        case ContextMenuItemTagUnicodeInsertRLMMark:
+        case ContextMenuItemTagUnicodeInsertLREMark:
+        case ContextMenuItemTagUnicodeInsertRLEMark:
+        case ContextMenuItemTagUnicodeInsertLROMark:
+        case ContextMenuItemTagUnicodeInsertRLOMark:
+        case ContextMenuItemTagUnicodeInsertPDFMark:
+        case ContextMenuItemTagUnicodeInsertZWSMark:
+        case ContextMenuItemTagUnicodeInsertZWJMark:
+        case ContextMenuItemTagUnicodeInsertZWNJMark:
             shouldEnable = true;
             break;
 #endif
index fdae946..d3c56a2 100644 (file)
@@ -85,6 +85,9 @@ namespace WebCore {
         void createAndAppendTextDirectionSubMenu(ContextMenuItem&);
         void createAndAppendSubstitutionsSubMenu(ContextMenuItem&);
         void createAndAppendTransformationsSubMenu(ContextMenuItem&);
+#if PLATFORM(GTK)
+        void createAndAppendUnicodeSubMenu(ContextMenuItem&);
+#endif
 
         Page* m_page;
         ContextMenuClient* m_client;
index 1f0954f..4ecd565 100644 (file)
@@ -140,6 +140,10 @@ public:
     virtual void toggleAutomaticSpellingCorrection() = 0;
 #endif
 
+#if PLATFORM(GTK)
+    virtual bool shouldShowUnicodeMenu() = 0;
+#endif
+
     virtual TextCheckerClient* textChecker() = 0;
 
     enum AutocorrectionResponseType {
index 15bff48..0357814 100644 (file)
@@ -77,6 +77,16 @@ namespace WebCore {
 #if PLATFORM(GTK)
         ContextMenuItemTagInputMethods,
         ContextMenuItemTagUnicode,
+        ContextMenuItemTagUnicodeInsertLRMMark,
+        ContextMenuItemTagUnicodeInsertRLMMark,
+        ContextMenuItemTagUnicodeInsertLREMark,
+        ContextMenuItemTagUnicodeInsertRLEMark,
+        ContextMenuItemTagUnicodeInsertLROMark,
+        ContextMenuItemTagUnicodeInsertRLOMark,
+        ContextMenuItemTagUnicodeInsertPDFMark,
+        ContextMenuItemTagUnicodeInsertZWSMark,
+        ContextMenuItemTagUnicodeInsertZWJMark,
+        ContextMenuItemTagUnicodeInsertZWNJMark,
 #endif
         ContextMenuItemTagSpellingGuess,
         ContextMenuItemTagNoGuessesFound,
index ff8fbbf..60be9f7 100644 (file)
@@ -69,6 +69,16 @@ namespace WebCore {
     String contextMenuItemTagDelete();
     String contextMenuItemTagInputMethods();
     String contextMenuItemTagUnicode();
+    String contextMenuItemTagUnicodeInsertLRMMark();
+    String contextMenuItemTagUnicodeInsertRLMMark();
+    String contextMenuItemTagUnicodeInsertLREMark();
+    String contextMenuItemTagUnicodeInsertRLEMark();
+    String contextMenuItemTagUnicodeInsertLROMark();
+    String contextMenuItemTagUnicodeInsertRLOMark();
+    String contextMenuItemTagUnicodeInsertPDFMark();
+    String contextMenuItemTagUnicodeInsertZWSMark();
+    String contextMenuItemTagUnicodeInsertZWJMark();
+    String contextMenuItemTagUnicodeInsertZWNJMark();
 #endif
 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
     String contextMenuItemTagSelectAll();
index 2230da3..495d9de 100644 (file)
@@ -342,6 +342,56 @@ String contextMenuItemTagInspectElement()
     return String::fromUTF8(_("Inspect _Element"));
 }
 
+String contextMenuItemTagUnicodeInsertLRMMark()
+{
+    return String::fromUTF8(_("LRM _Left-to-right mark"));
+}
+
+String contextMenuItemTagUnicodeInsertRLMMark()
+{
+    return String::fromUTF8(_("RLM _Right-to-left mark"));
+}
+
+String contextMenuItemTagUnicodeInsertLREMark()
+{
+    return String::fromUTF8(_("LRE Left-to-right _embedding"));
+}
+
+String contextMenuItemTagUnicodeInsertRLEMark()
+{
+    return String::fromUTF8(_("RLE Right-to-left e_mbedding"));
+}
+
+String contextMenuItemTagUnicodeInsertLROMark()
+{
+    return String::fromUTF8(_("LRO Left-to-right _override"));
+}
+
+String contextMenuItemTagUnicodeInsertRLOMark()
+{
+    return String::fromUTF8(_("RLO Right-to-left o_verride"));
+}
+
+String contextMenuItemTagUnicodeInsertPDFMark()
+{
+    return String::fromUTF8(_("PDF _Pop directional formatting"));
+}
+
+String contextMenuItemTagUnicodeInsertZWSMark()
+{
+    return String::fromUTF8(_("ZWS _Zero width space"));
+}
+
+String contextMenuItemTagUnicodeInsertZWJMark()
+{
+    return String::fromUTF8(_("ZWJ Zero width _joiner"));
+}
+
+String contextMenuItemTagUnicodeInsertZWNJMark()
+{
+    return String::fromUTF8(_("ZWNJ Zero width _non-joiner"));
+}
+
 String searchMenuNoRecentSearchesText()
 {
     return String::fromUTF8(_("No recent searches"));
index b911837..40ae039 100644 (file)
@@ -1,3 +1,20 @@
+2012-03-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Implement unicode submenu items
+        https://bugs.webkit.org/show_bug.cgi?id=81117
+
+        Reviewed by Martin Robinson.
+
+        * WebCoreSupport/ContextMenuClientGtk.cpp:
+        (WebKit::getUnicodeMenuItemPosition): Helper function to get the
+        position of the unicode menu item in the default context menu.
+        (WebKit::ContextMenuClient::getCustomMenuFromDefaultItems): Remove
+        code to build the unicode menu, since it's now built by WebCore.
+        * WebCoreSupport/EditorClientGtk.cpp:
+        (WebKit::EditorClient::shouldShowUnicodeMenu): Check whether
+        unicode menu should be shown based on gtk-show-unicode-menu GtkSetting.
+        * WebCoreSupport/EditorClientGtk.h:
+
 2012-03-13  Adam Barth  <abarth@webkit.org> && Benjamin Poulain  <bpoulain@apple.com>
 
         Always enable ENABLE(CLIENT_BASED_GEOLOCATION)
index d9c59d0..801e2ea 100644 (file)
@@ -24,6 +24,7 @@
 #include "ContextMenuController.h"
 #include "HitTestResult.h"
 #include "KURL.h"
+#include "LocalizedStrings.h"
 #include "NotImplemented.h"
 #include "Page.h"
 #include "webkitwebviewprivate.h"
@@ -70,60 +71,22 @@ static GtkWidget* inputMethodsMenuItem (WebKitWebView* webView)
     return menuitem;
 }
 
-// Values taken from gtktextutil.c
-typedef struct {
-  const char *label;
-  gunichar ch;
-} GtkUnicodeMenuEntry;
-static const GtkUnicodeMenuEntry bidi_menu_entries[] = {
-  { N_("LRM _Left-to-right mark"), 0x200E },
-  { N_("RLM _Right-to-left mark"), 0x200F },
-  { N_("LRE Left-to-right _embedding"), 0x202A },
-  { N_("RLE Right-to-left e_mbedding"), 0x202B },
-  { N_("LRO Left-to-right _override"), 0x202D },
-  { N_("RLO Right-to-left o_verride"), 0x202E },
-  { N_("PDF _Pop directional formatting"), 0x202C },
-  { N_("ZWS _Zero width space"), 0x200B },
-  { N_("ZWJ Zero width _joiner"), 0x200D },
-  { N_("ZWNJ Zero width _non-joiner"), 0x200C }
-};
-
-static void insertControlCharacter(GtkWidget* widget)
+static int getUnicodeMenuItemPosition(GtkMenu* menu)
 {
-    // GtkUnicodeMenuEntry* entry = (GtkUnicodeMenuEntry*)g_object_get_data(G_OBJECT(widget), "gtk-unicode-menu-entry");
-    notImplemented();
-}
-
-static GtkWidget* unicodeMenuItem(WebKitWebView* webView)
-{
-    if (gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 10)) {
-        GtkSettings* settings = webView ? gtk_widget_get_settings(GTK_WIDGET(webView)) : gtk_settings_get_default();
-
-        gboolean showMenu = TRUE;
-        if (settings)
-            g_object_get(settings, "gtk-show-unicode-menu", &showMenu, NULL);
-        if (!showMenu)
-            return 0;
-    }
-
-    GtkWidget* menuitem = gtk_image_menu_item_new_with_mnemonic(
-        _("_Insert Unicode Control Character"));
-
-    GtkWidget* unicodeContextMenu = gtk_menu_new();
-    unsigned i;
-    for (i = 0; i < G_N_ELEMENTS(bidi_menu_entries); i++) {
-        GtkWidget* menuitem = gtk_menu_item_new_with_mnemonic(_(bidi_menu_entries[i].label));
-        g_object_set_data(G_OBJECT(menuitem), "gtk-unicode-menu-entry", (gpointer)&bidi_menu_entries[i]);
-        g_signal_connect(menuitem, "activate", G_CALLBACK(insertControlCharacter), 0);
-        gtk_widget_show(menuitem);
-        gtk_menu_shell_append(GTK_MENU_SHELL(unicodeContextMenu), menuitem);
-        // FIXME: Make the item sensitive as insertControlCharacter() is implemented
-        gtk_widget_set_sensitive(menuitem, FALSE);
+    GOwnPtr<GList> items(gtk_container_get_children(GTK_CONTAINER(menu)));
+    int unicodeMenuItemPosition = -1;
+    GList* iter;
+    int i = 0;
+    for (iter = items.get(), i = 0; iter; iter = g_list_next(iter), ++i) {
+        GtkMenuItem* item = GTK_MENU_ITEM(iter->data);
+        if (GTK_IS_SEPARATOR_MENU_ITEM(item))
+            continue;
+        if (String::fromUTF8(gtk_menu_item_get_label(item)) == contextMenuItemTagUnicode()) {
+            unicodeMenuItemPosition = i;
+            break;
+        }
     }
-
-    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), unicodeContextMenu);
-
-    return menuitem;
+    return unicodeMenuItemPosition;
 }
 
 PlatformMenuDescription ContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu* menu)
@@ -134,26 +97,21 @@ PlatformMenuDescription ContextMenuClient::getCustomMenuFromDefaultItems(Context
     HitTestResult result = core(webView)->contextMenuController()->hitTestResult();
 
     if (result.isContentEditable()) {
-
         GtkWidget* imContextMenu = inputMethodsMenuItem(webView);
-        GtkWidget* unicodeContextMenu = unicodeMenuItem(webView);
+        if (!imContextMenu)
+            return gtkmenu;
 
-        if (imContextMenu || unicodeContextMenu) {
+        // Place the im context menu item right before the unicode menu item
+        // if it's present.
+        int unicodeMenuItemPosition = getUnicodeMenuItemPosition(gtkmenu);
+        if (unicodeMenuItemPosition == -1) {
             GtkWidget* separator = gtk_separator_menu_item_new();
             gtk_menu_shell_append(GTK_MENU_SHELL(gtkmenu), separator);
             gtk_widget_show(separator);
         }
 
-        if (imContextMenu) {
-            gtk_menu_shell_append(GTK_MENU_SHELL(gtkmenu), imContextMenu);
-            gtk_widget_show(imContextMenu);
-        }
-
-        if (unicodeContextMenu) {
-            gtk_menu_shell_append(GTK_MENU_SHELL(gtkmenu), unicodeContextMenu);
-            gtk_widget_show(unicodeContextMenu);
-        }
-
+        gtk_menu_shell_insert(GTK_MENU_SHELL(gtkmenu), imContextMenu, unicodeMenuItemPosition);
+        gtk_widget_show(imContextMenu);
     }
 
     return gtkmenu;
index b8e160e..120b03b 100644 (file)
@@ -133,6 +133,21 @@ void EditorClient::setInputMethodState(bool active)
 #endif
 }
 
+bool EditorClient::shouldShowUnicodeMenu()
+{
+    if (gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 10)) {
+        GtkSettings* settings = gtk_widget_get_settings(GTK_WIDGET(m_webView));
+        if (!settings)
+            return true;
+
+        gboolean enabled;
+        g_object_get(settings, "gtk-show-unicode-menu", &enabled, NULL);
+        return enabled;
+    }
+
+    return true;
+}
+
 bool EditorClient::shouldDeleteRange(Range* range)
 {
     gboolean accept = TRUE;
index ef159c6..2f08d8d 100644 (file)
@@ -137,6 +137,8 @@ class EditorClient : public WebCore::EditorClient {
         virtual void willSetInputMethodState();
         virtual void setInputMethodState(bool enabled);
 
+        virtual bool shouldShowUnicodeMenu();
+
     private:
 #if ENABLE(SPELLCHECK)
         TextCheckerClientGtk m_textCheckerClient;
index 32a78d4..2bd3cd4 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Implement unicode submenu items
+        https://bugs.webkit.org/show_bug.cgi?id=81117
+
+        Reviewed by Martin Robinson.
+
+        * WebProcess/WebCoreSupport/WebEditorClient.h:
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::WebEditorClient::shouldShowUnicodeMenu): Implement
+        shouldShowUnicodeMenu() returning always true. When ContextMenu
+        API is implemented for GTK+ the UI process will decide whether to
+        show the unicode menu or not.
+
 2012-03-15  Andras Becsi  <andras.becsi@nokia.com>
 
         [Qt][WK2] Fix bounce-back behaviour for panning
index 010cd4b..78ea8db 100644 (file)
@@ -148,6 +148,9 @@ private:
     virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel) OVERRIDE;
     virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) OVERRIDE;
 #endif
+#if PLATFORM(GTK)
+    virtual bool shouldShowUnicodeMenu() OVERRIDE;
+#endif
     WebPage* m_page;
 };
 
index 9f34530..e33d723 100644 (file)
@@ -194,5 +194,9 @@ void WebEditorClient::setSelectionPrimaryClipboardIfNeeded(Frame* frame)
 #endif
 }
 
+bool WebEditorClient::shouldShowUnicodeMenu()
+{
+    return true;
+}
 
 }