1/* 2 * Copyright 2007, The Android Open Source Project 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 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * 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 THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef EditorClientAndroid_h 27#define EditorClientAndroid_h 28 29#include "config.h" 30 31 32#include "EditorClient.h" 33#include "Page.h" 34#include "TextCheckerClient.h" 35#include "autofill/WebAutofill.h" 36 37#include <wtf/OwnPtr.h> 38 39using namespace WebCore; 40 41namespace android { 42 43class EditorClientAndroid : public EditorClient, public TextCheckerClient { 44public: 45 EditorClientAndroid() { 46 m_shouldChangeSelectedRange = true; 47 m_uiGeneratedSelectionChange = false; 48 } 49 virtual void pageDestroyed(); 50 51 virtual bool shouldDeleteRange(Range*); 52 virtual bool shouldShowDeleteInterface(HTMLElement*); 53 virtual bool smartInsertDeleteEnabled(); 54 virtual bool isSelectTrailingWhitespaceEnabled(); 55 virtual bool isContinuousSpellCheckingEnabled(); 56 virtual void toggleContinuousSpellChecking(); 57 virtual bool isGrammarCheckingEnabled(); 58 virtual void toggleGrammarChecking(); 59 virtual int spellCheckerDocumentTag(); 60 61 virtual bool isEditable(); 62 63 virtual bool shouldBeginEditing(Range*); 64 virtual bool shouldEndEditing(Range*); 65 virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction); 66 virtual bool shouldInsertText(const String&, Range*, EditorInsertAction); 67 virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting); 68 69 virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*); 70// virtual bool shouldChangeTypingStyle(CSSStyleDeclaration* fromStyle, CSSStyleDeclaration* toStyle); 71// virtual bool doCommandBySelector(SEL selector); 72 virtual bool shouldMoveRangeAfterDelete(Range*, Range*); 73 74 virtual void didBeginEditing(); 75 virtual void respondToChangedContents(); 76 virtual void respondToChangedSelection(); 77 virtual void didEndEditing(); 78 virtual void didWriteSelectionToPasteboard(); 79 virtual void didSetSelectionTypesForPasteboard(); 80// virtual void didChangeTypingStyle:(NSNotification *)notification; 81// virtual void didChangeSelection:(NSNotification *)notification; 82// virtual NSUndoManager* undoManager:(WebView *)webView; 83 84 virtual void registerCommandForUndo(PassRefPtr<EditCommand>); 85 virtual void registerCommandForRedo(PassRefPtr<EditCommand>); 86 virtual void clearUndoRedoOperations(); 87 88 virtual bool canCopyCut(bool defaultValue) const; 89 virtual bool canPaste(bool defaultValue) const; 90 virtual bool canUndo() const; 91 virtual bool canRedo() const; 92 93 virtual void undo(); 94 virtual void redo(); 95 96 virtual void handleKeyboardEvent(KeyboardEvent*); 97 virtual void handleInputMethodKeydown(KeyboardEvent*); 98 99 virtual void textFieldDidBeginEditing(Element*); 100 virtual void textFieldDidEndEditing(Element*); 101 virtual void textDidChangeInTextField(Element*); 102 virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*); 103 virtual void textWillBeDeletedInTextField(Element*); 104 virtual void textDidChangeInTextArea(Element*); 105 106 virtual void ignoreWordInSpellDocument(const String&); 107 virtual void learnWord(const String&); 108 virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength); 109 virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWorld); 110 virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength); 111 virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail); 112 virtual void updateSpellingUIWithMisspelledWord(const String&); 113 virtual void showSpellingUI(bool show); 114 virtual bool spellingUIIsShowing(); 115 virtual void getGuessesForWord(const String&, const String& context, WTF::Vector<String>& guesses); 116 virtual void willSetInputMethodState(); 117 virtual void setInputMethodState(bool); 118 virtual void requestCheckingOfString(SpellChecker*, int, TextCheckingTypeMask, const String&); 119 120 virtual TextCheckerClient* textChecker() { return this; } 121 122 // Android specific: 123 void setPage(Page* page) { m_page = page; } 124 void setShouldChangeSelectedRange(bool shouldChangeSelectedRange) { m_shouldChangeSelectedRange = shouldChangeSelectedRange; } 125 void setUiGeneratedSelectionChange(bool uiGenerated) { m_uiGeneratedSelectionChange = uiGenerated; } 126#if ENABLE(WEB_AUTOFILL) 127 WebAutofill* getAutofill(); 128#endif 129private: 130 Page* m_page; 131 bool m_shouldChangeSelectedRange; 132 bool m_uiGeneratedSelectionChange; 133#if ENABLE(WEB_AUTOFILL) 134 OwnPtr<WebAutofill> m_autoFill; 135#endif 136}; 137 138} 139 140#endif 141