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 {Node} result Search result to be spoken. | 25 * @param {Node} 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), cvox.QueueMode.QUEUE); | 34 cvox.ChromeVox.tts.speak(cvox.DomUtil.getName(elems.item(i)), |
| 35 cvox.QueueMode.QUEUE); |
35 } | 36 } |
36 } | 37 } |
37 if (selectText.text) { | 38 if (selectText.text) { |
38 cvox.ChromeVox.tts.speak(selectText.text, cvox.QueueMode.QUEUE); | 39 cvox.ChromeVox.tts.speak(selectText.text, cvox.QueueMode.QUEUE); |
39 } | 40 } |
40 } | 41 } |
41 }; | 42 }; |
42 | 43 |
43 /** | 44 /** |
44 * Unknown Result Type. This is used if we don't know what to do. | 45 * Unknown Result Type. This is used if we don't know what to do. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 { select: SITE_LINK_SELECT }, | 90 { select: SITE_LINK_SELECT }, |
90 { select: MORE_RESULTS_SELECT }, | 91 { select: MORE_RESULTS_SELECT }, |
91 { select: MORE_RESULTS_LINK_SELECT }]; | 92 { select: MORE_RESULTS_LINK_SELECT }]; |
92 cvox.SearchResults.speakResultBySelectTexts(result, NORMAL_SELECTORS); | 93 cvox.SearchResults.speakResultBySelectTexts(result, NORMAL_SELECTORS); |
93 | 94 |
94 var DISCUSS_TITLE_SELECT = '.mas-1st-col div'; | 95 var DISCUSS_TITLE_SELECT = '.mas-1st-col div'; |
95 var DISCUSS_DATE_SELECT = '.mas-col div'; | 96 var DISCUSS_DATE_SELECT = '.mas-col div'; |
96 var discussTitles = result.querySelectorAll(DISCUSS_TITLE_SELECT); | 97 var discussTitles = result.querySelectorAll(DISCUSS_TITLE_SELECT); |
97 var discussDates = result.querySelectorAll(DISCUSS_DATE_SELECT); | 98 var discussDates = result.querySelectorAll(DISCUSS_DATE_SELECT); |
98 for (var i = 0; i < discussTitles.length; i++) { | 99 for (var i = 0; i < discussTitles.length; i++) { |
99 cvox.ChromeVox.speakNode(discussTitles.item(i), cvox.QueueMode.QUEUE); | 100 cvox.ChromeVox.tts.speak( |
100 cvox.ChromeVox.speakNode(discussDates.item(i), cvox.QueueMode.QUEUE); | 101 cvox.DomUtil.getName(discussTitles.item(i)), cvox.QueueMode.QUEUE); |
| 102 cvox.ChromeVox.tts.speak( |
| 103 cvox.DomUtil.getName(discussDates.item(i)), cvox.QueueMode.QUEUE); |
101 } | 104 } |
102 return true; | 105 return true; |
103 }; | 106 }; |
104 | 107 |
105 /* Weather Result */ | 108 /* Weather Result */ |
106 /** | 109 /** |
107 * @constructor | 110 * @constructor |
108 * @extends {cvox.AbstractResult} | 111 * @extends {cvox.AbstractResult} |
109 */ | 112 */ |
110 cvox.WeatherResult = function() { | 113 cvox.WeatherResult = function() { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 cvox.KnowResult.prototype.isType = function(result) { | 210 cvox.KnowResult.prototype.isType = function(result) { |
208 var KNOP_SELECT = '.kno-ec'; | 211 var KNOP_SELECT = '.kno-ec'; |
209 return result.querySelector(KNOP_SELECT) !== null; | 212 return result.querySelector(KNOP_SELECT) !== null; |
210 }; | 213 }; |
211 | 214 |
212 /** | 215 /** |
213 * Speak a knowledge panel search result. | 216 * Speak a knowledge panel search result. |
214 * @override | 217 * @override |
215 */ | 218 */ |
216 cvox.KnowResult.prototype.speak = function(result) { | 219 cvox.KnowResult.prototype.speak = function(result) { |
217 cvox.ChromeVox.speakNode(result, cvox.QueueMode.QUEUE); | 220 |
| 221 cvox.ChromeVox.tts.speak( |
| 222 cvox.DomUtil.getName(result), cvox.QueueMode.QUEUE); |
218 return true; | 223 return true; |
219 }; | 224 }; |
220 | 225 |
221 /** | 226 /** |
222 * Extracts the wikipedia URL from knowledge panel. | 227 * Extracts the wikipedia URL from knowledge panel. |
223 * @override | 228 * @override |
224 */ | 229 */ |
225 cvox.KnowResult.prototype.getURL = function(result) { | 230 cvox.KnowResult.prototype.getURL = function(result) { |
226 var LINK_SELECTOR = '.q'; | 231 var LINK_SELECTOR = '.q'; |
227 return cvox.SearchUtil.extractURL(result.querySelector(LINK_SELECTOR)); | 232 return cvox.SearchUtil.extractURL(result.querySelector(LINK_SELECTOR)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 /** | 373 /** |
369 * Speak a category result. | 374 * Speak a category result. |
370 * @override | 375 * @override |
371 */ | 376 */ |
372 cvox.CategoryResult.prototype.speak = function(result) { | 377 cvox.CategoryResult.prototype.speak = function(result) { |
373 if (!result) { | 378 if (!result) { |
374 return false; | 379 return false; |
375 } | 380 } |
376 var LABEL_SELECT = '.rg_bb_label'; | 381 var LABEL_SELECT = '.rg_bb_label'; |
377 var label = result.querySelector(LABEL_SELECT); | 382 var label = result.querySelector(LABEL_SELECT); |
378 cvox.ChromeVox.speakNode(label, cvox.QueueMode.QUEUE); | 383 |
| 384 cvox.ChromeVox.tts.speak( |
| 385 cvox.DomUtil.getName(label), cvox.QueueMode.QUEUE); |
379 return true; | 386 return true; |
380 }; | 387 }; |
381 | 388 |
382 /* Ad Result */ | 389 /* Ad Result */ |
383 /** | 390 /** |
384 * @constructor | 391 * @constructor |
385 * @extends {cvox.AbstractResult} | 392 * @extends {cvox.AbstractResult} |
386 */ | 393 */ |
387 cvox.AdResult = function() { | 394 cvox.AdResult = function() { |
388 }; | 395 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 cvox.UnknownResult, | 433 cvox.UnknownResult, |
427 cvox.NormalResult, | 434 cvox.NormalResult, |
428 cvox.KnowResult, | 435 cvox.KnowResult, |
429 cvox.WeatherResult, | 436 cvox.WeatherResult, |
430 cvox.AdResult, | 437 cvox.AdResult, |
431 cvox.CalcResult, | 438 cvox.CalcResult, |
432 cvox.GameResult, | 439 cvox.GameResult, |
433 cvox.ImageResult, | 440 cvox.ImageResult, |
434 cvox.CategoryResult | 441 cvox.CategoryResult |
435 ]; | 442 ]; |
OLD | NEW |