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

Side by Side Diff: Source/core/accessibility/AXRenderObject.cpp

Issue 189963007: Use isHTML*Element() helpers more in the accessibility code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/accessibility/AXObjectCache.cpp ('k') | Source/core/accessibility/AXTable.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 303
304 if (cssBox && cssBox->isRenderView()) 304 if (cssBox && cssBox->isRenderView())
305 return WebAreaRole; 305 return WebAreaRole;
306 306
307 if (cssBox && cssBox->isTextField()) 307 if (cssBox && cssBox->isTextField())
308 return TextFieldRole; 308 return TextFieldRole;
309 309
310 if (cssBox && cssBox->isTextArea()) 310 if (cssBox && cssBox->isTextArea())
311 return TextAreaRole; 311 return TextAreaRole;
312 312
313 if (node && node->hasTagName(inputTag)) { 313 if (isHTMLInputElement(node)) {
314 HTMLInputElement* input = toHTMLInputElement(node); 314 HTMLInputElement& input = toHTMLInputElement(*node);
315 if (input->isCheckbox()) 315 if (input.isCheckbox())
316 return CheckBoxRole; 316 return CheckBoxRole;
317 if (input->isRadioButton()) 317 if (input.isRadioButton())
318 return RadioButtonRole; 318 return RadioButtonRole;
319 if (input->isTextButton()) 319 if (input.isTextButton())
320 return buttonRoleType(); 320 return buttonRoleType();
321 321
322 const AtomicString& type = input->getAttribute(typeAttr); 322 const AtomicString& type = input.getAttribute(typeAttr);
323 if (equalIgnoringCase(type, "color")) 323 if (equalIgnoringCase(type, "color"))
324 return ColorWellRole; 324 return ColorWellRole;
325 } 325 }
326 326
327 if (isFileUploadButton()) 327 if (isFileUploadButton())
328 return ButtonRole; 328 return ButtonRole;
329 329
330 if (cssBox && cssBox->isMenuList()) 330 if (cssBox && cssBox->isMenuList())
331 return PopUpButtonRole; 331 return PopUpButtonRole;
332 332
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 if (!renderer) 439 if (!renderer)
440 return false; 440 return false;
441 // Widgets are the replaced elements that we represent to AX as attachments 441 // Widgets are the replaced elements that we represent to AX as attachments
442 bool isWidget = renderer->isWidget(); 442 bool isWidget = renderer->isWidget();
443 ASSERT(!isWidget || (renderer->isReplaced() && !isImage())); 443 ASSERT(!isWidget || (renderer->isReplaced() && !isImage()));
444 return isWidget; 444 return isWidget;
445 } 445 }
446 446
447 bool AXRenderObject::isFileUploadButton() const 447 bool AXRenderObject::isFileUploadButton() const
448 { 448 {
449 if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(input Tag)) { 449 if (m_renderer && isHTMLInputElement(m_renderer->node())) {
450 HTMLInputElement* input = toHTMLInputElement(m_renderer->node()); 450 HTMLInputElement& input = toHTMLInputElement(*m_renderer->node());
451 return input->isFileUpload(); 451 return input.isFileUpload();
452 } 452 }
453 453
454 return false; 454 return false;
455 } 455 }
456 456
457 static bool isLinkable(const AXObject& object) 457 static bool isLinkable(const AXObject& object)
458 { 458 {
459 if (!object.renderer()) 459 if (!object.renderer())
460 return false; 460 return false;
461 461
462 // See https://wiki.mozilla.org/Accessibility/AT-Windows-API for the element s 462 // See https://wiki.mozilla.org/Accessibility/AT-Windows-API for the element s
463 // Mozilla considers linkable. 463 // Mozilla considers linkable.
464 return object.isLink() || object.isImage() || object.renderer()->isText(); 464 return object.isLink() || object.isImage() || object.renderer()->isText();
465 } 465 }
466 466
467 bool AXRenderObject::isLinked() const 467 bool AXRenderObject::isLinked() const
468 { 468 {
469 if (!isLinkable(*this)) 469 if (!isLinkable(*this))
470 return false; 470 return false;
471 471
472 Element* anchor = anchorElement(); 472 Element* anchor = anchorElement();
473 if (!anchor || !anchor->hasTagName(aTag)) 473 if (!isHTMLAnchorElement(anchor))
474 return false; 474 return false;
475 475
476 return !toHTMLAnchorElement(anchor)->href().isEmpty(); 476 return !toHTMLAnchorElement(*anchor).href().isEmpty();
477 } 477 }
478 478
479 bool AXRenderObject::isLoaded() const 479 bool AXRenderObject::isLoaded() const
480 { 480 {
481 return !m_renderer->document().parser(); 481 return !m_renderer->document().parser();
482 } 482 }
483 483
484 bool AXRenderObject::isOffScreen() const 484 bool AXRenderObject::isOffScreen() const
485 { 485 {
486 ASSERT(m_renderer); 486 ASSERT(m_renderer);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 ASSERT(isTextControl()); 801 ASSERT(isTextControl());
802 802
803 if (isPasswordField()) 803 if (isPasswordField())
804 return -1; // need to return something distinct from 0 804 return -1; // need to return something distinct from 0
805 805
806 return text().length(); 806 return text().length();
807 } 807 }
808 808
809 KURL AXRenderObject::url() const 809 KURL AXRenderObject::url() const
810 { 810 {
811 if (isAnchor() && m_renderer->node()->hasTagName(aTag)) { 811 if (isAnchor() && isHTMLAnchorElement(m_renderer->node())) {
812 if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement())) 812 if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement()))
813 return anchor->href(); 813 return anchor->href();
814 } 814 }
815 815
816 if (isWebArea()) 816 if (isWebArea())
817 return m_renderer->document().url(); 817 return m_renderer->document().url();
818 818
819 if (isImage() && m_renderer->node() && m_renderer->node()->hasTagName(imgTag )) 819 if (isImage() && isHTMLImageElement(m_renderer->node()))
820 return toHTMLImageElement(m_renderer->node())->src(); 820 return toHTMLImageElement(*m_renderer->node()).src();
821 821
822 if (isInputImage()) 822 if (isInputImage())
823 return toHTMLInputElement(m_renderer->node())->src(); 823 return toHTMLInputElement(m_renderer->node())->src();
824 824
825 return KURL(); 825 return KURL();
826 } 826 }
827 827
828 // 828 //
829 // Properties of interactive elements. 829 // Properties of interactive elements.
830 // 830 //
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 1257
1258 RenderLayer* layer = toRenderBox(m_renderer)->layer(); 1258 RenderLayer* layer = toRenderBox(m_renderer)->layer();
1259 1259
1260 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); 1260 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
1261 HitTestResult hitTestResult = HitTestResult(point); 1261 HitTestResult hitTestResult = HitTestResult(point);
1262 layer->hitTest(request, hitTestResult); 1262 layer->hitTest(request, hitTestResult);
1263 if (!hitTestResult.innerNode()) 1263 if (!hitTestResult.innerNode())
1264 return 0; 1264 return 0;
1265 Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode(); 1265 Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
1266 1266
1267 if (node->hasTagName(areaTag)) 1267 if (isHTMLAreaElement(node))
1268 return accessibilityImageMapHitTest(toHTMLAreaElement(node), point); 1268 return accessibilityImageMapHitTest(toHTMLAreaElement(node), point);
1269 1269
1270 if (node->hasTagName(optionTag)) 1270 if (isHTMLOptionElement(node))
1271 node = toHTMLOptionElement(node)->ownerSelectElement(); 1271 node = toHTMLOptionElement(*node).ownerSelectElement();
1272 1272
1273 RenderObject* obj = node->renderer(); 1273 RenderObject* obj = node->renderer();
1274 if (!obj) 1274 if (!obj)
1275 return 0; 1275 return 0;
1276 1276
1277 AXObject* result = obj->document().axObjectCache()->getOrCreate(obj); 1277 AXObject* result = obj->document().axObjectCache()->getOrCreate(obj);
1278 result->updateChildrenIfNecessary(); 1278 result->updateChildrenIfNecessary();
1279 1279
1280 // Allow the element to perform any hit-testing it might need to do to reach non-render children. 1280 // Allow the element to perform any hit-testing it might need to do to reach non-render children.
1281 result = result->elementAccessibilityHitTest(point); 1281 result = result->elementAccessibilityHitTest(point);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 } 1589 }
1590 1590
1591 void AXRenderObject::setValue(const String& string) 1591 void AXRenderObject::setValue(const String& string)
1592 { 1592 {
1593 if (!node() || !node()->isElementNode()) 1593 if (!node() || !node()->isElementNode())
1594 return; 1594 return;
1595 if (!m_renderer || !m_renderer->isBoxModelObject()) 1595 if (!m_renderer || !m_renderer->isBoxModelObject())
1596 return; 1596 return;
1597 1597
1598 RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer); 1598 RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
1599 if (renderer->isTextField() && node()->hasTagName(inputTag)) { 1599 if (renderer->isTextField() && isHTMLInputElement(*node()))
1600 toHTMLInputElement(node())->setValue(string); 1600 toHTMLInputElement(*node()).setValue(string);
1601 } else if (renderer->isTextArea() && node()->hasTagName(textareaTag)) { 1601 else if (renderer->isTextArea() && isHTMLTextAreaElement(*node()))
1602 toHTMLTextAreaElement(node())->setValue(string); 1602 toHTMLTextAreaElement(*node()).setValue(string);
1603 }
1604 } 1603 }
1605 1604
1606 // FIXME: This function should use an IntSize to avoid the conversion below. 1605 // FIXME: This function should use an IntSize to avoid the conversion below.
1607 void AXRenderObject::scrollTo(const IntPoint& point) const 1606 void AXRenderObject::scrollTo(const IntPoint& point) const
1608 { 1607 {
1609 if (!m_renderer || !m_renderer->isBox()) 1608 if (!m_renderer || !m_renderer->isBox())
1610 return; 1609 return;
1611 1610
1612 RenderBox* box = toRenderBox(m_renderer); 1611 RenderBox* box = toRenderBox(m_renderer);
1613 if (!box->canBeScrolledAndHasScrollableArea()) 1612 if (!box->canBeScrolledAndHasScrollableArea())
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 checkFocusElement = checkFocusElement->parentObject(); 1889 checkFocusElement = checkFocusElement->parentObject();
1891 } 1890 }
1892 } 1891 }
1893 1892
1894 return false; 1893 return false;
1895 } 1894 }
1896 1895
1897 AXObject* AXRenderObject::internalLinkElement() const 1896 AXObject* AXRenderObject::internalLinkElement() const
1898 { 1897 {
1899 Element* element = anchorElement(); 1898 Element* element = anchorElement();
1900 if (!element) 1899 // Right now, we do not support ARIA links as internal link elements
1900 if (!isHTMLAnchorElement(element))
1901 return 0; 1901 return 0;
1902 HTMLAnchorElement& anchor = toHTMLAnchorElement(*element);
1902 1903
1903 // Right now, we do not support ARIA links as internal link elements 1904 KURL linkURL = anchor.href();
1904 if (!element->hasTagName(aTag))
1905 return 0;
1906 HTMLAnchorElement* anchor = toHTMLAnchorElement(element);
1907
1908 KURL linkURL = anchor->href();
1909 String fragmentIdentifier = linkURL.fragmentIdentifier(); 1905 String fragmentIdentifier = linkURL.fragmentIdentifier();
1910 if (fragmentIdentifier.isEmpty()) 1906 if (fragmentIdentifier.isEmpty())
1911 return 0; 1907 return 0;
1912 1908
1913 // check if URL is the same as current URL 1909 // check if URL is the same as current URL
1914 KURL documentURL = m_renderer->document().url(); 1910 KURL documentURL = m_renderer->document().url();
1915 if (!equalIgnoringFragmentIdentifier(documentURL, linkURL)) 1911 if (!equalIgnoringFragmentIdentifier(documentURL, linkURL))
1916 return 0; 1912 return 0;
1917 1913
1918 Node* linkedNode = m_renderer->document().findAnchor(fragmentIdentifier); 1914 Node* linkedNode = m_renderer->document().findAnchor(fragmentIdentifier);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 insertionIndex = previousSize; 2125 insertionIndex = previousSize;
2130 2126
2131 insertChild(axObjectCache()->getOrCreate(child), insertionIndex); 2127 insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
2132 insertionIndex += (m_children.size() - previousSize); 2128 insertionIndex += (m_children.size() - previousSize);
2133 } 2129 }
2134 } 2130 }
2135 2131
2136 void AXRenderObject::addTextFieldChildren() 2132 void AXRenderObject::addTextFieldChildren()
2137 { 2133 {
2138 Node* node = this->node(); 2134 Node* node = this->node();
2139 if (!node || !node->hasTagName(inputTag)) 2135 if (!isHTMLInputElement(node))
2140 return; 2136 return;
2141 2137
2142 HTMLInputElement* input = toHTMLInputElement(node); 2138 HTMLInputElement& input = toHTMLInputElement(*node);
2143 Element* spinButtonElement = input->userAgentShadowRoot()->getElementById(Sh adowElementNames::spinButton()); 2139 Element* spinButtonElement = input.userAgentShadowRoot()->getElementById(Sha dowElementNames::spinButton());
2144 if (!spinButtonElement || !spinButtonElement->isSpinButtonElement()) 2140 if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
2145 return; 2141 return;
2146 2142
2147 AXSpinButton* axSpinButton = toAXSpinButton(axObjectCache()->getOrCreate(Spi nButtonRole)); 2143 AXSpinButton* axSpinButton = toAXSpinButton(axObjectCache()->getOrCreate(Spi nButtonRole));
2148 axSpinButton->setSpinButtonElement(toSpinButtonElement(spinButtonElement)); 2144 axSpinButton->setSpinButtonElement(toSpinButtonElement(spinButtonElement));
2149 axSpinButton->setParent(this); 2145 axSpinButton->setParent(this);
2150 m_children.append(axSpinButton); 2146 m_children.append(axSpinButton);
2151 } 2147 }
2152 2148
2153 void AXRenderObject::addImageMapChildren() 2149 void AXRenderObject::addImageMapChildren()
2154 { 2150 {
2155 RenderBoxModelObject* cssBox = renderBoxModelObject(); 2151 RenderBoxModelObject* cssBox = renderBoxModelObject();
2156 if (!cssBox || !cssBox->isRenderImage()) 2152 if (!cssBox || !cssBox->isRenderImage())
2157 return; 2153 return;
2158 2154
2159 HTMLMapElement* map = toRenderImage(cssBox)->imageMap(); 2155 HTMLMapElement* map = toRenderImage(cssBox)->imageMap();
2160 if (!map) 2156 if (!map)
2161 return; 2157 return;
2162 2158
2163 for (Element* current = ElementTraversal::firstWithin(*map); current; curren t = ElementTraversal::next(*current, map)) { 2159 for (Element* current = ElementTraversal::firstWithin(*map); current; curren t = ElementTraversal::next(*current, map)) {
2164 // add an <area> element for this child if it has a link 2160 // add an <area> element for this child if it has a link
2165 if (current->hasTagName(areaTag) && current->isLink()) { 2161 if (isHTMLAreaElement(*current) && current->isLink()) {
2166 AXImageMapLink* areaObject = toAXImageMapLink(axObjectCache()->getOr Create(ImageMapLinkRole)); 2162 AXImageMapLink* areaObject = toAXImageMapLink(axObjectCache()->getOr Create(ImageMapLinkRole));
2167 areaObject->setHTMLAreaElement(toHTMLAreaElement(current)); 2163 areaObject->setHTMLAreaElement(toHTMLAreaElement(current));
2168 areaObject->setHTMLMapElement(map); 2164 areaObject->setHTMLMapElement(map);
2169 areaObject->setParent(this); 2165 areaObject->setParent(this);
2170 if (!areaObject->accessibilityIsIgnored()) 2166 if (!areaObject->accessibilityIsIgnored())
2171 m_children.append(areaObject); 2167 m_children.append(areaObject);
2172 else 2168 else
2173 axObjectCache()->remove(areaObject->axObjectID()); 2169 axObjectCache()->remove(areaObject->axObjectID());
2174 } 2170 }
2175 } 2171 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 if (label && label->renderer()) { 2319 if (label && label->renderer()) {
2324 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect(); 2320 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect();
2325 result.unite(labelRect); 2321 result.unite(labelRect);
2326 } 2322 }
2327 } 2323 }
2328 2324
2329 return result; 2325 return result;
2330 } 2326 }
2331 2327
2332 } // namespace WebCore 2328 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/accessibility/AXObjectCache.cpp ('k') | Source/core/accessibility/AXTable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698