1/*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
4 * Copyright (C) 2006 Apple Computer, Inc.
5 * Copyright (C) 2008 INdT - Instituto Nokia de Tecnologia
6 * Copyright (C) 2009-2010 ProFUSION embedded systems
7 * Copyright (C) 2009-2010 Samsung Electronics
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef EditorClientEfl_h
34#define EditorClientEfl_h
35
36#include "EditorClient.h"
37
38#include "EditorInsertAction.h"
39#include "TextAffinity.h"
40#include "TextCheckerClient.h"
41#include <wtf/Deque.h>
42#include <wtf/Forward.h>
43
44struct Ewk_Should_Insert_Node_Event {
45    WebCore::Node* node;
46    WebCore::Range* range;
47    WebCore::EditorInsertAction action;
48};
49
50struct Ewk_Should_Insert_Text_Event {
51    const char* text;
52    WebCore::Range* range;
53    WebCore::EditorInsertAction action;
54};
55
56struct Ewk_Should_Change_Selected_Range_Event {
57    WebCore::Range* fromRange;
58    WebCore::Range* toRange;
59    WebCore::EAffinity affinity;
60    bool stillSelecting;
61};
62
63struct Ewk_Should_Apply_Style_Event {
64    WebCore::StylePropertySet* style;
65    WebCore::Range* range;
66};
67
68namespace WebCore {
69class Page;
70
71class EditorClientEfl : public EditorClient, public TextCheckerClient {
72protected:
73    bool m_isInRedo;
74    WTF::Deque<WTF::RefPtr<WebCore::UndoStep> > undoStack;
75    WTF::Deque<WTF::RefPtr<WebCore::UndoStep> > redoStack;
76
77public:
78    explicit EditorClientEfl(Evas_Object* view);
79    ~EditorClientEfl();
80
81    // from EditorClient
82    virtual void pageDestroyed();
83    virtual void frameWillDetachPage(Frame*) { }
84
85    virtual bool shouldDeleteRange(Range*);
86    virtual bool smartInsertDeleteEnabled();
87    virtual bool isSelectTrailingWhitespaceEnabled();
88    virtual bool isContinuousSpellCheckingEnabled();
89    virtual void toggleContinuousSpellChecking();
90    virtual bool isGrammarCheckingEnabled();
91    virtual void toggleGrammarChecking();
92    virtual int spellCheckerDocumentTag();
93
94    virtual bool shouldBeginEditing(Range*);
95    virtual bool shouldEndEditing(Range*);
96    virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction);
97    virtual bool shouldInsertText(const String&, Range*, EditorInsertAction);
98    virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting);
99
100    virtual bool shouldApplyStyle(StylePropertySet*, Range*);
101
102    virtual bool shouldMoveRangeAfterDelete(Range*, Range*);
103
104    virtual void didBeginEditing();
105    virtual void respondToChangedContents();
106    virtual void respondToChangedSelection(Frame*);
107    virtual void didEndEditing();
108    virtual void willWriteSelectionToPasteboard(WebCore::Range*);
109    virtual void didWriteSelectionToPasteboard();
110    virtual void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer> >& pasteboardData);
111    virtual void didSetSelectionTypesForPasteboard();
112
113    virtual void registerUndoStep(WTF::PassRefPtr<UndoStep>);
114    virtual void registerRedoStep(WTF::PassRefPtr<UndoStep>);
115    virtual void clearUndoRedoOperations();
116
117    virtual bool canCopyCut(Frame*, bool defaultValue) const;
118    virtual bool canPaste(Frame*, bool defaultValue) const;
119    virtual bool canUndo() const;
120    virtual bool canRedo() const;
121
122    virtual void undo();
123    virtual void redo();
124
125    virtual const char* interpretKeyEvent(const KeyboardEvent*);
126    virtual bool handleEditingKeyboardEvent(KeyboardEvent*);
127    virtual void handleKeyboardEvent(KeyboardEvent*);
128    virtual void handleInputMethodKeydown(KeyboardEvent*);
129
130    virtual void textFieldDidBeginEditing(Element*);
131    virtual void textFieldDidEndEditing(Element*);
132    virtual void textDidChangeInTextField(Element*);
133    virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
134    virtual void textWillBeDeletedInTextField(Element*);
135    virtual void textDidChangeInTextArea(Element*);
136
137    virtual bool shouldEraseMarkersAfterChangeSelection(TextCheckingType) const;
138    virtual void ignoreWordInSpellDocument(const String&);
139    virtual void learnWord(const String&);
140    virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
141    virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord);
142    virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
143    virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&);
144    virtual void updateSpellingUIWithMisspelledWord(const String&);
145    virtual void showSpellingUI(bool show);
146    virtual bool spellingUIIsShowing();
147    virtual void getGuessesForWord(const String& word, const String& context, WTF::Vector<String>& guesses);
148    virtual void willSetInputMethodState();
149    virtual void setInputMethodState(bool enabled);
150    virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) { }
151#if USE(UNIFIED_TEXT_CHECKING)
152    virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) { }
153#endif
154    virtual TextCheckerClient* textChecker() { return this; }
155
156private:
157    Evas_Object *m_view;
158};
159}
160
161#endif // EditorClientEfl_h
162