Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 if (cvox.ChromeVox.isStickyPrefOn) | 631 if (cvox.ChromeVox.isStickyPrefOn) |
| 632 chrome.accessibilityPrivate.setKeyboardListener(true, true); | 632 chrome.accessibilityPrivate.setKeyboardListener(true, true); |
| 633 else | 633 else |
| 634 chrome.accessibilityPrivate.setKeyboardListener(true, false); | 634 chrome.accessibilityPrivate.setKeyboardListener(true, false); |
| 635 return false; | 635 return false; |
| 636 case 'passThroughMode': | 636 case 'passThroughMode': |
| 637 cvox.ChromeVox.passThroughMode = true; | 637 cvox.ChromeVox.passThroughMode = true; |
| 638 cvox.ChromeVox.tts.speak( | 638 cvox.ChromeVox.tts.speak( |
| 639 Msgs.getMsg('pass_through_key'), cvox.QueueMode.QUEUE); | 639 Msgs.getMsg('pass_through_key'), cvox.QueueMode.QUEUE); |
| 640 return true; | 640 return true; |
| 641 case 'openChromeVoxMenus': | 641 case 'toggleKeyboardHelp': |
| 642 this.startExcursion(); | 642 this.startExcursion(); |
| 643 (new PanelCommand(PanelCommandType.OPEN_MENUS)).send(); | 643 (new PanelCommand(PanelCommandType.OPEN_MENUS)).send(); |
| 644 return false; | 644 return false; |
| 645 case 'showHeadingsList': | |
| 646 this.startExcursion(); | |
| 647 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_heading')).send(); | |
| 648 return false; | |
| 649 case 'showFormsList': | |
| 650 this.startExcursion(); | |
| 651 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_form')).send(); | |
| 652 return false; | |
| 653 case 'showLandmarksList': | |
| 654 this.startExcursion(); | |
| 655 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_landmark')).send(); | |
| 656 return false; | |
| 657 case 'showLinksList': | |
| 658 this.startExcursion(); | |
| 659 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_link')).send(); | |
| 660 return false; | |
| 661 case 'showTablesList': | |
| 662 this.startExcursion(); | |
| 663 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'table_strategy')) | |
| 664 .send(); | |
| 665 return false; | |
| 645 case 'toggleSearchWidget': | 666 case 'toggleSearchWidget': |
| 646 (new PanelCommand(PanelCommandType.SEARCH)).send(); | 667 (new PanelCommand(PanelCommandType.SEARCH)).send(); |
| 647 return false; | 668 return false; |
| 648 case 'showKbExplorerPage': | 669 case 'showKbExplorerPage': |
| 649 var explorerPage = {url: 'chromevox/background/kbexplorer.html'}; | 670 var explorerPage = {url: 'chromevox/background/kbexplorer.html'}; |
| 650 chrome.tabs.create(explorerPage); | 671 chrome.tabs.create(explorerPage); |
| 651 break; | 672 break; |
| 652 case 'decreaseTtsRate': | 673 case 'decreaseTtsRate': |
| 653 this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.RATE, false); | 674 this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.RATE, false); |
| 654 return false; | 675 return false; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 } else { | 803 } else { |
| 783 if (predErrorMsg) { | 804 if (predErrorMsg) { |
| 784 cvox.ChromeVox.tts.speak(Msgs.getMsg(predErrorMsg), | 805 cvox.ChromeVox.tts.speak(Msgs.getMsg(predErrorMsg), |
| 785 cvox.QueueMode.FLUSH); | 806 cvox.QueueMode.FLUSH); |
| 786 } | 807 } |
| 787 return false; | 808 return false; |
| 788 } | 809 } |
| 789 } | 810 } |
| 790 | 811 |
| 791 if (current) | 812 if (current) |
| 792 this.navigateToRange_(current); | 813 this.navigateToRange(current); |
| 793 | 814 |
| 794 return false; | 815 return false; |
| 795 }, | 816 }, |
| 796 | 817 |
| 797 /** | 818 /** |
| 798 * Increase or decrease a speech property and make an announcement. | 819 * Increase or decrease a speech property and make an announcement. |
| 799 * @param {string} propertyName The name of the property to change. | 820 * @param {string} propertyName The name of the property to change. |
| 800 * @param {boolean} increase If true, increases the property value by one | 821 * @param {boolean} increase If true, increases the property value by one |
| 801 * step size, otherwise decreases. | 822 * step size, otherwise decreases. |
| 802 */ | 823 */ |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 819 if (announcement) { | 840 if (announcement) { |
| 820 cvox.ChromeVox.tts.speak( | 841 cvox.ChromeVox.tts.speak( |
| 821 announcement, cvox.QueueMode.FLUSH, | 842 announcement, cvox.QueueMode.FLUSH, |
| 822 cvox.AbstractTts.PERSONALITY_ANNOTATION); | 843 cvox.AbstractTts.PERSONALITY_ANNOTATION); |
| 823 } | 844 } |
| 824 }, | 845 }, |
| 825 | 846 |
| 826 /** | 847 /** |
| 827 * Navigate to the given range - it both sets the range and outputs it. | 848 * Navigate to the given range - it both sets the range and outputs it. |
| 828 * @param {!cursors.Range} range The new range. | 849 * @param {!cursors.Range} range The new range. |
| 850 * @param {boolean=} opt_focus Focus the range; defaults to true. | |
| 829 * @private | 851 * @private |
| 830 */ | 852 */ |
| 831 navigateToRange_: function(range) { | 853 navigateToRange: function(range, opt_focus) { |
| 832 // TODO(dtseng): Figure out what it means to focus a range. | 854 opt_focus = opt_focus === undefined ? true : opt_focus; |
| 833 var actionNode = range.start.node; | |
| 834 if (actionNode.role == RoleType.inlineTextBox) | |
| 835 actionNode = actionNode.parent; | |
| 836 | 855 |
| 837 // Iframes, when focused, causes the child webArea to fire focus event. | 856 if (opt_focus) { |
| 838 // This can result in getting stuck when navigating backward. | 857 // TODO(dtseng): Figure out what it means to focus a range. |
| 839 if (actionNode.role != RoleType.iframe && !actionNode.state.focused && | 858 var actionNode = range.start.node; |
| 840 !AutomationPredicate.container(actionNode)) | 859 if (actionNode.role == RoleType.inlineTextBox) |
| 841 actionNode.focus(); | 860 actionNode = actionNode.parent; |
| 842 | 861 |
| 862 // Iframes, when focused, causes the child webArea to fire focus event. | |
| 863 // This can result in getting stuck when navigating backward. | |
| 864 if (actionNode.role != RoleType.iframe && !actionNode.state.focused && | |
| 865 !AutomationPredicate.container(actionNode)) | |
| 866 actionNode.focus(); | |
| 867 } | |
| 843 var prevRange = this.currentRange_; | 868 var prevRange = this.currentRange_; |
| 844 this.setCurrentRange(range); | 869 this.setCurrentRange(range); |
| 845 | 870 |
| 846 range.select(); | 871 range.select(); |
| 847 | 872 |
| 848 new Output().withRichSpeechAndBraille( | 873 new Output().withRichSpeechAndBraille( |
| 849 range, prevRange, Output.EventType.NAVIGATE) | 874 range, prevRange, Output.EventType.NAVIGATE) |
| 850 .withQueueMode(cvox.QueueMode.FLUSH) | 875 .withQueueMode(cvox.QueueMode.FLUSH) |
| 851 .go(); | 876 .go(); |
| 852 }, | 877 }, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 } else if (action == 'flushNextUtterance') { | 1058 } else if (action == 'flushNextUtterance') { |
| 1034 Output.flushNextSpeechUtterance(); | 1059 Output.flushNextSpeechUtterance(); |
| 1035 } | 1060 } |
| 1036 break; | 1061 break; |
| 1037 } | 1062 } |
| 1038 }, | 1063 }, |
| 1039 | 1064 |
| 1040 /** | 1065 /** |
| 1041 * Restore the range to the last range that was *not* in the ChromeVox | 1066 * Restore the range to the last range that was *not* in the ChromeVox |
| 1042 * panel. This is used when the ChromeVox Panel closes. | 1067 * panel. This is used when the ChromeVox Panel closes. |
| 1068 * @param {function()=} opt_callback | |
|
dmazzoni
2016/06/07 16:36:06
nit: indentation
David Tseng
2016/06/08 19:28:33
Done.
| |
| 1043 * @private | 1069 * @private |
| 1044 */ | 1070 */ |
| 1045 restoreCurrentRange_: function() { | 1071 restoreCurrentRange_: function(opt_callback) { |
| 1046 if (this.savedRange_) { | 1072 if (this.savedRange_) { |
| 1047 var node = this.savedRange_.start.node; | 1073 var node = this.savedRange_.start.node; |
| 1048 var containingWebView = node; | 1074 var containingWebView = node; |
| 1049 while (containingWebView && containingWebView.role != RoleType.webView) | 1075 while (containingWebView && containingWebView.role != RoleType.webView) |
| 1050 containingWebView = containingWebView.parent; | 1076 containingWebView = containingWebView.parent; |
| 1051 | 1077 |
| 1052 if (containingWebView) { | 1078 if (containingWebView) { |
| 1053 // Focusing the webView causes a focus change event which steals focus | 1079 // Focusing the webView causes a focus change event which steals focus |
| 1054 // away from the saved range. | 1080 // away from the saved range. |
| 1055 var saved = this.savedRange_; | 1081 var saved = this.savedRange_; |
| 1056 var setSavedRange = function(e) { | 1082 var setSavedRange = function(e) { |
| 1057 if (e.target.root == saved.start.node.root) | 1083 if (e.target.root == saved.start.node.root) { |
| 1058 this.navigateToRange_(saved); | 1084 this.navigateToRange(saved, false); |
| 1085 opt_callback && opt_callback(); | |
| 1086 } | |
| 1059 node.root.removeEventListener(EventType.focus, setSavedRange, true); | 1087 node.root.removeEventListener(EventType.focus, setSavedRange, true); |
| 1060 }.bind(this); | 1088 }.bind(this); |
| 1061 node.root.addEventListener(EventType.focus, setSavedRange, true); | 1089 node.root.addEventListener(EventType.focus, setSavedRange, true); |
| 1062 containingWebView.focus(); | 1090 containingWebView.focus(); |
| 1063 } | 1091 } |
| 1064 this.navigateToRange_(this.savedRange_); | 1092 this.navigateToRange(this.savedRange_); |
| 1065 this.savedRange_ = null; | 1093 this.savedRange_ = null; |
| 1066 } | 1094 } |
| 1067 }, | 1095 }, |
| 1068 | 1096 |
| 1069 /** | 1097 /** |
| 1070 * Move ChromeVox without saving any ranges. | 1098 * Move ChromeVox without saving any ranges. |
| 1071 */ | 1099 */ |
| 1072 startExcursion: function() { | 1100 startExcursion: function() { |
| 1073 this.inExcursion_ = true; | 1101 this.inExcursion_ = true; |
| 1074 }, | 1102 }, |
| 1075 | 1103 |
| 1076 /** | 1104 /** |
| 1077 * Move ChromeVox back to the last saved range. | 1105 * Move ChromeVox back to the last saved range. |
| 1106 * @param {function()=} opt_callback Called when range has been restored. | |
| 1078 */ | 1107 */ |
| 1079 endExcursion: function() { | 1108 endExcursion: function(opt_callback) { |
| 1080 this.inExcursion_ = false; | 1109 this.inExcursion_ = false; |
| 1081 this.restoreCurrentRange_(); | 1110 this.restoreCurrentRange_(opt_callback); |
| 1082 }, | 1111 }, |
| 1083 | 1112 |
| 1084 /** | 1113 /** |
| 1085 * Move ChromeVox back to the last saved range. | 1114 * Move ChromeVox back to the last saved range. |
| 1086 */ | 1115 */ |
| 1087 saveExcursion: function() { | 1116 saveExcursion: function() { |
| 1088 this.savedRange_ = | 1117 this.savedRange_ = |
| 1089 new cursors.Range(this.currentRange_.start, this.currentRange_.end); | 1118 new cursors.Range(this.currentRange_.start, this.currentRange_.end); |
| 1090 }, | 1119 }, |
| 1091 | 1120 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 1172 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 1144 .replace(/\*/g, '.*') | 1173 .replace(/\*/g, '.*') |
| 1145 .replace(/\?/g, '.'); | 1174 .replace(/\?/g, '.'); |
| 1146 }).join('|') + ')$'); | 1175 }).join('|') + ')$'); |
| 1147 }; | 1176 }; |
| 1148 | 1177 |
| 1149 /** @type {Background} */ | 1178 /** @type {Background} */ |
| 1150 global.backgroundObj = new Background(); | 1179 global.backgroundObj = new Background(); |
| 1151 | 1180 |
| 1152 }); // goog.scope | 1181 }); // goog.scope |
| OLD | NEW |