Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js |
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js |
index 11f093d1bbdae929bd9b380901ba0a93dca422e4..a01ea9863af172e63317a4c740c0425917fa95d2 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js |
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js |
@@ -17,6 +17,7 @@ goog.require('LiveRegions'); |
goog.require('NextEarcons'); |
goog.require('Output'); |
goog.require('Output.EventType'); |
+goog.require('PanelCommand'); |
goog.require('constants'); |
goog.require('cursors.Cursor'); |
goog.require('cvox.BrailleKeyCommand'); |
@@ -63,6 +64,12 @@ Background = function() { |
this.currentRange_ = null; |
/** |
+ * @type {cursors.Range} |
+ * @private |
+ */ |
+ this.savedRange_ = null; |
+ |
+ /** |
* Which variant of ChromeVox is active. |
* @type {ChromeVoxMode} |
* @private |
@@ -184,6 +191,13 @@ Background.prototype = { |
cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); |
} |
+ if (mode === ChromeVoxMode.NEXT || |
+ mode === ChromeVoxMode.FORCE_NEXT) { |
+ (new PanelCommand(PanelCommandType.ENABLE_MENUS)).send(); |
+ } else { |
+ (new PanelCommand(PanelCommandType.DISABLE_MENUS)).send(); |
+ } |
+ |
this.mode_ = mode; |
}, |
@@ -225,6 +239,11 @@ Background.prototype = { |
if (!newRange) |
return; |
+ var panelUrl = chrome.extension.getURL('cvox2/background/panel.html'); |
+ if (newRange.start.node.root.docUrl.indexOf(panelUrl) != 0) { |
+ this.savedRange_ = new cursors.Range(newRange.start, newRange.end); |
+ } |
David Tseng
2016/01/12 20:10:57
nit: remove braces
dmazzoni
2016/01/13 23:26:39
Done.
|
+ |
this.currentRange_ = newRange; |
if (this.currentRange_) |
@@ -285,12 +304,12 @@ Background.prototype = { |
pred = AutomationPredicate.button; |
predErrorMsg = 'no_previous_button'; |
break; |
- case 'nextCheckBox': |
+ case 'nextCheckbox': |
dir = Dir.FORWARD; |
pred = AutomationPredicate.checkBox; |
predErrorMsg = 'no_next_checkbox'; |
break; |
- case 'previousCheckBox': |
+ case 'previousCheckbox': |
dir = Dir.BACKWARD; |
pred = AutomationPredicate.checkBox; |
predErrorMsg = 'no_previous_checkbox'; |
@@ -366,14 +385,14 @@ Background.prototype = { |
predErrorMsg = 'no_previous_visited_link'; |
break; |
case 'right': |
- case 'nextElement': |
+ case 'nextObject': |
current = current.move(cursors.Unit.DOM_NODE, Dir.FORWARD); |
break; |
case 'left': |
- case 'previousElement': |
+ case 'previousObject': |
current = current.move(cursors.Unit.DOM_NODE, Dir.BACKWARD); |
break; |
- case 'goToBeginning': |
+ case 'jumpToTop': |
David Tseng
2016/01/12 19:24:42
goToEnd/jumpToBottom as well?
dmazzoni
2016/01/13 23:26:39
Done.
|
var node = |
AutomationUtil.findNodePost(current.start.node.root, |
Dir.FORWARD, |
@@ -390,7 +409,7 @@ Background.prototype = { |
current = cursors.Range.fromNode(node); |
break; |
case 'forceClickOnCurrentItem': |
- case 'doDefault': |
+ case 'performDefaultAction': |
if (this.currentRange_) { |
var actionNode = this.currentRange_.start.node; |
if (actionNode.role == RoleType.inlineTextBox) |
@@ -400,7 +419,7 @@ Background.prototype = { |
// Skip all other processing; if focus changes, we should get an event |
// for that. |
return false; |
- case 'continuousRead': |
+ case 'readFromHere': |
global.isReadingContinuously = true; |
var continueReading = function(prevRange) { |
if (!global.isReadingContinuously || !this.currentRange_) |
@@ -420,7 +439,7 @@ Background.prototype = { |
continueReading(null); |
return false; |
- case 'showContextMenu': |
+ case 'contextMenu': |
if (this.currentRange_) { |
var actionNode = this.currentRange_.start.node; |
if (actionNode.role == RoleType.inlineTextBox) |
@@ -464,6 +483,26 @@ Background.prototype = { |
cvox.ChromeVoxBackground.setPref('sticky', |
!cvox.ChromeVox.isStickyPrefOn, |
true); |
+ case 'openChromeVoxMenus': |
+ (new PanelCommand(PanelCommandType.OPEN_MENUS)).send(); |
+ break; |
+ case 'decreaseTtsRate': |
+ this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.RATE, false); |
+ break; |
+ case 'increaseTtsRate': |
+ this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.RATE, true); |
+ break; |
+ case 'decreaseTtsPitch': |
+ this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.PITCH, false); |
+ break; |
+ case 'increaseTtsPitch': |
+ this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.PITCH, true); |
+ break; |
+ case 'decreaseTtsVolume': |
+ this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.VOLUME, false); |
+ break; |
+ case 'increaseTtsVolume': |
+ this.increaseOrDecreaseSpeechProperty_(cvox.AbstractTts.VOLUME, true); |
break; |
default: |
return true; |
@@ -484,23 +523,58 @@ Background.prototype = { |
} |
} |
- if (current) { |
- // TODO(dtseng): Figure out what it means to focus a range. |
- var actionNode = current.start.node; |
- if (actionNode.role == RoleType.inlineTextBox) |
- actionNode = actionNode.parent; |
- actionNode.focus(); |
+ if (current) |
+ this.navigateToRange_(current); |
- var prevRange = this.currentRange_; |
- this.setCurrentRange(current); |
+ return false; |
+ }, |
- new Output().withSpeechAndBraille( |
- this.currentRange_, prevRange, Output.EventType.NAVIGATE) |
- .withQueueMode(cvox.QueueMode.FLUSH) |
- .go(); |
+ /** |
+ * Increase or decrease a speech property and make an announcement. |
+ * @param {string} propertyName The name of the property to change. |
+ * @param {boolean} increase If true, increases the property value by one |
+ * step size, otherwise decreases. |
+ */ |
+ increaseOrDecreaseSpeechProperty_: function(propertyName, increase) { |
+ cvox.ChromeVox.tts.increaseOrDecreaseProperty(propertyName, increase); |
+ var announcement; |
+ var valueAsPercent = Math.round( |
+ cvox.ChromeVox.tts.propertyToPercentage(propertyName) * 100); |
+ switch (propertyName) { |
+ case cvox.AbstractTts.RATE: |
+ announcement = Msgs.getMsg('announce_rate', [valueAsPercent]); |
+ break; |
+ case cvox.AbstractTts.PITCH: |
+ announcement = Msgs.getMsg('announce_pitch', [valueAsPercent]); |
+ break; |
+ case cvox.AbstractTts.VOLUME: |
+ announcement = Msgs.getMsg('announce_volume', [valueAsPercent]); |
+ break; |
+ } |
+ if (announcement) { |
+ cvox.ChromeVox.tts.speak( |
+ announcement, cvox.QueueMode.FLUSH, |
+ cvox.AbstractTts.PERSONALITY_ANNOTATION); |
} |
+ }, |
- return false; |
+ /** |
+ * Navigate to the given range - it both sets the range and outputs it. |
+ * @param {!cursors.Range} range The new range. |
+ * @private |
+ */ |
+ navigateToRange_: function(range) { |
+ // TODO(dtseng): Figure out what it means to focus a range. |
+ var actionNode = range.start.node; |
+ if (actionNode.role == RoleType.inlineTextBox) |
+ actionNode = actionNode.parent; |
+ actionNode.focus(); |
+ |
+ var prevRange = this.currentRange_; |
+ this.setCurrentRange(range); |
+ |
+ new Output().withSpeechAndBraille( |
+ range, prevRange, Output.EventType.NAVIGATE).go(); |
}, |
/** |
@@ -539,10 +613,10 @@ Background.prototype = { |
switch (evt.command) { |
case cvox.BrailleKeyCommand.PAN_LEFT: |
- this.onGotCommand('previousElement'); |
+ this.onGotCommand('previousObject'); |
break; |
case cvox.BrailleKeyCommand.PAN_RIGHT: |
- this.onGotCommand('nextElement'); |
+ this.onGotCommand('nextObject'); |
break; |
case cvox.BrailleKeyCommand.LINE_UP: |
this.onGotCommand('previousLine'); |
@@ -551,10 +625,10 @@ Background.prototype = { |
this.onGotCommand('nextLine'); |
break; |
case cvox.BrailleKeyCommand.TOP: |
- this.onGotCommand('goToBeginning'); |
+ this.onGotCommand('jumpToTop'); |
break; |
case cvox.BrailleKeyCommand.BOTTOM: |
- this.onGotCommand('goToEnd'); |
+ this.onGotCommand('jumpToBottom'); |
break; |
case cvox.BrailleKeyCommand.ROUTING: |
this.brailleRoutingCommand_( |
@@ -660,7 +734,25 @@ Background.prototype = { |
} |
break; |
} |
- } |
+ }, |
+ |
+ /** |
+ * Restore the range to the last range that was *not* in the ChromeVox |
+ * panel. This is used when the ChromeVox Panel closes. |
+ */ |
+ restoreCurrentRange: function() { |
+ if (this.savedRange_) { |
+ var containingWebView = this.savedRange_.start.node; |
+ while (containingWebView && containingWebView.role != RoleType.webView) { |
+ containingWebView = containingWebView.parent; |
+ } |
David Tseng
2016/01/12 20:10:57
nit: remove braces
dmazzoni
2016/01/13 23:26:39
Done.
|
+ if (containingWebView) |
+ containingWebView.focus(); |
David Tseng
2016/01/12 20:10:57
Does this restore focus properly? What if savedRan
dmazzoni
2016/01/13 23:26:39
It's okay to call focus() on a dead node, it's a n
|
+ |
+ this.navigateToRange_(this.savedRange_); |
+ this.savedRange_ = null; |
+ } |
+ }, |
}; |
/** |