SpellingCorrectionController.h [plain text]
#ifndef SpellingCorrectionController_h
#define SpellingCorrectionController_h
#if PLATFORM(MAC) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
#define SUPPORT_AUTOCORRECTION_PANEL 1
#define REMOVE_MARKERS_UPON_EDITING 1
#else
#define SUPPORT_AUTOCORRECTION_PANEL 0
#define REMOVE_MARKERS_UPON_EDITING 0
#endif // #if PLATFORM(MAC) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
#include "DocumentMarker.h"
#include "Range.h"
#include "Timer.h"
#include "VisibleSelection.h"
#include <wtf/Noncopyable.h>
#include <wtf/UnusedParam.h>
namespace WebCore {
class EditorClient;
class EditCommand;
class Frame;
class TextCheckerClient;
struct CorrectionPanelInfo {
enum PanelType {
PanelTypeCorrection = 0,
PanelTypeReversion,
PanelTypeSpellingSuggestions
};
RefPtr<Range> rangeToBeReplaced;
String replacedString;
String replacementString;
PanelType panelType;
bool isActive;
};
struct TextCheckingResult;
enum ReasonForDismissingCorrectionPanel {
ReasonForDismissingCorrectionPanelCancelled = 0,
ReasonForDismissingCorrectionPanelIgnored,
ReasonForDismissingCorrectionPanelAccepted
};
#if SUPPORT_AUTOCORRECTION_PANEL
#define UNLESS_ENABLED(functionBody) ;
#else
#define UNLESS_ENABLED(functionBody) functionBody
#endif
class SpellingCorrectionController {
WTF_MAKE_NONCOPYABLE(SpellingCorrectionController); WTF_MAKE_FAST_ALLOCATED;
public:
SpellingCorrectionController(Frame*) UNLESS_ENABLED({})
~SpellingCorrectionController() UNLESS_ENABLED({})
void startCorrectionPanelTimer(CorrectionPanelInfo::PanelType) UNLESS_ENABLED({})
void stopCorrectionPanelTimer() UNLESS_ENABLED({})
void dismiss(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({})
String dismissSoon(ReasonForDismissingCorrectionPanel) UNLESS_ENABLED({ return String(); })
void show(PassRefPtr<Range> rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); })
void applyCorrectionPanelInfo(const Vector<DocumentMarker::MarkerType>&) UNLESS_ENABLED({})
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(EditCommand*) UNLESS_ENABLED({})
void respondToUnappliedEditing(EditCommand*) UNLESS_ENABLED({})
void respondToChangedSelection(const VisibleSelection& oldSelection) 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 handleCorrectionPanelResult(const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(correction); })
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() { return REMOVE_MARKERS_UPON_EDITING; }
void correctionPanelTimerFired(Timer<SpellingCorrectionController>*) UNLESS_ENABLED({})
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); })
void recordSpellcheckerResponseForModifiedCorrection(Range* rangeOfCorrection, const String& corrected, const String& correction) UNLESS_ENABLED({ UNUSED_PARAM(rangeOfCorrection); UNUSED_PARAM(corrected); UNUSED_PARAM(correction); })
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); })
#if SUPPORT_AUTOCORRECTION_PANEL
private:
void recordAutocorrectionResponseReversed(const String& replacedString, const String& replacementString);
bool shouldStartTimerFor(const DocumentMarker& marker, int endOffset) const
{
return (((marker.type == DocumentMarker::Replacement && !marker.description.isNull())
|| marker.type == DocumentMarker::Spelling) && static_cast<int>(marker.endOffset) == endOffset);
}
EditorClient* client();
TextCheckerClient* textChecker();
FloatRect windowRectForRange(const Range*) const;
void markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand*);
EditorClient* m_client;
Frame* m_frame;
Timer<SpellingCorrectionController> m_correctionPanelTimer;
CorrectionPanelInfo m_correctionPanelInfo;
bool m_correctionPanelIsDismissedByEditor;
String m_originalStringForLastDeletedAutocorrection;
Position m_positionForLastDeletedAutocorrection;
#endif
};
#undef UNLESS_ENABLED
}
#endif // SpellingCorrectionController_h