OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @fileoverview Provides different rules for each type of result. | 7 * @fileoverview Provides different rules for each type of result. |
8 */ | 8 */ |
9 | 9 |
10 goog.provide('cvox.SearchResults'); | 10 goog.provide('cvox.SearchResults'); |
(...skipping 13 matching lines...) Expand all Loading... |
24 * Speaks a result based on given selectors. | 24 * Speaks a result based on given selectors. |
25 * @param {Element} result Search result to be spoken. | 25 * @param {Element} result Search result to be spoken. |
26 * @param {Array} selectTexts Array of selectors or text to speak. | 26 * @param {Array} selectTexts Array of selectors or text to speak. |
27 */ | 27 */ |
28 cvox.SearchResults.speakResultBySelectTexts = function(result, selectTexts) { | 28 cvox.SearchResults.speakResultBySelectTexts = function(result, selectTexts) { |
29 for (var j = 0; j < selectTexts.length; j++) { | 29 for (var j = 0; j < selectTexts.length; j++) { |
30 var selectText = selectTexts[j]; | 30 var selectText = selectTexts[j]; |
31 if (selectText.select) { | 31 if (selectText.select) { |
32 var elems = result.querySelectorAll(selectText.select); | 32 var elems = result.querySelectorAll(selectText.select); |
33 for (var i = 0; i < elems.length; i++) { | 33 for (var i = 0; i < elems.length; i++) { |
34 cvox.ChromeVox.speakNode(elems.item(i), 1); | 34 cvox.ChromeVox.speakNode(elems.item(i), cvox.QueueMode.QUEUE); |
35 } | 35 } |
36 } | 36 } |
37 if (selectText.text) { | 37 if (selectText.text) { |
38 cvox.ChromeVox.tts.speak(selectText.text, 1); | 38 cvox.ChromeVox.tts.speak(selectText.text, cvox.QueueMode.QUEUE); |
39 } | 39 } |
40 } | 40 } |
41 }; | 41 }; |
42 | 42 |
43 /** | 43 /** |
44 * Unknown Result Type. This is used if we don't know what to do. | 44 * Unknown Result Type. This is used if we don't know what to do. |
45 * @constructor | 45 * @constructor |
46 * @extends {cvox.AbstractResult} | 46 * @extends {cvox.AbstractResult} |
47 */ | 47 */ |
48 cvox.UnknownResult = function() { | 48 cvox.UnknownResult = function() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 { select: SITE_LINK_SELECT }, | 93 { select: SITE_LINK_SELECT }, |
94 { select: MORE_RESULTS_SELECT }, | 94 { select: MORE_RESULTS_SELECT }, |
95 { select: MORE_RESULTS_LINK_SELECT }]; | 95 { select: MORE_RESULTS_LINK_SELECT }]; |
96 cvox.SearchResults.speakResultBySelectTexts(result, NORMAL_SELECTORS); | 96 cvox.SearchResults.speakResultBySelectTexts(result, NORMAL_SELECTORS); |
97 | 97 |
98 var DISCUSS_TITLE_SELECT = '.mas-1st-col div'; | 98 var DISCUSS_TITLE_SELECT = '.mas-1st-col div'; |
99 var DISCUSS_DATE_SELECT = '.mas-col div'; | 99 var DISCUSS_DATE_SELECT = '.mas-col div'; |
100 var discussTitles = result.querySelectorAll(DISCUSS_TITLE_SELECT); | 100 var discussTitles = result.querySelectorAll(DISCUSS_TITLE_SELECT); |
101 var discussDates = result.querySelectorAll(DISCUSS_DATE_SELECT); | 101 var discussDates = result.querySelectorAll(DISCUSS_DATE_SELECT); |
102 for (var i = 0; i < discussTitles.length; i++) { | 102 for (var i = 0; i < discussTitles.length; i++) { |
103 cvox.ChromeVox.speakNode(discussTitles.item(i), 1); | 103 cvox.ChromeVox.speakNode(discussTitles.item(i), cvox.QueueMode.QUEUE); |
104 cvox.ChromeVox.speakNode(discussDates.item(i), 1); | 104 cvox.ChromeVox.speakNode(discussDates.item(i), cvox.QueueMode.QUEUE); |
105 } | 105 } |
106 return true; | 106 return true; |
107 }; | 107 }; |
108 | 108 |
109 /* Weather Result */ | 109 /* Weather Result */ |
110 /** | 110 /** |
111 * @constructor | 111 * @constructor |
112 * @extends {cvox.AbstractResult} | 112 * @extends {cvox.AbstractResult} |
113 */ | 113 */ |
114 cvox.WeatherResult = function() { | 114 cvox.WeatherResult = function() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 { select: WEATHER_PREC_SELECT }, | 184 { select: WEATHER_PREC_SELECT }, |
185 { text: WEATHER_HUMID_INTRO }, | 185 { text: WEATHER_HUMID_INTRO }, |
186 { select: WEATHER_HUMID_SELECT }, | 186 { select: WEATHER_HUMID_SELECT }, |
187 { text: WEATHER_WIND_INTRO }, | 187 { text: WEATHER_WIND_INTRO }, |
188 { select: WEATHER_WIND_SELECT } | 188 { select: WEATHER_WIND_SELECT } |
189 ]; | 189 ]; |
190 cvox.SearchResults.speakResultBySelectTexts(result, WEATHER_SELECT_TEXTS); | 190 cvox.SearchResults.speakResultBySelectTexts(result, WEATHER_SELECT_TEXTS); |
191 | 191 |
192 var WEATHER_FORCAST_CLASS = 'wob_df'; | 192 var WEATHER_FORCAST_CLASS = 'wob_df'; |
193 var forecasts = result.getElementsByClassName(WEATHER_FORCAST_CLASS); | 193 var forecasts = result.getElementsByClassName(WEATHER_FORCAST_CLASS); |
194 cvox.ChromeVox.tts.speak(FORE_INTRO, 1); | 194 cvox.ChromeVox.tts.speak(FORE_INTRO, cvox.QueueMode.QUEUE); |
195 for (var i = 0; i < forecasts.length; i++) { | 195 for (var i = 0; i < forecasts.length; i++) { |
196 var forecast = forecasts.item(i); | 196 var forecast = forecasts.item(i); |
197 cvox.WeatherResult.speakForecast(forecast); | 197 cvox.WeatherResult.speakForecast(forecast); |
198 } | 198 } |
199 return true; | 199 return true; |
200 }; | 200 }; |
201 | 201 |
202 /* Knowledge Panel Result */ | 202 /* Knowledge Panel Result */ |
203 /** | 203 /** |
204 * @constructor | 204 * @constructor |
(...skipping 14 matching lines...) Expand all Loading... |
219 return result.querySelector(KNOP_SELECT) !== null; | 219 return result.querySelector(KNOP_SELECT) !== null; |
220 }; | 220 }; |
221 | 221 |
222 /** | 222 /** |
223 * Speak a knowledge panel search result. | 223 * Speak a knowledge panel search result. |
224 * @param {Element} result Knowledge panel result to be spoken. | 224 * @param {Element} result Knowledge panel result to be spoken. |
225 * @return {boolean} Whether or not the result was spoken. | 225 * @return {boolean} Whether or not the result was spoken. |
226 * @override | 226 * @override |
227 */ | 227 */ |
228 cvox.KnowResult.prototype.speak = function(result) { | 228 cvox.KnowResult.prototype.speak = function(result) { |
229 cvox.ChromeVox.speakNode(result, 1); | 229 cvox.ChromeVox.speakNode(result, cvox.QueueMode.QUEUE); |
230 return true; | 230 return true; |
231 }; | 231 }; |
232 | 232 |
233 /** | 233 /** |
234 * Extracts the wikipedia URL from knowledge panel. | 234 * Extracts the wikipedia URL from knowledge panel. |
235 * @param {Element} result Result to extract from. | 235 * @param {Element} result Result to extract from. |
236 * @return {?string} URL. | 236 * @return {?string} URL. |
237 * @override | 237 * @override |
238 */ | 238 */ |
239 cvox.KnowResult.prototype.getURL = function(result) { | 239 cvox.KnowResult.prototype.getURL = function(result) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 * @param {Element} result Category result to be spoken. | 397 * @param {Element} result Category result to be spoken. |
398 * @return {boolean} Whether or not the result was spoken. | 398 * @return {boolean} Whether or not the result was spoken. |
399 * @override | 399 * @override |
400 */ | 400 */ |
401 cvox.CategoryResult.prototype.speak = function(result) { | 401 cvox.CategoryResult.prototype.speak = function(result) { |
402 if (!result) { | 402 if (!result) { |
403 return false; | 403 return false; |
404 } | 404 } |
405 var LABEL_SELECT = '.rg_bb_label'; | 405 var LABEL_SELECT = '.rg_bb_label'; |
406 var label = result.querySelector(LABEL_SELECT); | 406 var label = result.querySelector(LABEL_SELECT); |
407 cvox.ChromeVox.speakNode(label, 1); | 407 cvox.ChromeVox.speakNode(label, cvox.QueueMode.QUEUE); |
408 return true; | 408 return true; |
409 }; | 409 }; |
410 | 410 |
411 /* Ad Result */ | 411 /* Ad Result */ |
412 /** | 412 /** |
413 * @constructor | 413 * @constructor |
414 * @extends {cvox.AbstractResult} | 414 * @extends {cvox.AbstractResult} |
415 */ | 415 */ |
416 cvox.AdResult = function() { | 416 cvox.AdResult = function() { |
417 }; | 417 }; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 cvox.UnknownResult, | 459 cvox.UnknownResult, |
460 cvox.NormalResult, | 460 cvox.NormalResult, |
461 cvox.KnowResult, | 461 cvox.KnowResult, |
462 cvox.WeatherResult, | 462 cvox.WeatherResult, |
463 cvox.AdResult, | 463 cvox.AdResult, |
464 cvox.CalcResult, | 464 cvox.CalcResult, |
465 cvox.GameResult, | 465 cvox.GameResult, |
466 cvox.ImageResult, | 466 cvox.ImageResult, |
467 cvox.CategoryResult | 467 cvox.CategoryResult |
468 ]; | 468 ]; |
OLD | NEW |