1/* 2 * Copyright (C) 2013 University of Washington. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26WebInspector.ProbeSetDetailsSection = function(probeSet) 27{ 28 console.assert(probeSet instanceof WebInspector.ProbeSet, "Invalid ProbeSet argument:", probeSet); 29 30 this._listeners = new WebInspector.EventListenerSet(this, "ProbeSetDetailsSection UI listeners"); 31 this._probeSet = probeSet; 32 33 var optionsElement = document.createElement("div"); 34 optionsElement.classList.add(WebInspector.ProbeSetDetailsSection.SectionOptionsStyleClassName); 35 36 var removeProbeButton = optionsElement.createChild("img"); 37 removeProbeButton.classList.add(WebInspector.ProbeSetDetailsSection.ProbeRemoveStyleClassName); 38 removeProbeButton.classList.add(WebInspector.ProbeSetDetailsSection.ProbeButtonEnabledStyleClassName); 39 this._listeners.register(removeProbeButton, "click", this._removeButtonClicked); 40 41 var clearSamplesButton = optionsElement.createChild("img"); 42 clearSamplesButton.classList.add(WebInspector.ProbeSetDetailsSection.ProbeClearSamplesStyleClassName); 43 clearSamplesButton.classList.add(WebInspector.ProbeSetDetailsSection.ProbeButtonEnabledStyleClassName); 44 this._listeners.register(clearSamplesButton, "click", this._clearSamplesButtonClicked); 45 46 var addProbeButton = optionsElement.createChild("img"); 47 addProbeButton.classList.add(WebInspector.ProbeSetDetailsSection.AddProbeValueStyleClassName); 48 this._listeners.register(addProbeButton, "click", this._addProbeButtonClicked); 49 50 var titleElement = this._probeSetPositionTextOrLink(); 51 titleElement.classList.add(WebInspector.ProbeSetDetailsSection.DontFloatLinkStyleClassName); 52 optionsElement.appendChild(titleElement); 53 54 this._dataGrid = new WebInspector.ProbeSetDataGrid(probeSet); 55 var singletonRow = new WebInspector.DetailsSectionRow; 56 singletonRow.element.appendChild(this._dataGrid.element); 57 var probeSectionGroup = new WebInspector.DetailsSectionGroup([singletonRow]); 58 59 var dummyTitle = ""; 60 WebInspector.DetailsSection.call(this, "probe", dummyTitle, [probeSectionGroup], optionsElement); 61 this.element.classList.add(WebInspector.ProbeSetDetailsSection.StyleClassName); 62 63 this._listeners.install(); 64}; 65 66WebInspector.ProbeSetDetailsSection.AddProbeValueStyleClassName = "probe-add"; 67WebInspector.ProbeSetDetailsSection.DontFloatLinkStyleClassName = "dont-float"; 68WebInspector.ProbeSetDetailsSection.ProbeButtonEnabledStyleClassName = "enabled"; 69WebInspector.ProbeSetDetailsSection.ProbePopoverElementStyleClassName = "probe-popover"; 70WebInspector.ProbeSetDetailsSection.ProbeClearSamplesStyleClassName = "probe-clear-samples"; 71WebInspector.ProbeSetDetailsSection.ProbeRemoveStyleClassName = "probe-remove"; 72WebInspector.ProbeSetDetailsSection.SectionOptionsStyleClassName = "options"; 73WebInspector.ProbeSetDetailsSection.StyleClassName = "probe-set"; 74 75WebInspector.ProbeSetDetailsSection.prototype = { 76 __proto__: WebInspector.DetailsSection.prototype, 77 constructor: WebInspector.ProbeSetDetailsSection, 78 79 // Public 80 81 closed: function() 82 { 83 this._listeners.uninstall(true); 84 this.element.remove(); 85 }, 86 87 // Private 88 89 _probeSetPositionTextOrLink: function() 90 { 91 var breakpoint = this._probeSet.breakpoint; 92 return WebInspector.createSourceCodeLocationLink(breakpoint.sourceCodeLocation); 93 }, 94 95 _addProbeButtonClicked: function(event) 96 { 97 function createProbeFromEnteredExpression(visiblePopover, event) 98 { 99 if (event.keyCode !== 13) 100 return; 101 var expression = event.target.value; 102 this._probeSet.createProbe(expression); 103 visiblePopover.dismiss(); 104 } 105 106 var popover = new WebInspector.Popover; 107 var content = document.createElement("div"); 108 content.classList.add(WebInspector.ProbeSetDetailsSection.ProbePopoverElementStyleClassName); 109 content.createChild("div").textContent = WebInspector.UIString("Add New Probe Expression"); 110 var textBox = content.createChild("input"); 111 textBox.addEventListener("keypress", createProbeFromEnteredExpression.bind(this, popover)); 112 textBox.addEventListener("click", function (event) {event.target.select()}); 113 textBox.type = "text"; 114 textBox.placeholder = WebInspector.UIString("Expression"); 115 popover.content = content; 116 var target = WebInspector.Rect.rectFromClientRect(event.target.getBoundingClientRect()); 117 popover.present(target, [WebInspector.RectEdge.MAX_Y, WebInspector.RectEdge.MIN_Y, WebInspector.RectEdge.MAX_X]); 118 textBox.select(); 119 }, 120 121 _removeButtonClicked: function(event) 122 { 123 this._probeSet.clear(); 124 }, 125 126 _clearSamplesButtonClicked: function(event) 127 { 128 this._probeSet.clearSamples(); 129 } 130}; 131