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

Side by Side Diff: webkit/tools/test_shell/text_input_controller.cc

Issue 6296015: Remove eventSender, accessibilityController, plainText and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/webkit/tools/test_shell
Patch Set: Created 9 years, 11 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 (c) 2010 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 "webkit/tools/test_shell/text_input_controller.h"
6
7 #include "base/string_util.h"
8 #include "base/stringprintf.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
16 #include "webkit/tools/test_shell/test_shell.h"
17
18 using WebKit::WebBindings;
19 using WebKit::WebFrame;
20 using WebKit::WebRange;
21 using WebKit::WebRect;
22 using WebKit::WebString;
23 using WebKit::WebVector;
24
25 TestShell* TextInputController::shell_ = NULL;
26
27 TextInputController::TextInputController(TestShell* shell) {
28 // Set static shell_ variable. Be careful not to assign shell_ to new
29 // windows which are temporary.
30 if (NULL == shell_)
31 shell_ = shell;
32
33 BindMethod("insertText", &TextInputController::insertText);
34 BindMethod("doCommand", &TextInputController::doCommand);
35 BindMethod("setMarkedText", &TextInputController::setMarkedText);
36 BindMethod("unmarkText", &TextInputController::unmarkText);
37 BindMethod("hasMarkedText", &TextInputController::hasMarkedText);
38 BindMethod("conversationIdentifier", &TextInputController::conversationIdentif ier);
39 BindMethod("substringFromRange", &TextInputController::substringFromRange);
40 BindMethod("attributedSubstringFromRange", &TextInputController::attributedSub stringFromRange);
41 BindMethod("markedRange", &TextInputController::markedRange);
42 BindMethod("selectedRange", &TextInputController::selectedRange);
43 BindMethod("firstRectForCharacterRange", &TextInputController::firstRectForCha racterRange);
44 BindMethod("characterIndexForPoint", &TextInputController::characterIndexForPo int);
45 BindMethod("validAttributesForMarkedText", &TextInputController::validAttribut esForMarkedText);
46 BindMethod("makeAttributedString", &TextInputController::makeAttributedString) ;
47 }
48
49 // static
50 WebFrame* TextInputController::GetMainFrame() {
51 return shell_->webView()->mainFrame();
52 }
53
54 void TextInputController::insertText(
55 const CppArgumentList& args, CppVariant* result) {
56 result->SetNull();
57
58 WebFrame* main_frame = GetMainFrame();
59 if (!main_frame)
60 return;
61
62 if (args.size() >= 1 && args[0].isString()) {
63 if (main_frame->hasMarkedText()) {
64 main_frame->unmarkText();
65 main_frame->replaceSelection(WebString());
66 }
67 main_frame->insertText(WebString::fromUTF8(args[0].ToString()));
68 }
69 }
70
71 void TextInputController::doCommand(
72 const CppArgumentList& args, CppVariant* result) {
73 result->SetNull();
74
75 WebFrame* main_frame = GetMainFrame();
76 if (!main_frame)
77 return;
78
79 if (args.size() >= 1 && args[0].isString())
80 main_frame->executeCommand(WebString::fromUTF8(args[0].ToString()));
81 }
82
83 void TextInputController::setMarkedText(
84 const CppArgumentList& args, CppVariant* result) {
85 result->SetNull();
86
87 WebFrame* main_frame = GetMainFrame();
88 if (!main_frame)
89 return;
90
91 if (args.size() >= 3 && args[0].isString()
92 && args[1].isNumber() && args[2].isNumber()) {
93 main_frame->setMarkedText(WebString::fromUTF8(args[0].ToString()),
94 args[1].ToInt32(),
95 args[2].ToInt32());
96 }
97 }
98
99 void TextInputController::unmarkText(
100 const CppArgumentList& args, CppVariant* result) {
101 result->SetNull();
102
103 WebFrame* main_frame = GetMainFrame();
104 if (!main_frame)
105 return;
106
107 main_frame->unmarkText();
108 }
109
110 void TextInputController::hasMarkedText(
111 const CppArgumentList& args, CppVariant* result) {
112 result->SetNull();
113
114 WebFrame* main_frame = GetMainFrame();
115 if (!main_frame)
116 return;
117
118 result->Set(main_frame->hasMarkedText());
119 }
120
121 void TextInputController::conversationIdentifier(
122 const CppArgumentList& args, CppVariant* result) {
123 NOTIMPLEMENTED();
124 result->SetNull();
125 }
126
127 void TextInputController::substringFromRange(
128 const CppArgumentList& args, CppVariant* result) {
129 NOTIMPLEMENTED();
130 result->SetNull();
131 }
132
133 void TextInputController::attributedSubstringFromRange(
134 const CppArgumentList& args, CppVariant* result) {
135 NOTIMPLEMENTED();
136 result->SetNull();
137 }
138
139 void TextInputController::markedRange(
140 const CppArgumentList& args, CppVariant* result) {
141 result->SetNull();
142
143 WebFrame* main_frame = GetMainFrame();
144 if (!main_frame)
145 return;
146
147 WebRange range = main_frame->markedRange();
148
149 std::string range_str;
150 base::SStringPrintf(&range_str, "%d,%d", range.startOffset(),
151 range.endOffset());
152 result->Set(range_str);
153 }
154
155 void TextInputController::selectedRange(
156 const CppArgumentList& args, CppVariant* result) {
157 result->SetNull();
158
159 WebFrame* main_frame = GetMainFrame();
160 if (!main_frame)
161 return;
162
163 WebRange range = main_frame->selectionRange();
164
165 std::string range_str;
166 base::SStringPrintf(&range_str, "%d,%d", range.startOffset(),
167 range.endOffset());
168 result->Set(range_str);
169 }
170
171 void TextInputController::firstRectForCharacterRange(
172 const CppArgumentList& args, CppVariant* result) {
173 result->SetNull();
174
175 WebFrame* main_frame = GetMainFrame();
176 if (!main_frame)
177 return;
178
179 if (args.size() < 2 || !args[0].isNumber() || !args[1].isNumber())
180 return;
181
182 WebRect rect;
183 if (!main_frame->firstRectForCharacterRange(
184 args[0].ToInt32(), args[1].ToInt32(), rect))
185 return;
186
187 WebVector<int> intArray(static_cast<size_t>(4));
188 intArray[0] = rect.x;
189 intArray[1] = rect.y;
190 intArray[2] = rect.width;
191 intArray[3] = rect.height;
192 result->Set(WebBindings::makeIntArray(intArray));
193 }
194
195 void TextInputController::characterIndexForPoint(
196 const CppArgumentList& args, CppVariant* result) {
197 NOTIMPLEMENTED();
198 result->SetNull();
199 }
200
201 void TextInputController::validAttributesForMarkedText(
202 const CppArgumentList& args, CppVariant* result) {
203 result->SetNull();
204
205 WebFrame* main_frame = GetMainFrame();
206 if (!main_frame)
207 return;
208
209 result->Set("NSUnderline,NSUnderlineColor,NSMarkedClauseSegment,"
210 "NSTextInputReplacementRangeAttributeName");
211 }
212
213 void TextInputController::makeAttributedString(
214 const CppArgumentList& args, CppVariant* result) {
215 NOTIMPLEMENTED();
216 result->SetNull();
217 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/text_input_controller.h ('k') | webkit/tools/test_shell/text_input_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698