Changeset 235955 in webkit


Ignore:
Timestamp:
Sep 12, 2018 3:26:12 PM (6 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] Complete support for Paste as Quotation
https://bugs.webkit.org/show_bug.cgi?id=189504

Reviewed by Wenson Hsieh.

Source/WebCore:

Tests: editing/pasteboard/4930986-1-paste-as-quotation.html

editing/pasteboard/4930986-2-paste-as-quotation.html
editing/pasteboard/4930986-3-paste-as-quotation.html

  • editing/Editor.cpp: Added ClipboardEventKind::PasteAsQuotation.

(WebCore::eventNameForClipboardEvent): Map PasteAsQuotation to the "paste" DOM event name.
(WebCore::createDataTransferForClipboardEvent): Place the unquoted content in the event.

This means that currently event handlers can’t emulate pasting as quotation, because they
neither have the quoted content nor knowledge that quoting has been requested. We could
change this in the future if needed.

(WebCore::Editor::paste): Updated for change in pasteWithPasteboard’s argument type.
(WebCore::Editor::pasteAsQuotation): Added. Similar to paste, but passes

PasteOption::AsQuotation to pasteWithPasteboard.

(WebCore::Editor::quoteFragmentForPasting): Added. Quoting for pasting consists of enclosing

the fragment in a blockquote element with the "type" attribute set to "cite" and the
"class" attribute set to a well-known value, which is used to trigger special behavior in
ReplaceSelectionCommand. The behavior includes removing the "class" attribute in the end,
so eventually, we could stop using this form of in-band signaling.

  • editing/Editor.h: Declared PasteOption enum class to encompass the existing allowPlainText and MailBlockquoteHandling arguments to pasteWithPasteboard as well as the new AsQuotation behavior.
  • editing/EditorCommand.cpp:

(WebCore::executePasteAsQuotation): Added. Similar to executing Paste.
(WebCore::createCommandMap): Added an entry for PasteAsQuotation, based on the Paste entry.

  • editing/cocoa/EditorCocoa.mm:

(WebCore::Editor::webContentFromPasteboard): Moved from EditorIOS.mm and EditorMac.mm to

here.

  • editing/gtk/EditorGtk.cpp:

(WebCore::Editor::pasteWithPasteboard): Updated for new OptionSet argument, added a call to

quote the fragment if needed.

  • editing/ios/EditorIOS.mm:

(WebCore::Editor::pasteWithPasteboard): Ditto.
(WebCore::Editor::webContentFromPasteboard): Moved to EditorCocoa.mm.

  • editing/mac/EditorMac.mm:

(WebCore::Editor::pasteWithPasteboard): Updated for new OptionSet argument, added a call to

quote the fragment if needed.

(WebCore::Editor::readSelectionFromPasteboard): Updated for new OptionSet argument to

pasteWithPasteboard.

(WebCore::Editor::webContentFromPasteboard): Moved to EditorCocoa.mm.

  • editing/win/EditorWin.cpp:

(WebCore::Editor::pasteWithPasteboard): Updated for new OptionSet argument, added a call to

quote the fragment if needed.

  • editing/wpe/EditorWPE.cpp:

(WebCore::Editor::pasteWithPasteboard): Ditto.

Source/WebKit:

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView canPerformAction:withSender:]): Handle _pasteAsQuotation:. It’s not included

in FOR_EACH_WKCONTENTVIEW_ACTION, because it’s declared and implemented in the WKPrivate
category. If we add more actions in the category, it could make sense to fold them into
a new FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION.

(-[WKWebView targetForAction:withSender:]): Handle _pasteAsQuotation:.
(-[WKWebView _pasteAsQuotation:]): Send to the WebViewImpl or the WKContentView.

  • UIProcess/API/Cocoa/WKWebViewPrivate.h: Declared a new _pasteAsQuotation: action.
  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::selectorExceptionMap): Added a custom mapping from the new selector to the

PasteAsQuotation command.

  • UIProcess/ios/WKContentViewInteraction.h: Declare methods for the new action.
  • UIProcess/ios/WKContentViewInteraction.mm: Forward _pasteAsQuotation: to the WKWebView so that clients get a chance to override its behavior.

(-[WKContentView _pasteAsQuotationForWebView:]): Send the command to the page.

Tools:

  • MiniBrowser/mac/MainMenu.xib: Added a Paste as Quotation command in the Edit menu.

LayoutTests:

Took a few existing tests of the Paste as Quotation behavior and modified them to use the
new PasteAsQuotation command. The only difference in the results is that the blockquote has
the "type" attribute set to "cite".

  • editing/pasteboard/4930986-1-paste-as-quotation-expected.txt: Added.
  • editing/pasteboard/4930986-1-paste-as-quotation.html: Added.
  • editing/pasteboard/4930986-2-paste-as-quotation-expected.txt: Added.
  • editing/pasteboard/4930986-2-paste-as-quotation.html: Added.
  • editing/pasteboard/4930986-3-paste-as-quotation-expected.txt: Added.
  • editing/pasteboard/4930986-3-paste-as-quotation.html: Added.
Location:
trunk
Files:
6 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r235954 r235955  
     12018-09-12  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Complete support for Paste as Quotation
     4        https://bugs.webkit.org/show_bug.cgi?id=189504
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Took a few existing tests of the Paste as Quotation behavior and modified them to use the
     9        new PasteAsQuotation command. The only difference in the results is that the blockquote has
     10        the "type" attribute set to "cite".
     11
     12        * editing/pasteboard/4930986-1-paste-as-quotation-expected.txt: Added.
     13        * editing/pasteboard/4930986-1-paste-as-quotation.html: Added.
     14        * editing/pasteboard/4930986-2-paste-as-quotation-expected.txt: Added.
     15        * editing/pasteboard/4930986-2-paste-as-quotation.html: Added.
     16        * editing/pasteboard/4930986-3-paste-as-quotation-expected.txt: Added.
     17        * editing/pasteboard/4930986-3-paste-as-quotation.html: Added.
     18
    1192018-09-12  Sihui Liu  <sihui_liu@apple.com>
    220
  • trunk/Source/WebCore/ChangeLog

    r235953 r235955  
     12018-09-12  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Complete support for Paste as Quotation
     4        https://bugs.webkit.org/show_bug.cgi?id=189504
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Tests: editing/pasteboard/4930986-1-paste-as-quotation.html
     9               editing/pasteboard/4930986-2-paste-as-quotation.html
     10               editing/pasteboard/4930986-3-paste-as-quotation.html
     11
     12        * editing/Editor.cpp:
     13          Added ClipboardEventKind::PasteAsQuotation.
     14        (WebCore::eventNameForClipboardEvent): Map PasteAsQuotation to the "paste" DOM event name.
     15        (WebCore::createDataTransferForClipboardEvent): Place the unquoted content in the event.
     16          This means that currently event handlers can’t emulate pasting as quotation, because they
     17          neither have the quoted content nor knowledge that quoting has been requested. We could
     18          change this in the future if needed.
     19        (WebCore::Editor::paste): Updated for change in pasteWithPasteboard’s argument type.
     20        (WebCore::Editor::pasteAsQuotation): Added. Similar to paste, but passes
     21          PasteOption::AsQuotation to pasteWithPasteboard.
     22        (WebCore::Editor::quoteFragmentForPasting): Added. Quoting for pasting consists of enclosing
     23          the fragment in a blockquote element with the "type" attribute set to "cite" and the
     24          "class" attribute set to a well-known value, which is used to trigger special behavior in
     25          ReplaceSelectionCommand. The behavior includes removing the "class" attribute in the end,
     26          so eventually, we could stop using this form of in-band signaling.
     27        * editing/Editor.h: Declared PasteOption enum class to encompass the existing allowPlainText
     28          and MailBlockquoteHandling arguments to pasteWithPasteboard as well as the new AsQuotation
     29          behavior.
     30
     31        * editing/EditorCommand.cpp:
     32        (WebCore::executePasteAsQuotation): Added. Similar to executing Paste.
     33        (WebCore::createCommandMap): Added an entry for PasteAsQuotation, based on the Paste entry.
     34
     35        * editing/cocoa/EditorCocoa.mm:
     36        (WebCore::Editor::webContentFromPasteboard): Moved from EditorIOS.mm and EditorMac.mm to
     37          here.
     38
     39        * editing/gtk/EditorGtk.cpp:
     40        (WebCore::Editor::pasteWithPasteboard): Updated for new OptionSet argument, added a call to
     41          quote the fragment if needed.
     42
     43        * editing/ios/EditorIOS.mm:
     44        (WebCore::Editor::pasteWithPasteboard): Ditto.
     45        (WebCore::Editor::webContentFromPasteboard): Moved to EditorCocoa.mm.
     46
     47        * editing/mac/EditorMac.mm:
     48        (WebCore::Editor::pasteWithPasteboard): Updated for new OptionSet argument, added a call to
     49          quote the fragment if needed.
     50        (WebCore::Editor::readSelectionFromPasteboard): Updated for new OptionSet argument to
     51          pasteWithPasteboard.
     52        (WebCore::Editor::webContentFromPasteboard): Moved to EditorCocoa.mm.
     53
     54        * editing/win/EditorWin.cpp:
     55        (WebCore::Editor::pasteWithPasteboard): Updated for new OptionSet argument, added a call to
     56          quote the fragment if needed.
     57
     58        * editing/wpe/EditorWPE.cpp:
     59        (WebCore::Editor::pasteWithPasteboard): Ditto.
     60
    1612018-09-11  Simon Fraser  <simon.fraser@apple.com>
    262
  • trunk/Source/WebCore/editing/Editor.cpp

    r235775 r235955  
    5555#include "GraphicsContext.h"
    5656#include "HTMLAttachmentElement.h"
     57#include "HTMLBRElement.h"
    5758#include "HTMLCollection.h"
    5859#include "HTMLFormControlElement.h"
     
    6162#include "HTMLInputElement.h"
    6263#include "HTMLNames.h"
     64#include "HTMLQuoteElement.h"
    6365#include "HTMLSpanElement.h"
    6466#include "HitTestResult.h"
     
    328330    Paste,
    329331    PasteAsPlainText,
     332    PasteAsQuotation,
    330333    BeforeCopy,
    331334    BeforeCut,
     
    342345    case ClipboardEventKind::Paste:
    343346    case ClipboardEventKind::PasteAsPlainText:
     347    case ClipboardEventKind::PasteAsQuotation:
    344348        return eventNames().pasteEvent;
    345349    case ClipboardEventKind::BeforeCopy:
     
    370374        FALLTHROUGH;
    371375    case ClipboardEventKind::Paste:
     376    case ClipboardEventKind::PasteAsQuotation:
    372377        return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Readonly, Pasteboard::createForCopyAndPaste());
    373378    case ClipboardEventKind::BeforeCopy:
     
    14051410    ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader());
    14061411    if (m_frame.selection().selection().isContentRichlyEditable())
    1407         pasteWithPasteboard(&pasteboard, true);
     1412        pasteWithPasteboard(&pasteboard, { PasteOption::AllowPlainText });
    14081413    else
    14091414        pasteAsPlainTextWithPasteboard(pasteboard);
     
    14181423    updateMarkersForWordsAffectedByEditing(false);
    14191424    pasteAsPlainTextWithPasteboard(*Pasteboard::createForCopyAndPaste());
     1425}
     1426
     1427void Editor::pasteAsQuotation()
     1428{
     1429    if (!dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::PasteAsQuotation))
     1430        return;
     1431    if (!canPaste())
     1432        return;
     1433    updateMarkersForWordsAffectedByEditing(false);
     1434    ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader());
     1435    auto pasteboard = Pasteboard::createForCopyAndPaste();
     1436    if (m_frame.selection().selection().isContentRichlyEditable())
     1437        pasteWithPasteboard(pasteboard.get(), { PasteOption::AllowPlainText, PasteOption::AsQuotation });
     1438    else
     1439        pasteAsPlainTextWithPasteboard(*pasteboard);
     1440}
     1441
     1442void Editor::quoteFragmentForPasting(DocumentFragment& fragment)
     1443{
     1444    auto blockQuote = HTMLQuoteElement::create(blockquoteTag, document());
     1445    blockQuote->setAttributeWithoutSynchronization(typeAttr, AtomicString("cite"));
     1446    blockQuote->setAttributeWithoutSynchronization(classAttr, AtomicString(ApplePasteAsQuotation));
     1447
     1448    auto childNode = fragment.firstChild();
     1449
     1450    if (childNode) {
     1451        while (childNode) {
     1452            blockQuote->appendChild(*childNode);
     1453            childNode = fragment.firstChild();
     1454        }
     1455    } else
     1456        blockQuote->appendChild(HTMLBRElement::create(document()));
     1457
     1458    fragment.appendChild(blockQuote);
    14201459}
    14211460
  • trunk/Source/WebCore/editing/Editor.h

    r235857 r235955  
    130130    ~Editor();
    131131
     132    enum class PasteOption : uint8_t {
     133        AllowPlainText = 1 << 0,
     134        IgnoreMailBlockquote = 1 << 1,
     135        AsQuotation = 1 << 2,
     136    };
     137
    132138    WEBCORE_EXPORT EditorClient* client() const;
    133139    WEBCORE_EXPORT TextCheckerClient* textChecker() const;
     
    159165    void paste(Pasteboard&);
    160166    WEBCORE_EXPORT void pasteAsPlainText();
     167    void pasteAsQuotation();
    161168    WEBCORE_EXPORT void performDelete();
    162169
     
    520527    bool canSmartReplaceWithPasteboard(Pasteboard&);
    521528    void pasteAsPlainTextWithPasteboard(Pasteboard&);
    522     void pasteWithPasteboard(Pasteboard*, bool allowPlainText, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
     529    void pasteWithPasteboard(Pasteboard*, OptionSet<PasteOption>);
    523530    String plainTextFromPasteboard(const PasteboardPlainText&);
     531
     532    void quoteFragmentForPasting(DocumentFragment&);
    524533
    525534    void revealSelectionAfterEditingOperation(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, RevealExtentOption = DoNotRevealExtent);
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r235775 r235955  
    924924    } else
    925925        frame.editor().pasteAsPlainText();
     926    return true;
     927}
     928
     929static bool executePasteAsQuotation(Frame& frame, Event*, EditorCommandSource source, const String&)
     930{
     931    if (source == CommandFromMenuOrKeyBinding) {
     932        UserTypingGestureIndicator typingGestureIndicator(frame);
     933        frame.editor().pasteAsQuotation();
     934    } else
     935        frame.editor().pasteAsQuotation();
    926936    return true;
    927937}
     
    16371647        { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } },
    16381648        { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } },
     1649        { "PasteAsQuotation", { executePasteAsQuotation, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } },
    16391650        { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    16401651        { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
  • trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm

    r235343 r235955  
    292292}
    293293
    294 }
     294// FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect.
     295// Or refactor so it does not do that.
     296RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText)
     297{
     298    WebContentReader reader(m_frame, context, allowPlainText);
     299    pasteboard.read(reader);
     300    chosePlainText = reader.madeFragmentFromPlainText;
     301    return WTFMove(reader.fragment);
     302}
     303
     304}
  • trunk/Source/WebCore/editing/gtk/EditorGtk.cpp

    r222603 r235955  
    8787}
    8888
    89 void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
     89void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options)
    9090{
    9191    RefPtr<Range> range = selectedRange();
     
    9494
    9595    bool chosePlainText;
    96     RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, allowPlainText, chosePlainText);
     96    RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     97
     98    if (fragment && options.contains(PasteOption::AsQuotation))
     99        quoteFragmentForPasting(*fragment);
     100
    97101    if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted))
    98         pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
     102        pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote);
    99103}
    100104
  • trunk/Source/WebCore/editing/ios/EditorIOS.mm

    r235775 r235955  
    216216}
    217217
    218 // FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect.
    219 // Or refactor so it does not do that.
    220 RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText)
    221 {
    222     WebContentReader reader(m_frame, context, allowPlainText);
    223     pasteboard.read(reader);
    224     chosePlainText = reader.madeFragmentFromPlainText;
    225     return WTFMove(reader.fragment);
    226 }
    227 
    228 void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
     218void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options)
    229219{
    230220    RefPtr<Range> range = selectedRange();
     221    bool allowPlainText = options.contains(PasteOption::AllowPlainText);
    231222    WebContentReader reader(m_frame, *range, allowPlainText);
    232223    int numberOfPasteboardItems = client()->getPasteboardItemsCount();
     
    244235    }
    245236
     237    if (fragment && options.contains(PasteOption::AsQuotation))
     238        quoteFragmentForPasting(*fragment);
     239
    246240    if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted))
    247         pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling);
     241        pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote);
    248242}
    249243
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r235935 r235955  
    7878}
    7979
    80 void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
     80void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options)
    8181{
    8282    RefPtr<Range> range = selectedRange();
     
    8888
    8989    bool chosePlainText;
    90     RefPtr<DocumentFragment> fragment = webContentFromPasteboard(*pasteboard, *range, allowPlainText, chosePlainText);
     90    RefPtr<DocumentFragment> fragment = webContentFromPasteboard(*pasteboard, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     91
     92    if (fragment && options.contains(PasteOption::AsQuotation))
     93        quoteFragmentForPasting(*fragment);
    9194
    9295    if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted))
    93         pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling);
     96        pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote );
    9497
    9598    client()->setInsertionPasteboard(String());
     
    121124    Pasteboard pasteboard(pasteboardName);
    122125    if (m_frame.selection().selection().isContentRichlyEditable())
    123         pasteWithPasteboard(&pasteboard, true);
     126        pasteWithPasteboard(&pasteboard, { PasteOption::AllowPlainText });
    124127    else
    125128        pasteAsPlainTextWithPasteboard(pasteboard);
     
    277280}
    278281
    279 // FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect.
    280 // Or refactor so it does not do that.
    281 RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText)
    282 {
    283     WebContentReader reader(m_frame, context, allowPlainText);
    284     pasteboard.read(reader);
    285     chosePlainText = reader.madeFragmentFromPlainText;
    286     return WTFMove(reader.fragment);
    287 }
    288 
    289282} // namespace WebCore
    290283
  • trunk/Source/WebCore/editing/win/EditorWin.cpp

    r216351 r235955  
    3636namespace WebCore {
    3737
    38 void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
     38void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options)
    3939{
    4040    RefPtr<Range> range = selectedRange();
     
    4343
    4444    bool chosePlainText;
    45     RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, *range, allowPlainText, chosePlainText);
     45    RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     46
     47    if (fragment && options.contains(PasteOption::AsQuotation))
     48        quoteFragmentForPasting(*fragment);
     49
    4650    if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted))
    47         pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
     51        pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote);
    4852}
    4953
  • trunk/Source/WebCore/editing/wpe/EditorWPE.cpp

    r222680 r235955  
    7474}
    7575
    76 void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
     76void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options)
    7777{
    7878    RefPtr<Range> range = selectedRange();
     
    8181
    8282    bool chosePlainText;
    83     RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, allowPlainText, chosePlainText);
     83    RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     84
     85    if (fragment && options.contains(PasteOption::AsQuotation))
     86        quoteFragmentForPasting(*fragment);
     87
    8488    if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted))
    85         pasteAsFragment(*fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
     89        pasteAsFragment(*fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote);
    8690}
    8791
  • trunk/Source/WebKit/ChangeLog

    r235954 r235955  
     12018-09-12  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Complete support for Paste as Quotation
     4        https://bugs.webkit.org/show_bug.cgi?id=189504
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * UIProcess/API/Cocoa/WKWebView.mm:
     9        (-[WKWebView canPerformAction:withSender:]): Handle _pasteAsQuotation:. It’s not included
     10          in FOR_EACH_WKCONTENTVIEW_ACTION, because it’s declared and implemented in the WKPrivate
     11          category. If we add more actions in the category, it could make sense to fold them into
     12          a new FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION.
     13        (-[WKWebView targetForAction:withSender:]): Handle _pasteAsQuotation:.
     14        (-[WKWebView _pasteAsQuotation:]): Send to the WebViewImpl or the WKContentView.
     15        * UIProcess/API/Cocoa/WKWebViewPrivate.h: Declared a new _pasteAsQuotation: action.
     16
     17        * UIProcess/Cocoa/WebViewImpl.mm:
     18        (WebKit::selectorExceptionMap): Added a custom mapping from the new selector to the
     19          PasteAsQuotation command.
     20
     21        * UIProcess/ios/WKContentViewInteraction.h: Declare methods for the new action.
     22        * UIProcess/ios/WKContentViewInteraction.mm:
     23          Forward _pasteAsQuotation: to the WKWebView so that clients get a chance to override its
     24          behavior.
     25        (-[WKContentView _pasteAsQuotationForWebView:]): Send the command to the page.
     26
    1272018-09-12  Sihui Liu  <sihui_liu@apple.com>
    228
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r235944 r235955  
    13881388    FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW)
    13891389
     1390    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_pasteAsQuotation)
     1391
    13901392    #undef FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW
    13911393
     
    14001402
    14011403    FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW)
     1404
     1405    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_pasteAsQuotation)
    14021406
    14031407    #undef FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW
     
    45484552}
    45494553
     4554- (void)_pasteAsQuotation:(id)sender
     4555{
     4556#if PLATFORM(MAC)
     4557    _impl->executeEditCommandForSelector(_cmd);
     4558#else
     4559    if (self.usesStandardContentView)
     4560        [_contentView _pasteAsQuotationForWebView:sender];
     4561#endif
     4562}
     4563
    45504564- (void)_evaluateJavaScriptWithoutUserGesture:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
    45514565{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r235944 r235955  
    185185- (_WKAttachment *)_insertAttachmentWithFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType options:(_WKAttachmentDisplayOptions *)options completion:(void(^)(BOOL success))completionHandler WK_API_DEPRECATED_WITH_REPLACEMENT("-_insertAttachmentWithFileWrapper:contentType:completion:", macosx(WK_MAC_TBA, WK_MAC_TBA), ios(WK_IOS_TBA, WK_IOS_TBA));
    186186- (_WKAttachment *)_insertAttachmentWithFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType completion:(void(^)(BOOL success))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     187
     188- (IBAction)_pasteAsQuotation:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    187189
    188190#if TARGET_OS_IPHONE
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r235944 r235955  
    26252625        { @selector(pageUpAndModifySelection:), "MovePageUpAndModifySelection"_s },
    26262626        { @selector(scrollPageDown:), "ScrollPageForward"_s },
    2627         { @selector(scrollPageUp:), "ScrollPageBackward"_s }
     2627        { @selector(scrollPageUp:), "ScrollPageBackward"_s },
     2628#if WK_API_ENABLED
     2629        { @selector(_pasteAsQuotation:), "PasteAsQuotation"_s },
     2630#endif
    26282631    };
    26292632
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r235878 r235955  
    317317    - (void)_action ## ForWebView:(id)sender;
    318318FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
     319DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_pasteAsQuotation)
    319320#undef DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW
    320321
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r235878 r235955  
    21622162FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW)
    21632163
     2164FORWARD_ACTION_TO_WKWEBVIEW(_pasteAsQuotation)
     2165
    21642166#undef FORWARD_ACTION_TO_WKWEBVIEW
    21652167
     
    24612463{
    24622464    _page->executeEditCommand("paste"_s);
     2465}
     2466
     2467- (void)_pasteAsQuotationForWebView:(id)sender
     2468{
     2469    _page->executeEditCommand("PasteAsQuotation"_s);
    24632470}
    24642471
  • trunk/Tools/ChangeLog

    r235954 r235955  
     12018-09-12  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Complete support for Paste as Quotation
     4        https://bugs.webkit.org/show_bug.cgi?id=189504
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * MiniBrowser/mac/MainMenu.xib: Added a Paste as Quotation command in the Edit menu.
     9
    1102018-09-12  Sihui Liu  <sihui_liu@apple.com>
    211
  • trunk/Tools/MiniBrowser/mac/MainMenu.xib

    r226008 r235955  
    198198                                </connections>
    199199                            </menuItem>
     200                            <menuItem title="Paste as Quotation" keyEquivalent="V" id="8Ng-DB-z0Y">
     201                                <connections>
     202                                    <action selector="_pasteAsQuotation:" target="-1" id="6Mn-XC-2qO"/>
     203                                </connections>
     204                            </menuItem>
    200205                            <menuItem title="Paste and Match Style" keyEquivalent="V" id="485">
    201206                                <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
Note: See TracChangeset for help on using the changeset viewer.