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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/command_handler.js
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/command_handler.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/command_handler.js
index e483f40de44b8eb657e834ab9f28c9904ab2851c..c7794a2f65a8627abcf1e7d7c06f13307b606b30 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/command_handler.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/command_handler.js
@@ -13,6 +13,7 @@ goog.require('Output');
goog.require('cvox.ChromeVoxBackground');
goog.scope(function() {
+var AutomationEvent = chrome.automation.AutomationEvent;
var AutomationNode = chrome.automation.AutomationNode;
var Dir = constants.Dir;
var EventType = chrome.automation.EventType;
@@ -578,7 +579,9 @@ CommandHandler.onCommand = function(command) {
.withRichSpeechAndBraille(current, null, Output.EventType.NAVIGATE)
.go();
return false;
-
+ case 'viewGraphicAsBraille':
+ CommandHandler.viewGraphicAsBraille_(current);
+ return false;
// Table commands.
case 'previousRow':
dir = Dir.BACKWARD;
@@ -774,4 +777,52 @@ CommandHandler.increaseOrDecreaseSpeechProperty_ =
}
};
+/**
+ * To support viewGraphicAsBraille_(), the current image node and its
+ * associated event listener that listens for the image frame updated
+ * event.
+ * @type {{node: AutomationNode, listener: function(AutomationEvent)}?};
+ */
+CommandHandler.imageNode_;
+
+/**
+ * Handle the command to view the first graphic within the current range
+ * as braille.
+ * @param {!AutomationNode} current The current range.
+ * @private
+ */
+CommandHandler.viewGraphicAsBraille_ = function(current) {
+ 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
+ CommandHandler.imageNode_.node.removeEventListener(
+ EventType.IMAGE_FRAME_UPDATED, CommandHandler.imageNode_.listener,
+ false);
+ CommandHandler.imageNode_ = null;
+ }
+
+ // Find the first node within the current range that supports image data.
+ var imageNode = AutomationUtil.findNodePost(
+ current.start.node, Dir.FORWARD,
+ AutomationPredicate.supportsImageData);
+ if (!imageNode)
David Tseng 2017/02/27 16:27:13 If the current range already has our event listene
+ return;
+
+ var listener = function(event) {
+ var target = event.target;
+ if (target != CommandHandler.imageNode_.node)
+ return;
+ 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.
+ cvox.ChromeVox.braille.writeRawImage(target.imageDataUrl);
+ cvox.ChromeVox.braille.freeze();
+ }
+ }
+
+ imageNode.addEventListener(EventType.IMAGE_FRAME_UPDATED, listener, false);
+ 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.
+ if (imageNode.imageDataUrl) {
+ listener({target: imageNode});
+ } else {
+ imageNode.getImageData(0, 0);
+ }
+};
+
}); // goog.scope

Powered by Google App Engine
This is Rietveld 408576698