Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef WEBKIT_GLUE_WEBACCESSIBILITY_H_
      6 #define WEBKIT_GLUE_WEBACCESSIBILITY_H_
      7 
      8 #include <map>
      9 #include <vector>
     10 
     11 #include "base/string16.h"
     12 #include "ui/gfx/rect.h"
     13 
     14 namespace WebKit {
     15 class WebAccessibilityCache;
     16 class WebAccessibilityObject;
     17 }
     18 
     19 namespace webkit_glue {
     20 
     21 // A compact representation of the accessibility information for a
     22 // single web object, in a form that can be serialized and sent from
     23 // the renderer process to the browser process.
     24 struct WebAccessibility {
     25  public:
     26   // An alphabetical enumeration of accessibility roles.
     27   enum Role {
     28     ROLE_NONE = 0,
     29 
     30     ROLE_UNKNOWN,
     31 
     32     ROLE_ALERT,
     33     ROLE_ALERT_DIALOG,
     34     ROLE_ANNOTATION,
     35     ROLE_APPLICATION,
     36     ROLE_ARTICLE,
     37     ROLE_BROWSER,
     38     ROLE_BUSY_INDICATOR,
     39     ROLE_BUTTON,
     40     ROLE_CELL,
     41     ROLE_CHECKBOX,
     42     ROLE_COLOR_WELL,
     43     ROLE_COLUMN,
     44     ROLE_COLUMN_HEADER,
     45     ROLE_COMBO_BOX,
     46     ROLE_DEFINITION_LIST_DEFINITION,
     47     ROLE_DEFINITION_LIST_TERM,
     48     ROLE_DIALOG,
     49     ROLE_DIRECTORY,
     50     ROLE_DISCLOSURE_TRIANGLE,
     51     ROLE_DOCUMENT,
     52     ROLE_DRAWER,
     53     ROLE_EDITABLE_TEXT,
     54     ROLE_GRID,
     55     ROLE_GROUP,
     56     ROLE_GROW_AREA,
     57     ROLE_HEADING,
     58     ROLE_HELP_TAG,
     59     ROLE_IGNORED,
     60     ROLE_IMAGE,
     61     ROLE_IMAGE_MAP,
     62     ROLE_IMAGE_MAP_LINK,
     63     ROLE_INCREMENTOR,
     64     ROLE_LANDMARK_APPLICATION,
     65     ROLE_LANDMARK_BANNER,
     66     ROLE_LANDMARK_COMPLEMENTARY,
     67     ROLE_LANDMARK_CONTENTINFO,
     68     ROLE_LANDMARK_MAIN,
     69     ROLE_LANDMARK_NAVIGATION,
     70     ROLE_LANDMARK_SEARCH,
     71     ROLE_LINK,
     72     ROLE_LIST,
     73     ROLE_LISTBOX,
     74     ROLE_LISTBOX_OPTION,
     75     ROLE_LIST_ITEM,
     76     ROLE_LIST_MARKER,
     77     ROLE_LOG,
     78     ROLE_MARQUEE,
     79     ROLE_MATH,
     80     ROLE_MATTE,
     81     ROLE_MENU,
     82     ROLE_MENU_BAR,
     83     ROLE_MENU_ITEM,
     84     ROLE_MENU_BUTTON,
     85     ROLE_MENU_LIST_OPTION,
     86     ROLE_MENU_LIST_POPUP,
     87     ROLE_NOTE,
     88     ROLE_OUTLINE,
     89     ROLE_POPUP_BUTTON,
     90     ROLE_PROGRESS_INDICATOR,
     91     ROLE_RADIO_BUTTON,
     92     ROLE_RADIO_GROUP,
     93     ROLE_REGION,
     94     ROLE_ROW,
     95     ROLE_ROW_HEADER,
     96     ROLE_RULER,
     97     ROLE_RULER_MARKER,
     98     ROLE_SCROLLAREA,
     99     ROLE_SCROLLBAR,
    100     ROLE_SHEET,
    101     ROLE_SLIDER,
    102     ROLE_SLIDER_THUMB,
    103     ROLE_SPLITTER,
    104     ROLE_SPLIT_GROUP,
    105     ROLE_STATIC_TEXT,
    106     ROLE_STATUS,
    107     ROLE_SYSTEM_WIDE,
    108     ROLE_TAB,
    109     ROLE_TABLE,
    110     ROLE_TABLE_HEADER_CONTAINER,
    111     ROLE_TAB_GROUP,
    112     ROLE_TAB_LIST,
    113     ROLE_TAB_PANEL,
    114     ROLE_TEXTAREA,
    115     ROLE_TEXT_FIELD,
    116     ROLE_TIMER,
    117     ROLE_TOOLBAR,
    118     ROLE_TOOLTIP,
    119     ROLE_TREE,
    120     ROLE_TREE_GRID,
    121     ROLE_TREE_ITEM,
    122     ROLE_VALUE_INDICATOR,
    123     ROLE_WEBCORE_LINK,
    124     ROLE_WEB_AREA,
    125     ROLE_WINDOW,
    126     NUM_ROLES
    127   };
    128 
    129   // An alphabetical enumeration of accessibility states.
    130   // A state bitmask is formed by shifting 1 to the left by each state,
    131   // for example:
    132   //   int mask = (1 << STATE_CHECKED) | (1 << STATE_FOCUSED);
    133   enum State {
    134     STATE_CHECKED,
    135     STATE_COLLAPSED,
    136     STATE_EXPANDED,
    137     STATE_FOCUSABLE,
    138     STATE_FOCUSED,
    139     STATE_HASPOPUP,
    140     STATE_HOTTRACKED,
    141     STATE_INDETERMINATE,
    142     STATE_INVISIBLE,
    143     STATE_LINKED,
    144     STATE_MULTISELECTABLE,
    145     STATE_OFFSCREEN,
    146     STATE_PRESSED,
    147     STATE_PROTECTED,
    148     STATE_READONLY,
    149     STATE_SELECTABLE,
    150     STATE_SELECTED,
    151     STATE_TRAVERSED,
    152     STATE_BUSY,
    153     STATE_UNAVAILABLE
    154   };
    155 
    156   // Additional optional attributes that can be optionally attached to
    157   // a node.
    158   enum Attribute {
    159     // Doc attributes: only make sense when applied to the top-level
    160     // Document node.
    161     ATTR_DOC_URL,
    162     ATTR_DOC_TITLE,
    163     ATTR_DOC_MIMETYPE,
    164     ATTR_DOC_DOCTYPE,
    165     ATTR_DOC_SCROLLX,
    166     ATTR_DOC_SCROLLY,
    167 
    168     // Editable text attributes
    169     ATTR_TEXT_SEL_START,
    170     ATTR_TEXT_SEL_END,
    171 
    172     // Attributes that could apply to any node.
    173     ATTR_ACTION,
    174     ATTR_DESCRIPTION,
    175     ATTR_DISPLAY,
    176     ATTR_HELP,
    177     ATTR_HTML_TAG,
    178     ATTR_SHORTCUT,
    179     ATTR_URL,
    180     NUM_ATTRIBUTES
    181   };
    182 
    183   // Empty constructor, for serialization.
    184   WebAccessibility();
    185 
    186   // Construct from a WebAccessibilityObject. Recursively creates child
    187   // nodes as needed to complete the tree. Adds |src| to |cache| and
    188   // stores its cache ID.
    189   WebAccessibility(const WebKit::WebAccessibilityObject& src,
    190                    WebKit::WebAccessibilityCache* cache,
    191                    bool include_children);
    192 
    193   ~WebAccessibility();
    194 
    195  private:
    196   // Initialize an already-created struct, same as the constructor above.
    197   void Init(const WebKit::WebAccessibilityObject& src,
    198             WebKit::WebAccessibilityCache* cache,
    199             bool include_children);
    200 
    201   // Returns true if |ancestor| is the first unignored parent of |child|,
    202   // which means that when walking up the parent chain from |child|,
    203   // |ancestor| is the *first* ancestor that isn't marked as
    204   // accessibilityIsIgnored().
    205   bool IsParentUnignoredOf(const WebKit::WebAccessibilityObject& ancestor,
    206                            const WebKit::WebAccessibilityObject& child);
    207 
    208  public:
    209   // This is a simple serializable struct. All member variables should be
    210   // copyable.
    211   int32 id;
    212   string16 name;
    213   string16 value;
    214   Role role;
    215   uint32 state;
    216   gfx::Rect location;
    217   std::map<int32, string16> attributes;
    218   std::vector<WebAccessibility> children;
    219   std::vector<int32> indirect_child_ids;
    220   std::vector<std::pair<string16, string16> > html_attributes;
    221 };
    222 
    223 }  // namespace webkit_glue
    224 
    225 #endif  // WEBKIT_GLUE_WEBACCESSIBILITY_H_
    226