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

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

Issue 2217363002: Use relative bounding boxes throughout Chrome accessibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback from aboxhall 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 406 }
407 } 407 }
408 408
409 void BrowserAccessibilityManager::OnLocationChanges( 409 void BrowserAccessibilityManager::OnLocationChanges(
410 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { 410 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
411 for (size_t i = 0; i < params.size(); ++i) { 411 for (size_t i = 0; i < params.size(); ++i) {
412 BrowserAccessibility* obj = GetFromID(params[i].id); 412 BrowserAccessibility* obj = GetFromID(params[i].id);
413 if (!obj) 413 if (!obj)
414 continue; 414 continue;
415 ui::AXNode* node = obj->node(); 415 ui::AXNode* node = obj->node();
416 node->SetLocation(params[i].new_location); 416 node->SetLocation(params[i].new_location.offset_container_id,
417 params[i].new_location.bounds,
418 params[i].new_location.transform.get());
417 } 419 }
418 SendLocationChangeEvents(params); 420 SendLocationChangeEvents(params);
419 } 421 }
420 422
421 void BrowserAccessibilityManager::SendLocationChangeEvents( 423 void BrowserAccessibilityManager::SendLocationChangeEvents(
422 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { 424 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
423 for (size_t i = 0; i < params.size(); ++i) { 425 for (size_t i = 0; i < params.size(); ++i) {
424 BrowserAccessibility* obj = GetFromID(params[i].id); 426 BrowserAccessibility* obj = GetFromID(params[i].id);
425 if (obj) 427 if (obj)
426 obj->OnLocationChanged(); 428 obj->OnLocationChanged();
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 if (end_offset <= static_cast<int>(end_text_object->GetText().length())) { 882 if (end_offset <= static_cast<int>(end_text_object->GetText().length())) {
881 text += end_text_object->GetText().substr(0, end_offset); 883 text += end_text_object->GetText().substr(0, end_offset);
882 } else { 884 } else {
883 text += end_text_object->GetText(); 885 text += end_text_object->GetText();
884 } 886 }
885 887
886 return text; 888 return text;
887 } 889 }
888 890
889 // static 891 // static
890 gfx::Rect BrowserAccessibilityManager::GetLocalBoundsForRange( 892 gfx::Rect BrowserAccessibilityManager::GetPageBoundsForRange(
891 const BrowserAccessibility& start_object, 893 const BrowserAccessibility& start_object,
892 int start_offset, 894 int start_offset,
893 const BrowserAccessibility& end_object, 895 const BrowserAccessibility& end_object,
894 int end_offset) { 896 int end_offset) {
895 DCHECK_GE(start_offset, 0); 897 DCHECK_GE(start_offset, 0);
896 DCHECK_GE(end_offset, 0); 898 DCHECK_GE(end_offset, 0);
897 899
898 if (&start_object == &end_object && start_object.IsSimpleTextControl()) { 900 if (&start_object == &end_object && start_object.IsSimpleTextControl()) {
899 if (start_offset > end_offset) 901 if (start_offset > end_offset)
900 std::swap(start_offset, end_offset); 902 std::swap(start_offset, end_offset);
901 903
902 if (start_offset >= static_cast<int>(start_object.GetText().length()) || 904 if (start_offset >= static_cast<int>(start_object.GetText().length()) ||
903 end_offset > static_cast<int>(start_object.GetText().length())) { 905 end_offset > static_cast<int>(start_object.GetText().length())) {
904 return gfx::Rect(); 906 return gfx::Rect();
905 } 907 }
906 908
907 return start_object.GetLocalBoundsForRange( 909 return start_object.GetPageBoundsForRange(
908 start_offset, end_offset - start_offset); 910 start_offset, end_offset - start_offset);
909 } 911 }
910 912
911 gfx::Rect result; 913 gfx::Rect result;
912 const BrowserAccessibility* first = &start_object; 914 const BrowserAccessibility* first = &start_object;
913 const BrowserAccessibility* last = &end_object; 915 const BrowserAccessibility* last = &end_object;
914 916
915 switch (CompareNodes(*first, *last)) { 917 switch (CompareNodes(*first, *last)) {
916 case ui::AX_TREE_ORDER_BEFORE: 918 case ui::AX_TREE_ORDER_BEFORE:
917 case ui::AX_TREE_ORDER_EQUAL: 919 case ui::AX_TREE_ORDER_EQUAL:
918 break; 920 break;
919 case ui::AX_TREE_ORDER_AFTER: 921 case ui::AX_TREE_ORDER_AFTER:
920 std::swap(first, last); 922 std::swap(first, last);
921 std::swap(start_offset, end_offset); 923 std::swap(start_offset, end_offset);
922 break; 924 break;
923 default: 925 default:
924 return gfx::Rect(); 926 return gfx::Rect();
925 } 927 }
926 928
927 const BrowserAccessibility* current = first; 929 const BrowserAccessibility* current = first;
928 do { 930 do {
929 if (current->IsTextOnlyObject()) { 931 if (current->IsTextOnlyObject()) {
930 int len = static_cast<int>(current->GetText().size()); 932 int len = static_cast<int>(current->GetText().size());
931 int start_char_index = 0; 933 int start_char_index = 0;
932 int end_char_index = len; 934 int end_char_index = len;
933 if (current == first) 935 if (current == first)
934 start_char_index = start_offset; 936 start_char_index = start_offset;
935 if (current == last) 937 if (current == last)
936 end_char_index = end_offset; 938 end_char_index = end_offset;
937 result.Union(current->GetLocalBoundsForRange( 939 result.Union(current->GetPageBoundsForRange(
938 start_char_index, end_char_index - start_char_index)); 940 start_char_index, end_char_index - start_char_index));
939 } else { 941 } else {
940 result.Union(current->GetLocalBoundsRect()); 942 result.Union(current->GetPageBoundsRect());
941 } 943 }
942 944
943 if (current == last) 945 if (current == last)
944 break; 946 break;
945 947
946 current = NextInTreeOrder(current); 948 current = NextInTreeOrder(current);
947 } while (current); 949 } while (current);
948 950
949 return result; 951 return result;
950 } 952 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 tree_source(tree_->CreateTreeSource()); 1039 tree_source(tree_->CreateTreeSource());
1038 ui::AXTreeSerializer<const ui::AXNode*, 1040 ui::AXTreeSerializer<const ui::AXNode*,
1039 ui::AXNodeData, 1041 ui::AXNodeData,
1040 ui::AXTreeData> serializer(tree_source.get()); 1042 ui::AXTreeData> serializer(tree_source.get());
1041 ui::AXTreeUpdate update; 1043 ui::AXTreeUpdate update;
1042 serializer.SerializeChanges(tree_->root(), &update); 1044 serializer.SerializeChanges(tree_->root(), &update);
1043 return update; 1045 return update;
1044 } 1046 }
1045 1047
1046 } // namespace content 1048 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698