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

Side by Side Diff: Source/modules/accessibility/AXLayoutObject.cpp

Issue 1039873002: AX presentation role should be inherited to its required owned elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
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 27 matching lines...) Expand all
38 #include "core/editing/VisibleUnits.h" 38 #include "core/editing/VisibleUnits.h"
39 #include "core/editing/htmlediting.h" 39 #include "core/editing/htmlediting.h"
40 #include "core/editing/iterators/CharacterIterator.h" 40 #include "core/editing/iterators/CharacterIterator.h"
41 #include "core/editing/iterators/TextIterator.h" 41 #include "core/editing/iterators/TextIterator.h"
42 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/frame/Settings.h" 43 #include "core/frame/Settings.h"
44 #include "core/html/HTMLImageElement.h" 44 #include "core/html/HTMLImageElement.h"
45 #include "core/html/HTMLLabelElement.h" 45 #include "core/html/HTMLLabelElement.h"
46 #include "core/html/HTMLOptionElement.h" 46 #include "core/html/HTMLOptionElement.h"
47 #include "core/html/HTMLSelectElement.h" 47 #include "core/html/HTMLSelectElement.h"
48 #include "core/html/HTMLTableCellElement.h"
49 #include "core/html/HTMLTableElement.h"
50 #include "core/html/HTMLTableRowElement.h"
51 #include "core/html/HTMLTableSectionElement.h"
48 #include "core/html/HTMLTextAreaElement.h" 52 #include "core/html/HTMLTextAreaElement.h"
49 #include "core/html/shadow/ShadowElementNames.h" 53 #include "core/html/shadow/ShadowElementNames.h"
50 #include "core/layout/HitTestResult.h" 54 #include "core/layout/HitTestResult.h"
51 #include "core/layout/LayoutFieldset.h" 55 #include "core/layout/LayoutFieldset.h"
52 #include "core/layout/LayoutFileUploadControl.h" 56 #include "core/layout/LayoutFileUploadControl.h"
53 #include "core/layout/LayoutHTMLCanvas.h" 57 #include "core/layout/LayoutHTMLCanvas.h"
54 #include "core/layout/LayoutImage.h" 58 #include "core/layout/LayoutImage.h"
55 #include "core/layout/LayoutInline.h" 59 #include "core/layout/LayoutInline.h"
56 #include "core/layout/LayoutListMarker.h" 60 #include "core/layout/LayoutListMarker.h"
57 #include "core/layout/LayoutMenuList.h" 61 #include "core/layout/LayoutMenuList.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return toLayoutInline(layoutObject)->continuation(); 168 return toLayoutInline(layoutObject)->continuation();
165 if (layoutObject->isLayoutBlock()) 169 if (layoutObject->isLayoutBlock())
166 return toLayoutBlock(layoutObject)->inlineElementContinuation(); 170 return toLayoutBlock(layoutObject)->inlineElementContinuation();
167 return 0; 171 return 0;
168 } 172 }
169 173
170 AXLayoutObject::AXLayoutObject(LayoutObject* layoutObject, AXObjectCacheImpl* ax ObjectCache) 174 AXLayoutObject::AXLayoutObject(LayoutObject* layoutObject, AXObjectCacheImpl* ax ObjectCache)
171 : AXNodeObject(layoutObject->node(), axObjectCache) 175 : AXNodeObject(layoutObject->node(), axObjectCache)
172 , m_layoutObject(layoutObject) 176 , m_layoutObject(layoutObject)
173 , m_cachedElementRectDirty(true) 177 , m_cachedElementRectDirty(true)
178 , m_hasInheritedPresentationRole(false)
174 { 179 {
175 #if ENABLE(ASSERT) 180 #if ENABLE(ASSERT)
176 m_layoutObject->setHasAXObject(true); 181 m_layoutObject->setHasAXObject(true);
177 #endif 182 #endif
178 } 183 }
179 184
180 PassRefPtr<AXLayoutObject> AXLayoutObject::create(LayoutObject* layoutObject, AX ObjectCacheImpl* axObjectCache) 185 PassRefPtr<AXLayoutObject> AXLayoutObject::create(LayoutObject* layoutObject, AX ObjectCacheImpl* axObjectCache)
181 { 186 {
182 return adoptRef(new AXLayoutObject(layoutObject, axObjectCache)); 187 return adoptRef(new AXLayoutObject(layoutObject, axObjectCache));
183 } 188 }
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 544 }
540 545
541 return AXObject::defaultObjectInclusion(); 546 return AXObject::defaultObjectInclusion();
542 } 547 }
543 548
544 bool AXLayoutObject::computeAccessibilityIsIgnored() const 549 bool AXLayoutObject::computeAccessibilityIsIgnored() const
545 { 550 {
546 #if ENABLE(ASSERT) 551 #if ENABLE(ASSERT)
547 ASSERT(m_initialized); 552 ASSERT(m_initialized);
548 #endif 553 #endif
554 m_hasInheritedPresentationRole = false;
549 555
550 // Check first if any of the common reasons cause this element to be ignored . 556 // Check first if any of the common reasons cause this element to be ignored .
551 // Then process other use cases that need to be applied to all the various r oles 557 // Then process other use cases that need to be applied to all the various r oles
552 // that AXLayoutObjects take on. 558 // that AXLayoutObjects take on.
553 AXObjectInclusion decision = defaultObjectInclusion(); 559 AXObjectInclusion decision = defaultObjectInclusion();
554 if (decision == IncludeObject) 560 if (decision == IncludeObject)
555 return false; 561 return false;
556 if (decision == IgnoreObject) 562 if (decision == IgnoreObject)
557 return true; 563 return true;
558 564
559 // If this element is within a parent that cannot have children, it should n ot be exposed. 565 // If this element is within a parent that cannot have children, it should n ot be exposed.
560 if (isDescendantOfBarrenParent()) 566 if (isDescendantOfBarrenParent())
561 return true; 567 return true;
562 568
563 if (roleValue() == IgnoredRole) 569 if (roleValue() == IgnoredRole)
564 return true; 570 return true;
565 571
566 if ((roleValue() == NoneRole || roleValue() == PresentationalRole) || inheri tsPresentationalRole()) 572 if (roleValue() == NoneRole || roleValue() == PresentationalRole) {
573 m_hasInheritedPresentationRole = true;
dmazzoni 2015/03/29 07:46:22 I don't want to compute this inside computeAccessi
je_julie(Not used) 2015/03/31 16:14:27 I added computeHasInheritedPresentationRole.
574 return true;
575 }
576
577 if (inheritsPresentationalRole())
567 return true; 578 return true;
568 579
569 // An ARIA tree can only have tree items and static text as children. 580 // An ARIA tree can only have tree items and static text as children.
570 if (!isAllowedChildOfTree()) 581 if (!isAllowedChildOfTree())
571 return true; 582 return true;
572 583
573 // TODO: we should refactor this - but right now this is necessary to make 584 // TODO: we should refactor this - but right now this is necessary to make
574 // sure scroll areas stay in the tree. 585 // sure scroll areas stay in the tree.
575 if (isAttachment()) 586 if (isAttachment())
576 return false; 587 return false;
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 2332
2322 return equalIgnoringCase(getAttribute(attributeName), "true"); 2333 return equalIgnoringCase(getAttribute(attributeName), "true");
2323 } 2334 }
2324 2335
2325 bool AXLayoutObject::inheritsPresentationalRole() const 2336 bool AXLayoutObject::inheritsPresentationalRole() const
2326 { 2337 {
2327 // ARIA states if an item can get focus, it should not be presentational. 2338 // ARIA states if an item can get focus, it should not be presentational.
2328 if (canSetFocusAttribute()) 2339 if (canSetFocusAttribute())
2329 return false; 2340 return false;
2330 2341
2331 // ARIA spec says that when a parent object is presentational, and it has re quired child elements, 2342 // http://www.w3.org/TR/wai-aria/complete#presentation
2332 // those child elements are also presentational. For example, <li> becomes p resentational from <ul>. 2343 // ARIA spec says that the user agent MUST apply an inherited role of presen tation
2333 // http://www.w3.org/WAI/PF/aria/complete#presentation 2344 // to any owned elements that do not have an explicit role defined.
2334 if (roleValue() != ListItemRole && roleValue() != ListMarkerRole) 2345 if (ariaRoleAttribute() != UnknownRole)
2335 return false; 2346 return false;
2336 2347
2337 AXObject* parent = parentObject(); 2348 AXObject* parent = parentObject();
2349 if (!parent)
2350 return false;
2351
2352 // The parent should have presentationalRole.
2353 if (!isPresentationRole(parent) && !isPresentationRoleInTable(parent))
2354 return false;
2355
2356 // ARIA spec says that when a parent object is presentational, and it has re quired owned elements,
2357 // those elements are also presentational. For example, <li> becomes present ational from <ul>.
2358 return m_hasInheritedPresentationRole = isRequiredOwnedElement(parent);
2359 }
2360
2361 bool AXLayoutObject::isRequiredOwnedElement(AXObject* parent) const
2362 {
2338 if (!parent->isAXLayoutObject()) 2363 if (!parent->isAXLayoutObject())
2339 return false; 2364 return false;
2340 2365
2341 Node* elementNode = toAXLayoutObject(parent)->node(); 2366 Node* parentNode = toAXLayoutObject(parent)->node();
2342 if (!elementNode || !elementNode->isElementNode()) 2367 if (!parentNode || !parentNode->isElementNode())
2343 return false; 2368 return false;
2344 2369
2345 QualifiedName tagName = toElement(elementNode)->tagQName(); 2370 AccessibilityRole role = roleValue();
2346 if (tagName != ulTag && tagName != olTag && tagName != dlTag)
2347 return false;
2348 2371
2349 if (parent->roleValue() == NoneRole || parent->roleValue() == Presentational Role) 2372 if (role == ListItemRole)
2350 return ariaRoleAttribute() == UnknownRole; 2373 return isListElement(parentNode);
2374 if (role == ListMarkerRole)
2375 return isHTMLLIElement(*parentNode);
2376 if (role == MenuItemCheckBoxRole || role == MenuItemRole || role == MenuIt emRadioRole)
2377 return isHTMLMenuElement(*parentNode);
2351 2378
2379 Node* curNode = node();
2380 if (isHTMLTableCellElement(curNode))
2381 return isHTMLTableRowElement(*parentNode);
2382 if (isHTMLTableRowElement(curNode))
2383 return isHTMLTableSectionElement(*parentNode);
2384
2385 // In case of ListboxRole and it's child, ListBoxOptionRole,
2386 // Inheritance of presentation role is handled in AXListBoxOption
2387 // Because ListBoxOption Role doesn't have any child.
2388 // If it's just ignored because of presentation, we can't see any AX tree re lated to ListBoxOption.
2352 return false; 2389 return false;
2353 } 2390 }
2354 2391
2392 bool AXLayoutObject::isListElement(Node* node) const
2393 {
2394 return isHTMLUListElement(*node) || isHTMLOListElement(*node) || isHTMLDList Element(*node);
2395 }
2396
2397 bool AXLayoutObject::isPresentationRole(AXObject* parent) const
2398 {
2399 return parent->roleValue() == NoneRole || parent->roleValue() == Presentatio nalRole
2400 || parent->hasInheritedPresentationRole();
2401 }
2402
2403 bool AXLayoutObject::isPresentationRoleInTable(AXObject* parent) const
2404 {
2405 Node* parentNode = parent->node();
2406 if (!parentNode || !parentNode->isElementNode())
2407 return false;
2408
2409 Node* curNode = node();
2410 // AXTable determines the role as checking isTableXXX.
2411 // If Table has explicit role including presentation, AXTable doesn't assign implicit Role
2412 // to a whole Table. That's why we should check it based on node.
2413 // Normal Table Tree is that
2414 // cell(its role)-> tr(tr role)-> tfoot, tbody, thead(ignored role) -> table (table role).
2415 // If table has presentation role, it will be like
2416 // cell(group)-> tr(unknown) -> tfoot, tbody, thead(ignored) -> table(presen tation).
2417 if (isHTMLTableCellElement(curNode) && isHTMLTableRowElement(*parentNode))
2418 return parent->hasInheritedPresentationRole();
2419
2420 if (isHTMLTableRowElement(curNode) && isHTMLTableSectionElement(*parentNode) ) {
2421 // Because TableSections have ignored role, presentation should be check ed with its parent node
2422 AXObject* tableObject = parent->parentObject();
2423 Node* tableNode = tableObject->node();
2424 return isHTMLTableElement(tableNode) && tableObject->hasInheritedPresent ationRole();
2425 }
2426 return false;
2427 }
2428
2355 LayoutRect AXLayoutObject::computeElementRect() const 2429 LayoutRect AXLayoutObject::computeElementRect() const
2356 { 2430 {
2357 LayoutObject* obj = m_layoutObject; 2431 LayoutObject* obj = m_layoutObject;
2358 2432
2359 if (!obj) 2433 if (!obj)
2360 return LayoutRect(); 2434 return LayoutRect();
2361 2435
2362 if (obj->node()) // If we are a continuation, we want to make sure to use th e primary layoutObject. 2436 if (obj->node()) // If we are a continuation, we want to make sure to use th e primary layoutObject.
2363 obj = obj->node()->layoutObject(); 2437 obj = obj->node()->layoutObject();
2364 2438
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 if (label && label->layoutObject()) { 2470 if (label && label->layoutObject()) {
2397 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect(); 2471 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect();
2398 result.unite(labelRect); 2472 result.unite(labelRect);
2399 } 2473 }
2400 } 2474 }
2401 2475
2402 return result; 2476 return result;
2403 } 2477 }
2404 2478
2405 } // namespace blink 2479 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698