| 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 WebCore { |
| 32 | enum class DOMPasteAccessResponse : uint8_t; |
| 33 | } |
| 34 | |
| 35 | namespace WebKit { |
| 36 | |
| 37 | class WebPage; |
| 38 | |
| 39 | class WebEditorClient final : public WebCore::EditorClient, public WebCore::TextCheckerClient { |
| 40 | public: |
| 41 | WebEditorClient(WebPage* page) |
| 42 | : m_page(page) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | bool shouldDeleteRange(WebCore::Range*) final; |
| 48 | bool smartInsertDeleteEnabled() final; |
| 49 | bool isSelectTrailingWhitespaceEnabled() const final; |
| 50 | bool isContinuousSpellCheckingEnabled() final; |
| 51 | void toggleContinuousSpellChecking() final; |
| 52 | bool isGrammarCheckingEnabled() final; |
| 53 | void toggleGrammarChecking() final; |
| 54 | int spellCheckerDocumentTag() final; |
| 55 | |
| 56 | bool shouldBeginEditing(WebCore::Range*) final; |
| 57 | bool shouldEndEditing(WebCore::Range*) final; |
| 58 | bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction) final; |
| 59 | bool shouldInsertText(const String&, WebCore::Range*, WebCore::EditorInsertAction) final; |
| 60 | bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting) final; |
| 61 | |
| 62 | bool shouldApplyStyle(WebCore::StyleProperties*, WebCore::Range*) final; |
| 63 | void didApplyStyle() final; |
| 64 | bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*) final; |
| 65 | |
| 66 | #if ENABLE(ATTACHMENT_ELEMENT) |
| 67 | void registerAttachmentIdentifier(const String&, const String& contentType, const String& preferredFileName, Ref<WebCore::SharedBuffer>&&) final; |
| 68 | void registerAttachmentIdentifier(const String&, const String& contentType, const String& filePath) final; |
| 69 | void registerAttachmentIdentifier(const String&) final; |
| 70 | void registerAttachments(Vector<WebCore::SerializedAttachmentData>&&) final; |
| 71 | void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier) final; |
| 72 | void didInsertAttachmentWithIdentifier(const String& identifier, const String& source, bool hasEnclosingImage) final; |
| 73 | void didRemoveAttachmentWithIdentifier(const String& identifier) final; |
| 74 | bool supportsClientSideAttachmentData() const final { return true; } |
| 75 | Vector<WebCore::SerializedAttachmentData> serializedAttachmentDataForIdentifiers(const Vector<String>&) final; |
| 76 | #endif |
| 77 | |
| 78 | void didBeginEditing() final; |
| 79 | void respondToChangedContents() final; |
| 80 | void respondToChangedSelection(WebCore::Frame*) final; |
| 81 | void didEndUserTriggeredSelectionChanges() final; |
| 82 | void updateEditorStateAfterLayoutIfEditabilityChanged() final; |
| 83 | void discardedComposition(WebCore::Frame*) final; |
| 84 | void canceledComposition() final; |
| 85 | void didUpdateComposition() final; |
| 86 | void didEndEditing() final; |
| 87 | void willWriteSelectionToPasteboard(WebCore::Range*) final; |
| 88 | void didWriteSelectionToPasteboard() final; |
| 89 | void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final; |
| 90 | |
| 91 | void registerUndoStep(WebCore::UndoStep&) final; |
| 92 | void registerRedoStep(WebCore::UndoStep&) final; |
| 93 | void clearUndoRedoOperations() final; |
| 94 | |
| 95 | WebCore::DOMPasteAccessResponse requestDOMPasteAccess(const String& originIdentifier) final; |
| 96 | |
| 97 | bool canCopyCut(WebCore::Frame*, bool defaultValue) const final; |
| 98 | bool canPaste(WebCore::Frame*, bool defaultValue) const final; |
| 99 | bool canUndo() const final; |
| 100 | bool canRedo() const final; |
| 101 | |
| 102 | void undo() final; |
| 103 | void redo() final; |
| 104 | |
| 105 | void handleKeyboardEvent(WebCore::KeyboardEvent&) final; |
| 106 | void handleInputMethodKeydown(WebCore::KeyboardEvent&) final; |
| 107 | |
| 108 | void textFieldDidBeginEditing(WebCore::Element*) final; |
| 109 | void textFieldDidEndEditing(WebCore::Element*) final; |
| 110 | void textDidChangeInTextField(WebCore::Element*) final; |
| 111 | bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*) final; |
| 112 | void textWillBeDeletedInTextField(WebCore::Element*) final; |
| 113 | void textDidChangeInTextArea(WebCore::Element*) final; |
| 114 | void overflowScrollPositionChanged() final; |
| 115 | |
| 116 | #if PLATFORM(COCOA) |
| 117 | void setInsertionPasteboard(const String& pasteboardName) final; |
| 118 | #endif |
| 119 | |
| 120 | #if USE(APPKIT) |
| 121 | void uppercaseWord() final; |
| 122 | void lowercaseWord() final; |
| 123 | void capitalizeWord() final; |
| 124 | #endif |
| 125 | |
| 126 | #if USE(AUTOMATIC_TEXT_REPLACEMENT) |
| 127 | void showSubstitutionsPanel(bool show) final; |
| 128 | bool substitutionsPanelIsShowing() final; |
| 129 | void toggleSmartInsertDelete() final; |
| 130 | bool isAutomaticQuoteSubstitutionEnabled() final; |
| 131 | void toggleAutomaticQuoteSubstitution() final; |
| 132 | bool isAutomaticLinkDetectionEnabled() final; |
| 133 | void toggleAutomaticLinkDetection() final; |
| 134 | bool isAutomaticDashSubstitutionEnabled() final; |
| 135 | void toggleAutomaticDashSubstitution() final; |
| 136 | bool isAutomaticTextReplacementEnabled() final; |
| 137 | void toggleAutomaticTextReplacement() final; |
| 138 | bool isAutomaticSpellingCorrectionEnabled() final; |
| 139 | void toggleAutomaticSpellingCorrection() final; |
| 140 | #endif |
| 141 | |
| 142 | #if PLATFORM(GTK) |
| 143 | bool executePendingEditorCommands(WebCore::Frame&, const Vector<WTF::String>&, bool); |
| 144 | bool handleGtkEditorCommand(WebCore::Frame&, const String& command, bool); |
| 145 | void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&); |
| 146 | void updateGlobalSelection(WebCore::Frame*); |
| 147 | #endif |
| 148 | |
| 149 | TextCheckerClient* textChecker() final { return this; } |
| 150 | |
| 151 | bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const final; |
| 152 | void ignoreWordInSpellDocument(const String&) final; |
| 153 | void learnWord(const String&) final; |
| 154 | void checkSpellingOfString(StringView, int* misspellingLocation, int* misspellingLength) final; |
| 155 | String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) final; |
| 156 | void checkGrammarOfString(StringView, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) final; |
| 157 | |
| 158 | #if USE(UNIFIED_TEXT_CHECKING) |
| 159 | Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, OptionSet<WebCore::TextCheckingType> checkingTypes, const WebCore::VisibleSelection& currentSelection) final; |
| 160 | #endif |
| 161 | |
| 162 | void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) final; |
| 163 | void updateSpellingUIWithMisspelledWord(const String&) final; |
| 164 | void showSpellingUI(bool show) final; |
| 165 | bool spellingUIIsShowing() final; |
| 166 | void getGuessesForWord(const String& word, const String& context, const WebCore::VisibleSelection& currentSelection, Vector<String>& guesses) final; |
| 167 | void willSetInputMethodState() final; |
| 168 | void setInputMethodState(bool enabled) final; |
| 169 | void requestCheckingOfString(WebCore::TextCheckingRequest&, const WebCore::VisibleSelection& currentSelection) final; |
| 170 | |
| 171 | #if PLATFORM(GTK) |
| 172 | bool () final; |
| 173 | #endif |
| 174 | |
| 175 | #if PLATFORM(IOS_FAMILY) |
| 176 | void startDelayingAndCoalescingContentChangeNotifications() final; |
| 177 | void stopDelayingAndCoalescingContentChangeNotifications() final; |
| 178 | bool hasRichlyEditableSelection() final; |
| 179 | int getPasteboardItemsCount() final; |
| 180 | RefPtr<WebCore::DocumentFragment> documentFragmentFromDelegate(int index) final; |
| 181 | bool performsTwoStepPaste(WebCore::DocumentFragment*) final; |
| 182 | void updateStringForFind(const String&) final; |
| 183 | #endif |
| 184 | |
| 185 | bool performTwoStepDrop(WebCore::DocumentFragment&, WebCore::Range&, bool isMove) final; |
| 186 | bool supportsGlobalSelection() final; |
| 187 | |
| 188 | WebPage* m_page; |
| 189 | }; |
| 190 | |
| 191 | } // namespace WebKit |
| 192 | |