2 * Copyright (C) 2011 Google Inc. 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 Google Inc. 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.PopoverHelper}
34 * @param {!Element} panelElement
35 * @param {function(!Element, !Event):(!Element|!AnchorBox|undefined)} getAnchor
36 * @param {function(!Element, function(!WebInspector.RemoteObject, boolean, !Element=):undefined, string):undefined} queryObject
37 * @param {function()=} onHide
38 * @param {boolean=} disableOnClick
40 WebInspector.ObjectPopoverHelper = function(panelElement, getAnchor, queryObject, onHide, disableOnClick)
42 WebInspector.PopoverHelper.call(this, panelElement, getAnchor, this._showObjectPopover.bind(this), this._onHideObjectPopover.bind(this), disableOnClick);
43 this._queryObject = queryObject;
44 this._onHideCallback = onHide;
45 this._popoverObjectGroup = "popover";
46 panelElement.addEventListener("scroll", this.hidePopover.bind(this), true);
49 WebInspector.ObjectPopoverHelper.MaxPopoverTextLength = 10000;
51 WebInspector.ObjectPopoverHelper.prototype = {
53 * @param {function(!WebInspector.RemoteObject):string} formatter
55 setRemoteObjectFormatter: function(formatter)
57 this._remoteObjectFormatter = formatter;
61 * @param {!Element} element
62 * @param {!WebInspector.Popover} popover
64 _showObjectPopover: function(element, popover)
67 * @param {!WebInspector.Target} target
68 * @param {!Element} anchorElement
69 * @param {!Element} popoverContentElement
70 * @param {?WebInspector.DebuggerModel.FunctionDetails} response
71 * @this {WebInspector.ObjectPopoverHelper}
73 function didGetDetails(target, anchorElement, popoverContentElement, response)
78 var container = createElement("div");
79 container.className = "inline-block";
81 var title = container.createChild("div", "function-popover-title source-code");
82 var functionName = title.createChild("span", "function-name");
83 functionName.textContent = response.functionName || WebInspector.UIString("(anonymous function)");
85 var rawLocation = response.location;
86 var sourceURL = response.sourceURL;
87 if (rawLocation && sourceURL) {
88 this._linkifier = new WebInspector.Linkifier();
89 var link = this._linkifier.linkifyRawLocation(rawLocation, sourceURL, "function-location-link");
90 title.appendChild(link);
93 container.appendChild(popoverContentElement);
94 popover.show(container, anchorElement);
98 * @param {!WebInspector.RemoteObject} result
99 * @param {boolean} wasThrown
100 * @param {!Element=} anchorOverride
101 * @this {WebInspector.ObjectPopoverHelper}
103 function showObjectPopover(result, wasThrown, anchorOverride)
105 if (popover.disposed)
111 this._objectTarget = result.target();
112 var anchorElement = anchorOverride || element;
113 var description = (this._remoteObjectFormatter && this._remoteObjectFormatter(result)) || result.description;
114 description = description.trimEnd(WebInspector.ObjectPopoverHelper.MaxPopoverTextLength);
115 var popoverContentElement = null;
116 if (result.type !== "object") {
117 popoverContentElement = createElement("span");
118 popoverContentElement.className = "monospace console-formatted-" + result.type;
119 popoverContentElement.style.whiteSpace = "pre";
120 if (result.type === "string")
121 popoverContentElement.createTextChildren("\"", description, "\"");
123 popoverContentElement.textContent = description;
124 if (result.type === "function") {
125 result.functionDetails(didGetDetails.bind(this, result.target(), anchorElement, popoverContentElement));
128 popover.show(popoverContentElement, anchorElement);
130 if (result.subtype === "node") {
131 result.highlightAsDOMNode();
132 this._resultHighlightedAsDOM = result;
134 popoverContentElement = createElement("div");
135 this._titleElement = createElement("div");
136 this._titleElement.className = "source-frame-popover-title monospace";
137 this._titleElement.textContent = description;
138 popoverContentElement.appendChild(this._titleElement);
140 var section = new WebInspector.ObjectPropertiesSection(result);
141 // For HTML DOM wrappers, append "#id" to title, if not empty.
142 if (description.substr(0, 4) === "HTML") {
143 this._sectionUpdateProperties = section.updateProperties.bind(section);
144 section.updateProperties = this._updateHTMLId.bind(this);
146 section.expanded = true;
147 section.element.classList.add("source-frame-popover-tree");
148 section.headerElement.classList.add("hidden");
149 popoverContentElement.appendChild(section.element);
151 const popoverWidth = 300;
152 const popoverHeight = 250;
153 popover.show(popoverContentElement, anchorElement, popoverWidth, popoverHeight);
156 this._queryObject(element, showObjectPopover.bind(this), this._popoverObjectGroup);
159 _onHideObjectPopover: function()
161 if (this._resultHighlightedAsDOM) {
162 this._resultHighlightedAsDOM.target().domModel.hideDOMNodeHighlight();
163 delete this._resultHighlightedAsDOM;
165 if (this._linkifier) {
166 this._linkifier.reset();
167 delete this._linkifier;
169 if (this._onHideCallback)
170 this._onHideCallback();
171 if (this._objectTarget) {
172 this._objectTarget.runtimeAgent().releaseObjectGroup(this._popoverObjectGroup);
173 delete this._objectTarget;
177 _updateHTMLId: function(properties, rootTreeElementConstructor, rootPropertyComparer)
179 for (var i = 0; i < properties.length; ++i) {
180 if (properties[i].name === "id") {
181 if (properties[i].value.description)
182 this._titleElement.textContent += "#" + properties[i].value.description;
186 this._sectionUpdateProperties(properties, rootTreeElementConstructor, rootPropertyComparer);
189 __proto__: WebInspector.PopoverHelper.prototype