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 Computer, 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 #ifndef AccessibilityNodeObject_h 30 #define AccessibilityNodeObject_h 31 32 #include "core/accessibility/AccessibilityObject.h" 33 #include "core/platform/graphics/LayoutRect.h" 34 #include "wtf/Forward.h" 35 36 namespace WebCore { 37 38 class AXObjectCache; 39 class Element; 40 class Frame; 41 class FrameView; 42 class HitTestResult; 43 class HTMLAnchorElement; 44 class HTMLAreaElement; 45 class HTMLElement; 46 class HTMLLabelElement; 47 class HTMLMapElement; 48 class HTMLSelectElement; 49 class IntPoint; 50 class IntSize; 51 class Node; 52 class RenderListBox; 53 class RenderTextControl; 54 class RenderView; 55 class VisibleSelection; 56 class Widget; 57 58 class AccessibilityNodeObject : public AccessibilityObject { 59 protected: 60 explicit AccessibilityNodeObject(Node*); 61 62 public: 63 static PassRefPtr<AccessibilityNodeObject> create(Node*); 64 virtual ~AccessibilityNodeObject(); 65 66 protected: 67 // Protected data. 68 AccessibilityRole m_ariaRole; 69 bool m_childrenDirty; 70 #ifndef NDEBUG 71 bool m_initialized; 72 #endif 73 74 virtual bool computeAccessibilityIsIgnored() const OVERRIDE; 75 virtual AccessibilityRole determineAccessibilityRole(); 76 77 String accessibilityDescriptionForElements(Vector<Element*> &elements) const; 78 void alterSliderValue(bool increase); 79 String ariaAccessibilityDescription() const; 80 void ariaLabeledByElements(Vector<Element*>& elements) const; 81 void changeValueByStep(bool increase); 82 AccessibilityRole determineAriaRoleAttribute() const; 83 void elementsFromAttribute(Vector<Element*>& elements, const QualifiedName&) const; 84 bool hasContentEditableAttributeSet() const; 85 bool isARIARange() const; 86 bool isDescendantOfBarrenParent() const; 87 // This returns true if it's focusable but it's not content editable and it's not a control or ARIA control. 88 bool isGenericFocusableElement() const; 89 HTMLLabelElement* labelForElement(Element*) const; 90 AccessibilityObject* menuButtonForMenu() const; 91 Element* menuItemElementForMenu() const; 92 Element* mouseButtonListener() const; 93 AccessibilityRole remapAriaRoleDueToParent(AccessibilityRole) const; 94 bool isNativeCheckboxOrRadio() const; 95 void setNode(Node*); 96 97 // 98 // Overridden from AccessibilityObject. 99 // 100 101 virtual void init() OVERRIDE; 102 virtual void detach() OVERRIDE; 103 virtual bool isDetached() const OVERRIDE { return !m_node; } 104 virtual bool isAccessibilityNodeObject() const OVERRIDE { return true; } 105 106 // Check object role or purpose. 107 virtual bool isAnchor() const OVERRIDE; 108 virtual bool isControl() const OVERRIDE; 109 virtual bool isFieldset() const OVERRIDE; 110 virtual bool isHeading() const OVERRIDE; 111 virtual bool isHovered() const OVERRIDE; 112 virtual bool isImage() const OVERRIDE; 113 bool isImageButton() const; 114 virtual bool isInputImage() const OVERRIDE; 115 virtual bool isLink() const; 116 virtual bool isMenu() const OVERRIDE; 117 virtual bool isMenuButton() const OVERRIDE; 118 virtual bool isMultiSelectable() const OVERRIDE; 119 bool isNativeImage() const; 120 virtual bool isNativeTextControl() const OVERRIDE; 121 virtual bool isNonNativeTextControl() const OVERRIDE; 122 virtual bool isPasswordField() const OVERRIDE; 123 virtual bool isProgressIndicator() const OVERRIDE; 124 virtual bool isSlider() const OVERRIDE; 125 126 // Check object state. 127 virtual bool isChecked() const OVERRIDE; 128 virtual bool isEnabled() const OVERRIDE; 129 virtual bool isIndeterminate() const OVERRIDE; 130 virtual bool isPressed() const OVERRIDE; 131 virtual bool isReadOnly() const OVERRIDE; 132 virtual bool isRequired() const OVERRIDE; 133 134 // Check whether certain properties can be modified. 135 virtual bool canSetFocusAttribute() const OVERRIDE; 136 137 // Properties of static elements. 138 virtual bool canvasHasFallbackContent() const OVERRIDE; 139 virtual int headingLevel() const OVERRIDE; 140 virtual unsigned hierarchicalLevel() const OVERRIDE; 141 virtual String text() const OVERRIDE; 142 143 // Properties of interactive elements. 144 virtual AccessibilityButtonState checkboxOrRadioValue() const OVERRIDE; 145 virtual void colorValue(int& r, int& g, int& b) const OVERRIDE; 146 virtual String valueDescription() const OVERRIDE; 147 virtual float valueForRange() const OVERRIDE; 148 virtual float maxValueForRange() const OVERRIDE; 149 virtual float minValueForRange() const OVERRIDE; 150 virtual String stringValue() const OVERRIDE; 151 152 // ARIA attributes. 153 virtual String ariaDescribedByAttribute() const; 154 virtual String ariaLabeledByAttribute() const OVERRIDE; 155 virtual AccessibilityRole ariaRoleAttribute() const OVERRIDE; 156 157 // Accessibility Text. 158 virtual void accessibilityText(Vector<AccessibilityText>&) OVERRIDE; 159 virtual String textUnderElement() const OVERRIDE; 160 161 // Accessibility Text - (To be deprecated). 162 virtual String accessibilityDescription() const OVERRIDE; 163 virtual String title() const OVERRIDE; 164 virtual String helpText() const OVERRIDE; 165 166 // Location and click point in frame-relative coordinates. 167 virtual LayoutRect elementRect() const OVERRIDE; 168 169 // High-level accessibility tree access. 170 virtual AccessibilityObject* parentObject() const OVERRIDE; 171 virtual AccessibilityObject* parentObjectIfExists() const OVERRIDE; 172 173 // Low-level accessibility tree exploration. 174 virtual AccessibilityObject* firstChild() const OVERRIDE; 175 virtual AccessibilityObject* nextSibling() const OVERRIDE; 176 virtual void addChildren() OVERRIDE; 177 virtual bool canHaveChildren() const OVERRIDE; 178 void addChild(AccessibilityObject*); 179 void insertChild(AccessibilityObject*, unsigned index); 180 181 // DOM and Render tree access. 182 virtual Element* actionElement() const OVERRIDE; 183 virtual Element* anchorElement() const OVERRIDE; 184 virtual Document* document() const OVERRIDE; 185 virtual Node* node() const OVERRIDE { return m_node; } 186 187 // Modify or take an action on an object. 188 virtual void increment() OVERRIDE; 189 virtual void decrement() OVERRIDE; 190 191 // Notifications that this object may have changed. 192 virtual void childrenChanged() OVERRIDE; 193 virtual void selectionChanged() OVERRIDE; 194 virtual void textChanged() OVERRIDE; 195 virtual void updateAccessibilityRole() OVERRIDE; 196 197 private: 198 Node* m_node; 199 200 String alternativeTextForWebArea() const; 201 void alternativeText(Vector<AccessibilityText>&) const; 202 void ariaLabeledByText(Vector<AccessibilityText>&) const; 203 void changeValueByPercent(float percentChange); 204 void helpText(Vector<AccessibilityText>&) const; 205 void titleElementText(Vector<AccessibilityText>&); 206 void visibleText(Vector<AccessibilityText>&) const; 207 float stepValueForRange() const; 208 }; 209 210 inline AccessibilityNodeObject* toAccessibilityNodeObject(AccessibilityObject* object) 211 { 212 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isAccessibilityNodeObject()); 213 return static_cast<AccessibilityNodeObject*>(object); 214 } 215 216 inline const AccessibilityNodeObject* toAccessibilityNodeObject(const AccessibilityObject* object) 217 { 218 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isAccessibilityNodeObject()); 219 return static_cast<const AccessibilityNodeObject*>(object); 220 } 221 222 // This will catch anyone doing an unnecessary cast. 223 void toAccessibilityNodeObject(const AccessibilityNodeObject*); 224 225 } // namespace WebCore 226 227 #endif // AccessibilityNodeObject_h 228