Closed Bug 1843825 Opened 2 years ago Closed 2 years ago

Remove unused roles

Categories

(Core :: Disability Access APIs, task)

task

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox117 --- fixed

People

(Reporter: Jamie, Assigned: Jamie)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

We have 52 unused cross-platform roles. Most of these are from platform APIs, but we don't expose them anywhere. This is rather tedious/confusing, especially when making major changes to RoleMap; e.g. bug 1824935, bug 798492.

Some of these roles were duplicates, while others were just never used.
This removes the following roles:

  • TITLEBAR
  • GRIP
  • SOUND
  • CURSOR
  • CARET
  • WINDOW
  • CHART
  • BORDER
  • COLUMN
  • HELPBALLOON
  • CHARACTER
  • INDICATOR
  • DROPLIST
  • DIAL
  • HOTKEYFIELD
  • EQUATION
  • BUTTONDROPDOWNGRID
  • CLOCK
  • SPLITBUTTON
  • IPADDRESS
  • ACCEL_LABEL
  • ARROW
  • COLOR_CHOOSER
  • DESKTOP_ICON
  • DESKTOP_FRAME
  • DIRECTORY_PANE
  • FILE_CHOOSER
  • FONT_CHOOSER
  • GLASS_PANE
  • HTML_CONTAINER
  • ICON
  • LAYERED_PANE
  • OPTION_PANE
  • POPUP_MENU
  • ROOT_PANE
  • SCROLL_PANE
  • SPLIT_PANE
  • TABLE_COLUMN_HEADER
  • TABLE_ROW_HEADER
  • TEAR_OFF_MENU_ITEM
  • TERMINAL
  • VIEWPORT
  • HEADER
  • FOOTER
  • RULER
  • AUTOCOMPLETE
  • EDITBAR
  • PAGE
  • REDUNDANT_OBJECT
  • IME
  • CALENDAR
  • EMBEDDED_OBJECT

This was done with the following script:

import re

RE_ENUM = re.compile(r'^([^=]*= *)([\d]+)([^=]*\n)$')

def processFile(fn):
  inLines = open(fn, 'rt').readlines()
  outLines = []
  outNum = 0
  for inLine in inLines:
    m = RE_ENUM.match(inLine)
    if m:
      # Group 1 is the part of the line before the number.
      # Group 2 is the number.
      # Group 3 is the rest of the line after the number.
      inNum = int(m.group(2))
      if outNum == 0 and inNum != 0:
        raise ValueError("The first enum value isn't 0: %s" % inLine)
      outLine = m.group(1) + str(outNum) + m.group(3)
      outNum += 1
    else:
      outLine = inLine
    outLines.append(outLine)
  open(fn, 'wt').writelines(outLines)

processFile("accessible/base/Role.h")
processFile("accessible/interfaces/nsIAccessibleRole.idl")

For future reference, here's a Python script to find unused roles:

#!/usr/bin/python3
import re
import subprocess

RE_GREP_COMMENT = re.compile(r'^[^:]+: *(//|\*)')
def checkUnused(role):
  out = subprocess.run(
    ("git", "grep", "-P",
      r'(roles::|[^_]ROLE_)' + role + r'[^A-Z_]',
      'accessible/base', 'accessible/generic', 'accessible/html',
      'accessible/xul'),
    stdout=subprocess.PIPE).stdout
  if not out:
    print(role)
    return
  if all(RE_GREP_COMMENT.search(line)
      for line in out.decode("UTF-8").splitlines()):
    print("%s (appears in comments only)" % role)

RE_ROLE = re.compile(r'^ *([A-Z_]+) *= *[\d]+[^=]*$')

for line in open("accessible/base/Role.h", "rt"):
  m = RE_ROLE.match(line)
  if not m:
    continue
  role = m.group(1)
  checkUnused(role)
Pushed by jteh@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/96a62cce7639 part 1: Remove unused Gecko a11y roles. r=eeejay https://hg.mozilla.org/integration/autoland/rev/ea98d441cef7 part 2: Renumber roles to fill in the gaps left by removed roles. r=eeejay
Blocks: 1844238
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: