InputMethodFilter.h [plain text]
#ifndef InputMethodFilter_h
#define InputMethodFilter_h
#include <WebCore/IntPoint.h>
#include <functional>
#include <wtf/Noncopyable.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/text/WTFString.h>
typedef struct _GdkEventKey GdkEventKey;
typedef struct _GtkIMContext GtkIMContext;
namespace WebCore {
struct CompositionResults;
class IntRect;
}
namespace WebKit {
class WebPageProxy;
class InputMethodFilter {
WTF_MAKE_NONCOPYABLE(InputMethodFilter);
public:
enum EventFakedForComposition {
EventFaked,
EventNotFaked
};
InputMethodFilter();
~InputMethodFilter();
GtkIMContext* context() const { return m_context.get(); }
void setPage(WebPageProxy* page) { m_page = page; }
void setEnabled(bool);
void setCursorRect(const WebCore::IntRect&);
using FilterKeyEventCompletionHandler = std::function<void (const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition)>;
void filterKeyEvent(GdkEventKey*, FilterKeyEventCompletionHandler&& = nullptr);
void notifyFocusedIn();
void notifyFocusedOut();
void notifyMouseButtonPress();
#if ENABLE(API_TESTS)
void setTestingMode(bool enable) { m_testingMode = enable; }
const Vector<String>& events() const { return m_events; }
#endif
private:
enum ResultsToSend {
Preedit = 1 << 1,
Composition = 1 << 2,
PreeditAndComposition = Preedit | Composition
};
static void handleCommitCallback(InputMethodFilter*, const char* compositionString);
static void handlePreeditStartCallback(InputMethodFilter*);
static void handlePreeditChangedCallback(InputMethodFilter*);
static void handlePreeditEndCallback(InputMethodFilter*);
void handleCommit(const char* compositionString);
void handlePreeditChanged();
void handlePreeditStart();
void handlePreeditEnd();
void handleKeyboardEvent(GdkEventKey*, const String& eventString = String(), EventFakedForComposition = EventNotFaked);
void handleKeyboardEventWithCompositionResults(GdkEventKey*, ResultsToSend = PreeditAndComposition, EventFakedForComposition = EventNotFaked);
void sendCompositionAndPreeditWithFakeKeyEvents(ResultsToSend);
void confirmComposition();
void updatePreedit();
void confirmCurrentComposition();
void cancelContextComposition();
#if ENABLE(API_TESTS)
void logHandleKeyboardEventForTesting(GdkEventKey*, const String&, EventFakedForComposition);
void logHandleKeyboardEventWithCompositionResultsForTesting(GdkEventKey*, ResultsToSend, EventFakedForComposition);
void logConfirmCompositionForTesting();
void logSetPreeditForTesting();
#endif
GRefPtr<GtkIMContext> m_context;
WebPageProxy* m_page;
unsigned m_enabled : 1;
unsigned m_composingTextCurrently : 1;
unsigned m_filteringKeyEvent : 1;
unsigned m_preeditChanged : 1;
unsigned m_preventNextCommit : 1;
unsigned m_justSentFakeKeyUp : 1;
int m_cursorOffset;
unsigned m_lastFilteredKeyPressCodeWithNoResults;
WebCore::IntPoint m_lastCareLocation;
String m_confirmedComposition;
String m_preedit;
FilterKeyEventCompletionHandler m_filterKeyEventCompletionHandler;
#if ENABLE(API_TESTS)
bool m_testingMode;
Vector<String> m_events;
#endif
};
}
#endif // InputMethodFilter_h