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 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 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
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 willWriteSelectionToPasteboard(WebCore::Range*);
58    virtual void didWriteSelectionToPasteboard();
59    virtual void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer> >& pasteboardData);
60
61    virtual void respondToChangedContents();
62    virtual void respondToChangedSelection(WebCore::Frame*);
63
64    bool shouldDeleteRange(WebCore::Range*);
65
66    bool shouldInsertNode(WebCore::Node*, WebCore::Range* replacingRange, WebCore::EditorInsertAction);
67    bool shouldApplyStyle(WebCore::StyleProperties*, WebCore::Range*);
68    bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
69    bool shouldChangeTypingStyle(WebCore::StyleProperties* currentStyle, WebCore::StyleProperties* toProposedStyle);
70
71    void webViewDidChangeTypingStyle(WebNotification*);
72    void webViewDidChangeSelection(WebNotification*);
73
74    bool smartInsertDeleteEnabled();
75    bool isSelectTrailingWhitespaceEnabled();
76
77    void registerUndoStep(PassRefPtr<WebCore::UndoStep>);
78    void registerRedoStep(PassRefPtr<WebCore::UndoStep>);
79    void clearUndoRedoOperations();
80
81    bool canCopyCut(WebCore::Frame*, bool defaultValue) const;
82    bool canPaste(WebCore::Frame*, 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) override;
90    virtual void textFieldDidBeginEditing(WebCore::Element*) override;
91    virtual void textFieldDidEndEditing(WebCore::Element*) override;
92    virtual void textDidChangeInTextField(WebCore::Element*) override;
93    virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*) override;
94    virtual void textWillBeDeletedInTextField(WebCore::Element* input) override;
95    virtual void textDidChangeInTextArea(WebCore::Element*) override;
96    virtual void overflowScrollPositionChanged() override { }
97
98    void handleKeyboardEvent(WebCore::KeyboardEvent*);
99    void handleInputMethodKeydown(WebCore::KeyboardEvent*);
100
101    virtual bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const override;
102    virtual void ignoreWordInSpellDocument(const WTF::String&) override;
103    virtual void learnWord(const WTF::String&) override;
104    virtual void checkSpellingOfString(StringView, int* misspellingLocation, int* misspellingLength) override;
105    virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) override;
106    virtual void checkGrammarOfString(StringView, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) override;
107    virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) override;
108    virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) override;
109    virtual void showSpellingUI(bool show) override;
110    virtual bool spellingUIIsShowing() override;
111    virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses) override;
112
113    virtual void willSetInputMethodState() override;
114    virtual void setInputMethodState(bool) override;
115    virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) override { }
116
117    virtual WebCore::TextCheckerClient* textChecker() override { return this; }
118
119private:
120    WebView* m_webView;
121    WebEditorUndoTarget* m_undoTarget;
122};
123
124#endif // WebEditorClient_H
125