Chromium Code Reviews| 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 WebVector<WebAXObject> objects, | |
|
dcheng
2017/01/19 23:02:44
Nit: pass by const ref
dmazzoni
2017/01/21 00:16:35
Done.
| |
| 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 ~AXContentNodeDataSparseAttributeAdapter() override {} | |
| 73 | |
| 74 private: | |
| 75 AXContentNodeData* dst_; | |
| 76 | |
| 77 void addBoolAttribute(blink::WebAXBoolAttribute attribute, | |
| 78 bool value) override { | |
| 79 NOTREACHED(); | |
| 80 } | |
| 81 | |
| 82 void addStringAttribute(blink::WebAXStringAttribute attribute, | |
| 83 const blink::WebString& value) override { | |
| 84 NOTREACHED(); | |
| 85 } | |
| 86 | |
| 87 void addObjectAttribute(blink::WebAXObjectAttribute attribute, | |
| 88 const blink::WebAXObject& value) override { | |
| 89 switch (attribute) { | |
| 90 case blink::WebAXObjectAttribute::AriaActiveDescendant: | |
| 91 dst_->AddIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, value.axID()); | |
| 92 break; | |
| 93 default: | |
| 94 NOTREACHED(); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void addObjectVectorAttribute( | |
| 99 blink::WebAXObjectVectorAttribute attribute, | |
| 100 const blink::WebVector<WebAXObject>& value) override { | |
| 101 switch (attribute) { | |
| 102 case blink::WebAXObjectVectorAttribute::AriaControls: | |
| 103 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS, value, | |
| 104 dst_); | |
| 105 break; | |
| 106 case blink::WebAXObjectVectorAttribute::AriaFlowTo: | |
| 107 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS, value, dst_); | |
| 108 break; | |
| 109 default: | |
| 110 NOTREACHED(); | |
| 111 } | |
| 112 } | |
| 113 }; | |
| 114 | |
| 58 WebAXObject ParentObjectUnignored(WebAXObject child) { | 115 WebAXObject ParentObjectUnignored(WebAXObject child) { |
| 59 WebAXObject parent = child.parentObject(); | 116 WebAXObject parent = child.parentObject(); |
| 60 while (!parent.isDetached() && parent.accessibilityIsIgnored()) | 117 while (!parent.isDetached() && parent.accessibilityIsIgnored()) |
| 61 parent = parent.parentObject(); | 118 parent = parent.parentObject(); |
| 62 return parent; | 119 return parent; |
| 63 } | 120 } |
| 64 | 121 |
| 65 // Returns true if |ancestor| is the first unignored parent of |child|, | 122 // Returns true if |ancestor| is the first unignored parent of |child|, |
| 66 // which means that when walking up the parent chain from |child|, | 123 // which means that when walking up the parent chain from |child|, |
| 67 // |ancestor| is the *first* ancestor that isn't marked as | 124 // |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"; | 159 return "slider"; |
| 103 case ui::AX_ROLE_TIME: | 160 case ui::AX_ROLE_TIME: |
| 104 return "time"; | 161 return "time"; |
| 105 default: | 162 default: |
| 106 break; | 163 break; |
| 107 } | 164 } |
| 108 | 165 |
| 109 return std::string(); | 166 return std::string(); |
| 110 } | 167 } |
| 111 | 168 |
| 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 | 169 } // namespace |
| 123 | 170 |
| 124 ScopedFreezeBlinkAXTreeSource::ScopedFreezeBlinkAXTreeSource( | 171 ScopedFreezeBlinkAXTreeSource::ScopedFreezeBlinkAXTreeSource( |
| 125 BlinkAXTreeSource* tree_source) | 172 BlinkAXTreeSource* tree_source) |
| 126 : tree_source_(tree_source) { | 173 : tree_source_(tree_source) { |
| 127 tree_source_->Freeze(); | 174 tree_source_->Freeze(); |
| 128 } | 175 } |
| 129 | 176 |
| 130 ScopedFreezeBlinkAXTreeSource::~ScopedFreezeBlinkAXTreeSource() { | 177 ScopedFreezeBlinkAXTreeSource::~ScopedFreezeBlinkAXTreeSource() { |
| 131 tree_source_->Thaw(); | 178 tree_source_->Thaw(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 WebFloatRect bounds_in_container; | 364 WebFloatRect bounds_in_container; |
| 318 SkMatrix44 container_transform; | 365 SkMatrix44 container_transform; |
| 319 src.getRelativeBounds( | 366 src.getRelativeBounds( |
| 320 offset_container, bounds_in_container, container_transform); | 367 offset_container, bounds_in_container, container_transform); |
| 321 dst->location = bounds_in_container; | 368 dst->location = bounds_in_container; |
| 322 if (!container_transform.isIdentity()) | 369 if (!container_transform.isIdentity()) |
| 323 dst->transform = base::WrapUnique(new gfx::Transform(container_transform)); | 370 dst->transform = base::WrapUnique(new gfx::Transform(container_transform)); |
| 324 if (!offset_container.isDetached()) | 371 if (!offset_container.isDetached()) |
| 325 dst->offset_container_id = offset_container.axID(); | 372 dst->offset_container_id = offset_container.axID(); |
| 326 | 373 |
| 374 AXContentNodeDataSparseAttributeAdapter sparse_attribute_adapter(dst); | |
| 375 src.getSparseAXAttributes(sparse_attribute_adapter); | |
| 376 | |
| 327 blink::WebAXNameFrom nameFrom; | 377 blink::WebAXNameFrom nameFrom; |
| 328 blink::WebVector<blink::WebAXObject> nameObjects; | 378 blink::WebVector<blink::WebAXObject> nameObjects; |
| 329 blink::WebString web_name = src.name(nameFrom, nameObjects); | 379 blink::WebString web_name = src.name(nameFrom, nameObjects); |
| 330 if (!web_name.isEmpty()) { | 380 if (!web_name.isEmpty()) { |
| 331 dst->AddStringAttribute(ui::AX_ATTR_NAME, web_name.utf8()); | 381 dst->AddStringAttribute(ui::AX_ATTR_NAME, web_name.utf8()); |
| 332 dst->AddIntAttribute(ui::AX_ATTR_NAME_FROM, AXNameFromFromBlink(nameFrom)); | 382 dst->AddIntAttribute(ui::AX_ATTR_NAME_FROM, AXNameFromFromBlink(nameFrom)); |
| 333 AddIntListAttributeFromWebObjects( | 383 AddIntListAttributeFromWebObjects( |
| 334 ui::AX_ATTR_LABELLEDBY_IDS, nameObjects, dst); | 384 ui::AX_ATTR_LABELLEDBY_IDS, nameObjects, dst); |
| 335 } | 385 } |
| 336 | 386 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 WebAXObject child = src.childAt(i); | 798 WebAXObject child = src.childAt(i); |
| 749 std::vector<int32_t> indirect_child_ids; | 799 std::vector<int32_t> indirect_child_ids; |
| 750 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child)) | 800 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child)) |
| 751 indirect_child_ids.push_back(child.axID()); | 801 indirect_child_ids.push_back(child.axID()); |
| 752 if (indirect_child_ids.size() > 0) { | 802 if (indirect_child_ids.size() > 0) { |
| 753 dst->AddIntListAttribute( | 803 dst->AddIntListAttribute( |
| 754 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids); | 804 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids); |
| 755 } | 805 } |
| 756 } | 806 } |
| 757 | 807 |
| 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()) { | 808 if (src.isScrollableContainer()) { |
| 767 const gfx::Point& scrollOffset = src.getScrollOffset(); | 809 const gfx::Point& scrollOffset = src.getScrollOffset(); |
| 768 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scrollOffset.x()); | 810 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scrollOffset.x()); |
| 769 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scrollOffset.y()); | 811 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scrollOffset.y()); |
| 770 | 812 |
| 771 const gfx::Point& minScrollOffset = src.minimumScrollOffset(); | 813 const gfx::Point& minScrollOffset = src.minimumScrollOffset(); |
| 772 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, minScrollOffset.x()); | 814 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, minScrollOffset.x()); |
| 773 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, minScrollOffset.y()); | 815 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, minScrollOffset.y()); |
| 774 | 816 |
| 775 const gfx::Point& maxScrollOffset = src.maximumScrollOffset(); | 817 const gfx::Point& maxScrollOffset = src.maximumScrollOffset(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 796 return WebAXObject(); | 838 return WebAXObject(); |
| 797 | 839 |
| 798 WebDocument document = render_frame_->GetWebFrame()->document(); | 840 WebDocument document = render_frame_->GetWebFrame()->document(); |
| 799 if (!document.isNull()) | 841 if (!document.isNull()) |
| 800 return document.accessibilityObject(); | 842 return document.accessibilityObject(); |
| 801 | 843 |
| 802 return WebAXObject(); | 844 return WebAXObject(); |
| 803 } | 845 } |
| 804 | 846 |
| 805 } // namespace content | 847 } // namespace content |
| OLD | NEW |