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

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

Issue 2703663002: Display images in multiline Braille (Closed)
Patch Set: Address feedback Created 3 years, 9 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 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('Output'); 12 goog.require('Output');
13 goog.require('cvox.ChromeVoxBackground'); 13 goog.require('cvox.ChromeVoxBackground');
14 14
15 goog.scope(function() { 15 goog.scope(function() {
16 var AutomationEvent = chrome.automation.AutomationEvent;
16 var AutomationNode = chrome.automation.AutomationNode; 17 var AutomationNode = chrome.automation.AutomationNode;
17 var Dir = constants.Dir; 18 var Dir = constants.Dir;
18 var EventType = chrome.automation.EventType; 19 var EventType = chrome.automation.EventType;
19 var RoleType = chrome.automation.RoleType; 20 var RoleType = chrome.automation.RoleType;
20 21
21 /** 22 /**
22 * Handles ChromeVox Next commands. 23 * Handles ChromeVox Next commands.
23 * @param {string} command 24 * @param {string} command
24 * @return {boolean} True if the command should propagate. 25 * @return {boolean} True if the command should propagate.
25 */ 26 */
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 ChromeVoxState.instance.pageSel_ = null; 572 ChromeVoxState.instance.pageSel_ = null;
572 return false; 573 return false;
573 } 574 }
574 break; 575 break;
575 case 'fullyDescribe': 576 case 'fullyDescribe':
576 var o = new Output(); 577 var o = new Output();
577 o.withContextFirst() 578 o.withContextFirst()
578 .withRichSpeechAndBraille(current, null, Output.EventType.NAVIGATE) 579 .withRichSpeechAndBraille(current, null, Output.EventType.NAVIGATE)
579 .go(); 580 .go();
580 return false; 581 return false;
581 582 case 'viewGraphicAsBraille':
583 CommandHandler.viewGraphicAsBraille_(current);
584 return false;
582 // Table commands. 585 // Table commands.
583 case 'previousRow': 586 case 'previousRow':
584 dir = Dir.BACKWARD; 587 dir = Dir.BACKWARD;
585 var tableOpts = {row: true, dir: dir}; 588 var tableOpts = {row: true, dir: dir};
586 pred = AutomationPredicate.makeTableCellPredicate( 589 pred = AutomationPredicate.makeTableCellPredicate(
587 current.start.node, tableOpts); 590 current.start.node, tableOpts);
588 predErrorMsg = 'no_cell_above'; 591 predErrorMsg = 'no_cell_above';
589 rootPred = AutomationPredicate.table; 592 rootPred = AutomationPredicate.table;
590 break; 593 break;
591 case 'previousCol': 594 case 'previousCol':
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 announcement = Msgs.getMsg('announce_volume', [valueAsPercent]); 770 announcement = Msgs.getMsg('announce_volume', [valueAsPercent]);
768 break; 771 break;
769 } 772 }
770 if (announcement) { 773 if (announcement) {
771 cvox.ChromeVox.tts.speak( 774 cvox.ChromeVox.tts.speak(
772 announcement, cvox.QueueMode.FLUSH, 775 announcement, cvox.QueueMode.FLUSH,
773 cvox.AbstractTts.PERSONALITY_ANNOTATION); 776 cvox.AbstractTts.PERSONALITY_ANNOTATION);
774 } 777 }
775 }; 778 };
776 779
780 /**
781 * To support viewGraphicAsBraille_(), the current image node and its
782 * associated event listener that listens for the image frame updated
783 * event.
784 * @type {{node: AutomationNode, listener: function(AutomationEvent)}?};
785 */
786 CommandHandler.imageNode_;
787
788 /**
789 * Handle the command to view the first graphic within the current range
790 * as braille.
791 * @param {!AutomationNode} current The current range.
792 * @private
793 */
794 CommandHandler.viewGraphicAsBraille_ = function(current) {
795 if (CommandHandler.imageNode_) {
David Tseng 2017/02/27 16:27:13 I don't think you need to track the image node (an
dmazzoni 2017/02/28 05:08:23 Fixed as discussed offline. Tracking the image nod
796 CommandHandler.imageNode_.node.removeEventListener(
797 EventType.IMAGE_FRAME_UPDATED, CommandHandler.imageNode_.listener,
798 false);
799 CommandHandler.imageNode_ = null;
800 }
801
802 // Find the first node within the current range that supports image data.
803 var imageNode = AutomationUtil.findNodePost(
804 current.start.node, Dir.FORWARD,
805 AutomationPredicate.supportsImageData);
806 if (!imageNode)
David Tseng 2017/02/27 16:27:13 If the current range already has our event listene
807 return;
808
809 var listener = function(event) {
810 var target = event.target;
811 if (target != CommandHandler.imageNode_.node)
812 return;
813 if (target.imageDataUrl) {
David Tseng 2017/02/27 16:15:50 If the current range is no longer the image node,
dmazzoni 2017/02/28 05:08:23 Done.
814 cvox.ChromeVox.braille.writeRawImage(target.imageDataUrl);
815 cvox.ChromeVox.braille.freeze();
816 }
817 }
818
819 imageNode.addEventListener(EventType.IMAGE_FRAME_UPDATED, listener, false);
820 CommandHandler.imageNode_ = {node: imageNode, listener: listener};
David Tseng 2017/02/27 16:27:13 Set current range to the image node and don't keep
dmazzoni 2017/02/28 05:08:23 As discussed, this would leak too many listeners.
821 if (imageNode.imageDataUrl) {
822 listener({target: imageNode});
823 } else {
824 imageNode.getImageData(0, 0);
825 }
826 };
827
777 }); // goog.scope 828 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698