summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-17 17:51:23 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-17 17:51:23 +0000
commit4f52926cf7394643faa05e4181c0a596908cdb12 (patch)
tree73482c1de21de1e5c98bae8fae61fae98b87c6cb
parent7a29561b1bf022324bf3533a0dd9183e00061028 (diff)
downloadchromium_src-4f52926cf7394643faa05e4181c0a596908cdb12.zip
chromium_src-4f52926cf7394643faa05e4181c0a596908cdb12.tar.gz
chromium_src-4f52926cf7394643faa05e4181c0a596908cdb12.tar.bz2
Move TextInputController from CppBoundClass to gin::Wrappable.
Also, change the class to use chromium coding style. BUG=297480, 331301 R=jochen@chromium.org Review URL: https://codereview.chromium.org/144013010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251692 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_shell.gypi4
-rw-r--r--content/shell/renderer/test_runner/TestInterfaces.cpp10
-rw-r--r--content/shell/renderer/test_runner/TestInterfaces.h4
-rw-r--r--content/shell/renderer/test_runner/TextInputController.cpp193
-rw-r--r--content/shell/renderer/test_runner/TextInputController.h42
-rw-r--r--content/shell/renderer/test_runner/text_input_controller.cc252
-rw-r--r--content/shell/renderer/test_runner/text_input_controller.h56
7 files changed, 317 insertions, 244 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index e27b028..9a9537f 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -220,8 +220,6 @@
'shell/renderer/test_runner/TestPlugin.h',
'shell/renderer/test_runner/TestRunner.cpp',
'shell/renderer/test_runner/TestRunner.h',
- 'shell/renderer/test_runner/TextInputController.cpp',
- 'shell/renderer/test_runner/TextInputController.h',
'shell/renderer/test_runner/WebAXObjectProxy.cpp',
'shell/renderer/test_runner/WebAXObjectProxy.h',
'shell/renderer/test_runner/WebFrameTestProxy.h',
@@ -243,6 +241,8 @@
'shell/renderer/test_runner/WebUserMediaClientMock.h',
'shell/renderer/test_runner/gamepad_controller.cc',
'shell/renderer/test_runner/gamepad_controller.h',
+ 'shell/renderer/test_runner/text_input_controller.cc',
+ 'shell/renderer/test_runner/text_input_controller.h',
'shell/renderer/webkit_test_runner.cc',
'shell/renderer/webkit_test_runner.h',
'test/layouttest_support.cc',
diff --git a/content/shell/renderer/test_runner/TestInterfaces.cpp b/content/shell/renderer/test_runner/TestInterfaces.cpp
index 7981f36..426f652 100644
--- a/content/shell/renderer/test_runner/TestInterfaces.cpp
+++ b/content/shell/renderer/test_runner/TestInterfaces.cpp
@@ -10,9 +10,9 @@
#include "content/shell/renderer/test_runner/AccessibilityController.h"
#include "content/shell/renderer/test_runner/EventSender.h"
#include "content/shell/renderer/test_runner/TestRunner.h"
-#include "content/shell/renderer/test_runner/TextInputController.h"
#include "content/shell/renderer/test_runner/WebTestProxy.h"
#include "content/shell/renderer/test_runner/gamepad_controller.h"
+#include "content/shell/renderer/test_runner/text_input_controller.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/web/WebCache.h"
@@ -29,7 +29,7 @@ TestInterfaces::TestInterfaces()
: m_accessibilityController(new AccessibilityController())
, m_eventSender(new EventSender(this))
, m_gamepadController(new content::GamepadController())
- , m_textInputController(new TextInputController())
+ , m_textInputController(new content::TextInputController())
, m_testRunner(new TestRunner(this))
, m_delegate(0)
{
@@ -46,7 +46,7 @@ TestInterfaces::~TestInterfaces()
m_accessibilityController->setWebView(0);
m_eventSender->setWebView(0);
// m_gamepadController doesn't depend on WebView.
- m_textInputController->setWebView(0);
+ m_textInputController->SetWebView(NULL);
m_testRunner->setWebView(0, 0);
m_accessibilityController->setDelegate(0);
@@ -62,7 +62,7 @@ void TestInterfaces::setWebView(WebView* webView, WebTestProxyBase* proxy)
m_accessibilityController->setWebView(webView);
m_eventSender->setWebView(webView);
// m_gamepadController doesn't depend on WebView.
- m_textInputController->setWebView(webView);
+ m_textInputController->SetWebView(webView);
m_testRunner->setWebView(webView, proxy);
}
@@ -81,7 +81,7 @@ void TestInterfaces::bindTo(WebFrame* frame)
m_accessibilityController->bindToJavascript(frame, WebString::fromUTF8("accessibilityController"));
m_eventSender->bindToJavascript(frame, WebString::fromUTF8("eventSender"));
m_gamepadController->Install(frame);
- m_textInputController->bindToJavascript(frame, WebString::fromUTF8("textInputController"));
+ m_textInputController->Install(frame);
m_testRunner->bindToJavascript(frame, WebString::fromUTF8("testRunner"));
m_testRunner->bindToJavascript(frame, WebString::fromUTF8("layoutTestController"));
}
diff --git a/content/shell/renderer/test_runner/TestInterfaces.h b/content/shell/renderer/test_runner/TestInterfaces.h
index 5e6ed26..69e490c 100644
--- a/content/shell/renderer/test_runner/TestInterfaces.h
+++ b/content/shell/renderer/test_runner/TestInterfaces.h
@@ -26,6 +26,7 @@ class WebView;
namespace content {
class GamepadController;
+class TextInputController;
}
namespace WebTestRunner {
@@ -33,7 +34,6 @@ namespace WebTestRunner {
class AccessibilityController;
class EventSender;
class TestRunner;
-class TextInputController;
class WebTestDelegate;
class WebTestProxyBase;
@@ -65,7 +65,7 @@ private:
scoped_ptr<AccessibilityController> m_accessibilityController;
scoped_ptr<EventSender> m_eventSender;
scoped_ptr<content::GamepadController> m_gamepadController;
- scoped_ptr<TextInputController> m_textInputController;
+ scoped_ptr<content::TextInputController> m_textInputController;
scoped_ptr<TestRunner> m_testRunner;
WebTestDelegate* m_delegate;
WebTestProxyBase* m_proxy;
diff --git a/content/shell/renderer/test_runner/TextInputController.cpp b/content/shell/renderer/test_runner/TextInputController.cpp
deleted file mode 100644
index e2811a0..0000000
--- a/content/shell/renderer/test_runner/TextInputController.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/shell/renderer/test_runner/TextInputController.h"
-
-#include <string>
-#include "content/shell/renderer/test_runner/TestCommon.h"
-#include "third_party/WebKit/public/platform/WebString.h"
-#include "third_party/WebKit/public/platform/WebVector.h"
-#include "third_party/WebKit/public/web/WebBindings.h"
-#include "third_party/WebKit/public/web/WebCompositionUnderline.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
-#include "third_party/WebKit/public/web/WebInputEvent.h"
-#include "third_party/WebKit/public/web/WebRange.h"
-#include "third_party/WebKit/public/web/WebView.h"
-
-using namespace blink;
-using namespace std;
-
-namespace WebTestRunner {
-
-TextInputController::TextInputController()
-{
- bindMethod("doCommand", &TextInputController::doCommand);
- bindMethod("firstRectForCharacterRange", &TextInputController::firstRectForCharacterRange);
- bindMethod("hasMarkedText", &TextInputController::hasMarkedText);
- bindMethod("insertText", &TextInputController::insertText);
- bindMethod("markedRange", &TextInputController::markedRange);
- bindMethod("selectedRange", &TextInputController::selectedRange);
- bindMethod("setMarkedText", &TextInputController::setMarkedText);
- bindMethod("unmarkText", &TextInputController::unmarkText);
- bindMethod("setComposition", &TextInputController::setComposition);
-}
-
-void TextInputController::insertText(const CppArgumentList& arguments, CppVariant* result)
-{
- result->setNull();
-
- if (arguments.size() < 1 || !arguments[0].isString())
- return;
-
- m_webView->confirmComposition(WebString::fromUTF8(arguments[0].toString()));
-}
-
-void TextInputController::doCommand(const CppArgumentList& arguments, CppVariant* result)
-{
- result->setNull();
-
- WebFrame* mainFrame = m_webView->mainFrame();
- if (!mainFrame)
- return;
-
- if (arguments.size() >= 1 && arguments[0].isString())
- mainFrame->executeCommand(WebString::fromUTF8(arguments[0].toString()));
-}
-
-void TextInputController::setMarkedText(const CppArgumentList& arguments, CppVariant* result)
-{
- result->setNull();
-
- if (arguments.size() < 3 || !arguments[0].isString()
- || !arguments[1].isNumber() || !arguments[2].isNumber())
- return;
-
- WebString text(WebString::fromUTF8(arguments[0].toString()));
- int start = arguments[1].toInt32();
- int length = arguments[2].toInt32();
-
- // Split underline into up to 3 elements (before, selection, and after).
- vector<WebCompositionUnderline> underlines;
- WebCompositionUnderline underline;
- if (!start) {
- underline.endOffset = length;
- } else {
- underline.endOffset = start;
- underlines.push_back(underline);
- underline.startOffset = start;
- underline.endOffset = start + length;
- }
- underline.thick = true;
- underlines.push_back(underline);
- if (start + length < static_cast<int>(text.length())) {
- underline.startOffset = underline.endOffset;
- underline.endOffset = text.length();
- underline.thick = false;
- underlines.push_back(underline);
- }
-
- m_webView->setComposition(text, underlines, start, start + length);
-}
-
-void TextInputController::unmarkText(const CppArgumentList&, CppVariant* result)
-{
- result->setNull();
-
- m_webView->confirmComposition();
-}
-
-void TextInputController::hasMarkedText(const CppArgumentList&, CppVariant* result)
-{
- result->setNull();
-
- WebFrame* mainFrame = m_webView->mainFrame();
- if (!mainFrame)
- return;
-
- result->set(mainFrame->hasMarkedText());
-}
-
-void TextInputController::markedRange(const CppArgumentList&, CppVariant* result)
-{
- result->setNull();
-
- WebFrame* mainFrame = m_webView->mainFrame();
- if (!mainFrame)
- return;
-
- WebRange range = mainFrame->markedRange();
- vector<int> intArray(2);
- intArray[0] = range.startOffset();
- intArray[1] = range.endOffset();
-
- NPObject* resultArray = WebBindings::makeIntArray(intArray);
- result->set(resultArray);
- WebBindings::releaseObject(resultArray);
-}
-
-void TextInputController::selectedRange(const CppArgumentList&, CppVariant* result)
-{
- result->setNull();
-
- WebFrame* mainFrame = m_webView->mainFrame();
- if (!mainFrame)
- return;
-
- WebRange range = mainFrame->selectionRange();
- vector<int> intArray(2);
- intArray[0] = range.startOffset();
- intArray[1] = range.endOffset();
-
- NPObject* resultArray = WebBindings::makeIntArray(intArray);
- result->set(resultArray);
- WebBindings::releaseObject(resultArray);
-}
-
-void TextInputController::firstRectForCharacterRange(const CppArgumentList& arguments, CppVariant* result)
-{
- result->setNull();
-
- WebFrame* frame = m_webView->focusedFrame();
- if (!frame)
- return;
-
- if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumber())
- return;
-
- WebRect rect;
- if (!frame->firstRectForCharacterRange(arguments[0].toInt32(), arguments[1].toInt32(), rect))
- return;
-
- vector<int> intArray(4);
- intArray[0] = rect.x;
- intArray[1] = rect.y;
- intArray[2] = rect.width;
- intArray[3] = rect.height;
-
- NPObject* resultArray = WebBindings::makeIntArray(intArray);
- result->set(resultArray);
- WebBindings::releaseObject(resultArray);
-}
-
-void TextInputController::setComposition(const CppArgumentList& arguments, CppVariant* result)
-{
- result->setNull();
-
- if (arguments.size() < 1)
- return;
-
- // Sends a keydown event with key code = 0xE5 to emulate input method behavior.
- WebKeyboardEvent keyDown;
- keyDown.type = WebInputEvent::RawKeyDown;
- keyDown.modifiers = 0;
- keyDown.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY
- keyDown.setKeyIdentifierFromWindowsKeyCode();
- m_webView->handleInputEvent(keyDown);
-
- WebVector<WebCompositionUnderline> underlines;
- WebString text(WebString::fromUTF8(arguments[0].toString()));
- m_webView->setComposition(text, underlines, 0, text.length());
-}
-
-}
diff --git a/content/shell/renderer/test_runner/TextInputController.h b/content/shell/renderer/test_runner/TextInputController.h
deleted file mode 100644
index eabea24..0000000
--- a/content/shell/renderer/test_runner/TextInputController.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// TextInputController is bound to window.textInputController in Javascript
-// when DRT is running. Layout tests use it to exercise various corners of
-// text input.
-
-#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_TEXTINPUTCONTROLLER_H_
-#define CONTENT_SHELL_RENDERER_TEST_RUNNER_TEXTINPUTCONTROLLER_H_
-
-#include "content/shell/renderer/test_runner/CppBoundClass.h"
-
-namespace blink {
-class WebView;
-}
-
-namespace WebTestRunner {
-
-class TextInputController : public CppBoundClass {
-public:
- TextInputController();
-
- void setWebView(blink::WebView* webView) { m_webView = webView; }
-
- void insertText(const CppArgumentList&, CppVariant*);
- void doCommand(const CppArgumentList&, CppVariant*);
- void setMarkedText(const CppArgumentList&, CppVariant*);
- void unmarkText(const CppArgumentList&, CppVariant*);
- void hasMarkedText(const CppArgumentList&, CppVariant*);
- void markedRange(const CppArgumentList&, CppVariant*);
- void selectedRange(const CppArgumentList&, CppVariant*);
- void firstRectForCharacterRange(const CppArgumentList&, CppVariant*);
- void setComposition(const CppArgumentList&, CppVariant*);
-
-private:
- blink::WebView* m_webView;
-};
-
-}
-
-#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TEXTINPUTCONTROLLER_H_
diff --git a/content/shell/renderer/test_runner/text_input_controller.cc b/content/shell/renderer/test_runner/text_input_controller.cc
new file mode 100644
index 0000000..5a468cc
--- /dev/null
+++ b/content/shell/renderer/test_runner/text_input_controller.cc
@@ -0,0 +1,252 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/shell/renderer/test_runner/text_input_controller.h"
+
+#include "gin/arguments.h"
+#include "gin/handle.h"
+#include "gin/object_template_builder.h"
+#include "gin/wrappable.h"
+#include "third_party/WebKit/public/web/WebCompositionUnderline.h"
+#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+#include "third_party/WebKit/public/web/WebKit.h"
+#include "third_party/WebKit/public/web/WebRange.h"
+#include "third_party/WebKit/public/web/WebView.h"
+#include "v8/include/v8.h"
+
+namespace content {
+
+class TextInputControllerBindings
+ : public gin::Wrappable<TextInputControllerBindings> {
+ public:
+ static gin::WrapperInfo kWrapperInfo;
+
+ static void Install(base::WeakPtr<TextInputController> controller,
+ blink::WebFrame* frame);
+
+ private:
+ explicit TextInputControllerBindings(
+ base::WeakPtr<TextInputController> controller);
+ virtual ~TextInputControllerBindings();
+
+ // gin::Wrappable:
+ virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
+ v8::Isolate* isolate) OVERRIDE;
+
+ void InsertText(const std::string& text);
+ void UnmarkText();
+ void DoCommand(const std::string& text);
+ void SetMarkedText(const std::string& text, int start, int length);
+ bool HasMarkedText();
+ std::vector<int> MarkedRange();
+ std::vector<int> SelectedRange();
+ std::vector<int> FirstRectForCharacterRange(unsigned location,
+ unsigned length);
+ void SetComposition(const std::string& text);
+
+ base::WeakPtr<TextInputController> controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextInputControllerBindings);
+};
+
+gin::WrapperInfo TextInputControllerBindings::kWrapperInfo = {
+ gin::kEmbedderNativeGin};
+
+// static
+void TextInputControllerBindings::Install(
+ base::WeakPtr<TextInputController> controller,
+ blink::WebFrame* frame) {
+ v8::Isolate* isolate = blink::mainThreadIsolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
+ if (context.IsEmpty())
+ return;
+
+ v8::Context::Scope context_scope(context);
+
+ gin::Handle<TextInputControllerBindings> bindings =
+ gin::CreateHandle(isolate, new TextInputControllerBindings(controller));
+ v8::Handle<v8::Object> global = context->Global();
+ global->Set(gin::StringToV8(isolate, "textInputController"), bindings.ToV8());
+}
+
+TextInputControllerBindings::TextInputControllerBindings(
+ base::WeakPtr<TextInputController> controller)
+ : controller_(controller) {}
+
+TextInputControllerBindings::~TextInputControllerBindings() {}
+
+gin::ObjectTemplateBuilder
+TextInputControllerBindings::GetObjectTemplateBuilder(v8::Isolate* isolate) {
+ return gin::Wrappable<TextInputControllerBindings>::GetObjectTemplateBuilder(
+ isolate)
+ .SetMethod("insertText", &TextInputControllerBindings::InsertText)
+ .SetMethod("unmarkText", &TextInputControllerBindings::UnmarkText)
+ .SetMethod("doCommand", &TextInputControllerBindings::DoCommand)
+ .SetMethod("setMarkedText", &TextInputControllerBindings::SetMarkedText)
+ .SetMethod("hasMarkedText", &TextInputControllerBindings::HasMarkedText)
+ .SetMethod("markedRange", &TextInputControllerBindings::MarkedRange)
+ .SetMethod("selectedRange", &TextInputControllerBindings::SelectedRange)
+ .SetMethod("firstRectForCharacterRange",
+ &TextInputControllerBindings::FirstRectForCharacterRange)
+ .SetMethod("setComposition",
+ &TextInputControllerBindings::SetComposition);
+}
+
+void TextInputControllerBindings::InsertText(const std::string& text) {
+ if (controller_)
+ controller_->InsertText(text);
+}
+
+void TextInputControllerBindings::UnmarkText() {
+ if (controller_)
+ controller_->UnmarkText();
+}
+
+void TextInputControllerBindings::DoCommand(const std::string& text) {
+ if (controller_)
+ controller_->DoCommand(text);
+}
+
+void TextInputControllerBindings::SetMarkedText(const std::string& text,
+ int start,
+ int length) {
+ if (controller_)
+ controller_->SetMarkedText(text, start, length);
+}
+
+bool TextInputControllerBindings::HasMarkedText() {
+ return controller_ ? controller_->HasMarkedText() : false;
+}
+
+std::vector<int> TextInputControllerBindings::MarkedRange() {
+ return controller_ ? controller_->MarkedRange() : std::vector<int>();
+}
+
+std::vector<int> TextInputControllerBindings::SelectedRange() {
+ return controller_ ? controller_->SelectedRange() : std::vector<int>();
+}
+
+std::vector<int> TextInputControllerBindings::FirstRectForCharacterRange(
+ unsigned location,
+ unsigned length) {
+ return controller_ ? controller_->FirstRectForCharacterRange(location, length)
+ : std::vector<int>();
+}
+
+void TextInputControllerBindings::SetComposition(const std::string& text) {
+ if (controller_)
+ controller_->SetComposition(text);
+}
+
+// TextInputController ---------------------------------------------------------
+
+TextInputController::TextInputController()
+ : view_(NULL), weak_factory_(this) {}
+
+TextInputController::~TextInputController() {}
+
+void TextInputController::Install(blink::WebFrame* frame) {
+ TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
+}
+
+void TextInputController::SetWebView(blink::WebView* view) {
+ view_ = view;
+}
+
+void TextInputController::InsertText(const std::string& text) {
+ view_->confirmComposition(blink::WebString::fromUTF8(text));
+}
+
+void TextInputController::UnmarkText() {
+ view_->confirmComposition();
+}
+
+void TextInputController::DoCommand(const std::string& text) {
+ view_->mainFrame()->executeCommand(blink::WebString::fromUTF8(text));
+}
+
+void TextInputController::SetMarkedText(const std::string& text,
+ int start,
+ int length) {
+ blink::WebString web_text(blink::WebString::fromUTF8(text));
+
+ // Split underline into up to 3 elements (before, selection, and after).
+ std::vector<blink::WebCompositionUnderline> underlines;
+ blink::WebCompositionUnderline underline;
+ if (!start) {
+ underline.endOffset = length;
+ } else {
+ underline.endOffset = start;
+ underlines.push_back(underline);
+ underline.startOffset = start;
+ underline.endOffset = start + length;
+ }
+ underline.thick = true;
+ underlines.push_back(underline);
+ if (start + length < static_cast<int>(web_text.length())) {
+ underline.startOffset = underline.endOffset;
+ underline.endOffset = web_text.length();
+ underline.thick = false;
+ underlines.push_back(underline);
+ }
+
+ view_->setComposition(web_text, underlines, start, start + length);
+}
+
+bool TextInputController::HasMarkedText() {
+ return view_->mainFrame()->hasMarkedText();
+}
+
+std::vector<int> TextInputController::MarkedRange() {
+ blink::WebRange range = view_->mainFrame()->markedRange();
+ std::vector<int> int_array(2);
+ int_array[0] = range.startOffset();
+ int_array[1] = range.endOffset();
+
+ return int_array;
+}
+
+std::vector<int> TextInputController::SelectedRange() {
+ blink::WebRange range = view_->mainFrame()->selectionRange();
+ std::vector<int> int_array(2);
+ int_array[0] = range.startOffset();
+ int_array[1] = range.endOffset();
+
+ return int_array;
+}
+
+std::vector<int> TextInputController::FirstRectForCharacterRange(
+ unsigned location,
+ unsigned length) {
+ blink::WebRect rect;
+ if (!view_->mainFrame()->firstRectForCharacterRange(location, length, rect))
+ return std::vector<int>();
+
+ std::vector<int> int_array(4);
+ int_array[0] = rect.x;
+ int_array[1] = rect.y;
+ int_array[2] = rect.width;
+ int_array[3] = rect.height;
+
+ return int_array;
+}
+
+void TextInputController::SetComposition(const std::string& text) {
+ // Sends a keydown event with key code = 0xE5 to emulate input method
+ // behavior.
+ blink::WebKeyboardEvent key_down;
+ key_down.type = blink::WebInputEvent::RawKeyDown;
+ key_down.modifiers = 0;
+ key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY
+ key_down.setKeyIdentifierFromWindowsKeyCode();
+ view_->handleInputEvent(key_down);
+
+ blink::WebVector<blink::WebCompositionUnderline> underlines;
+ blink::WebString web_text(blink::WebString::fromUTF8(text));
+ view_->setComposition(web_text, underlines, 0, web_text.length());
+}
+
+} // namespace content
diff --git a/content/shell/renderer/test_runner/text_input_controller.h b/content/shell/renderer/test_runner/text_input_controller.h
new file mode 100644
index 0000000..7a3706c
--- /dev/null
+++ b/content/shell/renderer/test_runner/text_input_controller.h
@@ -0,0 +1,56 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_TEXTINPUTCONTROLLER_H_
+#define CONTENT_SHELL_RENDERER_TEST_RUNNER_TEXTINPUTCONTROLLER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+
+namespace blink {
+class WebFrame;
+class WebView;
+}
+
+namespace content {
+
+// TextInputController is bound to window.textInputController in Javascript
+// when content_shell is running. Layout tests use it to exercise various
+// corners of text input.
+class TextInputController : public base::SupportsWeakPtr<TextInputController> {
+ public:
+ TextInputController();
+ ~TextInputController();
+
+ void Install(blink::WebFrame* frame);
+
+ void SetWebView(blink::WebView* view);
+
+ private:
+ friend class TextInputControllerBindings;
+
+ void InsertText(const std::string& text);
+ void UnmarkText();
+ void DoCommand(const std::string& text);
+ void SetMarkedText(const std::string& text, int start, int length);
+ bool HasMarkedText();
+ std::vector<int> MarkedRange();
+ std::vector<int> SelectedRange();
+ std::vector<int> FirstRectForCharacterRange(unsigned location,
+ unsigned length);
+ void SetComposition(const std::string& text);
+
+ blink::WebView* view_;
+
+ base::WeakPtrFactory<TextInputController> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextInputController);
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TEXTINPUTCONTROLLER_H_