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

Unified Diff: chrome/browser/resources/access_chromevox/common/focus_util.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/common/focus_util.js
===================================================================
--- chrome/browser/resources/access_chromevox/common/focus_util.js (revision 0)
+++ chrome/browser/resources/access_chromevox/common/focus_util.js (revision 0)
@@ -0,0 +1,87 @@
+// 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.
+
+/**
+ * @fileoverview A collection of JavaScript utilities used to manage focus
+ * within a document.
+ */
+
+
+goog.provide('cvox.FocusUtil');
+
+
+/**
+ * Utilities for managing focus.
+ * @constructor
+ */
+cvox.FocusUtil = function() {
+};
+
+/**
+ * Maps whether an input element of specified type accepts text selection or
+ * not. True if the element does accept text selection, false if it does not.
+ * This can be used to determine whether a visitor to that element should
+ * provide interactive text editing to the user.
+ * From the W3C table of possible type keywords:
+ * http://www.w3.org/TR/html5/the-input-element.html#attr-input-type
+ * @type {Object}
+ */
+cvox.FocusUtil.INPUT_TYPE_ACCEPTS_SELECTION_TABLE = {
+ 'hidden' : false,
+ 'text' : true,
+ 'search' : true,
+ 'tel' : true,
+ 'url' : true,
+ 'email' : true,
+ 'password' : true,
+ 'datetime' : false,
+ 'date' : false,
+ 'month' : false,
+ 'week' : false,
+ 'time' : false,
+ 'datetime-local' : false,
+ 'number' : false,
+ 'range' : false,
+ 'color' : false,
+ 'checkbox' : false,
+ 'radio' : false,
+ 'file' : false,
+ 'submit' : false,
+ 'image' : false,
+ 'reset' : false,
+ 'button' : false
+};
+
+/**
+ * Checks if the currently focused element is a field that accepts text input
+ * (This can include text fields and selectors)
+ *
+ * @return {boolean} True if the currently focused element accepts text input.
+ */
+cvox.FocusUtil.isFocusInTextInputField = function() {
+ // TODO(rshearer): Check all editable text fields here, including
+ // aria role=textbox.
+
+ var activeElement = document.activeElement;
+
+ if (activeElement.isContentEditable) {
+ return true;
+ }
+
+ if ((activeElement.tagName === 'INPUT') ||
+ (activeElement.tagName === 'TEXTAREA') ||
+ (activeElement.tagName === 'SELECT')) {
+
+ if (activeElement.getAttribute('readOnly') == 'true') {
+ return false;
+ } else if (! activeElement.hasAttribute('type')) {
+ return true;
+ } else {
+ var activeType = activeElement.getAttribute('type').toLowerCase();
+
+ return cvox.FocusUtil.INPUT_TYPE_ACCEPTS_SELECTION_TABLE[activeType];
+ }
+ }
+ return false;
+};
Property changes on: chrome/browser/resources/access_chromevox/common/focus_util.js
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698