This source file includes following definitions.
- create
- locale
- target
- compositionStartOffset
- compositionEndOffset
- confirmComposition
- hasFocus
- compositionText
- selectedSegment
- selectionStart
- selectionEnd
- segments
- inputMethodController
- interfaceName
- executionContext
- dispatchCandidateWindowShowEvent
- dispatchCandidateWindowUpdateEvent
- dispatchCandidateWindowHideEvent
#include "config.h"
#include "core/html/ime/InputMethodContext.h"
#include "core/dom/Text.h"
#include "core/editing/InputMethodController.h"
#include "core/frame/LocalFrame.h"
namespace WebCore {
PassOwnPtr<InputMethodContext> InputMethodContext::create(HTMLElement* element)
{
return adoptPtr(new InputMethodContext(element));
}
InputMethodContext::InputMethodContext(HTMLElement* element)
: m_element(element)
{
ScriptWrappable::init(this);
}
InputMethodContext::~InputMethodContext()
{
}
String InputMethodContext::locale() const
{
return emptyString();
}
HTMLElement* InputMethodContext::target() const
{
return m_element;
}
unsigned InputMethodContext::compositionStartOffset()
{
if (hasFocus())
return inputMethodController().compositionStart();
return 0;
}
unsigned InputMethodContext::compositionEndOffset()
{
if (hasFocus())
return inputMethodController().compositionEnd();
return 0;
}
void InputMethodContext::confirmComposition()
{
if (hasFocus())
inputMethodController().confirmCompositionAndResetState();
}
bool InputMethodContext::hasFocus() const
{
LocalFrame* frame = m_element->document().frame();
if (!frame)
return false;
const Element* element = frame->document()->focusedElement();
return element && element->isHTMLElement() && m_element == toHTMLElement(element);
}
String InputMethodContext::compositionText() const
{
if (!hasFocus())
return emptyString();
Text* text = inputMethodController().compositionNode();
return text ? text->wholeText() : emptyString();
}
CompositionUnderline InputMethodContext::selectedSegment() const
{
CompositionUnderline underline;
if (!hasFocus())
return underline;
const InputMethodController& controller = inputMethodController();
if (!controller.hasComposition())
return underline;
Vector<CompositionUnderline> underlines = controller.customCompositionUnderlines();
for (size_t i = 0; i < underlines.size(); ++i) {
if (underlines[i].thick)
return underlines[i];
}
underline.endOffset = controller.compositionEnd() - controller.compositionStart();
return underline;
}
int InputMethodContext::selectionStart() const
{
return selectedSegment().startOffset;
}
int InputMethodContext::selectionEnd() const
{
return selectedSegment().endOffset;
}
const Vector<unsigned>& InputMethodContext::segments()
{
m_segments.clear();
if (!hasFocus())
return m_segments;
const InputMethodController& controller = inputMethodController();
if (!controller.hasComposition())
return m_segments;
Vector<CompositionUnderline> underlines = controller.customCompositionUnderlines();
if (!underlines.size()) {
m_segments.append(0);
} else {
for (size_t i = 0; i < underlines.size(); ++i)
m_segments.append(underlines[i].startOffset);
}
return m_segments;
}
InputMethodController& InputMethodContext::inputMethodController() const
{
return m_element->document().frame()->inputMethodController();
}
const AtomicString& InputMethodContext::interfaceName() const
{
return EventTargetNames::InputMethodContext;
}
ExecutionContext* InputMethodContext::executionContext() const
{
return &m_element->document();
}
void InputMethodContext::dispatchCandidateWindowShowEvent()
{
dispatchEvent(Event::create(EventTypeNames::candidatewindowshow));
}
void InputMethodContext::dispatchCandidateWindowUpdateEvent()
{
dispatchEvent(Event::create(EventTypeNames::candidatewindowupdate));
}
void InputMethodContext::dispatchCandidateWindowHideEvent()
{
dispatchEvent(Event::create(EventTypeNames::candidatewindowhide));
}
}