| 1 | /* |
| 2 | * Copyright (C) 2012, Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #pragma once |
| 30 | |
| 31 | #include "AccessibilityObject.h" |
| 32 | #include "LayoutRect.h" |
| 33 | #include <wtf/Forward.h> |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | class AXObjectCache; |
| 38 | class Element; |
| 39 | class HTMLLabelElement; |
| 40 | class Node; |
| 41 | |
| 42 | enum MouseButtonListenerResultFilter { |
| 43 | ExcludeBodyElement = 1, |
| 44 | IncludeBodyElement, |
| 45 | }; |
| 46 | |
| 47 | class AccessibilityNodeObject : public AccessibilityObject { |
| 48 | public: |
| 49 | static Ref<AccessibilityNodeObject> create(Node*); |
| 50 | virtual ~AccessibilityNodeObject(); |
| 51 | |
| 52 | void init() override; |
| 53 | |
| 54 | bool canvasHasFallbackContent() const override; |
| 55 | |
| 56 | bool isControl() const override; |
| 57 | bool isFieldset() const override; |
| 58 | bool isGroup() const override; |
| 59 | bool isHeading() const override; |
| 60 | bool isHovered() const override; |
| 61 | bool isImage() const override; |
| 62 | bool isImageButton() const override; |
| 63 | bool isInputImage() const override; |
| 64 | bool isLink() const override; |
| 65 | bool () const override; |
| 66 | bool () const override; |
| 67 | bool () const override; |
| 68 | bool () const override; |
| 69 | bool () const override; |
| 70 | bool isMultiSelectable() const override; |
| 71 | virtual bool isNativeCheckboxOrRadio() const; |
| 72 | bool isNativeImage() const override; |
| 73 | bool isNativeTextControl() const override; |
| 74 | bool isPasswordField() const override; |
| 75 | AccessibilityObject* passwordFieldOrContainingPasswordField() override; |
| 76 | bool isProgressIndicator() const override; |
| 77 | bool isSearchField() const override; |
| 78 | bool isSlider() const override; |
| 79 | |
| 80 | bool isChecked() const override; |
| 81 | bool isEnabled() const override; |
| 82 | bool isIndeterminate() const override; |
| 83 | bool isPressed() const override; |
| 84 | bool isRequired() const override; |
| 85 | bool supportsRequiredAttribute() const override; |
| 86 | |
| 87 | bool canSetSelectedAttribute() const override; |
| 88 | |
| 89 | void setNode(Node*); |
| 90 | Node* node() const override { return m_node; } |
| 91 | Document* document() const override; |
| 92 | |
| 93 | bool canSetFocusAttribute() const override; |
| 94 | int headingLevel() const override; |
| 95 | |
| 96 | bool canSetValueAttribute() const override; |
| 97 | |
| 98 | String valueDescription() const override; |
| 99 | float valueForRange() const override; |
| 100 | float maxValueForRange() const override; |
| 101 | float minValueForRange() const override; |
| 102 | float stepValueForRange() const override; |
| 103 | |
| 104 | AccessibilityObject* selectedRadioButton() override; |
| 105 | AccessibilityObject* selectedTabItem() override; |
| 106 | AccessibilityButtonState checkboxOrRadioValue() const override; |
| 107 | |
| 108 | unsigned hierarchicalLevel() const override; |
| 109 | String textUnderElement(AccessibilityTextUnderElementMode = AccessibilityTextUnderElementMode()) const override; |
| 110 | String accessibilityDescriptionForChildren() const; |
| 111 | String accessibilityDescription() const override; |
| 112 | String helpText() const override; |
| 113 | String title() const override; |
| 114 | String text() const override; |
| 115 | String stringValue() const override; |
| 116 | void colorValue(int& r, int& g, int& b) const override; |
| 117 | String ariaLabeledByAttribute() const override; |
| 118 | bool hasAttributesRequiredForInclusion() const final; |
| 119 | void setIsExpanded(bool) override; |
| 120 | |
| 121 | Element* actionElement() const override; |
| 122 | Element* mouseButtonListener(MouseButtonListenerResultFilter = ExcludeBodyElement) const; |
| 123 | Element* anchorElement() const override; |
| 124 | AccessibilityObject* () const; |
| 125 | |
| 126 | virtual void changeValueByPercent(float percentChange); |
| 127 | |
| 128 | AccessibilityObject* firstChild() const override; |
| 129 | AccessibilityObject* lastChild() const override; |
| 130 | AccessibilityObject* previousSibling() const override; |
| 131 | AccessibilityObject* nextSibling() const override; |
| 132 | AccessibilityObject* parentObject() const override; |
| 133 | AccessibilityObject* parentObjectIfExists() const override; |
| 134 | |
| 135 | void detach(AccessibilityDetachmentType, AXObjectCache*) override; |
| 136 | void childrenChanged() override; |
| 137 | void updateAccessibilityRole() override; |
| 138 | |
| 139 | void increment() override; |
| 140 | void decrement() override; |
| 141 | |
| 142 | LayoutRect elementRect() const override; |
| 143 | |
| 144 | protected: |
| 145 | explicit AccessibilityNodeObject(Node*); |
| 146 | |
| 147 | AccessibilityRole m_ariaRole { AccessibilityRole::Unknown }; |
| 148 | mutable AccessibilityRole m_roleForMSAA { AccessibilityRole::Unknown }; |
| 149 | #ifndef NDEBUG |
| 150 | bool m_initialized { false }; |
| 151 | #endif |
| 152 | |
| 153 | bool isDetached() const override { return !m_node; } |
| 154 | |
| 155 | virtual AccessibilityRole determineAccessibilityRole(); |
| 156 | void addChildren() override; |
| 157 | |
| 158 | bool canHaveChildren() const override; |
| 159 | AccessibilityRole ariaRoleAttribute() const override; |
| 160 | virtual AccessibilityRole determineAriaRoleAttribute() const; |
| 161 | AccessibilityRole remapAriaRoleDueToParent(AccessibilityRole) const; |
| 162 | bool isDescendantOfBarrenParent() const override; |
| 163 | void alterSliderValue(bool increase); |
| 164 | void changeValueByStep(bool increase); |
| 165 | // This returns true if it's focusable but it's not content editable and it's not a control or ARIA control. |
| 166 | bool isGenericFocusableElement() const; |
| 167 | bool isLabelable() const; |
| 168 | HTMLLabelElement* labelForElement(Element*) const; |
| 169 | String textForLabelElement(Element*) const; |
| 170 | String ariaAccessibilityDescription() const; |
| 171 | void ariaLabeledByElements(Vector<Element*>& elements) const; |
| 172 | String accessibilityDescriptionForElements(Vector<Element*> &elements) const; |
| 173 | LayoutRect boundingBoxRect() const override; |
| 174 | String ariaDescribedByAttribute() const override; |
| 175 | |
| 176 | Element* () const; |
| 177 | Element* () const; |
| 178 | AccessibilityObject* () const; |
| 179 | AccessibilityObject* captionForFigure() const; |
| 180 | virtual void titleElementText(Vector<AccessibilityText>&) const; |
| 181 | |
| 182 | private: |
| 183 | bool isAccessibilityNodeObject() const final { return true; } |
| 184 | void accessibilityText(Vector<AccessibilityText>&) const override; |
| 185 | void alternativeText(Vector<AccessibilityText>&) const; |
| 186 | void visibleText(Vector<AccessibilityText>&) const; |
| 187 | void helpText(Vector<AccessibilityText>&) const; |
| 188 | String alternativeTextForWebArea() const; |
| 189 | void ariaLabeledByText(Vector<AccessibilityText>&) const; |
| 190 | bool computeAccessibilityIsIgnored() const override; |
| 191 | bool usesAltTagForTextComputation() const; |
| 192 | bool roleIgnoresTitle() const; |
| 193 | |
| 194 | Node* m_node; |
| 195 | }; |
| 196 | |
| 197 | } // namespace WebCore |
| 198 | |
| 199 | SPECIALIZE_TYPE_TRAITS_ACCESSIBILITY(AccessibilityNodeObject, isAccessibilityNodeObject()) |
| 200 | |