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