6f5abbac2da99699e7a52e500bded4bfe46d1280
[WebKit-https.git] / Source / WebCore / editing / Editor.h
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2013, 2014 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #pragma once
27
28 #include "CompositionUnderline.h"
29 #include "DictationAlternative.h"
30 #include "DocumentMarker.h"
31 #include "EditAction.h"
32 #include "EditingBehavior.h"
33 #include "EditingStyle.h"
34 #include "EditorInsertAction.h"
35 #include "FindOptions.h"
36 #include "FrameSelection.h"
37 #include "PasteboardWriterData.h"
38 #include "TextChecking.h"
39 #include "TextEventInputType.h"
40 #include "TextIteratorBehavior.h"
41 #include "VisibleSelection.h"
42 #include "WritingDirection.h"
43 #include <memory>
44
45 #if PLATFORM(COCOA)
46 OBJC_CLASS NSAttributedString;
47 OBJC_CLASS NSDictionary;
48 OBJC_CLASS NSMutableDictionary;
49 #endif
50
51 namespace PAL {
52 class KillRing;
53 }
54
55 namespace WebCore {
56
57 class AlternativeTextController;
58 class ArchiveResource;
59 class DataTransfer;
60 class CompositeEditCommand;
61 class DeleteButtonController;
62 class EditCommand;
63 class EditCommandComposition;
64 class EditorClient;
65 class EditorInternalCommand;
66 class File;
67 class Frame;
68 class HTMLElement;
69 class HitTestResult;
70 class KeyboardEvent;
71 class KillRing;
72 class Pasteboard;
73 class PasteboardWriterData;
74 class SharedBuffer;
75 class Font;
76 class SpellCheckRequest;
77 class SpellChecker;
78 class StaticRange;
79 class StyleProperties;
80 class Text;
81 class TextCheckerClient;
82 class TextEvent;
83
84 struct PasteboardPlainText;
85 struct PasteboardURL;
86 struct TextCheckingResult;
87
88 enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
89 enum EditorParagraphSeparator { EditorParagraphSeparatorIsDiv, EditorParagraphSeparatorIsP };
90
91 enum class MailBlockquoteHandling {
92     RespectBlockquote,
93     IgnoreBlockquote,
94 };
95
96 #if ENABLE(ATTACHMENT_ELEMENT)
97 class HTMLAttachmentElement;
98 struct AttachmentDisplayOptions;
99 #endif
100
101 enum TemporarySelectionOption : uint8_t {
102     // Scroll to reveal the selection.
103     TemporarySelectionOptionRevealSelection = 1 << 0,
104
105     // Don't propagate selection changes to the client layer.
106     TemporarySelectionOptionIgnoreSelectionChanges = 1 << 1,
107
108     // Force the render tree to update selection state. Only respected on iOS.
109     TemporarySelectionOptionEnableAppearanceUpdates = 1 << 2
110 };
111
112 class TemporarySelectionChange {
113 public:
114     TemporarySelectionChange(Frame&, std::optional<VisibleSelection> = std::nullopt, OptionSet<TemporarySelectionOption> = { });
115     ~TemporarySelectionChange();
116
117 private:
118     Ref<Frame> m_frame;
119     OptionSet<TemporarySelectionOption> m_options;
120     bool m_wasIgnoringSelectionChanges;
121 #if PLATFORM(IOS)
122     bool m_appearanceUpdatesWereEnabled;
123 #endif
124     std::optional<VisibleSelection> m_selectionToRestore;
125 };
126
127 class Editor {
128     WTF_MAKE_FAST_ALLOCATED;
129 public:
130     explicit Editor(Frame&);
131     ~Editor();
132
133     WEBCORE_EXPORT EditorClient* client() const;
134     WEBCORE_EXPORT TextCheckerClient* textChecker() const;
135
136     CompositeEditCommand* lastEditCommand() { return m_lastEditCommand.get(); }
137
138     void handleKeyboardEvent(KeyboardEvent&);
139     void handleInputMethodKeydown(KeyboardEvent&);
140     bool handleTextEvent(TextEvent&);
141
142     WEBCORE_EXPORT bool canEdit() const;
143     WEBCORE_EXPORT bool canEditRichly() const;
144
145     bool canDHTMLCut();
146     bool canDHTMLCopy();
147     WEBCORE_EXPORT bool canDHTMLPaste();
148     bool tryDHTMLCopy();
149     bool tryDHTMLCut();
150
151     WEBCORE_EXPORT bool canCut() const;
152     WEBCORE_EXPORT bool canCopy() const;
153     WEBCORE_EXPORT bool canPaste() const;
154     WEBCORE_EXPORT bool canDelete() const;
155     bool canSmartCopyOrDelete();
156
157     WEBCORE_EXPORT void cut();
158     WEBCORE_EXPORT void copy();
159     WEBCORE_EXPORT void paste();
160     void paste(Pasteboard&);
161     WEBCORE_EXPORT void pasteAsPlainText();
162     WEBCORE_EXPORT void performDelete();
163
164     WEBCORE_EXPORT void copyURL(const URL&, const String& title);
165     void copyURL(const URL&, const String& title, Pasteboard&);
166     PasteboardWriterData::URL pasteboardWriterURL(const URL&, const String& title);
167 #if !PLATFORM(IOS)
168     WEBCORE_EXPORT void copyImage(const HitTestResult&);
169 #endif
170
171     String readPlainTextFromPasteboard(Pasteboard&);
172
173     WEBCORE_EXPORT void indent();
174     WEBCORE_EXPORT void outdent();
175     void transpose();
176
177     bool shouldInsertFragment(DocumentFragment&, Range*, EditorInsertAction);
178     bool shouldInsertText(const String&, Range*, EditorInsertAction) const;
179     WEBCORE_EXPORT bool shouldDeleteRange(Range*) const;
180     bool shouldApplyStyle(StyleProperties*, Range*);
181
182     void respondToChangedContents(const VisibleSelection& endingSelection);
183
184     bool selectionStartHasStyle(CSSPropertyID, const String& value) const;
185     WEBCORE_EXPORT TriState selectionHasStyle(CSSPropertyID, const String& value) const;
186     String selectionStartCSSPropertyValue(CSSPropertyID);
187     
188     TriState selectionUnorderedListState() const;
189     TriState selectionOrderedListState() const;
190     WEBCORE_EXPORT RefPtr<Node> insertOrderedList();
191     WEBCORE_EXPORT RefPtr<Node> insertUnorderedList();
192     WEBCORE_EXPORT bool canIncreaseSelectionListLevel();
193     WEBCORE_EXPORT bool canDecreaseSelectionListLevel();
194     WEBCORE_EXPORT RefPtr<Node> increaseSelectionListLevel();
195     WEBCORE_EXPORT RefPtr<Node> increaseSelectionListLevelOrdered();
196     WEBCORE_EXPORT RefPtr<Node> increaseSelectionListLevelUnordered();
197     WEBCORE_EXPORT void decreaseSelectionListLevel();
198    
199     void removeFormattingAndStyle();
200
201     void clearLastEditCommand();
202 #if PLATFORM(IOS)
203     WEBCORE_EXPORT void ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping();
204 #endif
205
206     WEBCORE_EXPORT bool deleteWithDirection(SelectionDirection, TextGranularity, bool killRing, bool isTypingAction);
207     WEBCORE_EXPORT void deleteSelectionWithSmartDelete(bool smartDelete, EditAction = EditActionDelete);
208     void clearText();
209 #if PLATFORM(IOS)
210     WEBCORE_EXPORT void removeUnchangeableStyles();
211 #endif
212
213     WEBCORE_EXPORT void applyStyle(StyleProperties*, EditAction = EditActionUnspecified);
214     enum class ColorFilterMode { InvertColor, UseOriginalColor };
215     void applyStyle(RefPtr<EditingStyle>&&, EditAction, ColorFilterMode);
216     void applyParagraphStyle(StyleProperties*, EditAction = EditActionUnspecified);
217     WEBCORE_EXPORT void applyStyleToSelection(StyleProperties*, EditAction);
218     WEBCORE_EXPORT void applyStyleToSelection(Ref<EditingStyle>&&, EditAction, ColorFilterMode);
219     void applyParagraphStyleToSelection(StyleProperties*, EditAction);
220
221     // Returns whether or not we should proceed with editing.
222     bool willApplyEditing(CompositeEditCommand&, Vector<RefPtr<StaticRange>>&&) const;
223     bool willUnapplyEditing(const EditCommandComposition&) const;
224     bool willReapplyEditing(const EditCommandComposition&) const;
225
226     void appliedEditing(CompositeEditCommand&);
227     void unappliedEditing(EditCommandComposition&);
228     void reappliedEditing(EditCommandComposition&);
229     void unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction);
230
231     // This is off by default, since most editors want this behavior (originally matched IE but not Firefox).
232     void setShouldStyleWithCSS(bool flag) { m_shouldStyleWithCSS = flag; }
233     bool shouldStyleWithCSS() const { return m_shouldStyleWithCSS; }
234
235     class Command {
236     public:
237         WEBCORE_EXPORT Command();
238         Command(const EditorInternalCommand*, EditorCommandSource, Frame&);
239
240         WEBCORE_EXPORT bool execute(const String& parameter = String(), Event* triggeringEvent = nullptr) const;
241         WEBCORE_EXPORT bool execute(Event* triggeringEvent) const;
242
243         WEBCORE_EXPORT bool isSupported() const;
244         WEBCORE_EXPORT bool isEnabled(Event* triggeringEvent = nullptr) const;
245
246         WEBCORE_EXPORT TriState state(Event* triggeringEvent = nullptr) const;
247         String value(Event* triggeringEvent = nullptr) const;
248
249         WEBCORE_EXPORT bool isTextInsertion() const;
250         WEBCORE_EXPORT bool allowExecutionWhenDisabled() const;
251
252     private:
253         const EditorInternalCommand* m_command { nullptr };
254         EditorCommandSource m_source;
255         RefPtr<Frame> m_frame;
256     };
257     WEBCORE_EXPORT Command command(const String& commandName); // Command source is CommandFromMenuOrKeyBinding.
258     Command command(const String& commandName, EditorCommandSource);
259     WEBCORE_EXPORT static bool commandIsSupportedFromMenuOrKeyBinding(const String& commandName); // Works without a frame.
260
261     WEBCORE_EXPORT bool insertText(const String&, Event* triggeringEvent, TextEventInputType = TextEventInputKeyboard);
262     bool insertTextForConfirmedComposition(const String& text);
263     WEBCORE_EXPORT bool insertDictatedText(const String&, const Vector<DictationAlternative>& dictationAlternatives, Event* triggeringEvent);
264     bool insertTextWithoutSendingTextEvent(const String&, bool selectInsertedText, TextEvent* triggeringEvent);
265     bool insertLineBreak();
266     bool insertParagraphSeparator();
267     WEBCORE_EXPORT bool insertParagraphSeparatorInQuotedContent();
268
269     WEBCORE_EXPORT bool isContinuousSpellCheckingEnabled() const;
270     WEBCORE_EXPORT void toggleContinuousSpellChecking();
271     bool isGrammarCheckingEnabled();
272     void toggleGrammarChecking();
273     void ignoreSpelling();
274     void learnSpelling();
275     int spellCheckerDocumentTag();
276     WEBCORE_EXPORT bool isSelectionUngrammatical();
277     String misspelledSelectionString() const;
278     String misspelledWordAtCaretOrRange(Node* clickedNode) const;
279     Vector<String> guessesForMisspelledWord(const String&) const;
280     Vector<String> guessesForMisspelledOrUngrammatical(bool& misspelled, bool& ungrammatical);
281     bool isSpellCheckingEnabledInFocusedNode() const;
282     bool isSpellCheckingEnabledFor(Node*) const;
283     WEBCORE_EXPORT void markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping, bool doReplacement);
284     void markMisspellings(const VisibleSelection&, RefPtr<Range>& firstMisspellingRange);
285     void markBadGrammar(const VisibleSelection&);
286     void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
287     void markAndReplaceFor(const SpellCheckRequest&, const Vector<TextCheckingResult>&);
288
289     bool isOverwriteModeEnabled() const { return m_overwriteModeEnabled; }
290     WEBCORE_EXPORT void toggleOverwriteModeEnabled();
291
292     void markAllMisspellingsAndBadGrammarInRanges(OptionSet<TextCheckingType>, RefPtr<Range>&& spellingRange, RefPtr<Range>&& automaticReplacementRange, RefPtr<Range>&& grammarRange);
293 #if PLATFORM(IOS)
294     NO_RETURN_DUE_TO_ASSERT
295 #endif
296     void changeBackToReplacedString(const String& replacedString);
297
298 #if !PLATFORM(IOS)
299     WEBCORE_EXPORT void advanceToNextMisspelling(bool startBeforeSelection = false);
300 #endif
301     void showSpellingGuessPanel();
302     bool spellingPanelIsShowing();
303
304     bool shouldBeginEditing(Range*);
305     bool shouldEndEditing(Range*);
306
307     void clearUndoRedoOperations();
308     bool canUndo() const;
309     void undo();
310     bool canRedo() const;
311     void redo();
312
313     void didBeginEditing();
314     void didEndEditing();
315     void willWriteSelectionToPasteboard(Range*);
316     void didWriteSelectionToPasteboard();
317
318     void showFontPanel();
319     void showStylesPanel();
320     void showColorPanel();
321     void toggleBold();
322     void toggleUnderline();
323     WEBCORE_EXPORT void setBaseWritingDirection(WritingDirection);
324
325     // smartInsertDeleteEnabled and selectTrailingWhitespaceEnabled are 
326     // mutually exclusive, meaning that enabling one will disable the other.
327     bool smartInsertDeleteEnabled();
328     bool isSelectTrailingWhitespaceEnabled() const;
329     
330     WEBCORE_EXPORT bool hasBidiSelection() const;
331
332     // international text input composition
333     bool hasComposition() const { return m_compositionNode; }
334     WEBCORE_EXPORT void setComposition(const String&, const Vector<CompositionUnderline>&, unsigned selectionStart, unsigned selectionEnd);
335     WEBCORE_EXPORT void confirmComposition();
336     WEBCORE_EXPORT void confirmComposition(const String&); // if no existing composition, replaces selection
337     WEBCORE_EXPORT void cancelComposition();
338     bool cancelCompositionIfSelectionIsInvalid();
339     WEBCORE_EXPORT RefPtr<Range> compositionRange() const;
340     WEBCORE_EXPORT bool getCompositionSelection(unsigned& selectionStart, unsigned& selectionEnd) const;
341
342     // getting international text input composition state (for use by InlineTextBox)
343     Text* compositionNode() const { return m_compositionNode.get(); }
344     unsigned compositionStart() const { return m_compositionStart; }
345     unsigned compositionEnd() const { return m_compositionEnd; }
346     bool compositionUsesCustomUnderlines() const { return !m_customCompositionUnderlines.isEmpty(); }
347     const Vector<CompositionUnderline>& customCompositionUnderlines() const { return m_customCompositionUnderlines; }
348
349     enum class RevealSelection { No, Yes };
350     WEBCORE_EXPORT void setIgnoreSelectionChanges(bool, RevealSelection shouldRevealExistingSelection = RevealSelection::Yes);
351     bool ignoreSelectionChanges() const { return m_ignoreSelectionChanges; }
352
353     WEBCORE_EXPORT RefPtr<Range> rangeForPoint(const IntPoint& windowPoint);
354
355     void clear();
356
357     VisibleSelection selectionForCommand(Event*);
358
359     PAL::KillRing& killRing() const { return *m_killRing; }
360     SpellChecker& spellChecker() const { return *m_spellChecker; }
361
362     EditingBehavior behavior() const;
363
364     RefPtr<Range> selectedRange();
365
366 #if PLATFORM(IOS)
367     WEBCORE_EXPORT void confirmMarkedText();
368     WEBCORE_EXPORT void setTextAsChildOfElement(const String&, Element&);
369     WEBCORE_EXPORT void setTextAlignmentForChangedBaseWritingDirection(WritingDirection);
370     WEBCORE_EXPORT void insertDictationPhrases(Vector<Vector<String>>&& dictationPhrases, RetainPtr<id> metadata);
371     WEBCORE_EXPORT void setDictationPhrasesAsChildOfElement(const Vector<Vector<String>>& dictationPhrases, RetainPtr<id> metadata, Element&);
372 #endif
373     
374     enum class KillRingInsertionMode { PrependText, AppendText };
375     void addRangeToKillRing(const Range&, KillRingInsertionMode);
376     void addTextToKillRing(const String&, KillRingInsertionMode);
377     void setStartNewKillRingSequence(bool);
378
379     void startAlternativeTextUITimer();
380     // If user confirmed a correction in the correction panel, correction has non-zero length, otherwise it means that user has dismissed the panel.
381     WEBCORE_EXPORT void handleAlternativeTextUIResult(const String& correction);
382     void dismissCorrectionPanelAsIgnored();
383
384     WEBCORE_EXPORT void pasteAsFragment(Ref<DocumentFragment>&&, bool smartReplace, bool matchStyle, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
385     WEBCORE_EXPORT void pasteAsPlainText(const String&, bool smartReplace);
386
387     // This is only called on the mac where paste is implemented primarily at the WebKit level.
388     WEBCORE_EXPORT void pasteAsPlainTextBypassingDHTML();
389  
390     void clearMisspellingsAndBadGrammar(const VisibleSelection&);
391     void markMisspellingsAndBadGrammar(const VisibleSelection&);
392
393     Element* findEventTargetFrom(const VisibleSelection& selection) const;
394
395     WEBCORE_EXPORT String selectedText() const;
396     String selectedTextForDataTransfer() const;
397     WEBCORE_EXPORT bool findString(const String&, FindOptions);
398
399     WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
400
401     const VisibleSelection& mark() const; // Mark, to be used as emacs uses it.
402     void setMark(const VisibleSelection&);
403
404     void computeAndSetTypingStyle(EditingStyle& , EditAction = EditActionUnspecified);
405     WEBCORE_EXPORT void computeAndSetTypingStyle(StyleProperties& , EditAction = EditActionUnspecified);
406     WEBCORE_EXPORT void applyEditingStyleToBodyElement() const;
407     void applyEditingStyleToElement(Element*) const;
408
409     WEBCORE_EXPORT IntRect firstRectForRange(Range*) const;
410
411     void selectionWillChange();
412     void respondToChangedSelection(const VisibleSelection& oldSelection, OptionSet<FrameSelection::SetSelectionOption>);
413     WEBCORE_EXPORT void updateEditorUINowIfScheduled();
414     bool shouldChangeSelection(const VisibleSelection& oldSelection, const VisibleSelection& newSelection, EAffinity, bool stillSelecting) const;
415     WEBCORE_EXPORT unsigned countMatchesForText(const String&, Range*, FindOptions, unsigned limit, bool markMatches, Vector<RefPtr<Range>>*);
416     bool markedTextMatchesAreHighlighted() const;
417     WEBCORE_EXPORT void setMarkedTextMatchesAreHighlighted(bool);
418
419     void textFieldDidBeginEditing(Element*);
420     void textFieldDidEndEditing(Element*);
421     void textDidChangeInTextField(Element*);
422     bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
423     void textWillBeDeletedInTextField(Element* input);
424     void textDidChangeInTextArea(Element*);
425     WEBCORE_EXPORT WritingDirection baseWritingDirectionForSelectionStart() const;
426
427     WEBCORE_EXPORT void replaceSelectionWithFragment(DocumentFragment&, bool selectReplacement, bool smartReplace, bool matchStyle, EditAction = EditActionInsert, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
428     WEBCORE_EXPORT void replaceSelectionWithText(const String&, bool selectReplacement, bool smartReplace, EditAction = EditActionInsert);
429     WEBCORE_EXPORT bool selectionStartHasMarkerFor(DocumentMarker::MarkerType, int from, int length) const;
430     void updateMarkersForWordsAffectedByEditing(bool onlyHandleWordsContainingSelection);
431     void deletedAutocorrectionAtPosition(const Position&, const String& originalString);
432     
433     WEBCORE_EXPORT void simplifyMarkup(Node* startNode, Node* endNode);
434
435     EditorParagraphSeparator defaultParagraphSeparator() const { return m_defaultParagraphSeparator; }
436     void setDefaultParagraphSeparator(EditorParagraphSeparator separator) { m_defaultParagraphSeparator = separator; }
437     Vector<String> dictationAlternativesForMarker(const DocumentMarker&);
438     void applyDictationAlternativelternative(const String& alternativeString);
439
440 #if USE(APPKIT)
441     WEBCORE_EXPORT void uppercaseWord();
442     WEBCORE_EXPORT void lowercaseWord();
443     WEBCORE_EXPORT void capitalizeWord();
444 #endif
445
446 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
447     WEBCORE_EXPORT void showSubstitutionsPanel();
448     WEBCORE_EXPORT bool substitutionsPanelIsShowing();
449     WEBCORE_EXPORT void toggleSmartInsertDelete();
450     WEBCORE_EXPORT bool isAutomaticQuoteSubstitutionEnabled();
451     WEBCORE_EXPORT void toggleAutomaticQuoteSubstitution();
452     WEBCORE_EXPORT bool isAutomaticLinkDetectionEnabled();
453     WEBCORE_EXPORT void toggleAutomaticLinkDetection();
454     WEBCORE_EXPORT bool isAutomaticDashSubstitutionEnabled();
455     WEBCORE_EXPORT void toggleAutomaticDashSubstitution();
456     WEBCORE_EXPORT bool isAutomaticTextReplacementEnabled();
457     WEBCORE_EXPORT void toggleAutomaticTextReplacement();
458     WEBCORE_EXPORT bool isAutomaticSpellingCorrectionEnabled();
459     WEBCORE_EXPORT void toggleAutomaticSpellingCorrection();
460 #endif
461
462     RefPtr<DocumentFragment> webContentFromPasteboard(Pasteboard&, Range& context, bool allowPlainText, bool& chosePlainText);
463
464     WEBCORE_EXPORT const Font* fontForSelection(bool& hasMultipleFonts) const;
465     WEBCORE_EXPORT static const RenderStyle* styleForSelectionStart(Frame* , Node *&nodeToRemove);
466
467 #if PLATFORM(COCOA)
468     void getTextDecorationAttributesRespectingTypingStyle(const RenderStyle&, NSMutableDictionary*) const;
469     WEBCORE_EXPORT RetainPtr<NSDictionary> fontAttributesForSelectionStart() const;
470     WEBCORE_EXPORT String stringSelectionForPasteboard();
471     String stringSelectionForPasteboardWithImageAltText();
472 #if !PLATFORM(IOS)
473     bool canCopyExcludingStandaloneImages();
474     void takeFindStringFromSelection();
475     WEBCORE_EXPORT void readSelectionFromPasteboard(const String& pasteboardName, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
476     WEBCORE_EXPORT void replaceNodeFromPasteboard(Node*, const String& pasteboardName);
477     WEBCORE_EXPORT RefPtr<SharedBuffer> dataSelectionForPasteboard(const String& pasteboardName);
478     WEBCORE_EXPORT void applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits);
479 #endif // !PLATFORM(IOS)
480     WEBCORE_EXPORT void replaceSelectionWithAttributedString(NSAttributedString *, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
481 #endif
482
483     String clientReplacementURLForResource(Ref<SharedBuffer>&& resourceData, const String& mimeType);
484
485 #if !PLATFORM(WIN)
486     WEBCORE_EXPORT void writeSelectionToPasteboard(Pasteboard&);
487     WEBCORE_EXPORT void writeImageToPasteboard(Pasteboard&, Element& imageElement, const URL&, const String& title);
488     void writeSelection(PasteboardWriterData&);
489 #endif
490
491 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS)
492     void scanSelectionForTelephoneNumbers();
493     const Vector<RefPtr<Range>>& detectedTelephoneNumberRanges() const { return m_detectedTelephoneNumberRanges; }
494 #endif
495
496     WEBCORE_EXPORT String stringForCandidateRequest() const;
497     WEBCORE_EXPORT void handleAcceptedCandidate(TextCheckingResult);
498     WEBCORE_EXPORT RefPtr<Range> contextRangeForCandidateRequest() const;
499     RefPtr<Range> rangeForTextCheckingResult(const TextCheckingResult&) const;
500     bool isHandlingAcceptedCandidate() const { return m_isHandlingAcceptedCandidate; }
501
502     void setIsGettingDictionaryPopupInfo(bool b) { m_isGettingDictionaryPopupInfo = b; }
503     bool isGettingDictionaryPopupInfo() const { return m_isGettingDictionaryPopupInfo; }
504
505 #if ENABLE(ATTACHMENT_ELEMENT)
506     WEBCORE_EXPORT void insertAttachment(const String& identifier, const AttachmentDisplayOptions&, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType);
507     void registerAttachmentIdentifier(const String&, const String& /* contentType */, const String& /* preferredFileName */, Ref<SharedBuffer>&&);
508     void registerAttachmentIdentifier(const String&, const String& /* contentType */, const String& /* filePath */);
509     void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier);
510     void didInsertAttachmentElement(HTMLAttachmentElement&);
511     void didRemoveAttachmentElement(HTMLAttachmentElement&);
512
513 #if PLATFORM(COCOA)
514     void getPasteboardTypesAndDataForAttachment(Element&, Vector<String>& outTypes, Vector<RefPtr<SharedBuffer>>& outData);
515 #endif
516 #endif
517
518 private:
519     Document& document() const;
520
521     bool canDeleteRange(Range*) const;
522     bool canSmartReplaceWithPasteboard(Pasteboard&);
523     void pasteAsPlainTextWithPasteboard(Pasteboard&);
524     void pasteWithPasteboard(Pasteboard*, bool allowPlainText, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
525     String plainTextFromPasteboard(const PasteboardPlainText&);
526
527     void revealSelectionAfterEditingOperation(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, RevealExtentOption = DoNotRevealExtent);
528     void markMisspellingsOrBadGrammar(const VisibleSelection&, bool checkSpelling, RefPtr<Range>& firstMisspellingRange);
529     OptionSet<TextCheckingType> resolveTextCheckingTypeMask(const Node& rootEditableElement, OptionSet<TextCheckingType>);
530
531     WEBCORE_EXPORT String selectedText(TextIteratorBehavior) const;
532
533     void selectComposition();
534     enum SetCompositionMode { ConfirmComposition, CancelComposition };
535     void setComposition(const String&, SetCompositionMode);
536
537     void changeSelectionAfterCommand(const VisibleSelection& newSelection, OptionSet<FrameSelection::SetSelectionOption>);
538
539     enum EditorActionSpecifier { CutAction, CopyAction };
540     void performCutOrCopy(EditorActionSpecifier);
541
542     void editorUIUpdateTimerFired();
543
544     Element* findEventTargetFromSelection() const;
545
546     bool unifiedTextCheckerEnabled() const;
547
548     RefPtr<Range> adjustedSelectionRange();
549
550 #if PLATFORM(COCOA)
551     RefPtr<SharedBuffer> selectionInWebArchiveFormat();
552     String selectionInHTMLFormat();
553     RefPtr<SharedBuffer> imageInWebArchiveFormat(Element&);
554     static String userVisibleString(const URL&);
555     static RefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *);
556     static RefPtr<SharedBuffer> dataInRTFFormat(NSAttributedString *);
557 #endif
558
559     void scheduleEditorUIUpdate();
560
561 #if ENABLE(ATTACHMENT_ELEMENT)
562     void notifyClientOfAttachmentUpdates();
563 #endif
564
565     void postTextStateChangeNotificationForCut(const String&, const VisibleSelection&);
566
567     Frame& m_frame;
568     RefPtr<CompositeEditCommand> m_lastEditCommand;
569     RefPtr<Text> m_compositionNode;
570     unsigned m_compositionStart;
571     unsigned m_compositionEnd;
572     Vector<CompositionUnderline> m_customCompositionUnderlines;
573     bool m_ignoreSelectionChanges { false };
574     bool m_shouldStartNewKillRingSequence { false };
575     bool m_shouldStyleWithCSS { false };
576     const std::unique_ptr<PAL::KillRing> m_killRing;
577     const std::unique_ptr<SpellChecker> m_spellChecker;
578     const std::unique_ptr<AlternativeTextController> m_alternativeTextController;
579     EditorParagraphSeparator m_defaultParagraphSeparator { EditorParagraphSeparatorIsDiv };
580     bool m_overwriteModeEnabled { false };
581
582 #if ENABLE(ATTACHMENT_ELEMENT)
583     HashSet<String> m_insertedAttachmentIdentifiers;
584     HashSet<String> m_removedAttachmentIdentifiers;
585 #endif
586
587     VisibleSelection m_mark;
588     bool m_areMarkedTextMatchesHighlighted { false };
589
590     VisibleSelection m_oldSelectionForEditorUIUpdate;
591     Timer m_editorUIUpdateTimer;
592     bool m_editorUIUpdateTimerShouldCheckSpellingAndGrammar { false };
593     bool m_editorUIUpdateTimerWasTriggeredByDictation { false };
594     bool m_isHandlingAcceptedCandidate { false };
595
596 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS)
597     bool shouldDetectTelephoneNumbers();
598     void scanRangeForTelephoneNumbers(Range&, const StringView&, Vector<RefPtr<Range>>& markedRanges);
599
600     Timer m_telephoneNumberDetectionUpdateTimer;
601     Vector<RefPtr<Range>> m_detectedTelephoneNumberRanges;
602 #endif
603
604     bool m_isGettingDictionaryPopupInfo { false };
605 };
606
607 inline void Editor::setStartNewKillRingSequence(bool flag)
608 {
609     m_shouldStartNewKillRingSequence = flag;
610 }
611
612 inline const VisibleSelection& Editor::mark() const
613 {
614     return m_mark;
615 }
616
617 inline void Editor::setMark(const VisibleSelection& selection)
618 {
619     m_mark = selection;
620 }
621
622 inline bool Editor::markedTextMatchesAreHighlighted() const
623 {
624     return m_areMarkedTextMatchesHighlighted;
625 }
626
627 } // namespace WebCore