| 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/web_ax_object_proxy.h" | 5 #include "components/test_runner/web_ax_object_proxy.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "gin/handle.h" | 8 #include "gin/handle.h" |
| 9 #include "third_party/WebKit/public/platform/WebPoint.h" | 9 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 10 #include "third_party/WebKit/public/platform/WebRect.h" | 10 #include "third_party/WebKit/public/platform/WebRect.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 308 } |
| 309 | 309 |
| 310 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object, | 310 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object, |
| 311 int characterIndex) { | 311 int characterIndex) { |
| 312 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText); | 312 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText); |
| 313 int end = 0; | 313 int end = 0; |
| 314 for (unsigned i = 0; i < object.childCount(); i++) { | 314 for (unsigned i = 0; i < object.childCount(); i++) { |
| 315 blink::WebAXObject inline_text_box = object.childAt(i); | 315 blink::WebAXObject inline_text_box = object.childAt(i); |
| 316 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); | 316 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); |
| 317 int start = end; | 317 int start = end; |
| 318 end += inline_text_box.stringValue().length(); | 318 blink::WebAXNameFrom nameFrom; |
| 319 blink::WebVector<blink::WebAXObject> nameObjects; |
| 320 blink::WebString name = inline_text_box.name(nameFrom, nameObjects); |
| 321 end += name.length(); |
| 319 if (characterIndex < start || characterIndex >= end) | 322 if (characterIndex < start || characterIndex >= end) |
| 320 continue; | 323 continue; |
| 321 blink::WebRect inline_text_box_rect = inline_text_box.boundingBoxRect(); | 324 blink::WebRect inline_text_box_rect = inline_text_box.boundingBoxRect(); |
| 322 int localIndex = characterIndex - start; | 325 int localIndex = characterIndex - start; |
| 323 blink::WebVector<int> character_offsets; | 326 blink::WebVector<int> character_offsets; |
| 324 inline_text_box.characterOffsets(character_offsets); | 327 inline_text_box.characterOffsets(character_offsets); |
| 325 DCHECK(character_offsets.size() > 0 && | 328 DCHECK(character_offsets.size() > 0 && |
| 326 character_offsets.size() == inline_text_box.stringValue().length()); | 329 character_offsets.size() == name.length()); |
| 327 switch (inline_text_box.textDirection()) { | 330 switch (inline_text_box.textDirection()) { |
| 328 case blink::WebAXTextDirectionLR: { | 331 case blink::WebAXTextDirectionLR: { |
| 329 if (localIndex) { | 332 if (localIndex) { |
| 330 int left = inline_text_box_rect.x + character_offsets[localIndex - 1]; | 333 int left = inline_text_box_rect.x + character_offsets[localIndex - 1]; |
| 331 int width = character_offsets[localIndex] - | 334 int width = character_offsets[localIndex] - |
| 332 character_offsets[localIndex - 1]; | 335 character_offsets[localIndex - 1]; |
| 333 return blink::WebRect(left, inline_text_box_rect.y, | 336 return blink::WebRect(left, inline_text_box_rect.y, |
| 334 width, inline_text_box_rect.height); | 337 width, inline_text_box_rect.height); |
| 335 } | 338 } |
| 336 return blink::WebRect( | 339 return blink::WebRect( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 389 |
| 387 void GetBoundariesForOneWord(const blink::WebAXObject& object, | 390 void GetBoundariesForOneWord(const blink::WebAXObject& object, |
| 388 int character_index, | 391 int character_index, |
| 389 int& word_start, | 392 int& word_start, |
| 390 int& word_end) { | 393 int& word_end) { |
| 391 int end = 0; | 394 int end = 0; |
| 392 for (unsigned i = 0; i < object.childCount(); i++) { | 395 for (unsigned i = 0; i < object.childCount(); i++) { |
| 393 blink::WebAXObject inline_text_box = object.childAt(i); | 396 blink::WebAXObject inline_text_box = object.childAt(i); |
| 394 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); | 397 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); |
| 395 int start = end; | 398 int start = end; |
| 396 end += inline_text_box.stringValue().length(); | 399 blink::WebAXNameFrom nameFrom; |
| 400 blink::WebVector<blink::WebAXObject> nameObjects; |
| 401 blink::WebString name = inline_text_box.name(nameFrom, nameObjects); |
| 402 end += name.length(); |
| 397 if (end <= character_index) | 403 if (end <= character_index) |
| 398 continue; | 404 continue; |
| 399 int localIndex = character_index - start; | 405 int localIndex = character_index - start; |
| 400 | 406 |
| 401 blink::WebVector<int> starts; | 407 blink::WebVector<int> starts; |
| 402 blink::WebVector<int> ends; | 408 blink::WebVector<int> ends; |
| 403 inline_text_box.wordBoundaries(starts, ends); | 409 inline_text_box.wordBoundaries(starts, ends); |
| 404 size_t word_count = starts.size(); | 410 size_t word_count = starts.size(); |
| 405 DCHECK_EQ(ends.size(), word_count); | 411 DCHECK_EQ(ends.size(), word_count); |
| 406 | 412 |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 v8::Local<v8::Value> value_handle = gin::CreateHandle( | 1481 v8::Local<v8::Value> value_handle = gin::CreateHandle( |
| 1476 isolate, new WebAXObjectProxy(object, this)).ToV8(); | 1482 isolate, new WebAXObjectProxy(object, this)).ToV8(); |
| 1477 if (value_handle.IsEmpty()) | 1483 if (value_handle.IsEmpty()) |
| 1478 return v8::Local<v8::Object>(); | 1484 return v8::Local<v8::Object>(); |
| 1479 v8::Local<v8::Object> handle = value_handle->ToObject(isolate); | 1485 v8::Local<v8::Object> handle = value_handle->ToObject(isolate); |
| 1480 elements_.Append(handle); | 1486 elements_.Append(handle); |
| 1481 return handle; | 1487 return handle; |
| 1482 } | 1488 } |
| 1483 | 1489 |
| 1484 } // namespace test_runner | 1490 } // namespace test_runner |
| OLD | NEW |