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#ifndef WebEditorClient_h 27#define WebEditorClient_h 28 29#include <WebCore/EditorClient.h> 30#include <WebCore/TextCheckerClient.h> 31 32namespace WebKit { 33 34class WebPage; 35 36class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient { 37public: 38 WebEditorClient(WebPage* page) 39 : m_page(page) 40 { 41 } 42 43private: 44 virtual void pageDestroyed() override; 45 46 virtual bool shouldDeleteRange(WebCore::Range*) override; 47 virtual bool smartInsertDeleteEnabled() override; 48 virtual bool isSelectTrailingWhitespaceEnabled() override; 49 virtual bool isContinuousSpellCheckingEnabled() override; 50 virtual void toggleContinuousSpellChecking() override; 51 virtual bool isGrammarCheckingEnabled() override; 52 virtual void toggleGrammarChecking() override; 53 virtual int spellCheckerDocumentTag() override; 54 55 virtual bool shouldBeginEditing(WebCore::Range*) override; 56 virtual bool shouldEndEditing(WebCore::Range*) override; 57 virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction) override; 58 virtual bool shouldInsertText(const String&, WebCore::Range*, WebCore::EditorInsertAction) override; 59 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting) override; 60 61 virtual bool shouldApplyStyle(WebCore::StyleProperties*, WebCore::Range*) override; 62 virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*) override; 63 64 virtual void didBeginEditing() override; 65 virtual void respondToChangedContents() override; 66 virtual void respondToChangedSelection(WebCore::Frame*) override; 67 virtual void didEndEditing() override; 68 virtual void willWriteSelectionToPasteboard(WebCore::Range*) override; 69 virtual void didWriteSelectionToPasteboard() override; 70 virtual void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) override; 71 72 virtual void registerUndoStep(PassRefPtr<WebCore::UndoStep>) override; 73 virtual void registerRedoStep(PassRefPtr<WebCore::UndoStep>) override; 74 virtual void clearUndoRedoOperations() override; 75 76 virtual bool canCopyCut(WebCore::Frame*, bool defaultValue) const override; 77 virtual bool canPaste(WebCore::Frame*, bool defaultValue) const override; 78 virtual bool canUndo() const override; 79 virtual bool canRedo() const override; 80 81 virtual void undo() override; 82 virtual void redo() override; 83 84 virtual void handleKeyboardEvent(WebCore::KeyboardEvent*) override; 85 virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*) override; 86 87 virtual void textFieldDidBeginEditing(WebCore::Element*) override; 88 virtual void textFieldDidEndEditing(WebCore::Element*) override; 89 virtual void textDidChangeInTextField(WebCore::Element*) override; 90 virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*) override; 91 virtual void textWillBeDeletedInTextField(WebCore::Element*) override; 92 virtual void textDidChangeInTextArea(WebCore::Element*) override; 93 virtual void overflowScrollPositionChanged() override; 94 95#if PLATFORM(COCOA) 96 virtual NSString *userVisibleString(NSURL *) override; 97 virtual WebCore::DocumentFragment* documentFragmentFromAttributedString(NSAttributedString *, Vector< RefPtr<WebCore::ArchiveResource>>&) override; 98 virtual void setInsertionPasteboard(const String& pasteboardName) override; 99 virtual NSURL* canonicalizeURL(NSURL*) override; 100 virtual NSURL* canonicalizeURLString(NSString*) override; 101#endif 102 103#if USE(APPKIT) 104 virtual void uppercaseWord() override; 105 virtual void lowercaseWord() override; 106 virtual void capitalizeWord() override; 107#endif 108#if USE(AUTOMATIC_TEXT_REPLACEMENT) 109 virtual void showSubstitutionsPanel(bool show) override; 110 virtual bool substitutionsPanelIsShowing() override; 111 virtual void toggleSmartInsertDelete() override; 112 virtual bool isAutomaticQuoteSubstitutionEnabled() override; 113 virtual void toggleAutomaticQuoteSubstitution() override; 114 virtual bool isAutomaticLinkDetectionEnabled() override; 115 virtual void toggleAutomaticLinkDetection() override; 116 virtual bool isAutomaticDashSubstitutionEnabled() override; 117 virtual void toggleAutomaticDashSubstitution() override; 118 virtual bool isAutomaticTextReplacementEnabled() override; 119 virtual void toggleAutomaticTextReplacement() override; 120 virtual bool isAutomaticSpellingCorrectionEnabled() override; 121 virtual void toggleAutomaticSpellingCorrection() override; 122#endif 123 124#if ENABLE(DELETION_UI) 125 virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*) override; 126#endif 127 128#if PLATFORM(GTK) 129 bool executePendingEditorCommands(WebCore::Frame*, const Vector<WTF::String>&, bool); 130 void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&); 131 void updateGlobalSelection(WebCore::Frame*); 132#endif 133 134 TextCheckerClient* textChecker() override { return this; } 135 136 virtual bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const override; 137 virtual void ignoreWordInSpellDocument(const String&) override; 138 virtual void learnWord(const String&) override; 139 virtual void checkSpellingOfString(StringView, int* misspellingLocation, int* misspellingLength) override; 140 virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) override; 141 virtual void checkGrammarOfString(StringView, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) override; 142#if USE(UNIFIED_TEXT_CHECKING) 143 virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) override; 144#endif 145 virtual void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) override; 146 virtual void updateSpellingUIWithMisspelledWord(const String&) override; 147 virtual void showSpellingUI(bool show) override; 148 virtual bool spellingUIIsShowing() override; 149 virtual void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses) override; 150 virtual void willSetInputMethodState() override; 151 virtual void setInputMethodState(bool enabled) override; 152 virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) override; 153#if PLATFORM(GTK) 154 virtual bool shouldShowUnicodeMenu() override; 155#endif 156#if PLATFORM(IOS) 157 virtual void startDelayingAndCoalescingContentChangeNotifications() override; 158 virtual void stopDelayingAndCoalescingContentChangeNotifications() override; 159 virtual void writeDataToPasteboard(NSDictionary*) override; 160 virtual NSArray *supportedPasteboardTypesForCurrentSelection() override; 161 virtual NSArray *readDataFromPasteboard(NSString* type, int index) override; 162 virtual bool hasRichlyEditableSelection() override; 163 virtual int getPasteboardItemsCount() override; 164 virtual WebCore::DocumentFragment* documentFragmentFromDelegate(int index) override; 165 virtual bool performsTwoStepPaste(WebCore::DocumentFragment*) override; 166 virtual int pasteboardChangeCount() override; 167#endif 168 169 virtual bool supportsGlobalSelection() override; 170 171#if ENABLE(TELEPHONE_NUMBER_DETECTION) || ENABLE(SERVICE_CONTROLS) 172 virtual void selectedTelephoneNumberRangesChanged() override; 173 virtual void selectionRectsDidChange(const Vector<WebCore::LayoutRect>&, const Vector<WebCore::GapRects>&, bool isTextOnly) override; 174#endif 175 176 WebPage* m_page; 177}; 178 179} // namespace WebKit 180 181#endif // WebEditorClient_h 182