| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 ChromeVox commands. | 6 * @fileoverview ChromeVox commands. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('CommandHandler'); | 9 goog.provide('CommandHandler'); |
| 10 | 10 |
| 11 goog.require('ChromeVoxState'); | 11 goog.require('ChromeVoxState'); |
| 12 goog.require('CustomAutomationEvent'); |
| 12 goog.require('Output'); | 13 goog.require('Output'); |
| 13 goog.require('cvox.ChromeVoxBackground'); | 14 goog.require('cvox.ChromeVoxBackground'); |
| 14 | 15 |
| 15 goog.scope(function() { | 16 goog.scope(function() { |
| 17 var AutomationEvent = chrome.automation.AutomationEvent; |
| 16 var AutomationNode = chrome.automation.AutomationNode; | 18 var AutomationNode = chrome.automation.AutomationNode; |
| 17 var Dir = constants.Dir; | 19 var Dir = constants.Dir; |
| 18 var EventType = chrome.automation.EventType; | 20 var EventType = chrome.automation.EventType; |
| 19 var RoleType = chrome.automation.RoleType; | 21 var RoleType = chrome.automation.RoleType; |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * Handles ChromeVox Next commands. | 24 * Handles ChromeVox Next commands. |
| 23 * @param {string} command | 25 * @param {string} command |
| 24 * @return {boolean} True if the command should propagate. | 26 * @return {boolean} True if the command should propagate. |
| 25 */ | 27 */ |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 ChromeVoxState.instance.pageSel_ = null; | 573 ChromeVoxState.instance.pageSel_ = null; |
| 572 return false; | 574 return false; |
| 573 } | 575 } |
| 574 break; | 576 break; |
| 575 case 'fullyDescribe': | 577 case 'fullyDescribe': |
| 576 var o = new Output(); | 578 var o = new Output(); |
| 577 o.withContextFirst() | 579 o.withContextFirst() |
| 578 .withRichSpeechAndBraille(current, null, Output.EventType.NAVIGATE) | 580 .withRichSpeechAndBraille(current, null, Output.EventType.NAVIGATE) |
| 579 .go(); | 581 .go(); |
| 580 return false; | 582 return false; |
| 581 | 583 case 'viewGraphicAsBraille': |
| 584 CommandHandler.viewGraphicAsBraille_(current); |
| 585 return false; |
| 582 // Table commands. | 586 // Table commands. |
| 583 case 'previousRow': | 587 case 'previousRow': |
| 584 dir = Dir.BACKWARD; | 588 dir = Dir.BACKWARD; |
| 585 var tableOpts = {row: true, dir: dir}; | 589 var tableOpts = {row: true, dir: dir}; |
| 586 pred = AutomationPredicate.makeTableCellPredicate( | 590 pred = AutomationPredicate.makeTableCellPredicate( |
| 587 current.start.node, tableOpts); | 591 current.start.node, tableOpts); |
| 588 predErrorMsg = 'no_cell_above'; | 592 predErrorMsg = 'no_cell_above'; |
| 589 rootPred = AutomationPredicate.table; | 593 rootPred = AutomationPredicate.table; |
| 590 break; | 594 break; |
| 591 case 'previousCol': | 595 case 'previousCol': |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 announcement = Msgs.getMsg('announce_volume', [valueAsPercent]); | 771 announcement = Msgs.getMsg('announce_volume', [valueAsPercent]); |
| 768 break; | 772 break; |
| 769 } | 773 } |
| 770 if (announcement) { | 774 if (announcement) { |
| 771 cvox.ChromeVox.tts.speak( | 775 cvox.ChromeVox.tts.speak( |
| 772 announcement, cvox.QueueMode.FLUSH, | 776 announcement, cvox.QueueMode.FLUSH, |
| 773 cvox.AbstractTts.PERSONALITY_ANNOTATION); | 777 cvox.AbstractTts.PERSONALITY_ANNOTATION); |
| 774 } | 778 } |
| 775 }; | 779 }; |
| 776 | 780 |
| 781 /** |
| 782 * To support viewGraphicAsBraille_(), the current image node. |
| 783 * @type {AutomationNode?}; |
| 784 */ |
| 785 CommandHandler.imageNode_; |
| 786 |
| 787 /** |
| 788 * Called when an image frame is received on a node. |
| 789 * @param {!(AutomationEvent|CustomAutomationEvent)} event The event. |
| 790 * @private |
| 791 */ |
| 792 CommandHandler.onImageFrameUpdated_ = function(event) { |
| 793 var target = event.target; |
| 794 if (target != CommandHandler.imageNode_) |
| 795 return; |
| 796 |
| 797 if (!AutomationUtil.isDescendantOf( |
| 798 ChromeVoxState.instance.currentRange.start.node, |
| 799 CommandHandler.imageNode_)) { |
| 800 CommandHandler.imageNode_.removeEventListener( |
| 801 EventType.IMAGE_FRAME_UPDATED, |
| 802 CommandHandler.onImageFrameUpdated_, false); |
| 803 CommandHandler.imageNode_ = null; |
| 804 return; |
| 805 } |
| 806 |
| 807 if (target.imageDataUrl) { |
| 808 cvox.ChromeVox.braille.writeRawImage(target.imageDataUrl); |
| 809 cvox.ChromeVox.braille.freeze(); |
| 810 } |
| 811 }; |
| 812 |
| 813 /** |
| 814 * Handle the command to view the first graphic within the current range |
| 815 * as braille. |
| 816 * @param {!AutomationNode} current The current range. |
| 817 * @private |
| 818 */ |
| 819 CommandHandler.viewGraphicAsBraille_ = function(current) { |
| 820 if (CommandHandler.imageNode_) { |
| 821 CommandHandler.imageNode_.removeEventListener( |
| 822 EventType.IMAGE_FRAME_UPDATED, |
| 823 CommandHandler.onImageFrameUpdated_, false); |
| 824 CommandHandler.imageNode_ = null; |
| 825 } |
| 826 |
| 827 // Find the first node within the current range that supports image data. |
| 828 var imageNode = AutomationUtil.findNodePost( |
| 829 current.start.node, Dir.FORWARD, |
| 830 AutomationPredicate.supportsImageData); |
| 831 if (!imageNode) |
| 832 return; |
| 833 |
| 834 imageNode.addEventListener(EventType.IMAGE_FRAME_UPDATED, |
| 835 this.onImageFrameUpdated_, false); |
| 836 CommandHandler.imageNode_ = imageNode; |
| 837 if (imageNode.imageDataUrl) { |
| 838 var event = new CustomAutomationEvent( |
| 839 EventType.IMAGE_FRAME_UPDATED, imageNode, 'page'); |
| 840 CommandHandler.onImageFrameUpdated_(event); |
| 841 } else { |
| 842 imageNode.getImageData(0, 0); |
| 843 } |
| 844 }; |
| 845 |
| 777 }); // goog.scope | 846 }); // goog.scope |
| OLD | NEW |