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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp

Issue 2945773002: Relation properties for Accessibility Object Model phase 1 (Closed)
Patch Set: Add tests for details and error message too Created 3 years, 6 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 /* 1 /*
2 * Copyright (C) 2012, Google Inc. All rights reserved. 2 * Copyright (C) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 ax_sparse_attribute_setter_map.Set( 207 ax_sparse_attribute_setter_map.Set(
208 aria_keyshortcutsAttr, 208 aria_keyshortcutsAttr,
209 new StringAttributeSetter(AXStringAttribute::kAriaKeyShortcuts)); 209 new StringAttributeSetter(AXStringAttribute::kAriaKeyShortcuts));
210 ax_sparse_attribute_setter_map.Set( 210 ax_sparse_attribute_setter_map.Set(
211 aria_roledescriptionAttr, 211 aria_roledescriptionAttr,
212 new StringAttributeSetter(AXStringAttribute::kAriaRoleDescription)); 212 new StringAttributeSetter(AXStringAttribute::kAriaRoleDescription));
213 } 213 }
214 return ax_sparse_attribute_setter_map; 214 return ax_sparse_attribute_setter_map;
215 } 215 }
216 216
217 class AXSparseAttributeAOMPropertyClient : public AOMPropertyClient {
218 public:
219 AXSparseAttributeAOMPropertyClient(
220 AXObjectCacheImpl& ax_object_cache,
221 AXSparseAttributeClient& sparse_attribute_client)
222 : ax_object_cache_(ax_object_cache),
223 sparse_attribute_client_(sparse_attribute_client) {}
224
225 void AddStringProperty(AOMStringProperty property,
226 const String& value) override {
227 AXStringAttribute attribute;
228 switch (property) {
229 case AOMStringProperty::kKeyShortcuts:
230 attribute = AXStringAttribute::kAriaKeyShortcuts;
231 break;
232 case AOMStringProperty::kRoleDescription:
233 attribute = AXStringAttribute::kAriaRoleDescription;
234 break;
235 default:
236 return;
237 }
238 sparse_attribute_client_.AddStringAttribute(attribute, value);
239 }
240
241 void AddBooleanProperty(AOMBooleanProperty property, bool value) override {}
aboxhall 2017/06/20 01:11:43 Are these still TODO..?
dmazzoni 2017/06/20 04:56:34 Not exactly. AOMPropertyClient iterates over ever
aboxhall 2017/06/22 01:12:39 Ah, got it. Thanks for explaining.
242
243 void AddIntProperty(AOMIntProperty property, int32_t value) override {}
244
245 void AddUIntProperty(AOMUIntProperty property, uint32_t value) override {}
246
247 void AddFloatProperty(AOMFloatProperty property, float value) override {}
248
249 void AddRelationProperty(AOMRelationProperty property,
250 const AccessibleNode& value) override {
251 AXObjectAttribute attribute;
252 switch (property) {
253 case AOMRelationProperty::kActiveDescendant:
254 attribute = AXObjectAttribute::kAriaActiveDescendant;
255 break;
256 case AOMRelationProperty::kDetails:
257 attribute = AXObjectAttribute::kAriaDetails;
258 break;
259 case AOMRelationProperty::kErrorMessage:
260 attribute = AXObjectAttribute::kAriaErrorMessage;
261 break;
262 default:
263 return;
264 }
265
266 Element* target_element = value.element();
267 AXObjectImpl* target_obj = ax_object_cache_->GetOrCreate(target_element);
268 if (target_element)
269 sparse_attribute_client_.AddObjectAttribute(attribute, *target_obj);
270 }
271
272 private:
273 Persistent<AXObjectCacheImpl> ax_object_cache_;
274 AXSparseAttributeClient& sparse_attribute_client_;
275 };
276
217 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl& ax_object_cache) 277 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl& ax_object_cache)
218 : AXObjectImpl(ax_object_cache), 278 : AXObjectImpl(ax_object_cache),
219 aria_role_(kUnknownRole), 279 aria_role_(kUnknownRole),
220 children_dirty_(false), 280 children_dirty_(false),
221 node_(node) {} 281 node_(node) {}
222 282
223 AXNodeObject* AXNodeObject::Create(Node* node, 283 AXNodeObject* AXNodeObject::Create(Node* node,
224 AXObjectCacheImpl& ax_object_cache) { 284 AXObjectCacheImpl& ax_object_cache) {
225 return new AXNodeObject(node, ax_object_cache); 285 return new AXNodeObject(node, ax_object_cache);
226 } 286 }
(...skipping 10 matching lines...) Expand all
237 float step = StepValueForRange(); 297 float step = StepValueForRange();
238 298
239 value += increase ? step : -step; 299 value += increase ? step : -step;
240 300
241 SetValue(String::Number(value)); 301 SetValue(String::Number(value));
242 AxObjectCache().PostNotification(GetNode(), 302 AxObjectCache().PostNotification(GetNode(),
243 AXObjectCacheImpl::kAXValueChanged); 303 AXObjectCacheImpl::kAXValueChanged);
244 } 304 }
245 305
246 AXObjectImpl* AXNodeObject::ActiveDescendant() { 306 AXObjectImpl* AXNodeObject::ActiveDescendant() {
247 if (!node_ || !node_->IsElementNode()) 307 Element* element = GetElement();
308 if (!element)
248 return nullptr; 309 return nullptr;
249 310
250 const AtomicString& active_descendant_attr =
251 GetAttribute(aria_activedescendantAttr);
252 if (active_descendant_attr.IsNull() || active_descendant_attr.IsEmpty())
253 return nullptr;
254
255 Element* element = ToElement(GetNode());
256 Element* descendant = 311 Element* descendant =
257 element->GetTreeScope().getElementById(active_descendant_attr); 312 GetAOMPropertyOrARIAAttribute(AOMRelationProperty::kActiveDescendant);
258 if (!descendant) 313 if (!descendant)
259 return nullptr; 314 return nullptr;
260 315
261 AXObjectImpl* ax_descendant = AxObjectCache().GetOrCreate(descendant); 316 AXObjectImpl* ax_descendant = AxObjectCache().GetOrCreate(descendant);
262 return ax_descendant; 317 return ax_descendant;
263 } 318 }
264 319
265 bool AXNodeObject::ComputeAccessibilityIsIgnored( 320 bool AXNodeObject::ComputeAccessibilityIsIgnored(
266 IgnoredReasons* ignored_reasons) const { 321 IgnoredReasons* ignored_reasons) const {
267 #if DCHECK_IS_ON() 322 #if DCHECK_IS_ON()
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 role_ = DetermineAccessibilityRole(); 964 role_ = DetermineAccessibilityRole();
910 } 965 }
911 966
912 void AXNodeObject::Detach() { 967 void AXNodeObject::Detach() {
913 AXObjectImpl::Detach(); 968 AXObjectImpl::Detach();
914 node_ = nullptr; 969 node_ = nullptr;
915 } 970 }
916 971
917 void AXNodeObject::GetSparseAXAttributes( 972 void AXNodeObject::GetSparseAXAttributes(
918 AXSparseAttributeClient& sparse_attribute_client) const { 973 AXSparseAttributeClient& sparse_attribute_client) const {
919 Node* node = this->GetNode(); 974 Element* element = GetElement();
920 if (!node || !node->IsElementNode()) 975 if (!element)
921 return; 976 return;
922 977
978 AXSparseAttributeAOMPropertyClient property_client(*ax_object_cache_,
979 sparse_attribute_client);
980 HashSet<QualifiedName> shadowed_aria_attributes;
981 AccessibleNode::GetAllAOMProperties(element, &property_client,
982 shadowed_aria_attributes);
983
923 AXSparseAttributeSetterMap& ax_sparse_attribute_setter_map = 984 AXSparseAttributeSetterMap& ax_sparse_attribute_setter_map =
924 GetSparseAttributeSetterMap(); 985 GetSparseAttributeSetterMap();
925 AttributeCollection attributes = ToElement(node)->AttributesWithoutUpdate(); 986 AttributeCollection attributes = element->AttributesWithoutUpdate();
926 for (const Attribute& attr : attributes) { 987 for (const Attribute& attr : attributes) {
988 if (shadowed_aria_attributes.Contains(attr.GetName()))
989 continue;
990
927 SparseAttributeSetter* setter = 991 SparseAttributeSetter* setter =
928 ax_sparse_attribute_setter_map.at(attr.GetName()); 992 ax_sparse_attribute_setter_map.at(attr.GetName());
929 if (setter) 993 if (setter)
930 setter->Run(*this, sparse_attribute_client, attr.Value()); 994 setter->Run(*this, sparse_attribute_client, attr.Value());
931 } 995 }
932
933 // TODO(dmazzoni): Efficiently iterate over AccessibleNode properties that are
934 // set and merge the two loops somehow.
935 if (ToElement(node)->ExistingAccessibleNode()) {
936 AtomicString key_shortcuts =
937 GetAOMPropertyOrARIAAttribute(AOMStringProperty::kKeyShortcuts);
938 if (!key_shortcuts.IsNull()) {
939 ax_sparse_attribute_setter_map.at(aria_keyshortcutsAttr)
940 ->Run(*this, sparse_attribute_client, key_shortcuts);
941 }
942 AtomicString role_description =
943 GetAOMPropertyOrARIAAttribute(AOMStringProperty::kRoleDescription);
944 if (!role_description.IsNull()) {
945 ax_sparse_attribute_setter_map.at(aria_roledescriptionAttr)
946 ->Run(*this, sparse_attribute_client, role_description);
947 }
948 }
949 } 996 }
950 997
951 bool AXNodeObject::IsAnchor() const { 998 bool AXNodeObject::IsAnchor() const {
952 return !IsNativeImage() && IsLink(); 999 return !IsNativeImage() && IsLink();
953 } 1000 }
954 1001
955 bool AXNodeObject::IsControl() const { 1002 bool AXNodeObject::IsControl() const {
956 Node* node = this->GetNode(); 1003 Node* node = this->GetNode();
957 if (!node) 1004 if (!node)
958 return false; 1005 return false;
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 return String(); 3262 return String();
3216 return ToTextControlElement(node)->StrippedPlaceholder(); 3263 return ToTextControlElement(node)->StrippedPlaceholder();
3217 } 3264 }
3218 3265
3219 DEFINE_TRACE(AXNodeObject) { 3266 DEFINE_TRACE(AXNodeObject) {
3220 visitor->Trace(node_); 3267 visitor->Trace(node_);
3221 AXObjectImpl::Trace(visitor); 3268 AXObjectImpl::Trace(visitor);
3222 } 3269 }
3223 3270
3224 } // namespace blink 3271 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698