⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 239986 in webkit


Ignore:
Timestamp:
Jan 15, 2019, 8:28:37 AM (8 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Audit: provide a way to query for all nodes with a given computed Accessibility role
​https://bugs.webkit.org/show_bug.cgi?id=193228
<rdar://problem/46787787>

Reviewed by Joseph Pecoraro.

Source/WebCore:

Test: inspector/audit/run-accessibility.html

  • inspector/InspectorAuditAccessibilityObject.idl:
  • inspector/InspectorAuditAccessibilityObject.h:
  • inspector/InspectorAuditAccessibilityObject.cpp:

(WebCore::accessiblityObjectForNode): Added.
(WebCore::InspectorAuditAccessibilityObject::getElementsByComputedRole): Added.

LayoutTests:

  • inspector/audit/run-accessibility.html: Added.
  • inspector/audit/run-accessibility-expected.txt: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r239983 r239986  
     12019-01-15  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Audit: provide a way to query for all nodes with a given computed Accessibility role
     4        https://bugs.webkit.org/show_bug.cgi?id=193228
     5        <rdar://problem/46787787>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/audit/run-accessibility.html: Added.
     10        * inspector/audit/run-accessibility-expected.txt: Added.
     11
    1122019-01-15  Zalan Bujtas  <zalan@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r239985 r239986  
     12019-01-15  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Audit: provide a way to query for all nodes with a given computed Accessibility role
     4        https://bugs.webkit.org/show_bug.cgi?id=193228
     5        <rdar://problem/46787787>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Test: inspector/audit/run-accessibility.html
     10
     11        * inspector/InspectorAuditAccessibilityObject.idl:
     12        * inspector/InspectorAuditAccessibilityObject.h:
     13        * inspector/InspectorAuditAccessibilityObject.cpp:
     14        (WebCore::accessiblityObjectForNode): Added.
     15        (WebCore::InspectorAuditAccessibilityObject::getElementsByComputedRole): Added.
     16
    1172019-01-15  Simon Fraser  <simon.fraser@apple.com>
    218
  • trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp

    r239976 r239986  
    2828#include "InspectorAuditAccessibilityObject.h"
    2929
     30#include "AXObjectCache.h"
     31#include "AccessibilityObject.h"
     32#include "ContainerNode.h"
     33#include "Document.h"
     34#include "ElementDescendantIterator.h"
     35#include "Node.h"
     36#include <wtf/Vector.h>
     37
    3038namespace WebCore {
    3139
    3240using namespace Inspector;
    3341
    34 InspectorAuditAccessibilityObject::InspectorAuditAccessibilityObject()
     42#define ERROR_IF_NO_ACTIVE_AUDIT() \
     43    if (!m_auditAgent.hasActiveAudit()) \
     44        return Exception { NotAllowedError, "Cannot be called outside of a Web Inspector Audit"_s };
     45
     46InspectorAuditAccessibilityObject::InspectorAuditAccessibilityObject(InspectorAuditAgent& auditAgent)
     47    : m_auditAgent(auditAgent)
    3548{
    3649}
    3750
     51static AccessibilityObject* accessiblityObjectForNode(Node& node)
     52{
     53    if (!AXObjectCache::accessibilityEnabled())
     54        AXObjectCache::enableAccessibility();
     55
     56    if (AXObjectCache* axObjectCache = node.document().axObjectCache())
     57        return axObjectCache->getOrCreate(&node);
     58
     59    return nullptr;
     60}
     61
     62ExceptionOr<Vector<Ref<Node>>> InspectorAuditAccessibilityObject::getElementsByComputedRole(Document& document, const String& role, Node* container)
     63{
     64    ERROR_IF_NO_ACTIVE_AUDIT();
     65
     66    Vector<Ref<Node>> nodes;
     67
     68    for (Element& element : elementDescendants(is<ContainerNode>(container) ? downcast<ContainerNode>(*container) : document)) {
     69        if (AccessibilityObject* axObject = accessiblityObjectForNode(element)) {
     70            if (axObject->computedRoleString() == role)
     71                nodes.append(element);
     72        }
     73    }
     74
     75    return nodes;
     76}
     77
    3878} // namespace WebCore
  • trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.h

    r239976 r239986  
    2626#pragma once
    2727
     28#include "ExceptionOr.h"
    2829#include <JavaScriptCore/InspectorAuditAgent.h>
     30#include <wtf/Forward.h>
    2931#include <wtf/Ref.h>
    3032#include <wtf/RefCounted.h>
    … …  
    3234namespace WebCore {
    3335
     36class Document;
     37class Node;
     38
    3439class InspectorAuditAccessibilityObject : public RefCounted<InspectorAuditAccessibilityObject> {
    3540public:
    36     static Ref<InspectorAuditAccessibilityObject> create(Inspector::InspectorAuditAgent&)
     41    static Ref<InspectorAuditAccessibilityObject> create(Inspector::InspectorAuditAgent& auditAgent)
    3742    {
    38         return adoptRef(*new InspectorAuditAccessibilityObject());
     43        return adoptRef(*new InspectorAuditAccessibilityObject(auditAgent));
    3944    }
    4045
     46    ExceptionOr<Vector<Ref<Node>>> getElementsByComputedRole(Document&, const String& role, Node* container);
     47
    4148private:
    42     explicit InspectorAuditAccessibilityObject();
     49    explicit InspectorAuditAccessibilityObject(Inspector::InspectorAuditAgent&);
     50
     51    Inspector::InspectorAuditAgent& m_auditAgent;
    4352};
    4453
  • trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.idl

    r239976 r239986  
    2929    NoInterfaceObject,
    3030] interface InspectorAuditAccessibilityObject {
     31    [CallWith=Document, MayThrowException] sequence<Node> getElementsByComputedRole(DOMString role, optional Node? container);
    3132};
Note: See TracChangeset for help on using the changeset viewer.