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