1 | /* |
2 | * Copyright (C) 2006-2016 Apple Inc. All rights reserved. |
3 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #include "EditorInsertAction.h" |
30 | #include "SerializedAttachmentData.h" |
31 | #include "TextAffinity.h" |
32 | #include "TextChecking.h" |
33 | #include "UndoStep.h" |
34 | #include <wtf/Forward.h> |
35 | #include <wtf/Vector.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | enum class DOMPasteAccessResponse : uint8_t; |
40 | |
41 | class DocumentFragment; |
42 | class Element; |
43 | class Frame; |
44 | class KeyboardEvent; |
45 | class Node; |
46 | class Range; |
47 | class SharedBuffer; |
48 | class StyleProperties; |
49 | class TextCheckerClient; |
50 | class VisibleSelection; |
51 | |
52 | struct GapRects; |
53 | struct GrammarDetail; |
54 | |
55 | class EditorClient { |
56 | public: |
57 | virtual ~EditorClient() = default; |
58 | |
59 | virtual bool shouldDeleteRange(Range*) = 0; |
60 | virtual bool smartInsertDeleteEnabled() = 0; |
61 | virtual bool isSelectTrailingWhitespaceEnabled() const = 0; |
62 | virtual bool isContinuousSpellCheckingEnabled() = 0; |
63 | virtual void toggleContinuousSpellChecking() = 0; |
64 | virtual bool isGrammarCheckingEnabled() = 0; |
65 | virtual void toggleGrammarChecking() = 0; |
66 | virtual int spellCheckerDocumentTag() = 0; |
67 | |
68 | virtual bool shouldBeginEditing(Range*) = 0; |
69 | virtual bool shouldEndEditing(Range*) = 0; |
70 | virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction) = 0; |
71 | virtual bool shouldInsertText(const String&, Range*, EditorInsertAction) = 0; |
72 | virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting) = 0; |
73 | |
74 | virtual bool shouldApplyStyle(StyleProperties*, Range*) = 0; |
75 | virtual void didApplyStyle() = 0; |
76 | virtual bool shouldMoveRangeAfterDelete(Range*, Range*) = 0; |
77 | |
78 | #if ENABLE(ATTACHMENT_ELEMENT) |
79 | virtual void registerAttachmentIdentifier(const String& /* identifier */, const String& /* contentType */, const String& /* preferredFileName */, Ref<SharedBuffer>&&) { } |
80 | virtual void registerAttachmentIdentifier(const String& /* identifier */, const String& /* contentType */, const String& /* filePath */) { } |
81 | virtual void registerAttachments(Vector<SerializedAttachmentData>&&) { } |
82 | virtual void registerAttachmentIdentifier(const String& /* identifier */) { } |
83 | virtual void cloneAttachmentData(const String& /* fromIdentifier */, const String& /* toIdentifier */) { } |
84 | virtual void didInsertAttachmentWithIdentifier(const String& /* identifier */, const String& /* source */, bool /* hasEnclosingImage */) { } |
85 | virtual void didRemoveAttachmentWithIdentifier(const String&) { } |
86 | virtual bool supportsClientSideAttachmentData() const { return false; } |
87 | virtual Vector<SerializedAttachmentData> serializedAttachmentDataForIdentifiers(const Vector<String>&) { return { }; } |
88 | #endif |
89 | |
90 | virtual void didBeginEditing() = 0; |
91 | virtual void respondToChangedContents() = 0; |
92 | virtual void respondToChangedSelection(Frame*) = 0; |
93 | virtual void didEndUserTriggeredSelectionChanges() = 0; |
94 | virtual void updateEditorStateAfterLayoutIfEditabilityChanged() = 0; |
95 | virtual void didEndEditing() = 0; |
96 | virtual void willWriteSelectionToPasteboard(Range*) = 0; |
97 | virtual void didWriteSelectionToPasteboard() = 0; |
98 | virtual void getClientPasteboardDataForRange(Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData) = 0; |
99 | virtual void requestCandidatesForSelection(const VisibleSelection&) { } |
100 | virtual void handleAcceptedCandidateWithSoftSpaces(TextCheckingResult) { } |
101 | |
102 | virtual DOMPasteAccessResponse requestDOMPasteAccess(const String& originIdentifier) = 0; |
103 | |
104 | // Notify an input method that a composition was voluntarily discarded by WebCore, so that it could clean up too. |
105 | // This function is not called when a composition is closed per a request from an input method. |
106 | virtual void discardedComposition(Frame*) = 0; |
107 | virtual void canceledComposition() = 0; |
108 | virtual void didUpdateComposition() = 0; |
109 | |
110 | virtual void registerUndoStep(UndoStep&) = 0; |
111 | virtual void registerRedoStep(UndoStep&) = 0; |
112 | virtual void clearUndoRedoOperations() = 0; |
113 | |
114 | virtual bool canCopyCut(Frame*, bool defaultValue) const = 0; |
115 | virtual bool canPaste(Frame*, bool defaultValue) const = 0; |
116 | virtual bool canUndo() const = 0; |
117 | virtual bool canRedo() const = 0; |
118 | |
119 | virtual void undo() = 0; |
120 | virtual void redo() = 0; |
121 | |
122 | virtual void handleKeyboardEvent(KeyboardEvent&) = 0; |
123 | virtual void handleInputMethodKeydown(KeyboardEvent&) = 0; |
124 | |
125 | virtual void textFieldDidBeginEditing(Element*) = 0; |
126 | virtual void textFieldDidEndEditing(Element*) = 0; |
127 | virtual void textDidChangeInTextField(Element*) = 0; |
128 | virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*) = 0; |
129 | virtual void textWillBeDeletedInTextField(Element*) = 0; |
130 | virtual void textDidChangeInTextArea(Element*) = 0; |
131 | virtual void overflowScrollPositionChanged() = 0; |
132 | |
133 | #if PLATFORM(IOS_FAMILY) |
134 | virtual void startDelayingAndCoalescingContentChangeNotifications() = 0; |
135 | virtual void stopDelayingAndCoalescingContentChangeNotifications() = 0; |
136 | virtual bool hasRichlyEditableSelection() = 0; |
137 | virtual int getPasteboardItemsCount() = 0; |
138 | virtual RefPtr<DocumentFragment> documentFragmentFromDelegate(int index) = 0; |
139 | virtual bool performsTwoStepPaste(DocumentFragment*) = 0; |
140 | virtual void updateStringForFind(const String&) = 0; |
141 | #endif |
142 | |
143 | #if PLATFORM(COCOA) |
144 | virtual void setInsertionPasteboard(const String& pasteboardName) = 0; |
145 | #endif |
146 | |
147 | #if USE(APPKIT) |
148 | virtual void uppercaseWord() = 0; |
149 | virtual void lowercaseWord() = 0; |
150 | virtual void capitalizeWord() = 0; |
151 | #endif |
152 | |
153 | #if USE(AUTOMATIC_TEXT_REPLACEMENT) |
154 | virtual void showSubstitutionsPanel(bool show) = 0; |
155 | virtual bool substitutionsPanelIsShowing() = 0; |
156 | virtual void toggleSmartInsertDelete() = 0; |
157 | virtual bool isAutomaticQuoteSubstitutionEnabled() = 0; |
158 | virtual void toggleAutomaticQuoteSubstitution() = 0; |
159 | virtual bool isAutomaticLinkDetectionEnabled() = 0; |
160 | virtual void toggleAutomaticLinkDetection() = 0; |
161 | virtual bool isAutomaticDashSubstitutionEnabled() = 0; |
162 | virtual void toggleAutomaticDashSubstitution() = 0; |
163 | virtual bool isAutomaticTextReplacementEnabled() = 0; |
164 | virtual void toggleAutomaticTextReplacement() = 0; |
165 | virtual bool isAutomaticSpellingCorrectionEnabled() = 0; |
166 | virtual void toggleAutomaticSpellingCorrection() = 0; |
167 | #endif |
168 | |
169 | #if PLATFORM(GTK) |
170 | virtual bool () = 0; |
171 | #endif |
172 | |
173 | virtual TextCheckerClient* textChecker() = 0; |
174 | |
175 | virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail) = 0; |
176 | virtual void updateSpellingUIWithMisspelledWord(const String&) = 0; |
177 | virtual void showSpellingUI(bool show) = 0; |
178 | virtual bool spellingUIIsShowing() = 0; |
179 | virtual void willSetInputMethodState() = 0; |
180 | virtual void setInputMethodState(bool enabled) = 0; |
181 | |
182 | // Support for global selections, used on platforms like the X Window System that treat |
183 | // selection as a type of clipboard. |
184 | virtual bool supportsGlobalSelection() { return false; } |
185 | |
186 | virtual bool performTwoStepDrop(DocumentFragment&, Range& destination, bool isMove) = 0; |
187 | }; |
188 | |
189 | } |
190 | |