#ifndef InputMethodController_h
#define InputMethodController_h
#include "core/editing/CompositionUnderline.h"
#include "core/editing/PlainTextRange.h"
#include "wtf/Vector.h"
namespace WebCore {
class Editor;
class EditorClient;
class LocalFrame;
class Range;
class Text;
class InputMethodController {
WTF_MAKE_NONCOPYABLE(InputMethodController);
public:
enum ConfirmCompositionBehavior {
DoNotKeepSelection,
KeepSelection,
};
static PassOwnPtr<InputMethodController> create(LocalFrame&);
~InputMethodController();
bool hasComposition() const;
void setComposition(const String&, const Vector<CompositionUnderline>&, unsigned selectionStart, unsigned selectionEnd);
void setCompositionFromExistingText(const Vector<CompositionUnderline>&, unsigned compositionStart, unsigned compositionEnd);
bool confirmComposition();
bool confirmComposition(const String& text);
bool confirmCompositionOrInsertText(const String& text, ConfirmCompositionBehavior);
void confirmCompositionAndResetState();
void cancelComposition();
void cancelCompositionIfSelectionIsInvalid();
PassRefPtrWillBeRawPtr<Range> compositionRange() const;
Text* compositionNode() const { return m_compositionNode.get(); }
unsigned compositionStart() const { return m_compositionStart; }
unsigned compositionEnd() const { return m_compositionEnd; }
bool compositionUsesCustomUnderlines() const { return !m_customCompositionUnderlines.isEmpty(); }
const Vector<CompositionUnderline>& customCompositionUnderlines() const { return m_customCompositionUnderlines; }
void clear();
PlainTextRange getSelectionOffsets() const;
bool setEditableSelectionOffsets(const PlainTextRange&);
void extendSelectionAndDelete(int before, int after);
private:
class SelectionOffsetsScope {
WTF_MAKE_NONCOPYABLE(SelectionOffsetsScope);
public:
SelectionOffsetsScope(InputMethodController*);
~SelectionOffsetsScope();
private:
InputMethodController* m_inputMethodController;
const PlainTextRange m_offsets;
};
friend class SelectionOffsetsScope;
LocalFrame& m_frame;
RefPtr<Text> m_compositionNode;
unsigned m_compositionStart;
unsigned m_compositionEnd;
Vector<CompositionUnderline> m_customCompositionUnderlines;
explicit InputMethodController(LocalFrame&);
Editor& editor() const;
bool insertTextForConfirmedComposition(const String& text);
void selectComposition() const;
enum FinishCompositionMode { ConfirmComposition, CancelComposition };
bool finishComposition(const String&, FinishCompositionMode);
bool setSelectionOffsets(const PlainTextRange&);
};
}
#endif