Commit b538315d authored by Eitan Isaacson's avatar Eitan Isaacson
Browse files

Bug 1198336 - P4: Post AXLiveRegionChanged when live regions change. r=morgan

VoiceOver seems to do all the heavy lifting of figuring out what portion of the
live region should be read.

Depends on D96293

Differential Revision: https://phabricator.services.mozilla.com/D96294
parent 09d4370b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -259,6 +259,7 @@ nsresult AccessibleWrap::HandleAccEvent(AccEvent* aEvent) {
    case nsIAccessibleEvent::EVENT_SELECTION_REMOVE:
    case nsIAccessibleEvent::EVENT_LIVE_REGION_ADDED:
    case nsIAccessibleEvent::EVENT_LIVE_REGION_REMOVED:
    case nsIAccessibleEvent::EVENT_NAME_CHANGE:
      [nativeAcc handleAccessibleEvent:eventType];
      break;

+2 −1
Original line number Diff line number Diff line
@@ -85,7 +85,8 @@ void ProxyEvent(ProxyAccessible* aProxy, uint32_t aEventType) {
      aEventType != nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE &&
      aEventType != nsIAccessibleEvent::EVENT_REORDER &&
      aEventType != nsIAccessibleEvent::EVENT_LIVE_REGION_ADDED &&
      aEventType != nsIAccessibleEvent::EVENT_LIVE_REGION_REMOVED)
      aEventType != nsIAccessibleEvent::EVENT_LIVE_REGION_REMOVED &&
      aEventType != nsIAccessibleEvent::EVENT_NAME_CHANGE)
    return;

  mozAccessible* wrapper = GetNativeFromGeckoAccessible(aProxy);
+16 −1
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ using namespace mozilla::a11y;
- (BOOL)providesLabelNotTitle;

- (nsStaticAtom*)ARIARole;

- (void)maybePostLiveRegionChanged;
@end

@implementation mozAccessible
@@ -938,11 +940,20 @@ struct RoleDescrComparator {
  return NO;
}

- (void)maybePostLiveRegionChanged {
  for (id element = self; [element conformsToProtocol:@protocol(MOXAccessible)];
       element = [element moxUnignoredParent]) {
    if ([element moxIsLiveRegion]) {
      [element moxPostNotification:@"AXLiveRegionChanged"];
      return;
    }
  }
}

- (void)handleAccessibleTextChangeEvent:(NSString*)change
                               inserted:(BOOL)isInserted
                            inContainer:(const AccessibleOrProxy&)container
                                     at:(int32_t)start {
  // XXX: Eventually live region handling will go here.
}

- (void)handleAccessibleEvent:(uint32_t)eventType {
@@ -997,6 +1008,10 @@ struct RoleDescrComparator {
    case nsIAccessibleEvent::EVENT_LIVE_REGION_REMOVED:
      mIsLiveRegion = false;
      break;
    case nsIAccessibleEvent::EVENT_REORDER:
    case nsIAccessibleEvent::EVENT_NAME_CHANGE:
      [self maybePostLiveRegionChanged];
      break;
  }
}

+44 −0
Original line number Diff line number Diff line
@@ -118,3 +118,47 @@ addAccessibleTask(
    );
  }
);

/**
 * Test live region changes
 */
addAccessibleTask(
  `
  <div id="live" aria-live="polite">
  The time is <span id="time">4:55pm</span>
  <p id="p" style="display: none">Georgia on my mind</p>
  <button id="button" aria-label="Start"></button>
  </div>
  `,
  async (browser, accDoc) => {
    let liveRegionChanged = waitForMacEvent("AXLiveRegionChanged", "live");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("time").textContent = "4:56pm";
    });
    await liveRegionChanged;
    ok(true, "changed textContent");

    liveRegionChanged = waitForMacEvent("AXLiveRegionChanged", "live");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("p").style.display = "block";
    });
    await liveRegionChanged;
    ok(true, "changed display style to block");

    liveRegionChanged = waitForMacEvent("AXLiveRegionChanged", "live");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("p").style.display = "none";
    });
    await liveRegionChanged;
    ok(true, "changed display style to none");

    liveRegionChanged = waitForMacEvent("AXLiveRegionChanged", "live");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("button")
        .setAttribute("aria-label", "Stop");
    });
    await liveRegionChanged;
    ok(true, "changed aria-label");
  }
);