[Attachment Support] Provide the `src` of an attachment to the UI delegate when an...
[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 didInsertAttachment(const String& identifier, const String& source) final;
64     void didRemoveAttachment(const String& identifier) final;
65 #endif
66
67     void didBeginEditing() final;
68     void respondToChangedContents() final;
69     void respondToChangedSelection(WebCore::Frame*) final;
70     void didEndUserTriggeredSelectionChanges() final;
71     void updateEditorStateAfterLayoutIfEditabilityChanged() final;
72     void discardedComposition(WebCore::Frame*) final;
73     void canceledComposition() final;
74     void didUpdateComposition() final;
75     void didEndEditing() final;
76     void willWriteSelectionToPasteboard(WebCore::Range*) final;
77     void didWriteSelectionToPasteboard() final;
78     void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final;
79     
80     void registerUndoStep(WebCore::UndoStep&) final;
81     void registerRedoStep(WebCore::UndoStep&) final;
82     void clearUndoRedoOperations() final;
83
84     bool canCopyCut(WebCore::Frame*, bool defaultValue) const final;
85     bool canPaste(WebCore::Frame*, bool defaultValue) const final;
86     bool canUndo() const final;
87     bool canRedo() const final;
88     
89     void undo() final;
90     void redo() final;
91
92     void handleKeyboardEvent(WebCore::KeyboardEvent*) final;
93     void handleInputMethodKeydown(WebCore::KeyboardEvent*) final;
94     
95     void textFieldDidBeginEditing(WebCore::Element*) final;
96     void textFieldDidEndEditing(WebCore::Element*) final;
97     void textDidChangeInTextField(WebCore::Element*) final;
98     bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*) final;
99     void textWillBeDeletedInTextField(WebCore::Element*) final;
100     void textDidChangeInTextArea(WebCore::Element*) final;
101     void overflowScrollPositionChanged() final;
102
103 #if PLATFORM(COCOA)
104     void setInsertionPasteboard(const String& pasteboardName) final;
105 #endif
106
107 #if USE(APPKIT)
108     void uppercaseWord() final;
109     void lowercaseWord() final;
110     void capitalizeWord() final;
111 #endif
112
113 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
114     void showSubstitutionsPanel(bool show) final;
115     bool substitutionsPanelIsShowing() final;
116     void toggleSmartInsertDelete() final;
117     bool isAutomaticQuoteSubstitutionEnabled() final;
118     void toggleAutomaticQuoteSubstitution() final;
119     bool isAutomaticLinkDetectionEnabled() final;
120     void toggleAutomaticLinkDetection() final;
121     bool isAutomaticDashSubstitutionEnabled() final;
122     void toggleAutomaticDashSubstitution() final;
123     bool isAutomaticTextReplacementEnabled() final;
124     void toggleAutomaticTextReplacement() final;
125     bool isAutomaticSpellingCorrectionEnabled() final;
126     void toggleAutomaticSpellingCorrection() final;
127 #endif
128
129 #if PLATFORM(GTK)
130     bool executePendingEditorCommands(WebCore::Frame*, const Vector<WTF::String>&, bool);
131     void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&);
132     void updateGlobalSelection(WebCore::Frame*);
133 #endif
134
135     TextCheckerClient* textChecker() final { return this; }
136
137     bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const final;
138     void ignoreWordInSpellDocument(const String&) final;
139     void learnWord(const String&) final;
140     void checkSpellingOfString(StringView, int* misspellingLocation, int* misspellingLength) final;
141     String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) final;
142     void checkGrammarOfString(StringView, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) final;
143
144 #if USE(UNIFIED_TEXT_CHECKING)
145     Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes, const WebCore::VisibleSelection& currentSelection) final;
146 #endif
147
148     void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) final;
149     void updateSpellingUIWithMisspelledWord(const String&) final;
150     void showSpellingUI(bool show) final;
151     bool spellingUIIsShowing() final;
152     void getGuessesForWord(const String& word, const String& context, const WebCore::VisibleSelection& currentSelection, Vector<String>& guesses) final;
153     void willSetInputMethodState() final;
154     void setInputMethodState(bool enabled) final;
155     void requestCheckingOfString(WebCore::TextCheckingRequest&, const WebCore::VisibleSelection& currentSelection) final;
156
157 #if PLATFORM(GTK)
158     bool shouldShowUnicodeMenu() final;
159 #endif
160
161 #if PLATFORM(IOS)
162     void startDelayingAndCoalescingContentChangeNotifications() final;
163     void stopDelayingAndCoalescingContentChangeNotifications() final;
164     bool hasRichlyEditableSelection() final;
165     int getPasteboardItemsCount() final;
166     RefPtr<WebCore::DocumentFragment> documentFragmentFromDelegate(int index) final;
167     bool performsTwoStepPaste(WebCore::DocumentFragment*) final;
168 #endif
169
170     bool performTwoStepDrop(WebCore::DocumentFragment&, WebCore::Range&, bool isMove) final;
171     bool supportsGlobalSelection() final;
172
173     WebPage* m_page;
174 };
175
176 } // namespace WebKit