⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245460 in webkit


Ignore:
Timestamp:
May 17, 2019, 5:39:30 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Need WebKitContextMenuItemType to open emoji picker
https://bugs.webkit.org/show_bug.cgi?id=176760

Reviewed by Michael Catanzaro.

Source/WebCore:

Add a new context menu item to insert an emoji.

  • loader/EmptyClients.cpp: Empty implementation of ContextMenuClient::insertEmoji().
  • page/ContextMenuClient.h: Add insertEmoji for GTK port.
  • page/ContextMenuController.cpp:

(WebCore::ContextMenuController::contextMenuItemSelected): Handle insert emoji action.
(WebCore::ContextMenuController::populate): Add insert emoji item after select all.
(WebCore::ContextMenuController::checkOrEnableIfNeeded const): Handle insert emoji action.

  • platform/ContextMenuItem.h: Add insert emoji action.
  • platform/LocalizedStrings.h:
  • platform/gtk/LocalizedStringsGtk.cpp:

(WebCore::contextMenuItemTagInsertEmoji):

Source/WebCore/platform/gtk/po:

  • POTFILES.in: Add WebKitEmojiChooser.cpp.

Source/WebKit:

Add a default implementation to show the emoji chooser when requested by the application, either using the
context menu or keyboard shortcuts. GtkEmojiChooser is private in GTK, so we include our own copy, adapted to
the WebKit coding style. The emoji chooser is always shown by default when using GTK >= 3.24 for any editable
content. I'm going to add public API in a follow up patch to be able to use your own chooser, or even prevent
the default chooser from being shown, similar to what we do for other UI elements like file chooser, color
chooser, print dialog, etc.

  • Shared/API/glib/WebKitContextMenuActions.cpp:

(webkitContextMenuActionGetActionTag): Handle insert emoji action.
(webkitContextMenuActionGetForContextMenuItem): Ditto.
(webkitContextMenuActionGetLabel): Ditto.

  • SourcesGTK.txt:
  • UIProcess/API/gtk/WebKitContextMenuActions.h:
  • UIProcess/API/gtk/WebKitEmojiChooser.cpp: Added.

(webkitEmojiChooserAddEmoji):
(webkitEmojiChooserAddRecentItem):
(emojiActivated):
(emojiDataHasVariations):
(webkitEmojiChooserShowVariations):
(emojiLongPressed):
(emojiPressed):
(emojiPopupMenu):
(verticalAdjustmentChanged):
(webkitEmojiChooserSetupSectionBox):
(scrollToSection):
(webkitEmojiChooserSetupSectionButton):
(webkitEmojiChooserSetupRecent):
(webkitEmojiChooserEnsureEmptyResult):
(webkitEmojiChooserSearchChanged):
(webkitEmojiChooserSetupFilters):
(webkitEmojiChooserInitializeEmojiMaxWidth):
(webkitEmojiChooserConstructed):
(webkitEmojiChooserShow):
(webkit_emoji_chooser_class_init):
(webkitEmojiChooserNew):

  • UIProcess/API/gtk/WebKitEmojiChooser.h: Added.
  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(_WebKitWebViewBasePrivate::_WebKitWebViewBasePrivate): Add a timer to release the emoji chooser if not used
after 2 minutes.
(_WebKitWebViewBasePrivate::releaseEmojiChooserTimerFired): Destroy the emoji chooser.
(emojiChooserEmojiPicked): Complete the operation using the given emoji text.
(emojiChooserClosed): Complete the operation if needed using an empty string.
(webkitWebViewBaseShowEmojiChooser): Create the emoji chooser if needed and show it.

  • UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
  • UIProcess/WebPageProxy.h: Add showEmojiPicker().
  • UIProcess/WebPageProxy.messages.in: Add ShowEmojiPicker message.
  • UIProcess/gtk/KeyBindingTranslator.cpp:

(WebKit::insertEmojiCallback): Add GtkInsertEmoji command.
(WebKit::KeyBindingTranslator::KeyBindingTranslator): Connect to insert-emoji signal.

  • UIProcess/gtk/WebPageProxyGtk.cpp:

(WebKit::WebPageProxy::showEmojiPicker): Call webkitWebViewBaseShowEmojiChooser().

  • WebProcess/WebCoreSupport/WebContextMenuClient.h: Override insertEmoji() for GTK port.
  • WebProcess/WebCoreSupport/WebEditorClient.h: Add insertEmoji() for GTK port.
  • WebProcess/WebCoreSupport/gtk/WebContextMenuClientGtk.cpp:

(WebKit::WebContextMenuClient::insertEmoji): Call WebPage::showEmojiPicker().

  • WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:

(WebKit::WebEditorClient::handleGtkEditorCommand): Call WebPage::showEmojiPicker() if command is GtkInsertEmoji.
(WebKit::WebEditorClient::executePendingEditorCommands): Handle Gtk specific commands.
(WebKit::WebEditorClient::handleKeyboardEvent): Use a reference instead of a pointer for Frame.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/gtk/WebPageGtk.cpp:

(WebKit::WebPage::showEmojiPicker): Send ShowEmojiPicker message to the UI process.

Tools:

Update context menu test to check insert emoji action is included in default context menu for editable content.

  • TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
Location:
trunk
Files:
2 added
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r245429 r245460  
     12019-05-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Need WebKitContextMenuItemType to open emoji picker
     4        https://bugs.webkit.org/show_bug.cgi?id=176760
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add a new context menu item to insert an emoji.
     9
     10        * loader/EmptyClients.cpp: Empty implementation of ContextMenuClient::insertEmoji().
     11        * page/ContextMenuClient.h: Add insertEmoji for GTK port.
     12        * page/ContextMenuController.cpp:
     13        (WebCore::ContextMenuController::contextMenuItemSelected): Handle insert emoji action.
     14        (WebCore::ContextMenuController::populate): Add insert emoji item after select all.
     15        (WebCore::ContextMenuController::checkOrEnableIfNeeded const): Handle insert emoji action.
     16        * platform/ContextMenuItem.h: Add insert emoji action.
     17        * platform/LocalizedStrings.h:
     18        * platform/gtk/LocalizedStringsGtk.cpp:
     19        (WebCore::contextMenuItemTagInsertEmoji):
     20
    1212019-05-16  Greg Doolittle  <gr3g@apple.com>
    222
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r244932 r245460  
    110110#endif
    111111
     112#if PLATFORM(GTK)
     113    void insertEmoji(Frame&) final { }
     114#endif
     115
    112116#if USE(ACCESSIBILITY_CONTEXT_MENUS)
    113117    void showContextMenu() final { }
  • trunk/Source/WebCore/page/ContextMenuClient.h

    r238771 r245460  
    5050#endif
    5151
     52#if PLATFORM(GTK)
     53    virtual void insertEmoji(Frame&) = 0;
     54#endif
     55
    5256#if USE(ACCESSIBILITY_CONTEXT_MENUS)
    5357    virtual void showContextMenu() = 0;
  • trunk/Source/WebCore/page/ContextMenuController.cpp

    r242749 r245460  
    358358        insertUnicodeCharacter(zeroWidthNonJoiner, *frame);
    359359        break;
    360 #endif
    361 #if PLATFORM(GTK)
    362360    case ContextMenuItemTagSelectAll:
    363361        frame->editor().command("SelectAll").execute();
     362        break;
     363    case ContextMenuItemTagInsertEmoji:
     364        m_client.insertEmoji(*frame);
    364365        break;
    365366#endif
     
    812813#if PLATFORM(GTK)
    813814    ContextMenuItem DeleteItem(ActionType, ContextMenuItemTagDelete, contextMenuItemTagDelete());
    814 #endif
    815 #if PLATFORM(GTK)
    816815    ContextMenuItem SelectAllItem(ActionType, ContextMenuItemTagSelectAll, contextMenuItemTagSelectAll());
     816    ContextMenuItem InsertEmojiItem(ActionType, ContextMenuItemTagInsertEmoji, contextMenuItemTagInsertEmoji());
    817817#endif
    818818
     
    10501050        appendItem(DeleteItem, m_contextMenu.get());
    10511051        appendItem(*separatorItem(), m_contextMenu.get());
    1052 #endif
    1053 #if PLATFORM(GTK)
    10541052        appendItem(SelectAllItem, m_contextMenu.get());
     1053        appendItem(InsertEmojiItem, m_contextMenu.get());
    10551054#endif
    10561055
     
    12071206            shouldEnable = frame->editor().canDelete();
    12081207            break;
     1208        case ContextMenuItemTagInsertEmoji:
     1209            shouldEnable = frame->editor().canEdit();
     1210            break;
     1211        case ContextMenuItemTagSelectAll:
    12091212        case ContextMenuItemTagInputMethods:
    12101213        case ContextMenuItemTagUnicode:
     
    12191222        case ContextMenuItemTagUnicodeInsertZWJMark:
    12201223        case ContextMenuItemTagUnicodeInsertZWNJMark:
    1221             shouldEnable = true;
    1222             break;
    1223 #endif
    1224 #if PLATFORM(GTK)
    1225         case ContextMenuItemTagSelectAll:
    12261224            shouldEnable = true;
    12271225            break;
  • trunk/Source/WebCore/platform/ContextMenuItem.h

    r238771 r245460  
    6969    ContextMenuItemTagUnicodeInsertZWJMark,
    7070    ContextMenuItemTagUnicodeInsertZWNJMark,
     71    ContextMenuItemTagInsertEmoji,
    7172#endif
    7273    ContextMenuItemTagSpellingGuess,
  • trunk/Source/WebCore/platform/LocalizedStrings.h

    r244404 r245460  
    8484    String contextMenuItemTagUnicodeInsertZWJMark();
    8585    String contextMenuItemTagUnicodeInsertZWNJMark();
    86 #endif
    87 #if PLATFORM(GTK)
    8886    String contextMenuItemTagSelectAll();
     87    String contextMenuItemTagInsertEmoji();
    8988#endif
    9089    String contextMenuItemTagNoGuessesFound();
  • trunk/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp

    r238406 r245460  
    9999}
    100100
     101String contextMenuItemTagInsertEmoji()
     102{
     103    return String::fromUTF8(_("Insert _Emoji"));
     104}
     105
    101106String contextMenuItemTagUnicode()
    102107{
  • trunk/Source/WebCore/platform/gtk/po/ChangeLog

    r244805 r245460  
     12019-05-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Need WebKitContextMenuItemType to open emoji picker
     4        https://bugs.webkit.org/show_bug.cgi?id=176760
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * POTFILES.in: Add WebKitEmojiChooser.cpp.
     9
    1102019-04-30  Álvaro Torralba  <donfrutosgomez@gmail.com>
    211
  • trunk/Source/WebCore/platform/gtk/po/POTFILES.in

    r243409 r245460  
    3232../../../WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp
    3333../../../WebKit/UIProcess/API/gtk/WebKitColorChooserRequest.cpp
     34../../../WebKit/UIProcess/API/gtk/WebKitEmojiChooser.cpp
    3435../../../WebKit/UIProcess/API/gtk/WebKitPrintCustomWidget.cpp
    3536../../../WebKit/UIProcess/API/gtk/WebKitPrintOperation.cpp
  • trunk/Source/WebKit/ChangeLog

    r245427 r245460  
     12019-05-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Need WebKitContextMenuItemType to open emoji picker
     4        https://bugs.webkit.org/show_bug.cgi?id=176760
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add a default implementation to show the emoji chooser when requested by the application, either using the
     9        context menu or keyboard shortcuts. GtkEmojiChooser is private in GTK, so we include our own copy, adapted to
     10        the WebKit coding style. The emoji chooser is always shown by default when using GTK >= 3.24 for any editable
     11        content. I'm going to add public API in a follow up patch to be able to use your own chooser, or even prevent
     12        the default chooser from being shown, similar to what we do for other UI elements like file chooser, color
     13        chooser, print dialog, etc.
     14
     15        * Shared/API/glib/WebKitContextMenuActions.cpp:
     16        (webkitContextMenuActionGetActionTag): Handle insert emoji action.
     17        (webkitContextMenuActionGetForContextMenuItem): Ditto.
     18        (webkitContextMenuActionGetLabel): Ditto.
     19        * SourcesGTK.txt:
     20        * UIProcess/API/gtk/WebKitContextMenuActions.h:
     21        * UIProcess/API/gtk/WebKitEmojiChooser.cpp: Added.
     22        (webkitEmojiChooserAddEmoji):
     23        (webkitEmojiChooserAddRecentItem):
     24        (emojiActivated):
     25        (emojiDataHasVariations):
     26        (webkitEmojiChooserShowVariations):
     27        (emojiLongPressed):
     28        (emojiPressed):
     29        (emojiPopupMenu):
     30        (verticalAdjustmentChanged):
     31        (webkitEmojiChooserSetupSectionBox):
     32        (scrollToSection):
     33        (webkitEmojiChooserSetupSectionButton):
     34        (webkitEmojiChooserSetupRecent):
     35        (webkitEmojiChooserEnsureEmptyResult):
     36        (webkitEmojiChooserSearchChanged):
     37        (webkitEmojiChooserSetupFilters):
     38        (webkitEmojiChooserInitializeEmojiMaxWidth):
     39        (webkitEmojiChooserConstructed):
     40        (webkitEmojiChooserShow):
     41        (webkit_emoji_chooser_class_init):
     42        (webkitEmojiChooserNew):
     43        * UIProcess/API/gtk/WebKitEmojiChooser.h: Added.
     44        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     45        (_WebKitWebViewBasePrivate::_WebKitWebViewBasePrivate): Add a timer to release the emoji chooser if not used
     46        after 2 minutes.
     47        (_WebKitWebViewBasePrivate::releaseEmojiChooserTimerFired): Destroy the emoji chooser.
     48        (emojiChooserEmojiPicked): Complete the operation using the given emoji text.
     49        (emojiChooserClosed): Complete the operation if needed using an empty string.
     50        (webkitWebViewBaseShowEmojiChooser): Create the emoji chooser if needed and show it.
     51        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
     52        * UIProcess/WebPageProxy.h: Add showEmojiPicker().
     53        * UIProcess/WebPageProxy.messages.in: Add ShowEmojiPicker message.
     54        * UIProcess/gtk/KeyBindingTranslator.cpp:
     55        (WebKit::insertEmojiCallback): Add GtkInsertEmoji command.
     56        (WebKit::KeyBindingTranslator::KeyBindingTranslator): Connect to insert-emoji signal.
     57        * UIProcess/gtk/WebPageProxyGtk.cpp:
     58        (WebKit::WebPageProxy::showEmojiPicker): Call webkitWebViewBaseShowEmojiChooser().
     59        * WebProcess/WebCoreSupport/WebContextMenuClient.h: Override insertEmoji() for GTK port.
     60        * WebProcess/WebCoreSupport/WebEditorClient.h: Add insertEmoji() for GTK port.
     61        * WebProcess/WebCoreSupport/gtk/WebContextMenuClientGtk.cpp:
     62        (WebKit::WebContextMenuClient::insertEmoji): Call WebPage::showEmojiPicker().
     63        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
     64        (WebKit::WebEditorClient::handleGtkEditorCommand): Call WebPage::showEmojiPicker() if command is GtkInsertEmoji.
     65        (WebKit::WebEditorClient::executePendingEditorCommands): Handle Gtk specific commands.
     66        (WebKit::WebEditorClient::handleKeyboardEvent): Use a reference instead of a pointer for Frame.
     67        * WebProcess/WebPage/WebPage.h:
     68        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
     69        (WebKit::WebPage::showEmojiPicker): Send ShowEmojiPicker message to the UI process.
     70
    1712019-05-16  John Wilander  <wilander@apple.com>
    272
  • trunk/Source/WebKit/Shared/API/glib/WebKitContextMenuActions.cpp

    r218553 r245460  
    8484    case WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL:
    8585        return ContextMenuItemTagSelectAll;
     86    case WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI:
     87        return ContextMenuItemTagInsertEmoji;
    8688    case WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS:
    8789        return ContextMenuItemTagInputMethods;
     
    184186    case ContextMenuItemTagSelectAll:
    185187        return WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL;
     188    case ContextMenuItemTagInsertEmoji:
     189        return WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI;
    186190    case ContextMenuItemTagInputMethods:
    187191        return WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS;
     
    282286    case WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL:
    283287        return contextMenuItemTagSelectAll();
     288    case WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI:
     289        return contextMenuItemTagInsertEmoji();
    284290    case WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS:
    285291        return contextMenuItemTagInputMethods();
  • trunk/Source/WebKit/SourcesGTK.txt

    r245241 r245460  
    190190UIProcess/API/gtk/WebKitColorChooser.cpp @no-unify
    191191UIProcess/API/gtk/WebKitColorChooserRequest.cpp @no-unify
     192UIProcess/API/gtk/WebKitEmojiChooser.cpp @no-unify
    192193UIProcess/API/gtk/WebKitOptionMenu.cpp @no-unify
    193194UIProcess/API/gtk/WebKitOptionMenuItem.cpp @no-unify
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitContextMenuActions.h

    r213703 r245460  
    7575 * @WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK: Download video to disk. Since 2.2
    7676 * @WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK: Download audio to disk. Since 2.2
     77 * @WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI: Insert an emoji. Since 2.26
    7778 * @WEBKIT_CONTEXT_MENU_ACTION_CUSTOM: Custom action defined by applications.
    7879 *
     
    126127    WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK,
    127128    WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK,
     129    WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI,
    128130
    129131    WEBKIT_CONTEXT_MENU_ACTION_CUSTOM = 10000
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r245065 r245460  
    4343#include "WebInspectorProxy.h"
    4444#include "WebKit2Initialize.h"
     45#include "WebKitEmojiChooser.h"
    4546#include "WebKitWebViewBaseAccessible.h"
    4647#include "WebKitWebViewBasePrivate.h"
     
    6869#include <wtf/HashMap.h>
    6970#include <wtf/glib/GRefPtr.h>
     71#include <wtf/glib/RunLoopSourcePriority.h>
    7072#include <wtf/glib/WTFGType.h>
    7173#include <wtf/text/CString.h>
     
    148150    _WebKitWebViewBasePrivate()
    149151        : updateActivityStateTimer(RunLoop::main(), this, &_WebKitWebViewBasePrivate::updateActivityStateTimerFired)
     152#if GTK_CHECK_VERSION(3, 24, 0)
     153        , releaseEmojiChooserTimer(RunLoop::main(), this, &_WebKitWebViewBasePrivate::releaseEmojiChooserTimerFired)
     154#endif
    150155    {
     156#if GTK_CHECK_VERSION(3, 24, 0)
     157        releaseEmojiChooserTimer.setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer);
     158#endif
    151159    }
    152160
     
    158166        activityStateFlagsToUpdate = { };
    159167    }
     168
     169#if GTK_CHECK_VERSION(3, 24, 0)
     170    void releaseEmojiChooserTimerFired()
     171    {
     172        if (emojiChooser) {
     173            gtk_widget_destroy(emojiChooser);
     174            emojiChooser = nullptr;
     175        }
     176    }
     177#endif
    160178
    161179    WebKitWebViewChildrenMap children;
     
    208226    std::unique_ptr<ViewGestureController> viewGestureController;
    209227    bool isBackForwardNavigationGestureEnabled { false };
     228
     229#if GTK_CHECK_VERSION(3, 24, 0)
     230    GtkWidget* emojiChooser;
     231    CompletionHandler<void(String)> emojiChooserCompletionHandler;
     232    RunLoop::Timer<WebKitWebViewBasePrivate> releaseEmojiChooserTimer;
     233#endif
    210234};
    211235
     
    526550}
    527551
     552#if GTK_CHECK_VERSION(3, 24, 0)
     553static void webkitWebViewBaseCompleteEmojiChooserRequest(WebKitWebViewBase* webView, const String& text)
     554{
     555    if (auto completionHandler = std::exchange(webView->priv->emojiChooserCompletionHandler, nullptr))
     556        completionHandler(text);
     557}
     558#endif
     559
    528560static void webkitWebViewBaseDispose(GObject* gobject)
    529561{
    530562    WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(gobject);
    531563    webkitWebViewBaseSetToplevelOnScreenWindow(webView, nullptr);
     564#if GTK_CHECK_VERSION(3, 24, 0)
     565    webkitWebViewBaseCompleteEmojiChooserRequest(webView, emptyString());
     566#endif
    532567    webView->priv->pageProxy->close();
    533568    webView->priv->acceleratedBackingStore = nullptr;
     
    17551790        webkitWebViewBase->priv->viewGestureController->didRestoreScrollPosition();
    17561791}
     1792
     1793#if GTK_CHECK_VERSION(3, 24, 0)
     1794static void emojiChooserEmojiPicked(WebKitWebViewBase* webkitWebViewBase, const char* text)
     1795{
     1796    webkitWebViewBaseCompleteEmojiChooserRequest(webkitWebViewBase, String::fromUTF8(text));
     1797}
     1798
     1799static void emojiChooserClosed(WebKitWebViewBase* webkitWebViewBase)
     1800{
     1801    webkitWebViewBaseCompleteEmojiChooserRequest(webkitWebViewBase, emptyString());
     1802    webkitWebViewBase->priv->releaseEmojiChooserTimer.startOneShot(2_min);
     1803}
     1804#endif
     1805
     1806void webkitWebViewBaseShowEmojiChooser(WebKitWebViewBase* webkitWebViewBase, const IntRect& caretRect, CompletionHandler<void(String)>&& completionHandler)
     1807{
     1808#if GTK_CHECK_VERSION(3, 24, 0)
     1809    WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
     1810    priv->releaseEmojiChooserTimer.stop();
     1811
     1812    if (!priv->emojiChooser) {
     1813        priv->emojiChooser = webkitEmojiChooserNew();
     1814        g_signal_connect_swapped(priv->emojiChooser, "emoji-picked", G_CALLBACK(emojiChooserEmojiPicked), webkitWebViewBase);
     1815        g_signal_connect_swapped(priv->emojiChooser, "closed", G_CALLBACK(emojiChooserClosed), webkitWebViewBase);
     1816        gtk_popover_set_relative_to(GTK_POPOVER(priv->emojiChooser), GTK_WIDGET(webkitWebViewBase));
     1817    }
     1818
     1819    priv->emojiChooserCompletionHandler = WTFMove(completionHandler);
     1820
     1821    GdkRectangle gdkCaretRect = caretRect;
     1822    gtk_popover_set_pointing_to(GTK_POPOVER(priv->emojiChooser), &gdkCaretRect);
     1823    gtk_popover_popup(GTK_POPOVER(priv->emojiChooser));
     1824#else
     1825    UNUSED_PARAM(webkitWebViewBase);
     1826    UNUSED_PARAM(caretRect);
     1827    completionHandler(emptyString());
     1828#endif
     1829}
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h

    r244744 r245460  
    9494void webkitWebViewBaseDidSameDocumentNavigationForMainFrame(WebKitWebViewBase*, WebKit::SameDocumentNavigationType);
    9595void webkitWebViewBaseDidRestoreScrollPosition(WebKitWebViewBase*);
     96
     97void webkitWebViewBaseShowEmojiChooser(WebKitWebViewBase*, const WebCore::IntRect&, CompletionHandler<void(String)>&&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r245335 r245460  
    17751775    void getEditorCommandsForKeyEvent(const AtomicString&, Vector<String>&);
    17761776    void bindAccessibilityTree(const String&);
     1777    void showEmojiPicker(const WebCore::IntRect&, CompletionHandler<void(String)>&&);
    17771778#endif
    17781779
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r244633 r245460  
    564564
    565565    ConfigureLoggingChannel(String channelName, enum:uint8_t WTFLogChannelState state, enum:uint8_t WTFLogLevel level)
     566
     567#if PLATFORM(GTK)
     568    ShowEmojiPicker(WebCore::IntRect caretRect) -> (String result) Async
     569#endif
    566570}
  • trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp

    r194496 r245460  
    6060    translator->addPendingEditorCommand("OverWrite");
    6161}
     62
     63#if GTK_CHECK_VERSION(3, 24, 0)
     64static void insertEmojiCallback(GtkWidget* widget, KeyBindingTranslator* translator)
     65{
     66    g_signal_stop_emission_by_name(widget, "insert-emoji");
     67    translator->addPendingEditorCommand("GtkInsertEmoji");
     68}
     69#endif
    6270
    6371// GTK+ will still send these signals to the web view. So we can safely stop signal
     
    174182    g_signal_connect(m_nativeWidget.get(), "popup-menu", G_CALLBACK(popupMenuCallback), this);
    175183    g_signal_connect(m_nativeWidget.get(), "show-help", G_CALLBACK(showHelpCallback), this);
     184#if GTK_CHECK_VERSION(3, 24, 0)
     185    g_signal_connect(m_nativeWidget.get(), "insert-emoji", G_CALLBACK(insertEmojiCallback), this);
     186#endif
    176187}
    177188
  • trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp

    r244897 r245460  
    164164}
    165165
     166void WebPageProxy::showEmojiPicker(const WebCore::IntRect& caretRect, CompletionHandler<void(String)>&& completionHandler)
     167{
     168    webkitWebViewBaseShowEmojiChooser(WEBKIT_WEB_VIEW_BASE(viewWidget()), caretRect, WTFMove(completionHandler));
     169}
     170
    166171} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h

    r238771 r245460  
    5656#endif
    5757
     58#if PLATFORM(GTK)
     59    void insertEmoji(WebCore::Frame&) override;
     60#endif
     61
    5862#if USE(ACCESSIBILITY_CONTEXT_MENUS)
    5963    void showContextMenu() override;
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h

    r244932 r245460  
    141141
    142142#if PLATFORM(GTK)
    143     bool executePendingEditorCommands(WebCore::Frame*, const Vector<WTF::String>&, bool);
     143    bool executePendingEditorCommands(WebCore::Frame&, const Vector<WTF::String>&, bool);
     144    bool handleGtkEditorCommand(WebCore::Frame&, const String& command, bool);
    144145    void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&);
    145146    void updateGlobalSelection(WebCore::Frame*);
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebContextMenuClientGtk.cpp

    r228373 r245460  
    3030#if ENABLE(CONTEXT_MENUS)
    3131
     32#include "WebPage.h"
    3233#include <WebCore/NotImplemented.h>
    3334
     
    5657}
    5758
     59void WebContextMenuClient::insertEmoji(Frame& frame)
     60{
     61    m_page->showEmojiPicker(frame);
     62}
     63
    5864} // namespace WebKit
    5965#endif // ENABLE(CONTEXT_MENUS)
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp

    r244932 r245460  
    2929#include <WebCore/PlatformKeyboardEvent.h>
    3030#include <WebCore/markup.h>
     31#include <wtf/Variant.h>
    3132#include <wtf/glib/GRefPtr.h>
    3233
     
    3435using namespace WebCore;
    3536
    36 bool WebEditorClient::executePendingEditorCommands(Frame* frame, const Vector<WTF::String>& pendingEditorCommands, bool allowTextInsertion)
     37bool WebEditorClient::handleGtkEditorCommand(Frame& frame, const String& command, bool allowTextInsertion)
    3738{
    38     Vector<Editor::Command> commands;
    39     for (auto& commandString : pendingEditorCommands) {
    40         Editor::Command command = frame->editor().command(commandString);
    41         if (command.isTextInsertion() && !allowTextInsertion)
     39    if (command == "GtkInsertEmoji"_s) {
     40        if (!allowTextInsertion)
    4241            return false;
    43 
    44         commands.append(WTFMove(command));
     42        m_page->showEmojiPicker(frame);
     43        return true;
    4544    }
    4645
    47     for (auto& command : commands) {
    48         if (!command.execute())
    49             return false;
     46    return false;
     47}
     48
     49bool WebEditorClient::executePendingEditorCommands(Frame& frame, const Vector<WTF::String>& pendingEditorCommands, bool allowTextInsertion)
     50{
     51    Vector<Variant<Editor::Command, String>> commands;
     52    for (auto& commandString : pendingEditorCommands) {
     53        if (commandString.startsWith("Gtk"))
     54            commands.append(commandString);
     55        else {
     56            Editor::Command command = frame.editor().command(commandString);
     57            if (command.isTextInsertion() && !allowTextInsertion)
     58                return false;
     59
     60            commands.append(WTFMove(command));
     61        }
     62    }
     63
     64    for (auto& commandVariant : commands) {
     65        if (WTF::holds_alternative<String>(commandVariant)) {
     66            if (!handleGtkEditorCommand(frame, WTF::get<String>(commandVariant), allowTextInsertion))
     67                return false;
     68        } else {
     69            auto& command = WTF::get<Editor::Command>(commandVariant);
     70            if (!command.execute())
     71                return false;
     72        }
    5073    }
    5174
     
    7497        // through the DOM first.
    7598        if (platformEvent->type() == PlatformEvent::RawKeyDown) {
    76             if (executePendingEditorCommands(frame, pendingEditorCommands, false))
     99            if (executePendingEditorCommands(*frame, pendingEditorCommands, false))
    77100                event.setDefaultHandled();
    78101
     
    81104
    82105        // Only allow text insertion commands if the current node is editable.
    83         if (executePendingEditorCommands(frame, pendingEditorCommands, frame->editor().canEdit())) {
     106        if (executePendingEditorCommands(*frame, pendingEditorCommands, frame->editor().canEdit())) {
    84107            event.setDefaultHandled();
    85108            return;
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r245366 r245460  
    764764
    765765    void collapseSelectionInFrame(uint64_t frameID);
     766    void showEmojiPicker(WebCore::Frame&);
    766767#endif
    767768
  • trunk/Source/WebKit/WebProcess/WebPage/gtk/WebPageGtk.cpp

    r245072 r245460  
    196196}
    197197
     198void WebPage::showEmojiPicker(Frame& frame)
     199{
     200    CompletionHandler<void(String)> completionHandler = [frame = makeRef(frame)](String result) {
     201        if (!result.isEmpty())
     202            frame->editor().insertText(result, nullptr);
     203    };
     204    sendWithAsyncReply(Messages::WebPageProxy::ShowEmojiPicker(frame.selection().absoluteCaretBounds()), WTFMove(completionHandler));
     205}
     206
    198207void WebPage::effectiveAppearanceDidChange(bool useDarkAppearance, bool useInactiveAppearance)
    199208{
  • trunk/Tools/ChangeLog

    r245433 r245460  
     12019-05-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Need WebKitContextMenuItemType to open emoji picker
     4        https://bugs.webkit.org/show_bug.cgi?id=176760
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Update context menu test to check insert emoji action is included in default context menu for editable content.
     9
     10        * TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
     11
    1122019-05-16  Aakash Jain  <aakash_jain@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp

    r239772 r245460  
    403403            iter = checkCurrentItemIsSeparatorAndGetNext(iter);
    404404            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL, Visible | Enabled);
     405            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI, Visible | Enabled);
    405406            iter = checkCurrentItemIsSeparatorAndGetNext(iter);
    406407            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE, Visible | Enabled);
Note: See TracChangeset for help on using the changeset viewer.