| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility_manager.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { | 470 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { |
| 471 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager(); | 471 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager(); |
| 472 if (delegate) | 472 if (delegate) |
| 473 return delegate->AccessibilityGetViewBounds(); | 473 return delegate->AccessibilityGetViewBounds(); |
| 474 return gfx::Rect(); | 474 return gfx::Rect(); |
| 475 } | 475 } |
| 476 | 476 |
| 477 // Static | 477 // static |
| 478 BrowserAccessibility* BrowserAccessibilityManager::NextInTreeOrder( | 478 BrowserAccessibility* BrowserAccessibilityManager::NextInTreeOrder( |
| 479 const BrowserAccessibility* object) { | 479 const BrowserAccessibility* object) { |
| 480 if (!object) | 480 if (!object) |
| 481 return nullptr; | 481 return nullptr; |
| 482 | 482 |
| 483 if (object->PlatformChildCount()) | 483 if (object->PlatformChildCount()) |
| 484 return object->PlatformGetChild(0); | 484 return object->PlatformGetChild(0); |
| 485 | 485 |
| 486 while (object) { | 486 while (object) { |
| 487 BrowserAccessibility* sibling = object->GetNextSibling(); | 487 BrowserAccessibility* sibling = object->GetNextSibling(); |
| 488 if (sibling) | 488 if (sibling) |
| 489 return sibling; | 489 return sibling; |
| 490 | 490 |
| 491 object = object->GetParent(); | 491 object = object->GetParent(); |
| 492 } | 492 } |
| 493 | 493 |
| 494 return nullptr; | 494 return nullptr; |
| 495 } | 495 } |
| 496 | 496 |
| 497 // Static | 497 // static |
| 498 BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( | 498 BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( |
| 499 const BrowserAccessibility* object) { | 499 const BrowserAccessibility* object) { |
| 500 if (!object) | 500 if (!object) |
| 501 return nullptr; | 501 return nullptr; |
| 502 | 502 |
| 503 BrowserAccessibility* sibling = object->GetPreviousSibling(); | 503 BrowserAccessibility* sibling = object->GetPreviousSibling(); |
| 504 if (!sibling) | 504 if (!sibling) |
| 505 return object->GetParent(); | 505 return object->GetParent(); |
| 506 | 506 |
| 507 if (sibling->PlatformChildCount()) | 507 if (sibling->PlatformChildCount()) |
| 508 return sibling->PlatformDeepestLastChild(); | 508 return sibling->PlatformDeepestLastChild(); |
| 509 | 509 |
| 510 return sibling; | 510 return sibling; |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Static | 513 // static |
| 514 BrowserAccessibility* BrowserAccessibilityManager::PreviousTextOnlyObject( | 514 BrowserAccessibility* BrowserAccessibilityManager::PreviousTextOnlyObject( |
| 515 const BrowserAccessibility* object) { | 515 const BrowserAccessibility* object) { |
| 516 BrowserAccessibility* previous_object = PreviousInTreeOrder(object); | 516 BrowserAccessibility* previous_object = PreviousInTreeOrder(object); |
| 517 while (previous_object && !previous_object->IsTextOnlyObject()) | 517 while (previous_object && !previous_object->IsTextOnlyObject()) |
| 518 previous_object = PreviousInTreeOrder(previous_object); | 518 previous_object = PreviousInTreeOrder(previous_object); |
| 519 | 519 |
| 520 return previous_object; | 520 return previous_object; |
| 521 } | 521 } |
| 522 | 522 |
| 523 // Static | 523 // static |
| 524 BrowserAccessibility* BrowserAccessibilityManager::NextTextOnlyObject( | 524 BrowserAccessibility* BrowserAccessibilityManager::NextTextOnlyObject( |
| 525 const BrowserAccessibility* object) { | 525 const BrowserAccessibility* object) { |
| 526 BrowserAccessibility* next_object = NextInTreeOrder(object); | 526 BrowserAccessibility* next_object = NextInTreeOrder(object); |
| 527 while (next_object && !next_object->IsTextOnlyObject()) | 527 while (next_object && !next_object->IsTextOnlyObject()) |
| 528 next_object = NextInTreeOrder(next_object); | 528 next_object = NextInTreeOrder(next_object); |
| 529 | 529 |
| 530 return next_object; | 530 return next_object; |
| 531 } | 531 } |
| 532 | 532 |
| 533 // Static | 533 // static |
| 534 bool BrowserAccessibilityManager::FindIndicesInCommonParent( | 534 bool BrowserAccessibilityManager::FindIndicesInCommonParent( |
| 535 const BrowserAccessibility& object1, | 535 const BrowserAccessibility& object1, |
| 536 const BrowserAccessibility& object2, | 536 const BrowserAccessibility& object2, |
| 537 BrowserAccessibility** common_parent, | 537 BrowserAccessibility** common_parent, |
| 538 int* child_index1, | 538 int* child_index1, |
| 539 int* child_index2) { | 539 int* child_index2) { |
| 540 DCHECK(common_parent && child_index1 && child_index2); | 540 DCHECK(common_parent && child_index1 && child_index2); |
| 541 auto ancestor1 = const_cast<BrowserAccessibility*>(&object1); | 541 auto ancestor1 = const_cast<BrowserAccessibility*>(&object1); |
| 542 auto ancestor2 = const_cast<BrowserAccessibility*>(&object2); | 542 auto ancestor2 = const_cast<BrowserAccessibility*>(&object2); |
| 543 do { | 543 do { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 557 | 557 |
| 558 do { | 558 do { |
| 559 *child_index2 = ancestor2->GetIndexInParent(); | 559 *child_index2 = ancestor2->GetIndexInParent(); |
| 560 ancestor2 = ancestor2->GetParent(); | 560 ancestor2 = ancestor2->GetParent(); |
| 561 } while (ancestor1 != ancestor2); | 561 } while (ancestor1 != ancestor2); |
| 562 | 562 |
| 563 *common_parent = ancestor1; | 563 *common_parent = ancestor1; |
| 564 return true; | 564 return true; |
| 565 } | 565 } |
| 566 | 566 |
| 567 // Static | 567 // static |
| 568 base::string16 BrowserAccessibilityManager::GetTextForRange( | 568 base::string16 BrowserAccessibilityManager::GetTextForRange( |
| 569 const BrowserAccessibility& start_object, | 569 const BrowserAccessibility& start_object, |
| 570 int start_offset, | 570 int start_offset, |
| 571 const BrowserAccessibility& end_object, | 571 const BrowserAccessibility& end_object, |
| 572 int end_offset) { | 572 int end_offset) { |
| 573 DCHECK_GE(start_offset, 0); | 573 DCHECK_GE(start_offset, 0); |
| 574 DCHECK_GE(end_offset, 0); | 574 DCHECK_GE(end_offset, 0); |
| 575 | 575 |
| 576 if (&start_object == &end_object && start_object.IsSimpleTextControl()) { |
| 577 if (start_offset > end_offset) |
| 578 std::swap(start_offset, end_offset); |
| 579 |
| 580 if (start_offset >= static_cast<int>(start_object.GetValue().length()) || |
| 581 end_offset > static_cast<int>(start_object.GetValue().length())) { |
| 582 return base::string16(); |
| 583 } |
| 584 |
| 585 return start_object.GetValue().substr(start_offset, |
| 586 end_offset - start_offset); |
| 587 } |
| 588 |
| 576 int child_index1 = -1; | 589 int child_index1 = -1; |
| 577 int child_index2 = -1; | 590 int child_index2 = -1; |
| 578 if (&start_object != &end_object) { | 591 if (&start_object != &end_object) { |
| 579 BrowserAccessibility* common_parent; | 592 BrowserAccessibility* common_parent; |
| 580 if (!FindIndicesInCommonParent(start_object, end_object, &common_parent, | 593 if (!FindIndicesInCommonParent(start_object, end_object, &common_parent, |
| 581 &child_index1, &child_index2)) { | 594 &child_index1, &child_index2)) { |
| 582 return base::string16(); | 595 return base::string16(); |
| 583 } | 596 } |
| 584 | 597 |
| 585 DCHECK(common_parent); | 598 DCHECK(common_parent); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 611 if (!start_text_object->IsTextOnlyObject()) | 624 if (!start_text_object->IsTextOnlyObject()) |
| 612 start_text_object = NextTextOnlyObject(start_text_object); | 625 start_text_object = NextTextOnlyObject(start_text_object); |
| 613 if (!end_text_object->IsTextOnlyObject()) | 626 if (!end_text_object->IsTextOnlyObject()) |
| 614 end_text_object = PreviousTextOnlyObject(end_text_object); | 627 end_text_object = PreviousTextOnlyObject(end_text_object); |
| 615 | 628 |
| 616 if (!start_text_object || !end_text_object) | 629 if (!start_text_object || !end_text_object) |
| 617 return base::string16(); | 630 return base::string16(); |
| 618 | 631 |
| 619 // Be a little permissive with the start and end offsets. | 632 // Be a little permissive with the start and end offsets. |
| 620 if (start_text_object == end_text_object) { | 633 if (start_text_object == end_text_object) { |
| 634 if (start_offset > end_offset) |
| 635 std::swap(start_offset, end_offset); |
| 636 |
| 621 if (start_offset < | 637 if (start_offset < |
| 622 static_cast<int>(start_text_object->GetText().length()) && | 638 static_cast<int>(start_text_object->GetText().length()) && |
| 623 end_offset <= static_cast<int>(end_text_object->GetText().length())) { | 639 end_offset <= static_cast<int>(end_text_object->GetText().length())) { |
| 624 if (start_offset <= end_offset) { | 640 return start_text_object->GetText().substr(start_offset, |
| 625 return start_text_object->GetText().substr(start_offset, | 641 end_offset - start_offset); |
| 626 end_offset - start_offset); | |
| 627 } else { | |
| 628 return start_text_object->GetText().substr(end_offset, | |
| 629 start_offset - end_offset); | |
| 630 } | |
| 631 } | 642 } |
| 632 return start_text_object->GetText(); | 643 return start_text_object->GetText(); |
| 633 } | 644 } |
| 634 | 645 |
| 635 base::string16 text; | 646 base::string16 text; |
| 636 if (start_offset < static_cast<int>(start_text_object->GetText().length())) | 647 if (start_offset < static_cast<int>(start_text_object->GetText().length())) |
| 637 text += start_text_object->GetText().substr(start_offset); | 648 text += start_text_object->GetText().substr(start_offset); |
| 638 else | 649 else |
| 639 text += start_text_object->GetText(); | 650 text += start_text_object->GetText(); |
| 640 start_text_object = NextTextOnlyObject(start_text_object); | 651 start_text_object = NextTextOnlyObject(start_text_object); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 tree_->CreateTreeSource()); | 749 tree_->CreateTreeSource()); |
| 739 ui::AXTreeSerializer<const ui::AXNode*, | 750 ui::AXTreeSerializer<const ui::AXNode*, |
| 740 ui::AXNodeData, | 751 ui::AXNodeData, |
| 741 ui::AXTreeData> serializer(tree_source.get()); | 752 ui::AXTreeData> serializer(tree_source.get()); |
| 742 ui::AXTreeUpdate update; | 753 ui::AXTreeUpdate update; |
| 743 serializer.SerializeChanges(tree_->root(), &update); | 754 serializer.SerializeChanges(tree_->root(), &update); |
| 744 return update; | 755 return update; |
| 745 } | 756 } |
| 746 | 757 |
| 747 } // namespace content | 758 } // namespace content |
| OLD | NEW |