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

Side by Side Diff: content/shell/renderer/test_runner/text_input_controller.cc

Issue 144013010: Move TextInputController from CppBoundClass to gin::Wrappable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TextInputController1 -> TextInputController Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/renderer/test_runner/text_input_controller.h"
6
7 #include "gin/arguments.h"
8 #include "gin/handle.h"
9 #include "gin/object_template_builder.h"
10 #include "third_party/WebKit/public/web/WebBindings.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
12 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 #include "third_party/WebKit/public/web/WebKit.h"
14 #include "third_party/WebKit/public/web/WebRange.h"
15 #include "third_party/WebKit/public/web/WebView.h"
16 #include "v8/include/v8.h"
17
18 namespace WebTestRunner {
19
20 // static
21 gin::WrapperInfo TextInputController::kWrapperInfo = {
22 gin::kEmbedderNativeGin
23 };
24
25 // static
26 void TextInputController::Install(blink::WebFrame* frame) {
27 v8::Isolate* isolate = blink::mainThreadIsolate();
28 v8::HandleScope handle_scope(isolate);
29 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
30 if (context.IsEmpty())
31 return;
32
33 v8::Context::Scope context_scope(context);
34
35 gin::Handle<TextInputController> controller =
36 gin::CreateHandle(isolate, new TextInputController(frame));
37 v8::Handle<v8::Object> global = context->Global();
38 global->Set(gin::StringToV8(isolate, "textInputController"),
39 controller.ToV8());
40 }
41
42 TextInputController::TextInputController(blink::WebFrame* frame)
43 : frame_(frame) {}
44
45 TextInputController::~TextInputController() {}
46
47 gin::ObjectTemplateBuilder TextInputController::GetObjectTemplateBuilder(
48 v8::Isolate* isolate) {
49 return gin::Wrappable<TextInputController>::GetObjectTemplateBuilder(isolate)
50 .SetMethod("insertText", &TextInputController::InsertText)
51 .SetMethod("unmarkText", &TextInputController::UnmarkText)
52 .SetMethod("doCommand", &TextInputController::DoCommand)
53 .SetMethod("setMarkedText", &TextInputController::SetMarkedText)
54 .SetMethod("hasMarkedText", &TextInputController::HasMarkedText)
55 .SetMethod("markedRange", &TextInputController::MarkedRange)
56 .SetMethod("selectedRange", &TextInputController::SelectedRange)
57 .SetMethod("firstRectForCharacterRange", &TextInputController::FirstRectFo rCharacterRange)
58 .SetMethod("setComposition", &TextInputController::SetComposition);
59 }
60
61 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)
62 if (args->PeekNext().IsEmpty() || !args->PeekNext()->IsString())
63 return;
64
65 v8::Handle<v8::Value> value;
66 args->GetNext(&value);
67 //frame_->view()->confirmComposition(WebString::fromUTF8(###WHAT-GOES-HERE));
68 }
69
70 void TextInputController::UnmarkText() {
71 frame_->view()->confirmComposition();
72 }
73
74 void TextInputController::DoCommand(gin::Arguments* args) {
75 if (!args->PeekNext().IsEmpty() && !args->PeekNext()->IsString()) {
76 //frame_->executeCommand(WebString::fromUTF8(##WHAT-WE-PASS-HERE?));
77 }
78 }
79
80 void TextInputController::SetMarkedText(gin::Arguments* args) {
81 /*if (arguments.size() < 3 || !arguments[0].isString() ||
82 !arguments[1].isNumber() || !arguments[2].isNumber())
83 return;
84
85 WebString text(WebString::fromUTF8(arguments[0].toString()));
86 int start = arguments[1].toInt32();
87 int length = arguments[2].toInt32();
88
89 // Split underline into up to 3 elements (before, selection, and after).
90 std::vector<WebCompositionUnderline> underlines;
91 WebCompositionUnderline underline;
92 if (!start) {
93 underline.endOffset = length;
94 } else {
95 underline.endOffset = start;
96 underlines.push_back(underline);
97 underline.startOffset = start;
98 underline.endOffset = start + length;
99 }
100 underline.thick = true;
101 underlines.push_back(underline);
102 if (start + length < static_cast<int>(text.length())) {
103 underline.startOffset = underline.endOffset;
104 underline.endOffset = text.length();
105 underline.thick = false;
106 underlines.push_back(underline);
107 }
108
109 frame_->view()->setComposition(text, underlines, start, start + length);
110 */
111 }
112
113 void TextInputController::HasMarkedText() {
114 // result->set(frame_->hasMarkedText());
115 }
116
117 void TextInputController::MarkedRange() {
118 blink::WebRange range = frame_->markedRange();
119 std::vector<int> int_array(2);
120 int_array[0] = range.startOffset();
121 int_array[1] = range.endOffset();
122
123 NPObject* result_array = blink::WebBindings::makeIntArray(int_array);
124 //result->set(result_array);
125 blink::WebBindings::releaseObject(result_array);
126 }
127
128 void TextInputController::SelectedRange() {
129 blink::WebRange range = frame_->selectionRange();
130 std::vector<int> int_array(2);
131 int_array[0] = range.startOffset();
132 int_array[1] = range.endOffset();
133
134 NPObject* result_array = blink::WebBindings::makeIntArray(int_array);
135 //result->set(result_array);
136 blink::WebBindings::releaseObject(result_array);
137 }
138
139 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<
140 /*if (arguments.size() < 2 || !arguments[0].isNumber() ||
141 !arguments[1].isNumber())
142 return;
143 */
144 blink::WebRect rect;
145 /* if (!frame_->firstRectForCharacterRange(
146 arguments[0].toInt32(), arguments[1].toInt32(), rect))
147 return;
148
149 */
150 std::vector<int> int_array(4);
151 int_array[0] = rect.x;
152 int_array[1] = rect.y;
153 int_array[2] = rect.width;
154 int_array[3] = rect.height;
155
156 NPObject* result_array = blink::WebBindings::makeIntArray(int_array);
157 //result->set(result_array);
158 blink::WebBindings::releaseObject(result_array);
159 }
160
161 void TextInputController::SetComposition(gin::Arguments* args) {
162 if (args->PeekNext().IsEmpty())
163 return;
164
165 // Sends a keydown event with key code = 0xE5 to emulate input method
166 // behavior.
167 blink::WebKeyboardEvent key_down;
168 key_down.type = blink::WebInputEvent::RawKeyDown;
169 key_down.modifiers = 0;
170 key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY
171 key_down.setKeyIdentifierFromWindowsKeyCode();
172 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
173
174 /*WebVector<WebCompositionUnderline> underlines;
175 WebString text(WebString::fromUTF8(arguments[0].toString()));
176 frame_->view()->setComposition(text, underlines, 0, text.length());
177 */
178 }
179
180 } // namespace WebTestRunner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698