| 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 |
| 162 // Make the changes to the attribute |
| 163 if (userInput !== previousContent) |
| 164 this._parentPane.node().setAttributeValue(this._attribute.name, user
Input); |
| 165 }, |
| 166 |
| 167 _editingCancelled: function() |
| 168 { |
| 169 this._removePrompt(); |
| 170 this._populateListItem(); |
| 171 }, |
| 172 |
| 173 /** |
| 174 * @param {string} previousContent |
| 175 * @param {!Event} event |
| 176 */ |
| 177 _editingValueKeyDown: function(previousContent, event) |
| 178 { |
| 179 if (event.handled) |
| 180 return; |
| 181 |
| 182 if (isEnterKey(event)) { |
| 183 this._editingCommitted(event.target.textContent, previousContent); |
| 184 event.consume(); |
| 185 return; |
| 186 } |
| 187 |
| 188 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || eve
nt.keyIdentifier === "U+001B") { |
| 189 this._editingCancelled(); |
| 190 event.consume(); |
| 191 return; |
| 192 } |
| 193 }, |
| 194 |
| 195 __proto__: WebInspector.AXNodePropertyTreeElement.prototype |
| 196 }; |
| 197 |
| 198 /** |
| 199 * @param {string} value |
| 200 * @return {!Element} |
| 201 */ |
| 202 WebInspector.ARIAAttributesTreeElement.createARIAValueElement = function(value) |
| 203 { |
| 204 var valueElement = createElementWithClass("span", "monospace"); |
| 205 // TODO(aboxhall): quotation marks? |
| 206 valueElement.setTextContentTruncatedIfNeeded(value || ""); |
| 207 return valueElement; |
| 208 }; |
| 209 |
| 210 /** |
| 211 * @constructor |
| 212 * TODO: completions; see StylesSidebarPane.js |
| 213 * @extends {WebInspector.TextPrompt} |
| 214 * @param {!WebInspector.ARIAAttributesTreeElement} treeElement |
| 215 */ |
| 216 WebInspector.ARIAAttributesPane.ARIAAttributePrompt = function(treeElement) |
| 217 { |
| 218 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this)
); |
| 219 |
| 220 this._treeElement = treeElement; |
| 221 }; |
| 222 |
| 223 WebInspector.ARIAAttributesPane.ARIAAttributePrompt.prototype = { |
| 224 /** |
| 225 * @param {!Element} proxyElement |
| 226 * @param {string} text |
| 227 * @param {number} cursorOffset |
| 228 * @param {!Range} wordRange |
| 229 * @param {boolean} force |
| 230 * @param {function(!Array.<string>, number=)} completionsReadyCallback |
| 231 */ |
| 232 _buildPropertyCompletions: function(proxyElement, text, cursorOffset, wordRa
nge, force, completionsReadyCallback) |
| 233 { |
| 234 // TODO(aboxhall): replace placeholder implementation with real implemen
tation |
| 235 completionsReadyCallback([], 0); |
| 236 }, |
| 237 |
| 238 __proto__: WebInspector.TextPrompt.prototype |
| 239 } |
| 240 |
| 241 |
| 242 WebInspector.ARIAAttributesPane._attributes = [ |
| 243 "role", |
| 244 "aria-busy", |
| 245 "aria-checked", |
| 246 "aria-disabled", |
| 247 "aria-expanded", |
| 248 "aria-grabbed", |
| 249 "aria-hidden", |
| 250 "aria-invalid", |
| 251 "aria-pressed", |
| 252 "aria-selected", |
| 253 "aria-activedescendant", |
| 254 "aria-atomic", |
| 255 "aria-autocomplete", |
| 256 "aria-controls", |
| 257 "aria-describedby", |
| 258 "aria-dropeffect", |
| 259 "aria-flowto", |
| 260 "aria-haspopup", |
| 261 "aria-label", |
| 262 "aria-labelledby", |
| 263 "aria-level", |
| 264 "aria-live", |
| 265 "aria-multiline", |
| 266 "aria-multiselectable", |
| 267 "aria-orientation", |
| 268 "aria-owns", |
| 269 "aria-posinset", |
| 270 "aria-readonly", |
| 271 "aria-relevant", |
| 272 "aria-required", |
| 273 "aria-setsize", |
| 274 "aria-sort", |
| 275 "aria-valuemax", |
| 276 "aria-valuemin", |
| 277 "aria-valuenow", |
| 278 "aria-valuetext", |
| 279 ]; |
| OLD | NEW |