| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/accessibility/blink_ax_tree_source.h" | 5 #include "content/renderer/accessibility/blink_ax_tree_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 using blink::WebNode; | 48 using blink::WebNode; |
| 49 using blink::WebPlugin; | 49 using blink::WebPlugin; |
| 50 using blink::WebPluginContainer; | 50 using blink::WebPluginContainer; |
| 51 using blink::WebVector; | 51 using blink::WebVector; |
| 52 using blink::WebView; | 52 using blink::WebView; |
| 53 | 53 |
| 54 namespace content { | 54 namespace content { |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 void AddIntListAttributeFromWebObjects(ui::AXIntListAttribute attr, |
| 59 const WebVector<WebAXObject>& objects, |
| 60 AXContentNodeData* dst) { |
| 61 std::vector<int32_t> ids; |
| 62 for (size_t i = 0; i < objects.size(); i++) |
| 63 ids.push_back(objects[i].axID()); |
| 64 if (!ids.empty()) |
| 65 dst->AddIntListAttribute(attr, ids); |
| 66 } |
| 67 |
| 68 class AXContentNodeDataSparseAttributeAdapter |
| 69 : public blink::WebAXSparseAttributeClient { |
| 70 public: |
| 71 AXContentNodeDataSparseAttributeAdapter(AXContentNodeData* dst) : dst_(dst) { |
| 72 DCHECK(dst_); |
| 73 } |
| 74 ~AXContentNodeDataSparseAttributeAdapter() override {} |
| 75 |
| 76 private: |
| 77 AXContentNodeData* dst_; |
| 78 |
| 79 void addBoolAttribute(blink::WebAXBoolAttribute attribute, |
| 80 bool value) override { |
| 81 NOTREACHED(); |
| 82 } |
| 83 |
| 84 void addStringAttribute(blink::WebAXStringAttribute attribute, |
| 85 const blink::WebString& value) override { |
| 86 NOTREACHED(); |
| 87 } |
| 88 |
| 89 void addObjectAttribute(blink::WebAXObjectAttribute attribute, |
| 90 const blink::WebAXObject& value) override { |
| 91 switch (attribute) { |
| 92 case blink::WebAXObjectAttribute::AriaActiveDescendant: |
| 93 dst_->AddIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, value.axID()); |
| 94 break; |
| 95 default: |
| 96 NOTREACHED(); |
| 97 } |
| 98 } |
| 99 |
| 100 void addObjectVectorAttribute( |
| 101 blink::WebAXObjectVectorAttribute attribute, |
| 102 const blink::WebVector<WebAXObject>& value) override { |
| 103 switch (attribute) { |
| 104 case blink::WebAXObjectVectorAttribute::AriaControls: |
| 105 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS, value, |
| 106 dst_); |
| 107 break; |
| 108 case blink::WebAXObjectVectorAttribute::AriaFlowTo: |
| 109 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS, value, dst_); |
| 110 break; |
| 111 default: |
| 112 NOTREACHED(); |
| 113 } |
| 114 } |
| 115 }; |
| 116 |
| 58 WebAXObject ParentObjectUnignored(WebAXObject child) { | 117 WebAXObject ParentObjectUnignored(WebAXObject child) { |
| 59 WebAXObject parent = child.parentObject(); | 118 WebAXObject parent = child.parentObject(); |
| 60 while (!parent.isDetached() && parent.accessibilityIsIgnored()) | 119 while (!parent.isDetached() && parent.accessibilityIsIgnored()) |
| 61 parent = parent.parentObject(); | 120 parent = parent.parentObject(); |
| 62 return parent; | 121 return parent; |
| 63 } | 122 } |
| 64 | 123 |
| 65 // Returns true if |ancestor| is the first unignored parent of |child|, | 124 // Returns true if |ancestor| is the first unignored parent of |child|, |
| 66 // which means that when walking up the parent chain from |child|, | 125 // which means that when walking up the parent chain from |child|, |
| 67 // |ancestor| is the *first* ancestor that isn't marked as | 126 // |ancestor| is the *first* ancestor that isn't marked as |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return "slider"; | 161 return "slider"; |
| 103 case ui::AX_ROLE_TIME: | 162 case ui::AX_ROLE_TIME: |
| 104 return "time"; | 163 return "time"; |
| 105 default: | 164 default: |
| 106 break; | 165 break; |
| 107 } | 166 } |
| 108 | 167 |
| 109 return std::string(); | 168 return std::string(); |
| 110 } | 169 } |
| 111 | 170 |
| 112 void AddIntListAttributeFromWebObjects(ui::AXIntListAttribute attr, | |
| 113 WebVector<WebAXObject> objects, | |
| 114 AXContentNodeData* dst) { | |
| 115 std::vector<int32_t> ids; | |
| 116 for(size_t i = 0; i < objects.size(); i++) | |
| 117 ids.push_back(objects[i].axID()); | |
| 118 if (ids.size() > 0) | |
| 119 dst->AddIntListAttribute(attr, ids); | |
| 120 } | |
| 121 | |
| 122 } // namespace | 171 } // namespace |
| 123 | 172 |
| 124 ScopedFreezeBlinkAXTreeSource::ScopedFreezeBlinkAXTreeSource( | 173 ScopedFreezeBlinkAXTreeSource::ScopedFreezeBlinkAXTreeSource( |
| 125 BlinkAXTreeSource* tree_source) | 174 BlinkAXTreeSource* tree_source) |
| 126 : tree_source_(tree_source) { | 175 : tree_source_(tree_source) { |
| 127 tree_source_->Freeze(); | 176 tree_source_->Freeze(); |
| 128 } | 177 } |
| 129 | 178 |
| 130 ScopedFreezeBlinkAXTreeSource::~ScopedFreezeBlinkAXTreeSource() { | 179 ScopedFreezeBlinkAXTreeSource::~ScopedFreezeBlinkAXTreeSource() { |
| 131 tree_source_->Thaw(); | 180 tree_source_->Thaw(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 WebFloatRect bounds_in_container; | 366 WebFloatRect bounds_in_container; |
| 318 SkMatrix44 container_transform; | 367 SkMatrix44 container_transform; |
| 319 src.getRelativeBounds( | 368 src.getRelativeBounds( |
| 320 offset_container, bounds_in_container, container_transform); | 369 offset_container, bounds_in_container, container_transform); |
| 321 dst->location = bounds_in_container; | 370 dst->location = bounds_in_container; |
| 322 if (!container_transform.isIdentity()) | 371 if (!container_transform.isIdentity()) |
| 323 dst->transform = base::WrapUnique(new gfx::Transform(container_transform)); | 372 dst->transform = base::WrapUnique(new gfx::Transform(container_transform)); |
| 324 if (!offset_container.isDetached()) | 373 if (!offset_container.isDetached()) |
| 325 dst->offset_container_id = offset_container.axID(); | 374 dst->offset_container_id = offset_container.axID(); |
| 326 | 375 |
| 376 AXContentNodeDataSparseAttributeAdapter sparse_attribute_adapter(dst); |
| 377 src.getSparseAXAttributes(sparse_attribute_adapter); |
| 378 |
| 327 blink::WebAXNameFrom nameFrom; | 379 blink::WebAXNameFrom nameFrom; |
| 328 blink::WebVector<blink::WebAXObject> nameObjects; | 380 blink::WebVector<blink::WebAXObject> nameObjects; |
| 329 blink::WebString web_name = src.name(nameFrom, nameObjects); | 381 blink::WebString web_name = src.name(nameFrom, nameObjects); |
| 330 if (!web_name.isEmpty()) { | 382 if (!web_name.isEmpty()) { |
| 331 dst->AddStringAttribute(ui::AX_ATTR_NAME, web_name.utf8()); | 383 dst->AddStringAttribute(ui::AX_ATTR_NAME, web_name.utf8()); |
| 332 dst->AddIntAttribute(ui::AX_ATTR_NAME_FROM, AXNameFromFromBlink(nameFrom)); | 384 dst->AddIntAttribute(ui::AX_ATTR_NAME_FROM, AXNameFromFromBlink(nameFrom)); |
| 333 AddIntListAttributeFromWebObjects( | 385 AddIntListAttributeFromWebObjects( |
| 334 ui::AX_ATTR_LABELLEDBY_IDS, nameObjects, dst); | 386 ui::AX_ATTR_LABELLEDBY_IDS, nameObjects, dst); |
| 335 } | 387 } |
| 336 | 388 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 WebAXObject child = src.childAt(i); | 800 WebAXObject child = src.childAt(i); |
| 749 std::vector<int32_t> indirect_child_ids; | 801 std::vector<int32_t> indirect_child_ids; |
| 750 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child)) | 802 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child)) |
| 751 indirect_child_ids.push_back(child.axID()); | 803 indirect_child_ids.push_back(child.axID()); |
| 752 if (indirect_child_ids.size() > 0) { | 804 if (indirect_child_ids.size() > 0) { |
| 753 dst->AddIntListAttribute( | 805 dst->AddIntListAttribute( |
| 754 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids); | 806 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids); |
| 755 } | 807 } |
| 756 } | 808 } |
| 757 | 809 |
| 758 WebVector<WebAXObject> controls; | |
| 759 if (src.ariaControls(controls)) | |
| 760 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS, controls, dst); | |
| 761 | |
| 762 WebVector<WebAXObject> flowTo; | |
| 763 if (src.ariaFlowTo(flowTo)) | |
| 764 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS, flowTo, dst); | |
| 765 | |
| 766 if (src.isScrollableContainer()) { | 810 if (src.isScrollableContainer()) { |
| 767 const gfx::Point& scrollOffset = src.getScrollOffset(); | 811 const gfx::Point& scrollOffset = src.getScrollOffset(); |
| 768 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scrollOffset.x()); | 812 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scrollOffset.x()); |
| 769 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scrollOffset.y()); | 813 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scrollOffset.y()); |
| 770 | 814 |
| 771 const gfx::Point& minScrollOffset = src.minimumScrollOffset(); | 815 const gfx::Point& minScrollOffset = src.minimumScrollOffset(); |
| 772 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, minScrollOffset.x()); | 816 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, minScrollOffset.x()); |
| 773 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, minScrollOffset.y()); | 817 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, minScrollOffset.y()); |
| 774 | 818 |
| 775 const gfx::Point& maxScrollOffset = src.maximumScrollOffset(); | 819 const gfx::Point& maxScrollOffset = src.maximumScrollOffset(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 796 return WebAXObject(); | 840 return WebAXObject(); |
| 797 | 841 |
| 798 WebDocument document = render_frame_->GetWebFrame()->document(); | 842 WebDocument document = render_frame_->GetWebFrame()->document(); |
| 799 if (!document.isNull()) | 843 if (!document.isNull()) |
| 800 return document.accessibilityObject(); | 844 return document.accessibilityObject(); |
| 801 | 845 |
| 802 return WebAXObject(); | 846 return WebAXObject(); |
| 803 } | 847 } |
| 804 | 848 |
| 805 } // namespace content | 849 } // namespace content |
| OLD | NEW |