initial import
[vuplus_webkit] / Source / WebKit / mac / WebCoreSupport / WebEditorClient.h
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer. 
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution. 
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission. 
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #import "CorrectionPanel.h"
31 #import <WebCore/EditorClient.h>
32 #import <WebCore/TextCheckerClient.h>
33 #import <wtf/Forward.h>
34 #import <wtf/RetainPtr.h>
35 #import <wtf/Vector.h>
36
37 @class WebView;
38 @class WebEditorUndoTarget;
39
40 class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient {
41 public:
42     WebEditorClient(WebView *);
43     virtual ~WebEditorClient();
44     virtual void pageDestroyed();
45
46     virtual bool isGrammarCheckingEnabled();
47     virtual void toggleGrammarChecking();
48     virtual bool isContinuousSpellCheckingEnabled();
49     virtual void toggleContinuousSpellChecking();
50     virtual int spellCheckerDocumentTag();
51
52     virtual bool smartInsertDeleteEnabled();
53     virtual bool isSelectTrailingWhitespaceEnabled();
54
55     virtual bool shouldDeleteRange(WebCore::Range*);    
56     virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*);
57
58     virtual bool shouldBeginEditing(WebCore::Range*);
59     virtual bool shouldEndEditing(WebCore::Range*);
60     virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction);
61     virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction);
62     virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting);
63
64     virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
65     
66     virtual bool shouldMoveRangeAfterDelete(WebCore::Range* range, WebCore::Range* rangeToBeReplaced); 
67
68     virtual void didBeginEditing();
69     virtual void didEndEditing();
70     virtual void didWriteSelectionToPasteboard();
71     virtual void didSetSelectionTypesForPasteboard();
72
73     virtual NSString* userVisibleString(NSURL *);
74     virtual WebCore::DocumentFragment* documentFragmentFromAttributedString(NSAttributedString *, Vector< RefPtr<WebCore::ArchiveResource> >&);
75     virtual void setInsertionPasteboard(NSPasteboard *);
76     virtual NSURL* canonicalizeURL(NSURL*);
77     virtual NSURL* canonicalizeURLString(NSString*);
78     
79 #ifndef BUILDING_ON_LEOPARD
80     virtual void uppercaseWord();
81     virtual void lowercaseWord();
82     virtual void capitalizeWord();
83     virtual void showSubstitutionsPanel(bool show);
84     virtual bool substitutionsPanelIsShowing();
85     virtual void toggleSmartInsertDelete();
86     virtual bool isAutomaticQuoteSubstitutionEnabled();
87     virtual void toggleAutomaticQuoteSubstitution();
88     virtual bool isAutomaticLinkDetectionEnabled();
89     virtual void toggleAutomaticLinkDetection();
90     virtual bool isAutomaticDashSubstitutionEnabled();
91     virtual void toggleAutomaticDashSubstitution();
92     virtual bool isAutomaticTextReplacementEnabled();
93     virtual void toggleAutomaticTextReplacement();
94     virtual bool isAutomaticSpellingCorrectionEnabled();
95     virtual void toggleAutomaticSpellingCorrection();
96 #endif
97
98     TextCheckerClient* textChecker() { return this; }
99
100     virtual void respondToChangedContents();
101     virtual void respondToChangedSelection();
102
103     virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>);
104     virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>);
105     virtual void clearUndoRedoOperations();
106
107     virtual bool canCopyCut(WebCore::Frame*, bool defaultValue) const;
108     virtual bool canPaste(WebCore::Frame*, bool defaultValue) const;
109     virtual bool canUndo() const;
110     virtual bool canRedo() const;
111     
112     virtual void undo();
113     virtual void redo();
114     
115     virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
116     virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
117
118     virtual void textFieldDidBeginEditing(WebCore::Element*);
119     virtual void textFieldDidEndEditing(WebCore::Element*);
120     virtual void textDidChangeInTextField(WebCore::Element*);
121     virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
122     virtual void textWillBeDeletedInTextField(WebCore::Element*);
123     virtual void textDidChangeInTextArea(WebCore::Element*);
124     
125     virtual void ignoreWordInSpellDocument(const WTF::String&);
126     virtual void learnWord(const WTF::String&);
127     virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
128     virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&);
129     virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
130     virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results);
131     virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
132     virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
133     virtual void showSpellingUI(bool show);
134     virtual bool spellingUIIsShowing();
135     virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses);
136     virtual void willSetInputMethodState();
137     virtual void setInputMethodState(bool enabled);
138     virtual void requestCheckingOfString(WebCore::SpellChecker*, int, WebCore::TextCheckingTypeMask, const WTF::String&);
139 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
140     virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
141     virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
142     virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel);
143     virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString);
144 #endif
145 private:
146     void registerCommandForUndoOrRedo(PassRefPtr<WebCore::EditCommand>, bool isRedo);
147     WebEditorClient();
148
149     WebView *m_webView;
150     RetainPtr<WebEditorUndoTarget> m_undoTarget;
151     bool m_haveUndoRedoOperations;
152
153 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
154     CorrectionPanel m_correctionPanel;
155 #endif
156 };