Home | History | Annotate | Download | only in common
      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
      3 // found in the LICENSE file.
      4 
      5 goog.provide('cvox.BrailleTextHandler');
      6 
      7 goog.require('cvox.BrailleInterface');
      8 goog.require('cvox.BrailleUtil');
      9 goog.require('cvox.ChromeVox');
     10 goog.require('cvox.NavBraille');
     11 
     12 /**
     13  * @fileoverview Updates braille display contents following text changes.
     14  *
     15  */
     16 
     17 /**
     18  * Represents an editable text region.
     19  *
     20  * @constructor
     21  * @param {!cvox.BrailleInterface} braille Braille interface.
     22  */
     23 cvox.BrailleTextHandler = function(braille) {
     24   /**
     25    * Braille interface used to produce output.
     26    * @type {!cvox.BrailleInterface}
     27    * @private
     28    */
     29   this.braille_ = braille;
     30 };
     31 
     32 
     33 /**
     34  * Called by controller class when text changes.
     35  * @param {string} line The text of the line.
     36  * @param {number} start The 0-based index starting selection.
     37  * @param {number} end The 0-based index ending selection.
     38  * @param {boolean} multiline True if the text comes from a multi line text
     39  * field.
     40  * @param {Element} element DOM node which line comes from.
     41  * @param {number} lineStart Start offset of line (might be > 0 for multiline
     42  * fields).
     43  */
     44 cvox.BrailleTextHandler.prototype.changed = function(
     45     line, start, end, multiline, element, lineStart) {
     46   var content;
     47   if (multiline) {
     48     var spannable = cvox.BrailleUtil.createValue(line, start, end, lineStart);
     49     if (element) {
     50       spannable.setSpan(element, 0, line.length);
     51     }
     52     content = new cvox.NavBraille({text: spannable,
     53                                    startIndex: start,
     54                                    endIndex: end});
     55   } else {
     56     if (cvox.ChromeVox.navigationManager) {
     57       content = cvox.ChromeVox.navigationManager.getBraille();
     58     }
     59   }
     60   if (content) {
     61     this.braille_.write(content);
     62   }
     63 };
     64