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

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

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

Powered by Google App Engine
This is Rietveld 408576698