WebKit Bugzilla
Attachment 349426 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]
Multi-platform patch for EWS
file_189504.txt (text/plain), 20.33 KB, created by
mitz
on 2018-09-11 13:02:38 PDT
(
hide
)
Description:
Multi-platform patch for EWS
Filename:
MIME Type:
Creator:
mitz
Created:
2018-09-11 13:02:38 PDT
Size:
20.33 KB
patch
obsolete
>Index: Source/WebCore/editing/Editor.cpp >=================================================================== >--- Source/WebCore/editing/Editor.cpp (revision 235856) >+++ 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 235857) >+++ 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 235856) >+++ 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 235856) >+++ 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 235856) >+++ 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 235856) >+++ Source/WebCore/editing/ios/EditorIOS.mm (working copy) >@@ -215,17 +215,7 @@ 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(); > WebContentReader reader(m_frame, *range, allowPlainText); >@@ -240,11 +230,14 @@ void Editor::pasteWithPasteboard(Pastebo > RefPtr<DocumentFragment> fragment = reader.fragment; > if (!fragment) { > bool chosePlainTextIgnored; >- fragment = webContentFromPasteboard(*pasteboard, *range, allowPlainText, chosePlainTextIgnored); >+ fragment = webContentFromPasteboard(*pasteboard, *range, options.contains(PasteOption::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 235857) >+++ 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 235856) >+++ 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 235856) >+++ 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/UIProcess/API/Cocoa/WKWebView.mm >=================================================================== >--- Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (revision 235856) >+++ Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (working copy) >@@ -4483,6 +4483,11 @@ - (_WKAttachment *)_insertAttachmentWith > #endif > } > >+- (void)_pasteAsQuotation:(id)sender >+{ >+ _impl->executeEditCommandForSelector(_cmd); >+} >+ > - (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 235856) >+++ 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 235856) >+++ 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)
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
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189504
:
349400
|
349426
|
349432
|
349436
|
349454
|
349574