1/* 2 * Copyright (C) 2006, 2007 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 COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 WebEditorClient_H 27#define WebEditorClient_H 28 29#include "WebKit.h" 30#include <WebCore/EditorClient.h> 31#include <WebCore/TextCheckerClient.h> 32#include <wtf/OwnPtr.h> 33 34class WebView; 35class WebNotification; 36class WebEditorUndoTarget; 37 38class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient { 39public: 40 WebEditorClient(WebView*); 41 ~WebEditorClient(); 42 43 virtual void pageDestroyed(); 44 virtual void frameWillDetachPage(WebCore::Frame*) { } 45 46 virtual bool isContinuousSpellCheckingEnabled(); 47 virtual void toggleGrammarChecking(); 48 virtual bool isGrammarCheckingEnabled(); 49 virtual void toggleContinuousSpellChecking(); 50 virtual int spellCheckerDocumentTag(); 51 52 virtual bool shouldBeginEditing(WebCore::Range*); 53 virtual bool shouldEndEditing(WebCore::Range*); 54 virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction); 55 56 virtual void didBeginEditing(); 57 virtual void didEndEditing(); 58 virtual void willWriteSelectionToPasteboard(WebCore::Range*); 59 virtual void didWriteSelectionToPasteboard(); 60 virtual void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer> >& pasteboardData); 61 virtual void didSetSelectionTypesForPasteboard(); 62 63 virtual void respondToChangedContents(); 64 virtual void respondToChangedSelection(WebCore::Frame*); 65 66 bool shouldDeleteRange(WebCore::Range*); 67 68 bool shouldInsertNode(WebCore::Node*, WebCore::Range* replacingRange, WebCore::EditorInsertAction); 69 bool shouldApplyStyle(WebCore::StylePropertySet*, WebCore::Range*); 70 bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*); 71 bool shouldChangeTypingStyle(WebCore::StylePropertySet* currentStyle, WebCore::StylePropertySet* toProposedStyle); 72 73 void webViewDidChangeTypingStyle(WebNotification*); 74 void webViewDidChangeSelection(WebNotification*); 75 76 bool smartInsertDeleteEnabled(); 77 bool isSelectTrailingWhitespaceEnabled(); 78 79 void registerUndoStep(PassRefPtr<WebCore::UndoStep>); 80 void registerRedoStep(PassRefPtr<WebCore::UndoStep>); 81 void clearUndoRedoOperations(); 82 83 bool canCopyCut(WebCore::Frame*, bool defaultValue) const; 84 bool canPaste(WebCore::Frame*, bool defaultValue) const; 85 bool canUndo() const; 86 bool canRedo() const; 87 88 void undo(); 89 void redo(); 90 91 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting); 92 virtual void textFieldDidBeginEditing(WebCore::Element*); 93 virtual void textFieldDidEndEditing(WebCore::Element*); 94 virtual void textDidChangeInTextField(WebCore::Element*); 95 virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*); 96 virtual void textWillBeDeletedInTextField(WebCore::Element* input); 97 virtual void textDidChangeInTextArea(WebCore::Element*); 98 99 void handleKeyboardEvent(WebCore::KeyboardEvent*); 100 void handleInputMethodKeydown(WebCore::KeyboardEvent*); 101 102 virtual bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const; 103 virtual void ignoreWordInSpellDocument(const WTF::String&); 104 virtual void learnWord(const WTF::String&); 105 virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength); 106 virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&); 107 virtual void checkGrammarOfString(const UChar*, int length, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength); 108 virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail& detail); 109 virtual void updateSpellingUIWithMisspelledWord(const WTF::String&); 110 virtual void showSpellingUI(bool show); 111 virtual bool spellingUIIsShowing(); 112 virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses); 113 114 virtual void willSetInputMethodState(); 115 virtual void setInputMethodState(bool); 116 virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) { } 117 118 virtual WebCore::TextCheckerClient* textChecker() { return this; } 119 120private: 121 WebView* m_webView; 122 WebEditorUndoTarget* m_undoTarget; 123}; 124 125#endif // WebEditorClient_H 126