Bug 1442800 - Let New_Accessible take Element instead of nsIContent r=surkov

The passed nsIContent is always an Element.

MozReview-Commit-ID: IMvWuK6MIra

--HG--
extra : rebase_source : 520c6ea9d3bd90e480224315e0fc0ce7e5b7db27
This commit is contained in:
Timothy Guan-tin Chien 2018-03-06 13:47:43 -08:00
Родитель b076369cff
Коммит 686d0472da
3 изменённых файлов: 106 добавлений и 122 удалений

Просмотреть файл

@ -44,11 +44,10 @@ XULMAP_TYPE(tooltip, XULTooltipAccessible)
XULMAP(
colorpicker,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
if (aContent->IsElement() &&
aContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::button, eIgnoreCase)) {
return new XULColorPickerAccessible(aContent, aContext->Document());
[](Element* aElement, Accessible* aContext) -> Accessible* {
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::button, eIgnoreCase)) {
return new XULColorPickerAccessible(aElement, aContext->Document());
}
return nullptr;
}
@ -56,52 +55,47 @@ XULMAP(
XULMAP(
label,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
if (aContent->IsElement() &&
aContent->AsElement()->ClassList()->Contains(NS_LITERAL_STRING("text-link"))) {
return new XULLinkAccessible(aContent, aContext->Document());
[](Element* aElement, Accessible* aContext) -> Accessible* {
if (aElement->ClassList()->Contains(NS_LITERAL_STRING("text-link"))) {
return new XULLinkAccessible(aElement, aContext->Document());
}
return new XULLabelAccessible(aContent, aContext->Document());
return new XULLabelAccessible(aElement, aContext->Document());
}
)
XULMAP(
image,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
if (!aContent->IsElement()) {
return nullptr;
[](Element* aElement, Accessible* aContext) -> Accessible* {
if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::onclick)) {
return new XULToolbarButtonAccessible(aElement, aContext->Document());
}
if (aContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::onclick)) {
return new XULToolbarButtonAccessible(aContent, aContext->Document());
}
if (aContent->AsElement()->ClassList()->Contains(NS_LITERAL_STRING("colorpickertile"))) {
return new XULColorPickerTileAccessible(aContent, 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 (!aContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext)) {
if (!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext)) {
return nullptr;
}
return new ImageAccessibleWrap(aContent, aContext->Document());
return new ImageAccessibleWrap(aElement, aContext->Document());
}
)
XULMAP(
listcell,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
[](Element* aElement, Accessible* aContext) -> Accessible* {
// Only create cells if there's more than one per row.
nsIContent* listItem = aContent->GetParent();
nsIContent* listItem = aElement->GetParent();
if (!listItem) {
return nullptr;
}
for (nsIContent* child = listItem->GetFirstChild(); child;
child = child->GetNextSibling()) {
if (child->IsXULElement(nsGkAtoms::listcell) && child != aContent) {
return new XULListCellAccessibleWrap(aContent, aContext->Document());
if (child->IsXULElement(nsGkAtoms::listcell) && child != aElement) {
return new XULListCellAccessibleWrap(aElement, aContext->Document());
}
}
@ -111,59 +105,55 @@ XULMAP(
XULMAP(
menupopup,
[](nsIContent* aContent, Accessible* aContext) {
return CreateMenupopupAccessible(aContent, aContext);
[](Element* aElement, Accessible* aContext) {
return CreateMenupopupAccessible(aElement, aContext);
}
)
XULMAP(
panel,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
[](Element* aElement, Accessible* aContext) -> Accessible* {
static const Element::AttrValuesArray sIgnoreTypeVals[] =
{ &nsGkAtoms::autocomplete_richlistbox, &nsGkAtoms::autocomplete, nullptr };
if (!aContent->IsElement() ||
aContent->AsElement()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
sIgnoreTypeVals, eIgnoreCase) >= 0) {
if (aElement->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
sIgnoreTypeVals, eIgnoreCase) >= 0) {
return nullptr;
}
if (aContent->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::noautofocus,
nsGkAtoms::_true, eCaseMatters)) {
return new XULAlertAccessible(aContent, aContext->Document());
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautofocus,
nsGkAtoms::_true, eCaseMatters)) {
return new XULAlertAccessible(aElement, aContext->Document());
}
return new EnumRoleAccessible<roles::PANE>(aContent, aContext->Document());
return new EnumRoleAccessible<roles::PANE>(aElement, aContext->Document());
}
)
XULMAP(
popup,
[](nsIContent* aContent, Accessible* aContext) {
return CreateMenupopupAccessible(aContent, aContext);
[](Element* aElement, Accessible* aContext) {
return CreateMenupopupAccessible(aElement, aContext);
}
)
XULMAP(
textbox,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
if (aContent->IsElement() &&
aContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::autocomplete, eIgnoreCase)) {
return new XULComboboxAccessible(aContent, aContext->Document());
[](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>(aContent, aContext->Document());
return new EnumRoleAccessible<roles::SECTION>(aElement, aContext->Document());
}
)
XULMAP(
thumb,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
if (aContent->IsElement() &&
aContent->AsElement()->ClassList()->Contains(NS_LITERAL_STRING("scale-thumb"))) {
return new XULThumbAccessible(aContent, aContext->Document());
[](Element* aElement, Accessible* aContext) -> Accessible* {
if (aElement->ClassList()->Contains(NS_LITERAL_STRING("scale-thumb"))) {
return new XULThumbAccessible(aElement, aContext->Document());
}
return nullptr;
}
@ -171,8 +161,8 @@ XULMAP(
XULMAP(
tree,
[](nsIContent* aContent, Accessible* aContext) -> Accessible* {
nsIContent* child = nsTreeUtils::GetDescendantChild(aContent,
[](Element* aElement, Accessible* aContext) -> Accessible* {
nsIContent* child = nsTreeUtils::GetDescendantChild(aElement,
nsGkAtoms::treechildren);
if (!child)
return nullptr;
@ -187,10 +177,10 @@ XULMAP(
// Outline of list accessible.
if (count == 1) {
return new XULTreeAccessible(aContent, aContext->Document(), treeFrame);
return new XULTreeAccessible(aElement, aContext->Document(), treeFrame);
}
// Table or tree table accessible.
return new XULTreeGridAccessibleWrap(aContent, aContext->Document(), treeFrame);
return new XULTreeGridAccessibleWrap(aElement, aContext->Document(), treeFrame);
}
)

Просмотреть файл

@ -149,7 +149,7 @@ MustBeAccessible(nsIContent* aContent, DocAccessible* aDocument)
*/
#ifdef MOZ_XUL
Accessible*
CreateMenupopupAccessible(nsIContent* aContent, Accessible* aContext)
CreateMenupopupAccessible(Element* aElement, Accessible* aContext)
{
#ifdef MOZ_ACCESSIBILITY_ATK
// ATK considers this node to be redundant when within menubars, and it makes menu
@ -157,12 +157,12 @@ CreateMenupopupAccessible(nsIContent* aContent, Accessible* aContext)
// XXX In the future we will should this for consistency across the nsIAccessible
// implementations on each platform for a consistent scripting environment, but
// then strip out redundant accessibles in the AccessibleWrap class for each platform.
nsIContent *parent = aContent->GetParent();
nsIContent *parent = aElement->GetParent();
if (parent && parent->IsXULElement(nsGkAtoms::menu))
return nullptr;
#endif
return new XULMenupopupAccessible(aContent, aContext->Document());
return new XULMenupopupAccessible(aElement, aContext->Document());
}
#endif
@ -170,128 +170,122 @@ CreateMenupopupAccessible(nsIContent* aContent, Accessible* aContext)
// Accessible constructors
static Accessible*
New_HTMLLink(nsIContent* aContent, Accessible* aContext)
New_HTMLLink(Element* aElement, Accessible* aContext)
{
// Only some roles truly enjoy life as HTMLLinkAccessibles, for details
// see closed bug 494807.
const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aContent->AsElement());
const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aElement);
if (roleMapEntry && roleMapEntry->role != roles::NOTHING &&
roleMapEntry->role != roles::LINK) {
return new HyperTextAccessibleWrap(aContent, aContext->Document());
return new HyperTextAccessibleWrap(aElement, aContext->Document());
}
return new HTMLLinkAccessible(aContent, aContext->Document());
return new HTMLLinkAccessible(aElement, aContext->Document());
}
static Accessible* New_HyperText(nsIContent* aContent, Accessible* aContext)
{ return new HyperTextAccessibleWrap(aContent, aContext->Document()); }
static Accessible* New_HyperText(Element* aElement, Accessible* aContext)
{ return new HyperTextAccessibleWrap(aElement, aContext->Document()); }
static Accessible* New_HTMLFigcaption(nsIContent* aContent, Accessible* aContext)
{ return new HTMLFigcaptionAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLFigcaption(Element* aElement, Accessible* aContext)
{ return new HTMLFigcaptionAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLFigure(nsIContent* aContent, Accessible* aContext)
{ return new HTMLFigureAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLFigure(Element* aElement, Accessible* aContext)
{ return new HTMLFigureAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLHeaderOrFooter(nsIContent* aContent, Accessible* aContext)
{ return new HTMLHeaderOrFooterAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLHeaderOrFooter(Element* aElement, Accessible* aContext)
{ return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLLegend(nsIContent* aContent, Accessible* aContext)
{ return new HTMLLegendAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLLegend(Element* aElement, Accessible* aContext)
{ return new HTMLLegendAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLOption(nsIContent* aContent, Accessible* aContext)
{ return new HTMLSelectOptionAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLOption(Element* aElement, Accessible* aContext)
{ return new HTMLSelectOptionAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLOptgroup(nsIContent* aContent, Accessible* aContext)
{ return new HTMLSelectOptGroupAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLOptgroup(Element* aElement, Accessible* aContext)
{ return new HTMLSelectOptGroupAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLList(nsIContent* aContent, Accessible* aContext)
{ return new HTMLListAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLList(Element* aElement, Accessible* aContext)
{ return new HTMLListAccessible(aElement, aContext->Document()); }
static Accessible*
New_HTMLListitem(nsIContent* aContent, Accessible* aContext)
New_HTMLListitem(Element* aElement, Accessible* aContext)
{
// If list item is a child of accessible list then create an accessible for
// it unconditionally by tag name. nsBlockFrame creates the list item
// accessible for other elements styled as list items.
if (aContext->IsList() && aContext->GetContent() == aContent->GetParent())
return new HTMLLIAccessible(aContent, aContext->Document());
if (aContext->IsList() && aContext->GetContent() == aElement->GetParent())
return new HTMLLIAccessible(aElement, aContext->Document());
return nullptr;
}
static Accessible*
New_HTMLDefinition(nsIContent* aContent, Accessible* aContext)
New_HTMLDefinition(Element* aElement, Accessible* aContext)
{
if (aContext->IsList())
return new HyperTextAccessibleWrap(aContent, aContext->Document());
return new HyperTextAccessibleWrap(aElement, aContext->Document());
return nullptr;
}
static Accessible* New_HTMLLabel(nsIContent* aContent, Accessible* aContext)
{ return new HTMLLabelAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLLabel(Element* aElement, Accessible* aContext)
{ return new HTMLLabelAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLInput(nsIContent* aContent, Accessible* aContext)
static Accessible* New_HTMLInput(Element* aElement, Accessible* aContext)
{
if (!aContent->IsElement()) {
return nullptr;
}
Element* element = aContent->AsElement();
if (element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::checkbox, eIgnoreCase)) {
return new HTMLCheckboxAccessible(aContent, aContext->Document());
return new HTMLCheckboxAccessible(aElement, aContext->Document());
}
if (element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::radio, eIgnoreCase)) {
return new HTMLRadioButtonAccessible(aContent, aContext->Document());
return new HTMLRadioButtonAccessible(aElement, aContext->Document());
}
if (element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::time, eIgnoreCase)) {
return new EnumRoleAccessible<roles::GROUPING>(aContent, aContext->Document());
return new EnumRoleAccessible<roles::GROUPING>(aElement, aContext->Document());
}
if (element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::date, eIgnoreCase)) {
return new EnumRoleAccessible<roles::DATE_EDITOR>(aContent, aContext->Document());
return new EnumRoleAccessible<roles::DATE_EDITOR>(aElement, aContext->Document());
}
return nullptr;
}
static Accessible* New_HTMLOutput(nsIContent* aContent, Accessible* aContext)
{ return new HTMLOutputAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLOutput(Element* aElement, Accessible* aContext)
{ return new HTMLOutputAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLProgress(nsIContent* aContent, Accessible* aContext)
{ return new HTMLProgressMeterAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLProgress(Element* aElement, Accessible* aContext)
{ return new HTMLProgressMeterAccessible(aElement, aContext->Document()); }
static Accessible* New_HTMLSummary(nsIContent* aContent, Accessible* aContext)
{ return new HTMLSummaryAccessible(aContent, aContext->Document()); }
static Accessible* New_HTMLSummary(Element* aElement, Accessible* aContext)
{ return new HTMLSummaryAccessible(aElement, aContext->Document()); }
static Accessible*
New_HTMLTableAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableAccessible(aContent, aContext->Document()); }
New_HTMLTableAccessible(Element* aElement, Accessible* aContext)
{ return new HTMLTableAccessible(aElement, aContext->Document()); }
static Accessible*
New_HTMLTableRowAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableRowAccessible(aContent, aContext->Document()); }
New_HTMLTableRowAccessible(Element* aElement, Accessible* aContext)
{ return new HTMLTableRowAccessible(aElement, aContext->Document()); }
static Accessible*
New_HTMLTableCellAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableCellAccessible(aContent, aContext->Document()); }
New_HTMLTableCellAccessible(Element* aElement, Accessible* aContext)
{ return new HTMLTableCellAccessible(aElement, aContext->Document()); }
static Accessible*
New_HTMLTableHeaderCell(nsIContent* aContent, Accessible* aContext)
New_HTMLTableHeaderCell(Element* aElement, Accessible* aContext)
{
if (aContext->IsTableRow() && aContext->GetContent() == aContent->GetParent())
return new HTMLTableHeaderCellAccessibleWrap(aContent, aContext->Document());
if (aContext->IsTableRow() && aContext->GetContent() == aElement->GetParent())
return new HTMLTableHeaderCellAccessibleWrap(aElement, aContext->Document());
return nullptr;
}
static Accessible*
New_HTMLTableHeaderCellIfScope(nsIContent* aContent, Accessible* aContext)
New_HTMLTableHeaderCellIfScope(Element* aElement, Accessible* aContext)
{
if (aContext->IsTableRow() && aContext->GetContent() == aContent->GetParent() &&
aContent->IsElement() &&
aContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::scope))
return new HTMLTableHeaderCellAccessibleWrap(aContent, aContext->Document());
if (aContext->IsTableRow() && aContext->GetContent() == aElement->GetParent() &&
aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::scope))
return new HTMLTableHeaderCellAccessibleWrap(aElement, aContext->Document());
return nullptr;
}
@ -328,8 +322,8 @@ static const HTMLMarkupMapInfo sHTMLMarkupMapList[] = {
#define XULMAP_TYPE(atom, new_type) \
XULMAP( \
atom, \
[](nsIContent* aContent, Accessible* aContext) -> Accessible* { \
return new new_type(aContent, aContext->Document()); \
[](Element* aElement, Accessible* aContext) -> Accessible* { \
return new new_type(aElement, aContext->Document()); \
} \
)
@ -1178,7 +1172,7 @@ nsAccessibilityService::CreateAccessible(nsINode* aNode,
const HTMLMarkupMapInfo* markupMap =
mHTMLMarkupMap.Get(content->NodeInfo()->NameAtom());
if (markupMap && markupMap->new_func)
newAcc = markupMap->new_func(content, aContext);
newAcc = markupMap->new_func(content->AsElement(), aContext);
if (!newAcc) // try by frame accessible type.
newAcc = CreateAccessibleByFrameType(frame, content, aContext);
@ -1241,7 +1235,7 @@ nsAccessibilityService::CreateAccessible(nsINode* aNode,
const XULMarkupMapInfo* xulMap =
mXULMarkupMap.Get(content->NodeInfo()->NameAtom());
if (xulMap && xulMap->new_func) {
newAcc = xulMap->new_func(content, aContext);
newAcc = xulMap->new_func(content->AsElement(), aContext);
}
#endif
@ -1273,7 +1267,7 @@ nsAccessibilityService::CreateAccessible(nsINode* aNode,
const HTMLMarkupMapInfo* markupMap =
mHTMLMarkupMap.Get(content->NodeInfo()->NameAtom());
if (markupMap && markupMap->new_func)
newAcc = markupMap->new_func(content, aContext);
newAcc = markupMap->new_func(content->AsElement(), aContext);
// Fall back to text when encountering Content MathML.
if (!newAcc && !content->IsAnyOfMathMLElements(nsGkAtoms::annotation_,

Просмотреть файл

@ -51,7 +51,7 @@ SelectionManager* SelectionMgr();
ApplicationAccessible* ApplicationAcc();
xpcAccessibleApplication* XPCApplicationAcc();
typedef Accessible* (New_Accessible)(nsIContent* aContent, Accessible* aContext);
typedef Accessible* (New_Accessible)(Element* aElement, Accessible* aContext);
struct MarkupAttrInfo {
nsStaticAtom** name;