Commit 773c53fc authored by plundblad's avatar plundblad Committed by Commit bot

Refactor: remove a Chromevox abstract class.

Removes the superflous cvox.AbstractMsgs class and moves what was rpeviously
ChromeMsgs out of host.

BUG=341953
R=dtseng@chromium.org

Review URL: https://codereview.chromium.org/593133002

Cr-Commit-Position: refs/heads/master@{#296367}
parent d99e73cf
...@@ -13,7 +13,6 @@ goog.require('cvox.AbstractEarcons'); ...@@ -13,7 +13,6 @@ goog.require('cvox.AbstractEarcons');
goog.require('cvox.AccessibilityApiHandler'); goog.require('cvox.AccessibilityApiHandler');
goog.require('cvox.BrailleBackground'); goog.require('cvox.BrailleBackground');
goog.require('cvox.BrailleCaptionsBackground'); goog.require('cvox.BrailleCaptionsBackground');
goog.require('cvox.ChromeMsgs');
goog.require('cvox.ChromeVox'); goog.require('cvox.ChromeVox');
goog.require('cvox.ChromeVoxEditableTextBase'); goog.require('cvox.ChromeVoxEditableTextBase');
goog.require('cvox.ChromeVoxPrefs'); goog.require('cvox.ChromeVoxPrefs');
...@@ -23,6 +22,7 @@ goog.require('cvox.EarconsBackground'); ...@@ -23,6 +22,7 @@ goog.require('cvox.EarconsBackground');
goog.require('cvox.ExtensionBridge'); goog.require('cvox.ExtensionBridge');
goog.require('cvox.HostFactory'); goog.require('cvox.HostFactory');
goog.require('cvox.InjectedScriptLoader'); goog.require('cvox.InjectedScriptLoader');
goog.require('cvox.Msgs');
goog.require('cvox.NavBraille'); goog.require('cvox.NavBraille');
// TODO(dtseng): This is required to prevent Closure from stripping our export // TODO(dtseng): This is required to prevent Closure from stripping our export
// prefs on window. // prefs on window.
...@@ -56,7 +56,7 @@ cvox.ChromeVoxBackground.prototype.init = function() { ...@@ -56,7 +56,7 @@ cvox.ChromeVoxBackground.prototype.init = function() {
return; return;
} }
cvox.ChromeVox.msgs = cvox.HostFactory.getMsgs(); cvox.ChromeVox.msgs = new cvox.Msgs();
this.prefs = new cvox.ChromeVoxPrefs(); this.prefs = new cvox.ChromeVoxPrefs();
this.readPrefs(); this.readPrefs();
......
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
* *
*/ */
goog.require('cvox.ChromeMsgs');
goog.require('cvox.ChromeVoxBackground'); goog.require('cvox.ChromeVoxBackground');
goog.require('cvox.Msgs');
...@@ -13,7 +13,6 @@ goog.require('cvox.BrailleBackground'); ...@@ -13,7 +13,6 @@ goog.require('cvox.BrailleBackground');
goog.require('cvox.BrailleTable'); goog.require('cvox.BrailleTable');
goog.require('cvox.ChromeEarcons'); goog.require('cvox.ChromeEarcons');
goog.require('cvox.ChromeHost'); goog.require('cvox.ChromeHost');
goog.require('cvox.ChromeMsgs');
goog.require('cvox.ChromeTts'); goog.require('cvox.ChromeTts');
goog.require('cvox.ChromeVox'); goog.require('cvox.ChromeVox');
goog.require('cvox.ChromeVoxPrefs'); goog.require('cvox.ChromeVoxPrefs');
...@@ -22,6 +21,7 @@ goog.require('cvox.ExtensionBridge'); ...@@ -22,6 +21,7 @@ goog.require('cvox.ExtensionBridge');
goog.require('cvox.HostFactory'); goog.require('cvox.HostFactory');
goog.require('cvox.KeyMap'); goog.require('cvox.KeyMap');
goog.require('cvox.KeySequence'); goog.require('cvox.KeySequence');
goog.require('cvox.Msgs');
goog.require('cvox.PlatformFilter'); goog.require('cvox.PlatformFilter');
goog.require('cvox.PlatformUtil'); goog.require('cvox.PlatformUtil');
...@@ -67,7 +67,7 @@ cvox.OptionsPage.TEXT_TO_KEYCODE = { ...@@ -67,7 +67,7 @@ cvox.OptionsPage.TEXT_TO_KEYCODE = {
* @suppress {missingProperties} Property prefs never defined on Window * @suppress {missingProperties} Property prefs never defined on Window
*/ */
cvox.OptionsPage.init = function() { cvox.OptionsPage.init = function() {
cvox.ChromeVox.msgs = cvox.HostFactory.getMsgs(); cvox.ChromeVox.msgs = new cvox.Msgs();
cvox.OptionsPage.prefs = chrome.extension.getBackgroundPage().prefs; cvox.OptionsPage.prefs = chrome.extension.getBackgroundPage().prefs;
cvox.OptionsPage.populateKeyMapSelect(); cvox.OptionsPage.populateKeyMapSelect();
......
...@@ -46,7 +46,7 @@ cvox.InitGlobals.initGlobals = function() { ...@@ -46,7 +46,7 @@ cvox.InitGlobals.initGlobals = function() {
cvox.ChromeVox.mathJax = cvox.HostFactory.getMathJax(); cvox.ChromeVox.mathJax = cvox.HostFactory.getMathJax();
cvox.ChromeVox.earcons = cvox.HostFactory.getEarcons(); cvox.ChromeVox.earcons = cvox.HostFactory.getEarcons();
cvox.ChromeVox.msgs = cvox.HostFactory.getMsgs(); cvox.ChromeVox.msgs = new cvox.Msgs();
cvox.ChromeVox.isActive = true; cvox.ChromeVox.isActive = true;
cvox.ChromeVox.navigationManager = new cvox.NavigationManager(); cvox.ChromeVox.navigationManager = new cvox.NavigationManager();
cvox.ChromeVox.navigationManager.updateIndicator(); cvox.ChromeVox.navigationManager.updateIndicator();
......
...@@ -12,7 +12,7 @@ window.CLOSURE_USE_EXT_MESSAGES = true; ...@@ -12,7 +12,7 @@ window.CLOSURE_USE_EXT_MESSAGES = true;
goog.require('cvox.ChromeEarcons'); goog.require('cvox.ChromeEarcons');
goog.require('cvox.ChromeHost'); goog.require('cvox.ChromeHost');
goog.require('cvox.ChromeMathJax'); goog.require('cvox.ChromeMathJax');
goog.require('cvox.ChromeMsgs'); goog.require('cvox.Msgs');
goog.require('cvox.ChromeTts'); goog.require('cvox.ChromeTts');
goog.require('cvox.ChromeBraille'); goog.require('cvox.ChromeBraille');
goog.require('cvox.ChromeVoxInit'); goog.require('cvox.ChromeVoxInit');
......
...@@ -4,24 +4,16 @@ ...@@ -4,24 +4,16 @@
/** /**
* @fileoverview A cvox.AbstractMsgs implementation for Chrome. * @fileoverview Defines methods related to retrieving translated messages.
*/ */
goog.provide('cvox.ChromeMsgs'); goog.provide('cvox.Msgs');
goog.require('cvox.AbstractMsgs');
goog.require('cvox.HostFactory');
/** /**
* @constructor * @constructor
* @extends {cvox.AbstractMsgs}
*/ */
cvox.ChromeMsgs = function() { cvox.Msgs = function() {
cvox.AbstractMsgs.call(this);
}; };
goog.inherits(cvox.ChromeMsgs, cvox.AbstractMsgs);
/** /**
...@@ -30,14 +22,14 @@ goog.inherits(cvox.ChromeMsgs, cvox.AbstractMsgs); ...@@ -30,14 +22,14 @@ goog.inherits(cvox.ChromeMsgs, cvox.AbstractMsgs);
* @const * @const
* @private * @private
*/ */
cvox.ChromeMsgs.NAMESPACE_ = 'chromevox_'; cvox.Msgs.NAMESPACE_ = 'chromevox_';
/** /**
* Return the current locale. * Return the current locale.
* @return {string} The locale. * @return {string} The locale.
*/ */
cvox.ChromeMsgs.prototype.getLocale = function() { cvox.Msgs.prototype.getLocale = function() {
return chrome.i18n.getMessage('locale'); return chrome.i18n.getMessage('locale');
}; };
...@@ -48,15 +40,15 @@ cvox.ChromeMsgs.prototype.getLocale = function() { ...@@ -48,15 +40,15 @@ cvox.ChromeMsgs.prototype.getLocale = function() {
* If we can't find a message, throw an exception. This allows us to catch * If we can't find a message, throw an exception. This allows us to catch
* typos early. * typos early.
* *
* @param {string} message_id The id. * @param {string} messageId The id.
* @param {Array.<string>=} opt_subs Substitution strings. * @param {Array.<string>=} opt_subs Substitution strings.
* @return {string} The message. * @return {string} The message.
*/ */
cvox.ChromeMsgs.prototype.getMsg = function(message_id, opt_subs) { cvox.Msgs.prototype.getMsg = function(messageId, opt_subs) {
var message = chrome.i18n.getMessage( var message = chrome.i18n.getMessage(
cvox.ChromeMsgs.NAMESPACE_ + message_id, opt_subs); cvox.Msgs.NAMESPACE_ + messageId, opt_subs);
if (message == undefined || message == '') { if (message == undefined || message == '') {
throw new Error('Invalid ChromeVox message id: ' + message_id); throw new Error('Invalid ChromeVox message id: ' + messageId);
} }
return message; return message;
}; };
...@@ -68,7 +60,7 @@ cvox.ChromeMsgs.prototype.getMsg = function(message_id, opt_subs) { ...@@ -68,7 +60,7 @@ cvox.ChromeMsgs.prototype.getMsg = function(message_id, opt_subs) {
* *
* @param {Node} root The root node where the translation should be performed. * @param {Node} root The root node where the translation should be performed.
*/ */
cvox.ChromeMsgs.prototype.addTranslatedMessagesToDom = function(root) { cvox.Msgs.prototype.addTranslatedMessagesToDom = function(root) {
var elts = root.querySelectorAll('.i18n'); var elts = root.querySelectorAll('.i18n');
for (var i = 0; i < elts.length; i++) { for (var i = 0; i < elts.length; i++) {
var msgid = elts[i].getAttribute('msgid'); var msgid = elts[i].getAttribute('msgid');
...@@ -87,8 +79,6 @@ cvox.ChromeMsgs.prototype.addTranslatedMessagesToDom = function(root) { ...@@ -87,8 +79,6 @@ cvox.ChromeMsgs.prototype.addTranslatedMessagesToDom = function(root) {
* @param {number} num The number. * @param {number} num The number.
* @return {string} The number in the correct locale. * @return {string} The number in the correct locale.
*/ */
cvox.ChromeMsgs.prototype.getNumber = function(num) { cvox.Msgs.prototype.getNumber = function(num) {
return '' + num; return '' + num;
}; };
cvox.HostFactory.msgsConstructor = cvox.ChromeMsgs;
...@@ -36,8 +36,8 @@ goog.addDependency( ...@@ -36,8 +36,8 @@ goog.addDependency(
[]); []);
goog.addDependency( goog.addDependency(
'../host/interface/abstract_msgs.js', '../chromevox/messages/msgs.js',
['cvox.AbstractMsgs'], ['cvox.Msgs'],
[]); []);
goog.addDependency( goog.addDependency(
...@@ -97,7 +97,7 @@ cvox.ChromeVox.braille; ...@@ -97,7 +97,7 @@ cvox.ChromeVox.braille;
*/ */
cvox.ChromeVox.mathJax; cvox.ChromeVox.mathJax;
/** /**
* @type {cvox.AbstractMsgs} * @type {cvox.Msgs}
*/ */
cvox.ChromeVox.msgs = null; cvox.ChromeVox.msgs = null;
/** /**
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Defined the convenience function cvox.Msgs.getMsg.
*/
goog.provide('cvox.AbstractMsgs');
/**
* @constructor
*/
cvox.AbstractMsgs = function() { };
/**
* Return the current locale.
* @return {string} The locale.
*/
cvox.AbstractMsgs.prototype.getLocale = function() { };
/**
* Returns the message with the given message id.
*
* If we can't find a message, throw an exception. This allows us to catch
* typos early.
*
* @param {string} message_id The id.
* @param {Array.<string>=} opt_subs Substitution strings.
* @return {string} The message.
*/
cvox.AbstractMsgs.prototype.getMsg = function(message_id, opt_subs) {
};
/**
* Retuns a number formatted correctly.
*
* @param {number} num The number.
* @return {string} The number in the correct locale.
*/
cvox.AbstractMsgs.prototype.getNumber = function(num) {
};
...@@ -10,18 +10,15 @@ ...@@ -10,18 +10,15 @@
goog.provide('cvox.HostFactory'); goog.provide('cvox.HostFactory');
goog.require('cvox.AbstractBraille');
goog.require('cvox.AbstractEarcons'); goog.require('cvox.AbstractEarcons');
goog.require('cvox.AbstractHost'); goog.require('cvox.AbstractHost');
goog.require('cvox.AbstractMathJax'); goog.require('cvox.AbstractMathJax');
goog.require('cvox.AbstractMsgs');
goog.require('cvox.AbstractTts'); goog.require('cvox.AbstractTts');
goog.require('cvox.AbstractBraille');
/** /**
* @namespace. * @constructor
*/ */
cvox.HostFactory = function() {}; cvox.HostFactory = function() {};
...@@ -49,14 +46,6 @@ cvox.HostFactory.getBraille = function() { ...@@ -49,14 +46,6 @@ cvox.HostFactory.getBraille = function() {
return new cvox.HostFactory.brailleConstructor; return new cvox.HostFactory.brailleConstructor;
}; };
/**
* Returns the message interface.
* @return {cvox.AbstractMsgs}
*/
cvox.HostFactory.getMsgs = function() {
return new cvox.HostFactory.msgsConstructor;
};
/** /**
* Returns the earcons interface. * Returns the earcons interface.
* @return {cvox.AbstractEarcons} * @return {cvox.AbstractEarcons}
...@@ -88,11 +77,6 @@ cvox.HostFactory.ttsConstructor; ...@@ -88,11 +77,6 @@ cvox.HostFactory.ttsConstructor;
*/ */
cvox.HostFactory.brailleConstructor; cvox.HostFactory.brailleConstructor;
/**
* @type {function (new:cvox.AbstractMsgs)}
*/
cvox.HostFactory.msgsConstructor;
/** /**
* @type {function (new:cvox.AbstractEarcons)} * @type {function (new:cvox.AbstractEarcons)}
*/ */
......
...@@ -9,25 +9,22 @@ ...@@ -9,25 +9,22 @@
goog.provide('cvox.TestMsgs'); goog.provide('cvox.TestMsgs');
goog.require('cvox.AbstractMsgs'); goog.require('cvox.Msgs');
goog.require('cvox.HostFactory');
goog.require('cvox.TestMessages'); goog.require('cvox.TestMessages');
/** /**
* @constructor * @constructor
* @extends {cvox.AbstractMsgs} * @extends {cvox.Msgs}
*/ */
cvox.TestMsgs = function() { cvox.TestMsgs = function() {
cvox.AbstractMsgs.call(this); cvox.Msgs.call(this);
}; };
goog.inherits(cvox.TestMsgs, cvox.AbstractMsgs); goog.inherits(cvox.TestMsgs, cvox.Msgs);
/** /**
* Return the current locale. * @override
* @return {string} The locale.
*/ */
cvox.TestMsgs.prototype.getLocale = function() { cvox.TestMsgs.prototype.getLocale = function() {
return 'testing'; return 'testing';
...@@ -35,19 +32,15 @@ cvox.TestMsgs.prototype.getLocale = function() { ...@@ -35,19 +32,15 @@ cvox.TestMsgs.prototype.getLocale = function() {
/** /**
* Returns the message with the given message id from the ChromeVox namespace. * @override
*
* @param {string} message_id The id.
* @param {Array.<string>} opt_subs Substitution strings.
* @return {string} The message.
*/ */
cvox.TestMsgs.prototype.getMsg = function(message_id, opt_subs) { cvox.TestMsgs.prototype.getMsg = function(messageId, opt_subs) {
if (!message_id) { if (!messageId) {
throw Error('Message id required'); throw Error('Message id required');
} }
var message = cvox.TestMessages[('chromevox_' + message_id).toUpperCase()]; var message = cvox.TestMessages[('chromevox_' + messageId).toUpperCase()];
if (message == undefined) { if (message == undefined) {
throw Error('missing-msg: ' + message_id); throw Error('missing-msg: ' + messageId);
} }
var messageString = message.message; var messageString = message.message;
...@@ -59,19 +52,3 @@ cvox.TestMsgs.prototype.getMsg = function(message_id, opt_subs) { ...@@ -59,19 +52,3 @@ cvox.TestMsgs.prototype.getMsg = function(message_id, opt_subs) {
} }
return messageString; return messageString;
}; };
/**
* Retuns a number formatted correctly.
*
* @param {number} num The number.
* @return {string} The number in the correct locale.
*/
cvox.TestMsgs.prototype.getNumber = function(num) {
return '' + num;
};
/**
* Cosntructor for the host factory.
*/
cvox.HostFactory.msgsConstructor = cvox.TestMsgs;
...@@ -70,7 +70,7 @@ cvox.TableShifter.prototype.getName = function() { ...@@ -70,7 +70,7 @@ cvox.TableShifter.prototype.getName = function() {
/** /**
* @override * @override
* @suppress {checkTypes} actual parameter 2 of * @suppress {checkTypes} actual parameter 2 of
* cvox.AbstractMsgs.prototype.getMsg does not match formal parameter * cvox.Msgs.prototype.getMsg does not match formal parameter
* found : Array.<number> * found : Array.<number>
* required: (Array.<string>|null|undefined) * required: (Array.<string>|null|undefined)
*/ */
......
...@@ -55,7 +55,7 @@ cvox.TableWalker.prototype.sync = function(sel) { ...@@ -55,7 +55,7 @@ cvox.TableWalker.prototype.sync = function(sel) {
/** /**
* @override * @override
* @suppress {checkTypes} actual parameter 2 of * @suppress {checkTypes} actual parameter 2 of
* cvox.AbstractMsgs.prototype.getMsg does not match formal parameter * cvox.Msgs.prototype.getMsg does not match formal parameter
* found : Array.<number> * found : Array.<number>
* required: (Array.<string>|null|undefined) * required: (Array.<string>|null|undefined)
*/ */
...@@ -267,7 +267,7 @@ cvox.TableWalker.prototype.getHeaderText_ = function(sel) { ...@@ -267,7 +267,7 @@ cvox.TableWalker.prototype.getHeaderText_ = function(sel) {
* @param {!cvox.CursorSelection} sel A valid selection. * @param {!cvox.CursorSelection} sel A valid selection.
* @return {Array.<cvox.NavDescription>} The location description. * @return {Array.<cvox.NavDescription>} The location description.
* @suppress {checkTypes} actual parameter 2 of * @suppress {checkTypes} actual parameter 2 of
* cvox.AbstractMsgs.prototype.getMsg does not match * cvox.Msgs.prototype.getMsg does not match
* formal parameter * formal parameter
* found : Array.<number> * found : Array.<number>
* required: (Array.<string>|null|undefined) * required: (Array.<string>|null|undefined)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment