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

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: Fix merge error, format 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 ax_sparse_attribute_setter_map.Set( 206 ax_sparse_attribute_setter_map.Set(
207 aria_keyshortcutsAttr, 207 aria_keyshortcutsAttr,
208 new StringAttributeSetter(AXStringAttribute::kAriaKeyShortcuts)); 208 new StringAttributeSetter(AXStringAttribute::kAriaKeyShortcuts));
209 ax_sparse_attribute_setter_map.Set( 209 ax_sparse_attribute_setter_map.Set(
210 aria_roledescriptionAttr, 210 aria_roledescriptionAttr,
211 new StringAttributeSetter(AXStringAttribute::kAriaRoleDescription)); 211 new StringAttributeSetter(AXStringAttribute::kAriaRoleDescription));
212 } 212 }
213 return ax_sparse_attribute_setter_map; 213 return ax_sparse_attribute_setter_map;
214 } 214 }
215 215
216 class AXSparseAttributeAOMPropertyClient : public AOMPropertyClient {
217 public:
218 AXSparseAttributeAOMPropertyClient(
219 AXObjectCacheImpl& ax_object_cache,
220 AXSparseAttributeClient& sparse_attribute_client)
221 : ax_object_cache_(ax_object_cache),
222 sparse_attribute_client_(sparse_attribute_client) {}
223
224 void AddStringProperty(AOMStringProperty property,
225 const String& value) override {
226 AXStringAttribute attribute;
227 switch (property) {
228 case AOMStringProperty::kKeyShortcuts:
229 attribute = AXStringAttribute::kAriaKeyShortcuts;
230 break;
231 case AOMStringProperty::kRoleDescription:
232 attribute = AXStringAttribute::kAriaRoleDescription;
233 break;
234 default:
235 return;
236 }
237 sparse_attribute_client_.AddStringAttribute(attribute, value);
238 }
239
240 void AddBooleanProperty(AOMBooleanProperty property, bool value) override {}
241
242 void AddIntProperty(AOMIntProperty property, int32_t value) override {}
243
244 void AddUIntProperty(AOMUIntProperty property, uint32_t value) override {}
245
246 void AddFloatProperty(AOMFloatProperty property, float value) override {}
247
248 void AddRelationProperty(AOMRelationProperty property,
249 const AccessibleNode& value) override {
250 AXObjectAttribute attribute;
251 switch (property) {
252 case AOMRelationProperty::kActiveDescendant:
253 attribute = AXObjectAttribute::kAriaActiveDescendant;
254 break;
255 case AOMRelationProperty::kDetails:
256 attribute = AXObjectAttribute::kAriaDetails;
257 break;
258 case AOMRelationProperty::kErrorMessage:
259 attribute = AXObjectAttribute::kAriaErrorMessage;
260 break;
261 default:
262 return;
263 }
264
265 Element* target_element = value.element();
266 AXObject* target_obj = ax_object_cache_->GetOrCreate(target_element);
267 if (target_element)
268 sparse_attribute_client_.AddObjectAttribute(attribute, *target_obj);
269 }
270
271 private:
272 Persistent<AXObjectCacheImpl> ax_object_cache_;
273 AXSparseAttributeClient& sparse_attribute_client_;
274 };
275
216 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl& ax_object_cache) 276 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl& ax_object_cache)
217 : AXObject(ax_object_cache), 277 : AXObject(ax_object_cache),
218 aria_role_(kUnknownRole), 278 aria_role_(kUnknownRole),
219 children_dirty_(false), 279 children_dirty_(false),
220 node_(node) {} 280 node_(node) {}
221 281
222 AXNodeObject* AXNodeObject::Create(Node* node, 282 AXNodeObject* AXNodeObject::Create(Node* node,
223 AXObjectCacheImpl& ax_object_cache) { 283 AXObjectCacheImpl& ax_object_cache) {
224 return new AXNodeObject(node, ax_object_cache); 284 return new AXNodeObject(node, ax_object_cache);
225 } 285 }
(...skipping 10 matching lines...) Expand all
236 float step = StepValueForRange(); 296 float step = StepValueForRange();
237 297
238 value += increase ? step : -step; 298 value += increase ? step : -step;
239 299
240 SetValue(String::Number(value)); 300 SetValue(String::Number(value));
241 AxObjectCache().PostNotification(GetNode(), 301 AxObjectCache().PostNotification(GetNode(),
242 AXObjectCacheImpl::kAXValueChanged); 302 AXObjectCacheImpl::kAXValueChanged);
243 } 303 }
244 304
245 AXObject* AXNodeObject::ActiveDescendant() { 305 AXObject* AXNodeObject::ActiveDescendant() {
246 if (!node_ || !node_->IsElementNode()) 306 Element* element = GetElement();
307 if (!element)
247 return nullptr; 308 return nullptr;
248 309
249 const AtomicString& active_descendant_attr =
250 GetAttribute(aria_activedescendantAttr);
251 if (active_descendant_attr.IsNull() || active_descendant_attr.IsEmpty())
252 return nullptr;
253
254 Element* element = ToElement(GetNode());
255 Element* descendant = 310 Element* descendant =
256 element->GetTreeScope().getElementById(active_descendant_attr); 311 GetAOMPropertyOrARIAAttribute(AOMRelationProperty::kActiveDescendant);
257 if (!descendant) 312 if (!descendant)
258 return nullptr; 313 return nullptr;
259 314
260 AXObject* ax_descendant = AxObjectCache().GetOrCreate(descendant); 315 AXObject* ax_descendant = AxObjectCache().GetOrCreate(descendant);
261 return ax_descendant; 316 return ax_descendant;
262 } 317 }
263 318
264 bool AXNodeObject::ComputeAccessibilityIsIgnored( 319 bool AXNodeObject::ComputeAccessibilityIsIgnored(
265 IgnoredReasons* ignored_reasons) const { 320 IgnoredReasons* ignored_reasons) const {
266 #if DCHECK_IS_ON() 321 #if DCHECK_IS_ON()
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 role_ = DetermineAccessibilityRole(); 963 role_ = DetermineAccessibilityRole();
909 } 964 }
910 965
911 void AXNodeObject::Detach() { 966 void AXNodeObject::Detach() {
912 AXObject::Detach(); 967 AXObject::Detach();
913 node_ = nullptr; 968 node_ = nullptr;
914 } 969 }
915 970
916 void AXNodeObject::GetSparseAXAttributes( 971 void AXNodeObject::GetSparseAXAttributes(
917 AXSparseAttributeClient& sparse_attribute_client) const { 972 AXSparseAttributeClient& sparse_attribute_client) const {
918 Node* node = this->GetNode(); 973 Element* element = GetElement();
919 if (!node || !node->IsElementNode()) 974 if (!element)
920 return; 975 return;
921 976
977 AXSparseAttributeAOMPropertyClient property_client(*ax_object_cache_,
978 sparse_attribute_client);
979 HashSet<QualifiedName> shadowed_aria_attributes;
980 AccessibleNode::GetAllAOMProperties(element, &property_client,
981 shadowed_aria_attributes);
982
922 AXSparseAttributeSetterMap& ax_sparse_attribute_setter_map = 983 AXSparseAttributeSetterMap& ax_sparse_attribute_setter_map =
923 GetSparseAttributeSetterMap(); 984 GetSparseAttributeSetterMap();
924 AttributeCollection attributes = ToElement(node)->AttributesWithoutUpdate(); 985 AttributeCollection attributes = element->AttributesWithoutUpdate();
925 for (const Attribute& attr : attributes) { 986 for (const Attribute& attr : attributes) {
987 if (shadowed_aria_attributes.Contains(attr.GetName()))
988 continue;
989
926 SparseAttributeSetter* setter = 990 SparseAttributeSetter* setter =
927 ax_sparse_attribute_setter_map.at(attr.GetName()); 991 ax_sparse_attribute_setter_map.at(attr.GetName());
928 if (setter) 992 if (setter)
929 setter->Run(*this, sparse_attribute_client, attr.Value()); 993 setter->Run(*this, sparse_attribute_client, attr.Value());
930 } 994 }
931
932 // TODO(dmazzoni): Efficiently iterate over AccessibleNode properties that are
933 // set and merge the two loops somehow.
934 if (ToElement(node)->ExistingAccessibleNode()) {
935 AtomicString key_shortcuts =
936 GetAOMPropertyOrARIAAttribute(AOMStringProperty::kKeyShortcuts);
937 if (!key_shortcuts.IsNull()) {
938 ax_sparse_attribute_setter_map.at(aria_keyshortcutsAttr)
939 ->Run(*this, sparse_attribute_client, key_shortcuts);
940 }
941 AtomicString role_description =
942 GetAOMPropertyOrARIAAttribute(AOMStringProperty::kRoleDescription);
943 if (!role_description.IsNull()) {
944 ax_sparse_attribute_setter_map.at(aria_roledescriptionAttr)
945 ->Run(*this, sparse_attribute_client, role_description);
946 }
947 }
948 } 995 }
949 996
950 bool AXNodeObject::IsAnchor() const { 997 bool AXNodeObject::IsAnchor() const {
951 return !IsNativeImage() && IsLink(); 998 return !IsNativeImage() && IsLink();
952 } 999 }
953 1000
954 bool AXNodeObject::IsControl() const { 1001 bool AXNodeObject::IsControl() const {
955 Node* node = this->GetNode(); 1002 Node* node = this->GetNode();
956 if (!node) 1003 if (!node)
957 return false; 1004 return false;
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 return String(); 3258 return String();
3212 return ToTextControlElement(node)->StrippedPlaceholder(); 3259 return ToTextControlElement(node)->StrippedPlaceholder();
3213 } 3260 }
3214 3261
3215 DEFINE_TRACE(AXNodeObject) { 3262 DEFINE_TRACE(AXNodeObject) {
3216 visitor->Trace(node_); 3263 visitor->Trace(node_);
3217 AXObject::Trace(visitor); 3264 AXObject::Trace(visitor);
3218 } 3265 }
3219 3266
3220 } // namespace blink 3267 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/AccessibleNode.idl ('k') | third_party/WebKit/Source/modules/accessibility/AXObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698