Bug 1506041 - Code cleanup: Convert more static functions to lambdas in the markup map, r=Jamie
authorMarco Zehe <mzehe@mozilla.com>
Sun, 11 Nov 2018 23:13:35 +0000
changeset 445847 d4a258084934eb4bbddd24f592654387d154bb4b
parent 445846 244e82052be1aad0bc2df0fd621719f5817f210c
child 445848 9018814d9671dfe67ab073869bdeebf05b25b565
push id109783
push userapavel@mozilla.com
push dateMon, 12 Nov 2018 10:17:43 +0000
treeherdermozilla-inbound@32fdd47e849a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1506041
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506041 - Code cleanup: Convert more static functions to lambdas in the markup map, r=Jamie All static functions from nsAccessibilityService that were either only called once from the markup map, or are simple one-liners that were only called up to three times, were converted to lambdas in the markup map. the static function that creates HyperTextAccessibleWrap has remained untouched because it is called a lot from the markup map, even though its implementation is actually just a one-liner. The other untouched static function is the templated one for html:dt or html:dd. Differential Revision: https://phabricator.services.mozilla.com/D11458
accessible/base/MarkupMap.h
accessible/base/nsAccessibilityService.cpp
--- a/accessible/base/MarkupMap.h
+++ b/accessible/base/MarkupMap.h
@@ -1,18 +1,30 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=2:
  */
 /* 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/. */
 
-MARKUPMAP(a,
-          New_HTMLLink,
-          roles::LINK)
+MARKUPMAP(
+  a,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     // Only some roles truly enjoy life as HTMLLinkAccessibles, for details
+     // see closed bug 494807.
+     const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aElement);
+     if (roleMapEntry && roleMapEntry->role != roles::NOTHING &&
+         roleMapEntry->role != roles::LINK) {
+       return new HyperTextAccessibleWrap(aElement, aContext->Document());
+     }
+
+     return new HTMLLinkAccessible(aElement, aContext->Document());
+  },
+  roles::LINK
+)
 
 MARKUPMAP(abbr,
           New_HyperText,
           0)
 
 MARKUPMAP(acronym,
           New_HyperText,
           0)
@@ -41,48 +53,68 @@ MARKUPMAP(del,
 MARKUPMAP(details,
           New_HyperText,
           roles::DETAILS)
 
 MARKUPMAP(div,
           nullptr,
           roles::SECTION)
 
-MARKUPMAP(dl,
-          New_HTMLList,
-          roles::DEFINITION_LIST)
+MARKUPMAP(
+  dl,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLListAccessible(aElement, aContext->Document());
+  },
+  roles::DEFINITION_LIST
+)
 
 MARKUPMAP(dt,
           New_HTMLDtOrDd<HTMLLIAccessible>,
           roles::TERM)
 
-MARKUPMAP(figcaption,
-          New_HTMLFigcaption,
-          roles::CAPTION)
+MARKUPMAP(
+  figcaption,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLFigcaptionAccessible(aElement, aContext->Document());
+  },
+  roles::CAPTION
+)
 
-MARKUPMAP(figure,
-          New_HTMLFigure,
-          roles::FIGURE,
-          Attr(xmlroles, figure))
+MARKUPMAP(
+  figure,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLFigureAccessible(aElement, aContext->Document());
+  },
+  roles::FIGURE,
+  Attr(xmlroles, figure)
+)
 
 MARKUPMAP(
   form,
   [](Element* aElement, Accessible* aContext) -> Accessible* {
      return new HTMLFormAccessible(aElement, aContext->Document());
   },
   0
 )
 
-MARKUPMAP(footer,
-          New_HTMLHeaderOrFooter,
-          0)
+MARKUPMAP(
+  footer,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document());
+  },
+  0
+)
 
-MARKUPMAP(header,
-          New_HTMLHeaderOrFooter,
-          0)
+MARKUPMAP(
+  header,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document());
+  },
+  0
+)
 
 MARKUPMAP(h1,
           New_HyperText,
           roles::HEADING)
 
 MARKUPMAP(h2,
           New_HyperText,
           roles::HEADING)
@@ -98,35 +130,74 @@ MARKUPMAP(h4,
 MARKUPMAP(h5,
           New_HyperText,
           roles::HEADING)
 
 MARKUPMAP(h6,
           New_HyperText,
           roles::HEADING)
 
-MARKUPMAP(input,
-          New_HTMLInput,
-          0)
+MARKUPMAP(
+  input,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
+                              nsGkAtoms::checkbox, eIgnoreCase)) {
+       return new CheckboxAccessible(aElement, aContext->Document());
+     }
+     if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
+                              nsGkAtoms::radio, eIgnoreCase)) {
+       return new HTMLRadioButtonAccessible(aElement, aContext->Document());
+     }
+     if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
+                              nsGkAtoms::time, eIgnoreCase)) {
+       return new EnumRoleAccessible<roles::GROUPING>(aElement, aContext->Document());
+     }
+     if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
+                              nsGkAtoms::date, eIgnoreCase)) {
+    return new EnumRoleAccessible<roles::DATE_EDITOR>(aElement, aContext->Document());
+     }
+     return nullptr;
+  },
+  0
+)
 
 MARKUPMAP(ins,
           New_HyperText,
           roles::CONTENT_INSERTION)
 
-MARKUPMAP(label,
-          New_HTMLLabel,
-          roles::LABEL)
+MARKUPMAP(
+  label,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLLabelAccessible(aElement, aContext->Document());
+  },
+  roles::LABEL
+)
 
-MARKUPMAP(legend,
-          New_HTMLLegend,
-          roles::LABEL)
+MARKUPMAP(
+  legend,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLLegendAccessible(aElement, aContext->Document());
+  },
+  roles::LABEL
+)
 
-MARKUPMAP(li,
-          New_HTMLListitem,
-          0)
+MARKUPMAP(
+  li,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     // 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() == aElement->GetParent()) {
+       return new HTMLLIAccessible(aElement, aContext->Document());
+     }
+
+     return nullptr;
+  },
+  0
+)
 
 MARKUPMAP(main,
           New_HyperText,
           roles::LANDMARK)
 
 MARKUPMAP(map,
           nullptr,
           roles::TEXT_CONTAINER)
@@ -227,34 +298,50 @@ MARKUPMAP(munderover_,
           AttrFromDOM(accent_, accent_),
           AttrFromDOM(accentunder_, accentunder_),
           AttrFromDOM(align, align))
 
 MARKUPMAP(mmultiscripts_,
           New_HyperText,
           roles::MATHML_MULTISCRIPTS)
 
-MARKUPMAP(mtable_,
-          New_HTMLTableAccessible,
-          roles::MATHML_TABLE,
-          AttrFromDOM(align, align),
-          AttrFromDOM(columnlines_, columnlines_),
-          AttrFromDOM(rowlines_, rowlines_))
+MARKUPMAP(
+  mtable_,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLTableAccessible(aElement, aContext->Document());
+  },
+  roles::MATHML_TABLE,
+  AttrFromDOM(align, align),
+  AttrFromDOM(columnlines_, columnlines_),
+  AttrFromDOM(rowlines_, rowlines_)
+)
 
-MARKUPMAP(mlabeledtr_,
-          New_HTMLTableRowAccessible,
-          roles::MATHML_LABELED_ROW)
+MARKUPMAP(
+  mlabeledtr_,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLTableRowAccessible(aElement, aContext->Document());
+  },
+  roles::MATHML_LABELED_ROW
+)
 
-MARKUPMAP(mtr_,
-          New_HTMLTableRowAccessible,
-          roles::MATHML_TABLE_ROW)
+MARKUPMAP(
+  mtr_,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLTableRowAccessible(aElement, aContext->Document());
+  },
+  roles::MATHML_TABLE_ROW
+)
 
-MARKUPMAP(mtd_,
-          New_HTMLTableCellAccessible,
-          roles::MATHML_CELL)
+MARKUPMAP(
+  mtd_,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLTableCellAccessible(aElement, aContext->Document());
+  },
+  roles::MATHML_CELL
+)
 
 MARKUPMAP(maction_,
           New_HyperText,
           roles::MATHML_ACTION,
           AttrFromDOM(actiontype_, actiontype_),
           AttrFromDOM(selection_, selection_))
 
 MARKUPMAP(merror_,
@@ -298,56 +385,80 @@ MARKUPMAP(msline_,
           New_HyperText,
           roles::MATHML_STACK_LINE,
           AttrFromDOM(position, position))
 
 MARKUPMAP(nav,
           New_HyperText,
           roles::LANDMARK)
 
-MARKUPMAP(ol,
-          New_HTMLList,
-          roles::LIST)
+MARKUPMAP(
+  ol,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLListAccessible(aElement, aContext->Document());
+  },
+  roles::LIST
+)
 
-MARKUPMAP(option,
-          New_HTMLOption,
-          0)
+MARKUPMAP(
+  option,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLSelectOptionAccessible(aElement, aContext->Document());
+  },
+  0
+)
 
-MARKUPMAP(optgroup,
-          New_HTMLOptgroup,
-          0)
+MARKUPMAP(
+  optgroup,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLSelectOptGroupAccessible(aElement, aContext->Document());
+  },
+  0
+)
 
-MARKUPMAP(output,
-          New_HTMLOutput,
-          roles::SECTION,
-          Attr(live, polite))
+MARKUPMAP(
+  output,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLOutputAccessible(aElement, aContext->Document());
+  },
+  roles::SECTION,
+  Attr(live, polite)
+)
 
 MARKUPMAP(p,
           nullptr,
           roles::PARAGRAPH)
 
-MARKUPMAP(progress,
-          New_HTMLProgress,
-          0)
+MARKUPMAP(
+  progress,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLProgressMeterAccessible(aElement, aContext->Document());
+  },
+  0
+)
 
 MARKUPMAP(q,
           New_HyperText,
           0)
 
 MARKUPMAP(
   section,
   [](Element* aElement, Accessible* aContext) -> Accessible* {
      return new HTMLSectionAccessible(aElement, aContext->Document());
   },
   0
 )
 
-MARKUPMAP(summary,
-          New_HTMLSummary,
-          roles::SUMMARY)
+MARKUPMAP(
+  summary,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLSummaryAccessible(aElement, aContext->Document());
+  },
+  roles::SUMMARY
+)
 
 MARKUPMAP(
   table,
   [](Element* aElement, Accessible* aContext) -> Accessible* {
      if (aElement->GetPrimaryFrame() &&
          aElement->GetPrimaryFrame()->AccessibleType() != eHTMLTableType) {
        return new ARIAGridAccessibleWrap(aElement, aContext->Document());
      }
@@ -425,11 +536,15 @@ MARKUPMAP(
           }
         }
       }
       return nullptr;
   },
   0
 )
 
-MARKUPMAP(ul,
-          New_HTMLList,
-          roles::LIST)
+MARKUPMAP(
+  ul,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLListAccessible(aElement, aContext->Document());
+  },
+  roles::LIST
+)
--- a/accessible/base/nsAccessibilityService.cpp
+++ b/accessible/base/nsAccessibilityService.cpp
@@ -164,66 +164,19 @@ CreateMenupopupAccessible(Element* aElem
 
     return new XULMenupopupAccessible(aElement, aContext->Document());
 }
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
 // Accessible constructors
 
-static Accessible*
-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(aElement);
-  if (roleMapEntry && roleMapEntry->role != roles::NOTHING &&
-      roleMapEntry->role != roles::LINK) {
-    return new HyperTextAccessibleWrap(aElement, aContext->Document());
-  }
-
-  return new HTMLLinkAccessible(aElement, aContext->Document());
-}
-
 static Accessible* New_HyperText(Element* aElement, Accessible* aContext)
   { return new HyperTextAccessibleWrap(aElement, aContext->Document()); }
 
-static Accessible* New_HTMLFigcaption(Element* aElement, Accessible* aContext)
-  { return new HTMLFigcaptionAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLFigure(Element* aElement, Accessible* aContext)
-  { return new HTMLFigureAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLHeaderOrFooter(Element* aElement, Accessible* aContext)
-  { return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLLegend(Element* aElement, Accessible* aContext)
-  { return new HTMLLegendAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLOption(Element* aElement, Accessible* aContext)
-  { return new HTMLSelectOptionAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLOptgroup(Element* aElement, Accessible* aContext)
-  { return new HTMLSelectOptGroupAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLList(Element* aElement, Accessible* aContext)
-  { return new HTMLListAccessible(aElement, aContext->Document()); }
-
-static Accessible*
-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() == aElement->GetParent())
-    return new HTMLLIAccessible(aElement, aContext->Document());
-
-  return nullptr;
-}
-
 template<typename AccClass>
 static Accessible*
 New_HTMLDtOrDd(Element* aElement, Accessible* aContext)
 {
   nsIContent* parent = aContext->GetContent();
   if (parent->IsHTMLElement(nsGkAtoms::div)) {
     // It is conforming in HTML to use a div to group dt/dd elements.
     parent = parent->GetParent();
@@ -231,61 +184,16 @@ New_HTMLDtOrDd(Element* aElement, Access
 
   if (parent && parent->IsHTMLElement(nsGkAtoms::dl)) {
     return new AccClass(aElement, aContext->Document());
   }
 
   return nullptr;
 }
 
-static Accessible* New_HTMLLabel(Element* aElement, Accessible* aContext)
-  { return new HTMLLabelAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLInput(Element* aElement, Accessible* aContext)
-{
-  if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
-                           nsGkAtoms::checkbox, eIgnoreCase)) {
-    return new CheckboxAccessible(aElement, aContext->Document());
-  }
-  if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
-                           nsGkAtoms::radio, eIgnoreCase)) {
-    return new HTMLRadioButtonAccessible(aElement, aContext->Document());
-  }
-  if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
-                           nsGkAtoms::time, eIgnoreCase)) {
-    return new EnumRoleAccessible<roles::GROUPING>(aElement, aContext->Document());
-  }
-  if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
-                           nsGkAtoms::date, eIgnoreCase)) {
-    return new EnumRoleAccessible<roles::DATE_EDITOR>(aElement, aContext->Document());
-  }
-  return nullptr;
-}
-
-static Accessible* New_HTMLOutput(Element* aElement, Accessible* aContext)
-  { return new HTMLOutputAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLProgress(Element* aElement, Accessible* aContext)
-  { return new HTMLProgressMeterAccessible(aElement, aContext->Document()); }
-
-static Accessible* New_HTMLSummary(Element* aElement, Accessible* aContext)
-  { return new HTMLSummaryAccessible(aElement, aContext->Document()); }
-
-static Accessible*
-New_HTMLTableAccessible(Element* aElement, Accessible* aContext)
-  { return new HTMLTableAccessible(aElement, aContext->Document()); }
-
-static Accessible*
-New_HTMLTableRowAccessible(Element* aElement, Accessible* aContext)
-  { return new HTMLTableRowAccessible(aElement, aContext->Document()); }
-
-static Accessible*
-New_HTMLTableCellAccessible(Element* aElement, Accessible* aContext)
-  { return new HTMLTableCellAccessible(aElement, aContext->Document()); }
-
 /**
  * Cached value of the PREF_ACCESSIBILITY_FORCE_DISABLED preference.
  */
 static int32_t sPlatformDisabledState = 0;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Markup maps array.