Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js

Issue 2412433004: Recovery: Implement focus recovery across root AutomationNodes (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview The entry point for all ChromeVox2 related code for the 6 * @fileoverview The entry point for all ChromeVox2 related code for the
7 * background page. 7 * background page.
8 */ 8 */
9 9
10 goog.provide('Background'); 10 goog.provide('Background');
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 /** 148 /**
149 * Stores the mode as computed the last time a current range was set. 149 * Stores the mode as computed the last time a current range was set.
150 * @type {?ChromeVoxMode} 150 * @type {?ChromeVoxMode}
151 * @private 151 * @private
152 */ 152 */
153 this.mode_ = null; 153 this.mode_ = null;
154 154
155 chrome.accessibilityPrivate.onAccessibilityGesture.addListener( 155 chrome.accessibilityPrivate.onAccessibilityGesture.addListener(
156 this.onAccessibilityGesture_); 156 this.onAccessibilityGesture_);
157
158 /**
159 * @type {WeakMap<AutomationNode>}
dmazzoni 2016/10/11 17:41:18 I think it should be WeakMap<AutomationNode, Autom
David Tseng 2016/10/11 21:24:32 Yup; you're right. Done (Closure doesn't seem to c
160 * @private
161 */
162 this.focusRecoveryMap_ = new WeakMap();
157 }; 163 };
158 164
159 /** 165 /**
160 * @const {string} 166 * @const {string}
161 */ 167 */
162 Background.ISSUE_URL = 'https://code.google.com/p/chromium/issues/entry?' + 168 Background.ISSUE_URL = 'https://code.google.com/p/chromium/issues/entry?' +
163 'labels=Type-Bug,Pri-2,cvox2,OS-Chrome&' + 169 'labels=Type-Bug,Pri-2,cvox2,OS-Chrome&' +
164 'components=UI>accessibility&' + 170 'components=UI>accessibility&' +
165 'description='; 171 'description=';
166 172
(...skipping 24 matching lines...) Expand all
191 'swipeUp1': 'previousLine', 197 'swipeUp1': 'previousLine',
192 'swipeDown1': 'nextLine', 198 'swipeDown1': 'nextLine',
193 'swipeLeft1': 'previousObject', 199 'swipeLeft1': 'previousObject',
194 'swipeRight1': 'nextObject', 200 'swipeRight1': 'nextObject',
195 'swipeUp2': 'jumpToTop', 201 'swipeUp2': 'jumpToTop',
196 'swipeDown2': 'readFromHere', 202 'swipeDown2': 'readFromHere',
197 }; 203 };
198 204
199 Background.prototype = { 205 Background.prototype = {
200 __proto__: ChromeVoxState.prototype, 206 __proto__: ChromeVoxState.prototype,
207 /**
208 * Maps the last node with range in a given root.
209 * @type {WeakMap<AutomationNode>}
210 */
211 get focusRecoveryMap() {
212 return this.focusRecoveryMap_;
213 },
201 214
202 /** 215 /**
203 * @override 216 * @override
204 */ 217 */
205 getMode: function() { 218 getMode: function() {
206 if (localStorage['useNext'] == 'true') 219 if (localStorage['useNext'] == 'true')
207 return ChromeVoxMode.FORCE_NEXT; 220 return ChromeVoxMode.FORCE_NEXT;
208 221
209 var target; 222 var target;
210 if (!this.getCurrentRange()) { 223 if (!this.getCurrentRange()) {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } else if (action == 'onCommand') { 650 } else if (action == 'onCommand') {
638 CommandHandler.onCommand(msg['command']); 651 CommandHandler.onCommand(msg['command']);
639 } else if (action == 'flushNextUtterance') { 652 } else if (action == 'flushNextUtterance') {
640 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.FLUSH); 653 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.FLUSH);
641 } 654 }
642 break; 655 break;
643 } 656 }
644 }, 657 },
645 658
646 /** 659 /**
647 * Restore the range to the last range that was *not* in the ChromeVox 660 * Save the current ChromeVox range.
648 * panel. This is used when the ChromeVox Panel closes.
649 * @param {function()=} opt_callback
650 * @private
651 */ 661 */
652 restoreCurrentRange_: function(opt_callback) { 662 markCurrentRange: function() {
653 if (this.savedRange_) { 663 if (!this.currentRange)
654 var node = this.savedRange_.start.node; 664 return;
655 var containingWebView = node;
656 while (containingWebView && containingWebView.role != RoleType.webView)
657 containingWebView = containingWebView.parent;
658 665
659 if (containingWebView) { 666 var root = AutomationUtil.getTopLevelRoot(this.currentRange.start.node);
660 // Focusing the webView causes a focus change event which steals focus 667 if (root)
661 // away from the saved range. 668 this.focusRecoveryMap_.set(root, this.currentRange.start.node);
dmazzoni 2016/10/11 17:41:18 Why not store and recover the whole range?
David Tseng 2016/10/11 21:24:32 Done.
662 var saved = this.savedRange_;
663 var setSavedRange = function(e) {
664 if (e.target.root == saved.start.node.root) {
665 this.navigateToRange(saved, false);
666 opt_callback && opt_callback();
667 }
668 node.root.removeEventListener(EventType.focus, setSavedRange, true);
669 }.bind(this);
670 node.root.addEventListener(EventType.focus, setSavedRange, true);
671 containingWebView.focus();
672 }
673 this.navigateToRange(this.savedRange_);
674 this.savedRange_ = null;
675 }
676 }, 669 },
677 670
678 /** 671 /**
679 * Move ChromeVox without saving any ranges.
680 */
681 startExcursion: function() {
682 this.inExcursion_ = true;
683 },
684
685 /**
686 * Move ChromeVox back to the last saved range.
687 * @param {function()=} opt_callback Called when range has been restored.
688 */
689 endExcursion: function(opt_callback) {
690 this.inExcursion_ = false;
691 this.restoreCurrentRange_(opt_callback);
692 },
693
694 /**
695 * Move ChromeVox back to the last saved range.
696 */
697 saveExcursion: function() {
698 this.savedRange_ =
699 new cursors.Range(this.currentRange_.start, this.currentRange_.end);
700 },
701
702 /**
703 * Handles accessibility gestures from the touch screen. 672 * Handles accessibility gestures from the touch screen.
704 * @param {string} gesture The gesture to handle, based on the AXGesture enum 673 * @param {string} gesture The gesture to handle, based on the AXGesture enum
705 * defined in ui/accessibility/ax_enums.idl 674 * defined in ui/accessibility/ax_enums.idl
706 * @private 675 * @private
707 */ 676 */
708 onAccessibilityGesture_: function(gesture) { 677 onAccessibilityGesture_: function(gesture) {
709 // If we're in classic mode, some gestures need to be handled by the 678 // If we're in classic mode, some gestures need to be handled by the
710 // content script. Other gestures are universal and will be handled in 679 // content script. Other gestures are universal and will be handled in
711 // this function. 680 // this function.
712 if (this.mode == ChromeVoxMode.CLASSIC) { 681 if (this.mode == ChromeVoxMode.CLASSIC) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return new RegExp('^(' + globs.map(function(glob) { 731 return new RegExp('^(' + globs.map(function(glob) {
763 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') 732 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&')
764 .replace(/\*/g, '.*') 733 .replace(/\*/g, '.*')
765 .replace(/\?/g, '.'); 734 .replace(/\?/g, '.');
766 }).join('|') + ')$'); 735 }).join('|') + ')$');
767 }; 736 };
768 737
769 new Background(); 738 new Background();
770 739
771 }); // goog.scope 740 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698