1 /* 2 * Copyright (C) 2008 Apple 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 AccessibilityRenderObject_h 30 #define AccessibilityRenderObject_h 31 32 #include "core/accessibility/AccessibilityNodeObject.h" 33 #include "core/platform/graphics/LayoutRect.h" 34 #include "wtf/Forward.h" 35 36 namespace WebCore { 37 38 class AccessibilitySVGRoot; 39 class AXObjectCache; 40 class Element; 41 class Frame; 42 class FrameView; 43 class HitTestResult; 44 class HTMLAnchorElement; 45 class HTMLAreaElement; 46 class HTMLElement; 47 class HTMLLabelElement; 48 class HTMLMapElement; 49 class HTMLSelectElement; 50 class IntPoint; 51 class IntSize; 52 class Node; 53 class RenderListBox; 54 class RenderTextControl; 55 class RenderView; 56 class VisibleSelection; 57 class Widget; 58 59 class AccessibilityRenderObject : public AccessibilityNodeObject { 60 protected: 61 explicit AccessibilityRenderObject(RenderObject*); 62 public: 63 static PassRefPtr<AccessibilityRenderObject> create(RenderObject*); 64 virtual ~AccessibilityRenderObject(); 65 66 // Public, overridden from AccessibilityObject. 67 virtual RenderObject* renderer() const OVERRIDE { return m_renderer; } 68 virtual LayoutRect elementRect() const OVERRIDE; 69 70 void setRenderer(RenderObject*); 71 RenderBoxModelObject* renderBoxModelObject() const; 72 RenderView* topRenderer() const; 73 Document* topDocument() const; 74 HTMLLabelElement* labelElementContainer() const; 75 bool shouldNotifyActiveDescendant() const; 76 bool needsToUpdateChildren() const { return m_childrenDirty; } 77 ScrollableArea* getScrollableAreaIfScrollable() const; 78 virtual AccessibilityRole determineAccessibilityRole() OVERRIDE; 79 void checkCachedElementRect() const; 80 void updateCachedElementRect() const; 81 82 protected: 83 RenderObject* m_renderer; 84 mutable LayoutRect m_cachedElementRect; 85 mutable LayoutRect m_cachedFrameRect; 86 mutable IntPoint m_cachedScrollPosition; 87 mutable bool m_cachedElementRectDirty; 88 89 // 90 // Overridden from AccessibilityObject. 91 // 92 93 virtual void init() OVERRIDE; 94 virtual void detach() OVERRIDE; 95 virtual bool isDetached() const OVERRIDE { return !m_renderer; } 96 virtual bool isAccessibilityRenderObject() const OVERRIDE { return true; } 97 98 // Check object role or purpose. 99 virtual bool isAttachment() const OVERRIDE; 100 virtual bool isFileUploadButton() const OVERRIDE; 101 virtual bool isLinked() const OVERRIDE; 102 virtual bool isLoaded() const OVERRIDE; 103 virtual bool isOffScreen() const OVERRIDE; 104 virtual bool isReadOnly() const OVERRIDE; 105 virtual bool isVisited() const OVERRIDE; 106 107 // Check object state. 108 virtual bool isFocused() const OVERRIDE; 109 virtual bool isSelected() const OVERRIDE; 110 111 // Check whether certain properties can be modified. 112 virtual bool canSetValueAttribute() const OVERRIDE; 113 114 // Whether objects are ignored, i.e. not included in the tree. 115 virtual AccessibilityObjectInclusion defaultObjectInclusion() const OVERRIDE; 116 virtual bool computeAccessibilityIsIgnored() const OVERRIDE; 117 118 // Properties of static elements. 119 virtual const AtomicString& accessKey() const OVERRIDE; 120 virtual bool exposesTitleUIElement() const OVERRIDE; 121 virtual AccessibilityOrientation orientation() const OVERRIDE; 122 virtual String text() const OVERRIDE; 123 virtual int textLength() const OVERRIDE; 124 virtual AccessibilityObject* titleUIElement() const OVERRIDE; 125 virtual KURL url() const OVERRIDE; 126 127 // Properties of interactive elements. 128 virtual String actionVerb() const OVERRIDE; 129 virtual void selectedChildren(AccessibilityChildrenVector&) OVERRIDE; 130 virtual String stringValue() const OVERRIDE; 131 132 // ARIA attributes. 133 virtual AccessibilityObject* activeDescendant() const OVERRIDE; 134 virtual void ariaFlowToElements(AccessibilityChildrenVector&) const OVERRIDE; 135 virtual bool ariaHasPopup() const OVERRIDE; 136 virtual bool ariaRoleHasPresentationalChildren() const OVERRIDE; 137 virtual bool isPresentationalChildOfAriaRole() const OVERRIDE; 138 virtual bool shouldFocusActiveDescendant() const OVERRIDE; 139 virtual bool supportsARIADragging() const OVERRIDE; 140 virtual bool supportsARIADropping() const OVERRIDE; 141 virtual bool supportsARIAFlowTo() const OVERRIDE; 142 virtual bool supportsARIAOwns() const OVERRIDE; 143 144 // ARIA live-region features. 145 virtual const AtomicString& ariaLiveRegionStatus() const OVERRIDE; 146 virtual const AtomicString& ariaLiveRegionRelevant() const OVERRIDE; 147 virtual bool ariaLiveRegionAtomic() const OVERRIDE; 148 virtual bool ariaLiveRegionBusy() const OVERRIDE; 149 150 // Accessibility Text. 151 virtual String textUnderElement() const OVERRIDE; 152 153 // Accessibility Text - (To be deprecated). 154 virtual String helpText() const OVERRIDE; 155 156 // Location and click point in frame-relative coordinates. 157 virtual void markCachedElementRectDirty() const OVERRIDE; 158 virtual IntPoint clickPoint() OVERRIDE; 159 160 // Hit testing. 161 virtual AccessibilityObject* accessibilityHitTest(const IntPoint&) const OVERRIDE; 162 virtual AccessibilityObject* elementAccessibilityHitTest(const IntPoint&) const OVERRIDE; 163 164 // High-level accessibility tree access. Other modules should only use these functions. 165 virtual AccessibilityObject* parentObject() const OVERRIDE; 166 virtual AccessibilityObject* parentObjectIfExists() const OVERRIDE; 167 168 // Low-level accessibility tree exploration, only for use within the accessibility module. 169 virtual AccessibilityObject* firstChild() const OVERRIDE; 170 virtual AccessibilityObject* nextSibling() const OVERRIDE; 171 virtual void addChildren() OVERRIDE; 172 virtual bool canHaveChildren() const OVERRIDE; 173 virtual void updateChildrenIfNecessary() OVERRIDE; 174 virtual void setNeedsToUpdateChildren() OVERRIDE { m_childrenDirty = true; } 175 virtual void clearChildren() OVERRIDE; 176 virtual AccessibilityObject* observableObject() const OVERRIDE; 177 178 // Properties of the object's owning document or page. 179 virtual double estimatedLoadingProgress() const OVERRIDE; 180 181 // DOM and Render tree access. 182 virtual Node* node() const OVERRIDE; 183 virtual Document* document() const OVERRIDE; 184 virtual FrameView* documentFrameView() const OVERRIDE; 185 virtual Element* anchorElement() const OVERRIDE; 186 virtual Widget* widgetForAttachmentView() const OVERRIDE; 187 188 // Selected text. 189 virtual PlainTextRange selectedTextRange() const OVERRIDE; 190 virtual String selectedText() const OVERRIDE; 191 192 // Modify or take an action on an object. 193 virtual void setFocused(bool) OVERRIDE; 194 virtual void setSelectedTextRange(const PlainTextRange&) OVERRIDE; 195 virtual void setValue(const String&) OVERRIDE; 196 virtual void scrollTo(const IntPoint&) const OVERRIDE; 197 198 // Notifications that this object may have changed. 199 virtual void handleActiveDescendantChanged() OVERRIDE; 200 virtual void handleAriaExpandedChanged() OVERRIDE; 201 202 // Text metrics. Most of these should be deprecated, needs major cleanup. 203 virtual int index(const VisiblePosition&) const OVERRIDE; 204 virtual VisiblePosition visiblePositionForIndex(int) const OVERRIDE; 205 virtual void lineBreaks(Vector<int>&) const OVERRIDE; 206 207 private: 208 bool isAllowedChildOfTree() const; 209 bool hasTextAlternative() const; 210 void ariaListboxSelectedChildren(AccessibilityChildrenVector&); 211 PlainTextRange ariaSelectedTextRange() const; 212 bool nodeIsTextControl(const Node*) const; 213 bool isTabItemSelected() const; 214 AccessibilityObject* internalLinkElement() const; 215 AccessibilityObject* accessibilityImageMapHitTest(HTMLAreaElement*, const IntPoint&) const; 216 bool renderObjectIsObservable(RenderObject*) const; 217 RenderObject* renderParentObject() const; 218 bool isDescendantOfElementType(const QualifiedName& tagName) const; 219 bool isSVGImage() const; 220 void detachRemoteSVGRoot(); 221 AccessibilitySVGRoot* remoteSVGRootElement() const; 222 AccessibilityObject* remoteSVGElementHitTest(const IntPoint&) const; 223 void offsetBoundingBoxForRemoteSVGElement(LayoutRect&) const; 224 void addHiddenChildren(); 225 void addTextFieldChildren(); 226 void addImageMapChildren(); 227 void addCanvasChildren(); 228 void addAttachmentChildren(); 229 void addRemoteSVGChildren(); 230 void ariaSelectedRows(AccessibilityChildrenVector&); 231 bool elementAttributeValue(const QualifiedName&) const; 232 bool inheritsPresentationalRole() const; 233 LayoutRect computeElementRect() const; 234 VisibleSelection selection() const; 235 String stringForRange(const PlainTextRange&) const; 236 AccessibilityObject* correspondingControlForLabelElement() const; 237 int indexForVisiblePosition(const VisiblePosition&) const; 238 }; 239 240 inline AccessibilityRenderObject* toAccessibilityRenderObject(AccessibilityObject* object) 241 { 242 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isAccessibilityRenderObject()); 243 return static_cast<AccessibilityRenderObject*>(object); 244 } 245 246 inline const AccessibilityRenderObject* toAccessibilityRenderObject(const AccessibilityObject* object) 247 { 248 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isAccessibilityRenderObject()); 249 return static_cast<const AccessibilityRenderObject*>(object); 250 } 251 252 // This will catch anyone doing an unnecessary cast. 253 void toAccessibilityRenderObject(const AccessibilityRenderObject*); 254 255 } // namespace WebCore 256 257 #endif // AccessibilityRenderObject_h 258