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 == RoleType.textField) | |
Peter Lundblad
2015/08/26 18:42:37
Should we have an else here where we clear the edi
| |
480 this.createEditableTextHandlerIfNeeded_(evt.target); | |
481 | |
472 this.onEventDefault({target: node, type: 'focus'}); | 482 this.onEventDefault({target: node, type: 'focus'}); |
473 }, | 483 }, |
474 | 484 |
475 /** | 485 /** |
476 * Provides all feedback once a load complete event fires. | 486 * Provides all feedback once a load complete event fires. |
477 * @param {Object} evt | 487 * @param {Object} evt |
478 */ | 488 */ |
479 onLoadComplete: function(evt) { | 489 onLoadComplete: function(evt) { |
480 this.setupChromeVoxVariants_(evt.target.docUrl); | 490 this.setupChromeVoxVariants_(evt.target.docUrl); |
481 | 491 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 return; | 534 return; |
525 | 535 |
526 if (!evt.target.state.focused) | 536 if (!evt.target.state.focused) |
527 return; | 537 return; |
528 | 538 |
529 if (!this.currentRange_) { | 539 if (!this.currentRange_) { |
530 this.onEventDefault(evt); | 540 this.onEventDefault(evt); |
531 this.currentRange_ = cursors.Range.fromNode(evt.target); | 541 this.currentRange_ = cursors.Range.fromNode(evt.target); |
532 } | 542 } |
533 | 543 |
544 this.createEditableTextHandlerIfNeeded_(evt.target); | |
534 var textChangeEvent = new cvox.TextChangeEvent( | 545 var textChangeEvent = new cvox.TextChangeEvent( |
535 evt.target.value, | 546 evt.target.value, |
536 evt.target.textSelStart, | 547 evt.target.textSelStart, |
537 evt.target.textSelEnd, | 548 evt.target.textSelEnd, |
538 true); // triggered by user | 549 true); // triggered by user |
539 if (!this.editableTextHandler || | 550 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( | 551 new Output().withBraille( |
552 this.currentRange_, null, evt.type) | 552 this.currentRange_, null, evt.type) |
553 .go(); | 553 .go(); |
554 }, | 554 }, |
555 | 555 |
556 /** | 556 /** |
557 * Provides all feedback once a value changed event fires. | 557 * Provides all feedback once a value changed event fires. |
558 * @param {Object} evt | 558 * @param {Object} evt |
559 */ | 559 */ |
560 onValueChanged: function(evt) { | 560 onValueChanged: function(evt) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 }); | 732 }); |
733 if (!actionNode) | 733 if (!actionNode) |
734 return; | 734 return; |
735 if (actionNode.role === RoleType.inlineTextBox) | 735 if (actionNode.role === RoleType.inlineTextBox) |
736 actionNode = actionNode.parent; | 736 actionNode = actionNode.parent; |
737 actionNode.doDefault(); | 737 actionNode.doDefault(); |
738 if (selectionSpan) { | 738 if (selectionSpan) { |
739 var start = text.getSpanStart(selectionSpan); | 739 var start = text.getSpanStart(selectionSpan); |
740 actionNode.setSelection(position - start, position - start); | 740 actionNode.setSelection(position - start, position - start); |
741 } | 741 } |
742 }, | |
743 | |
744 /** | |
745 * Create an editable text handler for the given node if needed. | |
746 * @param {Object} node | |
Peter Lundblad
2015/08/26 18:42:37
chrome.automation.AutomationNode instead of Object
| |
747 */ | |
Peter Lundblad
2015/08/26 18:42:37
@private
| |
748 createEditableTextHandlerIfNeeded_: function(node) { | |
749 if (!this.editableTextHandler_ || node != this.currentRange_.start.node) { | |
750 this.editableTextHandler_ = | |
751 new cvox.ChromeVoxEditableTextBase( | |
752 node.value, | |
753 node.textSelStart, | |
754 node.textSelEnd, | |
755 node.state.protected, | |
756 cvox.ChromeVox.tts); | |
757 } | |
742 } | 758 } |
743 }; | 759 }; |
744 | 760 |
745 /** @type {Background} */ | 761 /** @type {Background} */ |
746 global.backgroundObj = new Background(); | 762 global.backgroundObj = new Background(); |
747 | 763 |
748 }); // goog.scope | 764 }); // goog.scope |
OLD | NEW |