-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAlternativeTextController.h
181 lines (148 loc) · 7.79 KB
/
AlternativeTextController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef AlternativeTextController_h
#define AlternativeTextController_h
#include "AlternativeTextClient.h"
#include "DocumentMarker.h"
#include "FrameSelection.h"
#include "Range.h"
#include "TextChecking.h"
#include "Timer.h"
#include "VisibleSelection.h"
#include <wtf/Noncopyable.h>
#include <wtf/UnusedParam.h>
namespace WebCore {
class CompositeEditCommand;
class EditorClient;
class EditCommand;
class EditCommandComposition;
class Event;
class Frame;
class TextCheckerClient;
struct DictationAlternative;
class AlternativeTextDetails : public RefCounted<AlternativeTextDetails> {
public:
AlternativeTextDetails() { }
virtual ~AlternativeTextDetails() { }
};
struct AlternativeTextInfo {
RefPtr<Range> rangeWithAlternative;
bool isActive;
AlternativeTextType type;
String originalText;
RefPtr<AlternativeTextDetails> details;
};
class DictationMarkerDetails : public DocumentMarkerDetails {
public:
static PassRefPtr<DictationMarkerDetails> create(const String& originalText, uint64_t dictationContext)
{
return adoptRef(new DictationMarkerDetails(originalText, dictationContext));
}
const String& originalText() const { return m_originalText; }
uint64_t dictationContext() const { return m_dictationContext; }
private:
DictationMarkerDetails(const String& originalText, uint64_t dictationContext)
: m_dictationContext(dictationContext)
, m_originalText(originalText)
{ }
uint64_t m_dictationContext;
String m_originalText;
};
struct TextCheckingResult;
#if USE(AUTOCORRECTION_PANEL)
// These backslashes are for making style checker happy.
#define UNLESS_ENABLED(functionBody) \
;\
#else
#define UNLESS_ENABLED(functionBody) functionBody
#endif
class AlternativeTextController {
WTF_MAKE_NONCOPYABLE(AlternativeTextController);
WTF_MAKE_FAST_ALLOCATED;
public:
explicit AlternativeTextController(Frame*) UNLESS_ENABLED({ })
~AlternativeTextController() UNLESS_ENABLED({ })
void startAlternativeTextUITimer(AlternativeTextType) UNLESS_ENABLED({ })
void stopAlternativeTextUITimer() UNLESS_ENABLED({ })
void dismiss(ReasonForDismissingAlternativeText) UNLESS_ENABLED({ })
void show(PassRefPtr<Range> rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); })
// Return true if correction was applied, false otherwise.
bool applyAutocorrectionBeforeTypingIfAppropriate() UNLESS_ENABLED({ return false; })
void respondToUnappliedSpellCorrection(const VisibleSelection&, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(corrected); UNUSED_PARAM(correction); })
void respondToAppliedEditing(CompositeEditCommand*) UNLESS_ENABLED({ })
void respondToUnappliedEditing(EditCommandComposition*) UNLESS_ENABLED({ })
void respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); })
void stopPendingCorrection(const VisibleSelection& oldSelection) UNLESS_ENABLED({ UNUSED_PARAM(oldSelection); })
void applyPendingCorrection(const VisibleSelection& selectionAfterTyping) UNLESS_ENABLED({ UNUSED_PARAM(selectionAfterTyping); })
void handleAlternativeTextUIResult(const String& result) UNLESS_ENABLED({ UNUSED_PARAM(result); })
void handleCancelOperation() UNLESS_ENABLED({ })
bool hasPendingCorrection() const UNLESS_ENABLED({ return false; })
bool isSpellingMarkerAllowed(PassRefPtr<Range> misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; })
bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; })
bool shouldRemoveMarkersUponEditing();
void recordAutocorrectionResponseReversed(const String& replacedString, PassRefPtr<Range> replacementRange) UNLESS_ENABLED({ UNUSED_PARAM(replacedString); UNUSED_PARAM(replacementRange); })
void markReversed(PassRefPtr<Range> changedRange) UNLESS_ENABLED({ UNUSED_PARAM(changedRange); })
void markCorrection(PassRefPtr<Range> replacedRange, const String& replacedString) UNLESS_ENABLED({ UNUSED_PARAM(replacedRange); UNUSED_PARAM(replacedString); })
// This function returns false if the replacement should not be carried out.
bool processMarkersOnTextToBeReplacedByResult(const TextCheckingResult*, Range* rangeToBeReplaced, const String& stringToBeReplaced) UNLESS_ENABLED({ UNUSED_PARAM(rangeToBeReplaced); UNUSED_PARAM(stringToBeReplaced); return true; });
void deletedAutocorrectionAtPosition(const Position&, const String& originalString) UNLESS_ENABLED({ UNUSED_PARAM(originalString); })
bool insertDictatedText(const String&, const Vector<DictationAlternative>&, Event*);
void removeDictationAlternativesForMarker(const DocumentMarker*);
Vector<String> dictationAlternativesForMarker(const DocumentMarker*);
void applyDictationAlternative(const String& alternativeString);
private:
#if USE(AUTOCORRECTION_PANEL)
String dismissSoon(ReasonForDismissingAlternativeText);
void applyAlternativeTextToRange(const Range*, const String& alternative, AlternativeTextType, const Vector<DocumentMarker::MarkerType>&);
void timerFired(Timer<AlternativeTextController>*);
void recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString);
void recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction);
String markerDescriptionForAppliedAlternativeText(AlternativeTextType, DocumentMarker::MarkerType);
bool shouldStartTimerFor(const DocumentMarker&, int endOffset) const;
bool respondToMarkerAtEndOfWord(const DocumentMarker&, const Position& endOfWordPosition, FrameSelection::SetSelectionOptions);
AlternativeTextClient* alternativeTextClient();
EditorClient* editorClient();
TextCheckerClient* textChecker();
FloatRect rootViewRectForRange(const Range*) const;
void markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand*);
Timer<AlternativeTextController> m_timer;
AlternativeTextInfo m_alternativeTextInfo;
bool m_isDismissedByEditing;
String m_originalStringForLastDeletedAutocorrection;
Position m_positionForLastDeletedAutocorrection;
#endif
Frame* m_frame;
};
#undef UNLESS_ENABLED
inline bool AlternativeTextController::shouldRemoveMarkersUponEditing()
{
#if USE(MARKER_REMOVAL_UPON_EDITING)
return true;
#else
return false;
#endif
}
} // namespace WebCore
#endif // AlternativeTextController_h