OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Puts text on a braille display. | 6 * @fileoverview Puts text on a braille display. |
7 * | 7 * |
8 */ | 8 */ |
9 | 9 |
10 goog.provide('cvox.BrailleDisplayManager'); | 10 goog.provide('cvox.BrailleDisplayManager'); |
(...skipping 19 matching lines...) Expand all Loading... |
30 this.translatorManager_ = translatorManager; | 30 this.translatorManager_ = translatorManager; |
31 /** | 31 /** |
32 * @type {!cvox.NavBraille} | 32 * @type {!cvox.NavBraille} |
33 * @private | 33 * @private |
34 */ | 34 */ |
35 this.content_ = new cvox.NavBraille({}); | 35 this.content_ = new cvox.NavBraille({}); |
36 /** | 36 /** |
37 * @type {!cvox.ExpandingBrailleTranslator.ExpansionType} valueExpansion | 37 * @type {!cvox.ExpandingBrailleTranslator.ExpansionType} valueExpansion |
38 * @private | 38 * @private |
39 */ | 39 */ |
40 this.expansionType_ = | 40 this.expansionType_ = cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION; |
41 cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION; | |
42 /** | 41 /** |
43 * @type {cvox.PanStrategy} | 42 * @type {cvox.PanStrategy} |
44 * @private | 43 * @private |
45 */ | 44 */ |
46 this.panStrategy_ = new cvox.PanStrategy(); | 45 this.panStrategy_ = new cvox.PanStrategy(); |
47 /** | 46 /** |
48 * @type {function(!cvox.BrailleKeyEvent, !cvox.NavBraille)} | 47 * @type {function(!cvox.BrailleKeyEvent, !cvox.NavBraille)} |
49 * @private | 48 * @private |
50 */ | 49 */ |
51 this.commandListener_ = function() {}; | 50 this.commandListener_ = function() {}; |
52 /** | 51 /** |
53 * Current display state to show in the Virtual Braille Captions display. | 52 * Current display state to show in the Virtual Braille Captions display. |
54 * This is different from realDisplayState_ if the braille captions feature | 53 * This is different from realDisplayState_ if the braille captions feature |
55 * is enabled and there is no hardware display connected. Otherwise, it is | 54 * is enabled and there is no hardware display connected. Otherwise, it is |
56 * the same object as realDisplayState_. | 55 * the same object as realDisplayState_. |
57 * @type {!cvox.BrailleDisplayState} | 56 * @type {!cvox.BrailleDisplayState} |
58 * @private | 57 * @private |
59 */ | 58 */ |
60 this.displayState_ = {available: false, textRowCount: 0, | 59 this.displayState_ = {available: false, textRowCount: 0, textColumnCount: 0}; |
61 textColumnCount: 0}; | |
62 /** | 60 /** |
63 * State reported from the chrome api, reflecting a real hardware | 61 * State reported from the chrome api, reflecting a real hardware |
64 * display. | 62 * display. |
65 * @type {!cvox.BrailleDisplayState} | 63 * @type {!cvox.BrailleDisplayState} |
66 * @private | 64 * @private |
67 */ | 65 */ |
68 this.realDisplayState_ = this.displayState_; | 66 this.realDisplayState_ = this.displayState_; |
69 | 67 |
70 translatorManager.addChangeListener(function() { | 68 translatorManager.addChangeListener(function() { |
71 this.translateContent_(this.content_, this.expansionType_); | 69 this.translateContent_(this.content_, this.expansionType_); |
72 }.bind(this)); | 70 }.bind(this)); |
73 | 71 |
74 chrome.storage.onChanged.addListener(function(changes, area) { | 72 chrome.storage.onChanged.addListener(function(changes, area) { |
75 if (area == 'local' && 'brailleWordWrap' in changes) { | 73 if (area == 'local' && 'brailleWordWrap' in changes) { |
76 this.updatePanStrategy_(changes.brailleWordWrap.newValue); | 74 this.updatePanStrategy_(changes.brailleWordWrap.newValue); |
77 } | 75 } |
78 if (area == 'local' && ('virtualBrailleRows' in changes || | 76 if (area == 'local' && |
79 'virtualBrailleColumns' in changes)) { | 77 ('virtualBrailleRows' in changes || |
| 78 'virtualBrailleColumns' in changes)) { |
80 this.onCaptionsStateChanged_(); | 79 this.onCaptionsStateChanged_(); |
81 } | 80 } |
82 }.bind(this)); | 81 }.bind(this)); |
83 chrome.storage.local.get({brailleWordWrap: true}, function(items) { | 82 chrome.storage.local.get({brailleWordWrap: true}, function(items) { |
84 this.updatePanStrategy_(items.brailleWordWrap); | 83 this.updatePanStrategy_(items.brailleWordWrap); |
85 }.bind(this)); | 84 }.bind(this)); |
86 | 85 |
87 cvox.BrailleCaptionsBackground.init(goog.bind( | 86 cvox.BrailleCaptionsBackground.init( |
88 this.onCaptionsStateChanged_, this)); | 87 goog.bind(this.onCaptionsStateChanged_, this)); |
89 if (goog.isDef(chrome.brailleDisplayPrivate)) { | 88 if (goog.isDef(chrome.brailleDisplayPrivate)) { |
90 var onDisplayStateChanged = goog.bind(this.refreshDisplayState_, this); | 89 var onDisplayStateChanged = goog.bind(this.refreshDisplayState_, this); |
91 chrome.brailleDisplayPrivate.getDisplayState(onDisplayStateChanged); | 90 chrome.brailleDisplayPrivate.getDisplayState(onDisplayStateChanged); |
92 chrome.brailleDisplayPrivate.onDisplayStateChanged.addListener( | 91 chrome.brailleDisplayPrivate.onDisplayStateChanged.addListener( |
93 onDisplayStateChanged); | 92 onDisplayStateChanged); |
94 chrome.brailleDisplayPrivate.onKeyEvent.addListener( | 93 chrome.brailleDisplayPrivate.onKeyEvent.addListener( |
95 goog.bind(this.onKeyEvent_, this)); | 94 goog.bind(this.onKeyEvent_, this)); |
96 } else { | 95 } else { |
97 // Get the initial captions state since we won't refresh the display | 96 // Get the initial captions state since we won't refresh the display |
98 // state in an API callback in this case. | 97 // state in an API callback in this case. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // are 6-dot (2 x 3), but we should have a way to detect that via brltty. | 167 // are 6-dot (2 x 3), but we should have a way to detect that via brltty. |
169 var cellWidth = 2; | 168 var cellWidth = 2; |
170 var cellHeight = 3; | 169 var cellHeight = 3; |
171 var maxCellHeight = 4; | 170 var maxCellHeight = 4; |
172 | 171 |
173 var rows = this.displayState_.textRowCount; | 172 var rows = this.displayState_.textRowCount; |
174 var columns = this.displayState_.textColumnCount; | 173 var columns = this.displayState_.textColumnCount; |
175 var imageDataUrl = imageUrl; | 174 var imageDataUrl = imageUrl; |
176 var imgElement = document.createElement('img'); | 175 var imgElement = document.createElement('img'); |
177 imgElement.src = imageDataUrl; | 176 imgElement.src = imageDataUrl; |
178 imgElement.onload = (function() { | 177 imgElement.onload = |
179 var canvas = document.createElement('canvas'); | 178 (function() { |
180 var context = canvas.getContext('2d'); | 179 var canvas = document.createElement('canvas'); |
181 canvas.width = columns * cellWidth; | 180 var context = canvas.getContext('2d'); |
182 canvas.height = rows * cellHeight; | 181 canvas.width = columns * cellWidth; |
183 context.drawImage(imgElement, 0, 0, canvas.width, canvas.height); | 182 canvas.height = rows * cellHeight; |
184 var imageData = context.getImageData(0, 0, canvas.width, canvas.height); | 183 context.drawImage(imgElement, 0, 0, canvas.width, canvas.height); |
185 var data = imageData.data; | 184 var imageData = context.getImageData(0, 0, canvas.width, canvas.height); |
186 var outputData = []; | 185 var data = imageData.data; |
| 186 var outputData = []; |
187 | 187 |
188 // Convert image to black and white by thresholding the luminance for | 188 // Convert image to black and white by thresholding the luminance for |
189 // all opaque (non-transparent) pixels. | 189 // all opaque (non-transparent) pixels. |
190 for (var i = 0; i < data.length; i += 4) { | 190 for (var i = 0; i < data.length; i += 4) { |
191 var red = data[i]; | 191 var red = data[i]; |
192 var green = data[i + 1]; | 192 var green = data[i + 1]; |
193 var blue = data[i + 2]; | 193 var blue = data[i + 2]; |
194 var alpha = data[i + 3]; | 194 var alpha = data[i + 3]; |
195 var luminance = | 195 var luminance = 0.2126 * red + 0.7152 * green + 0.0722 * blue; |
196 0.2126 * red + | 196 // Show braille pin if the alpha is greater than the threshold and |
197 0.7152 * green + | 197 // the luminance is less than the threshold. |
198 0.0722 * blue; | 198 var show = |
199 // Show braille pin if the alpha is greater than the threshold and | 199 (alpha >= cvox.BrailleDisplayManager.ALPHA_THRESHOLD_ && |
200 // the luminance is less than the threshold. | 200 luminance < cvox.BrailleDisplayManager.LUMINANCE_THRESHOLD_); |
201 var show = (alpha >= cvox.BrailleDisplayManager.ALPHA_THRESHOLD_ && | 201 outputData.push(show); |
202 luminance < cvox.BrailleDisplayManager.LUMINANCE_THRESHOLD_); | 202 } |
203 outputData.push(show); | |
204 } | |
205 | 203 |
206 // Convert black-and-white array to the proper encoding for Braille cells. | 204 // Convert black-and-white array to the proper encoding for Braille |
207 var brailleBuf = new ArrayBuffer(rows * columns); | 205 // cells. |
208 var view = new Uint8Array(brailleBuf); | 206 var brailleBuf = new ArrayBuffer(rows * columns); |
209 for (var i = 0; i < rows; i++) { | 207 var view = new Uint8Array(brailleBuf); |
210 for (var j = 0; j < columns; j++) { | 208 for (var i = 0; i < rows; i++) { |
211 // Index in braille array | 209 for (var j = 0; j < columns; j++) { |
212 var brailleIndex = i * columns + j; | 210 // Index in braille array |
213 for (var cellColumn = 0; cellColumn < cellWidth; cellColumn++) { | 211 var brailleIndex = i * columns + j; |
214 for (var cellRow = 0; cellRow < cellHeight; cellRow++) { | 212 for (var cellColumn = 0; cellColumn < cellWidth; cellColumn++) { |
215 var bitmapIndex = | 213 for (var cellRow = 0; cellRow < cellHeight; cellRow++) { |
216 (i * columns * cellHeight + j + cellRow * columns) * cellWidth | 214 var bitmapIndex = |
217 + cellColumn; | 215 (i * columns * cellHeight + j + cellRow * columns) * |
218 if (outputData[bitmapIndex]) { | 216 cellWidth + |
219 view[brailleIndex] += | 217 cellColumn; |
220 cvox.BrailleDisplayManager.COORDS_TO_BRAILLE_DOT_[ | 218 if (outputData[bitmapIndex]) { |
221 cellColumn * maxCellHeight + cellRow]; | 219 view[brailleIndex] += |
| 220 cvox.BrailleDisplayManager.COORDS_TO_BRAILLE_DOT_ |
| 221 [cellColumn * maxCellHeight + cellRow]; |
| 222 } |
| 223 } |
222 } | 224 } |
223 } | 225 } |
224 } | 226 } |
225 } | |
226 } | |
227 | 227 |
228 if (this.realDisplayState_.available) { | 228 if (this.realDisplayState_.available) { |
229 chrome.brailleDisplayPrivate.writeDots( | 229 chrome.brailleDisplayPrivate.writeDots( |
230 brailleBuf, | 230 brailleBuf, this.displayState_.textColumnCount, |
231 this.displayState_.textColumnCount, | 231 this.displayState_.textRowCount); |
232 this.displayState_.textRowCount); | 232 } |
233 } | 233 if (cvox.BrailleCaptionsBackground.isEnabled()) { |
234 if (cvox.BrailleCaptionsBackground.isEnabled()) { | 234 cvox.BrailleCaptionsBackground.setImageContent( |
235 cvox.BrailleCaptionsBackground.setImageContent( | 235 brailleBuf, rows, columns); |
236 brailleBuf, rows, columns); | 236 } |
237 } | 237 }).bind(this); |
238 }).bind(this); | |
239 }; | 238 }; |
240 | 239 |
241 | 240 |
242 /** | 241 /** |
243 * Sets the command listener. When a command is invoked, the listener will be | 242 * Sets the command listener. When a command is invoked, the listener will be |
244 * called with the BrailleKeyEvent corresponding to the command and the content | 243 * called with the BrailleKeyEvent corresponding to the command and the content |
245 * that was present on the display when the command was invoked. The content | 244 * that was present on the display when the command was invoked. The content |
246 * is guaranteed to be identical to an object previously used as the parameter | 245 * is guaranteed to be identical to an object previously used as the parameter |
247 * to cvox.BrailleDisplayManager.setContent, or null if no content was set. | 246 * to cvox.BrailleDisplayManager.setContent, or null if no content was set. |
248 * @param {function(!cvox.BrailleKeyEvent, !cvox.NavBraille)} func The listener. | 247 * @param {function(!cvox.BrailleKeyEvent, !cvox.NavBraille)} func The listener. |
(...skipping 12 matching lines...) Expand all Loading... |
261 | 260 |
262 | 261 |
263 /** | 262 /** |
264 * @param {{available: boolean, textRowCount: (number|undefined), | 263 * @param {{available: boolean, textRowCount: (number|undefined), |
265 * textColumnCount: (number|undefined)}} newState Display state reported | 264 * textColumnCount: (number|undefined)}} newState Display state reported |
266 * by the extension API. Note that the type is almost the same as | 265 * by the extension API. Note that the type is almost the same as |
267 * cvox.BrailleDisplayState except that the extension API allows | 266 * cvox.BrailleDisplayState except that the extension API allows |
268 * some fields to be undefined, while cvox.BrailleDisplayState does not. | 267 * some fields to be undefined, while cvox.BrailleDisplayState does not. |
269 * @private | 268 * @private |
270 */ | 269 */ |
271 cvox.BrailleDisplayManager.prototype.refreshDisplayState_ = function( | 270 cvox.BrailleDisplayManager.prototype.refreshDisplayState_ = function(newState) { |
272 newState) { | |
273 var oldColumnCount = this.displayState_.textColumnCount || 0; | 271 var oldColumnCount = this.displayState_.textColumnCount || 0; |
274 var oldRowCount = this.displayState_.textRowCount || 0; | 272 var oldRowCount = this.displayState_.textRowCount || 0; |
275 var processDisplayState = function(displayState) { | 273 var processDisplayState = function(displayState) { |
276 this.displayState_ = displayState; | 274 this.displayState_ = displayState; |
277 var newColumnCount = displayState.textColumnCount || 0; | 275 var newColumnCount = displayState.textColumnCount || 0; |
278 var newRowCount = displayState.textRowCount || 0; | 276 var newRowCount = displayState.textRowCount || 0; |
279 | 277 |
280 if (oldColumnCount != newColumnCount || oldRowCount != newRowCount) { | 278 if (oldColumnCount != newColumnCount || oldRowCount != newRowCount) { |
281 this.panStrategy_.setDisplaySize(newRowCount, newColumnCount); | 279 this.panStrategy_.setDisplaySize(newRowCount, newColumnCount); |
282 } | 280 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 * braille captions display. | 312 * braille captions display. |
315 * @private | 313 * @private |
316 */ | 314 */ |
317 cvox.BrailleDisplayManager.prototype.refresh_ = function() { | 315 cvox.BrailleDisplayManager.prototype.refresh_ = function() { |
318 if (!this.displayState_.available) { | 316 if (!this.displayState_.available) { |
319 return; | 317 return; |
320 } | 318 } |
321 var brailleBuf = this.panStrategy_.getCurrentBrailleViewportContents(); | 319 var brailleBuf = this.panStrategy_.getCurrentBrailleViewportContents(); |
322 var textBuf = this.panStrategy_.getCurrentTextViewportContents(); | 320 var textBuf = this.panStrategy_.getCurrentTextViewportContents(); |
323 if (this.realDisplayState_.available) { | 321 if (this.realDisplayState_.available) { |
324 chrome.brailleDisplayPrivate.writeDots(brailleBuf, | 322 chrome.brailleDisplayPrivate.writeDots( |
325 brailleBuf.byteLength, 1); | 323 brailleBuf, brailleBuf.byteLength, 1); |
326 } | 324 } |
327 if (cvox.BrailleCaptionsBackground.isEnabled()) { | 325 if (cvox.BrailleCaptionsBackground.isEnabled()) { |
328 cvox.BrailleCaptionsBackground.setContent(textBuf, brailleBuf, | 326 cvox.BrailleCaptionsBackground.setContent( |
329 this.panStrategy_.brailleToText, this.panStrategy_.offsetsForSlices, | 327 textBuf, brailleBuf, this.panStrategy_.brailleToText, |
330 this.displayState_.textRowCount, this.displayState_.textColumnCount); | 328 this.panStrategy_.offsetsForSlices, this.displayState_.textRowCount, |
| 329 this.displayState_.textColumnCount); |
331 } | 330 } |
332 }; | 331 }; |
333 | 332 |
334 /** | 333 /** |
335 * @param {!cvox.NavBraille} newContent New display content. | 334 * @param {!cvox.NavBraille} newContent New display content. |
336 * @param {cvox.ExpandingBrailleTranslator.ExpansionType} newExpansionType | 335 * @param {cvox.ExpandingBrailleTranslator.ExpansionType} newExpansionType |
337 * How the value part of of the new content should be expanded | 336 * How the value part of of the new content should be expanded |
338 * with regards to contractions. | 337 * with regards to contractions. |
339 * @private | 338 * @private |
340 */ | 339 */ |
(...skipping 26 matching lines...) Expand all Loading... |
367 translatedEndIndex = cells.byteLength; | 366 translatedEndIndex = cells.byteLength; |
368 } else { | 367 } else { |
369 translatedEndIndex = textToBraille[endIndex]; | 368 translatedEndIndex = textToBraille[endIndex]; |
370 } | 369 } |
371 // Add the cursor to cells. | 370 // Add the cursor to cells. |
372 this.writeCursor_(cells, translatedStartIndex, translatedEndIndex); | 371 this.writeCursor_(cells, translatedStartIndex, translatedEndIndex); |
373 targetPosition = translatedStartIndex; | 372 targetPosition = translatedStartIndex; |
374 } else { | 373 } else { |
375 targetPosition = 0; | 374 targetPosition = 0; |
376 } | 375 } |
377 this.panStrategy_.setContent(this.content_.text.toString(), | 376 this.panStrategy_.setContent( |
378 cells, brailleToText, targetPosition); | 377 this.content_.text.toString(), cells, brailleToText, targetPosition); |
379 | 378 |
380 this.refresh_(); | 379 this.refresh_(); |
381 }.bind(this); | 380 }.bind(this); |
382 | 381 |
383 var translator = this.translatorManager_.getExpandingTranslator(); | 382 var translator = this.translatorManager_.getExpandingTranslator(); |
384 if (!translator) { | 383 if (!translator) { |
385 writeTranslatedContent(new ArrayBuffer(0), [], []); | 384 writeTranslatedContent(new ArrayBuffer(0), [], []); |
386 } else { | 385 } else { |
387 translator.translate( | 386 translator.translate( |
388 newContent.text, | 387 newContent.text, newExpansionType, writeTranslatedContent); |
389 newExpansionType, | |
390 writeTranslatedContent); | |
391 } | 388 } |
392 }; | 389 }; |
393 | 390 |
394 | 391 |
395 /** | 392 /** |
396 * @param {cvox.BrailleKeyEvent} event The key event. | 393 * @param {cvox.BrailleKeyEvent} event The key event. |
397 * @private | 394 * @private |
398 */ | 395 */ |
399 cvox.BrailleDisplayManager.prototype.onKeyEvent_ = function(event) { | 396 cvox.BrailleDisplayManager.prototype.onKeyEvent_ = function(event) { |
400 switch (event.command) { | 397 switch (event.command) { |
401 case cvox.BrailleKeyCommand.PAN_LEFT: | 398 case cvox.BrailleKeyCommand.PAN_LEFT: |
402 this.panLeft_(); | 399 this.panLeft_(); |
403 break; | 400 break; |
404 case cvox.BrailleKeyCommand.PAN_RIGHT: | 401 case cvox.BrailleKeyCommand.PAN_RIGHT: |
405 this.panRight_(); | 402 this.panRight_(); |
406 break; | 403 break; |
407 case cvox.BrailleKeyCommand.ROUTING: | 404 case cvox.BrailleKeyCommand.ROUTING: |
408 event.displayPosition = this.brailleToTextPosition_( | 405 event.displayPosition = this.brailleToTextPosition_( |
409 event.displayPosition + this.panStrategy_.viewPort.firstRow * | 406 event.displayPosition + |
410 this.panStrategy_.displaySize.columns); | 407 this.panStrategy_.viewPort.firstRow * |
411 // fall through | 408 this.panStrategy_.displaySize.columns); |
| 409 // fall through |
412 default: | 410 default: |
413 this.commandListener_(event, this.content_); | 411 this.commandListener_(event, this.content_); |
414 break; | 412 break; |
415 } | 413 } |
416 }; | 414 }; |
417 | 415 |
418 | 416 |
419 /** | 417 /** |
420 * Shift the display by one full display size and refresh the content. | 418 * Shift the display by one full display size and refresh the content. |
421 * Sends the appropriate command if the display is already at the leftmost | 419 * Sends the appropriate command if the display is already at the leftmost |
422 * position. | 420 * position. |
423 * @private | 421 * @private |
424 */ | 422 */ |
425 cvox.BrailleDisplayManager.prototype.panLeft_ = function() { | 423 cvox.BrailleDisplayManager.prototype.panLeft_ = function() { |
426 if (this.panStrategy_.previous()) { | 424 if (this.panStrategy_.previous()) { |
427 this.refresh_(); | 425 this.refresh_(); |
428 } else { | 426 } else { |
429 this.commandListener_({ | 427 this.commandListener_( |
430 command: cvox.BrailleKeyCommand.PAN_LEFT | 428 {command: cvox.BrailleKeyCommand.PAN_LEFT}, this.content_); |
431 }, this.content_); | |
432 } | 429 } |
433 }; | 430 }; |
434 | 431 |
435 | 432 |
436 /** | 433 /** |
437 * Shifts the display position to the right by one full display size and | 434 * Shifts the display position to the right by one full display size and |
438 * refreshes the content. Sends the appropriate command if the display is | 435 * refreshes the content. Sends the appropriate command if the display is |
439 * already at its rightmost position. | 436 * already at its rightmost position. |
440 * @private | 437 * @private |
441 */ | 438 */ |
442 cvox.BrailleDisplayManager.prototype.panRight_ = function() { | 439 cvox.BrailleDisplayManager.prototype.panRight_ = function() { |
443 if (this.panStrategy_.next()) { | 440 if (this.panStrategy_.next()) { |
444 this.refresh_(); | 441 this.refresh_(); |
445 } else { | 442 } else { |
446 this.commandListener_({ | 443 this.commandListener_( |
447 command: cvox.BrailleKeyCommand.PAN_RIGHT | 444 {command: cvox.BrailleKeyCommand.PAN_RIGHT}, this.content_); |
448 }, this.content_); | |
449 } | 445 } |
450 }; | 446 }; |
451 | 447 |
452 /** | 448 /** |
453 * Writes a cursor in the specified range into translated content. | 449 * Writes a cursor in the specified range into translated content. |
454 * @param {ArrayBuffer} buffer Buffer to add cursor to. | 450 * @param {ArrayBuffer} buffer Buffer to add cursor to. |
455 * @param {number} startIndex The start index to place the cursor. | 451 * @param {number} startIndex The start index to place the cursor. |
456 * @param {number} endIndex The end index to place the cursor (exclusive). | 452 * @param {number} endIndex The end index to place the cursor (exclusive). |
457 * @private | 453 * @private |
458 */ | 454 */ |
(...skipping 16 matching lines...) Expand all Loading... |
475 }; | 471 }; |
476 | 472 |
477 /** | 473 /** |
478 * Returns the text position corresponding to an absolute braille position, | 474 * Returns the text position corresponding to an absolute braille position, |
479 * that is not accounting for the current pan position. | 475 * that is not accounting for the current pan position. |
480 * @private | 476 * @private |
481 * @param {number} braillePosition Braille position relative to the startof | 477 * @param {number} braillePosition Braille position relative to the startof |
482 * the translated content. | 478 * the translated content. |
483 * @return {number} The mapped position in code units. | 479 * @return {number} The mapped position in code units. |
484 */ | 480 */ |
485 cvox.BrailleDisplayManager.prototype.brailleToTextPosition_ = | 481 cvox.BrailleDisplayManager.prototype.brailleToTextPosition_ = function( |
486 function(braillePosition) { | 482 braillePosition) { |
487 var mapping = this.panStrategy_.brailleToText; | 483 var mapping = this.panStrategy_.brailleToText; |
488 if (braillePosition < 0) { | 484 if (braillePosition < 0) { |
489 // This shouldn't happen. | 485 // This shouldn't happen. |
490 console.error('WARNING: Braille position < 0: ' + braillePosition); | 486 console.error('WARNING: Braille position < 0: ' + braillePosition); |
491 return 0; | 487 return 0; |
492 } else if (braillePosition >= mapping.length) { | 488 } else if (braillePosition >= mapping.length) { |
493 // This happens when the user clicks on the right part of the display | 489 // This happens when the user clicks on the right part of the display |
494 // when it is not entirely filled with content. Allow addressing the | 490 // when it is not entirely filled with content. Allow addressing the |
495 // position after the last character. | 491 // position after the last character. |
496 return this.content_.text.length; | 492 return this.content_.text.length; |
497 } else { | 493 } else { |
498 return mapping[braillePosition]; | 494 return mapping[braillePosition]; |
499 } | 495 } |
500 }; | 496 }; |
501 | 497 |
502 /** | 498 /** |
503 * @param {boolean} wordWrap | 499 * @param {boolean} wordWrap |
504 * @private | 500 * @private |
505 */ | 501 */ |
506 cvox.BrailleDisplayManager.prototype.updatePanStrategy_ = function(wordWrap) { | 502 cvox.BrailleDisplayManager.prototype.updatePanStrategy_ = function(wordWrap) { |
507 this.panStrategy_.setPanStrategy(wordWrap); | 503 this.panStrategy_.setPanStrategy(wordWrap); |
508 this.refresh_(); | 504 this.refresh_(); |
509 }; | 505 }; |
OLD | NEW |