WebKit/chromium/src/EditorClientImpl.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2009 Google 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 are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #ifndef EditorClientImpl_h
       
    32 #define EditorClientImpl_h
       
    33 
       
    34 #include "EditorClient.h"
       
    35 #include "Timer.h"
       
    36 #include <wtf/Deque.h>
       
    37 
       
    38 namespace WebCore {
       
    39 class HTMLInputElement;
       
    40 }
       
    41 
       
    42 namespace WebKit {
       
    43 class WebViewImpl;
       
    44 
       
    45 class EditorClientImpl : public WebCore::EditorClient {
       
    46 public:
       
    47     EditorClientImpl(WebViewImpl* webView);
       
    48 
       
    49     virtual ~EditorClientImpl();
       
    50     virtual void pageDestroyed();
       
    51 
       
    52     virtual bool shouldShowDeleteInterface(WebCore::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     virtual bool isEditable();
       
    61     virtual bool shouldBeginEditing(WebCore::Range*);
       
    62     virtual bool shouldEndEditing(WebCore::Range*);
       
    63     virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction);
       
    64     virtual bool shouldInsertText(const WebCore::String&, WebCore::Range*, WebCore::EditorInsertAction);
       
    65     virtual bool shouldDeleteRange(WebCore::Range*);
       
    66     virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange,
       
    67                                            WebCore::Range* toRange,
       
    68                                            WebCore::EAffinity,
       
    69                                            bool stillSelecting);
       
    70     virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
       
    71     virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
       
    72     virtual void didBeginEditing();
       
    73     virtual void respondToChangedContents();
       
    74     virtual void respondToChangedSelection();
       
    75     virtual void didEndEditing();
       
    76     virtual void didWriteSelectionToPasteboard();
       
    77     virtual void didSetSelectionTypesForPasteboard();
       
    78     virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>);
       
    79     virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>);
       
    80     virtual void clearUndoRedoOperations();
       
    81     virtual bool canUndo() const;
       
    82     virtual bool canRedo() const;
       
    83     virtual void undo();
       
    84     virtual void redo();
       
    85     virtual const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
       
    86     virtual bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
       
    87     virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
       
    88     virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
       
    89     virtual void textFieldDidBeginEditing(WebCore::Element*);
       
    90     virtual void textFieldDidEndEditing(WebCore::Element*);
       
    91     virtual void textDidChangeInTextField(WebCore::Element*);
       
    92     virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
       
    93     virtual void textWillBeDeletedInTextField(WebCore::Element*);
       
    94     virtual void textDidChangeInTextArea(WebCore::Element*);
       
    95     virtual void ignoreWordInSpellDocument(const WebCore::String&);
       
    96     virtual void learnWord(const WebCore::String&);
       
    97     virtual void checkSpellingOfString(const UChar*, int length,
       
    98                                        int* misspellingLocation,
       
    99                                        int* misspellingLength);
       
   100     virtual void checkGrammarOfString(const UChar*, int length,
       
   101                                       WTF::Vector<WebCore::GrammarDetail>&,
       
   102                                       int* badGrammarLocation,
       
   103                                       int* badGrammarLength);
       
   104     virtual WebCore::String getAutoCorrectSuggestionForMisspelledWord(const WebCore::String&);
       
   105     virtual void updateSpellingUIWithGrammarString(const WebCore::String&, const WebCore::GrammarDetail&);
       
   106     virtual void updateSpellingUIWithMisspelledWord(const WebCore::String&);
       
   107     virtual void showSpellingUI(bool show);
       
   108     virtual bool spellingUIIsShowing();
       
   109     virtual void getGuessesForWord(const WebCore::String& word,
       
   110                                    WTF::Vector<WebCore::String>& guesses);
       
   111     virtual void willSetInputMethodState();
       
   112     virtual void setInputMethodState(bool enabled);
       
   113 
       
   114     // Shows the form autofill popup for |node| if it is an HTMLInputElement and
       
   115     // it is empty.  This is called when you press the up or down arrow in a
       
   116     // text-field or when clicking an already focused text-field.
       
   117     // Returns true if the autofill popup has been scheduled to be shown, false
       
   118     // otherwise.
       
   119     virtual bool showFormAutofillForNode(WebCore::Node*);
       
   120 
       
   121     // Notification that the text changed due to acceptance of a suggestion
       
   122     // provided by an Autocomplete popup.  Having a separate callback in this
       
   123     // case is a simple way to break the cycle that would otherwise occur if
       
   124     // textDidChangeInTextField was called.
       
   125     virtual void onAutocompleteSuggestionAccepted(WebCore::HTMLInputElement*);
       
   126 
       
   127 private:
       
   128     void modifySelection(WebCore::Frame*, WebCore::KeyboardEvent*);
       
   129 
       
   130     // Triggers autofill for an input element if applicable.  This can be form
       
   131     // autofill (via a popup-menu) or password autofill depending on the
       
   132     // input element.  If |formAutofillOnly| is true, password autofill is not
       
   133     // triggered.
       
   134     // |autofillOnEmptyValue| indicates whether the autofill should be shown
       
   135     // when the text-field is empty.
       
   136     // If |requiresCaretAtEnd| is true, the autofill popup is only shown if the
       
   137     // caret is located at the end of the entered text.
       
   138     // Returns true if the autofill popup has been scheduled to be shown, false
       
   139     // otherwise.
       
   140     bool autofill(WebCore::HTMLInputElement*,
       
   141                   bool formAutofillOnly, bool autofillOnEmptyValue,
       
   142                   bool requiresCaretAtEnd);
       
   143 
       
   144     // Called to process the autofill described by m_autofillArgs.
       
   145     // This method is invoked asynchronously if the caret position is not
       
   146     // reflecting the last text change yet, and we need it to decide whether or
       
   147     // not to show the autofill popup.
       
   148     void doAutofill(WebCore::Timer<EditorClientImpl>*);
       
   149 
       
   150     void cancelPendingAutofill();
       
   151 
       
   152     // Returns whether or not the focused control needs spell-checking.
       
   153     // Currently, this function just retrieves the focused node and determines
       
   154     // whether or not it is a <textarea> element or an element whose
       
   155     // contenteditable attribute is true.
       
   156     // FIXME: Bug 740540: This code just implements the default behavior
       
   157     // proposed in this issue. We should also retrieve "spellcheck" attributes
       
   158     // for text fields and create a flag to over-write the default behavior.
       
   159     bool shouldSpellcheckByDefault();
       
   160 
       
   161     WebViewImpl* m_webView;
       
   162     bool m_inRedo;
       
   163 
       
   164     typedef Deque<RefPtr<WebCore::EditCommand> > EditCommandStack;
       
   165     EditCommandStack m_undoStack;
       
   166     EditCommandStack m_redoStack;
       
   167 
       
   168     // Whether the last entered key was a backspace.
       
   169     bool m_backspaceOrDeletePressed;
       
   170 
       
   171     // This flag is set to false if spell check for this editor is manually
       
   172     // turned off. The default setting is SpellCheckAutomatic.
       
   173     enum {
       
   174         SpellCheckAutomatic,
       
   175         SpellCheckForcedOn,
       
   176         SpellCheckForcedOff
       
   177     };
       
   178     int m_spellCheckThisFieldStatus;
       
   179 
       
   180     // Used to delay autofill processing.
       
   181     WebCore::Timer<EditorClientImpl> m_autofillTimer;
       
   182 
       
   183     struct AutofillArgs {
       
   184         RefPtr<WebCore::HTMLInputElement> inputElement;
       
   185         bool autofillFormOnly;
       
   186         bool autofillOnEmptyValue;
       
   187         bool requireCaretAtEnd;
       
   188         bool backspaceOrDeletePressed;
       
   189     };
       
   190     OwnPtr<AutofillArgs> m_autofillArgs;
       
   191 };
       
   192 
       
   193 } // namespace WebKit
       
   194 
       
   195 #endif