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