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

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

Issue 192413002: Use new is*Element() helper functions in 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
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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 if (node && node->isLink()) { 277 if (node && node->isLink()) {
278 if (cssBox && cssBox->isImage()) 278 if (cssBox && cssBox->isImage())
279 return ImageMapRole; 279 return ImageMapRole;
280 return LinkRole; 280 return LinkRole;
281 } 281 }
282 if (cssBox && cssBox->isListItem()) 282 if (cssBox && cssBox->isListItem())
283 return ListItemRole; 283 return ListItemRole;
284 if (m_renderer->isListMarker()) 284 if (m_renderer->isListMarker())
285 return ListMarkerRole; 285 return ListMarkerRole;
286 if (node && node->hasTagName(buttonTag)) 286 if (isHTMLButtonElement(node))
287 return buttonRoleType(); 287 return buttonRoleType();
288 if (node && node->hasTagName(legendTag)) 288 if (isHTMLLegendElement(node))
289 return LegendRole; 289 return LegendRole;
290 if (m_renderer->isText()) 290 if (m_renderer->isText())
291 return StaticTextRole; 291 return StaticTextRole;
292 if (cssBox && cssBox->isImage()) { 292 if (cssBox && cssBox->isImage()) {
293 if (node && node->hasTagName(inputTag)) 293 if (isHTMLInputElement(node))
294 return ariaHasPopup() ? PopUpButtonRole : ButtonRole; 294 return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
295 if (isSVGImage()) 295 if (isSVGImage())
296 return SVGRootRole; 296 return SVGRootRole;
297 return ImageRole; 297 return ImageRole;
298 } 298 }
299 299
300 // Note: if JavaScript is disabled, the renderer won't be a RenderHTMLCanvas . 300 // Note: if JavaScript is disabled, the renderer won't be a RenderHTMLCanvas .
301 if (node && node->hasTagName(canvasTag) && m_renderer->isCanvas()) 301 if (isHTMLCanvasElement(node) && m_renderer->isCanvas())
302 return CanvasRole; 302 return CanvasRole;
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;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag))) 347 if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag)))
348 return AnnotationRole; 348 return AnnotationRole;
349 349
350 // Table sections should be ignored. 350 // Table sections should be ignored.
351 if (m_renderer->isTableSection()) 351 if (m_renderer->isTableSection())
352 return IgnoredRole; 352 return IgnoredRole;
353 353
354 if (m_renderer->isHR()) 354 if (m_renderer->isHR())
355 return HorizontalRuleRole; 355 return HorizontalRuleRole;
356 356
357 if (node && node->hasTagName(pTag)) 357 if (isHTMLParagraphElement(node))
dmazzoni 2014/03/10 15:26:38 As long as we're discussing this function...I was
Inactive 2014/03/10 17:13:15 I think it would make sense. It would avoid all th
358 return ParagraphRole; 358 return ParagraphRole;
359 359
360 if (node && node->hasTagName(labelTag)) 360 if (isHTMLLabelElement(node))
361 return LabelRole; 361 return LabelRole;
362 362
363 if (node && node->hasTagName(divTag)) 363 if (isHTMLDivElement(node))
364 return DivRole; 364 return DivRole;
365 365
366 if (node && node->hasTagName(formTag)) 366 if (isHTMLFormElement(node))
367 return FormRole; 367 return FormRole;
368 368
369 if (node && node->hasTagName(articleTag)) 369 if (node && node->hasTagName(articleTag))
370 return ArticleRole; 370 return ArticleRole;
371 371
372 if (node && node->hasTagName(mainTag)) 372 if (node && node->hasTagName(mainTag))
373 return MainRole; 373 return MainRole;
374 374
375 if (node && node->hasTagName(navTag)) 375 if (node && node->hasTagName(navTag))
376 return NavigationRole; 376 return NavigationRole;
377 377
378 if (node && node->hasTagName(asideTag)) 378 if (node && node->hasTagName(asideTag))
379 return ComplementaryRole; 379 return ComplementaryRole;
380 380
381 if (node && node->hasTagName(sectionTag)) 381 if (node && node->hasTagName(sectionTag))
382 return RegionRole; 382 return RegionRole;
383 383
384 if (node && node->hasTagName(addressTag)) 384 if (node && node->hasTagName(addressTag))
385 return ContentInfoRole; 385 return ContentInfoRole;
386 386
387 if (node && node->hasTagName(dialogTag)) 387 if (node && node->hasTagName(dialogTag))
388 return DialogRole; 388 return DialogRole;
389 389
390 // The HTML element should not be exposed as an element. That's what the Ren derView element does. 390 // The HTML element should not be exposed as an element. That's what the Ren derView element does.
391 if (node && node->hasTagName(htmlTag)) 391 if (isHTMLHtmlElement(node))
392 return IgnoredRole; 392 return IgnoredRole;
393 393
394 // There should only be one banner/contentInfo per page. If header/footer ar e being used within an article or section 394 // There should only be one banner/contentInfo per page. If header/footer ar e being used within an article or section
395 // then it should not be exposed as whole page's banner/contentInfo 395 // then it should not be exposed as whole page's banner/contentInfo
396 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articl eTag) && !isDescendantOfElementType(sectionTag)) 396 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articl eTag) && !isDescendantOfElementType(sectionTag))
397 return BannerRole; 397 return BannerRole;
398 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articl eTag) && !isDescendantOfElementType(sectionTag)) 398 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articl eTag) && !isDescendantOfElementType(sectionTag))
399 return FooterRole; 399 return FooterRole;
400 400
401 if (node && node->hasTagName(aTag) && isClickable()) 401 if (isHTMLAnchorElement(node) && isClickable())
402 return LinkRole; 402 return LinkRole;
403 403
404 if (m_renderer->isRenderBlockFlow()) 404 if (m_renderer->isRenderBlockFlow())
405 return GroupRole; 405 return GroupRole;
406 406
407 // If the element does not have role, but it has ARIA attributes, accessibil ity should fallback to exposing it as a group. 407 // If the element does not have role, but it has ARIA attributes, accessibil ity should fallback to exposing it as a group.
408 if (supportsARIAAttributes()) 408 if (supportsARIAAttributes())
409 return GroupRole; 409 return GroupRole;
410 410
411 return UnknownRole; 411 return UnknownRole;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 655
656 // all controls are accessible 656 // all controls are accessible
657 if (isControl()) 657 if (isControl())
658 return false; 658 return false;
659 659
660 if (ariaRoleAttribute() != UnknownRole) 660 if (ariaRoleAttribute() != UnknownRole)
661 return false; 661 return false;
662 662
663 // don't ignore labels, because they serve as TitleUIElements 663 // don't ignore labels, because they serve as TitleUIElements
664 Node* node = m_renderer->node(); 664 Node* node = m_renderer->node();
665 if (node && node->hasTagName(labelTag)) 665 if (isHTMLLabelElement(node))
666 return false; 666 return false;
667 667
668 // Anything that is content editable should not be ignored. 668 // Anything that is content editable should not be ignored.
669 // However, one cannot just call node->rendererIsEditable() since that will ask if its parents 669 // However, one cannot just call node->rendererIsEditable() since that will ask if its parents
670 // are also editable. Only the top level content editable region should be e xposed. 670 // are also editable. Only the top level content editable region should be e xposed.
671 if (hasContentEditableAttributeSet()) 671 if (hasContentEditableAttributeSet())
672 return false; 672 return false;
673 673
674 // List items play an important role in defining the structure of lists. The y should not be ignored. 674 // List items play an important role in defining the structure of lists. The y should not be ignored.
675 if (roleValue() == ListItemRole) 675 if (roleValue() == ListItemRole)
676 return false; 676 return false;
677 677
678 if (roleValue() == DialogRole) 678 if (roleValue() == DialogRole)
679 return false; 679 return false;
680 680
681 // if this element has aria attributes on it, it should not be ignored. 681 // if this element has aria attributes on it, it should not be ignored.
682 if (supportsARIAAttributes()) 682 if (supportsARIAAttributes())
683 return false; 683 return false;
684 684
685 // <span> tags are inline tags and not meant to convey information if they h ave no other aria 685 // <span> tags are inline tags and not meant to convey information if they h ave no other aria
686 // information on them. If we don't ignore them, they may emit signals expec ted to come from 686 // information on them. If we don't ignore them, they may emit signals expec ted to come from
687 // their parent. In addition, because included spans are GroupRole objects, and GroupRole 687 // their parent. In addition, because included spans are GroupRole objects, and GroupRole
688 // objects are often containers with meaningful information, the inclusion o f a span can have 688 // objects are often containers with meaningful information, the inclusion o f a span can have
689 // the side effect of causing the immediate parent accessible to be ignored. This is especially 689 // the side effect of causing the immediate parent accessible to be ignored. This is especially
690 // problematic for platforms which have distinct roles for textual block ele ments. 690 // problematic for platforms which have distinct roles for textual block ele ments.
691 if (node && node->hasTagName(spanTag)) 691 if (isHTMLSpanElement(node))
692 return true; 692 return true;
693 693
694 if (m_renderer->isRenderBlockFlow() && m_renderer->childrenInline() && !canS etFocusAttribute()) 694 if (m_renderer->isRenderBlockFlow() && m_renderer->childrenInline() && !canS etFocusAttribute())
695 return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListene r(); 695 return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListene r();
696 696
697 // ignore images seemingly used as spacers 697 // ignore images seemingly used as spacers
698 if (isImage()) { 698 if (isImage()) {
699 699
700 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important. 700 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
701 if (canSetFocusAttribute()) 701 if (canSetFocusAttribute())
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 } 1518 }
1519 1519
1520 // bail if none found 1520 // bail if none found
1521 if (!currRenderer) 1521 if (!currRenderer)
1522 return 0; 1522 return 0;
1523 1523
1524 // search up the DOM tree for an anchor element 1524 // search up the DOM tree for an anchor element
1525 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElem ent 1525 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElem ent
1526 Node* node = currRenderer->node(); 1526 Node* node = currRenderer->node();
1527 for ( ; node; node = node->parentNode()) { 1527 for ( ; node; node = node->parentNode()) {
1528 if (node->hasTagName(aTag) || (node->renderer() && cache->getOrCreate(no de->renderer())->isAnchor())) 1528 if (isHTMLAnchorElement(*node) || (node->renderer() && cache->getOrCreat e(node->renderer())->isAnchor()))
1529 return toElement(node); 1529 return toElement(node);
1530 } 1530 }
1531 1531
1532 return 0; 1532 return 0;
1533 } 1533 }
1534 1534
1535 Widget* AXRenderObject::widgetForAttachmentView() const 1535 Widget* AXRenderObject::widgetForAttachmentView() const
1536 { 1536 {
1537 if (!isAttachment()) 1537 if (!isAttachment())
1538 return 0; 1538 return 0;
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 if (!areaObject->accessibilityIsIgnored()) 2166 if (!areaObject->accessibilityIsIgnored())
2167 m_children.append(areaObject); 2167 m_children.append(areaObject);
2168 else 2168 else
2169 axObjectCache()->remove(areaObject->axObjectID()); 2169 axObjectCache()->remove(areaObject->axObjectID());
2170 } 2170 }
2171 } 2171 }
2172 } 2172 }
2173 2173
2174 void AXRenderObject::addCanvasChildren() 2174 void AXRenderObject::addCanvasChildren()
2175 { 2175 {
2176 if (!node() || !node()->hasTagName(canvasTag)) 2176 if (!isHTMLCanvasElement(node()))
2177 return; 2177 return;
2178 2178
2179 // If it's a canvas, it won't have rendered children, but it might have acce ssible fallback content. 2179 // If it's a canvas, it won't have rendered children, but it might have acce ssible fallback content.
2180 // Clear m_haveChildren because AXNodeObject::addChildren will expect it to be false. 2180 // Clear m_haveChildren because AXNodeObject::addChildren will expect it to be false.
2181 ASSERT(!m_children.size()); 2181 ASSERT(!m_children.size());
2182 m_haveChildren = false; 2182 m_haveChildren = false;
2183 AXNodeObject::addChildren(); 2183 AXNodeObject::addChildren();
2184 } 2184 }
2185 2185
2186 void AXRenderObject::addAttachmentChildren() 2186 void AXRenderObject::addAttachmentChildren()
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 if (label && label->renderer()) { 2319 if (label && label->renderer()) {
2320 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect(); 2320 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect();
2321 result.unite(labelRect); 2321 result.unite(labelRect);
2322 } 2322 }
2323 } 2323 }
2324 2324
2325 return result; 2325 return result;
2326 } 2326 }
2327 2327
2328 } // namespace WebCore 2328 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698