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