Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager.cc

Issue 2207573002: Implement 3 Mac accessibility parameterized attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to enum Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 do { 711 do {
712 *child_index2 = ancestor2->GetIndexInParent(); 712 *child_index2 = ancestor2->GetIndexInParent();
713 ancestor2 = ancestor2->GetParent(); 713 ancestor2 = ancestor2->GetParent();
714 } while (ancestor1 != ancestor2); 714 } while (ancestor1 != ancestor2);
715 715
716 *common_parent = ancestor1; 716 *common_parent = ancestor1;
717 return true; 717 return true;
718 } 718 }
719 719
720 // static 720 // static
721 ui::AXTreeOrder BrowserAccessibilityManager::CompareNodes(
722 const BrowserAccessibility& object1,
723 const BrowserAccessibility& object2) {
724 if (&object1 == &object2)
725 return ui::AX_TREE_ORDER_EQUAL;
726
727 BrowserAccessibility* common_parent;
728 int child_index1;
729 int child_index2;
730 if (FindIndicesInCommonParent(
731 object1, object2, &common_parent, &child_index1, &child_index2)) {
732 if (child_index1 < child_index2)
733 return ui::AX_TREE_ORDER_BEFORE;
734 if (child_index1 > child_index2)
735 return ui::AX_TREE_ORDER_AFTER;
736 }
737
738 if (object2.IsDescendantOf(&object1))
739 return ui::AX_TREE_ORDER_BEFORE;
740 if (object1.IsDescendantOf(&object2))
741 return ui::AX_TREE_ORDER_AFTER;
742
743 return ui::AX_TREE_ORDER_UNDEFINED;
744 }
745
721 std::vector<const BrowserAccessibility*> 746 std::vector<const BrowserAccessibility*>
722 BrowserAccessibilityManager::FindTextOnlyObjectsInRange( 747 BrowserAccessibilityManager::FindTextOnlyObjectsInRange(
723 const BrowserAccessibility& start_object, 748 const BrowserAccessibility& start_object,
724 const BrowserAccessibility& end_object) { 749 const BrowserAccessibility& end_object) {
725 std::vector<const BrowserAccessibility*> text_only_objects; 750 std::vector<const BrowserAccessibility*> text_only_objects;
726 int child_index1 = -1; 751 int child_index1 = -1;
727 int child_index2 = -1; 752 int child_index2 = -1;
728 if (&start_object != &end_object) { 753 if (&start_object != &end_object) {
729 BrowserAccessibility* common_parent; 754 BrowserAccessibility* common_parent;
730 if (!FindIndicesInCommonParent(start_object, end_object, &common_parent, 755 if (!FindIndicesInCommonParent(start_object, end_object, &common_parent,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 const BrowserAccessibility* end_text_object = text_only_objects.back(); 879 const BrowserAccessibility* end_text_object = text_only_objects.back();
855 if (end_offset <= static_cast<int>(end_text_object->GetText().length())) { 880 if (end_offset <= static_cast<int>(end_text_object->GetText().length())) {
856 text += end_text_object->GetText().substr(0, end_offset); 881 text += end_text_object->GetText().substr(0, end_offset);
857 } else { 882 } else {
858 text += end_text_object->GetText(); 883 text += end_text_object->GetText();
859 } 884 }
860 885
861 return text; 886 return text;
862 } 887 }
863 888
889 // static
890 gfx::Rect BrowserAccessibilityManager::GetLocalBoundsForRange(
891 const BrowserAccessibility& start_object,
892 int start_offset,
893 const BrowserAccessibility& end_object,
894 int end_offset) {
895 DCHECK_GE(start_offset, 0);
896 DCHECK_GE(end_offset, 0);
897
898 if (&start_object == &end_object && start_object.IsSimpleTextControl()) {
899 if (start_offset > end_offset)
900 std::swap(start_offset, end_offset);
901
902 if (start_offset >= static_cast<int>(start_object.GetText().length()) ||
903 end_offset > static_cast<int>(start_object.GetText().length())) {
904 return gfx::Rect();
905 }
906
907 return start_object.GetLocalBoundsForRange(
908 start_offset, end_offset - start_offset);
909 }
910
911 gfx::Rect result;
912 const BrowserAccessibility* first = &start_object;
913 const BrowserAccessibility* last = &end_object;
914
915 switch (CompareNodes(*first, *last)) {
916 case ui::AX_TREE_ORDER_BEFORE:
917 case ui::AX_TREE_ORDER_EQUAL:
918 break;
919 case ui::AX_TREE_ORDER_AFTER:
920 std::swap(first, last);
921 std::swap(start_offset, end_offset);
922 break;
923 default:
924 return gfx::Rect();
925 }
926
927 const BrowserAccessibility* current = first;
928 do {
929 if (current->IsTextOnlyObject()) {
930 int len = static_cast<int>(current->GetText().size());
931 int start_char_index = 0;
932 int end_char_index = len;
933 if (current == first)
934 start_char_index = start_offset;
935 if (current == last)
936 end_char_index = end_offset;
937 result.Union(current->GetLocalBoundsForRange(
938 start_char_index, end_char_index - start_char_index));
939 } else {
940 result.Union(current->GetLocalBoundsRect());
941 }
942
943 if (current == last)
944 break;
945
946 current = NextInTreeOrder(current);
947 } while (current);
948
949 return result;
950 }
951
864 void BrowserAccessibilityManager::OnNodeDataWillChange( 952 void BrowserAccessibilityManager::OnNodeDataWillChange(
865 ui::AXTree* tree, 953 ui::AXTree* tree,
866 const ui::AXNodeData& old_node_data, 954 const ui::AXNodeData& old_node_data,
867 const ui::AXNodeData& new_node_data) {} 955 const ui::AXNodeData& new_node_data) {}
868 956
869 void BrowserAccessibilityManager::OnTreeDataChanged(ui::AXTree* tree) { 957 void BrowserAccessibilityManager::OnTreeDataChanged(ui::AXTree* tree) {
870 } 958 }
871 959
872 void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXTree* tree, 960 void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXTree* tree,
873 ui::AXNode* node) { 961 ui::AXNode* node) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 tree_source(tree_->CreateTreeSource()); 1037 tree_source(tree_->CreateTreeSource());
950 ui::AXTreeSerializer<const ui::AXNode*, 1038 ui::AXTreeSerializer<const ui::AXNode*,
951 ui::AXNodeData, 1039 ui::AXNodeData,
952 ui::AXTreeData> serializer(tree_source.get()); 1040 ui::AXTreeData> serializer(tree_source.get());
953 ui::AXTreeUpdate update; 1041 ui::AXTreeUpdate update;
954 serializer.SerializeChanges(tree_->root(), &update); 1042 serializer.SerializeChanges(tree_->root(), &update);
955 return update; 1043 return update;
956 } 1044 }
957 1045
958 } // namespace content 1046 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698