Home | History | Annotate | Download | only in DumpRenderTree
      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  * 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 
     26 #ifndef AccessibilityUIElement_h
     27 #define AccessibilityUIElement_h
     28 
     29 #include "AccessibilityTextMarker.h"
     30 #include <JavaScriptCore/JSObjectRef.h>
     31 #include <wtf/Platform.h>
     32 #include <wtf/Vector.h>
     33 
     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 
     44 #include <WebCore/COMPtr.h>
     45 #include <oleacc.h>
     46 
     47 typedef COMPtr<IAccessible> PlatformUIElement;
     48 #elif PLATFORM(GTK)
     49 #include <atk/atk.h>
     50 typedef AtkObject* PlatformUIElement;
     51 #else
     52 typedef void* PlatformUIElement;
     53 #endif
     54 
     55 #if PLATFORM(MAC)
     56 #ifdef __OBJC__
     57 typedef id NotificationHandler;
     58 #else
     59 typedef struct objc_object* NotificationHandler;
     60 #endif
     61 #endif
     62 
     63 class AccessibilityUIElement {
     64 public:
     65     AccessibilityUIElement(PlatformUIElement);
     66     AccessibilityUIElement(const AccessibilityUIElement&);
     67     ~AccessibilityUIElement();
     68 
     69     PlatformUIElement platformUIElement() { return m_element; }
     70 
     71     static JSObjectRef makeJSAccessibilityUIElement(JSContextRef, const AccessibilityUIElement&);
     72 
     73     bool isEqual(AccessibilityUIElement* otherElement);
     74 
     75     void getLinkedUIElements(Vector<AccessibilityUIElement>&);
     76     void getDocumentLinks(Vector<AccessibilityUIElement>&);
     77     void getChildren(Vector<AccessibilityUIElement>&);
     78     void getChildrenWithRange(Vector<AccessibilityUIElement>&, unsigned location, unsigned length);
     79 
     80     AccessibilityUIElement elementAtPoint(int x, int y);
     81     AccessibilityUIElement getChildAtIndex(unsigned);
     82     unsigned indexOfChild(AccessibilityUIElement*);
     83     int childrenCount();
     84     AccessibilityUIElement titleUIElement();
     85     AccessibilityUIElement parentElement();
     86 
     87     void takeFocus();
     88     void takeSelection();
     89     void addSelection();
     90     void removeSelection();
     91 
     92     // Methods - platform-independent implementations
     93     JSStringRef allAttributes();
     94     JSStringRef attributesOfLinkedUIElements();
     95     AccessibilityUIElement linkedUIElementAtIndex(unsigned);
     96 
     97     JSStringRef attributesOfDocumentLinks();
     98     JSStringRef attributesOfChildren();
     99     JSStringRef parameterizedAttributeNames();
    100     void increment();
    101     void decrement();
    102     void showMenu();
    103     void press();
    104 
    105     // Attributes - platform-independent implementations
    106     JSStringRef stringAttributeValue(JSStringRef attribute);
    107     bool boolAttributeValue(JSStringRef attribute);
    108     bool isAttributeSupported(JSStringRef attribute);
    109     bool isAttributeSettable(JSStringRef attribute);
    110     bool isActionSupported(JSStringRef action);
    111     JSStringRef role();
    112     JSStringRef subrole();
    113     JSStringRef roleDescription();
    114     JSStringRef title();
    115     JSStringRef description();
    116     JSStringRef language();
    117     JSStringRef stringValue();
    118     JSStringRef accessibilityValue() const;
    119     JSStringRef helpText() const;
    120     JSStringRef orientation() const;
    121     double x();
    122     double y();
    123     double width();
    124     double height();
    125     double intValue() const;
    126     double minValue();
    127     double maxValue();
    128     JSStringRef valueDescription();
    129     int insertionPointLineNumber();
    130     JSStringRef selectedTextRange();
    131     bool isEnabled();
    132     bool isRequired() const;
    133 
    134     bool isFocused() const;
    135     bool isFocusable() const;
    136     bool isSelected() const;
    137     bool isSelectable() const;
    138     bool isMultiSelectable() const;
    139     void setSelectedChild(AccessibilityUIElement*) const;
    140     unsigned selectedChildrenCount() const;
    141     AccessibilityUIElement selectedChildAtIndex(unsigned) const;
    142 
    143     bool isExpanded() const;
    144     bool isChecked() const;
    145     bool isVisible() const;
    146     bool isOffScreen() const;
    147     bool isCollapsed() const;
    148     bool isIgnored() const;
    149     bool hasPopup() const;
    150     int hierarchicalLevel() const;
    151     double clickPointX();
    152     double clickPointY();
    153     JSStringRef documentEncoding();
    154     JSStringRef documentURI();
    155     JSStringRef url();
    156 
    157     // CSS3-speech properties.
    158     JSStringRef speak();
    159 
    160     // Table-specific attributes
    161     JSStringRef attributesOfColumnHeaders();
    162     JSStringRef attributesOfRowHeaders();
    163     JSStringRef attributesOfColumns();
    164     JSStringRef attributesOfRows();
    165     JSStringRef attributesOfVisibleCells();
    166     JSStringRef attributesOfHeader();
    167     int indexInTable();
    168     JSStringRef rowIndexRange();
    169     JSStringRef columnIndexRange();
    170     int rowCount();
    171     int columnCount();
    172 
    173     // Tree/Outline specific attributes
    174     AccessibilityUIElement selectedRowAtIndex(unsigned);
    175     AccessibilityUIElement disclosedByRow();
    176     AccessibilityUIElement disclosedRowAtIndex(unsigned);
    177 
    178     // ARIA specific
    179     AccessibilityUIElement ariaOwnsElementAtIndex(unsigned);
    180     AccessibilityUIElement ariaFlowToElementAtIndex(unsigned);
    181 
    182     // ARIA Drag and Drop
    183     bool ariaIsGrabbed() const;
    184     // A space concatentated string of all the drop effects.
    185     JSStringRef ariaDropEffects() const;
    186 
    187     // Parameterized attributes
    188     int lineForIndex(int);
    189     JSStringRef rangeForLine(int);
    190     JSStringRef boundsForRange(unsigned location, unsigned length);
    191     void setSelectedTextRange(unsigned location, unsigned length);
    192     JSStringRef stringForRange(unsigned location, unsigned length);
    193     JSStringRef attributedStringForRange(unsigned location, unsigned length);
    194     bool attributedStringRangeIsMisspelled(unsigned location, unsigned length);
    195 
    196     // Table-specific
    197     AccessibilityUIElement cellForColumnAndRow(unsigned column, unsigned row);
    198 
    199     // Text markers.
    200     AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement*);
    201     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
    202     AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
    203     AccessibilityTextMarker endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
    204     AccessibilityTextMarker textMarkerForPoint(int x, int y);
    205     AccessibilityUIElement accessibilityElementForTextMarker(AccessibilityTextMarker*);
    206     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
    207 
    208     // Notifications
    209     // Function callback should take one argument, the name of the notification.
    210     bool addNotificationListener(JSObjectRef functionCallback);
    211     // Make sure you call remove, because you can't rely on objects being deallocated in a timely fashion.
    212     void removeNotificationListener();
    213 
    214 private:
    215     static JSClassRef getJSClass();
    216     PlatformUIElement m_element;
    217 
    218     // A retained, platform specific object used to help manage notifications for this object.
    219 #if PLATFORM(MAC)
    220     NotificationHandler m_notificationHandler;
    221 #endif
    222 };
    223 
    224 #endif // AccessibilityUIElement_h
    225