diff options
Diffstat (limited to 'chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui')
9 files changed, 0 insertions, 1450 deletions
diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/braille_overlay_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/braille_overlay_widget.js deleted file mode 100644 index cf3e5933d6b..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/braille_overlay_widget.js +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview Overlay that shows the current braille display contents, - * both as text and braille, on screen in a document. - */ - -goog.provide('cvox.BrailleOverlayWidget'); - -goog.require('cvox.ExtensionBridge'); - -/** - * @constructor - */ -cvox.BrailleOverlayWidget = function() { - /** - * Whether the widget is active in the prefs. - * @type {boolean} - * @private - */ - this.active_ = false; - /** - * @type {Element} - * @private - */ - this.containerNode_ = null; - /** - * @type {Element} - * @private - */ - this.contentNode_ = null; - /** - * @type {Element} - * @private - */ - this.brailleNode_ = null; -}; -goog.addSingletonGetter(cvox.BrailleOverlayWidget); - - -/** - * One-time initializer, to be called in a top-level document. Adds a - * listener for braille content messages from the background page. - */ -cvox.BrailleOverlayWidget.prototype.init = function() { - cvox.ExtensionBridge.addMessageListener(goog.bind( - this.onMessage_, this)); -}; - - -/** - * Sets whether the overlay is active and hides it if it is not active. - * @param {boolean} value Whether the overlay is active. - */ -cvox.BrailleOverlayWidget.prototype.setActive = function(value) { - this.active_ = value; - if (!value) { - this.hide_(); - } -}; - - -/** - * @return {boolean} Whether the overlay is active according to prefs. - */ -cvox.BrailleOverlayWidget.prototype.isActive = function() { - return this.active_; -}; - - -/** @private */ -cvox.BrailleOverlayWidget.prototype.show_ = function() { - var containerNode = this.createContainerNode_(); - this.containerNode_ = containerNode; - - var overlayNode = this.createOverlayNode_(); - containerNode.appendChild(overlayNode); - - this.contentNode_ = document.createElement('div'); - this.brailleNode_ = document.createElement('div'); - - overlayNode.appendChild(this.contentNode_); - overlayNode.appendChild(this.brailleNode_); - - document.body.appendChild(containerNode); - - window.setTimeout(function() { - containerNode.style['opacity'] = '1.0'; - }, 0); -}; - - -/** - * Hides the overlay if it is shown. - * @private - */ -// TODO(plundblad): Call when chromevox is deactivated and on some -// window focus changes. -cvox.BrailleOverlayWidget.prototype.hide_ = function() { - if (this.containerNode_) { - var containerNode = this.containerNode_; - containerNode.style.opacity = '0.0'; - window.setTimeout(function() { - document.body.removeChild(containerNode); - }, 1000); - this.containerNode_ = null; - this.contentNode_ = null; - this.brailleNode_ = null; - } -}; - - -/** - * @param {string} text The text represnting what was output on the display. - * @param {string} brailleChars The Unicode characters representing the - * braille patterns currently on the display. - * @private - */ -cvox.BrailleOverlayWidget.prototype.setContent_ = function(text, brailleChars) { - if (!this.contentNode_) { - this.show_(); - } - this.contentNode_.textContent = text; - this.brailleNode_.textContent = brailleChars; -}; - - -/** - * Create the container node for the braille overlay. - * - * @return {!Element} The new element, not yet added to the document. - * @private - */ -cvox.BrailleOverlayWidget.prototype.createContainerNode_ = function() { - var containerNode = document.createElement('div'); - containerNode.id = 'cvox-braille-overlay'; - containerNode.style['position'] = 'fixed'; - containerNode.style['top'] = '50%'; - containerNode.style['left'] = '50%'; - containerNode.style['-webkit-transition'] = 'all 0.3s ease-in'; - containerNode.style['opacity'] = '0.0'; - containerNode.style['z-index'] = '2147483647'; - containerNode.setAttribute('aria-hidden', 'true'); - return containerNode; -}; - - -/** - * Create the braille overlay. This should be a child of the node - * returned from createContainerNode. - * - * @return {!Element} The new element, not yet added to the document. - * @private - */ -cvox.BrailleOverlayWidget.prototype.createOverlayNode_ = function() { - var overlayNode = document.createElement('div'); - overlayNode.style['position'] = 'fixed'; - overlayNode.style['left'] = '40px'; - overlayNode.style['bottom'] = '20px'; - overlayNode.style['line-height'] = '1.2em'; - overlayNode.style['font-size'] = '20px'; - overlayNode.style['font-family'] = 'monospace'; - overlayNode.style['padding'] = '30px'; - overlayNode.style['min-width'] = '150px'; - overlayNode.style['color'] = '#fff'; - overlayNode.style['background-color'] = 'rgba(0, 0, 0, 0.7)'; - overlayNode.style['border-radius'] = '10px'; - return overlayNode; -}; - - -/** - * Listens for background page messages and show braille content when it - * arrives. - * @param {Object} msg Message from background page. - * @private - */ -cvox.BrailleOverlayWidget.prototype.onMessage_ = function(msg) { - if (msg['message'] == 'BRAILLE_CAPTION') { - this.setContent_(msg['text'], msg['brailleChars']); - } -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/context_menu_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/context_menu_widget.js deleted file mode 100644 index 7ea962a15a1..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/context_menu_widget.js +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview Widget presenting context menus. - */ - -goog.provide('cvox.ContextMenuWidget'); - -goog.require('cvox.ChromeVox'); -goog.require('cvox.OverlayWidget'); -goog.require('cvox.UserEventDetail'); - -var CONTEXT_MENU_ATTR = 'contextMenuActions'; -/** - * Return the list from a node or an ancestor. - * Note: If there are multiple lists, this well return the closest. - * @private - * @param {Object} node Node to extract from. - * @return {*} Extracted list. - */ -var extractMenuList_ = function(node) { - var curr = node; - while (curr !== document) { - var menuListJSON = curr.getAttribute(CONTEXT_MENU_ATTR); - if (menuListJSON) { - return JSON.parse(menuListJSON); - } - curr = curr.parentNode; - } - return null; -}; - -/** - * Gets the current element node. - * @private - * @return {Node} Current element node. - */ -var getCurrentElement_ = function() { - var currNode = cvox.ChromeVox.navigationManager.getCurrentNode(); - while (currNode.nodeType !== Node.ELEMENT_NODE) { - currNode = currNode.parentNode; - } - return currNode; -}; - -/** - * @constructor - * @extends {cvox.OverlayWidget} - */ -cvox.ContextMenuWidget = function() { - goog.base(this, ''); - this.container_ = document.createElement('div'); - - /** - * The element that triggered the ContextMenu. - * @private - * @type {Node} - */ - this.triggerElement_ = getCurrentElement_(); - - /** - * List of menu items in the context menu. - */ - this.menuList = extractMenuList_(this.triggerElement_); - - if (!this.menuList) { - console.log('No context menu found.'); - return; - } - - this.menuList.forEach(goog.bind(function(menuItem) { - if (menuItem['desc'] || menuItem['cmd']) { - var desc = menuItem['desc']; - var cmd = menuItem['cmd']; - - var menuElem = document.createElement('p'); - menuElem.id = cmd; - menuElem.textContent = desc; - menuElem.setAttribute('role', 'menuitem'); - this.container_.appendChild(menuElem); - } - }, this)); -}; -goog.inherits(cvox.ContextMenuWidget, cvox.OverlayWidget); - -/** - * @override - */ -cvox.ContextMenuWidget.prototype.show = function() { - if (this.menuList) { - goog.base(this, 'show'); - this.host_.appendChild(this.container_); - } -}; - -/** - * @override - */ -cvox.ContextMenuWidget.prototype.getNameMsg = function() { - return ['context_menu_intro']; -}; - -/** - * @override - */ -cvox.ContextMenuWidget.prototype.onKeyDown = function(evt) { - var ENTER_KEYCODE = 13; - if (evt.keyCode == ENTER_KEYCODE) { - var currentNode = cvox.ChromeVox.navigationManager.getCurrentNode(); - var cmd = currentNode.parentNode.id; - - /* Dispatch the event. */ - var detail = new cvox.UserEventDetail({customCommand: cmd}); - var userEvt = detail.createEventObject(); - this.triggerElement_.dispatchEvent(userEvt); - this.hide(); - - evt.preventDefault(); - evt.stopPropagation(); - return true; - } else { - return goog.base(this, 'onKeyDown', evt); - } -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/keyboard_help_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/keyboard_help_widget.js deleted file mode 100644 index bde0aab057d..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/keyboard_help_widget.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview Widget presenting all keyboard commands. - */ - -goog.provide('cvox.KeyboardHelpWidget'); - -goog.require('cvox.ChromeVox'); -goog.require('cvox.CommandStore'); -goog.require('cvox.KeyUtil'); -goog.require('cvox.OverlayWidget'); - -/** - * @constructor - * @extends {cvox.OverlayWidget} - */ -cvox.KeyboardHelpWidget = function() { - goog.base(this, ''); - this.container_ = document.createElement('div'); - var list = []; - var callbacks = []; - var keymap = cvox.ChromeVoxKbHandler.handlerKeyMap; - - keymap.bindings().forEach(goog.bind(function(pair) { - var command = pair.command; - var keySeq = pair.sequence; - var message = command; - try { - var id = cvox.CommandStore.messageForCommand(command); - if (!id) { - return; - } - message = Msgs.getMsg(id); - } catch (e) { - // TODO(dtseng): We have some commands that don't have valid message id's. - } - - var commandElement = document.createElement('p'); - commandElement.id = command; - commandElement.setAttribute('role', 'menuitem'); - commandElement.textContent = - message + ' - ' + cvox.KeyUtil.keySequenceToString(keySeq, true); - this.container_.appendChild(commandElement); - }, this)); -}; -goog.inherits(cvox.KeyboardHelpWidget, cvox.OverlayWidget); -goog.addSingletonGetter(cvox.KeyboardHelpWidget); - - -/** - * @override - */ -cvox.KeyboardHelpWidget.prototype.show = function() { - goog.base(this, 'show'); - this.host_.appendChild(this.container_); -}; - - -/** - * @override - */ -cvox.KeyboardHelpWidget.prototype.getNameMsg = function() { - return ['keyboard_help_intro']; -}; - -/** - * @override - */ -cvox.KeyboardHelpWidget.prototype.onKeyDown = function(evt) { - if (evt.keyCode == 13) { // Enter - var currentCommand = - cvox.ChromeVox.navigationManager.getCurrentNode().parentNode.id; - this.hide(); - cvox.ChromeVoxEventSuspender.withSuspendedEvents( - cvox.ChromeVoxUserCommands.commands[currentCommand])(); - evt.preventDefault(); - evt.stopPropagation(); - return true; - } else { - return goog.base(this, 'onKeyDown', evt); - } -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/node_search_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/node_search_widget.js deleted file mode 100644 index 93adad76da4..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/node_search_widget.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview A search Widget presenting a list of nodes with the ability - * to sync selection when chosen. - */ - -goog.provide('cvox.NodeSearchWidget'); - -goog.require('cvox.ChromeVox'); -goog.require('cvox.DomUtil'); -goog.require('cvox.SearchWidget'); - - -/** - * @constructor - * @param {string} typeMsg A message id identifying the type of items - * contained in the list. - * @param {?function(Array<Node>)} predicate A predicate; if null, no predicate - * applies. - * @extends {cvox.SearchWidget} - */ -cvox.NodeSearchWidget = function(typeMsg, predicate) { - this.typeMsg_ = typeMsg; - this.predicate_ = predicate; - goog.base(this); -}; -goog.inherits(cvox.NodeSearchWidget, cvox.SearchWidget); - - -/** - * @override - */ -cvox.NodeSearchWidget.prototype.getNameMsg = function() { - return ['choice_widget_name', [Msgs.getMsg(this.typeMsg_)]]; -}; - - -/** - * @override - */ -cvox.NodeSearchWidget.prototype.getHelpMsg = function() { - return 'choice_widget_help'; -}; - - -/** - * @override - */ -cvox.NodeSearchWidget.prototype.getPredicate = function() { - return this.predicate_; -}; - - -/** - * Shows a list generated dynamic satisfying some predicate. - * @param {string} typeMsg The message id of the type contained in nodes. - * @param {function(Array<Node>)} predicate The predicate. - * @return {cvox.NodeSearchWidget} The widget. - */ -cvox.NodeSearchWidget.create = function(typeMsg, predicate) { - return new cvox.NodeSearchWidget(typeMsg, predicate); -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/overlay_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/overlay_widget.js deleted file mode 100644 index d40c7af406b..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/overlay_widget.js +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview A widget hosting an HTML snippet. - */ - -goog.provide('cvox.OverlayWidget'); - -goog.require('cvox.DomUtil'); -goog.require('cvox.SearchWidget'); - - -/** - * @param {string} snippet The HTML snippet to render. - * @constructor - * @extends {cvox.SearchWidget} - */ -cvox.OverlayWidget = function(snippet) { - goog.base(this); - this.snippet_ = snippet; -}; -goog.inherits(cvox.OverlayWidget, cvox.SearchWidget); - - -/** - * @override - */ -cvox.OverlayWidget.prototype.show = function() { - goog.base(this, 'show'); - var host = document.createElement('DIV'); - host.innerHTML = this.snippet_; - - // Position the overlay over the current ChromeVox selection. - var hitPoint = cvox.DomUtil.elementToPoint( - cvox.ChromeVox.navigationManager.getCurrentNode()); - host.style.position = 'absolute'; - host.style.left = hitPoint.x; - host.style.top = hitPoint.y; - - document.body.appendChild(host); - cvox.ChromeVox.navigationManager.updateSelToArbitraryNode(host); - this.host_ = host; -}; - - -/** - * @override - */ -cvox.OverlayWidget.prototype.hide = function(opt_noSync) { - this.host_.remove(); - goog.base(this, 'hide'); -}; - - -/** - * @override - */ -cvox.OverlayWidget.prototype.onKeyDown = function(evt) { - // Allow the base class to handle all keys first. - goog.base(this, 'onKeyDown', evt); - - // Do not interfere with any key that exits the widget. - if (evt.keyCode == 13 || evt.keyCode == 27) { // Enter or escape. - return true; - } - - // Bound navigation within the snippet for any other key. - var r = cvox.ChromeVox.navigationManager.isReversed(); - if (!cvox.DomUtil.isDescendantOfNode( - cvox.ChromeVox.navigationManager.getCurrentNode(), this.host_)) { - if (r) { - cvox.ChromeVox.navigationManager.syncToBeginning(); - } else { - cvox.ChromeVox.navigationManager.updateSelToArbitraryNode(this.host_); - } - this.onNavigate(); - cvox.ChromeVox.navigationManager.speakDescriptionArray( - cvox.ChromeVox.navigationManager.getDescription(), - cvox.QueueMode.FLUSH, null); - } -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/search_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/search_widget.js deleted file mode 100644 index 410813aaed0..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/search_widget.js +++ /dev/null @@ -1,540 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview JavaScript for poppup up a search widget and performing - * search within a page. - */ - -goog.provide('cvox.SearchWidget'); - -goog.require('cvox.AbstractEarcons'); -goog.require('cvox.ApiImplementation'); -goog.require('cvox.ChromeVox'); -goog.require('cvox.CursorSelection'); -goog.require('cvox.NavigationManager'); -goog.require('cvox.SpokenMessages'); -goog.require('cvox.Widget'); - - -/** - * Initializes the search widget. - * @constructor - * @extends {cvox.Widget} - */ -cvox.SearchWidget = function() { - /** - * @type {Element} - * @private - */ - this.containerNode_ = null; - - /** - * @type {Element} - * @private - */ - this.txtNode_ = null; - - /** - * @type {string} - * @const - * @private - */ - this.PROMPT_ = 'Search:'; - - /** - * @type {boolean} - * @private - */ - this.caseSensitive_ = false; - - /** - * @type {boolean} - * @private - */ - this.hasMatch_ = false; - goog.base(this); -}; -goog.inherits(cvox.SearchWidget, cvox.Widget); -goog.addSingletonGetter(cvox.SearchWidget); - - -/** - * @override - */ -cvox.SearchWidget.prototype.show = function() { - goog.base(this, 'show'); - this.active = true; - this.hasMatch_ = false; - cvox.ChromeVox.navigationManager.setGranularity( - cvox.NavigationShifter.GRANULARITIES.OBJECT, true, false); - - // Always start search forward. - cvox.ChromeVox.navigationManager.setReversed(false); - - // During profiling, NavigationHistory was found to have a serious performance - // impact on search. - this.focusRecovery_ = cvox.ChromeVox.navigationManager.getFocusRecovery(); - cvox.ChromeVox.navigationManager.setFocusRecovery(false); - - var containerNode = this.createContainerNode_(); - this.containerNode_ = containerNode; - - var overlayNode = this.createOverlayNode_(); - containerNode.appendChild(overlayNode); - - var promptNode = document.createElement('span'); - promptNode.innerHTML = this.PROMPT_; - overlayNode.appendChild(promptNode); - - this.txtNode_ = this.createTextAreaNode_(); - - overlayNode.appendChild(this.txtNode_); - - document.body.appendChild(containerNode); - - this.txtNode_.focus(); - - window.setTimeout(function() { - containerNode.style['opacity'] = '1.0'; - }, 0); -}; - - -/** - * @override - */ -cvox.SearchWidget.prototype.hide = function(opt_noSync) { - if (this.isActive()) { - var containerNode = this.containerNode_; - containerNode.style.opacity = '0.0'; - window.setTimeout(function() { - document.body.removeChild(containerNode); - }, 1000); - this.txtNode_ = null; - cvox.SearchWidget.containerNode = null; - cvox.ChromeVox.navigationManager.setFocusRecovery(this.focusRecovery_); - this.active = false; - } - - cvox.$m('choice_widget_exited'). - andPause(). - andMessage(this.getNameMsg()). - speakFlush(); - - if (!this.hasMatch_ || !opt_noSync) { - cvox.ChromeVox.navigationManager.updateSelToArbitraryNode( - this.initialNode); - } - cvox.ChromeVoxEventSuspender.withSuspendedEvents(goog.bind( - cvox.ChromeVox.navigationManager.syncAll, - cvox.ChromeVox.navigationManager))(true); - cvox.ChromeVox.navigationManager.speakDescriptionArray( - cvox.ChromeVox.navigationManager.getDescription(), - cvox.QueueMode.QUEUE, - null, - cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); - - // Update on Braille too. - // TODO: Use line granularity in search so we can simply call - // cvox.ChromeVox.navigationManager.getBraille().write() instead. - var text = this.textFromCurrentDescription_(); - cvox.ChromeVox.braille.write(new cvox.NavBraille({ - text: text, - startIndex: 0, - endIndex: 0 - })); - - goog.base(this, 'hide', true); -}; - - -/** - * @override - */ -cvox.SearchWidget.prototype.getNameMsg = function() { - return ['search_widget_intro']; -}; - - -/** - * @override - */ -cvox.SearchWidget.prototype.getHelpMsg = function() { - return 'search_widget_intro_help'; -}; - - -/** - * @override - */ -cvox.SearchWidget.prototype.onKeyDown = function(evt) { - if (!this.isActive()) { - return false; - } - var searchStr = this.txtNode_.value; - if (evt.keyCode == 8) { // Backspace - if (searchStr.length > 0) { - searchStr = searchStr.substring(0, searchStr.length - 1); - this.txtNode_.value = searchStr; - this.beginSearch_(searchStr); - } else { - cvox.ChromeVox.navigationManager.updateSelToArbitraryNode( - this.initialNode); - cvox.ChromeVox.navigationManager.syncAll(); - } - } else if (evt.keyCode == 40) { // Down arrow - this.next_(searchStr, false); - } else if (evt.keyCode == 38) { // Up arrow - this.next_(searchStr, true); - } else if (evt.keyCode == 13) { // Enter - this.hide(true); - } else if (evt.keyCode == 27) { // Escape - this.hide(false); - } else if (evt.ctrlKey && evt.keyCode == 67) { // ctrl + c - this.toggleCaseSensitivity_(); - } else { - return goog.base(this, 'onKeyDown', evt); - } - evt.preventDefault(); - evt.stopPropagation(); - return true; -}; - - -/** - * Adds the letter the user typed to the search string and updates the search. - * @override - */ -cvox.SearchWidget.prototype.onKeyPress = function(evt) { - if (!this.isActive()) { - return false; - } - - this.txtNode_.value += String.fromCharCode(evt.charCode); - var searchStr = this.txtNode_.value; - this.beginSearch_(searchStr); - evt.preventDefault(); - evt.stopPropagation(); - return true; -}; - - -/** - * Called when navigation occurs. - * Override this method to react to navigation caused by user input. - */ -cvox.SearchWidget.prototype.onNavigate = function() { -}; - - -/** - * Gets the predicate to apply to every search. - * @return {?function(Array<Node>)} A predicate; if null, no predicate applies. - */ -cvox.SearchWidget.prototype.getPredicate = function() { - return null; -}; - - -/** - * Goes to the next or previous result. For use in AndroidVox. - * @param {boolean=} opt_reverse Whether to find the next result in reverse. - * @return {Array<cvox.NavDescription>} The next result. - */ -cvox.SearchWidget.prototype.nextResult = function(opt_reverse) { - if (!this.isActive()) { - return null; - } - var searchStr = this.txtNode_.value; - return this.next_(searchStr, opt_reverse); -}; - - -/** - * Create the container node for the search overlay. - * - * @return {!Element} The new element, not yet added to the document. - * @private - */ -cvox.SearchWidget.prototype.createContainerNode_ = function() { - var containerNode = document.createElement('div'); - containerNode.id = 'cvox-search'; - containerNode.style['position'] = 'fixed'; - containerNode.style['top'] = '50%'; - containerNode.style['left'] = '50%'; - containerNode.style['-webkit-transition'] = 'all 0.3s ease-in'; - containerNode.style['opacity'] = '0.0'; - containerNode.style['z-index'] = '2147483647'; - containerNode.setAttribute('aria-hidden', 'true'); - return containerNode; -}; - - -/** - * Create the search overlay. This should be a child of the node - * returned from createContainerNode. - * - * @return {!Element} The new element, not yet added to the document. - * @private - */ -cvox.SearchWidget.prototype.createOverlayNode_ = function() { - var overlayNode = document.createElement('div'); - overlayNode.style['position'] = 'relative'; - overlayNode.style['left'] = '-50%'; - overlayNode.style['top'] = '-40px'; - overlayNode.style['line-height'] = '1.2em'; - overlayNode.style['font-size'] = '20px'; - overlayNode.style['padding'] = '30px'; - overlayNode.style['min-width'] = '150px'; - overlayNode.style['color'] = '#fff'; - overlayNode.style['background-color'] = 'rgba(0, 0, 0, 0.7)'; - overlayNode.style['border-radius'] = '10px'; - return overlayNode; -}; - - -/** - * Create the text area node. This should be the child of the node - * returned from createOverlayNode. - * - * @return {!Element} The new element, not yet added to the document. - * @private - */ -cvox.SearchWidget.prototype.createTextAreaNode_ = function() { - var textNode = document.createElement('textarea'); - textNode.setAttribute('aria-hidden', 'true'); - textNode.setAttribute('rows', '1'); - textNode.style['color'] = '#fff'; - textNode.style['background-color'] = 'rgba(0, 0, 0, 0.7)'; - textNode.style['vertical-align'] = 'middle'; - textNode.addEventListener('textInput', - this.handleSearchChanged_, false); - return textNode; -}; - - -/** - * Toggles whether or not searches are case sensitive. - * @private - */ -cvox.SearchWidget.prototype.toggleCaseSensitivity_ = function() { - if (this.caseSensitive_) { - cvox.SearchWidget.caseSensitive_ = false; - cvox.ChromeVox.tts.speak( - Msgs.getMsg('ignoring_case'), - cvox.QueueMode.FLUSH, null); - } else { - this.caseSensitive_ = true; - cvox.ChromeVox.tts.speak( - Msgs.getMsg('case_sensitive'), - cvox.QueueMode.FLUSH, null); - } -}; - - -/** - * Gets the next result. - * - * @param {string} searchStr The text to search for. - * @return {Array<cvox.NavDescription>} The next result, in the form of - * NavDescriptions. - * @private - */ -cvox.SearchWidget.prototype.getNextResult_ = function(searchStr) { - var r = cvox.ChromeVox.navigationManager.isReversed(); - if (!this.caseSensitive_) { - searchStr = searchStr.toLowerCase(); - } - - cvox.ChromeVox.navigationManager.setGranularity( - cvox.NavigationShifter.GRANULARITIES.OBJECT, true, false); - - do { - if (this.getPredicate()) { - var retNode = this.getPredicate()(cvox.DomUtil.getAncestors( - cvox.ChromeVox.navigationManager.getCurrentNode())); - if (!retNode) { - continue; - } - } - - var descriptions = cvox.ChromeVox.navigationManager.getDescription(); - for (var i = 0; i < descriptions.length; i++) { - var targetStr = this.caseSensitive_ ? descriptions[i].text : - descriptions[i].text.toLowerCase(); - var targetIndex = targetStr.indexOf(searchStr); - - // Surround search hit with pauses. - if (targetIndex != -1 && targetStr.length > searchStr.length) { - descriptions[i].text = - cvox.DomUtil.collapseWhitespace( - targetStr.substring(0, targetIndex)) + - ', ' + searchStr + ', ' + - targetStr.substring(targetIndex + searchStr.length); - descriptions[i].text = - cvox.DomUtil.collapseWhitespace(descriptions[i].text); - } - if (targetIndex != -1) { - return descriptions; - } - } - cvox.ChromeVox.navigationManager.setReversed(r); - } while (cvox.ChromeVox.navigationManager.navigate(true, - cvox.NavigationShifter.GRANULARITIES.OBJECT)); -}; - - -/** - * Performs the search starting from the initial position. - * - * @param {string} searchStr The text to search for. - * @private - */ -cvox.SearchWidget.prototype.beginSearch_ = function(searchStr) { - var result = this.getNextResult_(searchStr); - this.outputSearchResult_(result, searchStr); - this.onNavigate(); -}; - - -/** - * Goes to the next (directed) matching result. - * - * @param {string} searchStr The text to search for. - * @param {boolean=} opt_reversed The direction. - * @return {Array<cvox.NavDescription>} The next result. - * @private - */ -cvox.SearchWidget.prototype.next_ = function(searchStr, opt_reversed) { - cvox.ChromeVox.navigationManager.setReversed(!!opt_reversed); - - var success = false; - if (this.getPredicate()) { - success = cvox.ChromeVox.navigationManager.findNext( - /** @type {function(Array<Node>)} */ (this.getPredicate())); - // TODO(dtseng): findNext always seems to point direction forward! - cvox.ChromeVox.navigationManager.setReversed(!!opt_reversed); - if (!success) { - cvox.ChromeVox.navigationManager.syncToBeginning(); - cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.WRAP); - success = true; - } - } else { - success = cvox.ChromeVox.navigationManager.navigate(true); - } - var result = success ? this.getNextResult_(searchStr) : null; - this.outputSearchResult_(result, searchStr); - this.onNavigate(); - return result; -}; - - -/** - * Given a range corresponding to a search result, highlight the result, - * speak it, focus the node if applicable, and speak some instructions - * at the end. - * - * @param {Array<cvox.NavDescription>} result The description of the next - * result. If null, no more results were found and an error will be presented. - * @param {string} searchStr The text to search for. - * @private - */ -cvox.SearchWidget.prototype.outputSearchResult_ = function(result, searchStr) { - cvox.ChromeVox.tts.stop(); - if (!result) { - cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.WRAP); - this.hasMatch_ = false; - return; - } - - this.hasMatch_ = true; - - // Speak the modified description and some instructions. - cvox.ChromeVoxEventSuspender.withSuspendedEvents(goog.bind( - cvox.ChromeVox.navigationManager.syncAll, - cvox.ChromeVox.navigationManager))(true); - - cvox.ChromeVox.navigationManager.speakDescriptionArray( - result, - cvox.QueueMode.FLUSH, - null, - cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); - - cvox.ChromeVox.tts.speak(Msgs.getMsg('search_help_item'), - cvox.QueueMode.QUEUE, - cvox.AbstractTts.PERSONALITY_ANNOTATION); - - // Output to Braille. - // TODO: Use line granularity in search so we can simply call - // cvox.ChromeVox.navigationManager.getBraille().write() instead. - this.outputSearchResultToBraille_(searchStr); -}; - - -/** - * Writes the currently selected search result to Braille, with description - * text formatted for Braille display instead of speech. - * - * @param {string} searchStr The text to search for. - * Should be in navigation manager's description. - * @private - */ -cvox.SearchWidget.prototype.outputSearchResultToBraille_ = function(searchStr) { - // Construct object we can pass to Chromevox.braille to write. - // We concatenate the text together and set the "cursor" - // position to be at the end of search query string - // (consistent with editing text in a field). - var text = this.textFromCurrentDescription_(); - var targetStr = this.caseSensitive_ ? text : - text.toLowerCase(); - searchStr = this.caseSensitive_ ? searchStr : searchStr.toLowerCase(); - var targetIndex = targetStr.indexOf(searchStr); - if (targetIndex == -1) { - console.log('Search string not in result when preparing for Braille.'); - return; - } - - // Mark the string as a search result by adding a prefix - // and adjust the targetIndex accordingly. - var oldLength = text.length; - text = Msgs.getMsg('mark_as_search_result_brl', [text]); - var newLength = text.length; - targetIndex += (newLength - oldLength); - - // Write to Braille with cursor at the end of the search hit. - cvox.ChromeVox.braille.write(new cvox.NavBraille({ - text: text, - startIndex: (targetIndex + searchStr.length), - endIndex: (targetIndex + searchStr.length) - })); -}; - - -/** - * Returns the concatenated text from the current description in the - * NavigationManager. - * TODO: May not be needed after we just simply use line granularity in search, - * since this is mostly used to display the long search result descriptions on - * Braille. - * @return {string} The concatenated text from the current description. - * @private - */ -cvox.SearchWidget.prototype.textFromCurrentDescription_ = function() { - var descriptions = cvox.ChromeVox.navigationManager.getDescription(); - var text = ''; - for (var i = 0; i < descriptions.length; i++) { - text += descriptions[i].text + ' '; - } - return text; -}; - -/** - * @param {Object} evt The onInput event that the function is handling. - * @private - */ -cvox.SearchWidget.prototype.handleSearchChanged_ = function(evt) { - var searchStr = evt.target.value + evt.data; - cvox.SearchWidget.prototype.beginSearch_(searchStr); -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/select_widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/select_widget.js deleted file mode 100644 index b2decc2bf68..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/select_widget.js +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview A widget hosting an HTML <select> element. - * In most cases, the browser's native key-driven usage model works for user - * interaction and manipulation of a <select>. However, on platforms like Mac - * OS X where <select> elements get their own renderer, users can still interact - * with <select> elements via a ChromeVox overlay/context widget. - */ - -goog.provide('cvox.SelectWidget'); - - -goog.require('cvox.OverlayWidget'); - - -/** - * @param {Node} node The select node. - * @constructor - * @extends {cvox.OverlayWidget} - */ -cvox.SelectWidget = function(node) { - goog.base(this, ''); - this.selectNode_ = node; -}; -goog.inherits(cvox.SelectWidget, cvox.OverlayWidget); - - -/** - * @override - */ -cvox.SelectWidget.prototype.show = function() { - goog.base(this, 'show'); - var container = document.createElement('div'); - container.setAttribute('role', 'menu'); - for (var i = 0, item = null; item = this.selectNode_.options[i]; i++) { - var newItem = document.createElement('p'); - newItem.innerHTML = item.innerHTML; - newItem.id = i; - newItem.setAttribute('role', 'menuitem'); - container.appendChild(newItem); - } - this.host_.appendChild(container); - var currentSelection = this.selectNode_.selectedIndex; - if (typeof(currentSelection) == 'number') { - cvox.ChromeVox.syncToNode(container.children[currentSelection], true); - } -}; - - -/** - * @override - */ -cvox.SelectWidget.prototype.hide = function(opt_noSync) { - var evt = document.createEvent('Event'); - evt.initEvent('change', false, false); - this.selectNode_.dispatchEvent(evt); - goog.base(this, 'hide', true); -}; - - -/** - * @override - */ -cvox.SelectWidget.prototype.onNavigate = function() { - var self = this; - cvox.ChromeVoxEventSuspender.withSuspendedEvents(function() { - var selectedIndex = - cvox.ChromeVox.navigationManager.getCurrentNode().parentNode.id; - self.selectNode_.selectedIndex = selectedIndex; - })(); -}; - - -/** - * @override - */ -cvox.SelectWidget.prototype.getNameMsg = function() { - return ['role_menu']; -}; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/spoken_messages.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/spoken_messages.js deleted file mode 100644 index dc72579c805..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/spoken_messages.js +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview Useful abstraction when speaking messages. - * - * Usage: - * $m('role_link') - * .andPause() - * .andMessage('role_forms') - * .speakFlush(); - * - */ - -goog.provide('cvox.SpokenMessage'); -goog.provide('cvox.SpokenMessages'); - -goog.require('cvox.AbstractTts'); -goog.require('cvox.ChromeVox'); - -/** - * @constructor - */ -cvox.SpokenMessage = function() { - /** @type {Array} */ - this.id = null; -}; - -/** - * @type {Array} - */ -cvox.SpokenMessages.messages = []; - -/** - * Speaks the message chain and interrupts any on-going speech. - */ -cvox.SpokenMessages.speakFlush = function() { - cvox.SpokenMessages.speak(cvox.QueueMode.FLUSH); -}; - -/** - * Speak the message chain. - * @param {cvox.QueueMode} mode The speech queue mode. - */ -cvox.SpokenMessages.speak = function(mode) { - for (var i = 0; i < cvox.SpokenMessages.messages.length; ++i) { - var message = cvox.SpokenMessages.messages[i]; - - // An invalid message format. - if (!message || !message.id) - throw 'Invalid message received.'; - - var finalText = Msgs.getMsg.apply(Msgs, message.id); - cvox.ChromeVox.tts.speak(finalText, mode, - cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); - - // Always queue after the first message. - mode = cvox.QueueMode.QUEUE; - } - - cvox.SpokenMessages.messages = []; -}; - -/** - * Adds a message. - * @param {string|Array} messageId The id of the message. - * @return {Object} This object, useful for chaining. - */ -cvox.SpokenMessages.andMessage = function(messageId) { - var newMessage = new cvox.SpokenMessage(); - newMessage.id = typeof(messageId) == 'string' ? [messageId] : messageId; - cvox.SpokenMessages.messages.push(newMessage); - return cvox.SpokenMessages; -}; - -/** - * Pauses after the message, with an appropriate marker. - * @return {Object} This object, useful for chaining. - */ -cvox.SpokenMessages.andPause = function() { - return cvox.SpokenMessages.andMessage('pause'); -}; - -/** - * Adds a message. - * @param {string|Array} messageId The id of the message. - * @return {Object} This object, useful for chaining. - */ -cvox.$m = cvox.SpokenMessages.andMessage; diff --git a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/widget.js b/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/widget.js deleted file mode 100644 index 66a18e247a8..00000000000 --- a/chromium/chrome/browser/resources/chromeos/chromevox/chromevox/injected/ui/widget.js +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2014 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. - -/** - * @fileoverview Base class for all ChromeVox widgets. - * - * Widgets are keyboard driven and modal mediums for ChromeVox to expose - * additional features such as lists, interactive search, or grids. - */ - -goog.provide('cvox.Widget'); - -goog.require('cvox.AbstractEarcons'); -goog.require('cvox.ApiImplementation'); -goog.require('cvox.ChromeVox'); -goog.require('cvox.SpokenMessages'); - -/** - * Keeps a reference to a currently or formerly active widget. This enforces - * the singleton nature of widgets. - * @type {cvox.Widget} - * @private - */ -cvox.Widget.ref_; - - -/** - * @constructor - */ -cvox.Widget = function() { - /** - * @type {boolean} - * @protected - */ - this.active = false; - - - /** - * Keeps a reference to a node which should receive focus once a widget hides. - * @type {Node} - * @protected - */ - this.initialFocus = null; - - /** - * Keeps a reference to a node which should receive selection once a widget - * hides. - * @type {Node} - * @protected - */ - this.initialNode = null; - - // Checks to see if there is a current widget in use. - if (!cvox.Widget.ref_ || !cvox.Widget.ref_.isActive()) { - cvox.Widget.ref_ = this; - } -}; - - -/** - * Returns whether or not the widget is active. - * @return {boolean} Whether the widget is active. - */ -cvox.Widget.prototype.isActive = function() { - return this.active; -}; - - -/** - * Visual/aural display of this widget. - */ -cvox.Widget.prototype.show = function() { - if (this.isActive()) { - // Only one widget should be shown at any given time. - this.hide(true); - } - this.onKeyDown = goog.bind(this.onKeyDown, this); - this.onKeyPress = goog.bind(this.onKeyPress, this); - window.addEventListener('keydown', this.onKeyDown, true); - window.addEventListener('keypress', this.onKeyPress, true); - - this.initialNode = - cvox.ChromeVox.navigationManager.getCurrentNode(); - this.initialFocus = document.activeElement; - - // Widgets do not respond to sticky key. - cvox.ChromeVox.stickyOverride = false; - - if (this.getNameMsg() && this.getHelpMsg()) { - cvox.$m(this.getNameMsg()). - andPause(). - andMessage(this.getHelpMsg()). - speakFlush(); - } - cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.OBJECT_OPEN); - - this.active = true; -}; - - -/** - * Visual/aural hide of this widget. - * @param {boolean=} opt_noSync Whether to attempt to sync to the node before - * this widget was first shown. If left unspecified or false, an attempt to sync - * will be made. - */ -cvox.Widget.prototype.hide = function(opt_noSync) { - window.removeEventListener('keypress', this.onKeyPress, true); - window.removeEventListener('keydown', this.onKeyDown, true); - cvox.ChromeVox.stickyOverride = null; - - cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.OBJECT_CLOSE); - if (!opt_noSync) { - this.initialNode = this.initialNode.nodeType == 1 ? - this.initialNode : this.initialNode.parentNode; - cvox.ApiImplementation.syncToNode(this.initialNode, - true, - cvox.QueueMode.QUEUE); - } - - this.active = false; -}; - - -/** - * Toggle between showing and hiding. - */ -cvox.Widget.prototype.toggle = function() { - if (this.isActive()) { - this.hide(); - } else { - this.show(); - } -}; - - -/** - * The name of the widget. - * @return {!Array} The message id referencing the name of the widget in an - * array argument form passable to Msgs.getMsg.apply. - */ -cvox.Widget.prototype.getNameMsg = goog.abstractMethod; - - -/** - * Gets the help message for the widget. - * The help message succintly describes how to use the widget. - * @return {string} The message id referencing the help for the widget. - */ -cvox.Widget.prototype.getHelpMsg = goog.abstractMethod; - - -/** - * The default widget key down handler. - * - * @param {Event} evt The keyDown event. - * @return {boolean} Whether or not the event was handled. - * - * @protected - */ -cvox.Widget.prototype.onKeyDown = function(evt) { - if (evt.keyCode == 27) { // Escape - this.hide(); - evt.preventDefault(); - return true; - } else if (evt.keyCode == 9) { // Tab - this.hide(); - return true; - } else if (evt.keyCode == 17) { - cvox.ChromeVox.tts.stop(); - } - - evt.stopPropagation(); - return true; -}; - - -/** - * The default widget key press handler. - * - * @param {Event} evt The keyPress event. - * @return {boolean} Whether or not the event was handled. - * - * @protected - */ -cvox.Widget.prototype.onKeyPress = function(evt) { - return false; -}; -/** - * @return {boolean} True if any widget is currently active. - */ -cvox.Widget.isActive = function() { - return (cvox.Widget.ref_ && cvox.Widget.ref_.isActive()) || false; -}; |