| Index: chrome/browser/resources/access_chromevox/common/selection_walker.js
|
| ===================================================================
|
| --- chrome/browser/resources/access_chromevox/common/selection_walker.js (revision 0)
|
| +++ chrome/browser/resources/access_chromevox/common/selection_walker.js (revision 0)
|
| @@ -0,0 +1,103 @@
|
| +// 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 JavaScript class for walking the page using WebKit
|
| + * selection.
|
| + */
|
| +
|
| +
|
| +goog.provide('cvox.SelectionWalker');
|
| +
|
| +goog.require('cvox.SelectionUtil');
|
| +goog.require('cvox.TraverseContent');
|
| +
|
| +/**
|
| + * @constructor
|
| + */
|
| +cvox.SelectionWalker = function() {
|
| + this.traverseContent = new cvox.TraverseContent();
|
| + this.currentGranularity = 0;
|
| +};
|
| +
|
| +/**
|
| + * @type {Object}
|
| + */
|
| +cvox.SelectionWalker.GRANULARITY_LEVELS = new Array('paragraph',
|
| + 'sentence', 'word', 'character');
|
| +
|
| +/**
|
| + * Decreases the granularity.
|
| + * @return {boolean} Returns true if the granularity was changed successfully.
|
| + */
|
| +cvox.SelectionWalker.prototype.lessGranular = function() {
|
| + this.currentGranularity = this.currentGranularity - 1;
|
| + if (this.currentGranularity < 0) {
|
| + this.currentGranularity = 0;
|
| + return false;
|
| + }
|
| + return true;
|
| +};
|
| +
|
| +/**
|
| + * Increases the granularity.
|
| + * @return {boolean} Returns true if the granularity was changed successfully.
|
| + */
|
| +cvox.SelectionWalker.prototype.moreGranular = function() {
|
| + this.currentGranularity = this.currentGranularity + 1;
|
| + var max = cvox.SelectionWalker.GRANULARITY_LEVELS.length - 1;
|
| + if (this.currentGranularity > max) {
|
| + this.currentGranularity = max;
|
| + return false;
|
| + }
|
| + return true;
|
| +};
|
| +
|
| +/**
|
| + * Moves selection to the next item.
|
| + * @return {boolean} Returns true if the selection was moved successfully.
|
| + */
|
| +cvox.SelectionWalker.prototype.next = function() {
|
| + var status = this.traverseContent.nextElement(
|
| + cvox.SelectionWalker.GRANULARITY_LEVELS[this.currentGranularity]);
|
| + return !!status;
|
| +};
|
| +
|
| +/**
|
| + * Moves selection to the previous item.
|
| + * @return {boolean} Returns true if the selection was moved successfully.
|
| + */
|
| +cvox.SelectionWalker.prototype.previous = function() {
|
| + var status = this.traverseContent.prevElement(
|
| + cvox.SelectionWalker.GRANULARITY_LEVELS[this.currentGranularity]);
|
| + return !!status;
|
| +};
|
| +
|
| +/**
|
| + * Returns the current granularity setting.
|
| + * @return {string} The granularity setting.
|
| + */
|
| +cvox.SelectionWalker.prototype.getGranularity = function() {
|
| + return cvox.SelectionWalker.GRANULARITY_LEVELS[this.currentGranularity];
|
| +};
|
| +
|
| +/**
|
| + * Sets the node that the SelectionWalker should be moving through.
|
| + * @param {Node} currentNode The node to set the SelectionWalker to.
|
| + */
|
| +cvox.SelectionWalker.prototype.setCurrentNode = function(currentNode) {
|
| + this.traverseContent = new cvox.TraverseContent(currentNode);
|
| + this.traverseContent.reset();
|
| +};
|
| +
|
| +/**
|
| + * Returns the current content of the selection.
|
| + * @return {string} The content of the selection.
|
| + */
|
| +cvox.SelectionWalker.prototype.getCurrentContent = function() {
|
| + // TODO (dmazzoni, clchen): Implement getting content from virtual navigation
|
| + // here.
|
| + return cvox.SelectionUtil.getText();
|
| +};
|
| +
|
|
|
| Property changes on: chrome/browser/resources/access_chromevox/common/selection_walker.js
|
| ___________________________________________________________________
|
| Added: svn:executable
|
| + *
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|