Home | History | Annotate | Download | only in WebCoreSupport
      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 
     34 class WebView;
     35 class WebNotification;
     36 class WebEditorUndoTarget;
     37 
     38 class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient {
     39 public:
     40     WebEditorClient(WebView*);
     41     ~WebEditorClient();
     42 
     43     virtual void pageDestroyed();
     44 
     45     virtual bool isContinuousSpellCheckingEnabled();
     46     virtual void toggleGrammarChecking();
     47     virtual bool isGrammarCheckingEnabled();
     48     virtual void toggleContinuousSpellChecking();
     49     virtual int spellCheckerDocumentTag();
     50 
     51     virtual bool shouldBeginEditing(WebCore::Range*);
     52     virtual bool shouldEndEditing(WebCore::Range*);
     53     virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction);
     54 
     55     virtual void didBeginEditing();
     56     virtual void didEndEditing();
     57     virtual void didWriteSelectionToPasteboard();
     58     virtual void didSetSelectionTypesForPasteboard();
     59 
     60     virtual void respondToChangedContents();
     61     virtual void respondToChangedSelection();
     62 
     63     bool shouldShowDeleteInterface(WebCore::HTMLElement*);
     64     bool shouldDeleteRange(WebCore::Range*);
     65 
     66     bool shouldInsertNode(WebCore::Node*, WebCore::Range* replacingRange, WebCore::EditorInsertAction);
     67     bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
     68     bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
     69     bool shouldChangeTypingStyle(WebCore::CSSStyleDeclaration* currentStyle, WebCore::CSSStyleDeclaration* toProposedStyle);
     70 
     71     void webViewDidChangeTypingStyle(WebNotification*);
     72     void webViewDidChangeSelection(WebNotification*);
     73 
     74     bool smartInsertDeleteEnabled();
     75     bool isSelectTrailingWhitespaceEnabled();
     76 
     77     void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>);
     78     void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>);
     79     void clearUndoRedoOperations();
     80 
     81     bool canCopyCut(bool defaultValue) const;
     82     bool canPaste(bool defaultValue) const;
     83     bool canUndo() const;
     84     bool canRedo() const;
     85 
     86     void undo();
     87     void redo();
     88 
     89     virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting);
     90     virtual void textFieldDidBeginEditing(WebCore::Element*);
     91     virtual void textFieldDidEndEditing(WebCore::Element*);
     92     virtual void textDidChangeInTextField(WebCore::Element*);
     93     virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
     94     virtual void textWillBeDeletedInTextField(WebCore::Element* input);
     95     virtual void textDidChangeInTextArea(WebCore::Element*);
     96 
     97     void handleKeyboardEvent(WebCore::KeyboardEvent*);
     98     void handleInputMethodKeydown(WebCore::KeyboardEvent*);
     99 
    100     virtual void ignoreWordInSpellDocument(const WTF::String&);
    101     virtual void learnWord(const WTF::String&);
    102     virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
    103     virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&);
    104     virtual void checkGrammarOfString(const UChar*, int length, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
    105     virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail& detail);
    106     virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
    107     virtual void showSpellingUI(bool show);
    108     virtual bool spellingUIIsShowing();
    109     virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses);
    110 
    111     virtual void willSetInputMethodState();
    112     virtual void setInputMethodState(bool);
    113     virtual void requestCheckingOfString(WebCore::SpellChecker*, int, WebCore::TextCheckingTypeMask, const WTF::String&) {}
    114     virtual WebCore::TextCheckerClient* textChecker() { return this; }
    115 
    116 private:
    117     WebView* m_webView;
    118     WebEditorUndoTarget* m_undoTarget;
    119 };
    120 
    121 #endif // WebEditorClient_H
    122