AccessibilityUIElement.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (C) 2011 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. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef AccessibilityUIElement_h
  26. #define AccessibilityUIElement_h
  27. #include "AccessibilityTextMarker.h"
  28. #include "AccessibilityTextMarkerRange.h"
  29. #include "JSWrappable.h"
  30. #include <JavaScriptCore/JSObjectRef.h>
  31. #include <JavaScriptCore/JSRetainPtr.h>
  32. #include <wtf/Platform.h>
  33. #include <wtf/Vector.h>
  34. #if PLATFORM(MAC)
  35. #ifdef __OBJC__
  36. typedef id PlatformUIElement;
  37. #else
  38. typedef struct objc_object* PlatformUIElement;
  39. #endif
  40. #elif PLATFORM(WIN)
  41. #undef _WINSOCKAPI_
  42. #define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h
  43. #include <WebCore/COMPtr.h>
  44. #include <oleacc.h>
  45. typedef COMPtr<IAccessible> PlatformUIElement;
  46. #elif PLATFORM(GTK) || (PLATFORM(EFL) && HAVE(ACCESSIBILITY))
  47. #include <atk/atk.h>
  48. #include <wtf/gobject/GRefPtr.h>
  49. typedef GRefPtr<AtkObject> PlatformUIElement;
  50. #else
  51. typedef void* PlatformUIElement;
  52. #endif
  53. #if PLATFORM(MAC)
  54. #ifdef __OBJC__
  55. typedef id NotificationHandler;
  56. #else
  57. typedef struct objc_object* NotificationHandler;
  58. #endif
  59. #endif
  60. namespace WTR {
  61. class AccessibilityUIElement : public JSWrappable {
  62. public:
  63. static PassRefPtr<AccessibilityUIElement> create(PlatformUIElement);
  64. static PassRefPtr<AccessibilityUIElement> create(const AccessibilityUIElement&);
  65. ~AccessibilityUIElement();
  66. PlatformUIElement platformUIElement() { return m_element; }
  67. virtual JSClassRef wrapperClass();
  68. static JSObjectRef makeJSAccessibilityUIElement(JSContextRef, const AccessibilityUIElement&);
  69. bool isEqual(AccessibilityUIElement* otherElement);
  70. PassRefPtr<AccessibilityUIElement> elementAtPoint(int x, int y);
  71. PassRefPtr<AccessibilityUIElement> childAtIndex(unsigned);
  72. unsigned indexOfChild(AccessibilityUIElement*);
  73. int childrenCount();
  74. PassRefPtr<AccessibilityUIElement> titleUIElement();
  75. PassRefPtr<AccessibilityUIElement> parentElement();
  76. void takeFocus();
  77. void takeSelection();
  78. void addSelection();
  79. void removeSelection();
  80. // Methods - platform-independent implementations
  81. JSRetainPtr<JSStringRef> allAttributes();
  82. JSRetainPtr<JSStringRef> attributesOfLinkedUIElements();
  83. PassRefPtr<AccessibilityUIElement> linkedUIElementAtIndex(unsigned);
  84. JSRetainPtr<JSStringRef> attributesOfDocumentLinks();
  85. JSRetainPtr<JSStringRef> attributesOfChildren();
  86. JSRetainPtr<JSStringRef> parameterizedAttributeNames();
  87. void increment();
  88. void decrement();
  89. void showMenu();
  90. void press();
  91. // Attributes - platform-independent implementations
  92. JSRetainPtr<JSStringRef> stringAttributeValue(JSStringRef attribute);
  93. double numberAttributeValue(JSStringRef attribute);
  94. PassRefPtr<AccessibilityUIElement> uiElementAttributeValue(JSStringRef attribute) const;
  95. bool boolAttributeValue(JSStringRef attribute);
  96. bool isAttributeSupported(JSStringRef attribute);
  97. bool isAttributeSettable(JSStringRef attribute);
  98. bool isPressActionSupported();
  99. bool isIncrementActionSupported();
  100. bool isDecrementActionSupported();
  101. JSRetainPtr<JSStringRef> role();
  102. JSRetainPtr<JSStringRef> subrole();
  103. JSRetainPtr<JSStringRef> roleDescription();
  104. JSRetainPtr<JSStringRef> title();
  105. JSRetainPtr<JSStringRef> description();
  106. JSRetainPtr<JSStringRef> language();
  107. JSRetainPtr<JSStringRef> stringValue();
  108. JSRetainPtr<JSStringRef> accessibilityValue() const;
  109. JSRetainPtr<JSStringRef> helpText() const;
  110. JSRetainPtr<JSStringRef> orientation() const;
  111. double x();
  112. double y();
  113. double width();
  114. double height();
  115. double intValue() const;
  116. double minValue();
  117. double maxValue();
  118. JSRetainPtr<JSStringRef> valueDescription();
  119. int insertionPointLineNumber();
  120. JSRetainPtr<JSStringRef> selectedTextRange();
  121. bool isEnabled();
  122. bool isRequired() const;
  123. bool isFocused() const;
  124. bool isFocusable() const;
  125. bool isSelected() const;
  126. bool isSelectable() const;
  127. bool isMultiSelectable() const;
  128. void setSelectedChild(AccessibilityUIElement*) const;
  129. unsigned selectedChildrenCount() const;
  130. PassRefPtr<AccessibilityUIElement> selectedChildAtIndex(unsigned) const;
  131. bool isValid() const;
  132. bool isExpanded() const;
  133. bool isChecked() const;
  134. bool isVisible() const;
  135. bool isOffScreen() const;
  136. bool isCollapsed() const;
  137. bool isIgnored() const;
  138. bool hasPopup() const;
  139. int hierarchicalLevel() const;
  140. double clickPointX();
  141. double clickPointY();
  142. JSRetainPtr<JSStringRef> documentEncoding();
  143. JSRetainPtr<JSStringRef> documentURI();
  144. JSRetainPtr<JSStringRef> url();
  145. // CSS3-speech properties.
  146. JSRetainPtr<JSStringRef> speak();
  147. // Table-specific attributes
  148. JSRetainPtr<JSStringRef> attributesOfColumnHeaders();
  149. JSRetainPtr<JSStringRef> attributesOfRowHeaders();
  150. JSRetainPtr<JSStringRef> attributesOfColumns();
  151. JSRetainPtr<JSStringRef> attributesOfRows();
  152. JSRetainPtr<JSStringRef> attributesOfVisibleCells();
  153. JSRetainPtr<JSStringRef> attributesOfHeader();
  154. int indexInTable();
  155. JSRetainPtr<JSStringRef> rowIndexRange();
  156. JSRetainPtr<JSStringRef> columnIndexRange();
  157. int rowCount();
  158. int columnCount();
  159. // Tree/Outline specific attributes
  160. PassRefPtr<AccessibilityUIElement> selectedRowAtIndex(unsigned);
  161. PassRefPtr<AccessibilityUIElement> disclosedByRow();
  162. PassRefPtr<AccessibilityUIElement> disclosedRowAtIndex(unsigned);
  163. PassRefPtr<AccessibilityUIElement> rowAtIndex(unsigned);
  164. // ARIA specific
  165. PassRefPtr<AccessibilityUIElement> ariaOwnsElementAtIndex(unsigned);
  166. PassRefPtr<AccessibilityUIElement> ariaFlowToElementAtIndex(unsigned);
  167. // ARIA Drag and Drop
  168. bool ariaIsGrabbed() const;
  169. // A space concatentated string of all the drop effects.
  170. JSRetainPtr<JSStringRef> ariaDropEffects() const;
  171. // Parameterized attributes
  172. int lineForIndex(int);
  173. JSRetainPtr<JSStringRef> rangeForLine(int);
  174. JSRetainPtr<JSStringRef> rangeForPosition(int x, int y);
  175. JSRetainPtr<JSStringRef> boundsForRange(unsigned location, unsigned length);
  176. void setSelectedTextRange(unsigned location, unsigned length);
  177. JSRetainPtr<JSStringRef> stringForRange(unsigned location, unsigned length);
  178. JSRetainPtr<JSStringRef> attributedStringForRange(unsigned location, unsigned length);
  179. bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
  180. PassRefPtr<AccessibilityUIElement> uiElementForSearchPredicate(JSContextRef, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly);
  181. // Table-specific
  182. PassRefPtr<AccessibilityUIElement> cellForColumnAndRow(unsigned column, unsigned row);
  183. // Scrollarea-specific
  184. PassRefPtr<AccessibilityUIElement> horizontalScrollbar() const;
  185. PassRefPtr<AccessibilityUIElement> verticalScrollbar() const;
  186. void scrollToMakeVisible();
  187. // Text markers.
  188. PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);
  189. PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
  190. PassRefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
  191. PassRefPtr<AccessibilityTextMarker> endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
  192. PassRefPtr<AccessibilityTextMarker> textMarkerForPoint(int x, int y);
  193. PassRefPtr<AccessibilityTextMarker> previousTextMarker(AccessibilityTextMarker*);
  194. PassRefPtr<AccessibilityTextMarker> nextTextMarker(AccessibilityTextMarker*);
  195. PassRefPtr<AccessibilityUIElement> accessibilityElementForTextMarker(AccessibilityTextMarker*);
  196. JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
  197. int textMarkerRangeLength(AccessibilityTextMarkerRange*);
  198. bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
  199. int indexForTextMarker(AccessibilityTextMarker*);
  200. bool isTextMarkerValid(AccessibilityTextMarker*);
  201. PassRefPtr<AccessibilityTextMarker> textMarkerForIndex(int);
  202. // Returns an ordered list of supported actions for an element.
  203. JSRetainPtr<JSStringRef> supportedActions() const;
  204. JSRetainPtr<JSStringRef> mathPostscriptsDescription() const;
  205. JSRetainPtr<JSStringRef> mathPrescriptsDescription() const;
  206. JSRetainPtr<JSStringRef> pathDescription() const;
  207. // Notifications
  208. // Function callback should take one argument, the name of the notification.
  209. bool addNotificationListener(JSValueRef functionCallback);
  210. // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
  211. bool removeNotificationListener();
  212. private:
  213. AccessibilityUIElement(PlatformUIElement);
  214. AccessibilityUIElement(const AccessibilityUIElement&);
  215. PlatformUIElement m_element;
  216. // A retained, platform specific object used to help manage notifications for this object.
  217. #if PLATFORM(MAC)
  218. NotificationHandler m_notificationHandler;
  219. void getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >&);
  220. void getDocumentLinks(Vector<RefPtr<AccessibilityUIElement> >&);
  221. #endif
  222. #if PLATFORM(MAC) || PLATFORM(GTK) || (PLATFORM(EFL) && HAVE(ACCESSIBILITY))
  223. void getChildren(Vector<RefPtr<AccessibilityUIElement> >&);
  224. void getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >&, unsigned location, unsigned length);
  225. #endif
  226. };
  227. } // namespace WTR
  228. #endif // AccessibilityUIElement_h