Chromium Code Reviews| 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 The entry point for all ChromeVox2 related code for the | 6 * @fileoverview The entry point for all ChromeVox2 related code for the |
| 7 * background page. | 7 * background page. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('Background'); | 10 goog.provide('Background'); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 hover: this.onEventDefault, | 83 hover: this.onEventDefault, |
| 84 loadComplete: this.onLoadComplete, | 84 loadComplete: this.onLoadComplete, |
| 85 menuStart: this.onEventDefault, | 85 menuStart: this.onEventDefault, |
| 86 menuEnd: this.onEventDefault, | 86 menuEnd: this.onEventDefault, |
| 87 menuListValueChanged: this.onEventDefault, | 87 menuListValueChanged: this.onEventDefault, |
| 88 textChanged: this.onTextOrTextSelectionChanged, | 88 textChanged: this.onTextOrTextSelectionChanged, |
| 89 textSelectionChanged: this.onTextOrTextSelectionChanged, | 89 textSelectionChanged: this.onTextOrTextSelectionChanged, |
| 90 valueChanged: this.onValueChanged | 90 valueChanged: this.onValueChanged |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 /** | |
| 94 * The object that speaks changes to an editable text field. | |
| 95 * @type {?cvox.ChromeVoxEditableTextBase} | |
| 96 */ | |
| 97 this.editableTextHandler_ = null; | |
| 98 | |
| 93 chrome.automation.getDesktop(this.onGotDesktop); | 99 chrome.automation.getDesktop(this.onGotDesktop); |
| 94 | 100 |
| 95 // Handle messages directed to the Next background page. | 101 // Handle messages directed to the Next background page. |
| 96 cvox.ExtensionBridge.addMessageListener(function(msg, port) { | 102 cvox.ExtensionBridge.addMessageListener(function(msg, port) { |
| 97 var target = msg['target']; | 103 var target = msg['target']; |
| 98 var action = msg['action']; | 104 var action = msg['action']; |
| 99 | 105 |
| 100 switch (target) { | 106 switch (target) { |
| 101 case 'next': | 107 case 'next': |
| 102 if (action == 'getIsClassicEnabled') { | 108 if (action == 'getIsClassicEnabled') { |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 Dir.FORWARD, | 468 Dir.FORWARD, |
| 463 AutomationPredicate.focused) || node; | 469 AutomationPredicate.focused) || node; |
| 464 | 470 |
| 465 // Fall back to the first leaf node in the document. | 471 // Fall back to the first leaf node in the document. |
| 466 if (node.role == RoleType.rootWebArea) { | 472 if (node.role == RoleType.rootWebArea) { |
| 467 node = AutomationUtil.findNodePost(node, | 473 node = AutomationUtil.findNodePost(node, |
| 468 Dir.FORWARD, | 474 Dir.FORWARD, |
| 469 AutomationPredicate.leaf); | 475 AutomationPredicate.leaf); |
| 470 } | 476 } |
| 471 } | 477 } |
| 478 | |
| 479 if (evt.target.role == 'textField' || evt.target.role == 'textBox') { | |
|
Peter Lundblad
2015/08/26 16:56:13
Use chrome.automation.RoleType.
no braces around o
dmazzoni
2015/08/26 18:18:23
Done.
| |
| 480 this.createEditableTextHandlerIfNeeded_(evt.target); | |
| 481 } | |
| 482 | |
| 472 this.onEventDefault({target: node, type: 'focus'}); | 483 this.onEventDefault({target: node, type: 'focus'}); |
| 473 }, | 484 }, |
| 474 | 485 |
| 475 /** | 486 /** |
| 476 * Provides all feedback once a load complete event fires. | 487 * Provides all feedback once a load complete event fires. |
| 477 * @param {Object} evt | 488 * @param {Object} evt |
| 478 */ | 489 */ |
| 479 onLoadComplete: function(evt) { | 490 onLoadComplete: function(evt) { |
| 480 this.setupChromeVoxVariants_(evt.target.docUrl); | 491 this.setupChromeVoxVariants_(evt.target.docUrl); |
| 481 | 492 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 return; | 535 return; |
| 525 | 536 |
| 526 if (!evt.target.state.focused) | 537 if (!evt.target.state.focused) |
| 527 return; | 538 return; |
| 528 | 539 |
| 529 if (!this.currentRange_) { | 540 if (!this.currentRange_) { |
| 530 this.onEventDefault(evt); | 541 this.onEventDefault(evt); |
| 531 this.currentRange_ = cursors.Range.fromNode(evt.target); | 542 this.currentRange_ = cursors.Range.fromNode(evt.target); |
| 532 } | 543 } |
| 533 | 544 |
| 545 this.createEditableTextHandlerIfNeeded_(evt.target); | |
| 534 var textChangeEvent = new cvox.TextChangeEvent( | 546 var textChangeEvent = new cvox.TextChangeEvent( |
| 535 evt.target.value, | 547 evt.target.value, |
| 536 evt.target.textSelStart, | 548 evt.target.textSelStart, |
| 537 evt.target.textSelEnd, | 549 evt.target.textSelEnd, |
| 538 true); // triggered by user | 550 true); // triggered by user |
| 539 if (!this.editableTextHandler || | 551 this.editableTextHandler_.changed(textChangeEvent); |
| 540 evt.target != this.currentRange_.start.node) { | |
| 541 this.editableTextHandler = | |
| 542 new cvox.ChromeVoxEditableTextBase( | |
| 543 textChangeEvent.value, | |
| 544 textChangeEvent.start, | |
| 545 textChangeEvent.end, | |
| 546 evt.target.state['protected'], | |
| 547 cvox.ChromeVox.tts); | |
| 548 } | |
| 549 | |
| 550 this.editableTextHandler.changed(textChangeEvent); | |
| 551 new Output().withBraille( | 552 new Output().withBraille( |
| 552 this.currentRange_, null, evt.type) | 553 this.currentRange_, null, evt.type) |
| 553 .go(); | 554 .go(); |
| 554 }, | 555 }, |
| 555 | 556 |
| 556 /** | 557 /** |
| 557 * Provides all feedback once a value changed event fires. | 558 * Provides all feedback once a value changed event fires. |
| 558 * @param {Object} evt | 559 * @param {Object} evt |
| 559 */ | 560 */ |
| 560 onValueChanged: function(evt) { | 561 onValueChanged: function(evt) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 }); | 733 }); |
| 733 if (!actionNode) | 734 if (!actionNode) |
| 734 return; | 735 return; |
| 735 if (actionNode.role === RoleType.inlineTextBox) | 736 if (actionNode.role === RoleType.inlineTextBox) |
| 736 actionNode = actionNode.parent; | 737 actionNode = actionNode.parent; |
| 737 actionNode.doDefault(); | 738 actionNode.doDefault(); |
| 738 if (selectionSpan) { | 739 if (selectionSpan) { |
| 739 var start = text.getSpanStart(selectionSpan); | 740 var start = text.getSpanStart(selectionSpan); |
| 740 actionNode.setSelection(position - start, position - start); | 741 actionNode.setSelection(position - start, position - start); |
| 741 } | 742 } |
| 743 }, | |
| 744 | |
| 745 /** | |
| 746 * Create an editable text handler for the given node if needed. | |
| 747 * @param {Object} node | |
| 748 */ | |
| 749 createEditableTextHandlerIfNeeded_: function(node) { | |
| 750 if (!this.editableTextHandler_ || node != this.currentRange_.start.node) { | |
| 751 this.editableTextHandler_ = | |
| 752 new cvox.ChromeVoxEditableTextBase( | |
| 753 node.value, | |
| 754 node.textSelStart, | |
| 755 node.textSelEnd, | |
| 756 node.state['protected'], | |
|
Peter Lundblad
2015/08/26 16:56:13
Why do you use square brackets around 'protected'
dmazzoni
2015/08/26 18:18:23
I was thinking of it as a set/map. Changed to node
| |
| 757 cvox.ChromeVox.tts); | |
| 758 } | |
| 742 } | 759 } |
| 743 }; | 760 }; |
| 744 | 761 |
| 745 /** @type {Background} */ | 762 /** @type {Background} */ |
| 746 global.backgroundObj = new Background(); | 763 global.backgroundObj = new Background(); |
| 747 | 764 |
| 748 }); // goog.scope | 765 }); // goog.scope |
| OLD | NEW |