Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.AccessibilitySubPane} | |
| 8 */ | |
| 9 WebInspector.ARIAAttributesPane = function() | |
| 10 { | |
| 11 WebInspector.AccessibilitySubPane.call(this, WebInspector.UIString("ARIA Att ributes")); | |
| 12 | |
| 13 this._noPropertiesInfo = this.createInfo(WebInspector.UIString("No ARIA attr ibutes")); | |
| 14 this._treeOutline = this.createTreeOutline(); | |
| 15 }; | |
| 16 | |
| 17 | |
| 18 WebInspector.ARIAAttributesPane.prototype = { | |
| 19 /** | |
| 20 * @override | |
| 21 * @param {?WebInspector.DOMNode} node | |
| 22 */ | |
| 23 setNode: function(node) | |
| 24 { | |
| 25 WebInspector.AccessibilitySubPane.prototype.setNode.call(this, node); | |
| 26 this._treeOutline.removeChildren(); | |
| 27 if (!this.node()) | |
| 28 return; | |
| 29 var target = this.node().target(); | |
| 30 var attributes = node.attributes(); | |
| 31 for (var i = 0; i < attributes.length; ++i) { | |
| 32 var attribute = attributes[i]; | |
| 33 if (WebInspector.ARIAAttributesPane._attributes.indexOf(attribute.na me) < 0) | |
| 34 continue; | |
| 35 this._treeOutline.appendChild(new WebInspector.ARIAAttributesTreeEle ment(this, attribute, target)); | |
| 36 } | |
| 37 | |
| 38 var foundAttributes = (this._treeOutline.rootElement().childCount() !== 0); | |
| 39 this._noPropertiesInfo.classList.toggle("hidden", foundAttributes); | |
| 40 this._treeOutline.element.classList.toggle("hidden", !foundAttributes); | |
| 41 }, | |
| 42 | |
| 43 __proto__: WebInspector.AccessibilitySubPane.prototype | |
| 44 }; | |
| 45 | |
| 46 | |
| 47 /** | |
| 48 * @constructor | |
| 49 * @extends {WebInspector.AXNodePropertyTreeElement} | |
| 50 * @param {!WebInspector.ARIAAttributesPane} parentPane | |
| 51 * @param {!WebInspector.DOMNode.Attribute} attribute | |
| 52 * @param {!WebInspector.Target} target | |
| 53 */ | |
| 54 WebInspector.ARIAAttributesTreeElement = function(parentPane, attribute, target) | |
| 55 { | |
| 56 WebInspector.AXNodePropertyTreeElement.call(this, target); | |
| 57 | |
| 58 this._parentPane = parentPane; | |
| 59 this._attribute = attribute; | |
| 60 | |
| 61 this.selectable = false; | |
| 62 }; | |
| 63 | |
| 64 WebInspector.ARIAAttributesTreeElement.prototype = { | |
| 65 /** | |
| 66 * @override | |
| 67 */ | |
| 68 onattach: function() | |
| 69 { | |
| 70 this._populateListItem(); | |
| 71 this.listItemElement.addEventListener("click", this._mouseClick.bind(thi s)); | |
| 72 }, | |
| 73 | |
| 74 _populateListItem: function() | |
| 75 { | |
| 76 this.listItemElement.removeChildren(); | |
| 77 this.appendNameElement(this._attribute.name); | |
| 78 this.listItemElement.createChild("span", "separator").textContent = ":\u 00A0"; | |
| 79 this.appendAttributeValueElement(this._attribute.value); | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * @override | |
| 84 * @param {string} name | |
| 85 */ | |
| 86 appendNameElement: function(name) | |
| 87 { | |
| 88 this._nameElement = createElement("span"); | |
| 89 this._nameElement.textContent = name; | |
| 90 this._nameElement.classList.add("ax-name"); | |
| 91 this._nameElement.classList.add("monospace"); | |
| 92 this.listItemElement.appendChild(this._nameElement); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @param {string} value | |
| 97 */ | |
| 98 appendAttributeValueElement: function(value) | |
| 99 { | |
| 100 this._valueElement = WebInspector.ARIAAttributesTreeElement.createARIAVa lueElement(value); | |
| 101 this.listItemElement.appendChild(this._valueElement); | |
| 102 }, | |
| 103 | |
| 104 /** | |
| 105 * @param {!Event} event | |
| 106 */ | |
| 107 _mouseClick: function(event) | |
| 108 { | |
| 109 event.consume(true); | |
| 110 | |
| 111 if (event.target === this.listItemElement) | |
| 112 return; | |
| 113 | |
| 114 this._startEditing(); | |
| 115 }, | |
| 116 | |
| 117 _startEditing: function() | |
| 118 { | |
| 119 var valueElement = this._valueElement; | |
| 120 | |
| 121 if (WebInspector.isBeingEdited(valueElement)) | |
| 122 return; | |
| 123 | |
| 124 var previousContent = valueElement.textContent; | |
| 125 | |
| 126 /** | |
| 127 * @param {string} previousContent | |
| 128 * @param {!Event} event | |
| 129 * @this {WebInspector.ARIAAttributesTreeElement} | |
| 130 */ | |
| 131 function blurListener(previousContent, event) | |
| 132 { | |
| 133 var text = event.target.textContent; | |
| 134 this._editingCommitted(text, previousContent); | |
| 135 } | |
| 136 | |
| 137 this._prompt = new WebInspector.ARIAAttributesPane.ARIAAttributePrompt(t his); | |
| 138 this._prompt.setAutocompletionTimeout(0); | |
| 139 var proxyElement = this._prompt.attachAndStartEditing(valueElement, blur Listener.bind(this, previousContent)); | |
| 140 | |
| 141 proxyElement.addEventListener("keydown", this._editingValueKeyDown.bind( this, previousContent), false); | |
| 142 | |
| 143 valueElement.getComponentSelection().setBaseAndExtent(valueElement, 0, v alueElement, 1); | |
| 144 }, | |
| 145 | |
| 146 _removePrompt: function() | |
| 147 { | |
| 148 if (!this._prompt) | |
| 149 return; | |
| 150 this._prompt.detach(); | |
| 151 delete this._prompt; | |
| 152 }, | |
| 153 | |
| 154 /** | |
| 155 * @param {string} userInput | |
| 156 * @param {string} previousContent | |
| 157 */ | |
| 158 _editingCommitted: function(userInput, previousContent) | |
| 159 { | |
| 160 this._removePrompt(); | |
| 161 this._editingEnded(); | |
| 162 | |
| 163 // Make the changes to the attribute | |
| 164 if (userInput !== previousContent) | |
| 165 this._parentPane.node().setAttributeValue(this._attribute.name, user Input); | |
| 166 }, | |
| 167 | |
| 168 _editingEnded: function() | |
|
dgozman
2016/07/19 18:13:12
Looks like a useless method now.
aboxhall
2016/07/21 21:39:26
Haha, yes. Removed.
| |
| 169 { | |
| 170 var editedElement = this._valueElement; | |
| 171 // The proxyElement has been deleted, no need to remove listener. | |
| 172 }, | |
| 173 | |
| 174 _editingCancelled: function() | |
| 175 { | |
| 176 this._removePrompt(); | |
| 177 this._populateListItem(); | |
| 178 this._editingEnded(); | |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * @param {string} previousContent | |
| 183 * @param {!Event} event | |
| 184 */ | |
| 185 _editingValueKeyDown: function(previousContent, event) | |
| 186 { | |
| 187 if (event.handled) | |
| 188 return; | |
| 189 | |
| 190 if (isEnterKey(event)) { | |
| 191 this._editingCommitted(event.target.textContent, previousContent); | |
| 192 event.consume(); | |
| 193 return; | |
| 194 } | |
| 195 | |
| 196 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || eve nt.keyIdentifier === "U+001B") { | |
| 197 this._editingCancelled(); | |
| 198 event.consume(); | |
| 199 return; | |
| 200 } | |
| 201 }, | |
| 202 | |
| 203 __proto__: WebInspector.AXNodePropertyTreeElement.prototype | |
| 204 }; | |
| 205 | |
| 206 /** | |
| 207 * @param {string} value | |
| 208 * @return {!Element} | |
| 209 */ | |
| 210 WebInspector.ARIAAttributesTreeElement.createARIAValueElement = function(value) | |
| 211 { | |
| 212 var valueElement = createElementWithClass("span", "monospace"); | |
| 213 // TODO(aboxhall): quotation marks? | |
| 214 valueElement.setTextContentTruncatedIfNeeded(value || ""); | |
| 215 return valueElement; | |
| 216 }; | |
| 217 | |
| 218 /** | |
| 219 * @constructor | |
| 220 * TODO: completions; see StylesSidebarPane.js | |
| 221 * @extends {WebInspector.TextPrompt} | |
| 222 * @param {!WebInspector.ARIAAttributesTreeElement} treeElement | |
| 223 */ | |
| 224 WebInspector.ARIAAttributesPane.ARIAAttributePrompt = function(treeElement) | |
| 225 { | |
| 226 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this) ); | |
| 227 | |
| 228 this._treeElement = treeElement; | |
| 229 }; | |
| 230 | |
| 231 WebInspector.ARIAAttributesPane.ARIAAttributePrompt.prototype = { | |
| 232 /** | |
| 233 * @param {!Element} proxyElement | |
| 234 * @param {string} text | |
| 235 * @param {number} cursorOffset | |
| 236 * @param {!Range} wordRange | |
| 237 * @param {boolean} force | |
| 238 * @param {function(!Array.<string>, number=)} completionsReadyCallback | |
| 239 */ | |
| 240 _buildPropertyCompletions: function(proxyElement, text, cursorOffset, wordRa nge, force, completionsReadyCallback) | |
| 241 { | |
| 242 // TODO(aboxhall): replace placeholder implementation with real implemen tation | |
| 243 completionsReadyCallback([], 0); | |
| 244 }, | |
| 245 | |
| 246 __proto__: WebInspector.TextPrompt.prototype | |
| 247 } | |
| 248 | |
| 249 | |
| 250 WebInspector.ARIAAttributesPane._attributes = [ | |
| 251 "role", | |
| 252 "aria-busy", | |
| 253 "aria-checked", | |
| 254 "aria-disabled", | |
| 255 "aria-expanded", | |
| 256 "aria-grabbed", | |
| 257 "aria-hidden", | |
| 258 "aria-invalid", | |
| 259 "aria-pressed", | |
| 260 "aria-selected", | |
| 261 "aria-activedescendant", | |
| 262 "aria-atomic", | |
| 263 "aria-autocomplete", | |
| 264 "aria-controls", | |
| 265 "aria-describedby", | |
| 266 "aria-dropeffect", | |
| 267 "aria-flowto", | |
| 268 "aria-haspopup", | |
| 269 "aria-label", | |
| 270 "aria-labelledby", | |
| 271 "aria-level", | |
| 272 "aria-live", | |
| 273 "aria-multiline", | |
| 274 "aria-multiselectable", | |
| 275 "aria-orientation", | |
| 276 "aria-owns", | |
| 277 "aria-posinset", | |
| 278 "aria-readonly", | |
| 279 "aria-relevant", | |
| 280 "aria-required", | |
| 281 "aria-setsize", | |
| 282 "aria-sort", | |
| 283 "aria-valuemax", | |
| 284 "aria-valuemin", | |
| 285 "aria-valuenow", | |
| 286 "aria-valuetext", | |
| 287 ]; | |
| OLD | NEW |