Title: [261800] trunk
Revision
261800
Author
commit-qu...@webkit.org
Date
2020-05-18 00:37:28 -0700 (Mon, 18 May 2020)

Log Message

[GTK] Add WebKitContextMenuItemType for paste as plaintext
https://bugs.webkit.org/show_bug.cgi?id=177638

Patch by Carlos Garcia Campos <cgar...@igalia.com> on 2020-05-18
Reviewed by Michael Catanzaro.

Source/WebCore:

Add paste as plain text context menu item for rich editable content.

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
(WebCore::ContextMenuController::populate):
(WebCore::ContextMenuController::checkOrEnableIfNeeded const):
* platform/ContextMenuItem.h:
* platform/LocalizedStrings.h:
* platform/gtk/LocalizedStringsGtk.cpp:
(WebCore::contextMenuItemTagPasteAsPlainText):

Source/WebKit:

Add WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT.

* Shared/API/glib/WebKitContextMenuActions.cpp:
(webkitContextMenuActionGetActionTag):
(webkitContextMenuActionGetForContextMenuItem):
(webkitContextMenuActionGetLabel):
* UIProcess/API/gtk/WebKitContextMenuActions.h:
* UIProcess/gtk/KeyBindingTranslator.cpp:

Tools:

Update default context menu test case to also test the context menu for rich editable content.

* TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
(prepareContextMenuTestView):
(testContextMenuDefaultMenu):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (261799 => 261800)


--- trunk/Source/WebCore/ChangeLog	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebCore/ChangeLog	2020-05-18 07:37:28 UTC (rev 261800)
@@ -1,3 +1,21 @@
+2020-05-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitContextMenuItemType for paste as plaintext
+        https://bugs.webkit.org/show_bug.cgi?id=177638
+
+        Reviewed by Michael Catanzaro.
+
+        Add paste as plain text context menu item for rich editable content.
+
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::contextMenuItemSelected):
+        (WebCore::ContextMenuController::populate):
+        (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
+        * platform/ContextMenuItem.h:
+        * platform/LocalizedStrings.h:
+        * platform/gtk/LocalizedStringsGtk.cpp:
+        (WebCore::contextMenuItemTagPasteAsPlainText):
+
 2020-05-17  Simon Fraser  <simon.fra...@apple.com>
 
         Fix operator== and hash() for ExtendedColor

Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (261799 => 261800)


--- trunk/Source/WebCore/page/ContextMenuController.cpp	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp	2020-05-18 07:37:28 UTC (rev 261800)
@@ -330,6 +330,9 @@
         frame->editor().command("Paste").execute();
         break;
 #if PLATFORM(GTK)
+    case ContextMenuItemTagPasteAsPlainText:
+        frame->editor().command("PasteAsPlainText").execute();
+        break;
     case ContextMenuItemTagDelete:
         frame->editor().performDelete();
         break;
@@ -816,6 +819,7 @@
     ContextMenuItem CutItem(ActionType, ContextMenuItemTagCut, contextMenuItemTagCut());
     ContextMenuItem PasteItem(ActionType, ContextMenuItemTagPaste, contextMenuItemTagPaste());
 #if PLATFORM(GTK)
+    ContextMenuItem PasteAsPlainTextItem(ActionType, ContextMenuItemTagPasteAsPlainText, contextMenuItemTagPasteAsPlainText());
     ContextMenuItem DeleteItem(ActionType, ContextMenuItemTagDelete, contextMenuItemTagDelete());
     ContextMenuItem SelectAllItem(ActionType, ContextMenuItemTagSelectAll, contextMenuItemTagSelectAll());
     ContextMenuItem InsertEmojiItem(ActionType, ContextMenuItemTagInsertEmoji, contextMenuItemTagInsertEmoji());
@@ -1053,6 +1057,8 @@
         appendItem(CopyItem, m_contextMenu.get());
         appendItem(PasteItem, m_contextMenu.get());
 #if PLATFORM(GTK)
+        if (frame->editor().canEditRichly())
+            appendItem(PasteAsPlainTextItem, m_contextMenu.get());
         appendItem(DeleteItem, m_contextMenu.get());
         appendItem(*separatorItem(), m_contextMenu.get());
         appendItem(SelectAllItem, m_contextMenu.get());
@@ -1208,6 +1214,9 @@
             shouldEnable = frame->editor().canDHTMLPaste() || frame->editor().canPaste();
             break;
 #if PLATFORM(GTK)
+        case ContextMenuItemTagPasteAsPlainText:
+            shouldEnable = frame->editor().canDHTMLPaste() || frame->editor().canPaste();
+            break;
         case ContextMenuItemTagDelete:
             shouldEnable = frame->editor().canDelete();
             break;

Modified: trunk/Source/WebCore/platform/ContextMenuItem.h (261799 => 261800)


--- trunk/Source/WebCore/platform/ContextMenuItem.h	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebCore/platform/ContextMenuItem.h	2020-05-18 07:37:28 UTC (rev 261800)
@@ -54,6 +54,7 @@
     ContextMenuItemTagCut,
     ContextMenuItemTagPaste,
 #if PLATFORM(GTK)
+    ContextMenuItemTagPasteAsPlainText,
     ContextMenuItemTagDelete,
     ContextMenuItemTagSelectAll,
     ContextMenuItemTagInputMethods,

Modified: trunk/Source/WebCore/platform/LocalizedStrings.h (261799 => 261800)


--- trunk/Source/WebCore/platform/LocalizedStrings.h	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebCore/platform/LocalizedStrings.h	2020-05-18 07:37:28 UTC (rev 261800)
@@ -70,6 +70,7 @@
     String contextMenuItemTagCut();
     WEBCORE_EXPORT String contextMenuItemTagPaste();
 #if PLATFORM(GTK)
+    String contextMenuItemTagPasteAsPlainText();
     String contextMenuItemTagDelete();
     String contextMenuItemTagInputMethods();
     String contextMenuItemTagUnicode();

Modified: trunk/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp (261799 => 261800)


--- trunk/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp	2020-05-18 07:37:28 UTC (rev 261800)
@@ -88,6 +88,11 @@
     return String::fromUTF8(_("Switch Video to _Fullscreen"));
 }
 
+String contextMenuItemTagPasteAsPlainText()
+{
+    return String::fromUTF8(_("Paste As Plain _Text"));
+}
+
 String contextMenuItemTagDelete()
 {
     return String::fromUTF8(_("_Delete"));

Modified: trunk/Source/WebKit/ChangeLog (261799 => 261800)


--- trunk/Source/WebKit/ChangeLog	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebKit/ChangeLog	2020-05-18 07:37:28 UTC (rev 261800)
@@ -1,3 +1,19 @@
+2020-05-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitContextMenuItemType for paste as plaintext
+        https://bugs.webkit.org/show_bug.cgi?id=177638
+
+        Reviewed by Michael Catanzaro.
+
+        Add WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT.
+
+        * Shared/API/glib/WebKitContextMenuActions.cpp:
+        (webkitContextMenuActionGetActionTag):
+        (webkitContextMenuActionGetForContextMenuItem):
+        (webkitContextMenuActionGetLabel):
+        * UIProcess/API/gtk/WebKitContextMenuActions.h:
+        * UIProcess/gtk/KeyBindingTranslator.cpp:
+
 2020-05-17  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Move to new Pasteboard API

Modified: trunk/Source/WebKit/Shared/API/glib/WebKitContextMenuActions.cpp (261799 => 261800)


--- trunk/Source/WebKit/Shared/API/glib/WebKitContextMenuActions.cpp	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebKit/Shared/API/glib/WebKitContextMenuActions.cpp	2020-05-18 07:37:28 UTC (rev 261800)
@@ -79,6 +79,8 @@
     case WEBKIT_CONTEXT_MENU_ACTION_PASTE:
         return ContextMenuItemTagPaste;
 #if PLATFORM(GTK)
+    case WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT:
+        return ContextMenuItemTagPasteAsPlainText;
     case WEBKIT_CONTEXT_MENU_ACTION_DELETE:
         return ContextMenuItemTagDelete;
     case WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL:
@@ -181,6 +183,8 @@
     case ContextMenuItemTagPaste:
         return WEBKIT_CONTEXT_MENU_ACTION_PASTE;
 #if PLATFORM(GTK)
+    case ContextMenuItemTagPasteAsPlainText:
+        return WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT;
     case ContextMenuItemTagDelete:
         return WEBKIT_CONTEXT_MENU_ACTION_DELETE;
     case ContextMenuItemTagSelectAll:
@@ -281,6 +285,8 @@
     case WEBKIT_CONTEXT_MENU_ACTION_PASTE:
         return contextMenuItemTagPaste();
 #if PLATFORM(GTK)
+    case WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT:
+        return contextMenuItemTagPasteAsPlainText();
     case WEBKIT_CONTEXT_MENU_ACTION_DELETE:
         return contextMenuItemTagDelete();
     case WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL:

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitContextMenuActions.h (261799 => 261800)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitContextMenuActions.h	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitContextMenuActions.h	2020-05-18 07:37:28 UTC (rev 261800)
@@ -75,6 +75,7 @@
  * @WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK: Download video to disk. Since 2.2
  * @WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK: Download audio to disk. Since 2.2
  * @WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI: Insert an emoji. Since 2.26
+ * @WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT: Paste clipboard contents as plain text. Since 2.30
  * @WEBKIT_CONTEXT_MENU_ACTION_CUSTOM: Custom action defined by applications.
  *
  * Enum values used to denote the stock actions for
@@ -127,6 +128,7 @@
     WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK,
     WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK,
     WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI,
+    WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT,
 
     WEBKIT_CONTEXT_MENU_ACTION_CUSTOM = 10000
 } WebKitContextMenuAction;

Modified: trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp (261799 => 261800)


--- trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp	2020-05-18 07:37:28 UTC (rev 261800)
@@ -202,18 +202,19 @@
 };
 
 static const KeyCombinationEntry customKeyBindings[] = {
-    { GDK_KEY_b,         GDK_CONTROL_MASK, "ToggleBold"      },
-    { GDK_KEY_i,         GDK_CONTROL_MASK, "ToggleItalic"    },
-    { GDK_KEY_Escape,    0,                "Cancel"          },
-    { GDK_KEY_greater,   GDK_CONTROL_MASK, "Cancel"          },
-    { GDK_KEY_Tab,       0,                "InsertTab"       },
-    { GDK_KEY_Tab,       GDK_SHIFT_MASK,   "InsertBacktab"   },
-    { GDK_KEY_Return,    0,                "InsertNewLine"   },
-    { GDK_KEY_KP_Enter,  0,                "InsertNewLine"   },
-    { GDK_KEY_ISO_Enter, 0,                "InsertNewLine"   },
-    { GDK_KEY_Return,    GDK_SHIFT_MASK,   "InsertLineBreak" },
-    { GDK_KEY_KP_Enter,  GDK_SHIFT_MASK,   "InsertLineBreak" },
-    { GDK_KEY_ISO_Enter, GDK_SHIFT_MASK,   "InsertLineBreak" },
+    { GDK_KEY_b,         GDK_CONTROL_MASK,                  "ToggleBold"      },
+    { GDK_KEY_i,         GDK_CONTROL_MASK,                  "ToggleItalic"    },
+    { GDK_KEY_Escape,    0,                                 "Cancel"          },
+    { GDK_KEY_greater,   GDK_CONTROL_MASK,                  "Cancel"          },
+    { GDK_KEY_Tab,       0,                                 "InsertTab"       },
+    { GDK_KEY_Tab,       GDK_SHIFT_MASK,                    "InsertBacktab"   },
+    { GDK_KEY_Return,    0,                                 "InsertNewLine"   },
+    { GDK_KEY_KP_Enter,  0,                                 "InsertNewLine"   },
+    { GDK_KEY_ISO_Enter, 0,                                 "InsertNewLine"   },
+    { GDK_KEY_Return,    GDK_SHIFT_MASK,                    "InsertLineBreak" },
+    { GDK_KEY_KP_Enter,  GDK_SHIFT_MASK,                    "InsertLineBreak" },
+    { GDK_KEY_ISO_Enter, GDK_SHIFT_MASK,                    "InsertLineBreak" },
+    { GDK_KEY_V,         GDK_CONTROL_MASK | GDK_SHIFT_MASK, "PasteAsPlainText" },
 };
 
 static Vector<String> handleCustomKeyBindings(unsigned keyval, GdkModifierType state)

Modified: trunk/Tools/ChangeLog (261799 => 261800)


--- trunk/Tools/ChangeLog	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Tools/ChangeLog	2020-05-18 07:37:28 UTC (rev 261800)
@@ -1,3 +1,16 @@
+2020-05-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitContextMenuItemType for paste as plaintext
+        https://bugs.webkit.org/show_bug.cgi?id=177638
+
+        Reviewed by Michael Catanzaro.
+
+        Update default context menu test case to also test the context menu for rich editable content.
+
+        * TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
+        (prepareContextMenuTestView):
+        (testContextMenuDefaultMenu):
+
 2020-05-17  Simon Fraser  <simon.fra...@apple.com>
 
         Fix operator== and hash() for ExtendedColor

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp (261799 => 261800)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp	2020-05-18 07:24:14 UTC (rev 261799)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp	2020-05-18 07:37:28 UTC (rev 261800)
@@ -337,6 +337,7 @@
         Audio,
         VideoLive,
         Editable,
+        RichEditable,
         Selection
     };
 
@@ -459,6 +460,24 @@
             iter = checkCurrentItemIsSeparatorAndGetNext(iter);
             iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE, Visible | Enabled);
             break;
+        case RichEditable:
+            g_assert_false(webkit_hit_test_result_context_is_link(hitTestResult));
+            g_assert_false(webkit_hit_test_result_context_is_image(hitTestResult));
+            g_assert_false(webkit_hit_test_result_context_is_media(hitTestResult));
+            g_assert_true(webkit_hit_test_result_context_is_editable(hitTestResult));
+            g_assert_false(webkit_hit_test_result_context_is_selection(hitTestResult));
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_CUT, Visible);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY, Visible);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_PASTE, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_PASTE_AS_PLAIN_TEXT, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DELETE, Visible);
+            iter = checkCurrentItemIsSeparatorAndGetNext(iter);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_FONT_MENU, Visible | Enabled);
+            iter = checkCurrentItemIsSeparatorAndGetNext(iter);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE, Visible | Enabled);
+            break;
         case Selection:
             g_assert_false(webkit_hit_test_result_context_is_link(hitTestResult));
             g_assert_false(webkit_hit_test_result_context_is_image(hitTestResult));
@@ -496,7 +515,8 @@
         " <input style='position:absolute; left:1; top:30' size='10'></input>"
         " <video style='position:absolute; left:1; top:50' width='300' height='300' controls='controls' preload='none'><source src='' type='video/webm' /></video>"
         " <audio style='position:absolute; left:1; top:60' width='50' height='20' controls='controls' preload='none'><source src='' type='audio/ogg' /></audio>"
-        " <p style='position:absolute; left:1; top:90' id='text_to_select'>Lorem ipsum.</p>"
+        " <div contenteditable style='position:absolute; left:1; top: 90; height: 20px; width: 100px'></div>"
+        " <p style='position:absolute; left:1; top:110' id='text_to_select'>Lorem ipsum.</p>"
         " <script>"
         "  window.getSelection().removeAllRanges();"
         "  var select_range = document.createRange();"
@@ -517,7 +537,7 @@
     // Context menu for selection.
     // This test should always be the first because any other click removes the selection.
     test->m_expectedMenuType = ContextMenuDefaultTest::Selection;
-    test->showContextMenuAtPositionAndWaitUntilFinished(2, 115);
+    test->showContextMenuAtPositionAndWaitUntilFinished(2, 135);
 
     // Context menu for document.
     test->m_expectedMenuType = ContextMenuDefaultTest::Navigation;
@@ -550,6 +570,10 @@
     // Context menu for editable.
     test->m_expectedMenuType = ContextMenuDefaultTest::Editable;
     test->showContextMenuAtPositionAndWaitUntilFinished(5, 35);
+
+    // Context menu for rich editable.
+    test->m_expectedMenuType = ContextMenuDefaultTest::RichEditable;
+    test->showContextMenuAtPositionAndWaitUntilFinished(5, 95);
 }
 
 static void testPopupEventSignal(ContextMenuDefaultTest* test, gconstpointer)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to