Commit c0706b86 authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Mac a11y] Fix a bug in which focus shifts to the webpage and reads

it automatically on page load.

This CL is the first of two to fix a bug in which focus shifts to the
webpage and automatically reads it on page load.

Voiceover shifts focus to the webpage on the new tab page. We need to
ensure that focus shifts to the webpage when a new page loads, and
stays in the omnibox when a user opens a new tab.

The fix: Do not fire AXLoadComplete when on Chrome's new tab page.

An earlier fix to this bug replaced the AXLoadComplete events with
AXNewDocumentLoadComplete events. Voiceover does not listen for the
latter, so we remove them here.

The urls for the Chrome new tab page were taken from
chrome/common/url_constants.h. The browser_accessibility_manager_mac
lives in content/ and does not depend on anything from chrome.

For a longer explanation of this change, see this document:
https://docs.google.com/document/d/19s6E0hjTyzB9XU44bdCpXNOaQ8c6nbLRnJbR1EsltL4/edit#

Bug: 1049320
Change-Id: I7f1ef175b9db9c5978a5c3308291d1ba4e2b0531
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2356187Reviewed-by: default avatarAaron Leventhal <aleventhal@chromium.org>
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Cr-Commit-Position: refs/heads/master@{#799788}
parent 16682adf
......@@ -101,8 +101,8 @@ AccessibilityEventRecorderMac::AccessibilityEventRecorderMac(
AddNotification(@"AXInvalidStatusChanged");
AddNotification(@"AXLiveRegionChanged");
AddNotification(@"AXLiveRegionCreated");
AddNotification(@"AXLoadComplete");
AddNotification(@"AXMenuItemSelected");
AddNotification(@"AXNewDocumentLoadComplete");
AddNotification(@"AXRowCollapsed");
AddNotification(@"AXRowExpanded");
AddNotification(NSAccessibilityFocusedUIElementChangedNotification);
......
......@@ -67,6 +67,9 @@ class CONTENT_EXPORT BrowserAccessibilityManagerMac
bool IsInGeneratedEventBatch(ui::AXEventGenerator::Event event_type) const;
// Returns whether this page is a new tab page on Chrome.
bool IsChromeNewTabPage();
// Keeps track of any edits that have been made by the user during a tree
// update. Used by NSAccessibilityValueChangedNotification.
// Maps AXNode IDs to value attribute changes.
......@@ -79,6 +82,6 @@ class CONTENT_EXPORT BrowserAccessibilityManagerMac
DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManagerMac);
};
}
} // namespace content
#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_MAC_H_
......@@ -16,6 +16,7 @@
#import "content/browser/accessibility/browser_accessibility_mac.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#include "ui/accessibility/ax_role_properties.h"
......@@ -69,8 +70,7 @@ enum AXTextEditType {
// Native mac notifications fired.
NSString* const NSAccessibilityAutocorrectionOccurredNotification =
@"AXAutocorrectionOccurred";
NSString* const NSAccessibilityNewDocumentLoadCompleteNotification =
@"AXNewDocumentLoadComplete";
NSString* const NSAccessibilityLoadCompleteNotification = @"AXLoadComplete";
NSString* const NSAccessibilityInvalidStatusChangedNotification =
@"AXInvalidStatusChanged";
NSString* const NSAccessibilityLiveRegionCreatedNotification =
......@@ -222,16 +222,15 @@ void BrowserAccessibilityManagerMac::FireGeneratedEvent(
}
break;
case ui::AXEventGenerator::Event::LOAD_COMPLETE:
// |NSAccessibilityNewDocumentLoadCompleteNotification| should only be
// fired on the top document.
// |NSAccessibilityNewDocumentLoadCompleteNotification| is the event that
// Webkit notifies VoiceOver that a page load has completed.
// TODO(crbug.com/1049320): Verify in MacOS 10.16 that the "Automatically
// speak the webpage" option in the VoiceOver utility is triggered upon
// observing this event.
if (IsRootTree()) {
mac_notification = NSAccessibilityNewDocumentLoadCompleteNotification;
// |NSAccessibilityLoadCompleteNotification| should only be fired on the
// top document and when the document is not Chrome's new tab page.
if (IsRootTree() && !IsChromeNewTabPage()) {
mac_notification = NSAccessibilityLoadCompleteNotification;
} else {
// Voiceover moves focus to the web content when it receives an
// AXLoadComplete event. On Chrome's new tab page, focus should stay
// in the omnibox, so we purposefully do not fire the AXLoadComplete
// event in this case.
return;
}
break;
......@@ -599,4 +598,14 @@ id BrowserAccessibilityManagerMac::GetWindow() {
return delegate()->AccessibilityGetNativeViewAccessibleForWindow();
}
bool BrowserAccessibilityManagerMac::IsChromeNewTabPage() {
if (!delegate() || !IsRootTree())
return false;
content::WebContents* web_contents = delegate()->AccessibilityWebContents();
const GURL& url = web_contents->GetVisibleURL();
return url == GURL("chrome://newtab/") ||
url == GURL("chrome://new-tab-page") ||
url == GURL("chrome-search://local-ntp/local-ntp.html");
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment