1/*
2 * Copyright (C) 2006, 2007 Apple 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 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef EditorClient_h
28#define EditorClient_h
29
30#include "EditorInsertAction.h"
31#include "FloatRect.h"
32#include "TextAffinity.h"
33#include "TextChecking.h"
34#include "UndoStep.h"
35#include <wtf/Forward.h>
36#include <wtf/Vector.h>
37
38#if PLATFORM(COCOA)
39OBJC_CLASS NSAttributedString;
40OBJC_CLASS NSString;
41OBJC_CLASS NSURL;
42#endif
43
44#if PLATFORM(IOS)
45OBJC_CLASS NSArray;
46OBJC_CLASS NSDictionary;
47#endif
48
49namespace WebCore {
50
51class ArchiveResource;
52class DocumentFragment;
53class Editor;
54class Element;
55class Frame;
56class HTMLElement;
57class KeyboardEvent;
58class LayoutRect;
59class Node;
60class Range;
61class SharedBuffer;
62class StyleProperties;
63class TextCheckerClient;
64class VisibleSelection;
65class VisiblePosition;
66
67struct GapRects;
68struct GrammarDetail;
69
70class EditorClient {
71public:
72    virtual ~EditorClient() {  }
73    virtual void pageDestroyed() = 0;
74
75    virtual bool shouldDeleteRange(Range*) = 0;
76    virtual bool smartInsertDeleteEnabled() = 0;
77    virtual bool isSelectTrailingWhitespaceEnabled() = 0;
78    virtual bool isContinuousSpellCheckingEnabled() = 0;
79    virtual void toggleContinuousSpellChecking() = 0;
80    virtual bool isGrammarCheckingEnabled() = 0;
81    virtual void toggleGrammarChecking() = 0;
82    virtual int spellCheckerDocumentTag() = 0;
83
84    virtual bool shouldBeginEditing(Range*) = 0;
85    virtual bool shouldEndEditing(Range*) = 0;
86    virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction) = 0;
87    virtual bool shouldInsertText(const String&, Range*, EditorInsertAction) = 0;
88    virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting) = 0;
89
90    virtual bool shouldApplyStyle(StyleProperties*, Range*) = 0;
91    virtual bool shouldMoveRangeAfterDelete(Range*, Range*) = 0;
92
93    virtual void didBeginEditing() = 0;
94    virtual void respondToChangedContents() = 0;
95    virtual void respondToChangedSelection(Frame*) = 0;
96    virtual void didEndEditing() = 0;
97    virtual void willWriteSelectionToPasteboard(Range*) = 0;
98    virtual void didWriteSelectionToPasteboard() = 0;
99    virtual void getClientPasteboardDataForRange(Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData) = 0;
100
101    virtual void registerUndoStep(PassRefPtr<UndoStep>) = 0;
102    virtual void registerRedoStep(PassRefPtr<UndoStep>) = 0;
103    virtual void clearUndoRedoOperations() = 0;
104
105    virtual bool canCopyCut(Frame*, bool defaultValue) const = 0;
106    virtual bool canPaste(Frame*, bool defaultValue) const = 0;
107    virtual bool canUndo() const = 0;
108    virtual bool canRedo() const = 0;
109
110    virtual void undo() = 0;
111    virtual void redo() = 0;
112
113    virtual void handleKeyboardEvent(KeyboardEvent*) = 0;
114    virtual void handleInputMethodKeydown(KeyboardEvent*) = 0;
115
116    virtual void textFieldDidBeginEditing(Element*) = 0;
117    virtual void textFieldDidEndEditing(Element*) = 0;
118    virtual void textDidChangeInTextField(Element*) = 0;
119    virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*) = 0;
120    virtual void textWillBeDeletedInTextField(Element*) = 0;
121    virtual void textDidChangeInTextArea(Element*) = 0;
122    virtual void overflowScrollPositionChanged() = 0;
123
124#if PLATFORM(IOS)
125    virtual void startDelayingAndCoalescingContentChangeNotifications() = 0;
126    virtual void stopDelayingAndCoalescingContentChangeNotifications() = 0;
127    virtual void writeDataToPasteboard(NSDictionary*) = 0;
128    virtual NSArray* supportedPasteboardTypesForCurrentSelection() = 0;
129    virtual NSArray* readDataFromPasteboard(NSString* type, int index) = 0;
130    virtual bool hasRichlyEditableSelection() = 0;
131    virtual int getPasteboardItemsCount() = 0;
132    virtual DocumentFragment* documentFragmentFromDelegate(int index) = 0;
133    virtual bool performsTwoStepPaste(DocumentFragment*) = 0;
134    virtual int pasteboardChangeCount() = 0;
135#endif
136
137#if PLATFORM(COCOA)
138    virtual NSString* userVisibleString(NSURL*) = 0;
139    virtual DocumentFragment* documentFragmentFromAttributedString(NSAttributedString*, Vector< RefPtr<ArchiveResource>>&) = 0;
140    virtual void setInsertionPasteboard(const String& pasteboardName) = 0;
141    virtual NSURL* canonicalizeURL(NSURL*) = 0;
142    virtual NSURL* canonicalizeURLString(NSString*) = 0;
143#endif
144
145#if USE(APPKIT)
146    virtual void uppercaseWord() = 0;
147    virtual void lowercaseWord() = 0;
148    virtual void capitalizeWord() = 0;
149#endif
150
151#if USE(AUTOMATIC_TEXT_REPLACEMENT)
152    virtual void showSubstitutionsPanel(bool show) = 0;
153    virtual bool substitutionsPanelIsShowing() = 0;
154    virtual void toggleSmartInsertDelete() = 0;
155    virtual bool isAutomaticQuoteSubstitutionEnabled() = 0;
156    virtual void toggleAutomaticQuoteSubstitution() = 0;
157    virtual bool isAutomaticLinkDetectionEnabled() = 0;
158    virtual void toggleAutomaticLinkDetection() = 0;
159    virtual bool isAutomaticDashSubstitutionEnabled() = 0;
160    virtual void toggleAutomaticDashSubstitution() = 0;
161    virtual bool isAutomaticTextReplacementEnabled() = 0;
162    virtual void toggleAutomaticTextReplacement() = 0;
163    virtual bool isAutomaticSpellingCorrectionEnabled() = 0;
164    virtual void toggleAutomaticSpellingCorrection() = 0;
165#endif
166
167#if ENABLE(DELETION_UI)
168    virtual bool shouldShowDeleteInterface(HTMLElement*) = 0;
169#endif
170
171#if PLATFORM(GTK)
172    virtual bool shouldShowUnicodeMenu() = 0;
173#endif
174
175    virtual TextCheckerClient* textChecker() = 0;
176
177    virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail) = 0;
178    virtual void updateSpellingUIWithMisspelledWord(const String&) = 0;
179    virtual void showSpellingUI(bool show) = 0;
180    virtual bool spellingUIIsShowing() = 0;
181    virtual void willSetInputMethodState() = 0;
182    virtual void setInputMethodState(bool enabled) = 0;
183
184#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
185    virtual void selectedTelephoneNumberRangesChanged() { }
186    virtual void selectionRectsDidChange(const Vector<LayoutRect>&, const Vector<GapRects>&, bool) { }
187#endif
188
189    // Support for global selections, used on platforms like the X Window System that treat
190    // selection as a type of clipboard.
191    virtual bool supportsGlobalSelection() { return false; }
192};
193
194}
195
196#endif // EditorClient_h
197