Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 m_childrenDirty(false), | 220 m_childrenDirty(false), |
| 221 m_node(node) { | 221 m_node(node) { |
| 222 } | 222 } |
| 223 | 223 |
| 224 AXNodeObject* AXNodeObject::create(Node* node, | 224 AXNodeObject* AXNodeObject::create(Node* node, |
| 225 AXObjectCacheImpl& axObjectCache) { | 225 AXObjectCacheImpl& axObjectCache) { |
| 226 return new AXNodeObject(node, axObjectCache); | 226 return new AXNodeObject(node, axObjectCache); |
| 227 } | 227 } |
| 228 | 228 |
| 229 AXNodeObject::~AXNodeObject() { | 229 AXNodeObject::~AXNodeObject() { |
| 230 ASSERT(!m_node); | 230 DCHECK(!m_node); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void AXNodeObject::alterSliderValue(bool increase) { | 233 void AXNodeObject::alterSliderValue(bool increase) { |
| 234 if (roleValue() != SliderRole) | 234 if (roleValue() != SliderRole) |
| 235 return; | 235 return; |
| 236 | 236 |
| 237 float value = valueForRange(); | 237 float value = valueForRange(); |
| 238 float step = stepValueForRange(); | 238 float step = stepValueForRange(); |
| 239 | 239 |
| 240 value += increase ? step : -step; | 240 value += increase ? step : -step; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 261 | 261 |
| 262 AXObject* axDescendant = axObjectCache().getOrCreate(descendant); | 262 AXObject* axDescendant = axObjectCache().getOrCreate(descendant); |
| 263 return axDescendant; | 263 return axDescendant; |
| 264 } | 264 } |
| 265 | 265 |
| 266 bool AXNodeObject::computeAccessibilityIsIgnored( | 266 bool AXNodeObject::computeAccessibilityIsIgnored( |
| 267 IgnoredReasons* ignoredReasons) const { | 267 IgnoredReasons* ignoredReasons) const { |
| 268 #if DCHECK_IS_ON() | 268 #if DCHECK_IS_ON() |
| 269 // Double-check that an AXObject is never accessed before | 269 // Double-check that an AXObject is never accessed before |
| 270 // it's been initialized. | 270 // it's been initialized. |
| 271 ASSERT(m_initialized); | 271 DCHECK(m_initialized); |
| 272 #endif | 272 #endif |
| 273 | 273 |
| 274 // If this element is within a parent that cannot have children, it should not | 274 // If this element is within a parent that cannot have children, it should not |
| 275 // be exposed. | 275 // be exposed. |
| 276 if (isDescendantOfLeafNode()) { | 276 if (isDescendantOfLeafNode()) { |
| 277 if (ignoredReasons) | 277 if (ignoredReasons) |
| 278 ignoredReasons->push_back( | 278 ignoredReasons->push_back( |
| 279 IgnoredReason(AXAncestorIsLeafNode, leafNodeAncestor())); | 279 IgnoredReason(AXAncestorIsLeafNode, leafNodeAncestor())); |
| 280 return true; | 280 return true; |
| 281 } | 281 } |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 // searching up the chain. | 897 // searching up the chain. |
| 898 if (parentAriaRole) | 898 if (parentAriaRole) |
| 899 break; | 899 break; |
| 900 } | 900 } |
| 901 | 901 |
| 902 return role; | 902 return role; |
| 903 } | 903 } |
| 904 | 904 |
| 905 void AXNodeObject::init() { | 905 void AXNodeObject::init() { |
| 906 #if DCHECK_IS_ON() | 906 #if DCHECK_IS_ON() |
| 907 ASSERT(!m_initialized); | 907 DCHECK(!m_initialized); |
| 908 m_initialized = true; | 908 m_initialized = true; |
| 909 #endif | 909 #endif |
| 910 m_role = determineAccessibilityRole(); | 910 m_role = determineAccessibilityRole(); |
| 911 } | 911 } |
| 912 | 912 |
| 913 void AXNodeObject::detach() { | 913 void AXNodeObject::detach() { |
| 914 AXObject::detach(); | 914 AXObject::detach(); |
| 915 m_node = nullptr; | 915 m_node = nullptr; |
| 916 } | 916 } |
| 917 | 917 |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1869 | 1869 |
| 1870 String AXNodeObject::textAlternative(bool recursive, | 1870 String AXNodeObject::textAlternative(bool recursive, |
| 1871 bool inAriaLabelledByTraversal, | 1871 bool inAriaLabelledByTraversal, |
| 1872 AXObjectSet& visited, | 1872 AXObjectSet& visited, |
| 1873 AXNameFrom& nameFrom, | 1873 AXNameFrom& nameFrom, |
| 1874 AXRelatedObjectVector* relatedObjects, | 1874 AXRelatedObjectVector* relatedObjects, |
| 1875 NameSources* nameSources) const { | 1875 NameSources* nameSources) const { |
| 1876 // If nameSources is non-null, relatedObjects is used in filling it in, so it | 1876 // If nameSources is non-null, relatedObjects is used in filling it in, so it |
| 1877 // must be non-null as well. | 1877 // must be non-null as well. |
| 1878 if (nameSources) | 1878 if (nameSources) |
| 1879 ASSERT(relatedObjects); | 1879 DCHECK(relatedObjects); |
| 1880 | 1880 |
| 1881 bool foundTextAlternative = false; | 1881 bool foundTextAlternative = false; |
| 1882 | 1882 |
| 1883 if (!getNode() && !getLayoutObject()) | 1883 if (!getNode() && !getLayoutObject()) |
| 1884 return String(); | 1884 return String(); |
| 1885 | 1885 |
| 1886 String textAlternative = ariaTextAlternative( | 1886 String textAlternative = ariaTextAlternative( |
| 1887 recursive, inAriaLabelledByTraversal, visited, nameFrom, relatedObjects, | 1887 recursive, inAriaLabelledByTraversal, visited, nameFrom, relatedObjects, |
| 1888 nameSources, &foundTextAlternative); | 1888 nameSources, &foundTextAlternative); |
| 1889 if (foundTextAlternative && !nameSources) | 1889 if (foundTextAlternative && !nameSources) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2156 if (isHTMLOptionElement(node)) | 2156 if (isHTMLOptionElement(node)) |
| 2157 parentNode = toHTMLOptionElement(node)->ownerSelectElement(); | 2157 parentNode = toHTMLOptionElement(node)->ownerSelectElement(); |
| 2158 | 2158 |
| 2159 if (!parentNode) | 2159 if (!parentNode) |
| 2160 parentNode = node->parentNode(); | 2160 parentNode = node->parentNode(); |
| 2161 | 2161 |
| 2162 return parentNode; | 2162 return parentNode; |
| 2163 } | 2163 } |
| 2164 | 2164 |
| 2165 AXObject* AXNodeObject::computeParent() const { | 2165 AXObject* AXNodeObject::computeParent() const { |
| 2166 ASSERT(!isDetached()); | 2166 DCHECK(!isDetached()); |
| 2167 if (Node* parentNode = getParentNodeForComputeParent(getNode())) | 2167 if (Node* parentNode = getParentNodeForComputeParent(getNode())) |
| 2168 return axObjectCache().getOrCreate(parentNode); | 2168 return axObjectCache().getOrCreate(parentNode); |
| 2169 | 2169 |
| 2170 return nullptr; | 2170 return nullptr; |
| 2171 } | 2171 } |
| 2172 | 2172 |
| 2173 AXObject* AXNodeObject::computeParentIfExists() const { | 2173 AXObject* AXNodeObject::computeParentIfExists() const { |
| 2174 if (Node* parentNode = getParentNodeForComputeParent(getNode())) | 2174 if (Node* parentNode = getParentNodeForComputeParent(getNode())) |
| 2175 return axObjectCache().get(parentNode); | 2175 return axObjectCache().get(parentNode); |
| 2176 | 2176 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2194 return 0; | 2194 return 0; |
| 2195 | 2195 |
| 2196 Node* nextSibling = getNode()->nextSibling(); | 2196 Node* nextSibling = getNode()->nextSibling(); |
| 2197 if (!nextSibling) | 2197 if (!nextSibling) |
| 2198 return 0; | 2198 return 0; |
| 2199 | 2199 |
| 2200 return axObjectCache().getOrCreate(nextSibling); | 2200 return axObjectCache().getOrCreate(nextSibling); |
| 2201 } | 2201 } |
| 2202 | 2202 |
| 2203 void AXNodeObject::addChildren() { | 2203 void AXNodeObject::addChildren() { |
| 2204 ASSERT(!isDetached()); | 2204 DCHECK(!isDetached()); |
| 2205 // If the need to add more children in addition to existing children arises, | 2205 // If the need to add more children in addition to existing children arises, |
| 2206 // childrenChanged should have been called, leaving the object with no | 2206 // childrenChanged should have been called, leaving the object with no |
| 2207 // children. | 2207 // children. |
| 2208 ASSERT(!m_haveChildren); | 2208 DCHECK(!m_haveChildren); |
| 2209 | 2209 |
| 2210 if (!m_node) | 2210 if (!m_node) |
| 2211 return; | 2211 return; |
| 2212 | 2212 |
| 2213 m_haveChildren = true; | 2213 m_haveChildren = true; |
| 2214 | 2214 |
| 2215 // The only time we add children from the DOM tree to a node with a | 2215 // The only time we add children from the DOM tree to a node with a |
| 2216 // layoutObject is when it's a canvas. | 2216 // layoutObject is when it's a canvas. |
| 2217 if (getLayoutObject() && !isHTMLCanvasElement(*m_node)) | 2217 if (getLayoutObject() && !isHTMLCanvasElement(*m_node)) |
| 2218 return; | 2218 return; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 2247 // aria-hidden changes from working correctly. Hence, whenever a parent is | 2247 // aria-hidden changes from working correctly. Hence, whenever a parent is |
| 2248 // getting children, ensure data is not stale. | 2248 // getting children, ensure data is not stale. |
| 2249 child->clearChildren(); | 2249 child->clearChildren(); |
| 2250 | 2250 |
| 2251 if (child->accessibilityIsIgnored()) { | 2251 if (child->accessibilityIsIgnored()) { |
| 2252 const auto& children = child->children(); | 2252 const auto& children = child->children(); |
| 2253 size_t length = children.size(); | 2253 size_t length = children.size(); |
| 2254 for (size_t i = 0; i < length; ++i) | 2254 for (size_t i = 0; i < length; ++i) |
| 2255 m_children.insert(index + i, children[i]); | 2255 m_children.insert(index + i, children[i]); |
| 2256 } else { | 2256 } else { |
| 2257 ASSERT(child->parentObject() == this); | 2257 DCHECK(child->parentObject() == this); |
|
tkent
2017/04/09 23:21:23
Use DCHECK_EQ
| |
| 2258 m_children.insert(index, child); | 2258 m_children.insert(index, child); |
| 2259 } | 2259 } |
| 2260 } | 2260 } |
| 2261 | 2261 |
| 2262 bool AXNodeObject::canHaveChildren() const { | 2262 bool AXNodeObject::canHaveChildren() const { |
| 2263 // If this is an AXLayoutObject, then it's okay if this object | 2263 // If this is an AXLayoutObject, then it's okay if this object |
| 2264 // doesn't have a node - there are some layoutObjects that don't have | 2264 // doesn't have a node - there are some layoutObjects that don't have |
| 2265 // associated nodes, like scroll areas and css-generated text. | 2265 // associated nodes, like scroll areas and css-generated text. |
| 2266 if (!getNode() && !isAXLayoutObject()) | 2266 if (!getNode() && !isAXLayoutObject()) |
| 2267 return false; | 2267 return false; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2564 AXNameFrom& nameFrom, | 2564 AXNameFrom& nameFrom, |
| 2565 AXRelatedObjectVector* relatedObjects, | 2565 AXRelatedObjectVector* relatedObjects, |
| 2566 NameSources* nameSources, | 2566 NameSources* nameSources, |
| 2567 bool* foundTextAlternative) const { | 2567 bool* foundTextAlternative) const { |
| 2568 if (!getNode()) | 2568 if (!getNode()) |
| 2569 return String(); | 2569 return String(); |
| 2570 | 2570 |
| 2571 // If nameSources is non-null, relatedObjects is used in filling it in, so it | 2571 // If nameSources is non-null, relatedObjects is used in filling it in, so it |
| 2572 // must be non-null as well. | 2572 // must be non-null as well. |
| 2573 if (nameSources) | 2573 if (nameSources) |
| 2574 ASSERT(relatedObjects); | 2574 DCHECK(relatedObjects); |
| 2575 | 2575 |
| 2576 String textAlternative; | 2576 String textAlternative; |
| 2577 AXRelatedObjectVector localRelatedObjects; | 2577 AXRelatedObjectVector localRelatedObjects; |
| 2578 | 2578 |
| 2579 const HTMLInputElement* inputElement = nullptr; | 2579 const HTMLInputElement* inputElement = nullptr; |
| 2580 if (isHTMLInputElement(getNode())) | 2580 if (isHTMLInputElement(getNode())) |
| 2581 inputElement = toHTMLInputElement(getNode()); | 2581 inputElement = toHTMLInputElement(getNode()); |
| 2582 | 2582 |
| 2583 // 5.1/5.5 Text inputs, Other labelable Elements | 2583 // 5.1/5.5 Text inputs, Other labelable Elements |
| 2584 // If you change this logic, update AXNodeObject::nameFromLabelElement, too. | 2584 // If you change this logic, update AXNodeObject::nameFromLabelElement, too. |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2900 } | 2900 } |
| 2901 | 2901 |
| 2902 // Per SVG AAM 1.0's modifications to 2D of this algorithm. | 2902 // Per SVG AAM 1.0's modifications to 2D of this algorithm. |
| 2903 if (getNode()->isSVGElement()) { | 2903 if (getNode()->isSVGElement()) { |
| 2904 nameFrom = AXNameFromRelatedElement; | 2904 nameFrom = AXNameFromRelatedElement; |
| 2905 if (nameSources) { | 2905 if (nameSources) { |
| 2906 nameSources->push_back(NameSource(*foundTextAlternative)); | 2906 nameSources->push_back(NameSource(*foundTextAlternative)); |
| 2907 nameSources->back().type = nameFrom; | 2907 nameSources->back().type = nameFrom; |
| 2908 nameSources->back().nativeSource = AXTextFromNativeHTMLTitleElement; | 2908 nameSources->back().nativeSource = AXTextFromNativeHTMLTitleElement; |
| 2909 } | 2909 } |
| 2910 ASSERT(getNode()->isContainerNode()); | 2910 DCHECK(getNode()->isContainerNode()); |
| 2911 Element* title = ElementTraversal::firstChild( | 2911 Element* title = ElementTraversal::firstChild( |
| 2912 toContainerNode(*(getNode())), HasTagName(SVGNames::titleTag)); | 2912 toContainerNode(*(getNode())), HasTagName(SVGNames::titleTag)); |
| 2913 | 2913 |
| 2914 if (title) { | 2914 if (title) { |
| 2915 AXObject* titleAXObject = axObjectCache().getOrCreate(title); | 2915 AXObject* titleAXObject = axObjectCache().getOrCreate(title); |
| 2916 if (titleAXObject && !visited.contains(titleAXObject)) { | 2916 if (titleAXObject && !visited.contains(titleAXObject)) { |
| 2917 textAlternative = | 2917 textAlternative = |
| 2918 recursiveTextAlternative(*titleAXObject, false, visited); | 2918 recursiveTextAlternative(*titleAXObject, false, visited); |
| 2919 if (relatedObjects) { | 2919 if (relatedObjects) { |
| 2920 localRelatedObjects.push_back( | 2920 localRelatedObjects.push_back( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3047 | 3047 |
| 3048 // Based on | 3048 // Based on |
| 3049 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html#accessible-name-and- description-calculation | 3049 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html#accessible-name-and- description-calculation |
| 3050 String AXNodeObject::description(AXNameFrom nameFrom, | 3050 String AXNodeObject::description(AXNameFrom nameFrom, |
| 3051 AXDescriptionFrom& descriptionFrom, | 3051 AXDescriptionFrom& descriptionFrom, |
| 3052 DescriptionSources* descriptionSources, | 3052 DescriptionSources* descriptionSources, |
| 3053 AXRelatedObjectVector* relatedObjects) const { | 3053 AXRelatedObjectVector* relatedObjects) const { |
| 3054 // If descriptionSources is non-null, relatedObjects is used in filling it in, | 3054 // If descriptionSources is non-null, relatedObjects is used in filling it in, |
| 3055 // so it must be non-null as well. | 3055 // so it must be non-null as well. |
| 3056 if (descriptionSources) | 3056 if (descriptionSources) |
| 3057 ASSERT(relatedObjects); | 3057 DCHECK(relatedObjects); |
| 3058 | 3058 |
| 3059 if (!getNode()) | 3059 if (!getNode()) |
| 3060 return String(); | 3060 return String(); |
| 3061 | 3061 |
| 3062 String description; | 3062 String description; |
| 3063 bool foundDescription = false; | 3063 bool foundDescription = false; |
| 3064 | 3064 |
| 3065 descriptionFrom = AXDescriptionFromRelatedElement; | 3065 descriptionFrom = AXDescriptionFromRelatedElement; |
| 3066 if (descriptionSources) { | 3066 if (descriptionSources) { |
| 3067 descriptionSources->push_back( | 3067 descriptionSources->push_back( |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3261 return String(); | 3261 return String(); |
| 3262 return toTextControlElement(node)->strippedPlaceholder(); | 3262 return toTextControlElement(node)->strippedPlaceholder(); |
| 3263 } | 3263 } |
| 3264 | 3264 |
| 3265 DEFINE_TRACE(AXNodeObject) { | 3265 DEFINE_TRACE(AXNodeObject) { |
| 3266 visitor->trace(m_node); | 3266 visitor->trace(m_node); |
| 3267 AXObject::trace(visitor); | 3267 AXObject::trace(visitor); |
| 3268 } | 3268 } |
| 3269 | 3269 |
| 3270 } // namespace blink | 3270 } // namespace blink |
| OLD | NEW |