WebKit Bugzilla
Attachment 349574 Details for
Bug 189504
: [Cocoa] Complete support for Paste as Quotation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Add PasteAsQuotation command and -[WKWebView _pasteAsQuotation:]
bug-189504-20180912131152.patch (text/plain), 36.39 KB, created by
mitz
on 2018-09-12 13:11:53 PDT
(
hide
)
Description:
Add PasteAsQuotation command and -[WKWebView _pasteAsQuotation:]
Filename:
MIME Type:
Creator:
mitz
Created:
2018-09-12 13:11:53 PDT
Size:
36.39 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 235933) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,63 @@ >+2018-09-12 Dan Bernstein <mitz@apple.com> >+ >+ [Cocoa] Complete support for Paste as Quotation >+ https://bugs.webkit.org/show_bug.cgi?id=189504 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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. >+ > 2018-09-12 Pablo Saavedra <psaavedra@igalia.com> > > Linking against libWPEWebKit-0.1.so is not posible when WPE is build with ENABLE_VIDEO=OFF and ENABLE_WEB_AUDIO=OFF >Index: Source/WebCore/editing/Editor.cpp >=================================================================== >--- Source/WebCore/editing/Editor.cpp (revision 235933) >+++ Source/WebCore/editing/Editor.cpp (working copy) >@@ -54,12 +54,14 @@ > #include "FrameView.h" > #include "GraphicsContext.h" > #include "HTMLAttachmentElement.h" >+#include "HTMLBRElement.h" > #include "HTMLCollection.h" > #include "HTMLFormControlElement.h" > #include "HTMLFrameOwnerElement.h" > #include "HTMLImageElement.h" > #include "HTMLInputElement.h" > #include "HTMLNames.h" >+#include "HTMLQuoteElement.h" > #include "HTMLSpanElement.h" > #include "HitTestResult.h" > #include "IndentOutdentCommand.h" >@@ -327,6 +329,7 @@ enum class ClipboardEventKind { > Cut, > Paste, > PasteAsPlainText, >+ PasteAsQuotation, > BeforeCopy, > BeforeCut, > BeforePaste, >@@ -341,6 +344,7 @@ static AtomicString eventNameForClipboar > return eventNames().cutEvent; > case ClipboardEventKind::Paste: > case ClipboardEventKind::PasteAsPlainText: >+ case ClipboardEventKind::PasteAsQuotation: > return eventNames().pasteEvent; > case ClipboardEventKind::BeforeCopy: > return eventNames().beforecopyEvent; >@@ -369,6 +373,7 @@ static Ref<DataTransfer> createDataTrans > } > FALLTHROUGH; > case ClipboardEventKind::Paste: >+ case ClipboardEventKind::PasteAsQuotation: > return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Readonly, Pasteboard::createForCopyAndPaste()); > case ClipboardEventKind::BeforeCopy: > case ClipboardEventKind::BeforeCut: >@@ -1404,7 +1409,7 @@ void Editor::paste(Pasteboard& pasteboar > updateMarkersForWordsAffectedByEditing(false); > ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader()); > if (m_frame.selection().selection().isContentRichlyEditable()) >- pasteWithPasteboard(&pasteboard, true); >+ pasteWithPasteboard(&pasteboard, { PasteOption::AllowPlainText }); > else > pasteAsPlainTextWithPasteboard(pasteboard); > } >@@ -1419,6 +1424,40 @@ void Editor::pasteAsPlainText() > pasteAsPlainTextWithPasteboard(*Pasteboard::createForCopyAndPaste()); > } > >+void Editor::pasteAsQuotation() >+{ >+ if (!dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::PasteAsQuotation)) >+ return; >+ if (!canPaste()) >+ return; >+ updateMarkersForWordsAffectedByEditing(false); >+ ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader()); >+ auto pasteboard = Pasteboard::createForCopyAndPaste(); >+ if (m_frame.selection().selection().isContentRichlyEditable()) >+ pasteWithPasteboard(pasteboard.get(), { PasteOption::AllowPlainText, PasteOption::AsQuotation }); >+ else >+ pasteAsPlainTextWithPasteboard(*pasteboard); >+} >+ >+void Editor::quoteFragmentForPasting(DocumentFragment& fragment) >+{ >+ auto blockQuote = HTMLQuoteElement::create(blockquoteTag, document()); >+ blockQuote->setAttributeWithoutSynchronization(typeAttr, AtomicString("cite")); >+ blockQuote->setAttributeWithoutSynchronization(classAttr, AtomicString(ApplePasteAsQuotation)); >+ >+ auto childNode = fragment.firstChild(); >+ >+ if (childNode) { >+ while (childNode) { >+ blockQuote->appendChild(*childNode); >+ childNode = fragment.firstChild(); >+ } >+ } else >+ blockQuote->appendChild(HTMLBRElement::create(document())); >+ >+ fragment.appendChild(blockQuote); >+} >+ > void Editor::performDelete() > { > if (!canDelete()) { >Index: Source/WebCore/editing/Editor.h >=================================================================== >--- Source/WebCore/editing/Editor.h (revision 235933) >+++ Source/WebCore/editing/Editor.h (working copy) >@@ -129,6 +129,12 @@ public: > explicit Editor(Frame&); > ~Editor(); > >+ enum class PasteOption : uint8_t { >+ AllowPlainText = 1 << 0, >+ IgnoreMailBlockquote = 2 << 0, >+ AsQuotation = 2 << 0, >+ }; >+ > WEBCORE_EXPORT EditorClient* client() const; > WEBCORE_EXPORT TextCheckerClient* textChecker() const; > >@@ -158,6 +164,7 @@ public: > WEBCORE_EXPORT void paste(); > void paste(Pasteboard&); > WEBCORE_EXPORT void pasteAsPlainText(); >+ void pasteAsQuotation(); > WEBCORE_EXPORT void performDelete(); > > WEBCORE_EXPORT void copyURL(const URL&, const String& title); >@@ -519,9 +526,11 @@ private: > bool canDeleteRange(Range*) const; > bool canSmartReplaceWithPasteboard(Pasteboard&); > void pasteAsPlainTextWithPasteboard(Pasteboard&); >- void pasteWithPasteboard(Pasteboard*, bool allowPlainText, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote); >+ void pasteWithPasteboard(Pasteboard*, OptionSet<PasteOption>); > String plainTextFromPasteboard(const PasteboardPlainText&); > >+ void quoteFragmentForPasting(DocumentFragment&); >+ > void revealSelectionAfterEditingOperation(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, RevealExtentOption = DoNotRevealExtent); > void markMisspellingsOrBadGrammar(const VisibleSelection&, bool checkSpelling, RefPtr<Range>& firstMisspellingRange); > OptionSet<TextCheckingType> resolveTextCheckingTypeMask(const Node& rootEditableElement, OptionSet<TextCheckingType>); >Index: Source/WebCore/editing/EditorCommand.cpp >=================================================================== >--- Source/WebCore/editing/EditorCommand.cpp (revision 235933) >+++ Source/WebCore/editing/EditorCommand.cpp (working copy) >@@ -926,6 +926,16 @@ static bool executePasteAsPlainText(Fram > return true; > } > >+static bool executePasteAsQuotation(Frame& frame, Event*, EditorCommandSource source, const String&) >+{ >+ if (source == CommandFromMenuOrKeyBinding) { >+ UserTypingGestureIndicator typingGestureIndicator(frame); >+ frame.editor().pasteAsQuotation(); >+ } else >+ frame.editor().pasteAsQuotation(); >+ return true; >+} >+ > static bool executePrint(Frame& frame, Event*, EditorCommandSource, const String&) > { > Page* page = frame.page(); >@@ -1636,6 +1646,7 @@ static const CommandMap& createCommandMa > { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, > { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, > { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, >+ { "PasteAsQuotation", { executePasteAsQuotation, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, > { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, > { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, > { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, >Index: Source/WebCore/editing/cocoa/EditorCocoa.mm >=================================================================== >--- Source/WebCore/editing/cocoa/EditorCocoa.mm (revision 235933) >+++ Source/WebCore/editing/cocoa/EditorCocoa.mm (working copy) >@@ -291,4 +291,14 @@ RefPtr<SharedBuffer> Editor::dataInRTFFo > return nullptr; > } > >+// FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect. >+// Or refactor so it does not do that. >+RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText) >+{ >+ WebContentReader reader(m_frame, context, allowPlainText); >+ pasteboard.read(reader); >+ chosePlainText = reader.madeFragmentFromPlainText; >+ return WTFMove(reader.fragment); >+} >+ > } >Index: Source/WebCore/editing/gtk/EditorGtk.cpp >=================================================================== >--- Source/WebCore/editing/gtk/EditorGtk.cpp (revision 235933) >+++ Source/WebCore/editing/gtk/EditorGtk.cpp (working copy) >@@ -86,16 +86,20 @@ static RefPtr<DocumentFragment> createFr > return nullptr; > } > >-void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling) >+void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options) > { > RefPtr<Range> range = selectedRange(); > if (!range) > return; > > bool chosePlainText; >- RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, allowPlainText, chosePlainText); >+ RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText); >+ >+ if (fragment && options.contains(PasteOption::AsQuotation)) >+ quoteFragmentForPasting(*fragment); >+ > if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted)) >- pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling); >+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote); > } > > static const AtomicString& elementURL(Element& element) >Index: Source/WebCore/editing/ios/EditorIOS.mm >=================================================================== >--- Source/WebCore/editing/ios/EditorIOS.mm (revision 235933) >+++ Source/WebCore/editing/ios/EditorIOS.mm (working copy) >@@ -215,19 +215,10 @@ void Editor::writeImageToPasteboard(Past > pasteboard.write(pasteboardImage); > } > >-// FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect. >-// Or refactor so it does not do that. >-RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText) >-{ >- WebContentReader reader(m_frame, context, allowPlainText); >- pasteboard.read(reader); >- chosePlainText = reader.madeFragmentFromPlainText; >- return WTFMove(reader.fragment); >-} >- >-void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling) >+void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options) > { > RefPtr<Range> range = selectedRange(); >+ bool allowPlainText = options.contains(PasteOption::AllowPlainText); > WebContentReader reader(m_frame, *range, allowPlainText); > int numberOfPasteboardItems = client()->getPasteboardItemsCount(); > for (int i = 0; i < numberOfPasteboardItems; ++i) { >@@ -243,8 +234,11 @@ void Editor::pasteWithPasteboard(Pastebo > fragment = webContentFromPasteboard(*pasteboard, *range, allowPlainText, chosePlainTextIgnored); > } > >+ if (fragment && options.contains(PasteOption::AsQuotation)) >+ quoteFragmentForPasting(*fragment); >+ > if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted)) >- pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling); >+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote); > } > > void Editor::insertDictationPhrases(Vector<Vector<String>>&& dictationPhrases, RetainPtr<id> metadata) >Index: Source/WebCore/editing/mac/EditorMac.mm >=================================================================== >--- Source/WebCore/editing/mac/EditorMac.mm (revision 235933) >+++ Source/WebCore/editing/mac/EditorMac.mm (working copy) >@@ -77,7 +77,7 @@ void Editor::showColorPanel() > [[NSApplication sharedApplication] orderFrontColorPanel:nil]; > } > >-void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling) >+void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options) > { > RefPtr<Range> range = selectedRange(); > >@@ -88,10 +88,13 @@ void Editor::pasteWithPasteboard(Pastebo > #pragma clang diagnostic pop > > bool chosePlainText; >- RefPtr<DocumentFragment> fragment = webContentFromPasteboard(*pasteboard, *range, allowPlainText, chosePlainText); >+ RefPtr<DocumentFragment> fragment = webContentFromPasteboard(*pasteboard, *range, options.contains(PasteOption::AllowPlainText), chosePlainText); >+ >+ if (fragment && options.contains(PasteOption::AsQuotation)) >+ quoteFragmentForPasting(*fragment); > > if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted)) >- pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling); >+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote ); > > client()->setInsertionPasteboard(String()); > } >@@ -122,7 +125,7 @@ void Editor::readSelectionFromPasteboard > { > Pasteboard pasteboard(pasteboardName); > if (m_frame.selection().selection().isContentRichlyEditable()) >- pasteWithPasteboard(&pasteboard, true); >+ pasteWithPasteboard(&pasteboard, { PasteOption::AllowPlainText }); > else > pasteAsPlainTextWithPasteboard(pasteboard); > } >@@ -279,16 +282,6 @@ void Editor::writeImageToPasteboard(Past > pasteboard.write(pasteboardImage); > } > >-// FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect. >-// Or refactor so it does not do that. >-RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText) >-{ >- WebContentReader reader(m_frame, context, allowPlainText); >- pasteboard.read(reader); >- chosePlainText = reader.madeFragmentFromPlainText; >- return WTFMove(reader.fragment); >-} >- > } // namespace WebCore > > #endif // PLATFORM(MAC) >Index: Source/WebCore/editing/win/EditorWin.cpp >=================================================================== >--- Source/WebCore/editing/win/EditorWin.cpp (revision 235933) >+++ Source/WebCore/editing/win/EditorWin.cpp (working copy) >@@ -35,16 +35,20 @@ > > namespace WebCore { > >-void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling) >+void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options) > { > RefPtr<Range> range = selectedRange(); > if (!range) > return; > > bool chosePlainText; >- RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, *range, allowPlainText, chosePlainText); >+ RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText); >+ >+ if (fragment && options.contains(PasteOption::AsQuotation)) >+ quoteFragmentForPasting(*fragment); >+ > if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted)) >- pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling); >+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote); > } > > template <typename PlatformDragData> >Index: Source/WebCore/editing/wpe/EditorWPE.cpp >=================================================================== >--- Source/WebCore/editing/wpe/EditorWPE.cpp (revision 235933) >+++ Source/WebCore/editing/wpe/EditorWPE.cpp (working copy) >@@ -73,16 +73,20 @@ void Editor::writeImageToPasteboard(Past > notImplemented(); > } > >-void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling) >+void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options) > { > RefPtr<Range> range = selectedRange(); > if (!range) > return; > > bool chosePlainText; >- RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, allowPlainText, chosePlainText); >+ RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText); >+ >+ if (fragment && options.contains(PasteOption::AsQuotation)) >+ quoteFragmentForPasting(*fragment); >+ > if (fragment && shouldInsertFragment(*fragment, range.get(), EditorInsertAction::Pasted)) >- pasteAsFragment(*fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling); >+ pasteAsFragment(*fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote); > } > > } // namespace WebCore >Index: Source/WebKit/ChangeLog >=================================================================== >--- Source/WebKit/ChangeLog (revision 235933) >+++ Source/WebKit/ChangeLog (working copy) >@@ -1,3 +1,29 @@ >+2018-09-12 Dan Bernstein <mitz@apple.com> >+ >+ [Cocoa] Complete support for Paste as Quotation >+ https://bugs.webkit.org/show_bug.cgi?id=189504 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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. >+ > 2018-09-11 Olivia Barnett <obarnett@apple.com> > > Implement the Web Share API for mac >Index: Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >=================================================================== >--- Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (revision 235933) >+++ Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (working copy) >@@ -1387,6 +1387,8 @@ - (BOOL)canPerformAction:(SEL)action wit > > FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW) > >+ FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_pasteAsQuotation) >+ > #undef FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW > > return [super canPerformAction:action withSender:sender]; >@@ -1400,6 +1402,8 @@ - (id)targetForAction:(SEL)action withSe > > FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW) > >+ FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_pasteAsQuotation) >+ > #undef FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW > > return [super targetForAction:action withSender:sender]; >@@ -4516,6 +4520,16 @@ - (_WKAttachment *)_insertAttachmentWith > #endif > } > >+- (void)_pasteAsQuotation:(id)sender >+{ >+#if PLATFORM(MAC) >+ _impl->executeEditCommandForSelector(_cmd); >+#else >+ if (self.usesStandardContentView) >+ [_contentView _pasteAsQuotationForWebView:sender]; >+#endif >+} >+ > - (void)_evaluateJavaScriptWithoutUserGesture:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler > { > [self _evaluateJavaScript:javaScriptString forceUserGesture:NO completionHandler:completionHandler]; >Index: Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h >=================================================================== >--- Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (revision 235933) >+++ Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (working copy) >@@ -185,6 +185,8 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEd > - (_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)); > - (_WKAttachment *)_insertAttachmentWithFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType completion:(void(^)(BOOL success))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > >+- (IBAction)_pasteAsQuotation:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); >+ > #if TARGET_OS_IPHONE > // DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters. > // Define the smallest size a page take with a regular viewport. >Index: Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >=================================================================== >--- Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (revision 235933) >+++ Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (working copy) >@@ -2604,7 +2604,10 @@ static const SelectorNameMap& selectorEx > { @selector(pageUp:), "MovePageUp"_s }, > { @selector(pageUpAndModifySelection:), "MovePageUpAndModifySelection"_s }, > { @selector(scrollPageDown:), "ScrollPageForward"_s }, >- { @selector(scrollPageUp:), "ScrollPageBackward"_s } >+ { @selector(scrollPageUp:), "ScrollPageBackward"_s }, >+#if WK_API_ENABLED >+ { @selector(_pasteAsQuotation:), "PasteAsQuotation"_s }, >+#endif > }; > > for (auto& name : names) >Index: Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >=================================================================== >--- Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (revision 235933) >+++ Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (working copy) >@@ -316,6 +316,7 @@ struct WKAutoCorrectionData { > #define DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_action) \ > - (void)_action ## ForWebView:(id)sender; > FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW) >+DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_pasteAsQuotation) > #undef DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW > > #if ENABLE(TOUCH_EVENTS) >Index: Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >=================================================================== >--- Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (revision 235933) >+++ Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (working copy) >@@ -2161,6 +2161,8 @@ - (NSArray *)supportedPasteboardTypesFor > > FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW) > >+FORWARD_ACTION_TO_WKWEBVIEW(_pasteAsQuotation) >+ > #undef FORWARD_ACTION_TO_WKWEBVIEW > > - (void)_lookupForWebView:(id)sender >@@ -2462,6 +2464,11 @@ - (void)pasteForWebView:(id)sender > _page->executeEditCommand("paste"_s); > } > >+- (void)_pasteAsQuotationForWebView:(id)sender >+{ >+ _page->executeEditCommand("PasteAsQuotation"_s); >+} >+ > - (void)selectForWebView:(id)sender > { > [_textSelectionAssistant selectWord]; >Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 235945) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,12 @@ >+2018-09-12 Dan Bernstein <mitz@apple.com> >+ >+ [Cocoa] Complete support for Paste as Quotation >+ https://bugs.webkit.org/show_bug.cgi?id=189504 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * MiniBrowser/mac/MainMenu.xib: Added a Paste as Quotation command in the Edit menu. >+ > 2018-09-12 Fujii Hironori <Hironori.Fujii@sony.com> > > [Win][Clang][DumpRenderTree] 0 and nullptr can't be implicitly converted to AccessibilityUIElement >Index: Tools/MiniBrowser/mac/MainMenu.xib >=================================================================== >--- Tools/MiniBrowser/mac/MainMenu.xib (revision 235933) >+++ Tools/MiniBrowser/mac/MainMenu.xib (working copy) >@@ -197,6 +197,11 @@ > <action selector="paste:" target="-1" id="226"/> > </connections> > </menuItem> >+ <menuItem title="Paste as Quotation" keyEquivalent="V" id="8Ng-DB-z0Y"> >+ <connections> >+ <action selector="_pasteAsQuotation:" target="-1" id="6Mn-XC-2qO"/> >+ </connections> >+ </menuItem> > <menuItem title="Paste and Match Style" keyEquivalent="V" id="485"> > <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> > <connections> >Index: LayoutTests/ChangeLog >=================================================================== >--- LayoutTests/ChangeLog (revision 235933) >+++ LayoutTests/ChangeLog (working copy) >@@ -1,3 +1,21 @@ >+2018-09-12 Dan Bernstein <mitz@apple.com> >+ >+ [Cocoa] Complete support for Paste as Quotation >+ https://bugs.webkit.org/show_bug.cgi?id=189504 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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. >+ > 2018-09-11 Olivia Barnett <obarnett@apple.com> > > Implement the Web Share API for mac >Index: LayoutTests/editing/pasteboard/4930986-1-paste-as-quotation-expected.txt >=================================================================== >--- LayoutTests/editing/pasteboard/4930986-1-paste-as-quotation-expected.txt (nonexistent) >+++ LayoutTests/editing/pasteboard/4930986-1-paste-as-quotation-expected.txt (working copy) >@@ -0,0 +1,2 @@ >+This tests to make sure that content that has the document default color is pasted as blue (or whatever the color for quoted content is) during a Paste as Quotation. >+<blockquote type="cite">This text should be blue (it should not be wrapped in a style span).</blockquote> >Index: LayoutTests/editing/pasteboard/4930986-1-paste-as-quotation.html >=================================================================== >--- LayoutTests/editing/pasteboard/4930986-1-paste-as-quotation.html (nonexistent) >+++ LayoutTests/editing/pasteboard/4930986-1-paste-as-quotation.html (working copy) >@@ -0,0 +1,34 @@ >+<html> >+<head> >+<style> >+blockquote { >+ color: blue; >+ border-left: 2px solid blue; >+ margin-left: 0px; >+ padding-left: 10px; >+} >+</style> >+</head> >+<body> >+<div id="description">This tests to make sure that content that has the document default color is pasted as blue (or whatever the color for quoted content is) during a Paste as Quotation.</div> >+<div id="edit" contenteditable="true"></div> >+ >+<script> >+document.addEventListener("beforecopy", (event) => { event.preventDefault(); }); >+document.addEventListener("copy", (event) => { >+ event.clipboardData.setData("text/html", "<span class='Apple-style-span' style='color: black;'>This text should be blue (it should not be wrapped in a style span).</span>"); >+ event.preventDefault(); >+}); >+document.execCommand("Copy", false); >+ >+edit = document.getElementById("edit"); >+description = document.getElementById("description"); >+edit.focus(); >+document.execCommand("PasteAsQuotation", false); >+if (window.testRunner) { >+ window.testRunner.dumpAsText(); >+ document.body.innerText = description.innerText + "\n" + edit.innerHTML; >+} >+</script> >+</body> >+</html> >Index: LayoutTests/editing/pasteboard/4930986-2-paste-as-quotation-expected.txt >=================================================================== >--- LayoutTests/editing/pasteboard/4930986-2-paste-as-quotation-expected.txt (nonexistent) >+++ LayoutTests/editing/pasteboard/4930986-2-paste-as-quotation-expected.txt (working copy) >@@ -0,0 +1,2 @@ >+This tests to make sure that content that is colored by the user is pasted with that color during a Paste as Quotation. >+<blockquote type="cite"><span class="Apple-style-span" style="color: red;">This text should be red (it should be wrapped in a style span).</span></blockquote> >Index: LayoutTests/editing/pasteboard/4930986-2-paste-as-quotation.html >=================================================================== >--- LayoutTests/editing/pasteboard/4930986-2-paste-as-quotation.html (nonexistent) >+++ LayoutTests/editing/pasteboard/4930986-2-paste-as-quotation.html (working copy) >@@ -0,0 +1,34 @@ >+<html> >+<head> >+<style> >+blockquote { >+ color: blue; >+ border-left: 2px solid blue; >+ margin-left: 0px; >+ padding-left: 10px; >+} >+</style> >+<script> >+function runTest() { >+ document.addEventListener("beforecopy", (event) => { event.preventDefault(); }); >+ document.addEventListener("copy", (event) => { >+ event.clipboardData.setData("text/html", "<span class='Apple-style-span' style='color: black;'><span class='Apple-style-span' style='color: red;'>This text should be red (it should be wrapped in a style span).</span></span>"); >+ event.preventDefault(); >+ }); >+ document.execCommand("Copy", false); >+ >+ div = document.getElementById("edit"); >+ div.focus(); >+ document.execCommand("PasteAsQuotation", false); >+ if (window.testRunner) { >+ window.testRunner.dumpAsText(); >+ document.body.innerText = document.getElementById("description").innerText + "\n" + div.innerHTML; >+ } >+} >+</script> >+</head> >+<body onload="runTest();"> >+<div id="description">This tests to make sure that content that is colored by the user is pasted with that color during a Paste as Quotation.</div> >+<div id="edit" contenteditable="true"></div> >+</body> >+</html> >Index: LayoutTests/editing/pasteboard/4930986-3-paste-as-quotation-expected.txt >=================================================================== >--- LayoutTests/editing/pasteboard/4930986-3-paste-as-quotation-expected.txt (nonexistent) >+++ LayoutTests/editing/pasteboard/4930986-3-paste-as-quotation-expected.txt (working copy) >@@ -0,0 +1,2 @@ >+This tests to make sure that an Apple-paste-as-quotation blockquote can override document default styles even if they are different than the insertion position. >+<blockquote type="cite">This text should have the blockquote color (blue). There should be no style spans around it.</blockquote> >Index: LayoutTests/editing/pasteboard/4930986-3-paste-as-quotation.html >=================================================================== >--- LayoutTests/editing/pasteboard/4930986-3-paste-as-quotation.html (nonexistent) >+++ LayoutTests/editing/pasteboard/4930986-3-paste-as-quotation.html (working copy) >@@ -0,0 +1,34 @@ >+<html> >+<head> >+<style> >+blockquote { >+ color: blue; >+ padding-left: 10px; >+ margin-left: 0px; >+ border-left: 2px solid blue; >+} >+</style> >+</head> >+<body> >+<div id="description">This tests to make sure that an Apple-paste-as-quotation blockquote can override document default styles even if they are different than the insertion position.</div> >+<div id="edit" contenteditable="true" style="color: red;"></div> >+ >+<script> >+document.addEventListener("beforecopy", (event) => { event.preventDefault(); }); >+document.addEventListener("copy", (event) => { >+ event.clipboardData.setData("text/html", "<span class='Apple-style-span' style='color:black;'>This text should have the blockquote color (blue). There should be no style spans around it.</span>"); >+ event.preventDefault(); >+}); >+document.execCommand("Copy", false); >+ >+edit = document.getElementById("edit"); >+description = document.getElementById("description"); >+edit.focus(); >+document.execCommand("PasteAsQuotation", false); >+if (window.testRunner) { >+ window.testRunner.dumpAsText(); >+ document.body.innerText = description.innerText + "\n" + edit.innerHTML; >+} >+</script> >+</body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
wenson_hsieh
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189504
:
349400
|
349426
|
349432
|
349436
|
349454
| 349574