Index: content/shell/renderer/test_runner/text_input_controller.cc |
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 0000000000000000000000000000000000000000..c2136dd5d13ad81383bbd22fc5649b8c9855e3fc |
--- /dev/null |
+++ b/content/shell/renderer/test_runner/text_input_controller.cc |
@@ -0,0 +1,180 @@ |
+// 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 "third_party/WebKit/public/web/WebBindings.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 WebTestRunner { |
+ |
+// static |
+gin::WrapperInfo TextInputController::kWrapperInfo = { |
+ gin::kEmbedderNativeGin |
+}; |
+ |
+// static |
+void TextInputController::Install(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<TextInputController> controller = |
+ gin::CreateHandle(isolate, new TextInputController(frame)); |
+ v8::Handle<v8::Object> global = context->Global(); |
+ global->Set(gin::StringToV8(isolate, "textInputController"), |
+ controller.ToV8()); |
+} |
+ |
+TextInputController::TextInputController(blink::WebFrame* frame) |
+ : frame_(frame) {} |
+ |
+TextInputController::~TextInputController() {} |
+ |
+gin::ObjectTemplateBuilder TextInputController::GetObjectTemplateBuilder( |
+ v8::Isolate* isolate) { |
+ return gin::Wrappable<TextInputController>::GetObjectTemplateBuilder(isolate) |
+ .SetMethod("insertText", &TextInputController::InsertText) |
+ .SetMethod("unmarkText", &TextInputController::UnmarkText) |
+ .SetMethod("doCommand", &TextInputController::DoCommand) |
+ .SetMethod("setMarkedText", &TextInputController::SetMarkedText) |
+ .SetMethod("hasMarkedText", &TextInputController::HasMarkedText) |
+ .SetMethod("markedRange", &TextInputController::MarkedRange) |
+ .SetMethod("selectedRange", &TextInputController::SelectedRange) |
+ .SetMethod("firstRectForCharacterRange", &TextInputController::FirstRectForCharacterRange) |
+ .SetMethod("setComposition", &TextInputController::SetComposition); |
+} |
+ |
+void TextInputController::InsertText(gin::Arguments* args) { |
jochen (gone - plz use gerrit)
2014/02/10 12:32:05
if you declare InsertText(const std::string& text)
|
+ if (args->PeekNext().IsEmpty() || !args->PeekNext()->IsString()) |
+ return; |
+ |
+ v8::Handle<v8::Value> value; |
+ args->GetNext(&value); |
+ //frame_->view()->confirmComposition(WebString::fromUTF8(###WHAT-GOES-HERE)); |
+} |
+ |
+void TextInputController::UnmarkText() { |
+ frame_->view()->confirmComposition(); |
+} |
+ |
+void TextInputController::DoCommand(gin::Arguments* args) { |
+ if (!args->PeekNext().IsEmpty() && !args->PeekNext()->IsString()) { |
+ //frame_->executeCommand(WebString::fromUTF8(##WHAT-WE-PASS-HERE?)); |
+ } |
+} |
+ |
+void TextInputController::SetMarkedText(gin::Arguments* args) { |
+ /*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). |
+ std::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); |
+ } |
+ |
+ frame_->view()->setComposition(text, underlines, start, start + length); |
+ */ |
+} |
+ |
+void TextInputController::HasMarkedText() { |
+ // result->set(frame_->hasMarkedText()); |
+} |
+ |
+void TextInputController::MarkedRange() { |
+ blink::WebRange range = frame_->markedRange(); |
+ std::vector<int> int_array(2); |
+ int_array[0] = range.startOffset(); |
+ int_array[1] = range.endOffset(); |
+ |
+ NPObject* result_array = blink::WebBindings::makeIntArray(int_array); |
+ //result->set(result_array); |
+ blink::WebBindings::releaseObject(result_array); |
+} |
+ |
+void TextInputController::SelectedRange() { |
+ blink::WebRange range = frame_->selectionRange(); |
+ std::vector<int> int_array(2); |
+ int_array[0] = range.startOffset(); |
+ int_array[1] = range.endOffset(); |
+ |
+ NPObject* result_array = blink::WebBindings::makeIntArray(int_array); |
+ //result->set(result_array); |
+ blink::WebBindings::releaseObject(result_array); |
+} |
+ |
+void TextInputController::FirstRectForCharacterRange(gin::Arguments* args) { |
jochen (gone - plz use gerrit)
2014/02/10 12:32:05
same for the return value. If you return a vector<
|
+ /*if (arguments.size() < 2 || !arguments[0].isNumber() || |
+ !arguments[1].isNumber()) |
+ return; |
+*/ |
+ blink::WebRect rect; |
+ /* if (!frame_->firstRectForCharacterRange( |
+ arguments[0].toInt32(), arguments[1].toInt32(), rect)) |
+ return; |
+ |
+ */ |
+ 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; |
+ |
+ NPObject* result_array = blink::WebBindings::makeIntArray(int_array); |
+ //result->set(result_array); |
+ blink::WebBindings::releaseObject(result_array); |
+} |
+ |
+void TextInputController::SetComposition(gin::Arguments* args) { |
+ if (args->PeekNext().IsEmpty()) |
+ return; |
+ |
+ // 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(); |
+ frame_->view()->handleInputEvent(key_down); |
jochen (gone - plz use gerrit)
2014/02/10 12:32:05
you can't know for sure that frame exists at this
|
+ |
+ /*WebVector<WebCompositionUnderline> underlines; |
+ WebString text(WebString::fromUTF8(arguments[0].toString())); |
+ frame_->view()->setComposition(text, underlines, 0, text.length()); |
+ */ |
+} |
+ |
+} // namespace WebTestRunner |