Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/test_runner/text_input_controller.h" | 5 #include "components/test_runner/text_input_controller.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "components/test_runner/web_test_proxy.h" | 8 #include "components/test_runner/web_test_proxy.h" |
| 9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
| 10 #include "gin/handle.h" | 10 #include "gin/handle.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 | 159 |
| 160 void TextInputController::InsertText(const std::string& text) { | 160 void TextInputController::InsertText(const std::string& text) { |
| 161 view()->confirmComposition(blink::WebString::fromUTF8(text)); | 161 view()->confirmComposition(blink::WebString::fromUTF8(text)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void TextInputController::UnmarkText() { | 164 void TextInputController::UnmarkText() { |
| 165 view()->confirmComposition(); | 165 view()->confirmComposition(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void TextInputController::DoCommand(const std::string& text) { | 168 void TextInputController::DoCommand(const std::string& text) { |
| 169 if (view()->mainFrame()) | 169 if (view()->mainFrame()) { |
| 170 view()->mainFrame()->executeCommand(blink::WebString::fromUTF8(text)); | 170 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 171 CHECK(false) << "This function cannot be called if the main frame is not" | |
| 172 "a local frame."; | |
| 173 } | |
| 174 view()->mainFrame()->toWebLocalFrame()->executeCommand( | |
| 175 blink::WebString::fromUTF8(text)); | |
| 176 } | |
| 171 } | 177 } |
| 172 | 178 |
| 173 void TextInputController::SetMarkedText(const std::string& text, | 179 void TextInputController::SetMarkedText(const std::string& text, |
| 174 int start, | 180 int start, |
| 175 int length) { | 181 int length) { |
| 176 blink::WebString web_text(blink::WebString::fromUTF8(text)); | 182 blink::WebString web_text(blink::WebString::fromUTF8(text)); |
| 177 | 183 |
| 178 // Split underline into up to 3 elements (before, selection, and after). | 184 // Split underline into up to 3 elements (before, selection, and after). |
| 179 std::vector<blink::WebCompositionUnderline> underlines; | 185 std::vector<blink::WebCompositionUnderline> underlines; |
| 180 blink::WebCompositionUnderline underline; | 186 blink::WebCompositionUnderline underline; |
| 181 if (!start) { | 187 if (!start) { |
| 182 underline.endOffset = length; | 188 underline.endOffset = length; |
| 183 } else { | 189 } else { |
| 184 underline.endOffset = start; | 190 underline.endOffset = start; |
| 185 underlines.push_back(underline); | 191 underlines.push_back(underline); |
| 186 underline.startOffset = start; | 192 underline.startOffset = start; |
| 187 underline.endOffset = start + length; | 193 underline.endOffset = start + length; |
| 188 } | 194 } |
| 189 underline.thick = true; | 195 underline.thick = true; |
| 190 underlines.push_back(underline); | 196 underlines.push_back(underline); |
| 191 if (start + length < static_cast<int>(web_text.length())) { | 197 if (start + length < static_cast<int>(web_text.length())) { |
| 192 underline.startOffset = underline.endOffset; | 198 underline.startOffset = underline.endOffset; |
| 193 underline.endOffset = web_text.length(); | 199 underline.endOffset = web_text.length(); |
| 194 underline.thick = false; | 200 underline.thick = false; |
| 195 underlines.push_back(underline); | 201 underlines.push_back(underline); |
| 196 } | 202 } |
| 197 | 203 |
| 198 view()->setComposition(web_text, underlines, start, start + length); | 204 view()->setComposition(web_text, underlines, start, start + length); |
| 199 } | 205 } |
| 200 | 206 |
|
yabinh
2016/07/08 02:42:53
I think we don't need to CHECK here, because if it
dcheng
2016/07/08 03:31:09
Right, but fundamentally, we shouldn't be calling
yabinh
2016/07/08 04:22:54
OK. It's been added to the latest patch. Please ta
| |
| 201 bool TextInputController::HasMarkedText() { | 207 bool TextInputController::HasMarkedText() { |
| 202 return view()->mainFrame() && view()->mainFrame()->hasMarkedText(); | 208 return view()->mainFrame() && view()->mainFrame()->isWebLocalFrame() && |
| 209 view()->mainFrame()->toWebLocalFrame()->hasMarkedText(); | |
| 203 } | 210 } |
| 204 | 211 |
| 205 std::vector<int> TextInputController::MarkedRange() { | 212 std::vector<int> TextInputController::MarkedRange() { |
| 206 if (!view()->mainFrame()) | 213 if (!view()->mainFrame()) |
| 207 return std::vector<int>(); | 214 return std::vector<int>(); |
| 208 | 215 |
| 209 blink::WebRange range = view()->mainFrame()->markedRange(); | 216 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 217 CHECK(false) << "This function cannot be called if the main frame is not" | |
| 218 "a local frame."; | |
| 219 } | |
| 220 | |
| 221 blink::WebRange range = view()->mainFrame()->toWebLocalFrame()->markedRange(); | |
| 210 std::vector<int> int_array(2); | 222 std::vector<int> int_array(2); |
| 211 int_array[0] = range.startOffset(); | 223 int_array[0] = range.startOffset(); |
| 212 int_array[1] = range.endOffset(); | 224 int_array[1] = range.endOffset(); |
| 213 | 225 |
| 214 return int_array; | 226 return int_array; |
| 215 } | 227 } |
| 216 | 228 |
| 217 std::vector<int> TextInputController::SelectedRange() { | 229 std::vector<int> TextInputController::SelectedRange() { |
| 218 if (!view()->mainFrame()) | 230 if (!view()->mainFrame()) |
| 219 return std::vector<int>(); | 231 return std::vector<int>(); |
| 220 | 232 |
| 221 blink::WebRange range = view()->mainFrame()->selectionRange(); | 233 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 234 CHECK(false) << "This function cannot be called if the main frame is not" | |
| 235 "a local frame."; | |
| 236 } | |
| 237 | |
| 238 blink::WebRange range = | |
| 239 view()->mainFrame()->toWebLocalFrame()->selectionRange(); | |
| 222 if (range.isNull()) | 240 if (range.isNull()) |
| 223 return std::vector<int>(); | 241 return std::vector<int>(); |
| 224 std::vector<int> int_array(2); | 242 std::vector<int> int_array(2); |
| 225 int_array[0] = range.startOffset(); | 243 int_array[0] = range.startOffset(); |
| 226 int_array[1] = range.endOffset(); | 244 int_array[1] = range.endOffset(); |
| 227 | 245 |
| 228 return int_array; | 246 return int_array; |
| 229 } | 247 } |
| 230 | 248 |
| 231 std::vector<int> TextInputController::FirstRectForCharacterRange( | 249 std::vector<int> TextInputController::FirstRectForCharacterRange( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 blink::WebString::fromUTF8(text), | 282 blink::WebString::fromUTF8(text), |
| 265 blink::WebVector<blink::WebCompositionUnderline>(underlines), | 283 blink::WebVector<blink::WebCompositionUnderline>(underlines), |
| 266 text.length(), text.length()); | 284 text.length(), text.length()); |
| 267 } | 285 } |
| 268 | 286 |
| 269 blink::WebView* TextInputController::view() { | 287 blink::WebView* TextInputController::view() { |
| 270 return web_test_proxy_base_->web_view(); | 288 return web_test_proxy_base_->web_view(); |
| 271 } | 289 } |
| 272 | 290 |
| 273 } // namespace test_runner | 291 } // namespace test_runner |
| OLD | NEW |