Commit a98de0c2 authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

Add ChromeVox hotkey to report rich text attributes.

Adds new hotkey (modifier + a + f) for ChromeVox users to quickly get
all supported text format attributes: bold, italic, underline, strike
through, font family, font size, and color.

Bug: 929414
Change-Id: Ia33463e4a3566aed34631964a28d537c7d14fbbc
Reviewed-on: https://chromium-review.googlesource.com/c/1456210
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633863}
parent 13691062
...@@ -124,6 +124,7 @@ chromevox_modules = [ ...@@ -124,6 +124,7 @@ chromevox_modules = [
"cvox2/background/base_automation_handler.js", "cvox2/background/base_automation_handler.js",
"cvox2/background/braille_command_data.js", "cvox2/background/braille_command_data.js",
"cvox2/background/braille_command_handler.js", "cvox2/background/braille_command_handler.js",
"cvox2/background/color.js",
"cvox2/background/chromevox_state.js", "cvox2/background/chromevox_state.js",
"cvox2/background/command_handler.js", "cvox2/background/command_handler.js",
"cvox2/background/console_tts.js", "cvox2/background/console_tts.js",
...@@ -618,6 +619,7 @@ js2gtest("chromevox_extjs_tests") { ...@@ -618,6 +619,7 @@ js2gtest("chromevox_extjs_tests") {
"braille/liblouis_test.extjs", "braille/liblouis_test.extjs",
"cvox2/background/automation_util_test.extjs", "cvox2/background/automation_util_test.extjs",
"cvox2/background/background_test.extjs", "cvox2/background/background_test.extjs",
"cvox2/background/color_test.extjs",
"cvox2/background/cursors_test.extjs", "cvox2/background/cursors_test.extjs",
"cvox2/background/editing_test.extjs", "cvox2/background/editing_test.extjs",
"cvox2/background/i_search_test.extjs", "cvox2/background/i_search_test.extjs",
......
...@@ -1005,6 +1005,15 @@ ...@@ -1005,6 +1005,15 @@
"keyCode": [79, 66] "keyCode": [79, 66]
} }
} }
},
{
"command": "getRichTextDescription",
"sequence": {
"cvoxModifier": true,
"keys": {
"keyCode": [65, 70]
}
}
} }
] ]
} }
// Copyright 2019 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.
// Include test fixture.
GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']);
/**
* Test fixture for Color.
* @constructor
* @extends {ChromeVoxE2ETest}
*/
function ChromeVoxColorTest() {
ChromeVoxNextE2ETest.call(this);
}
ChromeVoxColorTest.prototype = {
__proto__: ChromeVoxNextE2ETest.prototype,
};
SYNC_TEST_F('ChromeVoxColorTest', 'FindDistanceTest', function() {
// Hexadecimal representations of colors.
var red = 0xff0000;
var lime = 0x00ff00;
var blue = 0x0000ff;
var opaqueRed = 0xffff0000;
var transparentLime = 0x0000ff00;
assertEquals(Color.findDistance(red,lime), Color.findDistance(lime, blue));
// Opacity should not factor into this calculation.
assertEquals(Color.findDistance(red,lime), Color.findDistance(opaqueRed, transparentLime));
});
SYNC_TEST_F('ChromeVoxColorTest', 'FindClosestMatchingColorTest', function() {
var white = 0xffffff;
var red = 0xff0000;
var lime = 0x00ff00;
var blue = 0x0000ff;
var black = 0x000000;
var looksLikePink = 0xF4CCCC;
var looksLikeGreen = 0x38761D;
var unknownColor = 0x0C343D;
// Exact matches.
assertEquals('White', Color.findClosestMatchingColor(white));
assertEquals('Red', Color.findClosestMatchingColor(red));
assertEquals('Lime', Color.findClosestMatchingColor(lime));
assertEquals('Blue', Color.findClosestMatchingColor(blue));
assertEquals('Black', Color.findClosestMatchingColor(black));
// Inexact matches.
assertEquals('Pink', Color.findClosestMatchingColor(looksLikePink));
assertEquals('Forest Green', Color.findClosestMatchingColor(looksLikeGreen));
// No match.
assertEquals('', Color.findClosestMatchingColor(unknownColor));
});
SYNC_TEST_F('ChromeVoxColorTest', 'GetOpacityPercentageTest', function() {
var opaqueRed = 0xffff0000;
var transparentLime = 0x0000ff00;
var translucentBlue = 0x800000ff;
assertEquals(100, Color.getOpacityPercentage(opaqueRed));
assertEquals(0, Color.getOpacityPercentage(transparentLime));
assertEquals(50, Color.getOpacityPercentage(translucentBlue));
});
...@@ -17,6 +17,7 @@ goog.require('cvox.ChromeVoxBackground'); ...@@ -17,6 +17,7 @@ goog.require('cvox.ChromeVoxBackground');
goog.require('cvox.ChromeVoxKbHandler'); goog.require('cvox.ChromeVoxKbHandler');
goog.require('cvox.ChromeVoxPrefs'); goog.require('cvox.ChromeVoxPrefs');
goog.require('cvox.CommandStore'); goog.require('cvox.CommandStore');
goog.require('Color');
goog.scope(function() { goog.scope(function() {
var AutomationEvent = chrome.automation.AutomationEvent; var AutomationEvent = chrome.automation.AutomationEvent;
...@@ -868,6 +869,28 @@ CommandHandler.onCommand = function(command) { ...@@ -868,6 +869,28 @@ CommandHandler.onCommand = function(command) {
.go(); .go();
}); });
break; break;
case 'getRichTextDescription':
var node = ChromeVoxState.instance.currentRange.start.node;
var optSubs = [];
node.fontSize ? optSubs.push('font size: ' + node.fontSize) :
optSubs.push('');
node.color ? optSubs.push(Color.getColorDescription(node.color)) :
optSubs.push('');
node.bold ? optSubs.push(Msgs.getMsg('bold')) : optSubs.push('');
node.italic ? optSubs.push(Msgs.getMsg('italic')) : optSubs.push('');
node.underline ? optSubs.push(Msgs.getMsg('underline')) :
optSubs.push('');
node.lineThrough ? optSubs.push(Msgs.getMsg('linethrough')) :
optSubs.push('');
node.fontFamily ? optSubs.push('font family: ' + node.fontFamily) :
optSubs.push('');
var richTextDescription = Msgs.getMsg('rich_text_attributes', optSubs);
new Output()
.withString(richTextDescription)
.withQueueMode(cvox.QueueMode.CATEGORY_FLUSH)
.go();
return false;
default: default:
return true; return true;
} }
......
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