| 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.h" | 5 #include "content/browser/accessibility/browser_accessibility.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 bool BrowserAccessibility::GetHtmlAttribute( | 734 bool BrowserAccessibility::GetHtmlAttribute( |
| 735 const char* html_attr, std::string* value) const { | 735 const char* html_attr, std::string* value) const { |
| 736 return GetData().GetHtmlAttribute(html_attr, value); | 736 return GetData().GetHtmlAttribute(html_attr, value); |
| 737 } | 737 } |
| 738 | 738 |
| 739 bool BrowserAccessibility::GetHtmlAttribute( | 739 bool BrowserAccessibility::GetHtmlAttribute( |
| 740 const char* html_attr, base::string16* value) const { | 740 const char* html_attr, base::string16* value) const { |
| 741 return GetData().GetHtmlAttribute(html_attr, value); | 741 return GetData().GetHtmlAttribute(html_attr, value); |
| 742 } | 742 } |
| 743 | 743 |
| 744 BrowserAccessibility* BrowserAccessibility::GetTable() const { | |
| 745 BrowserAccessibility* table = const_cast<BrowserAccessibility*>(this); | |
| 746 while (table && !ui::IsTableLikeRole(table->GetRole())) | |
| 747 table = table->PlatformGetParent(); | |
| 748 return table; | |
| 749 } | |
| 750 | |
| 751 BrowserAccessibility* BrowserAccessibility::GetTableCell(int index) const { | |
| 752 if (!ui::IsTableLikeRole(GetRole()) && | |
| 753 !ui::IsCellOrTableHeaderRole(GetRole())) | |
| 754 return nullptr; | |
| 755 | |
| 756 BrowserAccessibility* table = GetTable(); | |
| 757 if (!table) | |
| 758 return nullptr; | |
| 759 const std::vector<int32_t>& unique_cell_ids = | |
| 760 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | |
| 761 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size())) | |
| 762 return nullptr; | |
| 763 return table->manager_->GetFromID(unique_cell_ids[index]); | |
| 764 } | |
| 765 | |
| 766 BrowserAccessibility* BrowserAccessibility::GetTableCell(int row, | |
| 767 int column) const { | |
| 768 if (!ui::IsTableLikeRole(GetRole()) && | |
| 769 !ui::IsCellOrTableHeaderRole(GetRole())) | |
| 770 return nullptr; | |
| 771 if (row < 0 || row >= GetTableRowCount() || column < 0 || | |
| 772 column >= GetTableColumnCount()) { | |
| 773 return nullptr; | |
| 774 } | |
| 775 | |
| 776 BrowserAccessibility* table = GetTable(); | |
| 777 if (!table) | |
| 778 return nullptr; | |
| 779 | |
| 780 // In contrast to unique cell IDs, these are duplicated whenever a cell spans | |
| 781 // multiple columns or rows. | |
| 782 const std::vector<int32_t>& cell_ids = | |
| 783 table->GetIntListAttribute(ui::AX_ATTR_CELL_IDS); | |
| 784 DCHECK_EQ(GetTableRowCount() * GetTableColumnCount(), | |
| 785 static_cast<int>(cell_ids.size())); | |
| 786 int position = row * GetTableColumnCount() + column; | |
| 787 if (position < 0 || position >= static_cast<int>(cell_ids.size())) | |
| 788 return nullptr; | |
| 789 return table->manager_->GetFromID(cell_ids[position]); | |
| 790 } | |
| 791 | |
| 792 int BrowserAccessibility::GetTableCellIndex() const { | |
| 793 if (!ui::IsCellOrTableHeaderRole(GetRole())) | |
| 794 return -1; | |
| 795 | |
| 796 BrowserAccessibility* table = GetTable(); | |
| 797 if (!table) | |
| 798 return -1; | |
| 799 | |
| 800 const std::vector<int32_t>& unique_cell_ids = | |
| 801 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | |
| 802 auto iter = | |
| 803 std::find(unique_cell_ids.begin(), unique_cell_ids.end(), GetId()); | |
| 804 if (iter == unique_cell_ids.end()) | |
| 805 return -1; | |
| 806 | |
| 807 return std::distance(unique_cell_ids.begin(), iter); | |
| 808 } | |
| 809 | |
| 810 int BrowserAccessibility::GetTableColumn() const { | |
| 811 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX); | |
| 812 } | |
| 813 | |
| 814 int BrowserAccessibility::GetTableColumnCount() const { | |
| 815 BrowserAccessibility* table = GetTable(); | |
| 816 if (!table) | |
| 817 return 0; | |
| 818 | |
| 819 return table->GetIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT); | |
| 820 } | |
| 821 | |
| 822 int BrowserAccessibility::GetTableColumnSpan() const { | |
| 823 if (!ui::IsCellOrTableHeaderRole(GetRole())) | |
| 824 return 0; | |
| 825 | |
| 826 int column_span; | |
| 827 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &column_span)) | |
| 828 return column_span; | |
| 829 return 1; | |
| 830 } | |
| 831 | |
| 832 int BrowserAccessibility::GetTableRow() const { | |
| 833 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX); | |
| 834 } | |
| 835 | |
| 836 int BrowserAccessibility::GetTableRowCount() const { | |
| 837 BrowserAccessibility* table = GetTable(); | |
| 838 if (!table) | |
| 839 return 0; | |
| 840 | |
| 841 return table->GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT); | |
| 842 } | |
| 843 | |
| 844 int BrowserAccessibility::GetTableRowSpan() const { | |
| 845 if (!ui::IsCellOrTableHeaderRole(GetRole())) | |
| 846 return 0; | |
| 847 | |
| 848 int row_span; | |
| 849 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span)) | |
| 850 return row_span; | |
| 851 return 1; | |
| 852 } | |
| 853 | |
| 854 base::string16 BrowserAccessibility::GetText() const { | 744 base::string16 BrowserAccessibility::GetText() const { |
| 855 return GetInnerText(); | 745 return GetInnerText(); |
| 856 } | 746 } |
| 857 | 747 |
| 858 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { | 748 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { |
| 859 return GetData().HasState(state_enum); | 749 return GetData().HasState(state_enum); |
| 860 } | 750 } |
| 861 | 751 |
| 862 bool BrowserAccessibility::HasAction(ui::AXAction action_enum) const { | 752 bool BrowserAccessibility::HasAction(ui::AXAction action_enum) const { |
| 863 return GetData().HasAction(action_enum); | 753 return GetData().HasAction(action_enum); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 } | 1019 } |
| 1130 | 1020 |
| 1131 gfx::NativeViewAccessible BrowserAccessibility::GetFocus() { | 1021 gfx::NativeViewAccessible BrowserAccessibility::GetFocus() { |
| 1132 auto* focused = manager()->GetFocus(); | 1022 auto* focused = manager()->GetFocus(); |
| 1133 if (!focused) | 1023 if (!focused) |
| 1134 return nullptr; | 1024 return nullptr; |
| 1135 | 1025 |
| 1136 return focused->GetNativeViewAccessible(); | 1026 return focused->GetNativeViewAccessible(); |
| 1137 } | 1027 } |
| 1138 | 1028 |
| 1029 ui::AXPlatformNode* BrowserAccessibility::GetFromNodeID(int32_t id) { |
| 1030 // Not all BrowserAccessibility subclasses can return an AXPlatformNode yet. |
| 1031 // So, here we just return nullptr. |
| 1032 return nullptr; |
| 1033 } |
| 1034 |
| 1139 gfx::AcceleratedWidget | 1035 gfx::AcceleratedWidget |
| 1140 BrowserAccessibility::GetTargetForNativeAccessibilityEvent() { | 1036 BrowserAccessibility::GetTargetForNativeAccessibilityEvent() { |
| 1141 BrowserAccessibilityDelegate* root_delegate = | 1037 BrowserAccessibilityDelegate* root_delegate = |
| 1142 manager()->GetDelegateFromRootManager(); | 1038 manager()->GetDelegateFromRootManager(); |
| 1143 if (!root_delegate) | 1039 if (!root_delegate) |
| 1144 return gfx::kNullAcceleratedWidget; | 1040 return gfx::kNullAcceleratedWidget; |
| 1145 return root_delegate->AccessibilityGetAcceleratedWidget(); | 1041 return root_delegate->AccessibilityGetAcceleratedWidget(); |
| 1146 } | 1042 } |
| 1147 | 1043 |
| 1148 bool BrowserAccessibility::AccessibilityPerformAction( | 1044 bool BrowserAccessibility::AccessibilityPerformAction( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1160 return false; | 1056 return false; |
| 1161 } | 1057 } |
| 1162 | 1058 |
| 1163 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { | 1059 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { |
| 1164 BrowserAccessibilityStateImpl* accessibility_state = | 1060 BrowserAccessibilityStateImpl* accessibility_state = |
| 1165 BrowserAccessibilityStateImpl::GetInstance(); | 1061 BrowserAccessibilityStateImpl::GetInstance(); |
| 1166 return accessibility_state->disable_hot_tracking_for_testing(); | 1062 return accessibility_state->disable_hot_tracking_for_testing(); |
| 1167 } | 1063 } |
| 1168 | 1064 |
| 1169 } // namespace content | 1065 } // namespace content |
| OLD | NEW |