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 AXNodeObject_h 30 #define AXNodeObject_h 31 32 #include "core/accessibility/AXObject.h" 33 #include "platform/geometry/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 AXNodeObject : public AXObject { 59 protected: 60 explicit AXNodeObject(Node*); 61 62 public: 63 static PassRefPtr<AXNodeObject> create(Node*); 64 virtual ~AXNodeObject(); 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 isDescendantOfBarrenParent() const; 86 // This returns true if it's focusable but it's not content editable and it's not a control or ARIA control. 87 bool isGenericFocusableElement() const; 88 HTMLLabelElement* labelForElement(Element*) const; 89 AXObject* menuButtonForMenu() const; 90 Element* menuItemElementForMenu() const; 91 Element* mouseButtonListener() const; 92 AccessibilityRole remapAriaRoleDueToParent(AccessibilityRole) const; 93 bool isNativeCheckboxOrRadio() const; 94 void setNode(Node*); 95 AXObject* correspondingControlForLabelElement() const; 96 HTMLLabelElement* labelElementContainer() const; 97 98 // 99 // Overridden from AXObject. 100 // 101 102 virtual void init() OVERRIDE; 103 virtual void detach() OVERRIDE; 104 virtual bool isDetached() const OVERRIDE { return !m_node; } 105 virtual bool isAXNodeObject() const OVERRIDE { return true; } 106 107 // Check object role or purpose. 108 virtual bool isAnchor() const OVERRIDE; 109 virtual bool isControl() const OVERRIDE; 110 virtual bool isFieldset() const OVERRIDE; 111 virtual bool isHeading() const OVERRIDE; 112 virtual bool isHovered() const OVERRIDE; 113 virtual bool isImage() const OVERRIDE; 114 bool isImageButton() const; 115 virtual bool isInputImage() const OVERRIDE; 116 virtual bool isLink() const; 117 virtual bool isMenu() const OVERRIDE; 118 virtual bool isMenuButton() const OVERRIDE; 119 virtual bool isMultiSelectable() const OVERRIDE; 120 bool isNativeImage() const; 121 virtual bool isNativeTextControl() const OVERRIDE; 122 virtual bool isNonNativeTextControl() const OVERRIDE; 123 virtual bool isPasswordField() const OVERRIDE; 124 virtual bool isProgressIndicator() const OVERRIDE; 125 virtual bool isSlider() const OVERRIDE; 126 127 // Check object state. 128 virtual bool isChecked() const OVERRIDE; 129 virtual bool isClickable() const OVERRIDE; 130 virtual bool isEnabled() const OVERRIDE; 131 virtual bool isIndeterminate() const OVERRIDE; 132 virtual bool isPressed() const OVERRIDE; 133 virtual bool isReadOnly() const OVERRIDE; 134 virtual bool isRequired() const OVERRIDE; 135 136 // Check whether certain properties can be modified. 137 virtual bool canSetFocusAttribute() const OVERRIDE; 138 virtual bool canSetValueAttribute() const OVERRIDE; 139 140 // Properties of static elements. 141 virtual bool canvasHasFallbackContent() const OVERRIDE; 142 virtual bool exposesTitleUIElement() const OVERRIDE; 143 virtual int headingLevel() const OVERRIDE; 144 virtual unsigned hierarchicalLevel() const OVERRIDE; 145 virtual String text() const OVERRIDE; 146 virtual AXObject* titleUIElement() const OVERRIDE; 147 148 // Properties of interactive elements. 149 virtual AccessibilityButtonState checkboxOrRadioValue() const OVERRIDE; 150 virtual void colorValue(int& r, int& g, int& b) const OVERRIDE; 151 virtual String valueDescription() const OVERRIDE; 152 virtual float valueForRange() const OVERRIDE; 153 virtual float maxValueForRange() const OVERRIDE; 154 virtual float minValueForRange() const OVERRIDE; 155 virtual String stringValue() const OVERRIDE; 156 157 // ARIA attributes. 158 virtual String ariaDescribedByAttribute() const; 159 virtual String ariaLabeledByAttribute() const OVERRIDE; 160 virtual AccessibilityRole ariaRoleAttribute() const OVERRIDE; 161 162 // Accessibility Text. 163 virtual void accessibilityText(Vector<AccessibilityText>&) OVERRIDE; 164 virtual String textUnderElement() const OVERRIDE; 165 166 // Accessibility Text - (To be deprecated). 167 virtual String accessibilityDescription() const OVERRIDE; 168 virtual String title() const OVERRIDE; 169 virtual String helpText() const OVERRIDE; 170 171 // Location and click point in frame-relative coordinates. 172 virtual LayoutRect elementRect() const OVERRIDE; 173 174 // High-level accessibility tree access. 175 virtual AXObject* parentObject() const OVERRIDE; 176 virtual AXObject* parentObjectIfExists() const OVERRIDE; 177 178 // Low-level accessibility tree exploration. 179 virtual AXObject* firstChild() const OVERRIDE; 180 virtual AXObject* nextSibling() const OVERRIDE; 181 virtual void addChildren() OVERRIDE; 182 virtual bool canHaveChildren() const OVERRIDE; 183 void addChild(AXObject*); 184 void insertChild(AXObject*, unsigned index); 185 186 // DOM and Render tree access. 187 virtual Element* actionElement() const OVERRIDE; 188 virtual Element* anchorElement() const OVERRIDE; 189 virtual Document* document() const OVERRIDE; 190 virtual Node* node() const OVERRIDE { return m_node; } 191 192 // Modify or take an action on an object. 193 virtual void setFocused(bool) OVERRIDE; 194 virtual void increment() OVERRIDE; 195 virtual void decrement() OVERRIDE; 196 197 // Notifications that this object may have changed. 198 virtual void childrenChanged() OVERRIDE; 199 virtual void selectionChanged() OVERRIDE; 200 virtual void textChanged() OVERRIDE; 201 virtual void updateAccessibilityRole() OVERRIDE; 202 203 private: 204 Node* m_node; 205 206 String alternativeTextForWebArea() const; 207 void alternativeText(Vector<AccessibilityText>&) const; 208 void ariaLabeledByText(Vector<AccessibilityText>&) const; 209 void changeValueByPercent(float percentChange); 210 void helpText(Vector<AccessibilityText>&) const; 211 void titleElementText(Vector<AccessibilityText>&); 212 void visibleText(Vector<AccessibilityText>&) const; 213 float stepValueForRange() const; 214 }; 215 216 DEFINE_AX_OBJECT_TYPE_CASTS(AXNodeObject, isAXNodeObject()); 217 218 } // namespace WebCore 219 220 #endif // AXNodeObject_h 221