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

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: consistent quotation usage in layouttest html. 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
« no previous file with comments | « Source/core/html/ime/InputMethodContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/core/html/ime/InputMethodContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698