Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) IBM Corp. 2009 All rights reserved. | 2 * Copyright (C) IBM Corp. 2009 All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.SidebarPane} | 33 * @extends {WebInspector.SidebarPane} |
| 34 */ | 34 */ |
| 35 WebInspector.WatchExpressionsSidebarPane = function() | 35 WebInspector.WatchExpressionsSidebarPane = function() |
| 36 { | 36 { |
| 37 WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions ")); | 37 WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions ")); |
| 38 | 38 |
| 39 this.section = new WebInspector.WatchExpressionsSection(); | 39 this._requiresUpdate = false; |
| 40 this.bodyElement.appendChild(this.section.element); | 40 /** @type {!Array.<!WebInspector.WatchExpression>} */ |
| 41 this._watchExpressions = []; | |
| 42 | |
| 43 | |
| 44 this.bodyElement.classList.add("vbox"); | |
| 45 this.bodyElement.classList.add("watch-expressions"); | |
| 46 this.bodyElement.addEventListener("contextmenu", this._contextMenu.bind(this ), false); | |
| 41 | 47 |
| 42 var refreshButton = this.titleElement.createChild("button", "pane-title-butt on refresh"); | 48 var refreshButton = this.titleElement.createChild("button", "pane-title-butt on refresh"); |
| 43 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this ), false); | 49 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this ), false); |
| 44 refreshButton.title = WebInspector.UIString("Refresh"); | 50 refreshButton.title = WebInspector.UIString("Refresh"); |
| 45 | 51 |
| 46 var addButton = this.titleElement.createChild("button", "pane-title-button a dd"); | 52 var addButton = this.titleElement.createChild("button", "pane-title-button a dd"); |
| 47 addButton.addEventListener("click", this._addButtonClicked.bind(this), false ); | 53 addButton.addEventListener("click", this._addButtonClicked.bind(this), false ); |
| 48 addButton.title = WebInspector.UIString("Add watch expression"); | 54 addButton.title = WebInspector.UIString("Add watch expression"); |
| 49 | 55 |
| 50 this._requiresUpdate = true; | |
| 51 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this.refreshExpressions, this); | 56 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this.refreshExpressions, this); |
| 57 this._rebuildWatchExpressionUIs(WebInspector.settings.watchExpressions.get() ); | |
|
pfeldman
2015/02/09 13:13:52
You should only do this upon wasShown as previousl
sergeyv
2015/02/17 14:22:58
Done.
| |
| 52 } | 58 } |
| 53 | 59 |
| 54 WebInspector.WatchExpressionsSidebarPane.prototype = { | 60 WebInspector.WatchExpressionsSidebarPane.prototype = { |
| 55 wasShown: function() | 61 wasShown: function() |
| 56 { | 62 { |
| 57 this._refreshExpressionsIfNeeded(); | 63 this._refreshExpressionsIfNeeded(); |
| 58 }, | 64 }, |
| 59 | 65 |
| 60 refreshExpressions: function() | 66 refreshExpressions: function() |
| 61 { | 67 { |
| 62 this._requiresUpdate = true; | 68 this._requiresUpdate = true; |
| 63 this._refreshExpressionsIfNeeded(); | 69 this._refreshExpressionsIfNeeded(); |
| 64 }, | 70 }, |
| 65 | 71 |
| 66 /** | 72 /** |
| 67 * @param {string} expression | 73 * @param {string} expression |
| 68 */ | 74 */ |
| 69 addExpression: function(expression) | 75 addExpression: function(expression) |
| 70 { | 76 { |
| 71 this.section.addExpression(expression); | |
| 72 this.expand(); | 77 this.expand(); |
| 78 var watchExpression = this._createWatchExpression(expression); | |
| 79 this._watchExpressions.push(expression); | |
| 80 this._saveExpressions(); | |
| 81 }, | |
| 82 | |
| 83 _saveExpressions: function() | |
| 84 { | |
| 85 var toSave = []; | |
| 86 for (var i = 0; i < this._watchExpressions.length; i++) | |
| 87 if (this._watchExpressions[i].expression()) | |
| 88 toSave.push(this._watchExpressions[i].expression()); | |
| 89 | |
| 90 WebInspector.settings.watchExpressions.set(toSave); | |
| 73 }, | 91 }, |
| 74 | 92 |
| 75 _refreshExpressionsIfNeeded: function() | 93 _refreshExpressionsIfNeeded: function() |
| 76 { | 94 { |
| 77 if (this._requiresUpdate && this.isShowing()) { | 95 if (this._requiresUpdate && this.isShowing()) { |
| 78 this.section.update(); | 96 for (var watchExpression of this._watchExpressions) |
| 97 watchExpression.update(); | |
| 79 delete this._requiresUpdate; | 98 delete this._requiresUpdate; |
| 80 } else | 99 } else |
| 81 this._requiresUpdate = true; | 100 this._requiresUpdate = true; |
| 82 }, | 101 }, |
| 83 | 102 |
| 103 /** | |
| 104 * @param {!Event} event | |
| 105 */ | |
| 84 _addButtonClicked: function(event) | 106 _addButtonClicked: function(event) |
| 85 { | 107 { |
| 86 event.consume(); | 108 event.consume(true); |
| 87 this.expand(); | 109 this.expand(); |
| 88 this.section.addNewExpressionAndEdit(); | 110 this._createWatchExpression(null).startEditing(); |
| 89 }, | 111 }, |
| 90 | 112 |
| 113 /** | |
| 114 * @param {!Event} event | |
| 115 */ | |
| 91 _refreshButtonClicked: function(event) | 116 _refreshButtonClicked: function(event) |
| 92 { | 117 { |
| 93 event.consume(); | 118 event.consume(); |
| 94 this.refreshExpressions(); | 119 this.refreshExpressions(); |
| 95 }, | 120 }, |
| 96 | 121 |
| 122 _rebuildWatchExpressionUIs: function(watchExpressionStrings) | |
|
pfeldman
2015/02/09 13:13:53
Please annotate.
sergeyv
2015/02/17 14:22:58
Done.
| |
| 123 { | |
| 124 this.bodyElement.removeChildren(); | |
| 125 for (var i = 0; i < watchExpressionStrings.length; ++i) { | |
| 126 var expression = watchExpressionStrings[i]; | |
| 127 if (!expression) | |
| 128 continue; | |
| 129 | |
| 130 this._createWatchExpression(expression); | |
| 131 } | |
| 132 | |
| 133 this._createEmptyElementIfNeeded(); | |
| 134 }, | |
| 135 | |
| 136 /** | |
| 137 * @param {?string} expression | |
| 138 * @return {!WebInspector.WatchExpression} | |
| 139 */ | |
| 140 _createWatchExpression: function(expression) | |
| 141 { | |
| 142 if (this._emptyElement) { | |
|
pfeldman
2015/02/09 13:13:53
You should use CSS to show / hide it.
sergeyv
2015/02/17 14:22:58
Done.
| |
| 143 this.bodyElement.removeChild(this._emptyElement); | |
| 144 delete this._emptyElement; | |
| 145 } | |
| 146 | |
| 147 var watchExpression = new WebInspector.WatchExpression(expression); | |
| 148 watchExpression.addEventListener(WebInspector.WatchExpression.Events.Exp ressionUpdated, this._watchExpressionUpdated.bind(this)); | |
| 149 this.bodyElement.appendChild(watchExpression.element()); | |
| 150 this._watchExpressions.push(watchExpression); | |
| 151 return watchExpression; | |
| 152 }, | |
| 153 | |
| 154 _createEmptyElementIfNeeded: function() | |
| 155 { | |
| 156 if (this._watchExpressions.length) | |
| 157 return; | |
| 158 | |
| 159 this._emptyElement = this.bodyElement.createChild("div", "info"); | |
| 160 this._emptyElement.textContent = WebInspector.UIString("No Watch Express ions"); | |
| 161 }, | |
| 162 | |
| 163 /** | |
| 164 * @param {!WebInspector.Event} event | |
| 165 */ | |
| 166 _watchExpressionUpdated: function(event) | |
| 167 { | |
| 168 var watchExpression = /** @type {!WebInspector.WatchExpression} */ (even t.target); | |
| 169 if (!watchExpression.expression()) { | |
| 170 this._watchExpressions.remove(watchExpression); | |
| 171 this.bodyElement.removeChild(watchExpression.element()); | |
| 172 this._createEmptyElementIfNeeded(); | |
| 173 } | |
| 174 | |
| 175 this._saveExpressions(); | |
| 176 }, | |
| 177 | |
| 178 /** | |
| 179 * @param {!Event} event | |
| 180 */ | |
| 181 _contextMenu: function(event) | |
| 182 { | |
| 183 var contextMenu = new WebInspector.ContextMenu(event); | |
| 184 this._populateContextMenu(contextMenu, event); | |
| 185 contextMenu.show(); | |
| 186 }, | |
| 187 | |
| 188 /** | |
| 189 * @param {!WebInspector.ContextMenu} contextMenu | |
| 190 * @param {!Event} event | |
| 191 */ | |
| 192 _populateContextMenu: function(contextMenu, event) | |
| 193 { | |
| 194 var isEditing = false; | |
| 195 for (var watchExpression of this._watchExpressions) | |
| 196 isEditing |= watchExpression.isEditing(); | |
| 197 | |
| 198 if (!isEditing) | |
| 199 contextMenu.appendItem(WebInspector.UIString.capitalize("Add ^watch ^expression"), this._addButtonClicked.bind(this)); | |
| 200 | |
| 201 if (this._watchExpressions.length > 1) | |
| 202 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^all ^watch ^expressions"), this._deleteAllButtonClicked.bind(this)); | |
| 203 | |
| 204 for (var watchExpression of this._watchExpressions) | |
| 205 if (watchExpression.element().containsEventPoint(event)) | |
| 206 watchExpression._populateContextMenu(contextMenu, event); | |
| 207 }, | |
| 208 | |
| 209 _deleteAllButtonClicked: function() | |
| 210 { | |
| 211 this._watchExpressions = []; | |
| 212 this._saveExpressions(); | |
| 213 this._rebuildWatchExpressionUIs([]); | |
| 214 }, | |
| 215 | |
| 97 __proto__: WebInspector.SidebarPane.prototype | 216 __proto__: WebInspector.SidebarPane.prototype |
| 98 } | 217 } |
| 99 | 218 |
| 100 /** | 219 /** |
| 101 * @constructor | 220 * @constructor |
| 102 * @extends {WebInspector.PropertiesSection} | 221 * @extends {WebInspector.Object} |
| 222 * @param {?string} expression | |
| 103 */ | 223 */ |
| 104 WebInspector.WatchExpressionsSection = function() | 224 WebInspector.WatchExpression = function(expression) |
| 105 { | 225 { |
| 106 this._watchObjectGroupId = "watch-group"; | 226 this._expression = expression; |
| 107 | 227 this._element = createElementWithClass("div", "watch-expression monospace"); |
| 108 WebInspector.PropertiesSection.call(this, ""); | 228 this._editing = false; |
| 109 this.treeElementConstructor = WebInspector.ObjectPropertyTreeElement; | 229 |
| 110 this.skipProto = false; | 230 this._createWatchExpression(null, false); |
| 111 | 231 this.update(); |
| 112 this.emptyElement = createElementWithClass("div", "info"); | 232 |
| 113 this.emptyElement.textContent = WebInspector.UIString("No Watch Expressions" ); | 233 this._element.addEventListener("mousemove", this._mouseMove.bind(this), true ); |
| 114 | 234 this._element.addEventListener("mouseleave", this._mouseLeave.bind(this), tr ue); |
| 115 /** @type {!Array.<string>} */ | |
| 116 this.watchExpressions = WebInspector.settings.watchExpressions.get(); | |
| 117 | |
| 118 this.headerElement.className = "hidden"; | |
| 119 this.editable = true; | |
| 120 this.expand(); | |
| 121 this.propertiesElement.classList.add("watch-expressions"); | |
| 122 | |
| 123 this.element.addEventListener("mousemove", this._mouseMove.bind(this), true) ; | |
| 124 this.element.addEventListener("mouseleave", this._mouseLeave.bind(this), tru e); | |
| 125 this.element.addEventListener("dblclick", this._sectionDoubleClick.bind(this ), false); | |
| 126 this.emptyElement.addEventListener("contextmenu", this._emptyElementContextM enu.bind(this), false); | |
| 127 } | 235 } |
| 128 | 236 |
| 129 WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0"; | 237 WebInspector.WatchExpression._watchObjectGroupId = "watch-group"; |
| 130 | 238 |
| 131 WebInspector.WatchExpressionsSection.prototype = { | 239 WebInspector.WatchExpression.Events = { |
| 132 /** | 240 ExpressionUpdated: "ExpressionUpdated" |
| 133 * @param {!Event=} e | 241 } |
| 134 */ | 242 |
| 135 update: function(e) | 243 WebInspector.WatchExpression.prototype = { |
| 136 { | 244 |
| 137 if (e) | 245 /** |
| 138 e.consume(); | 246 * @return {!Element} |
| 139 | 247 */ |
| 140 /*** | 248 element: function() |
| 141 * @param {string} expression | 249 { |
| 142 * @param {number} watchIndex | 250 return this._element; |
| 143 * @param {?WebInspector.RemoteObject} result | 251 }, |
| 144 * @param {boolean} wasThrown | 252 |
| 145 * @this {WebInspector.WatchExpressionsSection} | 253 /** |
| 146 */ | 254 * @return {?string} |
| 147 function appendResult(expression, watchIndex, result, wasThrown) | 255 */ |
| 148 { | 256 expression: function() |
| 149 if (!result) | 257 { |
| 150 return; | 258 return this._expression; |
| 151 | 259 }, |
| 152 var property = new WebInspector.RemoteObjectProperty(expression, res ult); | 260 |
| 153 property.watchIndex = watchIndex; | 261 update: function() |
| 154 property.wasThrown = wasThrown; | 262 { |
| 155 | |
| 156 // To clarify what's going on here: | |
| 157 // In the outer function, we calculate the number of properties | |
| 158 // that we're going to be updating, and set that in the | |
| 159 // propertyCount variable. | |
| 160 // In this function, we test to see when we are processing the | |
| 161 // last property, and then call the superclass's updateProperties() | |
| 162 // method to get all the properties refreshed at once. | |
| 163 properties.push(property); | |
| 164 | |
| 165 if (properties.length == propertyCount) { | |
| 166 this.updateProperties(properties); | |
| 167 | |
| 168 // check to see if we just added a new watch expression, | |
| 169 // which will always be the last property | |
| 170 if (this._newExpressionAdded) { | |
| 171 delete this._newExpressionAdded; | |
| 172 | |
| 173 var treeElement = this.findAddedTreeElement(); | |
| 174 if (treeElement) | |
| 175 treeElement.startEditing(); | |
| 176 } | |
| 177 | |
| 178 // Force displaying delete button for hovered element. | |
| 179 if (this._lastMouseMovePageY) | |
| 180 this._updateHoveredElement(this._lastMouseMovePageY); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 // TODO: pass exact injected script id. | |
| 185 WebInspector.targetManager.targets().forEach(function(target) { target.r untimeAgent().releaseObjectGroup(this._watchObjectGroupId); }, this); | |
| 186 var properties = []; | |
| 187 | |
| 188 // Count the properties, so we known when to call this.updateProperties( ) | |
| 189 // in appendResult() | |
| 190 var propertyCount = 0; | |
| 191 for (var i = 0; i < this.watchExpressions.length; ++i) { | |
| 192 if (!this.watchExpressions[i]) | |
| 193 continue; | |
| 194 ++propertyCount; | |
| 195 } | |
| 196 | |
| 197 // Now process all the expressions, since we have the actual count, | |
| 198 // which is checked in the appendResult inner function. | |
| 199 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext); | 263 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext); |
| 200 if (currentExecutionContext) { | 264 if (currentExecutionContext && this._expression) |
| 201 for (var i = 0; i < this.watchExpressions.length; ++i) { | 265 currentExecutionContext.evaluate(this._expression, WebInspector.Watc hExpression._watchObjectGroupId, false, true, false, true, this._createWatchExpr ession.bind(this)); |
| 202 var expression = this.watchExpressions[i]; | 266 }, |
| 203 if (!expression) | 267 |
| 204 continue; | 268 startEditing: function() |
| 205 | 269 { |
| 206 currentExecutionContext.evaluate(expression, this._watchObjectGr oupId, false, true, false, false, appendResult.bind(this, expression, i)); | 270 this._editing = true; |
| 207 } | 271 this._element.removeChild(this._objectPresentationElement); |
| 208 } | 272 this._element.classList.add("watch-expression-editing"); |
| 209 | 273 var newDiv = this._element.createChild("div"); |
| 210 if (!propertyCount) { | 274 newDiv.textContent = this._nameElement.textContent; |
| 211 this.element.appendChild(this.emptyElement); | 275 this._textPrompt = new WebInspector.ObjectPropertyPrompt(true); |
| 212 this.propertiesElement.remove(); | 276 var proxyElement = this._textPrompt.attachAndStartEditing(newDiv, this._ finishEditing.bind(this, this._expression)); |
| 213 this.propertiesTreeOutline.removeChildren(); | 277 proxyElement.classList.add("watch-expression-text-prompt-proxy"); |
| 214 } else { | 278 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false); |
| 215 this.element.appendChild(this.propertiesElement); | 279 this._element.getComponentSelection().setBaseAndExtent(newDiv, 0, newDiv , 1); |
| 216 this.emptyElement.remove(); | 280 }, |
| 217 } | 281 |
| 218 }, | 282 /** |
| 219 | 283 * @return {boolean} |
| 220 /** | 284 */ |
| 221 * @param {!Array.<!WebInspector.RemoteObjectProperty>} properties | 285 isEditing: function() |
| 222 */ | 286 { |
| 223 updateProperties: function(properties) | 287 return !!this._editing; |
| 224 { | 288 }, |
| 225 this.propertiesTreeOutline.removeChildren(); | 289 |
| 226 WebInspector.ObjectPropertyTreeElement.populateWithProperties(this.prope rtiesTreeOutline, properties, [], | 290 /** |
| 227 WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressio nsSection.CompareProperties, false, null); | 291 * @param {?string} newExpression |
| 228 | 292 * @param {!Event} event |
| 229 this.propertiesForTest = properties; | 293 */ |
| 230 }, | 294 _finishEditing: function(newExpression, event) |
| 231 | 295 { |
| 232 /** | 296 if (event) |
| 233 * @param {string} expression | 297 event.consume(true); |
| 234 */ | 298 |
| 235 addExpression: function(expression) | 299 this._editing = false; |
| 236 { | 300 this._textPrompt.detach(); |
| 237 this.watchExpressions.push(expression); | 301 delete this._textPrompt; |
| 238 this.saveExpressions(); | 302 this._element.removeChildren(); |
| 303 this._element.classList.remove("watch-expression-editing"); | |
| 304 this._element.appendChild(this._objectPresentationElement); | |
| 305 this._updateExpression(newExpression); | |
| 306 }, | |
| 307 | |
| 308 /** | |
| 309 * @param {!Event} event | |
| 310 */ | |
| 311 _dblClickOnWatchExpression: function(event) | |
| 312 { | |
| 313 event.consume(); | |
| 314 if (!this.isEditing()) | |
| 315 this.startEditing(); | |
| 316 }, | |
| 317 | |
| 318 /** | |
| 319 * @param {?string} newExpression | |
| 320 */ | |
| 321 _updateExpression: function(newExpression) | |
| 322 { | |
| 323 this._expression = newExpression; | |
| 239 this.update(); | 324 this.update(); |
| 240 }, | 325 this.dispatchEventToListeners(WebInspector.WatchExpression.Events.Expres sionUpdated); |
| 241 | 326 }, |
| 242 addNewExpressionAndEdit: function() | 327 |
| 243 { | 328 /** |
| 244 this._newExpressionAdded = true; | 329 * @param {?WebInspector.RemoteObject} result |
| 245 this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatch Expression); | 330 * @param {boolean} wasThrown |
| 246 this.update(); | 331 */ |
| 247 }, | 332 _createWatchExpression: function(result, wasThrown) |
| 248 | 333 { |
| 249 _sectionDoubleClick: function(event) | 334 this._result = result; |
| 250 { | 335 this._element.removeChildren(); |
| 251 if (event.target !== this.element && event.target !== this.propertiesEle ment && event.target !== this.emptyElement) | |
| 252 return; | |
| 253 event.consume(); | |
| 254 this.addNewExpressionAndEdit(); | |
| 255 }, | |
| 256 | |
| 257 /** | |
| 258 * @param {!WebInspector.ObjectPropertyTreeElement} element | |
| 259 * @param {?string} value | |
| 260 */ | |
| 261 updateExpression: function(element, value) | |
| 262 { | |
| 263 if (value === null) { | |
| 264 var index = element.property.watchIndex; | |
| 265 this.watchExpressions.splice(index, 1); | |
| 266 } else { | |
| 267 this.watchExpressions[element.property.watchIndex] = value; | |
| 268 } | |
| 269 this.saveExpressions(); | |
| 270 this.update(); | |
| 271 }, | |
| 272 | |
| 273 _deleteAllExpressions: function() | |
| 274 { | |
| 275 this.watchExpressions = []; | |
| 276 this.saveExpressions(); | |
| 277 this.update(); | |
| 278 }, | |
| 279 | |
| 280 /** | |
| 281 * @return {?TreeElement} | |
| 282 */ | |
| 283 findAddedTreeElement: function() | |
| 284 { | |
| 285 var children = this.propertiesTreeOutline.children; | |
| 286 for (var i = 0; i < children.length; ++i) { | |
| 287 if (children[i].property.name === WebInspector.WatchExpressionsSecti on.NewWatchExpression) | |
| 288 return children[i]; | |
| 289 } | |
| 290 return null; | |
| 291 }, | |
| 292 | |
| 293 /** | |
| 294 * @return {number} | |
| 295 */ | |
| 296 saveExpressions: function() | |
| 297 { | |
| 298 var toSave = []; | |
| 299 for (var i = 0; i < this.watchExpressions.length; i++) | |
| 300 if (this.watchExpressions[i]) | |
| 301 toSave.push(this.watchExpressions[i]); | |
| 302 | |
| 303 WebInspector.settings.watchExpressions.set(toSave); | |
| 304 return toSave.length; | |
| 305 }, | |
| 306 | |
| 307 _mouseMove: function(e) | |
| 308 { | |
| 309 if (this.propertiesElement.firstChild) | |
| 310 this._updateHoveredElement(e.pageY); | |
| 311 }, | |
| 312 | |
| 313 _mouseLeave: function() | |
| 314 { | |
| 315 if (this._hoveredElement) { | |
| 316 this._hoveredElement.classList.remove("hovered"); | |
| 317 delete this._hoveredElement; | |
| 318 } | |
| 319 delete this._lastMouseMovePageY; | |
| 320 }, | |
| 321 | |
| 322 _updateHoveredElement: function(pageY) | |
| 323 { | |
| 324 var candidateElement = this.propertiesElement.firstChild; | |
| 325 while (true) { | |
| 326 var next = candidateElement.nextSibling; | |
| 327 while (next && !next.clientHeight) | |
| 328 next = next.nextSibling; | |
| 329 if (!next || next.totalOffsetTop() > pageY) | |
| 330 break; | |
| 331 candidateElement = next; | |
| 332 } | |
| 333 | |
| 334 if (this._hoveredElement !== candidateElement) { | |
| 335 if (this._hoveredElement) | |
| 336 this._hoveredElement.classList.remove("hovered"); | |
| 337 if (candidateElement) | |
| 338 candidateElement.classList.add("hovered"); | |
| 339 this._hoveredElement = candidateElement; | |
| 340 } | |
| 341 | |
| 342 this._lastMouseMovePageY = pageY; | |
| 343 }, | |
| 344 | |
| 345 _emptyElementContextMenu: function(event) | |
| 346 { | |
| 347 var contextMenu = new WebInspector.ContextMenu(event); | |
| 348 contextMenu.appendItem(WebInspector.UIString.capitalize("Add ^watch ^exp ression"), this.addNewExpressionAndEdit.bind(this)); | |
| 349 contextMenu.show(); | |
| 350 }, | |
| 351 | |
| 352 __proto__: WebInspector.PropertiesSection.prototype | |
| 353 } | |
| 354 | |
| 355 /** | |
| 356 * @param {!WebInspector.RemoteObjectProperty} propertyA | |
| 357 * @param {!WebInspector.RemoteObjectProperty} propertyB | |
| 358 * @return {number} | |
| 359 */ | |
| 360 WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, pro pertyB) | |
| 361 { | |
| 362 if (propertyA.watchIndex == propertyB.watchIndex) | |
| 363 return 0; | |
| 364 else if (propertyA.watchIndex < propertyB.watchIndex) | |
| 365 return -1; | |
| 366 else | |
| 367 return 1; | |
| 368 } | |
| 369 | |
| 370 /** | |
| 371 * @constructor | |
| 372 * @extends {WebInspector.ObjectPropertyTreeElement} | |
| 373 * @param {!WebInspector.RemoteObjectProperty} property | |
| 374 */ | |
| 375 WebInspector.WatchExpressionTreeElement = function(property) | |
| 376 { | |
| 377 WebInspector.ObjectPropertyTreeElement.call(this, property); | |
| 378 } | |
| 379 | |
| 380 WebInspector.WatchExpressionTreeElement.prototype = { | |
| 381 /** | |
| 382 * @override | |
| 383 * @return {*} | |
| 384 */ | |
| 385 elementIdentity: function() | |
| 386 { | |
| 387 return this.property.name; | |
| 388 }, | |
| 389 | |
| 390 update: function() | |
| 391 { | |
| 392 WebInspector.ObjectPropertyTreeElement.prototype.update.call(this); | |
| 393 | |
| 394 if (this.property.wasThrown) { | |
| 395 this.valueElement.textContent = WebInspector.UIString("<not availabl e>"); | |
| 396 this.listItemElement.classList.add("dimmed"); | |
| 397 } else { | |
| 398 this.listItemElement.classList.remove("dimmed"); | |
| 399 } | |
| 400 | |
| 401 var deleteButton = createElementWithClass("button", "delete-button"); | 336 var deleteButton = createElementWithClass("button", "delete-button"); |
| 402 deleteButton.title = WebInspector.UIString("Delete watch expression"); | 337 deleteButton.title = WebInspector.UIString("Delete watch expression"); |
| 403 deleteButton.addEventListener("click", this._deleteButtonClicked.bind(th is), false); | 338 deleteButton.addEventListener("click", this._updateExpression.bind(this, null), false); |
| 404 this.listItemElement.addEventListener("contextmenu", this._contextMenu.b ind(this), false); | 339 this._element.appendChild(deleteButton); |
| 405 this.listItemElement.insertBefore(deleteButton, this.listItemElement.fir stChild); | 340 |
| 341 var titleElement = createElementWithClass("div", "watch-expression-title "); | |
| 342 | |
| 343 this._nameElement = WebInspector.ObjectPropertiesSection.createNameEleme nt(this._expression); | |
| 344 this._valueElement = WebInspector.ObjectPropertiesSection.createValueEle ment(result, wasThrown, titleElement); | |
| 345 if (wasThrown) { | |
| 346 titleElement.classList.add("dimmed"); | |
| 347 this._valueElement.textContent = WebInspector.UIString("<not availab le>"); | |
| 348 } | |
| 349 var separatorElement = createElementWithClass("span", "separator"); | |
| 350 separatorElement.textContent = ": "; | |
| 351 | |
| 352 titleElement.appendChildren(this._nameElement, separatorElement, this._v alueElement); | |
| 353 if (!wasThrown && result && result.hasChildren) { | |
| 354 var objectPropertiesSection = new WebInspector.ObjectPropertiesSecti on(result, titleElement); | |
| 355 this._objectPresentationElement = objectPropertiesSection.element; | |
| 356 objectPropertiesSection.headerElement.addEventListener("click", this ._onSectionClick.bind(this, objectPropertiesSection), true); | |
| 357 } else { | |
| 358 this._objectPresentationElement = titleElement; | |
| 359 } | |
| 360 | |
| 361 this._element.appendChild(this._objectPresentationElement); | |
| 362 this._element.addEventListener("dblclick", this._dblClickOnWatchExpressi on.bind(this)); | |
| 363 }, | |
| 364 | |
| 365 /** | |
| 366 * @param {!WebInspector.ObjectPropertiesSection} objectPropertiesSection | |
| 367 * @param {!Event} event | |
| 368 */ | |
| 369 _onSectionClick: function(objectPropertiesSection, event) | |
| 370 { | |
| 371 event.consume(true); | |
| 372 if (event.detail == 1) { | |
| 373 this._preventClickTimeout = setTimeout(handleClick, 333); | |
| 374 } else { | |
| 375 clearTimeout(this._preventClickTimeout); | |
| 376 delete this._preventClickTimeout; | |
| 377 } | |
| 378 | |
| 379 function handleClick() { | |
|
pfeldman
2015/02/09 13:13:53
{ next line
sergeyv
2015/02/17 14:22:58
Done.
| |
| 380 if (objectPropertiesSection.expanded) | |
| 381 objectPropertiesSection.collapse(); | |
| 382 else | |
| 383 objectPropertiesSection.expand(); | |
| 384 } | |
| 385 }, | |
| 386 | |
| 387 /** | |
| 388 * @param {!Event} event | |
| 389 */ | |
| 390 _promptKeyDown: function(event) | |
| 391 { | |
| 392 if (isEnterKey(event)) { | |
| 393 this._finishEditing(this._textPrompt.text(), event); | |
| 394 return; | |
| 395 } | |
| 396 if (event.keyIdentifier === "U+001B") { // Esc | |
| 397 this._finishEditing(this._expression, event); | |
| 398 return; | |
| 399 } | |
| 406 }, | 400 }, |
| 407 | 401 |
| 408 /** | 402 /** |
| 409 * @param {!WebInspector.ContextMenu} contextMenu | 403 * @param {!WebInspector.ContextMenu} contextMenu |
| 410 * @override | 404 * @param {!Event} event |
| 411 */ | 405 */ |
| 412 populateContextMenu: function(contextMenu) | 406 _populateContextMenu: function(contextMenu, event) |
| 413 { | 407 { |
| 414 if (!this.isEditing()) { | 408 if (!this.isEditing()) |
| 415 contextMenu.appendItem(WebInspector.UIString.capitalize("Add ^watch ^expression"), this.treeOutline.section.addNewExpressionAndEdit.bind(this.treeOu tline.section)); | 409 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^wat ch ^expression"), this._updateExpression.bind(this, null)); |
| 416 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^wat ch ^expression"), this._deleteButtonClicked.bind(this, null)); | 410 |
| 417 } | 411 if (!this.isEditing() && this._result && (this._result.type === "number" || this._result.type === "string")) |
| 418 if (this.treeOutline.section.watchExpressions.length > 1) | |
| 419 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^all ^watch ^expressions"), this._deleteAllButtonClicked.bind(this)); | |
| 420 if (!this.isEditing() && (this.property.value.type === "number" || this. property.value.type === "string")) | |
| 421 contextMenu.appendItem(WebInspector.UIString.capitalize("Copy ^value "), this._copyValueButtonClicked.bind(this)); | 412 contextMenu.appendItem(WebInspector.UIString.capitalize("Copy ^value "), this._copyValueButtonClicked.bind(this)); |
| 422 }, | 413 |
| 423 | 414 if (this._valueElement.containsEventPoint(event)) |
| 424 _contextMenu: function(event) | 415 contextMenu.appendApplicableItems(this._result); |
| 425 { | |
| 426 var contextMenu = new WebInspector.ContextMenu(event); | |
| 427 this.populateContextMenu(contextMenu); | |
| 428 contextMenu.show(); | |
| 429 }, | |
| 430 | |
| 431 _deleteAllButtonClicked: function() | |
| 432 { | |
| 433 this.treeOutline.section._deleteAllExpressions(); | |
| 434 }, | |
| 435 | |
| 436 _deleteButtonClicked: function(event) | |
| 437 { | |
| 438 if (event) | |
| 439 event.consume(); | |
| 440 this.treeOutline.section.updateExpression(this, null); | |
| 441 }, | 416 }, |
| 442 | 417 |
| 443 _copyValueButtonClicked: function() | 418 _copyValueButtonClicked: function() |
| 444 { | 419 { |
| 445 InspectorFrontendHost.copyText(this.valueElement.textContent); | 420 InspectorFrontendHost.copyText(this._valueElement.textContent); |
| 446 }, | 421 }, |
| 447 | 422 |
| 448 /** | 423 _mouseMove: function() |
| 449 * @override | 424 { |
| 450 * @return {boolean} | 425 this._element.classList.add("hovered"); |
| 451 */ | 426 }, |
| 452 renderPromptAsBlock: function() | 427 |
| 453 { | 428 _mouseLeave: function() |
| 454 return true; | 429 { |
| 455 }, | 430 this._element.classList.remove("hovered"); |
| 456 | 431 }, |
| 457 /** | 432 |
| 458 * @override | 433 __proto__: WebInspector.Object.prototype |
| 459 * @return {{element: !Element, value: (string|undefined)}} | |
| 460 */ | |
| 461 elementAndValueToEdit: function() | |
| 462 { | |
| 463 return { element: this.nameElement, value: this.property.name.trim() }; | |
| 464 }, | |
| 465 | |
| 466 /** | |
| 467 * @override | |
| 468 */ | |
| 469 editingCancelled: function(element, context) | |
| 470 { | |
| 471 if (!context.elementToEdit.textContent) | |
| 472 this.treeOutline.section.updateExpression(this, null); | |
| 473 | |
| 474 WebInspector.ObjectPropertyTreeElement.prototype.editingCancelled.call(t his, element, context); | |
| 475 }, | |
| 476 | |
| 477 /** | |
| 478 * @override | |
| 479 * @param {string} expression | |
| 480 */ | |
| 481 applyExpression: function(expression) | |
| 482 { | |
| 483 expression = expression.trim(); | |
| 484 this.property.name = expression || null; | |
| 485 this.treeOutline.section.updateExpression(this, expression); | |
| 486 }, | |
| 487 | |
| 488 __proto__: WebInspector.ObjectPropertyTreeElement.prototype | |
| 489 } | 434 } |
| OLD | NEW |