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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return localStorage['active'] !== 'false'; | 109 return localStorage['active'] !== 'false'; |
110 }, | 110 }, |
111 set: function(value) { | 111 set: function(value) { |
112 localStorage['active'] = value; | 112 localStorage['active'] = value; |
113 } | 113 } |
114 }); | 114 }); |
115 | 115 |
116 cvox.ExtensionBridge.addMessageListener(this.onMessage_); | 116 cvox.ExtensionBridge.addMessageListener(this.onMessage_); |
117 | 117 |
118 document.addEventListener('keydown', this.onKeyDown.bind(this), true); | 118 document.addEventListener('keydown', this.onKeyDown.bind(this), true); |
| 119 document.addEventListener('keyup', this.onKeyUp.bind(this), true); |
119 cvox.ChromeVoxKbHandler.commandHandler = this.onGotCommand.bind(this); | 120 cvox.ChromeVoxKbHandler.commandHandler = this.onGotCommand.bind(this); |
120 | 121 |
121 // Classic keymap. | 122 // Classic keymap. |
122 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults(); | 123 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults(); |
123 | 124 |
124 // Live region handler. | 125 // Live region handler. |
125 this.liveRegions_ = new LiveRegions(this); | 126 this.liveRegions_ = new LiveRegions(this); |
126 | 127 |
| 128 /** @type {number} @private */ |
| 129 this.passThroughKeyUpCount_ = 0; |
| 130 |
127 if (!chrome.accessibilityPrivate.setKeyboardListener) | 131 if (!chrome.accessibilityPrivate.setKeyboardListener) |
128 chrome.accessibilityPrivate.setKeyboardListener = function() {}; | 132 chrome.accessibilityPrivate.setKeyboardListener = function() {}; |
129 }; | 133 }; |
130 | 134 |
131 Background.prototype = { | 135 Background.prototype = { |
132 __proto__: ChromeVoxState.prototype, | 136 __proto__: ChromeVoxState.prototype, |
133 | 137 |
134 /** | 138 /** |
135 * @override | 139 * @override |
136 */ | 140 */ |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 case 'toggleStickyMode': | 473 case 'toggleStickyMode': |
470 cvox.ChromeVoxBackground.setPref('sticky', | 474 cvox.ChromeVoxBackground.setPref('sticky', |
471 !cvox.ChromeVox.isStickyPrefOn, | 475 !cvox.ChromeVox.isStickyPrefOn, |
472 true); | 476 true); |
473 | 477 |
474 if (cvox.ChromeVox.isStickyPrefOn) | 478 if (cvox.ChromeVox.isStickyPrefOn) |
475 chrome.accessibilityPrivate.setKeyboardListener(true, true); | 479 chrome.accessibilityPrivate.setKeyboardListener(true, true); |
476 else | 480 else |
477 chrome.accessibilityPrivate.setKeyboardListener(true, false); | 481 chrome.accessibilityPrivate.setKeyboardListener(true, false); |
478 return false; | 482 return false; |
| 483 case 'passThroughMode': |
| 484 cvox.ChromeVox.passThroughMode = true; |
| 485 cvox.ChromeVox.tts.speak( |
| 486 Msgs.getMsg('pass_through_key'), cvox.QueueMode.QUEUE); |
| 487 return true; |
479 default: | 488 default: |
480 return true; | 489 return true; |
481 } | 490 } |
482 | 491 |
483 if (pred) { | 492 if (pred) { |
484 var node = AutomationUtil.findNextNode( | 493 var node = AutomationUtil.findNextNode( |
485 current.getBound(dir).node, dir, pred); | 494 current.getBound(dir).node, dir, pred); |
486 | 495 |
487 if (node) { | 496 if (node) { |
488 current = cursors.Range.fromNode(node); | 497 current = cursors.Range.fromNode(node); |
(...skipping 29 matching lines...) Expand all Loading... |
518 return false; | 527 return false; |
519 }, | 528 }, |
520 | 529 |
521 /** | 530 /** |
522 * Handles key down events. | 531 * Handles key down events. |
523 * @param {Event} evt The key down event to process. | 532 * @param {Event} evt The key down event to process. |
524 * @return {boolean} True if the default action should be performed. | 533 * @return {boolean} True if the default action should be performed. |
525 */ | 534 */ |
526 onKeyDown: function(evt) { | 535 onKeyDown: function(evt) { |
527 evt.stickyMode = cvox.ChromeVox.isStickyModeOn() && cvox.ChromeVox.isActive; | 536 evt.stickyMode = cvox.ChromeVox.isStickyModeOn() && cvox.ChromeVox.isActive; |
| 537 if (cvox.ChromeVox.passThroughMode) |
| 538 return false; |
| 539 |
528 if (this.mode_ != ChromeVoxMode.CLASSIC && | 540 if (this.mode_ != ChromeVoxMode.CLASSIC && |
529 !cvox.ChromeVoxKbHandler.basicKeyDownActionsListener(evt)) { | 541 !cvox.ChromeVoxKbHandler.basicKeyDownActionsListener(evt)) { |
530 evt.preventDefault(); | 542 evt.preventDefault(); |
531 evt.stopPropagation(); | 543 evt.stopPropagation(); |
532 } | 544 } |
| 545 Output.flushNextSpeechUtterance(); |
| 546 }, |
533 | 547 |
534 Output.flushNextSpeechUtterance(); | 548 /** |
| 549 * Handles key up events. |
| 550 * @param {Event} evt The key down event to process. |
| 551 * @return {boolean} True if the default action should be performed. |
| 552 */ |
| 553 onKeyUp: function(evt) { |
| 554 // Reset pass through mode once a keyup (not involving the pass through key) |
| 555 // is seen. The pass through command involves three keys. |
| 556 if (cvox.ChromeVox.passThroughMode) { |
| 557 if (this.passThroughKeyUpCount_ >= 3) { |
| 558 cvox.ChromeVox.passThroughMode = false; |
| 559 this.passThroughKeyUpCount_ = 0; |
| 560 } else { |
| 561 this.passThroughKeyUpCount_++; |
| 562 } |
| 563 } |
535 }, | 564 }, |
536 | 565 |
537 /** | 566 /** |
538 * Open the options page in a new tab. | 567 * Open the options page in a new tab. |
539 */ | 568 */ |
540 showOptionsPage: function() { | 569 showOptionsPage: function() { |
541 var optionsPage = {url: 'chromevox/background/options.html'}; | 570 var optionsPage = {url: 'chromevox/background/options.html'}; |
542 chrome.tabs.create(optionsPage); | 571 chrome.tabs.create(optionsPage); |
543 }, | 572 }, |
544 | 573 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 724 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
696 .replace(/\*/g, '.*') | 725 .replace(/\*/g, '.*') |
697 .replace(/\?/g, '.'); | 726 .replace(/\?/g, '.'); |
698 }).join('|') + ')$'); | 727 }).join('|') + ')$'); |
699 }; | 728 }; |
700 | 729 |
701 /** @type {Background} */ | 730 /** @type {Background} */ |
702 global.backgroundObj = new Background(); | 731 global.backgroundObj = new Background(); |
703 | 732 |
704 }); // goog.scope | 733 }); // goog.scope |
OLD | NEW |