[Extensions] Make extension message bubble factory platform-abstract
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / chromevox / common / aural_style_util.js
blob0e8c3b5cf57629440454ef9d2810c3458bd93f1b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview A set of classes to support aural CSS.
7 */
10 goog.provide('cvox.AuralProperty');
11 goog.provide('cvox.AuralStyleConverter');
12 goog.provide('cvox.AuralStyleUtil');
14 // This seems the only way to lay out an enum and use it as a key.
15 /**
16 * @enum {string}
18 cvox.AuralProperty = {
19 VOLUME: 'VOLUME',
20 SPEAK: 'SPEAK',
21 PAUSE_BEFORE: 'PAUSE_BEFORE',
22 PAUSE_AFTER: 'PAUSE_AFTER',
23 PAUSE: 'PAUSE',
24 CUE_BEFORE: 'CUE_BEFORE',
25 CUE_AFTER: 'CUE_AFTER',
26 CUE: 'CUE',
27 PLAY_DURING: 'PLAY_DURING',
28 AZIMUTH: 'AZIMUTH',
29 ELEVATION: 'ELEVATION',
30 SPEECH_RATE: 'SPEECH_RATE',
31 VOICE_FAMILY: 'VOICE_FAMILY',
32 PITCH: 'PITCH',
33 PITCH_RANGE: 'PITCH_RANGE',
34 STRESS: 'STRESS',
35 RICHNESS: 'RICHNESS',
36 SPEAK_PUNCTUATION: 'SPEAK_PUNCTUATION',
37 SPEAK_NUMERIAL: 'SPEAK_NUMERIAL',
38 SPEAK_HEADER: 'SPEAK_HEADER',
39 NONE: 'NONE'
43 /* A series of conversion functions. */
44 /**
45 * An identity conversion.
46 * @param {number} value The aural CSS value to convert.
47 * @return {number} The resulting tts property value.
49 cvox.AuralStyleConverter.identity = function(value) {
50 return value;
54 /**
55 * Conversion from an aural style property to Chrome TTS property.
56 * TODO(dtseng): no-op's below need to be supported by the extension API itself
57 * or by ChromeVox.
58 * @type {Object<cvox.AuralProperty, string>}
60 cvox.AuralStyleConverter.propertyTable = {
61 VOLUME: 'volume',
62 SPEAK: 'no-op',
63 PAUSE_BEFORE: 'no-op',
64 PAUSE_AFTER: 'no-op',
65 PAUSE: 'no-op',
66 CUE_BEFORE: 'no-op',
67 CUE_AFTER: 'no-op',
68 CUE: 'no-op',
69 PLAY_DURING: 'no-op',
70 AZIMUTH: 'no-op',
71 ELEVATION: 'no-op',
72 SPEECH_RATE: 'relativeRate',
73 VOICE_FAMILY: 'no-op',
74 PITCH: 'relativePitch',
75 PITCH_RANGE: 'no-op',
76 STRESS: 'no-op',
77 RICHNESS: 'no-op',
78 SPEAK_PUNCTUATION: 'no-op',
79 SPEAK_NUMERIAL: 'no-op',
80 SPEAK_HEADER: 'no-op',
81 NONE: 'no-op'
85 /**
86 * Conversion from an aural style value to Chrome TTS value.
87 * TODO(dtseng): Conversion of aural CSS values is incomplete; everything is an
88 * identity conversion at the moment.
89 * @type {Object<cvox.AuralProperty, function(*)>}
91 cvox.AuralStyleConverter.valueTable = {
92 VOLUME: cvox.AuralStyleConverter.identity,
93 SPEAK: cvox.AuralStyleConverter.identity,
94 PAUSE_BEFORE: cvox.AuralStyleConverter.identity,
95 PAUSE_AFTER: cvox.AuralStyleConverter.identity,
96 PAUSE: cvox.AuralStyleConverter.identity,
97 CUE_BEFORE: cvox.AuralStyleConverter.identity,
98 CUE_AFTER: cvox.AuralStyleConverter.identity,
99 CUE: cvox.AuralStyleConverter.identity,
100 PLAY_DURING: cvox.AuralStyleConverter.identity,
101 AZIMUTH: cvox.AuralStyleConverter.identity,
102 ELEVATION: cvox.AuralStyleConverter.identity,
103 SPEECH_RATE: cvox.AuralStyleConverter.identity,
104 VOICE_FAMILY: cvox.AuralStyleConverter.identity,
105 PITCH: cvox.AuralStyleConverter.identity,
106 PITCH_RANGE: cvox.AuralStyleConverter.identity,
107 STRESS: cvox.AuralStyleConverter.identity,
108 RICHNESS: cvox.AuralStyleConverter.identity,
109 SPEAK_PUNCTUATION: cvox.AuralStyleConverter.identity,
110 SPEAK_NUMERIAL: cvox.AuralStyleConverter.identity,
111 SPEAK_HEADER: cvox.AuralStyleConverter.identity,
112 NONE: cvox.AuralStyleConverter.identity
117 * Converts a given aural property/value rule to a tts property/value.
118 * @param {cvox.AuralProperty} property The property.
119 * @param {*} value The CSS-based value.
120 * @return {Object} An object holding tts property and value.
122 cvox.AuralStyleConverter.convertRule = function(property, value) {
123 return {
124 property: cvox.AuralStyleConverter.propertyTable[property],
125 value: cvox.AuralStyleConverter.valueTable[property](value)
131 * Converts an aural CSS style block to a TTS property object.
132 * @param {Object<cvox.AuralProperty, *>} style The style.
133 * @return {Object} The tts property object.
135 cvox.AuralStyleConverter.convertStyle = function(style) {
136 var ttsProperties = {};
137 for (var property in style) {
138 var ttsProperty =
139 cvox.AuralStyleConverter.convertRule(property, style[property]);
140 ttsProperties[ttsProperty.property] = ttsProperty.value;
142 return ttsProperties;
147 * Gets the aural style for a node.
148 * @param {Node} node The node.
149 * @return {Object} The aural style, converted to tts properties.
151 cvox.AuralStyleUtil.getStyleForNode = function(node) {
152 var style = cvox.AuralStyleUtil.defaultStyles[node.tagName];
153 if (!style) {
154 return null;
156 return cvox.AuralStyleConverter.convertStyle(style);
161 * A list of default aural styles.
163 cvox.AuralStyleUtil.defaultStyles = {
164 'ARTICLE': {
165 PITCH: -0.1
167 'ASIDE': {
168 PITCH: -0.1
170 'FOOTER': {
171 PITCH: -0.1
173 'H1': {
174 PITCH: -0.3
176 'H2': {
177 PITCH: -0.25
179 'H3': {
180 PITCH: -0.2
182 'H4': {
183 PITCH: -0.15
185 'H5': {
186 PITCH: -0.1
188 'H6': {
189 PITCH: -0.05
191 'HEADER': {
192 PITCH: -0.1
194 'HGROUP': {
195 PITCH: -0.1
197 'MARK': {
198 PITCH: -0.1
200 'NAV': {
201 PITCH: -0.1
203 'SECTION': {
204 PITCH: -0.1
206 'TIME': {
207 PITCH: -0.1