Commit 32559c6d authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

Merge (TextLog|TreeLog).LogType to LogStore.LogType in ChromeVox LogStore

This CL also fixes how to inherit class in TextLog and TreeLog

This change is a preparation of crbug/987173

Bug: 987173
Test: browser_tests --gtest_filter="ChromeVoxLogStore*"
Change-Id: Ie2de4c6c633311f6ea397b5241cb886127ce8d50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1734736
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686732}
parent f148fb80
...@@ -44,7 +44,7 @@ ConsoleTts.prototype = { ...@@ -44,7 +44,7 @@ ConsoleTts.prototype = {
logStr += ' category=' + properties.category; logStr += ' category=' + properties.category;
} }
logStr += ' "' + textString + '"'; logStr += ' "' + textString + '"';
LogStore.getInstance().writeTextLog(logStr, TextLog.LogType.SPEECH); LogStore.getInstance().writeTextLog(logStr, LogStore.LogType.SPEECH);
console.log(logStr); console.log(logStr);
} }
return this; return this;
......
...@@ -60,7 +60,7 @@ EventStreamLogger.prototype = { ...@@ -60,7 +60,7 @@ EventStreamLogger.prototype = {
logStr += ', RootName = ' + evt.target.root.name; logStr += ', RootName = ' + evt.target.root.name;
logStr += ', DocumentURL = ' + evt.target.docUrl; logStr += ', DocumentURL = ' + evt.target.docUrl;
console.log(logStr); console.log(logStr);
LogStore.getInstance().writeTextLog(logStr, TextLog.LogType.EVENT); LogStore.getInstance().writeTextLog(logStr, LogStore.LogType.EVENT);
}, },
/** /**
......
...@@ -43,7 +43,7 @@ LogPage.init = function() { ...@@ -43,7 +43,7 @@ LogPage.init = function() {
LogPage.LogStore = LogPage.backgroundWindow.LogStore.getInstance(); LogPage.LogStore = LogPage.backgroundWindow.LogStore.getInstance();
/** Create filter checkboxes. */ /** Create filter checkboxes. */
for (var type of LogStore.logTypes()) { for (var type of Object.values(LogStore.LogType)) {
var label = document.createElement('label'); var label = document.createElement('label');
var input = document.createElement('input'); var input = document.createElement('input');
input.id = type + 'Filter'; input.id = type + 'Filter';
...@@ -65,7 +65,7 @@ LogPage.init = function() { ...@@ -65,7 +65,7 @@ LogPage.init = function() {
}; };
var params = new URLSearchParams(location.search); var params = new URLSearchParams(location.search);
for (var type of LogStore.logTypes()) { for (var type of Object.values(LogStore.LogType)) {
var typeFilter = type + 'Filter'; var typeFilter = type + 'Filter';
LogPage.setFilterTypeEnabled(typeFilter, params.get(typeFilter)); LogPage.setFilterTypeEnabled(typeFilter, params.get(typeFilter));
} }
...@@ -117,7 +117,7 @@ LogPage.saveLogEvent = function(event) { ...@@ -117,7 +117,7 @@ LogPage.saveLogEvent = function(event) {
* update logs. * update logs.
*/ */
LogPage.update = function() { LogPage.update = function() {
for (var type of LogStore.logTypes()) { for (var type of Object.values(LogStore.LogType)) {
var typeFilter = type + 'Filter'; var typeFilter = type + 'Filter';
var element = document.getElementById(typeFilter); var element = document.getElementById(typeFilter);
element.checked = LogPage.urlPrefs_[typeFilter]; element.checked = LogPage.urlPrefs_[typeFilter];
...@@ -153,7 +153,7 @@ LogPage.updateLog = function(log, div) { ...@@ -153,7 +153,7 @@ LogPage.updateLog = function(log, div) {
p.appendChild(timeStamp); p.appendChild(timeStamp);
/** Add hide tree button when logType is tree. */ /** Add hide tree button when logType is tree. */
if (log[i].logType == TreeLog.LogType.TREE) { if (log[i].logType == LogStore.LogType.TREE) {
var toggle = document.createElement('label'); var toggle = document.createElement('label');
var toggleCheckbox = document.createElement('input'); var toggleCheckbox = document.createElement('input');
toggleCheckbox.type = 'checkbox'; toggleCheckbox.type = 'checkbox';
...@@ -191,7 +191,7 @@ LogPage.setFilterTypeEnabled = function(typeFilter, checked) { ...@@ -191,7 +191,7 @@ LogPage.setFilterTypeEnabled = function(typeFilter, checked) {
*/ */
LogPage.createUrlParams = function() { LogPage.createUrlParams = function() {
var urlParams = []; var urlParams = [];
for (var type of LogStore.logTypes()) { for (var type of Object.values(LogStore.LogType)) {
var typeFilter = type + 'Filter'; var typeFilter = type + 'Filter';
urlParams.push(typeFilter + '=' + LogPage.urlPrefs_[typeFilter]); urlParams.push(typeFilter + '=' + LogPage.urlPrefs_[typeFilter]);
} }
......
...@@ -16,7 +16,7 @@ goog.require('TreeDumper'); ...@@ -16,7 +16,7 @@ goog.require('TreeDumper');
/** @constructor */ /** @constructor */
BaseLog = function(logType) { BaseLog = function(logType) {
/** /**
* @type {!TextLog.LogType | !TreeLog.LogType} * @type {!LogStore.LogType}
*/ */
this.logType = logType; this.logType = logType;
...@@ -33,7 +33,7 @@ BaseLog.prototype.toString = function() { ...@@ -33,7 +33,7 @@ BaseLog.prototype.toString = function() {
/** /**
* @param {string} logStr * @param {string} logStr
* @param {!TextLog.LogType} logType * @param {!LogStore.LogType} logType
* @constructor * @constructor
* @extends {BaseLog} * @extends {BaseLog}
*/ */
...@@ -46,27 +46,11 @@ TextLog = function(logStr, logType) { ...@@ -46,27 +46,11 @@ TextLog = function(logStr, logType) {
*/ */
this.logStr_ = logStr; this.logStr_ = logStr;
}; };
goog.inherits(TextLog, BaseLog);
TextLog.prototype = { /** @override */
__proto__: BaseLog.prototype, TextLog.prototype.toString = function() {
return this.logStr_;
/** @override */
toString: function() {
return this.logStr_;
},
};
/**
* Filter type checkboxes are shown in this order at the log page.
* @enum {string}
*/
TextLog.LogType = {
SPEECH: 'speech',
SPEECH_RULE: 'speechRule',
BRAILLE: 'braille',
BRAILLE_RULE: 'brailleRule',
EARCON: 'earcon',
EVENT: 'event',
}; };
/** /**
...@@ -75,7 +59,7 @@ TextLog.LogType = { ...@@ -75,7 +59,7 @@ TextLog.LogType = {
* @extends {BaseLog} * @extends {BaseLog}
*/ */
TreeLog = function(logTree) { TreeLog = function(logTree) {
BaseLog.call(this, TreeLog.LogType.TREE); BaseLog.call(this, LogStore.LogType.TREE);
/** /**
* @type {!TreeDumper} * @type {!TreeDumper}
...@@ -83,19 +67,11 @@ TreeLog = function(logTree) { ...@@ -83,19 +67,11 @@ TreeLog = function(logTree) {
*/ */
this.logTree_ = logTree; this.logTree_ = logTree;
}; };
goog.inherits(TreeLog, BaseLog);
TreeLog.prototype = { /** @override */
__proto__: BaseLog.prototype, TreeLog.prototype.toString = function() {
return this.logTree_.treeToString();
/** @override */
toString: function() {
return this.logTree_.treeToString();
},
};
/** @enum {string} */
TreeLog.LogType = {
TREE: 'tree',
}; };
/** @constructor */ /** @constructor */
...@@ -124,32 +100,34 @@ LogStore = function() { ...@@ -124,32 +100,34 @@ LogStore = function() {
LogStore.LOG_LIMIT = 3000; LogStore.LOG_LIMIT = 3000;
/** /**
* List of all LogTypes. * List of all LogType.
* @return {!Array<!TextLog.LogType | !TreeLog.LogType>} * Note that filter type checkboxes are shown in this order at the log page.
* @enum {string}
*/ */
LogStore.logTypes = function() { LogStore.LogType = {
var types = []; SPEECH: 'speech',
for (var type in TextLog.LogType) SPEECH_RULE: 'speechRule',
types.push(TextLog.LogType[type]); BRAILLE: 'braille',
for (var type in TreeLog.LogType) BRAILLE_RULE: 'brailleRule',
types.push(TreeLog.LogType[type]); EARCON: 'earcon',
return types; EVENT: 'event',
TREE: 'tree',
}; };
/** /**
* Creates logs of type |type| in order. * Creates logs of type |type| in order.
* This is not the best way to create logs fast but * This is not the best way to create logs fast but
* getLogsOfType() is not called often. * getLogsOfType() is not called often.
* @param {!TextLog.LogType} logType * @param {!LogStore.LogType} LogType
* @return {!Array<BaseLog>} * @return {!Array<BaseLog>}
*/ */
LogStore.prototype.getLogsOfType = function(logType) { LogStore.prototype.getLogsOfType = function(LogType) {
var returnLogs = []; var returnLogs = [];
for (var i = 0; i < LogStore.LOG_LIMIT; i++) { for (var i = 0; i < LogStore.LOG_LIMIT; i++) {
var index = (this.startIndex_ + i) % LogStore.LOG_LIMIT; var index = (this.startIndex_ + i) % LogStore.LOG_LIMIT;
if (!this.logs_[index]) if (!this.logs_[index])
continue; continue;
if (this.logs_[index].logType == logType) if (this.logs_[index].logType == LogType)
returnLogs.push(this.logs_[index]); returnLogs.push(this.logs_[index]);
} }
return returnLogs; return returnLogs;
...@@ -176,13 +154,13 @@ LogStore.prototype.getLogs = function() { ...@@ -176,13 +154,13 @@ LogStore.prototype.getLogs = function() {
* Write a text log to this.logs_. * Write a text log to this.logs_.
* To add a message to logs, this function shuold be called. * To add a message to logs, this function shuold be called.
* @param {string} logContent * @param {string} logContent
* @param {!TextLog.LogType} logType * @param {!LogStore.LogType} LogType
*/ */
LogStore.prototype.writeTextLog = function(logContent, logType) { LogStore.prototype.writeTextLog = function(logContent, LogType) {
if (this.shouldSkipOutput_()) if (this.shouldSkipOutput_())
return; return;
var log = new TextLog(logContent, logType); var log = new TextLog(logContent, LogType);
this.logs_[this.startIndex_] = log; this.logs_[this.startIndex_] = log;
this.startIndex_ += 1; this.startIndex_ += 1;
if (this.startIndex_ == LogStore.LOG_LIMIT) if (this.startIndex_ == LogStore.LOG_LIMIT)
......
...@@ -63,7 +63,7 @@ NextEarcons.prototype = { ...@@ -63,7 +63,7 @@ NextEarcons.prototype = {
return; return;
} }
if (localStorage['enableEarconLogging'] == 'true') { if (localStorage['enableEarconLogging'] == 'true') {
LogStore.getInstance().writeTextLog(earcon, TextLog.LogType.EARCON); LogStore.getInstance().writeTextLog(earcon, LogStore.LogType.EARCON);
console.log('Earcon ' + earcon); console.log('Earcon ' + earcon);
} }
if (ChromeVoxState.instance.currentRange && if (ChromeVoxState.instance.currentRange &&
......
...@@ -1052,7 +1052,7 @@ Output.prototype = { ...@@ -1052,7 +1052,7 @@ Output.prototype = {
} }
if (this.speechRulesStr_.str) { if (this.speechRulesStr_.str) {
LogStore.getInstance().writeTextLog( LogStore.getInstance().writeTextLog(
this.speechRulesStr_.str, TextLog.LogType.SPEECH_RULE); this.speechRulesStr_.str, LogStore.LogType.SPEECH_RULE);
} }
// Braille. // Braille.
...@@ -1078,7 +1078,7 @@ Output.prototype = { ...@@ -1078,7 +1078,7 @@ Output.prototype = {
cvox.ChromeVox.braille.write(output); cvox.ChromeVox.braille.write(output);
if (this.brailleRulesStr_.str) { if (this.brailleRulesStr_.str) {
LogStore.getInstance().writeTextLog( LogStore.getInstance().writeTextLog(
this.brailleRulesStr_.str, TextLog.LogType.BRAILLE_RULE); this.brailleRulesStr_.str, LogStore.LogType.BRAILLE_RULE);
} }
} }
......
...@@ -77,7 +77,7 @@ cvox.BrailleBackground.prototype.write = function(params) { ...@@ -77,7 +77,7 @@ cvox.BrailleBackground.prototype.write = function(params) {
if (localStorage['enableBrailleLogging'] == 'true') { if (localStorage['enableBrailleLogging'] == 'true') {
var logStr = 'Braille "' + params.text.toString() + '"'; var logStr = 'Braille "' + params.text.toString() + '"';
LogStore.getInstance().writeTextLog(logStr, TextLog.LogType.BRAILLE); LogStore.getInstance().writeTextLog(logStr, LogStore.LogType.BRAILLE);
console.log(logStr); console.log(logStr);
} }
......
...@@ -57,7 +57,7 @@ cvox.ClassicEarcons.prototype.playEarcon = function(earcon, opt_location) { ...@@ -57,7 +57,7 @@ cvox.ClassicEarcons.prototype.playEarcon = function(earcon, opt_location) {
return; return;
} }
if (localStorage['enableEarconLogging'] == 'true') { if (localStorage['enableEarconLogging'] == 'true') {
LogStore.getInstance().writeTextLog(earcon, TextLog.LogType.EARCON); LogStore.getInstance().writeTextLog(earcon, LogStore.LogType.EARCON);
console.log('Earcon ' + earcon); console.log('Earcon ' + earcon);
} }
......
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