1 /* 2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #pragma once 27 28 #include "EditorClient.h" 29 #include "TextCheckerClient.h" 30 #include <wtf/java/JavaEnv.h> 31 32 #include <wtf/Deque.h> 33 #include <wtf/Forward.h> 34 35 namespace WebCore { 36 37 class Page; 38 39 class EditorClientJava final : public EditorClient, public TextCheckerClient { 40 WTF_MAKE_NONCOPYABLE(EditorClientJava); WTF_MAKE_FAST_ALLOCATED; 41 public: 42 EditorClientJava(const JLObject &webPage); 43 ~EditorClientJava() override; 44 45 bool shouldDeleteRange(Range*) override; 46 bool smartInsertDeleteEnabled() override; 47 bool isSelectTrailingWhitespaceEnabled() const override; 48 bool isContinuousSpellCheckingEnabled() override; 49 void toggleContinuousSpellChecking() override; 50 bool isGrammarCheckingEnabled() override; 51 void toggleGrammarChecking() override; 52 int spellCheckerDocumentTag() override; 53 54 bool shouldBeginEditing(Range*) override; 55 bool shouldEndEditing(Range*) override; 56 bool shouldInsertNode(Node*, Range*, EditorInsertAction) override; 57 bool shouldInsertText(const String&, Range*, EditorInsertAction) override; 58 bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting) override; 59 60 bool shouldApplyStyle(StyleProperties*, Range*) override; 61 void didApplyStyle() override; 62 bool shouldMoveRangeAfterDelete(Range*, Range*) override; 63 64 void didBeginEditing() override; 65 void respondToChangedContents() override; 66 void respondToChangedSelection(Frame*) override; 67 void didEndUserTriggeredSelectionChanges() final { } 68 void updateEditorStateAfterLayoutIfEditabilityChanged() override; 69 void didEndEditing() override; 70 void willWriteSelectionToPasteboard(Range*) override; 71 void didWriteSelectionToPasteboard() override; 72 void getClientPasteboardDataForRange(Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer> >& pasteboardData) override; 73 void didUpdateComposition() final { } 74 75 void discardedComposition(Frame*) override; 76 void canceledComposition() override; 77 78 void registerUndoStep(UndoStep&) override; 79 void registerRedoStep(UndoStep&) override; 80 void clearUndoRedoOperations() override; 81 82 bool canCopyCut(Frame*, bool defaultValue) const override; 83 bool canPaste(Frame*, bool defaultValue) const override; 84 bool canUndo() const override; 85 bool canRedo() const override; 86 87 void undo() override; 88 void redo() override; 89 90 void handleKeyboardEvent(KeyboardEvent*) override; 91 void handleInputMethodKeydown(KeyboardEvent*) override; 92 93 void textFieldDidBeginEditing(Element*) override; 94 void textFieldDidEndEditing(Element*) override; 95 void textDidChangeInTextField(Element*) override; 96 bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*) override; 97 void textWillBeDeletedInTextField(Element*) override; 98 void textDidChangeInTextArea(Element*) override; 99 void overflowScrollPositionChanged() override; 100 101 #if USE(APPKIT) 102 void uppercaseWord() override; 103 void lowercaseWord() override; 104 void capitalizeWord() override; 105 #endif 106 107 #if USE(AUTOMATIC_TEXT_REPLACEMENT) 108 void showSubstitutionsPanel(bool show) override; 109 bool substitutionsPanelIsShowing() override; 110 void toggleSmartInsertDelete() override; 111 bool isAutomaticQuoteSubstitutionEnabled() override; 112 void toggleAutomaticQuoteSubstitution() override; 113 bool isAutomaticLinkDetectionEnabled() override; 114 void toggleAutomaticLinkDetection() override; 115 bool isAutomaticDashSubstitutionEnabled() override; 116 void toggleAutomaticDashSubstitution() override; 117 bool isAutomaticTextReplacementEnabled() override; 118 void toggleAutomaticTextReplacement() override; 119 bool isAutomaticSpellingCorrectionEnabled() override; 120 void toggleAutomaticSpellingCorrection() override; 121 #endif 122 123 #if ENABLE(DELETION_UI) 124 bool shouldShowDeleteInterface(HTMLElement*) override; 125 #endif 126 127 TextCheckerClient* textChecker() override { return static_cast<TextCheckerClient*>(this); } 128 129 void updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail) override; 130 void updateSpellingUIWithMisspelledWord(const String&) override; 131 void showSpellingUI(bool show) override; 132 bool spellingUIIsShowing() override; 133 void willSetInputMethodState() override; 134 void setInputMethodState(bool enabled) override; 135 136 // TextCheckerClient member functions 137 bool shouldEraseMarkersAfterChangeSelection(TextCheckingType) const override; 138 void ignoreWordInSpellDocument(const String&) override; 139 void learnWord(const String&) override; 140 void checkSpellingOfString(StringView, int* misspellingLocation, int* misspellingLength) override; 141 String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) override; 142 void checkGrammarOfString(StringView, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) override; 143 144 #if USE(UNIFIED_TEXT_CHECKING) 145 Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes, const VisibleSelection& currentSelection) override; 146 #endif 147 148 // For spellcheckers that support multiple languages, it's often important to be able to identify the language in order to 149 // provide more accurate correction suggestions. Caller can pass in more text in "context" to aid such spellcheckers on language 150 // identification. Noramlly it's the text surrounding the "word" for which we are getting correction suggestions. 151 void getGuessesForWord(const String& word, const String& context, const VisibleSelection& currentSelection, Vector<String>& guesses) override; 152 void requestCheckingOfString(TextCheckingRequest&, const VisibleSelection& currentSelection) override; 153 bool performTwoStepDrop(WebCore::DocumentFragment&, WebCore::Range&, bool) final { return false; } 154 String replacementURLForResource(Ref<WebCore::SharedBuffer>&&, const String&) override; 155 protected: 156 JGObject m_webPage; 157 158 bool m_isInRedo; 159 Deque<Ref<UndoStep>> m_redoStack; 160 Deque<Ref<UndoStep>> m_undoStack; 161 static const char* interpretKeyEvent(const KeyboardEvent*); 162 static bool handleEditingKeyboardEvent(KeyboardEvent*); 163 }; 164 165 } // namespace WebCore