Commit 74a9bdea authored by Josiah K's avatar Josiah K Committed by Commit Bot

Plumb through screen_magnifier_focus_following preference in magnifier

Wires in screen_magnifier_focus_following preference added in crrev.com/c/2506771.

AX-Relnotes: Allow Screen Magnifier Focus Following Pref to take effect in magnifier.
Fixed: 1146583
Change-Id: Ieeb8b81d0852ce330f671f931cfa2bfb02fd4067
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522905
Commit-Queue: Josiah Krutz <josiahk@google.com>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831245}
parent 442bdc90
...@@ -113,4 +113,5 @@ js_library("autoclick") { ...@@ -113,4 +113,5 @@ js_library("autoclick") {
js_library("magnifier") { js_library("magnifier") {
sources = [ "magnifier/magnifier.js" ] sources = [ "magnifier/magnifier.js" ]
externs_list = [ "$externs_path/settings_private.js" ]
} }
...@@ -41,14 +41,14 @@ class AccessibilityCommon { ...@@ -41,14 +41,14 @@ class AccessibilityCommon {
this.onAutoclickUpdated_.bind(this)); this.onAutoclickUpdated_.bind(this));
chrome.accessibilityFeatures.screenMagnifier.get( chrome.accessibilityFeatures.screenMagnifier.get(
{}, this.onMagnifierUpdated_.bind(this)); {}, this.onMagnifierUpdated_.bind(this, Magnifier.Type.FULL_SCREEN));
chrome.accessibilityFeatures.screenMagnifier.onChange.addListener( chrome.accessibilityFeatures.screenMagnifier.onChange.addListener(
this.onMagnifierUpdated_.bind(this)); this.onMagnifierUpdated_.bind(this, Magnifier.Type.FULL_SCREEN));
chrome.accessibilityFeatures.dockedMagnifier.get( chrome.accessibilityFeatures.dockedMagnifier.get(
{}, this.onMagnifierUpdated_.bind(this)); {}, this.onMagnifierUpdated_.bind(this, Magnifier.Type.DOCKED));
chrome.accessibilityFeatures.dockedMagnifier.onChange.addListener( chrome.accessibilityFeatures.dockedMagnifier.onChange.addListener(
this.onMagnifierUpdated_.bind(this)); this.onMagnifierUpdated_.bind(this, Magnifier.Type.DOCKED));
} }
/** /**
...@@ -69,13 +69,15 @@ class AccessibilityCommon { ...@@ -69,13 +69,15 @@ class AccessibilityCommon {
} }
/** /**
* @param {!Magnifier.Type} type
* @param {*} details * @param {*} details
* @private * @private
*/ */
onMagnifierUpdated_(details) { onMagnifierUpdated_(type, details) {
if (details.value && !this.magnifier_) { if (details.value && !this.magnifier_) {
this.magnifier_ = new Magnifier(); this.magnifier_ = new Magnifier(type);
} else if (!details.value && this.magnifier_) { } else if (
!details.value && this.magnifier_ && this.magnifier_.type === type) {
this.magnifier_.onMagnifierDisabled(); this.magnifier_.onMagnifierDisabled();
this.magnifier_ = null; this.magnifier_ = null;
} }
......
...@@ -6,7 +6,20 @@ ...@@ -6,7 +6,20 @@
* Main class for the Chrome OS magnifier. * Main class for the Chrome OS magnifier.
*/ */
class Magnifier { class Magnifier {
constructor() { /**
* @param {!Magnifier.Type} type The type of magnifier in use.
*/
constructor(type) {
/** @const {!Magnifier.Type} */
this.type = type;
/**
* Whether focus following is enabled or not, based on
* settings.a11y.screen_magnifier_focus_following preference.
* @private {boolean}
*/
this.screenMagnifierFocusFollowing_;
/** @private {!EventHandler} */ /** @private {!EventHandler} */
this.focusHandler_ = new EventHandler( this.focusHandler_ = new EventHandler(
[], chrome.automation.EventType.FOCUS, this.onFocus_.bind(this)); [], chrome.automation.EventType.FOCUS, this.onFocus_.bind(this));
...@@ -29,6 +42,10 @@ class Magnifier { ...@@ -29,6 +42,10 @@ class Magnifier {
* @private * @private
*/ */
init_() { init_() {
chrome.settingsPrivate.getAllPrefs(this.updateFromPrefs_.bind(this));
chrome.settingsPrivate.onPrefsChanged.addListener(
this.updateFromPrefs_.bind(this));
chrome.automation.getDesktop(desktop => { chrome.automation.getDesktop(desktop => {
this.focusHandler_.setNodes(desktop); this.focusHandler_.setNodes(desktop);
this.focusHandler_.start(); this.focusHandler_.start();
...@@ -37,6 +54,35 @@ class Magnifier { ...@@ -37,6 +54,35 @@ class Magnifier {
}); });
} }
/**
* @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs
* @private
*/
updateFromPrefs_(prefs) {
prefs.forEach((pref) => {
switch (pref.key) {
case Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING:
this.screenMagnifierFocusFollowing_ = !!pref.value;
break;
default:
return;
}
});
}
/**
* Returns whether magnifier viewport should follow focus. Exposed for
* testing.
*
* TODO(crbug.com/1146595): Add Chrome OS preference to allow disabling focus
* following for docked magnifier.
*/
shouldFollowFocus() {
return this.type === Magnifier.Type.DOCKED ||
this.type === Magnifier.Type.FULL_SCREEN &&
this.screenMagnifierFocusFollowing_;
}
/** /**
* Listener for when focus is updated. Moves magnifier to include focused * Listener for when focus is updated. Moves magnifier to include focused
* element in viewport. * element in viewport.
...@@ -53,7 +99,7 @@ class Magnifier { ...@@ -53,7 +99,7 @@ class Magnifier {
*/ */
onFocus_(event) { onFocus_(event) {
const {location} = event.target; const {location} = event.target;
if (!location) { if (!location || !this.shouldFollowFocus()) {
return; return;
} }
...@@ -68,7 +114,7 @@ class Magnifier { ...@@ -68,7 +114,7 @@ class Magnifier {
*/ */
onActiveDescendantChanged_(event) { onActiveDescendantChanged_(event) {
const {activeDescendant} = event.target; const {activeDescendant} = event.target;
if (!activeDescendant) { if (!activeDescendant || !this.shouldFollowFocus()) {
return; return;
} }
...@@ -80,3 +126,23 @@ class Magnifier { ...@@ -80,3 +126,23 @@ class Magnifier {
chrome.accessibilityPrivate.moveMagnifierToRect(location); chrome.accessibilityPrivate.moveMagnifierToRect(location);
} }
} }
/**
* Magnifier types.
* @enum {string}
* @const
*/
Magnifier.Type = {
FULL_SCREEN: 'fullScreen',
DOCKED: 'docked',
};
/**
* Preferences that are configurable for Magnifier.
* @enum {string}
* @const
*/
Magnifier.Prefs = {
SCREEN_MAGNIFIER_FOCUS_FOLLOWING:
'settings.a11y.screen_magnifier_focus_following',
};
\ No newline at end of file
...@@ -28,6 +28,22 @@ MagnifierE2ETest = class extends E2ETestBase { ...@@ -28,6 +28,22 @@ MagnifierE2ETest = class extends E2ETestBase {
}); });
} }
async getPref(name) {
return new Promise(resolve => {
chrome.settingsPrivate.getPref(name, (ret) => {
resolve(ret);
});
});
}
async setPref(name, value) {
return new Promise(resolve => {
chrome.settingsPrivate.setPref(name, value, undefined, () => {
resolve();
});
});
}
/** @override */ /** @override */
testGenCppIncludes() { testGenCppIncludes() {
super.testGenCppIncludes(); super.testGenCppIncludes();
...@@ -100,3 +116,28 @@ TEST_F( ...@@ -100,3 +116,28 @@ TEST_F(
assertTrue(RectUtil.contains(bounds, banana.location)); assertTrue(RectUtil.contains(bounds, banana.location));
}); });
}); });
TEST_F('MagnifierE2ETest', 'ScreenMagnifierFocusFollowingPref', function() {
this.newCallback(async () => {
// Disable focus following for full screen magnifier, and verify prefs and
// state.
await this.setPref(Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING, false);
pref = await this.getPref(Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING);
assertEquals(Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING, pref.key);
assertFalse(pref.value);
magnifier = accessibilityCommon.getMagnifierForTest();
assertEquals(magnifier.type, Magnifier.Type.FULL_SCREEN);
assertFalse(magnifier.shouldFollowFocus());
// Enable focus following for full screen magnifier, and verify prefs and
// state.
await this.setPref(Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING, true);
pref = await this.getPref(Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING);
assertEquals(Magnifier.Prefs.SCREEN_MAGNIFIER_FOCUS_FOLLOWING, pref.key);
assertTrue(pref.value);
magnifier = accessibilityCommon.getMagnifierForTest();
assertEquals(magnifier.type, Magnifier.Type.FULL_SCREEN);
assertTrue(magnifier.shouldFollowFocus());
})();
});
\ No newline at end of file
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