Add support for using the current text selection as the find string on iOS
[WebKit-https.git] / Source / WebKit / WebProcess / WebCoreSupport / WebEditorClient.h
1 /*
2  * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include <WebCore/EditorClient.h>
29 #include <WebCore/TextCheckerClient.h>
30
31 namespace WebKit {
32
33 class WebPage;
34
35 class WebEditorClient final : public WebCore::EditorClient, public WebCore::TextCheckerClient {
36 public:
37     WebEditorClient(WebPage* page)
38         : m_page(page)
39     {
40     }
41
42 private:
43     bool shouldDeleteRange(WebCore::Range*) final;
44     bool smartInsertDeleteEnabled() final;
45     bool isSelectTrailingWhitespaceEnabled() const final;
46     bool isContinuousSpellCheckingEnabled() final;
47     void toggleContinuousSpellChecking() final;
48     bool isGrammarCheckingEnabled() final;
49     void toggleGrammarChecking() final;
50     int spellCheckerDocumentTag() final;
51     
52     bool shouldBeginEditing(WebCore::Range*) final;
53     bool shouldEndEditing(WebCore::Range*) final;
54     bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction) final;
55     bool shouldInsertText(const String&, WebCore::Range*, WebCore::EditorInsertAction) final;
56     bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting) final;
57     
58     bool shouldApplyStyle(WebCore::StyleProperties*, WebCore::Range*) final;
59     void didApplyStyle() final;
60     bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*) final;
61
62 #if ENABLE(ATTACHMENT_ELEMENT)
63     void registerAttachmentIdentifier(const String&, const String& contentType, const String& preferredFileName, Ref<WebCore::SharedBuffer>&&) final;
64     void registerAttachmentIdentifier(const String&, const String& contentType, const String& filePath) final;
65     void registerAttachmentIdentifier(const String&) final;
66     void registerAttachments(Vector<WebCore::SerializedAttachmentData>&&) final;
67     void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier) final;
68     void didInsertAttachmentWithIdentifier(const String& identifier, const String& source, bool hasEnclosingImage) final;
69     void didRemoveAttachmentWithIdentifier(const String& identifier) final;
70     bool supportsClientSideAttachmentData() const final { return true; }
71     Vector<WebCore::SerializedAttachmentData> serializedAttachmentDataForIdentifiers(const Vector<String>&) final;
72 #endif
73
74     void didBeginEditing() final;
75     void respondToChangedContents() final;
76     void respondToChangedSelection(WebCore::Frame*) final;
77     void didEndUserTriggeredSelectionChanges() final;
78     void updateEditorStateAfterLayoutIfEditabilityChanged() final;
79     void discardedComposition(WebCore::Frame*) final;
80     void canceledComposition() final;
81     void didUpdateComposition() final;
82     void didEndEditing() final;
83     void willWriteSelectionToPasteboard(WebCore::Range*) final;
84     void didWriteSelectionToPasteboard() final;
85     void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final;
86     String replacementURLForResource(Ref<WebCore::SharedBuffer>&& resourceData, const String& mimeType) final;
87     
88     void registerUndoStep(WebCore::UndoStep&) final;
89     void registerRedoStep(WebCore::UndoStep&) final;
90     void clearUndoRedoOperations() final;
91
92     bool canCopyCut(WebCore::Frame*, bool defaultValue) const final;
93     bool canPaste(WebCore::Frame*, bool defaultValue) const final;
94     bool canUndo() const final;
95     bool canRedo() const final;
96     
97     void undo() final;
98     void redo() final;
99
100     void handleKeyboardEvent(WebCore::KeyboardEvent*) final;
101     void handleInputMethodKeydown(WebCore::KeyboardEvent*) final;
102     
103     void textFieldDidBeginEditing(WebCore::Element*) final;
104     void textFieldDidEndEditing(WebCore::Element*) final;
105     void textDidChangeInTextField(WebCore::Element*) final;
106     bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*) final;
107     void textWillBeDeletedInTextField(WebCore::Element*) final;
108     void textDidChangeInTextArea(WebCore::Element*) final;
109     void overflowScrollPositionChanged() final;
110
111 #if PLATFORM(COCOA)
112     void setInsertionPasteboard(const String& pasteboardName) final;
113 #endif
114
115 #if USE(APPKIT)
116     void uppercaseWord() final;
117     void lowercaseWord() final;
118     void capitalizeWord() final;
119 #endif
120
121 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
122     void showSubstitutionsPanel(bool show) final;
123     bool substitutionsPanelIsShowing() final;
124     void toggleSmartInsertDelete() final;
125     bool isAutomaticQuoteSubstitutionEnabled() final;
126     void toggleAutomaticQuoteSubstitution() final;
127     bool isAutomaticLinkDetectionEnabled() final;
128     void toggleAutomaticLinkDetection() final;
129     bool isAutomaticDashSubstitutionEnabled() final;
130     void toggleAutomaticDashSubstitution() final;
131     bool isAutomaticTextReplacementEnabled() final;
132     void toggleAutomaticTextReplacement() final;
133     bool isAutomaticSpellingCorrectionEnabled() final;
134     void toggleAutomaticSpellingCorrection() final;
135 #endif
136
137 #if PLATFORM(GTK)
138     bool executePendingEditorCommands(WebCore::Frame*, const Vector<WTF::String>&, bool);
139     void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&);
140     void updateGlobalSelection(WebCore::Frame*);
141 #endif
142
143     TextCheckerClient* textChecker() final { return this; }
144
145     bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const final;
146     void ignoreWordInSpellDocument(const String&) final;
147     void learnWord(const String&) final;
148     void checkSpellingOfString(StringView, int* misspellingLocation, int* misspellingLength) final;
149     String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) final;
150     void checkGrammarOfString(StringView, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) final;
151
152 #if USE(UNIFIED_TEXT_CHECKING)
153     Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, OptionSet<WebCore::TextCheckingType> checkingTypes, const WebCore::VisibleSelection& currentSelection) final;
154 #endif
155
156     void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) final;
157     void updateSpellingUIWithMisspelledWord(const String&) final;
158     void showSpellingUI(bool show) final;
159     bool spellingUIIsShowing() final;
160     void getGuessesForWord(const String& word, const String& context, const WebCore::VisibleSelection& currentSelection, Vector<String>& guesses) final;
161     void willSetInputMethodState() final;
162     void setInputMethodState(bool enabled) final;
163     void requestCheckingOfString(WebCore::TextCheckingRequest&, const WebCore::VisibleSelection& currentSelection) final;
164
165 #if PLATFORM(GTK)
166     bool shouldShowUnicodeMenu() final;
167 #endif
168
169 #if PLATFORM(IOS_FAMILY)
170     void startDelayingAndCoalescingContentChangeNotifications() final;
171     void stopDelayingAndCoalescingContentChangeNotifications() final;
172     bool hasRichlyEditableSelection() final;
173     int getPasteboardItemsCount() final;
174     RefPtr<WebCore::DocumentFragment> documentFragmentFromDelegate(int index) final;
175     bool performsTwoStepPaste(WebCore::DocumentFragment*) final;
176     void updateStringForFind(const String&) final;
177 #endif
178
179     bool performTwoStepDrop(WebCore::DocumentFragment&, WebCore::Range&, bool isMove) final;
180     bool supportsGlobalSelection() final;
181
182     WebPage* m_page;
183 };
184
185 } // namespace WebKit