2 * Copyright (C) IBM Corp. 2009 All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of IBM Corp. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.SidebarPane}
35 WebInspector.WatchExpressionsSidebarPane = function()
37 WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions"));
39 this.section = new WebInspector.WatchExpressionsSection();
40 this.bodyElement.appendChild(this.section.element);
42 var refreshButton = document.createElement("button");
43 refreshButton.className = "pane-title-button refresh";
44 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
45 refreshButton.title = WebInspector.UIString("Refresh");
46 this.titleElement.appendChild(refreshButton);
48 var addButton = document.createElement("button");
49 addButton.className = "pane-title-button add";
50 addButton.addEventListener("click", this._addButtonClicked.bind(this), false);
51 this.titleElement.appendChild(addButton);
52 addButton.title = WebInspector.UIString("Add watch expression");
54 this._requiresUpdate = true;
57 WebInspector.WatchExpressionsSidebarPane.prototype = {
60 this._refreshExpressionsIfNeeded();
65 this.refreshExpressions();
68 refreshExpressions: function()
70 this._requiresUpdate = true;
71 this._refreshExpressionsIfNeeded();
74 addExpression: function(expression)
76 this.section.addExpression(expression);
80 _refreshExpressionsIfNeeded: function()
82 if (this._requiresUpdate && this.isShowing()) {
83 this.section.update();
84 delete this._requiresUpdate;
86 this._requiresUpdate = true;
89 _addButtonClicked: function(event)
93 this.section.addNewExpressionAndEdit();
96 _refreshButtonClicked: function(event)
99 this.refreshExpressions();
102 __proto__: WebInspector.SidebarPane.prototype
107 * @extends {WebInspector.ObjectPropertiesSection}
109 WebInspector.WatchExpressionsSection = function()
111 this._watchObjectGroupId = "watch-group";
113 WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
115 this.treeElementConstructor = WebInspector.WatchedPropertyTreeElement;
116 this._expandedExpressions = {};
117 this._expandedProperties = {};
119 this.emptyElement = document.createElement("div");
120 this.emptyElement.className = "info";
121 this.emptyElement.textContent = WebInspector.UIString("No Watch Expressions");
123 this.watchExpressions = WebInspector.settings.watchExpressions.get();
125 this.headerElement.className = "hidden";
126 this.editable = true;
127 this.expanded = true;
128 this.propertiesElement.classList.add("watch-expressions");
130 this.element.addEventListener("mousemove", this._mouseMove.bind(this), true);
131 this.element.addEventListener("mouseout", this._mouseOut.bind(this), true);
132 this.element.addEventListener("dblclick", this._sectionDoubleClick.bind(this), false);
133 this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), false);
136 WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0";
138 WebInspector.WatchExpressionsSection.prototype = {
148 * @param {string} expression
149 * @param {number} watchIndex
150 * @param {?WebInspector.RemoteObject} result
151 * @param {boolean} wasThrown
152 * @this {WebInspector.WatchExpressionsSection}
154 function appendResult(expression, watchIndex, result, wasThrown)
159 var property = new WebInspector.RemoteObjectProperty(expression, result);
160 property.watchIndex = watchIndex;
161 property.wasThrown = wasThrown;
163 // To clarify what's going on here:
164 // In the outer function, we calculate the number of properties
165 // that we're going to be updating, and set that in the
166 // propertyCount variable.
167 // In this function, we test to see when we are processing the
168 // last property, and then call the superclass's updateProperties()
169 // method to get all the properties refreshed at once.
170 properties.push(property);
172 if (properties.length == propertyCount) {
173 this.updateProperties(properties, [], WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressionsSection.CompareProperties);
175 // check to see if we just added a new watch expression,
176 // which will always be the last property
177 if (this._newExpressionAdded) {
178 delete this._newExpressionAdded;
180 var treeElement = this.findAddedTreeElement();
182 treeElement.startEditing();
185 // Force displaying delete button for hovered element.
186 if (this._lastMouseMovePageY)
187 this._updateHoveredElement(this._lastMouseMovePageY);
191 // TODO: pass exact injected script id.
192 RuntimeAgent.releaseObjectGroup(this._watchObjectGroupId)
195 // Count the properties, so we known when to call this.updateProperties()
197 var propertyCount = 0;
198 for (var i = 0; i < this.watchExpressions.length; ++i) {
199 if (!this.watchExpressions[i])
204 // Now process all the expressions, since we have the actual count,
205 // which is checked in the appendResult inner function.
206 for (var i = 0; i < this.watchExpressions.length; ++i) {
207 var expression = this.watchExpressions[i];
211 WebInspector.runtimeModel.evaluate(expression, this._watchObjectGroupId, false, true, false, false, appendResult.bind(this, expression, i));
214 if (!propertyCount) {
215 if (!this.emptyElement.parentNode)
216 this.element.appendChild(this.emptyElement);
218 if (this.emptyElement.parentNode)
219 this.element.removeChild(this.emptyElement);
222 // note this is setting the expansion of the tree, not the section;
223 // with no expressions, and expanded tree, we get some extra vertical
225 this.expanded = (propertyCount != 0);
228 addExpression: function(expression)
230 this.watchExpressions.push(expression);
231 this.saveExpressions();
235 addNewExpressionAndEdit: function()
237 this._newExpressionAdded = true;
238 this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatchExpression);
242 _sectionDoubleClick: function(event)
244 if (event.target !== this.element && event.target !== this.propertiesElement && event.target !== this.emptyElement)
247 this.addNewExpressionAndEdit();
250 updateExpression: function(element, value)
252 if (value === null) {
253 var index = element.property.watchIndex;
254 this.watchExpressions.splice(index, 1);
257 this.watchExpressions[element.property.watchIndex] = value;
258 this.saveExpressions();
262 _deleteAllExpressions: function()
264 this.watchExpressions = [];
265 this.saveExpressions();
270 * @return {?TreeElement}
272 findAddedTreeElement: function()
274 var children = this.propertiesTreeOutline.children;
275 for (var i = 0; i < children.length; ++i) {
276 if (children[i].property.name === WebInspector.WatchExpressionsSection.NewWatchExpression)
285 saveExpressions: function()
288 for (var i = 0; i < this.watchExpressions.length; i++)
289 if (this.watchExpressions[i])
290 toSave.push(this.watchExpressions[i]);
292 WebInspector.settings.watchExpressions.set(toSave);
293 return toSave.length;
296 _mouseMove: function(e)
298 if (this.propertiesElement.firstChild)
299 this._updateHoveredElement(e.pageY);
302 _mouseOut: function()
304 if (this._hoveredElement) {
305 this._hoveredElement.classList.remove("hovered");
306 delete this._hoveredElement;
308 delete this._lastMouseMovePageY;
311 _updateHoveredElement: function(pageY)
313 var candidateElement = this.propertiesElement.firstChild;
315 var next = candidateElement.nextSibling;
316 while (next && !next.clientHeight)
317 next = next.nextSibling;
318 if (!next || next.totalOffsetTop() > pageY)
320 candidateElement = next;
323 if (this._hoveredElement !== candidateElement) {
324 if (this._hoveredElement)
325 this._hoveredElement.classList.remove("hovered");
326 if (candidateElement)
327 candidateElement.classList.add("hovered");
328 this._hoveredElement = candidateElement;
331 this._lastMouseMovePageY = pageY;
334 _emptyElementContextMenu: function(event)
336 var contextMenu = new WebInspector.ContextMenu(event);
337 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add watch expression" : "Add Watch Expression"), this.addNewExpressionAndEdit.bind(this));
341 __proto__: WebInspector.ObjectPropertiesSection.prototype
344 WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, propertyB)
346 if (propertyA.watchIndex == propertyB.watchIndex)
348 else if (propertyA.watchIndex < propertyB.watchIndex)
356 * @extends {WebInspector.ObjectPropertyTreeElement}
357 * @param {!WebInspector.RemoteObjectProperty} property
359 WebInspector.WatchExpressionTreeElement = function(property)
361 WebInspector.ObjectPropertyTreeElement.call(this, property);
364 WebInspector.WatchExpressionTreeElement.prototype = {
367 WebInspector.ObjectPropertyTreeElement.prototype.onexpand.call(this);
368 this.treeOutline.section._expandedExpressions[this._expression()] = true;
371 oncollapse: function()
373 WebInspector.ObjectPropertyTreeElement.prototype.oncollapse.call(this);
374 delete this.treeOutline.section._expandedExpressions[this._expression()];
379 WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
380 if (this.treeOutline.section._expandedExpressions[this._expression()])
381 this.expanded = true;
384 _expression: function()
386 return this.property.name;
391 WebInspector.ObjectPropertyTreeElement.prototype.update.call(this);
393 if (this.property.wasThrown) {
394 this.valueElement.textContent = WebInspector.UIString("<not available>");
395 this.listItemElement.classList.add("dimmed");
397 this.listItemElement.classList.remove("dimmed");
399 var deleteButton = document.createElement("input");
400 deleteButton.type = "button";
401 deleteButton.title = WebInspector.UIString("Delete watch expression.");
402 deleteButton.classList.add("enabled-button");
403 deleteButton.classList.add("delete-button");
404 deleteButton.addEventListener("click", this._deleteButtonClicked.bind(this), false);
405 this.listItemElement.addEventListener("contextmenu", this._contextMenu.bind(this), false);
406 this.listItemElement.insertBefore(deleteButton, this.listItemElement.firstChild);
410 * @param {!WebInspector.ContextMenu} contextMenu
413 populateContextMenu: function(contextMenu)
415 if (!this.isEditing()) {
416 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add watch expression" : "Add Watch Expression"), this.treeOutline.section.addNewExpressionAndEdit.bind(this.treeOutline.section));
417 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Delete watch expression" : "Delete Watch Expression"), this._deleteButtonClicked.bind(this));
419 if (this.treeOutline.section.watchExpressions.length > 1)
420 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Delete all watch expressions" : "Delete All Watch Expressions"), this._deleteAllButtonClicked.bind(this));
423 _contextMenu: function(event)
425 var contextMenu = new WebInspector.ContextMenu(event);
426 this.populateContextMenu(contextMenu);
430 _deleteAllButtonClicked: function()
432 this.treeOutline.section._deleteAllExpressions();
435 _deleteButtonClicked: function()
437 this.treeOutline.section.updateExpression(this, null);
443 renderPromptAsBlock: function()
449 * @param {!Event=} event
450 * @return {!Array.<!Element|string>}
452 elementAndValueToEdit: function(event)
454 return [this.nameElement, this.property.name.trim()];
457 editingCancelled: function(element, context)
459 if (!context.elementToEdit.textContent)
460 this.treeOutline.section.updateExpression(this, null);
462 WebInspector.ObjectPropertyTreeElement.prototype.editingCancelled.call(this, element, context);
465 applyExpression: function(expression, updateInterface)
467 expression = expression.trim();
472 this.property.name = expression;
473 this.treeOutline.section.updateExpression(this, expression);
476 __proto__: WebInspector.ObjectPropertyTreeElement.prototype
482 * @extends {WebInspector.ObjectPropertyTreeElement}
483 * @param {!WebInspector.RemoteObjectProperty} property
485 WebInspector.WatchedPropertyTreeElement = function(property)
487 WebInspector.ObjectPropertyTreeElement.call(this, property);
490 WebInspector.WatchedPropertyTreeElement.prototype = {
493 WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
494 if (this.hasChildren && this.propertyPath() in this.treeOutline.section._expandedProperties)
500 WebInspector.ObjectPropertyTreeElement.prototype.onexpand.call(this);
501 this.treeOutline.section._expandedProperties[this.propertyPath()] = true;
504 oncollapse: function()
506 WebInspector.ObjectPropertyTreeElement.prototype.oncollapse.call(this);
507 delete this.treeOutline.section._expandedProperties[this.propertyPath()];
510 __proto__: WebInspector.ObjectPropertyTreeElement.prototype