| Index: Source/core/html/ime/InputMethodContext.cpp
|
| diff --git a/Source/core/html/ime/InputMethodContext.cpp b/Source/core/html/ime/InputMethodContext.cpp
|
| index 87560063a517bf19b10cf741827d3ea7f601d911..2ffdda01e70315b365d9f154df4ae973febec68f 100644
|
| --- a/Source/core/html/ime/InputMethodContext.cpp
|
| +++ b/Source/core/html/ime/InputMethodContext.cpp
|
| @@ -31,6 +31,7 @@
|
| #include "config.h"
|
| #include "core/html/ime/InputMethodContext.h"
|
|
|
| +#include "core/dom/Text.h"
|
| #include "core/editing/InputMethodController.h"
|
| #include "core/html/ime/Composition.h"
|
| #include "core/page/Frame.h"
|
| @@ -43,7 +44,7 @@ PassOwnPtr<InputMethodContext> InputMethodContext::create(HTMLElement* element)
|
| }
|
|
|
| InputMethodContext::InputMethodContext(HTMLElement* element)
|
| - : m_composition(0)
|
| + : m_composition(Composition::create(this))
|
| , m_element(element)
|
| {
|
| ScriptWrappable::init(this);
|
| @@ -55,8 +56,6 @@ InputMethodContext::~InputMethodContext()
|
|
|
| Composition* InputMethodContext::composition() const
|
| {
|
| - // FIXME: Implement this. This should lazily update the composition object
|
| - // here.
|
| return m_composition.get();
|
| }
|
|
|
| @@ -73,25 +72,95 @@ HTMLElement* InputMethodContext::target() const
|
|
|
| void InputMethodContext::confirmComposition()
|
| {
|
| + if (hasFocus())
|
| + inputMethodController().confirmCompositionAndResetState();
|
| +}
|
| +
|
| +void InputMethodContext::setCaretRectangle(Node* anchor, int x, int y, int w, int h)
|
| +{
|
| + // FIXME: Implement this.
|
| +}
|
| +
|
| +void InputMethodContext::setExclusionRectangle(Node* anchor, int x, int y, int w, int h)
|
| +{
|
| + // FIXME: Implement this.
|
| +}
|
| +
|
| +bool InputMethodContext::hasFocus() const
|
| +{
|
| Frame* frame = m_element->document().frame();
|
| if (!frame)
|
| - return;
|
| + return false;
|
|
|
| const Element* element = frame->document()->focusedElement();
|
| - if (!element || !element->isHTMLElement() || m_element != toHTMLElement(element))
|
| - return;
|
| + return element && element->isHTMLElement() && m_element == toHTMLElement(element);
|
| +}
|
|
|
| - frame->inputMethodController().confirmCompositionAndResetState();
|
| +String InputMethodContext::compositionText() const
|
| +{
|
| + if (!hasFocus())
|
| + return emptyString();
|
| +
|
| + Text* text = inputMethodController().compositionNode();
|
| + return text ? text->wholeText() : emptyString();
|
| }
|
|
|
| -void InputMethodContext::setCaretRectangle(Node* anchor, int x, int y, int w, int h)
|
| +CompositionUnderline InputMethodContext::selectedSegment() const
|
| {
|
| - // FIXME: Implement this.
|
| + 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];
|
| + }
|
| +
|
| + // When no underline information is available while composition exists,
|
| + // build a CompositionUnderline whose element is the whole composition.
|
| + underline.endOffset = controller.compositionEnd() - controller.compositionStart();
|
| + return underline;
|
| +
|
| }
|
|
|
| -void InputMethodContext::setExclusionRectangle(Node* anchor, int x, int y, int w, int h)
|
| +int InputMethodContext::selectionStart() const
|
| {
|
| - // FIXME: Implement this.
|
| + 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();
|
| }
|
|
|
| } // namespace WebCore
|
|
|