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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 bool BrowserAccessibility::GetHtmlAttribute( | 739 bool BrowserAccessibility::GetHtmlAttribute( |
740 const char* html_attr, std::string* value) const { | 740 const char* html_attr, std::string* value) const { |
741 return GetData().GetHtmlAttribute(html_attr, value); | 741 return GetData().GetHtmlAttribute(html_attr, value); |
742 } | 742 } |
743 | 743 |
744 bool BrowserAccessibility::GetHtmlAttribute( | 744 bool BrowserAccessibility::GetHtmlAttribute( |
745 const char* html_attr, base::string16* value) const { | 745 const char* html_attr, base::string16* value) const { |
746 return GetData().GetHtmlAttribute(html_attr, value); | 746 return GetData().GetHtmlAttribute(html_attr, value); |
747 } | 747 } |
748 | 748 |
749 BrowserAccessibility* BrowserAccessibility::GetTable() const { | |
750 BrowserAccessibility* table = const_cast<BrowserAccessibility*>(this); | |
751 while (table && !ui::IsTableLikeRole(table->GetRole())) | |
752 table = table->PlatformGetParent(); | |
753 return table; | |
754 } | |
755 | |
756 BrowserAccessibility* BrowserAccessibility::GetTableCell(int index) const { | |
757 if (!ui::IsTableLikeRole(GetRole()) && | |
758 !ui::IsCellOrTableHeaderRole(GetRole())) | |
759 return nullptr; | |
760 | |
761 BrowserAccessibility* table = GetTable(); | |
762 if (!table) | |
763 return nullptr; | |
764 const std::vector<int32_t>& unique_cell_ids = | |
765 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | |
766 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size())) | |
767 return nullptr; | |
768 return table->manager_->GetFromID(unique_cell_ids[index]); | |
769 } | |
770 | |
771 BrowserAccessibility* BrowserAccessibility::GetTableCell(int row, | |
772 int column) const { | |
773 if (!ui::IsTableLikeRole(GetRole()) && | |
774 !ui::IsCellOrTableHeaderRole(GetRole())) | |
775 return nullptr; | |
776 if (row < 0 || row >= GetTableRowCount() || column < 0 || | |
777 column >= GetTableColumnCount()) { | |
778 return nullptr; | |
779 } | |
780 | |
781 BrowserAccessibility* table = GetTable(); | |
782 if (!table) | |
783 return nullptr; | |
784 | |
785 // In contrast to unique cell IDs, these are duplicated whenever a cell spans | |
786 // multiple columns or rows. | |
787 const std::vector<int32_t>& cell_ids = | |
788 table->GetIntListAttribute(ui::AX_ATTR_CELL_IDS); | |
789 DCHECK_EQ(GetTableRowCount() * GetTableColumnCount(), | |
790 static_cast<int>(cell_ids.size())); | |
791 int position = row * GetTableColumnCount() + column; | |
792 if (position < 0 || position >= static_cast<int>(cell_ids.size())) | |
793 return nullptr; | |
794 return table->manager_->GetFromID(cell_ids[position]); | |
795 } | |
796 | |
797 int BrowserAccessibility::GetTableCellIndex() const { | |
798 if (!ui::IsCellOrTableHeaderRole(GetRole())) | |
799 return -1; | |
800 | |
801 BrowserAccessibility* table = GetTable(); | |
802 if (!table) | |
803 return -1; | |
804 | |
805 const std::vector<int32_t>& unique_cell_ids = | |
806 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | |
807 auto iter = | |
808 std::find(unique_cell_ids.begin(), unique_cell_ids.end(), GetId()); | |
809 if (iter == unique_cell_ids.end()) | |
810 return -1; | |
811 | |
812 return std::distance(unique_cell_ids.begin(), iter); | |
813 } | |
814 | |
815 int BrowserAccessibility::GetTableColumn() const { | |
816 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX); | |
817 } | |
818 | |
819 int BrowserAccessibility::GetTableColumnCount() const { | |
820 BrowserAccessibility* table = GetTable(); | |
821 if (!table) | |
822 return 0; | |
823 | |
824 return table->GetIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT); | |
825 } | |
826 | |
827 int BrowserAccessibility::GetTableColumnSpan() const { | |
828 if (!ui::IsCellOrTableHeaderRole(GetRole())) | |
829 return 0; | |
830 | |
831 int column_span; | |
832 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &column_span)) | |
833 return column_span; | |
834 return 1; | |
835 } | |
836 | |
837 int BrowserAccessibility::GetTableRow() const { | |
838 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX); | |
839 } | |
840 | |
841 int BrowserAccessibility::GetTableRowCount() const { | |
842 BrowserAccessibility* table = GetTable(); | |
843 if (!table) | |
844 return 0; | |
845 | |
846 return table->GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT); | |
847 } | |
848 | |
849 int BrowserAccessibility::GetTableRowSpan() const { | |
850 if (!ui::IsCellOrTableHeaderRole(GetRole())) | |
851 return 0; | |
852 | |
853 int row_span; | |
854 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span)) | |
855 return row_span; | |
856 return 1; | |
857 } | |
858 | |
859 base::string16 BrowserAccessibility::GetText() const { | 749 base::string16 BrowserAccessibility::GetText() const { |
860 return GetInnerText(); | 750 return GetInnerText(); |
861 } | 751 } |
862 | 752 |
863 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { | 753 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { |
864 return GetData().HasState(state_enum); | 754 return GetData().HasState(state_enum); |
865 } | 755 } |
866 | 756 |
867 bool BrowserAccessibility::HasAction(ui::AXAction action_enum) const { | 757 bool BrowserAccessibility::HasAction(ui::AXAction action_enum) const { |
868 return GetData().HasAction(action_enum); | 758 return GetData().HasAction(action_enum); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 } | 988 } |
1099 | 989 |
1100 gfx::NativeViewAccessible BrowserAccessibility::GetFocus() { | 990 gfx::NativeViewAccessible BrowserAccessibility::GetFocus() { |
1101 auto* focused = manager()->GetFocus(); | 991 auto* focused = manager()->GetFocus(); |
1102 if (!focused) | 992 if (!focused) |
1103 return nullptr; | 993 return nullptr; |
1104 | 994 |
1105 return focused->GetNativeViewAccessible(); | 995 return focused->GetNativeViewAccessible(); |
1106 } | 996 } |
1107 | 997 |
| 998 ui::AXPlatformNode* BrowserAccessibility::GetFromNodeID(int32_t id) { |
| 999 // Not all BrowserAccessibility subclasses can return an AXPlatformNode yet. |
| 1000 // So, here we just return nullptr. |
| 1001 return nullptr; |
| 1002 } |
| 1003 |
1108 gfx::AcceleratedWidget | 1004 gfx::AcceleratedWidget |
1109 BrowserAccessibility::GetTargetForNativeAccessibilityEvent() { | 1005 BrowserAccessibility::GetTargetForNativeAccessibilityEvent() { |
1110 BrowserAccessibilityDelegate* root_delegate = | 1006 BrowserAccessibilityDelegate* root_delegate = |
1111 manager()->GetDelegateFromRootManager(); | 1007 manager()->GetDelegateFromRootManager(); |
1112 if (!root_delegate) | 1008 if (!root_delegate) |
1113 return gfx::kNullAcceleratedWidget; | 1009 return gfx::kNullAcceleratedWidget; |
1114 return root_delegate->AccessibilityGetAcceleratedWidget(); | 1010 return root_delegate->AccessibilityGetAcceleratedWidget(); |
1115 } | 1011 } |
1116 | 1012 |
1117 bool BrowserAccessibility::AccessibilityPerformAction( | 1013 bool BrowserAccessibility::AccessibilityPerformAction( |
(...skipping 11 matching lines...) Expand all Loading... |
1129 return false; | 1025 return false; |
1130 } | 1026 } |
1131 | 1027 |
1132 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { | 1028 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { |
1133 BrowserAccessibilityStateImpl* accessibility_state = | 1029 BrowserAccessibilityStateImpl* accessibility_state = |
1134 BrowserAccessibilityStateImpl::GetInstance(); | 1030 BrowserAccessibilityStateImpl::GetInstance(); |
1135 return accessibility_state->disable_hot_tracking_for_testing(); | 1031 return accessibility_state->disable_hot_tracking_for_testing(); |
1136 } | 1032 } |
1137 | 1033 |
1138 } // namespace content | 1034 } // namespace content |
OLD | NEW |