accessible/src/base/ARIAMap.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/base/ARIAMap.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,823 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "ARIAMap.h"
    1.12 +
    1.13 +#include "nsAccUtils.h"
    1.14 +#include "nsCoreUtils.h"
    1.15 +#include "Role.h"
    1.16 +#include "States.h"
    1.17 +
    1.18 +#include "nsAttrName.h"
    1.19 +#include "nsWhitespaceTokenizer.h"
    1.20 +
    1.21 +using namespace mozilla;
    1.22 +using namespace mozilla::a11y;
    1.23 +using namespace mozilla::a11y::aria;
    1.24 +
    1.25 +static const uint32_t kGenericAccType = 0;
    1.26 +
    1.27 +/**
    1.28 + *  This list of WAI-defined roles are currently hardcoded.
    1.29 + *  Eventually we will most likely be loading an RDF resource that contains this information
    1.30 + *  Using RDF will also allow for role extensibility. See bug 280138.
    1.31 + *
    1.32 + *  Definition of nsRoleMapEntry contains comments explaining this table.
    1.33 + *
    1.34 + *  When no nsIAccessibleRole enum mapping exists for an ARIA role, the
    1.35 + *  role will be exposed via the object attribute "xml-roles".
    1.36 + *  In addition, in MSAA, the unmapped role will also be exposed as a BSTR string role.
    1.37 + *
    1.38 + *  There are no nsIAccessibleRole enums for the following landmark roles:
    1.39 + *    banner, contentinfo, main, navigation, note, search, secondary, seealso, breadcrumbs
    1.40 + */
    1.41 +
    1.42 +static nsRoleMapEntry sWAIRoleMaps[] =
    1.43 +{
    1.44 +  { // alert
    1.45 +    &nsGkAtoms::alert,
    1.46 +    roles::ALERT,
    1.47 +    kUseMapRole,
    1.48 +    eNoValue,
    1.49 +    eNoAction,
    1.50 +    eNoLiveAttr,
    1.51 +    kGenericAccType,
    1.52 +    kNoReqStates
    1.53 +  },
    1.54 +  { // alertdialog
    1.55 +    &nsGkAtoms::alertdialog,
    1.56 +    roles::DIALOG,
    1.57 +    kUseMapRole,
    1.58 +    eNoValue,
    1.59 +    eNoAction,
    1.60 +    eNoLiveAttr,
    1.61 +    kGenericAccType,
    1.62 +    kNoReqStates
    1.63 +  },
    1.64 +  { // application
    1.65 +    &nsGkAtoms::application,
    1.66 +    roles::APPLICATION,
    1.67 +    kUseMapRole,
    1.68 +    eNoValue,
    1.69 +    eNoAction,
    1.70 +    eNoLiveAttr,
    1.71 +    kGenericAccType,
    1.72 +    kNoReqStates
    1.73 +  },
    1.74 +  { // article
    1.75 +    &nsGkAtoms::article,
    1.76 +    roles::DOCUMENT,
    1.77 +    kUseMapRole,
    1.78 +    eNoValue,
    1.79 +    eNoAction,
    1.80 +    eNoLiveAttr,
    1.81 +    kGenericAccType,
    1.82 +    kNoReqStates,
    1.83 +    eReadonlyUntilEditable
    1.84 +  },
    1.85 +  { // button
    1.86 +    &nsGkAtoms::button,
    1.87 +    roles::PUSHBUTTON,
    1.88 +    kUseMapRole,
    1.89 +    eNoValue,
    1.90 +    ePressAction,
    1.91 +    eNoLiveAttr,
    1.92 +    eButton,
    1.93 +    kNoReqStates
    1.94 +    // eARIAPressed is auto applied on any button
    1.95 +  },
    1.96 +  { // checkbox
    1.97 +    &nsGkAtoms::checkbox,
    1.98 +    roles::CHECKBUTTON,
    1.99 +    kUseMapRole,
   1.100 +    eNoValue,
   1.101 +    eCheckUncheckAction,
   1.102 +    eNoLiveAttr,
   1.103 +    kGenericAccType,
   1.104 +    kNoReqStates,
   1.105 +    eARIACheckableMixed,
   1.106 +    eARIAReadonly
   1.107 +  },
   1.108 +  { // columnheader
   1.109 +    &nsGkAtoms::columnheader,
   1.110 +    roles::COLUMNHEADER,
   1.111 +    kUseMapRole,
   1.112 +    eNoValue,
   1.113 +    eSortAction,
   1.114 +    eNoLiveAttr,
   1.115 +    eTableCell,
   1.116 +    kNoReqStates,
   1.117 +    eARIASelectableIfDefined,
   1.118 +    eARIAReadonlyOrEditableIfDefined
   1.119 +  },
   1.120 +  { // combobox
   1.121 +    &nsGkAtoms::combobox,
   1.122 +    roles::COMBOBOX,
   1.123 +    kUseMapRole,
   1.124 +    eNoValue,
   1.125 +    eOpenCloseAction,
   1.126 +    eNoLiveAttr,
   1.127 +    kGenericAccType,
   1.128 +    states::COLLAPSED | states::HASPOPUP,
   1.129 +    eARIAAutoComplete,
   1.130 +    eARIAReadonly
   1.131 +  },
   1.132 +  { // dialog
   1.133 +    &nsGkAtoms::dialog,
   1.134 +    roles::DIALOG,
   1.135 +    kUseMapRole,
   1.136 +    eNoValue,
   1.137 +    eNoAction,
   1.138 +    eNoLiveAttr,
   1.139 +    kGenericAccType,
   1.140 +    kNoReqStates
   1.141 +  },
   1.142 +  { // directory
   1.143 +    &nsGkAtoms::directory,
   1.144 +    roles::LIST,
   1.145 +    kUseMapRole,
   1.146 +    eNoValue,
   1.147 +    eNoAction,
   1.148 +    eNoLiveAttr,
   1.149 +    eList,
   1.150 +    kNoReqStates
   1.151 +  },
   1.152 +  { // document
   1.153 +    &nsGkAtoms::document,
   1.154 +    roles::DOCUMENT,
   1.155 +    kUseMapRole,
   1.156 +    eNoValue,
   1.157 +    eNoAction,
   1.158 +    eNoLiveAttr,
   1.159 +    kGenericAccType,
   1.160 +    kNoReqStates,
   1.161 +    eReadonlyUntilEditable
   1.162 +  },
   1.163 +  { // form
   1.164 +    &nsGkAtoms::form,
   1.165 +    roles::FORM,
   1.166 +    kUseMapRole,
   1.167 +    eNoValue,
   1.168 +    eNoAction,
   1.169 +    eNoLiveAttr,
   1.170 +    kGenericAccType,
   1.171 +    kNoReqStates
   1.172 +  },
   1.173 +  { // grid
   1.174 +    &nsGkAtoms::grid,
   1.175 +    roles::TABLE,
   1.176 +    kUseMapRole,
   1.177 +    eNoValue,
   1.178 +    eNoAction,
   1.179 +    eNoLiveAttr,
   1.180 +    eSelect | eTable,
   1.181 +    kNoReqStates,
   1.182 +    eARIAMultiSelectable,
   1.183 +    eARIAReadonlyOrEditable,
   1.184 +    eFocusableUntilDisabled
   1.185 +  },
   1.186 +  { // gridcell
   1.187 +    &nsGkAtoms::gridcell,
   1.188 +    roles::GRID_CELL,
   1.189 +    kUseMapRole,
   1.190 +    eNoValue,
   1.191 +    eNoAction,
   1.192 +    eNoLiveAttr,
   1.193 +    eTableCell,
   1.194 +    kNoReqStates,
   1.195 +    eARIASelectable,
   1.196 +    eARIAReadonlyOrEditableIfDefined
   1.197 +  },
   1.198 +  { // group
   1.199 +    &nsGkAtoms::group,
   1.200 +    roles::GROUPING,
   1.201 +    kUseMapRole,
   1.202 +    eNoValue,
   1.203 +    eNoAction,
   1.204 +    eNoLiveAttr,
   1.205 +    kGenericAccType,
   1.206 +    kNoReqStates
   1.207 +  },
   1.208 +  { // heading
   1.209 +    &nsGkAtoms::heading,
   1.210 +    roles::HEADING,
   1.211 +    kUseMapRole,
   1.212 +    eNoValue,
   1.213 +    eNoAction,
   1.214 +    eNoLiveAttr,
   1.215 +    kGenericAccType,
   1.216 +    kNoReqStates
   1.217 +  },
   1.218 +  { // img
   1.219 +    &nsGkAtoms::img,
   1.220 +    roles::GRAPHIC,
   1.221 +    kUseMapRole,
   1.222 +    eNoValue,
   1.223 +    eNoAction,
   1.224 +    eNoLiveAttr,
   1.225 +    kGenericAccType,
   1.226 +    kNoReqStates
   1.227 +  },
   1.228 +  { // key
   1.229 +    &nsGkAtoms::key,
   1.230 +    roles::KEY,
   1.231 +    kUseMapRole,
   1.232 +    eNoValue,
   1.233 +    ePressAction,
   1.234 +    eNoLiveAttr,
   1.235 +    kGenericAccType,
   1.236 +    kNoReqStates,
   1.237 +    eARIAPressed
   1.238 +  },
   1.239 +  { // link
   1.240 +    &nsGkAtoms::link,
   1.241 +    roles::LINK,
   1.242 +    kUseMapRole,
   1.243 +    eNoValue,
   1.244 +    eJumpAction,
   1.245 +    eNoLiveAttr,
   1.246 +    kGenericAccType,
   1.247 +    states::LINKED
   1.248 +  },
   1.249 +  { // list
   1.250 +    &nsGkAtoms::list,
   1.251 +    roles::LIST,
   1.252 +    kUseMapRole,
   1.253 +    eNoValue,
   1.254 +    eNoAction,
   1.255 +    eNoLiveAttr,
   1.256 +    eList,
   1.257 +    states::READONLY
   1.258 +  },
   1.259 +  { // listbox
   1.260 +    &nsGkAtoms::listbox,
   1.261 +    roles::LISTBOX,
   1.262 +    kUseMapRole,
   1.263 +    eNoValue,
   1.264 +    eNoAction,
   1.265 +    eNoLiveAttr,
   1.266 +    eListControl | eSelect,
   1.267 +    kNoReqStates,
   1.268 +    eARIAMultiSelectable,
   1.269 +    eARIAReadonly,
   1.270 +    eFocusableUntilDisabled
   1.271 +  },
   1.272 +  { // listitem
   1.273 +    &nsGkAtoms::listitem,
   1.274 +    roles::LISTITEM,
   1.275 +    kUseMapRole,
   1.276 +    eNoValue,
   1.277 +    eNoAction, // XXX: should depend on state, parent accessible
   1.278 +    eNoLiveAttr,
   1.279 +    kGenericAccType,
   1.280 +    states::READONLY
   1.281 +  },
   1.282 +  { // log
   1.283 +    &nsGkAtoms::log_,
   1.284 +    roles::NOTHING,
   1.285 +    kUseNativeRole,
   1.286 +    eNoValue,
   1.287 +    eNoAction,
   1.288 +    ePoliteLiveAttr,
   1.289 +    kGenericAccType,
   1.290 +    kNoReqStates
   1.291 +  },
   1.292 +  { // marquee
   1.293 +    &nsGkAtoms::marquee,
   1.294 +    roles::ANIMATION,
   1.295 +    kUseMapRole,
   1.296 +    eNoValue,
   1.297 +    eNoAction,
   1.298 +    eOffLiveAttr,
   1.299 +    kGenericAccType,
   1.300 +    kNoReqStates
   1.301 +  },
   1.302 +  { // math
   1.303 +    &nsGkAtoms::math,
   1.304 +    roles::FLAT_EQUATION,
   1.305 +    kUseMapRole,
   1.306 +    eNoValue,
   1.307 +    eNoAction,
   1.308 +    eNoLiveAttr,
   1.309 +    kGenericAccType,
   1.310 +    kNoReqStates
   1.311 +  },
   1.312 +  { // menu
   1.313 +    &nsGkAtoms::menu,
   1.314 +    roles::MENUPOPUP,
   1.315 +    kUseMapRole,
   1.316 +    eNoValue,
   1.317 +    eNoAction, // XXX: technically accessibles of menupopup role haven't
   1.318 +               // any action, but menu can be open or close.
   1.319 +    eNoLiveAttr,
   1.320 +    kGenericAccType,
   1.321 +    kNoReqStates
   1.322 +  },
   1.323 +  { // menubar
   1.324 +    &nsGkAtoms::menubar,
   1.325 +    roles::MENUBAR,
   1.326 +    kUseMapRole,
   1.327 +    eNoValue,
   1.328 +    eNoAction,
   1.329 +    eNoLiveAttr,
   1.330 +    kGenericAccType,
   1.331 +    kNoReqStates
   1.332 +  },
   1.333 +  { // menuitem
   1.334 +    &nsGkAtoms::menuitem,
   1.335 +    roles::MENUITEM,
   1.336 +    kUseMapRole,
   1.337 +    eNoValue,
   1.338 +    eClickAction,
   1.339 +    eNoLiveAttr,
   1.340 +    kGenericAccType,
   1.341 +    kNoReqStates,
   1.342 +    eARIACheckedMixed
   1.343 +  },
   1.344 +  { // menuitemcheckbox
   1.345 +    &nsGkAtoms::menuitemcheckbox,
   1.346 +    roles::CHECK_MENU_ITEM,
   1.347 +    kUseMapRole,
   1.348 +    eNoValue,
   1.349 +    eClickAction,
   1.350 +    eNoLiveAttr,
   1.351 +    kGenericAccType,
   1.352 +    kNoReqStates,
   1.353 +    eARIACheckableMixed
   1.354 +  },
   1.355 +  { // menuitemradio
   1.356 +    &nsGkAtoms::menuitemradio,
   1.357 +    roles::RADIO_MENU_ITEM,
   1.358 +    kUseMapRole,
   1.359 +    eNoValue,
   1.360 +    eClickAction,
   1.361 +    eNoLiveAttr,
   1.362 +    kGenericAccType,
   1.363 +    kNoReqStates,
   1.364 +    eARIACheckableBool
   1.365 +  },
   1.366 +  { // note
   1.367 +    &nsGkAtoms::note_,
   1.368 +    roles::NOTE,
   1.369 +    kUseMapRole,
   1.370 +    eNoValue,
   1.371 +    eNoAction,
   1.372 +    eNoLiveAttr,
   1.373 +    kGenericAccType,
   1.374 +    kNoReqStates
   1.375 +  },
   1.376 +  { // option
   1.377 +    &nsGkAtoms::option,
   1.378 +    roles::OPTION,
   1.379 +    kUseMapRole,
   1.380 +    eNoValue,
   1.381 +    eSelectAction,
   1.382 +    eNoLiveAttr,
   1.383 +    kGenericAccType,
   1.384 +    kNoReqStates,
   1.385 +    eARIASelectable,
   1.386 +    eARIACheckedMixed
   1.387 +  },
   1.388 +  { // presentation
   1.389 +    &nsGkAtoms::presentation,
   1.390 +    roles::NOTHING,
   1.391 +    kUseMapRole,
   1.392 +    eNoValue,
   1.393 +    eNoAction,
   1.394 +    eNoLiveAttr,
   1.395 +    kGenericAccType,
   1.396 +    kNoReqStates
   1.397 +  },
   1.398 +  { // progressbar
   1.399 +    &nsGkAtoms::progressbar,
   1.400 +    roles::PROGRESSBAR,
   1.401 +    kUseMapRole,
   1.402 +    eHasValueMinMax,
   1.403 +    eNoAction,
   1.404 +    eNoLiveAttr,
   1.405 +    kGenericAccType,
   1.406 +    states::READONLY,
   1.407 +    eIndeterminateIfNoValue
   1.408 +  },
   1.409 +  { // radio
   1.410 +    &nsGkAtoms::radio,
   1.411 +    roles::RADIOBUTTON,
   1.412 +    kUseMapRole,
   1.413 +    eNoValue,
   1.414 +    eSelectAction,
   1.415 +    eNoLiveAttr,
   1.416 +    kGenericAccType,
   1.417 +    kNoReqStates,
   1.418 +    eARIACheckableBool
   1.419 +  },
   1.420 +  { // radiogroup
   1.421 +    &nsGkAtoms::radiogroup,
   1.422 +    roles::GROUPING,
   1.423 +    kUseMapRole,
   1.424 +    eNoValue,
   1.425 +    eNoAction,
   1.426 +    eNoLiveAttr,
   1.427 +    kGenericAccType,
   1.428 +    kNoReqStates
   1.429 +  },
   1.430 +  { // region
   1.431 +    &nsGkAtoms::region,
   1.432 +    roles::PANE,
   1.433 +    kUseMapRole,
   1.434 +    eNoValue,
   1.435 +    eNoAction,
   1.436 +    eNoLiveAttr,
   1.437 +    kGenericAccType,
   1.438 +    kNoReqStates
   1.439 +  },
   1.440 +  { // row
   1.441 +    &nsGkAtoms::row,
   1.442 +    roles::ROW,
   1.443 +    kUseMapRole,
   1.444 +    eNoValue,
   1.445 +    eNoAction,
   1.446 +    eNoLiveAttr,
   1.447 +    eTableRow,
   1.448 +    kNoReqStates,
   1.449 +    eARIASelectable
   1.450 +  },
   1.451 +  { // rowgroup
   1.452 +    &nsGkAtoms::rowgroup,
   1.453 +    roles::GROUPING,
   1.454 +    kUseMapRole,
   1.455 +    eNoValue,
   1.456 +    eNoAction,
   1.457 +    eNoLiveAttr,
   1.458 +    kGenericAccType,
   1.459 +    kNoReqStates
   1.460 +  },
   1.461 +  { // rowheader
   1.462 +    &nsGkAtoms::rowheader,
   1.463 +    roles::ROWHEADER,
   1.464 +    kUseMapRole,
   1.465 +    eNoValue,
   1.466 +    eSortAction,
   1.467 +    eNoLiveAttr,
   1.468 +    eTableCell,
   1.469 +    kNoReqStates,
   1.470 +    eARIASelectableIfDefined,
   1.471 +    eARIAReadonlyOrEditableIfDefined
   1.472 +  },
   1.473 +  { // scrollbar
   1.474 +    &nsGkAtoms::scrollbar,
   1.475 +    roles::SCROLLBAR,
   1.476 +    kUseMapRole,
   1.477 +    eHasValueMinMax,
   1.478 +    eNoAction,
   1.479 +    eNoLiveAttr,
   1.480 +    kGenericAccType,
   1.481 +    kNoReqStates,
   1.482 +    eARIAOrientation,
   1.483 +    eARIAReadonly
   1.484 +  },
   1.485 +  { // separator
   1.486 +    &nsGkAtoms::separator_,
   1.487 +    roles::SEPARATOR,
   1.488 +    kUseMapRole,
   1.489 +    eNoValue,
   1.490 +    eNoAction,
   1.491 +    eNoLiveAttr,
   1.492 +    kGenericAccType,
   1.493 +    kNoReqStates,
   1.494 +    eARIAOrientation
   1.495 +  },
   1.496 +  { // slider
   1.497 +    &nsGkAtoms::slider,
   1.498 +    roles::SLIDER,
   1.499 +    kUseMapRole,
   1.500 +    eHasValueMinMax,
   1.501 +    eNoAction,
   1.502 +    eNoLiveAttr,
   1.503 +    kGenericAccType,
   1.504 +    kNoReqStates,
   1.505 +    eARIAOrientation,
   1.506 +    eARIAReadonly
   1.507 +  },
   1.508 +  { // spinbutton
   1.509 +    &nsGkAtoms::spinbutton,
   1.510 +    roles::SPINBUTTON,
   1.511 +    kUseMapRole,
   1.512 +    eHasValueMinMax,
   1.513 +    eNoAction,
   1.514 +    eNoLiveAttr,
   1.515 +    kGenericAccType,
   1.516 +    kNoReqStates,
   1.517 +    eARIAReadonly
   1.518 +  },
   1.519 +  { // status
   1.520 +    &nsGkAtoms::status,
   1.521 +    roles::STATUSBAR,
   1.522 +    kUseMapRole,
   1.523 +    eNoValue,
   1.524 +    eNoAction,
   1.525 +    ePoliteLiveAttr,
   1.526 +    kGenericAccType,
   1.527 +    kNoReqStates
   1.528 +  },
   1.529 +  { // tab
   1.530 +    &nsGkAtoms::tab,
   1.531 +    roles::PAGETAB,
   1.532 +    kUseMapRole,
   1.533 +    eNoValue,
   1.534 +    eSwitchAction,
   1.535 +    eNoLiveAttr,
   1.536 +    kGenericAccType,
   1.537 +    kNoReqStates,
   1.538 +    eARIASelectable
   1.539 +  },
   1.540 +  { // tablist
   1.541 +    &nsGkAtoms::tablist,
   1.542 +    roles::PAGETABLIST,
   1.543 +    kUseMapRole,
   1.544 +    eNoValue,
   1.545 +    eNoAction,
   1.546 +    eNoLiveAttr,
   1.547 +    eSelect,
   1.548 +    kNoReqStates
   1.549 +  },
   1.550 +  { // tabpanel
   1.551 +    &nsGkAtoms::tabpanel,
   1.552 +    roles::PROPERTYPAGE,
   1.553 +    kUseMapRole,
   1.554 +    eNoValue,
   1.555 +    eNoAction,
   1.556 +    eNoLiveAttr,
   1.557 +    kGenericAccType,
   1.558 +    kNoReqStates
   1.559 +  },
   1.560 +  { // textbox
   1.561 +    &nsGkAtoms::textbox,
   1.562 +    roles::ENTRY,
   1.563 +    kUseMapRole,
   1.564 +    eNoValue,
   1.565 +    eActivateAction,
   1.566 +    eNoLiveAttr,
   1.567 +    kGenericAccType,
   1.568 +    kNoReqStates,
   1.569 +    eARIAAutoComplete,
   1.570 +    eARIAMultiline,
   1.571 +    eARIAReadonlyOrEditable
   1.572 +  },
   1.573 +  { // timer
   1.574 +    &nsGkAtoms::timer,
   1.575 +    roles::NOTHING,
   1.576 +    kUseNativeRole,
   1.577 +    eNoValue,
   1.578 +    eNoAction,
   1.579 +    eOffLiveAttr,
   1.580 +    kNoReqStates
   1.581 +  },
   1.582 +  { // toolbar
   1.583 +    &nsGkAtoms::toolbar,
   1.584 +    roles::TOOLBAR,
   1.585 +    kUseMapRole,
   1.586 +    eNoValue,
   1.587 +    eNoAction,
   1.588 +    eNoLiveAttr,
   1.589 +    kGenericAccType,
   1.590 +    kNoReqStates
   1.591 +  },
   1.592 +  { // tooltip
   1.593 +    &nsGkAtoms::tooltip,
   1.594 +    roles::TOOLTIP,
   1.595 +    kUseMapRole,
   1.596 +    eNoValue,
   1.597 +    eNoAction,
   1.598 +    eNoLiveAttr,
   1.599 +    kGenericAccType,
   1.600 +    kNoReqStates
   1.601 +  },
   1.602 +  { // tree
   1.603 +    &nsGkAtoms::tree,
   1.604 +    roles::OUTLINE,
   1.605 +    kUseMapRole,
   1.606 +    eNoValue,
   1.607 +    eNoAction,
   1.608 +    eNoLiveAttr,
   1.609 +    eSelect,
   1.610 +    kNoReqStates,
   1.611 +    eARIAReadonly,
   1.612 +    eARIAMultiSelectable,
   1.613 +    eFocusableUntilDisabled
   1.614 +  },
   1.615 +  { // treegrid
   1.616 +    &nsGkAtoms::treegrid,
   1.617 +    roles::TREE_TABLE,
   1.618 +    kUseMapRole,
   1.619 +    eNoValue,
   1.620 +    eNoAction,
   1.621 +    eNoLiveAttr,
   1.622 +    eSelect | eTable,
   1.623 +    kNoReqStates,
   1.624 +    eARIAReadonlyOrEditable,
   1.625 +    eARIAMultiSelectable,
   1.626 +    eFocusableUntilDisabled
   1.627 +  },
   1.628 +  { // treeitem
   1.629 +    &nsGkAtoms::treeitem,
   1.630 +    roles::OUTLINEITEM,
   1.631 +    kUseMapRole,
   1.632 +    eNoValue,
   1.633 +    eActivateAction, // XXX: should expose second 'expand/collapse' action based
   1.634 +                     // on states
   1.635 +    eNoLiveAttr,
   1.636 +    kGenericAccType,
   1.637 +    kNoReqStates,
   1.638 +    eARIASelectable,
   1.639 +    eARIACheckedMixed
   1.640 +  }
   1.641 +};
   1.642 +
   1.643 +static nsRoleMapEntry sLandmarkRoleMap = {
   1.644 +  &nsGkAtoms::_empty,
   1.645 +  roles::NOTHING,
   1.646 +  kUseNativeRole,
   1.647 +  eNoValue,
   1.648 +  eNoAction,
   1.649 +  eNoLiveAttr,
   1.650 +  kGenericAccType,
   1.651 +  kNoReqStates
   1.652 +};
   1.653 +
   1.654 +nsRoleMapEntry aria::gEmptyRoleMap = {
   1.655 +  &nsGkAtoms::_empty,
   1.656 +  roles::NOTHING,
   1.657 +  kUseMapRole,
   1.658 +  eNoValue,
   1.659 +  eNoAction,
   1.660 +  eNoLiveAttr,
   1.661 +  kGenericAccType,
   1.662 +  kNoReqStates
   1.663 +};
   1.664 +
   1.665 +/**
   1.666 + * Universal (Global) states:
   1.667 + * The following state rules are applied to any accessible element,
   1.668 + * whether there is an ARIA role or not:
   1.669 + */
   1.670 +static const EStateRule sWAIUnivStateMap[] = {
   1.671 +  eARIABusy,
   1.672 +  eARIADisabled,
   1.673 +  eARIAExpanded,  // Currently under spec review but precedent exists
   1.674 +  eARIAHasPopup,  // Note this is technically a "property"
   1.675 +  eARIAInvalid,
   1.676 +  eARIARequired,  // XXX not global, Bug 553117
   1.677 +  eARIANone
   1.678 +};
   1.679 +
   1.680 +
   1.681 +/**
   1.682 + * ARIA attribute map for attribute characteristics.
   1.683 + * @note ARIA attributes that don't have any flags are not included here.
   1.684 + */
   1.685 +
   1.686 +struct AttrCharacteristics
   1.687 +{
   1.688 +  nsIAtom** attributeName;
   1.689 +  const uint8_t characteristics;
   1.690 +};
   1.691 +
   1.692 +static const AttrCharacteristics gWAIUnivAttrMap[] = {
   1.693 +  {&nsGkAtoms::aria_activedescendant,  ATTR_BYPASSOBJ                               },
   1.694 +  {&nsGkAtoms::aria_atomic,   ATTR_BYPASSOBJ_IF_FALSE | ATTR_VALTOKEN | ATTR_GLOBAL },
   1.695 +  {&nsGkAtoms::aria_busy,                               ATTR_VALTOKEN | ATTR_GLOBAL },
   1.696 +  {&nsGkAtoms::aria_checked,           ATTR_BYPASSOBJ | ATTR_VALTOKEN               }, /* exposes checkable obj attr */
   1.697 +  {&nsGkAtoms::aria_controls,          ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.698 +  {&nsGkAtoms::aria_describedby,       ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.699 +  {&nsGkAtoms::aria_disabled,          ATTR_BYPASSOBJ | ATTR_VALTOKEN | ATTR_GLOBAL },
   1.700 +  {&nsGkAtoms::aria_dropeffect,                         ATTR_VALTOKEN | ATTR_GLOBAL },
   1.701 +  {&nsGkAtoms::aria_expanded,          ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.702 +  {&nsGkAtoms::aria_flowto,            ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.703 +  {&nsGkAtoms::aria_grabbed,                            ATTR_VALTOKEN | ATTR_GLOBAL },
   1.704 +  {&nsGkAtoms::aria_haspopup,          ATTR_BYPASSOBJ | ATTR_VALTOKEN | ATTR_GLOBAL },
   1.705 +  {&nsGkAtoms::aria_hidden,   ATTR_BYPASSOBJ_IF_FALSE | ATTR_VALTOKEN | ATTR_GLOBAL },
   1.706 +  {&nsGkAtoms::aria_invalid,           ATTR_BYPASSOBJ | ATTR_VALTOKEN | ATTR_GLOBAL },
   1.707 +  {&nsGkAtoms::aria_label,             ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.708 +  {&nsGkAtoms::aria_labelledby,        ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.709 +  {&nsGkAtoms::aria_level,             ATTR_BYPASSOBJ                               }, /* handled via groupPosition */
   1.710 +  {&nsGkAtoms::aria_live,                               ATTR_VALTOKEN | ATTR_GLOBAL },
   1.711 +  {&nsGkAtoms::aria_multiline,         ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.712 +  {&nsGkAtoms::aria_multiselectable,   ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.713 +  {&nsGkAtoms::aria_owns,              ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.714 +  {&nsGkAtoms::aria_orientation,                        ATTR_VALTOKEN               },
   1.715 +  {&nsGkAtoms::aria_posinset,          ATTR_BYPASSOBJ                               }, /* handled via groupPosition */
   1.716 +  {&nsGkAtoms::aria_pressed,           ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.717 +  {&nsGkAtoms::aria_readonly,          ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.718 +  {&nsGkAtoms::aria_relevant,          ATTR_BYPASSOBJ                 | ATTR_GLOBAL },
   1.719 +  {&nsGkAtoms::aria_required,          ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.720 +  {&nsGkAtoms::aria_selected,          ATTR_BYPASSOBJ | ATTR_VALTOKEN               },
   1.721 +  {&nsGkAtoms::aria_setsize,           ATTR_BYPASSOBJ                               }, /* handled via groupPosition */
   1.722 +  {&nsGkAtoms::aria_sort,                               ATTR_VALTOKEN               },
   1.723 +  {&nsGkAtoms::aria_valuenow,          ATTR_BYPASSOBJ                               },
   1.724 +  {&nsGkAtoms::aria_valuemin,          ATTR_BYPASSOBJ                               },
   1.725 +  {&nsGkAtoms::aria_valuemax,          ATTR_BYPASSOBJ                               },
   1.726 +  {&nsGkAtoms::aria_valuetext,         ATTR_BYPASSOBJ                               }
   1.727 +};
   1.728 +
   1.729 +nsRoleMapEntry*
   1.730 +aria::GetRoleMap(nsINode* aNode)
   1.731 +{
   1.732 +  nsIContent* content = nsCoreUtils::GetRoleContent(aNode);
   1.733 +  nsAutoString roles;
   1.734 +  if (!content ||
   1.735 +      !content->GetAttr(kNameSpaceID_None, nsGkAtoms::role, roles) ||
   1.736 +      roles.IsEmpty()) {
   1.737 +    // We treat role="" as if the role attribute is absent (per aria spec:8.1.1)
   1.738 +    return nullptr;
   1.739 +  }
   1.740 +
   1.741 +  nsWhitespaceTokenizer tokenizer(roles);
   1.742 +  while (tokenizer.hasMoreTokens()) {
   1.743 +    // Do a binary search through table for the next role in role list
   1.744 +    const nsDependentSubstring role = tokenizer.nextToken();
   1.745 +    uint32_t low = 0;
   1.746 +    uint32_t high = ArrayLength(sWAIRoleMaps);
   1.747 +    while (low < high) {
   1.748 +      uint32_t idx = (low + high) / 2;
   1.749 +      int32_t compare = Compare(role, sWAIRoleMaps[idx].ARIARoleString());
   1.750 +      if (compare == 0)
   1.751 +        return sWAIRoleMaps + idx;
   1.752 +
   1.753 +      if (compare < 0)
   1.754 +        high = idx;
   1.755 +      else
   1.756 +        low = idx + 1;
   1.757 +    }
   1.758 +  }
   1.759 +
   1.760 +  // Always use some entry if there is a non-empty role string
   1.761 +  // To ensure an accessible object is created
   1.762 +  return &sLandmarkRoleMap;
   1.763 +}
   1.764 +
   1.765 +uint64_t
   1.766 +aria::UniversalStatesFor(mozilla::dom::Element* aElement)
   1.767 +{
   1.768 +  uint64_t state = 0;
   1.769 +  uint32_t index = 0;
   1.770 +  while (MapToState(sWAIUnivStateMap[index], aElement, &state))
   1.771 +    index++;
   1.772 +
   1.773 +  return state;
   1.774 +}
   1.775 +
   1.776 +uint8_t
   1.777 +aria::AttrCharacteristicsFor(nsIAtom* aAtom)
   1.778 +{
   1.779 +  for (uint32_t i = 0; i < ArrayLength(gWAIUnivAttrMap); i++)
   1.780 +    if (*gWAIUnivAttrMap[i].attributeName == aAtom)
   1.781 +      return gWAIUnivAttrMap[i].characteristics;
   1.782 +
   1.783 +  return 0;
   1.784 +}
   1.785 +
   1.786 +////////////////////////////////////////////////////////////////////////////////
   1.787 +// AttrIterator class
   1.788 +
   1.789 +bool
   1.790 +AttrIterator::Next(nsAString& aAttrName, nsAString& aAttrValue)
   1.791 +{
   1.792 +  while (mAttrIdx < mAttrCount) {
   1.793 +    const nsAttrName* attr = mContent->GetAttrNameAt(mAttrIdx);
   1.794 +    mAttrIdx++;
   1.795 +    if (attr->NamespaceEquals(kNameSpaceID_None)) {
   1.796 +      nsIAtom* attrAtom = attr->Atom();
   1.797 +      nsDependentAtomString attrStr(attrAtom);
   1.798 +      if (!StringBeginsWith(attrStr, NS_LITERAL_STRING("aria-")))
   1.799 +        continue; // Not ARIA
   1.800 +
   1.801 +      uint8_t attrFlags = aria::AttrCharacteristicsFor(attrAtom);
   1.802 +      if (attrFlags & ATTR_BYPASSOBJ)
   1.803 +        continue; // No need to handle exposing as obj attribute here
   1.804 +
   1.805 +      if ((attrFlags & ATTR_VALTOKEN) &&
   1.806 +           !nsAccUtils::HasDefinedARIAToken(mContent, attrAtom))
   1.807 +        continue; // only expose token based attributes if they are defined
   1.808 +
   1.809 +      if ((attrFlags & ATTR_BYPASSOBJ_IF_FALSE) &&
   1.810 +          mContent->AttrValueIs(kNameSpaceID_None, attrAtom,
   1.811 +                                nsGkAtoms::_false, eCaseMatters)) {
   1.812 +        continue; // only expose token based attribute if value is not 'false'.
   1.813 +      }
   1.814 +
   1.815 +      nsAutoString value;
   1.816 +      if (mContent->GetAttr(kNameSpaceID_None, attrAtom, value)) {
   1.817 +        aAttrName.Assign(Substring(attrStr, 5));
   1.818 +        aAttrValue.Assign(value);
   1.819 +        return true;
   1.820 +      }
   1.821 +    }
   1.822 +  }
   1.823 +
   1.824 +  return false;
   1.825 +}
   1.826 +

mercurial