Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/editing.js

Issue 2650733002: Revert of Update json_schema_compiler to handle the Automation extension API (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 Processes events related to editing text and emits the 6 * @fileoverview Processes events related to editing text and emits the
7 * appropriate spoken and braille feedback. 7 * appropriate spoken and braille feedback.
8 */ 8 */
9 9
10 goog.provide('editing.TextEditHandler'); 10 goog.provide('editing.TextEditHandler');
11 11
12 goog.require('AutomationTreeWalker'); 12 goog.require('AutomationTreeWalker');
13 goog.require('AutomationUtil'); 13 goog.require('AutomationUtil');
14 goog.require('Output'); 14 goog.require('Output');
15 goog.require('Output.EventType'); 15 goog.require('Output.EventType');
16 goog.require('cursors.Cursor'); 16 goog.require('cursors.Cursor');
17 goog.require('cursors.Range'); 17 goog.require('cursors.Range');
18 goog.require('cvox.ChromeVoxEditableTextBase'); 18 goog.require('cvox.ChromeVoxEditableTextBase');
19 19
20 goog.scope(function() { 20 goog.scope(function() {
21 var AutomationEvent = chrome.automation.AutomationEvent; 21 var AutomationEvent = chrome.automation.AutomationEvent;
22 var AutomationNode = chrome.automation.AutomationNode; 22 var AutomationNode = chrome.automation.AutomationNode;
23 var Cursor = cursors.Cursor; 23 var Cursor = cursors.Cursor;
24 var Dir = AutomationUtil.Dir; 24 var Dir = AutomationUtil.Dir;
25 var EventType = chrome.automation.EventType; 25 var EventType = chrome.automation.EventType;
26 var Range = cursors.Range; 26 var Range = cursors.Range;
27 var RoleType = chrome.automation.RoleType; 27 var RoleType = chrome.automation.RoleType;
28 var StateType = chrome.automation.StateType;
29 var Movement = cursors.Movement; 28 var Movement = cursors.Movement;
30 var Unit = cursors.Unit; 29 var Unit = cursors.Unit;
31 30
32 /** 31 /**
33 * A handler for automation events in a focused text field or editable root 32 * A handler for automation events in a focused text field or editable root
34 * such as a |contenteditable| subtree. 33 * such as a |contenteditable| subtree.
35 * @constructor 34 * @constructor
36 * @param {!AutomationNode} node 35 * @param {!AutomationNode} node
37 */ 36 */
38 editing.TextEditHandler = function(node) { 37 editing.TextEditHandler = function(node) {
39 /** @const {!AutomationNode} @private */ 38 /** @const {!AutomationNode} @private */
40 this.node_ = node; 39 this.node_ = node;
41 }; 40 };
42 41
43 editing.TextEditHandler.prototype = { 42 editing.TextEditHandler.prototype = {
44 /** @return {!AutomationNode} */ 43 /** @return {!AutomationNode} */
45 get node() { 44 get node() {
46 return this.node_; 45 return this.node_;
47 }, 46 },
48 47
49 /** 48 /**
50 * Receives the following kinds of events when the node provided to the 49 * Receives the following kinds of events when the node provided to the
51 * constructor is focuse: |focus|, |textChanged|, |textSelectionChanged| and 50 * constructor is focuse: |focus|, |textChanged|, |textSelectionChanged| and
52 * |valueChanged|. 51 * |valueChanged|.
53 * An implementation of this method should emit the appropritate braille and 52 * An implementation of this method should emit the appropritate braille and
54 * spoken feedback for the event. 53 * spoken feedback for the event.
55 * @param {!(AutomationEvent|CustomAutomationEvent)} evt 54 * @param {!AutomationEvent} evt
56 */ 55 */
57 onEvent: goog.abstractMethod, 56 onEvent: goog.abstractMethod,
58 }; 57 };
59 58
60 /** 59 /**
61 * A |TextEditHandler| suitable for text fields. 60 * A |TextEditHandler| suitable for text fields.
62 * @constructor 61 * @constructor
63 * @param {!AutomationNode} node A node with the role of |textField| 62 * @param {!AutomationNode} node A node with the role of |textField|
64 * @extends {editing.TextEditHandler} 63 * @extends {editing.TextEditHandler}
65 */ 64 */
66 function TextFieldTextEditHandler(node) { 65 function TextFieldTextEditHandler(node) {
67 editing.TextEditHandler.call(this, node); 66 editing.TextEditHandler.call(this, node);
68 /** @type {AutomationEditableText} @private */ 67 /** @type {AutomationEditableText} @private */
69 this.editableText_ = new AutomationEditableText(node); 68 this.editableText_ = new AutomationEditableText(node);
70 } 69 }
71 70
72 TextFieldTextEditHandler.prototype = { 71 TextFieldTextEditHandler.prototype = {
73 __proto__: editing.TextEditHandler.prototype, 72 __proto__: editing.TextEditHandler.prototype,
74 73
75 /** @override */ 74 /** @override */
76 onEvent: function(evt) { 75 onEvent: function(evt) {
77 if (evt.type !== EventType.TEXT_CHANGED && 76 if (evt.type !== EventType.textChanged &&
78 evt.type !== EventType.TEXT_SELECTION_CHANGED && 77 evt.type !== EventType.textSelectionChanged &&
79 evt.type !== EventType.VALUE_CHANGED && 78 evt.type !== EventType.valueChanged &&
80 evt.type !== EventType.FOCUS) 79 evt.type !== EventType.focus)
81 return; 80 return;
82 if (!evt.target.state.focused || 81 if (!evt.target.state.focused ||
83 !evt.target.state.editable || 82 !evt.target.state.editable ||
84 evt.target != this.node_) 83 evt.target != this.node_)
85 return; 84 return;
86 85
87 this.editableText_.onUpdate(); 86 this.editableText_.onUpdate();
88 }, 87 },
89 }; 88 };
90 89
91 /** 90 /**
92 * A |ChromeVoxEditableTextBase| that implements text editing feedback 91 * A |ChromeVoxEditableTextBase| that implements text editing feedback
93 * for automation tree text fields. 92 * for automation tree text fields.
94 * @constructor 93 * @constructor
95 * @param {!AutomationNode} node 94 * @param {!AutomationNode} node
96 * @extends {cvox.ChromeVoxEditableTextBase} 95 * @extends {cvox.ChromeVoxEditableTextBase}
97 */ 96 */
98 function AutomationEditableText(node) { 97 function AutomationEditableText(node) {
99 if (!node.state.editable) 98 if (!node.state.editable)
100 throw Error('Node must have editable state set to true.'); 99 throw Error('Node must have editable state set to true.');
101 var start = node.textSelStart; 100 var start = node.textSelStart;
102 var end = node.textSelEnd; 101 var end = node.textSelEnd;
103 cvox.ChromeVoxEditableTextBase.call( 102 cvox.ChromeVoxEditableTextBase.call(
104 this, 103 this,
105 node.value || '', 104 node.value,
106 Math.min(start, end), 105 Math.min(start, end),
107 Math.max(start, end), 106 Math.max(start, end),
108 node.state[StateType.PROTECTED] /**password*/, 107 node.state.protected /**password*/,
109 cvox.ChromeVox.tts); 108 cvox.ChromeVox.tts);
110 /** @override */ 109 /** @override */
111 this.multiline = node.state[StateType.MULTILINE] || false; 110 this.multiline = node.state.multiline || false;
112 /** @type {!AutomationNode} @private */ 111 /** @type {!AutomationNode} @private */
113 this.node_ = node; 112 this.node_ = node;
114 /** @type {Array<number>} @private */ 113 /** @type {Array<number>} @private */
115 this.lineBreaks_ = []; 114 this.lineBreaks_ = [];
116 } 115 }
117 116
118 AutomationEditableText.prototype = { 117 AutomationEditableText.prototype = {
119 __proto__: cvox.ChromeVoxEditableTextBase.prototype, 118 __proto__: cvox.ChromeVoxEditableTextBase.prototype,
120 119
121 /** 120 /**
122 * Called when the text field has been updated. 121 * Called when the text field has been updated.
123 */ 122 */
124 onUpdate: function() { 123 onUpdate: function() {
125 var newValue = this.node_.value || ''; 124 var newValue = this.node_.value;
126 125
127 if (this.value != newValue) 126 if (this.value != newValue)
128 this.lineBreaks_ = []; 127 this.lineBreaks_ = [];
129 128
130 var textChangeEvent = new cvox.TextChangeEvent( 129 var textChangeEvent = new cvox.TextChangeEvent(
131 newValue, 130 newValue,
132 this.node_.textSelStart || 0, 131 this.node_.textSelStart,
133 this.node_.textSelEnd || 0, 132 this.node_.textSelEnd,
134 true /* triggered by user */); 133 true /* triggered by user */);
135 this.changed(textChangeEvent); 134 this.changed(textChangeEvent);
136 this.outputBraille_(); 135 this.outputBraille_();
137 }, 136 },
138 137
139 /** @override */ 138 /** @override */
140 getLineIndex: function(charIndex) { 139 getLineIndex: function(charIndex) {
141 if (!this.multiline) 140 if (!this.multiline)
142 return 0; 141 return 0;
143 var breaks = this.node_.lineBreaks || []; 142 var breaks = this.node_.lineBreaks || [];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 /** 200 /**
202 * @param {!AutomationNode} node The root editable node, i.e. the root of a 201 * @param {!AutomationNode} node The root editable node, i.e. the root of a
203 * contenteditable subtree or a text field. 202 * contenteditable subtree or a text field.
204 * @return {editing.TextEditHandler} 203 * @return {editing.TextEditHandler}
205 */ 204 */
206 editing.TextEditHandler.createForNode = function(node) { 205 editing.TextEditHandler.createForNode = function(node) {
207 var rootFocusedEditable = null; 206 var rootFocusedEditable = null;
208 var testNode = node; 207 var testNode = node;
209 208
210 do { 209 do {
211 if (testNode.state[StateType.FOCUSED] && testNode.state[StateType.EDITABLE]) 210 if (testNode.state.focused && testNode.state.editable)
212 rootFocusedEditable = testNode; 211 rootFocusedEditable = testNode;
213 testNode = testNode.parent; 212 testNode = testNode.parent;
214 } while (testNode); 213 } while (testNode);
215 214
216 if (rootFocusedEditable) 215 if (rootFocusedEditable)
217 return new TextFieldTextEditHandler(rootFocusedEditable); 216 return new TextFieldTextEditHandler(rootFocusedEditable);
218 217
219 return null; 218 return null;
220 }; 219 };
221 220
222 }); 221 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698