Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: chrome/browser/resources/access_chromevox/scripts/instant.js

Issue 6254007: Adding ChromeVox as a component extensions (enabled only for ChromeOS, for no... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/access_chromevox/scripts/instant.js
===================================================================
--- chrome/browser/resources/access_chromevox/scripts/instant.js (revision 0)
+++ chrome/browser/resources/access_chromevox/scripts/instant.js (revision 0)
@@ -0,0 +1,127 @@
+// Copyright (c) 2011 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.
+
+goog.provide('cvox.ChromeVoxInstantSearch');
+
+goog.require('cvox.ChromeVox');
+
+/**
+ * @fileoverview Script for enhancing Google Instant Search.
+ */
+cvox.ChromeVoxInstantSearch = { };
+
+/**
+ * @type {boolean}
+ */
+cvox.ChromeVoxInstantSearch.speakFirstResult = false;
+
+/**
+ * @type {number}
+ */
+cvox.ChromeVoxInstantSearch.updateDelay = 2000;
+
+/**
+ * @type {number}
+ */
+cvox.ChromeVoxInstantSearch.updateTime = new Date().getTime() +
+ cvox.ChromeVoxInstantSearch.updateDelay;
+
+/**
+ * @type {Object}
+ */
+cvox.ChromeVoxInstantSearch.previousSnippetNode = null;
+
+/**
+ * Initializes the Psychic Search script.
+ */
+cvox.ChromeVoxInstantSearch.init = function() {
+ var headID = document.getElementsByTagName('head')[0];
+ var cssNode = document.createElement('style');
+ cssNode.type = 'text/css';
+ cssNode.innerHTML = '#knavm-container {font-size: 150%}';
+ headID.appendChild(cssNode);
+
+ window.addEventListener('DOMSubtreeModified',
+ cvox.ChromeVoxInstantSearch.domSubtreeModified, true);
+ window.setTimeout(cvox.ChromeVoxInstantSearch.processUpdateQueue, 200);
+};
+
+/**
+ * Goes to the current result with the chevron arrow pointed at it and
+ * speaks it if it wasn't just spoken. Returns true if it was able to
+ * find such a result and speak it.
+ *
+ * @return {boolean} whether or not it was able to find and speak the
+ * current result on the page.
+ */
+cvox.ChromeVoxInstantSearch.gotoCurrentResult = function() {
+ var currentChevronNode = document.getElementById('knavm');
+ if (currentChevronNode) {
+ currentResultNode = currentChevronNode.parentNode;
+ if (currentResultNode != cvox.ChromeVoxInstantSearch.previousSnippetNode) {
+ var containerNode = document.getElementById('knavm-container');
+ if (containerNode != null) {
+ containerNode.id = '';
+ }
+ currentResultNode.id = 'knavm-container';
+ cvox.ChromeVoxInstantSearch.previousSnippetNode = currentResultNode;
+ var resultText = cvox.DomUtil.getText(currentResultNode);
+ // Use a setTimeout here so we don't get clobbered by the focus event.
+ window.setTimeout(function() {
+ cvox.ChromeVox.tts.speak(resultText, 0, null);
+ }, 0);
+ if (currentResultNode.previousSibling) {
+ cvox.ChromeVox.navigationManager.syncToNode(
+ currentResultNode.previousSibling);
+ } else {
+ // Sync to the top of the results section.
+ cvox.ChromeVox.navigationManager.syncToNode(
+ document.getElementById('subform_ctrl'));
+ }
+ return true;
+ }
+ }
+ return false;
+};
+
+/**
+ * Speaks when the user is moving through the results with the highlight
+ * and when the user is moving through suggestions.
+ *
+ * @param {Object} evt The DOMSubtreeModified event used to determine when
+ * there is a user action that we should respond to.
+ */
+cvox.ChromeVoxInstantSearch.domSubtreeModified = function(evt) {
+ if (cvox.ChromeVoxInstantSearch.gotoCurrentResult()) {
+ return;
+ }
+ var target = evt.target;
+ if (target.className &&
+ (target.className == 'gac_b')) {
+ var completion = target.getElementsByClassName('gac_c')[0];
+ cvox.ChromeVox.tts.speak(completion.textContent, 0, null);
+ cvox.ChromeVoxInstantSearch.speakFirstResult = true;
+ cvox.ChromeVoxInstantSearch.updateTime = new Date().getTime() +
+ cvox.ChromeVoxInstantSearch.updateDelay;
+ }
+};
+
+/**
+ * Speaks the first result when the results area is updated.
+ */
+cvox.ChromeVoxInstantSearch.processUpdateQueue = function() {
+ var resultsNode = document.getElementById('ires');
+ var results = resultsNode.getElementsByTagName('li');
+ if (results.length > 0) {
+ if ((cvox.ChromeVoxInstantSearch.speakFirstResult) &&
+ (new Date().getTime() > cvox.ChromeVoxInstantSearch.updateTime)) {
+ var resultText = cvox.DomUtil.getText(results[0]);
+ cvox.ChromeVox.tts.speak(resultText, 0, null);
+ cvox.ChromeVoxInstantSearch.speakFirstResult = false;
+ }
+ }
+ window.setTimeout(cvox.ChromeVoxInstantSearch.processUpdateQueue, 200);
+};
+
+window.setTimeout(cvox.ChromeVoxInstantSearch.init, 500);
Property changes on: chrome/browser/resources/access_chromevox/scripts/instant.js
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698