• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef WebEditorClient_h
27 #define WebEditorClient_h
28 
29 #include <WebCore/EditorClient.h>
30 #include <WebCore/TextCheckerClient.h>
31 
32 namespace WebKit {
33 
34 class WebPage;
35 
36 class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient {
37 public:
WebEditorClient(WebPage * page)38     WebEditorClient(WebPage* page)
39         : m_page(page)
40     {
41     }
42 
43 private:
44     virtual void pageDestroyed();
45 
46     virtual bool shouldDeleteRange(WebCore::Range*);
47     virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*);
48     virtual bool smartInsertDeleteEnabled();
49     virtual bool isSelectTrailingWhitespaceEnabled();
50     virtual bool isContinuousSpellCheckingEnabled();
51     virtual void toggleContinuousSpellChecking();
52     virtual bool isGrammarCheckingEnabled();
53     virtual void toggleGrammarChecking();
54     virtual int spellCheckerDocumentTag();
55 
56     virtual bool isEditable();
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 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     virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
66 
67     virtual void didBeginEditing();
68     virtual void respondToChangedContents();
69     virtual void respondToChangedSelection();
70     virtual void didEndEditing();
71     virtual void didWriteSelectionToPasteboard();
72     virtual void didSetSelectionTypesForPasteboard();
73 
74     virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>);
75     virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>);
76     virtual void clearUndoRedoOperations();
77 
78     virtual bool canCopyCut(bool defaultValue) const;
79     virtual bool canPaste(bool defaultValue) const;
80     virtual bool canUndo() const;
81     virtual bool canRedo() const;
82 
83     virtual void undo();
84     virtual void redo();
85 
86     virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
87     virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
88 
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 
96 #if PLATFORM(MAC)
97     virtual NSString *userVisibleString(NSURL *);
98     virtual WebCore::DocumentFragment* documentFragmentFromAttributedString(NSAttributedString *, Vector< RefPtr<WebCore::ArchiveResource> >&);
99     virtual void setInsertionPasteboard(NSPasteboard *);
100     virtual NSURL* canonicalizeURL(NSURL*);
101     virtual NSURL* canonicalizeURLString(NSString*);
102 #ifdef BUILDING_ON_TIGER
103     virtual NSArray *pasteboardTypesForSelection(WebCore::Frame*);
104 #endif
105 #endif
106 
107 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
108     virtual void uppercaseWord();
109     virtual void lowercaseWord();
110     virtual void capitalizeWord();
111     virtual void showSubstitutionsPanel(bool show);
112     virtual bool substitutionsPanelIsShowing();
113     virtual void toggleSmartInsertDelete();
114     virtual bool isAutomaticQuoteSubstitutionEnabled();
115     virtual void toggleAutomaticQuoteSubstitution();
116     virtual bool isAutomaticLinkDetectionEnabled();
117     virtual void toggleAutomaticLinkDetection();
118     virtual bool isAutomaticDashSubstitutionEnabled();
119     virtual void toggleAutomaticDashSubstitution();
120     virtual bool isAutomaticTextReplacementEnabled();
121     virtual void toggleAutomaticTextReplacement();
122     virtual bool isAutomaticSpellingCorrectionEnabled();
123     virtual void toggleAutomaticSpellingCorrection();
124 #endif
125 
126 #if PLATFORM(GTK)
127     bool executePendingEditorCommands(WebCore::Frame*, Vector<WTF::String>, bool);
128     void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&);
129 #endif
130 
textChecker()131     TextCheckerClient* textChecker() { return this; }
132 
133     virtual void ignoreWordInSpellDocument(const String&);
134     virtual void learnWord(const String&);
135     virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
136     virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord);
137     virtual void checkGrammarOfString(const UChar*, int length, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
138 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
139     virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<WebCore::TextCheckingResult>& results);
140 #endif
141     virtual void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail& detail);
142     virtual void updateSpellingUIWithMisspelledWord(const String&);
143     virtual void showSpellingUI(bool show);
144     virtual bool spellingUIIsShowing();
145     virtual void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
146     virtual void willSetInputMethodState();
147     virtual void setInputMethodState(bool enabled);
148     virtual void requestCheckingOfString(WebCore::SpellChecker*, int, WebCore::TextCheckingTypeMask, const WTF::String&);
149 #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD)
150     virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
151     virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
152     virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel);
153     virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString);
154 #endif
155     WebPage* m_page;
156 };
157 
158 } // namespace WebKit
159 
160 #endif // WebEditorClient_h
161