accessible/base/XULMap.h
author Paolo Amadini <paolo.mozmail@amadzone.org>
Wed, 18 Jul 2018 11:23:32 +0100
changeset 484907 38ebcdae9bca37cfdb17c2199030cbe4f2612aa8
parent 481535 7cf808cb0b0dbab494e3d6e7beefde0cbb07958c
child 491558 0af181b51b7638ea9990717ace6c09436a955607
permissions -rw-r--r--
Bug 1472555 - Part 5 - Remove the listbox layout. r=bz,surkov MozReview-Commit-ID: Bx1p1nTurCz

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

XULMAP_TYPE(browser, OuterDocAccessible)
XULMAP_TYPE(button, XULButtonAccessible)
XULMAP_TYPE(checkbox, XULCheckboxAccessible)
XULMAP_TYPE(description, XULLabelAccessible)
XULMAP_TYPE(dropMarker, XULDropmarkerAccessible)
XULMAP_TYPE(editor, OuterDocAccessible)
XULMAP_TYPE(findbar, XULToolbarAccessible)
XULMAP_TYPE(groupbox, XULGroupboxAccessible)
XULMAP_TYPE(iframe, OuterDocAccessible)
XULMAP_TYPE(listheader, XULColumAccessible)
XULMAP_TYPE(menu, XULMenuitemAccessibleWrap)
XULMAP_TYPE(menubar, XULMenubarAccessible)
XULMAP_TYPE(menucaption, XULMenuitemAccessibleWrap)
XULMAP_TYPE(menuitem, XULMenuitemAccessibleWrap)
XULMAP_TYPE(menulist, XULComboboxAccessible)
XULMAP_TYPE(menuseparator, XULMenuSeparatorAccessible)
XULMAP_TYPE(notification, XULAlertAccessible)
XULMAP_TYPE(progressmeter, XULProgressMeterAccessible)
XULMAP_TYPE(radio, XULRadioButtonAccessible)
XULMAP_TYPE(radiogroup, XULRadioGroupAccessible)
XULMAP_TYPE(richlistbox, XULListboxAccessibleWrap)
XULMAP_TYPE(richlistitem, XULListitemAccessible)
XULMAP_TYPE(statusbar, XULStatusBarAccessible)
XULMAP_TYPE(tab, XULTabAccessible)
XULMAP_TYPE(tabpanels, XULTabpanelsAccessible)
XULMAP_TYPE(tabs, XULTabsAccessible)
XULMAP_TYPE(toolbarseparator, XULToolbarSeparatorAccessible)
XULMAP_TYPE(toolbarspacer, XULToolbarSeparatorAccessible)
XULMAP_TYPE(toolbarspring, XULToolbarSeparatorAccessible)
XULMAP_TYPE(treecol, XULColumnItemAccessible)
XULMAP_TYPE(treecolpicker, XULButtonAccessible)
XULMAP_TYPE(treecols, XULTreeColumAccessible)
XULMAP_TYPE(toolbar, XULToolbarAccessible)
XULMAP_TYPE(toolbarbutton, XULToolbarButtonAccessible)
XULMAP_TYPE(tooltip, XULTooltipAccessible)

XULMAP(
  colorpicker,
  [](Element* aElement, Accessible* aContext) -> Accessible* {
    if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
                              nsGkAtoms::button, eIgnoreCase)) {
      return new XULColorPickerAccessible(aElement, aContext->Document());
    }
    return nullptr;
  }
)

XULMAP(
  label,
  [](Element* aElement, Accessible* aContext) -> Accessible* {
    if (aElement->ClassList()->Contains(NS_LITERAL_STRING("text-link"))) {
      return new XULLinkAccessible(aElement, aContext->Document());
    }
    return new XULLabelAccessible(aElement, aContext->Document());
  }
)

XULMAP(
  image,
  [](Element* aElement, Accessible* aContext) -> Accessible* {
    if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::onclick)) {
      return new XULToolbarButtonAccessible(aElement, aContext->Document());
    }

    if (aElement->ClassList()->Contains(NS_LITERAL_STRING("colorpickertile"))) {
      return new XULColorPickerTileAccessible(aElement, aContext->Document());
    }

    // Don't include nameless images in accessible tree.
    if (!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext)) {
      return nullptr;
    }

    return new ImageAccessibleWrap(aElement, aContext->Document());
  }
)

XULMAP(
  menupopup,
  [](Element* aElement, Accessible* aContext) {
    return CreateMenupopupAccessible(aElement, aContext);
  }
)

XULMAP(
  panel,
  [](Element* aElement, Accessible* aContext) -> Accessible* {
    static const Element::AttrValuesArray sIgnoreTypeVals[] =
      { &nsGkAtoms::autocomplete_richlistbox, &nsGkAtoms::autocomplete, nullptr };

    if (aElement->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
                                  sIgnoreTypeVals, eIgnoreCase) >= 0) {
      return nullptr;
    }

    if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautofocus,
                              nsGkAtoms::_true, eCaseMatters)) {
      return new XULAlertAccessible(aElement, aContext->Document());
    }

    return new EnumRoleAccessible<roles::PANE>(aElement, aContext->Document());
  }
)

XULMAP(
  popup,
  [](Element* aElement, Accessible* aContext) {
    return CreateMenupopupAccessible(aElement, aContext);
  }
)

XULMAP(
  textbox,
  [](Element* aElement, Accessible* aContext) -> Accessible* {
    if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
                              nsGkAtoms::autocomplete, eIgnoreCase)) {
      return new XULComboboxAccessible(aElement, aContext->Document());
    }

    return new EnumRoleAccessible<roles::SECTION>(aElement, aContext->Document());
  }
)

XULMAP(
  tree,
  [](Element* aElement, Accessible* aContext) -> Accessible* {
    nsIContent* child = nsTreeUtils::GetDescendantChild(aElement,
                                                        nsGkAtoms::treechildren);
    if (!child)
      return nullptr;

    nsTreeBodyFrame* treeFrame = do_QueryFrame(child->GetPrimaryFrame());
    if (!treeFrame)
      return nullptr;

    RefPtr<nsTreeColumns> treeCols = treeFrame->Columns();
    uint32_t count = treeCols->Count();

    // Outline of list accessible.
    if (count == 1) {
      return new XULTreeAccessible(aElement, aContext->Document(), treeFrame);
    }

    // Table or tree table accessible.
    return new XULTreeGridAccessibleWrap(aElement, aContext->Document(), treeFrame);
  }
)