WebViewInputMethodFilter.cpp [plain text]
#include "config.h"
#include "WebViewInputMethodFilter.h"
#include "FocusController.h"
#include "Frame.h"
#include "PlatformKeyboardEvent.h"
#include "webkitwebviewprivate.h"
#include <wtf/text/CString.h>
using namespace WebCore;
namespace WebKit {
Frame* WebViewInputMethodFilter::focusedOrMainFrame()
{
ASSERT(m_webView);
Page* page = core(m_webView);
if (!page)
return 0;
return page->focusController()->focusedOrMainFrame();
}
void WebViewInputMethodFilter::setWebView(WebKitWebView* webView)
{
m_webView = webView;
GtkInputMethodFilter::setWidget(GTK_WIDGET(webView));
}
bool WebViewInputMethodFilter::canEdit()
{
Frame* frame = focusedOrMainFrame();
return frame && frame->editor()->canEdit();
}
bool WebViewInputMethodFilter::sendSimpleKeyEvent(GdkEventKey* event, WTF::String simpleString)
{
PlatformKeyboardEvent platformEvent(event, CompositionResults(simpleString));
return focusedOrMainFrame()->eventHandler()->keyEvent(platformEvent);
}
bool WebViewInputMethodFilter::sendKeyEventWithCompositionResults(GdkEventKey* event, ResultsToSend resultsToSend)
{
PlatformKeyboardEvent platformEvent(event, CompositionResults(resultsToSend & Composition ? m_confirmedComposition : String(),
resultsToSend & Preedit ? m_preedit : String(),
m_cursorOffset));
return focusedOrMainFrame()->eventHandler()->keyEvent(platformEvent);
}
void WebViewInputMethodFilter::confirmCompositionText(String text)
{
Frame* frame = focusedOrMainFrame();
if (!frame || !frame->editor()->canEdit())
return;
if (text.isNull()) {
confirmCurrentComposition();
return;
}
frame->editor()->confirmComposition(m_confirmedComposition);
}
void WebViewInputMethodFilter::confirmCurrentComposition()
{
Frame* frame = focusedOrMainFrame();
if (!frame || !frame->editor()->canEdit())
return;
frame->editor()->confirmComposition();
}
void WebViewInputMethodFilter::cancelCurrentComposition()
{
Frame* frame = focusedOrMainFrame();
if (!frame || !frame->editor()->canEdit())
return;
frame->editor()->cancelComposition();
}
void WebViewInputMethodFilter::setPreedit(String newPreedit, int cursorOffset)
{
Frame* frame = focusedOrMainFrame();
if (!frame || !frame->editor()->canEdit())
return;
Vector<CompositionUnderline> underlines;
underlines.append(CompositionUnderline(0, newPreedit.length(), Color(1, 1, 1), false));
frame->editor()->setComposition(newPreedit, underlines, m_cursorOffset, m_cursorOffset);
}
}