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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 return GetData().GetHtmlAttribute(html_attr, value); | 735 return GetData().GetHtmlAttribute(html_attr, value); |
736 } | 736 } |
737 | 737 |
738 bool BrowserAccessibility::GetHtmlAttribute( | 738 bool BrowserAccessibility::GetHtmlAttribute( |
739 const char* html_attr, base::string16* value) const { | 739 const char* html_attr, base::string16* value) const { |
740 return GetData().GetHtmlAttribute(html_attr, value); | 740 return GetData().GetHtmlAttribute(html_attr, value); |
741 } | 741 } |
742 | 742 |
743 BrowserAccessibility* BrowserAccessibility::GetTable() const { | 743 BrowserAccessibility* BrowserAccessibility::GetTable() const { |
744 BrowserAccessibility* table = const_cast<BrowserAccessibility*>(this); | 744 BrowserAccessibility* table = const_cast<BrowserAccessibility*>(this); |
745 while (table && !table->IsTableLikeRole()) | 745 while (table && !ui::IsTableLikeRole(table->GetRole())) |
746 table = table->PlatformGetParent(); | 746 table = table->PlatformGetParent(); |
747 return table; | 747 return table; |
748 } | 748 } |
749 | 749 |
750 BrowserAccessibility* BrowserAccessibility::GetTableCell(int index) const { | 750 BrowserAccessibility* BrowserAccessibility::GetTableCell(int index) const { |
751 if (!IsTableLikeRole() && !IsCellOrTableHeaderRole()) | 751 if (!ui::IsTableLikeRole(GetRole()) && |
| 752 !ui::IsCellOrTableHeaderRole(GetRole())) |
752 return nullptr; | 753 return nullptr; |
753 | 754 |
754 BrowserAccessibility* table = GetTable(); | 755 BrowserAccessibility* table = GetTable(); |
755 if (!table) | 756 if (!table) |
756 return nullptr; | 757 return nullptr; |
757 const std::vector<int32_t>& unique_cell_ids = | 758 const std::vector<int32_t>& unique_cell_ids = |
758 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | 759 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); |
759 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size())) | 760 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size())) |
760 return nullptr; | 761 return nullptr; |
761 return table->manager_->GetFromID(unique_cell_ids[index]); | 762 return table->manager_->GetFromID(unique_cell_ids[index]); |
762 } | 763 } |
763 | 764 |
764 BrowserAccessibility* BrowserAccessibility::GetTableCell(int row, | 765 BrowserAccessibility* BrowserAccessibility::GetTableCell(int row, |
765 int column) const { | 766 int column) const { |
766 if (!IsTableLikeRole() && !IsCellOrTableHeaderRole()) | 767 if (!ui::IsTableLikeRole(GetRole()) && |
| 768 !ui::IsCellOrTableHeaderRole(GetRole())) |
767 return nullptr; | 769 return nullptr; |
768 if (row < 0 || row >= GetTableRowCount() || column < 0 || | 770 if (row < 0 || row >= GetTableRowCount() || column < 0 || |
769 column >= GetTableColumnCount()) { | 771 column >= GetTableColumnCount()) { |
770 return nullptr; | 772 return nullptr; |
771 } | 773 } |
772 | 774 |
773 BrowserAccessibility* table = GetTable(); | 775 BrowserAccessibility* table = GetTable(); |
774 if (!table) | 776 if (!table) |
775 return nullptr; | 777 return nullptr; |
776 | 778 |
777 // In contrast to unique cell IDs, these are duplicated whenever a cell spans | 779 // In contrast to unique cell IDs, these are duplicated whenever a cell spans |
778 // multiple columns or rows. | 780 // multiple columns or rows. |
779 const std::vector<int32_t>& cell_ids = | 781 const std::vector<int32_t>& cell_ids = |
780 table->GetIntListAttribute(ui::AX_ATTR_CELL_IDS); | 782 table->GetIntListAttribute(ui::AX_ATTR_CELL_IDS); |
781 DCHECK_EQ(GetTableRowCount() * GetTableColumnCount(), | 783 DCHECK_EQ(GetTableRowCount() * GetTableColumnCount(), |
782 static_cast<int>(cell_ids.size())); | 784 static_cast<int>(cell_ids.size())); |
783 int position = row * GetTableColumnCount() + column; | 785 int position = row * GetTableColumnCount() + column; |
784 if (position < 0 || position >= static_cast<int>(cell_ids.size())) | 786 if (position < 0 || position >= static_cast<int>(cell_ids.size())) |
785 return nullptr; | 787 return nullptr; |
786 return table->manager_->GetFromID(cell_ids[position]); | 788 return table->manager_->GetFromID(cell_ids[position]); |
787 } | 789 } |
788 | 790 |
789 int BrowserAccessibility::GetTableCellIndex() const { | 791 int BrowserAccessibility::GetTableCellIndex() const { |
790 if (!IsCellOrTableHeaderRole()) | 792 if (!ui::IsCellOrTableHeaderRole(GetRole())) |
791 return -1; | 793 return -1; |
792 | 794 |
793 BrowserAccessibility* table = GetTable(); | 795 BrowserAccessibility* table = GetTable(); |
794 if (!table) | 796 if (!table) |
795 return -1; | 797 return -1; |
796 | 798 |
797 const std::vector<int32_t>& unique_cell_ids = | 799 const std::vector<int32_t>& unique_cell_ids = |
798 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | 800 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); |
799 auto iter = | 801 auto iter = |
800 std::find(unique_cell_ids.begin(), unique_cell_ids.end(), GetId()); | 802 std::find(unique_cell_ids.begin(), unique_cell_ids.end(), GetId()); |
801 if (iter == unique_cell_ids.end()) | 803 if (iter == unique_cell_ids.end()) |
802 return -1; | 804 return -1; |
803 | 805 |
804 return std::distance(unique_cell_ids.begin(), iter); | 806 return std::distance(unique_cell_ids.begin(), iter); |
805 } | 807 } |
806 | 808 |
807 int BrowserAccessibility::GetTableColumn() const { | 809 int BrowserAccessibility::GetTableColumn() const { |
808 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX); | 810 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX); |
809 } | 811 } |
810 | 812 |
811 int BrowserAccessibility::GetTableColumnCount() const { | 813 int BrowserAccessibility::GetTableColumnCount() const { |
812 BrowserAccessibility* table = GetTable(); | 814 BrowserAccessibility* table = GetTable(); |
813 if (!table) | 815 if (!table) |
814 return 0; | 816 return 0; |
815 | 817 |
816 return table->GetIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT); | 818 return table->GetIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT); |
817 } | 819 } |
818 | 820 |
819 int BrowserAccessibility::GetTableColumnSpan() const { | 821 int BrowserAccessibility::GetTableColumnSpan() const { |
820 if (!IsCellOrTableHeaderRole()) | 822 if (!ui::IsCellOrTableHeaderRole(GetRole())) |
821 return 0; | 823 return 0; |
822 | 824 |
823 int column_span; | 825 int column_span; |
824 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &column_span)) | 826 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN, &column_span)) |
825 return column_span; | 827 return column_span; |
826 return 1; | 828 return 1; |
827 } | 829 } |
828 | 830 |
829 int BrowserAccessibility::GetTableRow() const { | 831 int BrowserAccessibility::GetTableRow() const { |
830 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX); | 832 return GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX); |
831 } | 833 } |
832 | 834 |
833 int BrowserAccessibility::GetTableRowCount() const { | 835 int BrowserAccessibility::GetTableRowCount() const { |
834 BrowserAccessibility* table = GetTable(); | 836 BrowserAccessibility* table = GetTable(); |
835 if (!table) | 837 if (!table) |
836 return 0; | 838 return 0; |
837 | 839 |
838 return table->GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT); | 840 return table->GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT); |
839 } | 841 } |
840 | 842 |
841 int BrowserAccessibility::GetTableRowSpan() const { | 843 int BrowserAccessibility::GetTableRowSpan() const { |
842 if (!IsCellOrTableHeaderRole()) | 844 if (!ui::IsCellOrTableHeaderRole(GetRole())) |
843 return 0; | 845 return 0; |
844 | 846 |
845 int row_span; | 847 int row_span; |
846 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span)) | 848 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span)) |
847 return row_span; | 849 return row_span; |
848 return 1; | 850 return 1; |
849 } | 851 } |
850 | 852 |
851 base::string16 BrowserAccessibility::GetText() const { | 853 base::string16 BrowserAccessibility::GetText() const { |
852 return GetInnerText(); | 854 return GetInnerText(); |
853 } | 855 } |
854 | 856 |
855 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { | 857 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { |
856 return GetData().HasState(state_enum); | 858 return GetData().HasState(state_enum); |
857 } | 859 } |
858 | 860 |
859 bool BrowserAccessibility::HasAction(ui::AXAction action_enum) const { | 861 bool BrowserAccessibility::HasAction(ui::AXAction action_enum) const { |
860 return GetData().HasAction(action_enum); | 862 return GetData().HasAction(action_enum); |
861 } | 863 } |
862 | 864 |
863 bool BrowserAccessibility::IsCellOrTableHeaderRole() const { | |
864 return (GetRole() == ui::AX_ROLE_CELL || | |
865 GetRole() == ui::AX_ROLE_COLUMN_HEADER || | |
866 GetRole() == ui::AX_ROLE_ROW_HEADER); | |
867 } | |
868 | |
869 bool BrowserAccessibility::IsTableLikeRole() const { | |
870 return (GetRole() == ui::AX_ROLE_TABLE || | |
871 GetRole() == ui::AX_ROLE_GRID || | |
872 GetRole() == ui::AX_ROLE_TREE_GRID); | |
873 } | |
874 | |
875 bool BrowserAccessibility::HasCaret() const { | 865 bool BrowserAccessibility::HasCaret() const { |
876 if (IsSimpleTextControl() && HasIntAttribute(ui::AX_ATTR_TEXT_SEL_START) && | 866 if (IsSimpleTextControl() && HasIntAttribute(ui::AX_ATTR_TEXT_SEL_START) && |
877 HasIntAttribute(ui::AX_ATTR_TEXT_SEL_END)) { | 867 HasIntAttribute(ui::AX_ATTR_TEXT_SEL_END)) { |
878 return true; | 868 return true; |
879 } | 869 } |
880 | 870 |
881 // The caret is always at the focus of the selection. | 871 // The caret is always at the focus of the selection. |
882 int32_t focus_id = manager()->GetTreeData().sel_focus_object_id; | 872 int32_t focus_id = manager()->GetTreeData().sel_focus_object_id; |
883 BrowserAccessibility* focus_object = manager()->GetFromID(focus_id); | 873 BrowserAccessibility* focus_object = manager()->GetFromID(focus_id); |
884 if (!focus_object) | 874 if (!focus_object) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 | 1150 |
1161 if (data.action == ui::AX_ACTION_FOCUS) { | 1151 if (data.action == ui::AX_ACTION_FOCUS) { |
1162 manager_->SetFocus(*this); | 1152 manager_->SetFocus(*this); |
1163 return true; | 1153 return true; |
1164 } | 1154 } |
1165 | 1155 |
1166 return false; | 1156 return false; |
1167 } | 1157 } |
1168 | 1158 |
1169 } // namespace content | 1159 } // namespace content |
OLD | NEW |