Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1290)

Unified Diff: Source/core/html/ime/InputMethodContext.cpp

Issue 23604053: Implement Composition interface for IME API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..fe42dee487c5271541af090116593b1884c59b41 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,91 @@ HTMLElement* InputMethodContext::target() const
void InputMethodContext::confirmComposition()
{
+ if (hasFocus())
+ m_element->document().frame()->inputMethodController().confirmCompositionAndResetState();
tkent 2013/09/11 08:10:55 nit: We had better have a helper function to get a
kochi 2013/09/11 08:32:00 Done. Added inputMethodController() helper functi
+}
+
+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);
+}
+
+String InputMethodContext::getCompositionText() const
+{
+ if (!hasFocus())
+ return emptyString();
+
+ Text* text = m_element->document().frame()->inputMethodController().compositionNode();
- frame->inputMethodController().confirmCompositionAndResetState();
+ return text ? text->wholeText() : emptyString();
}
-void InputMethodContext::setCaretRectangle(Node* anchor, int x, int y, int w, int h)
+CompositionUnderline InputMethodContext::getSelectedSegment() const
{
- // FIXME: Implement this.
+ CompositionUnderline underline;
+ if (!hasFocus())
+ return underline;
+
+ const InputMethodController& controller = m_element->document().frame()->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::getSelectionStart() const
{
- // FIXME: Implement this.
+ return getSelectedSegment().startOffset;
+}
+
+int InputMethodContext::getSelectionEnd() const
+{
+ return getSelectedSegment().endOffset;
+}
+
+const Vector<unsigned>& InputMethodContext::getSegments()
+{
+ m_segments.clear();
+ if (!hasFocus())
+ return m_segments;
+ const InputMethodController& controller = m_element->document().frame()->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;
}
} // namespace WebCore
« Source/core/html/ime/InputMethodContext.h ('K') | « Source/core/html/ime/InputMethodContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698