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.prototype = {
51 * @param {function(!WebInspector.RemoteObject):string} formatter
53 setRemoteObjectFormatter: function(formatter)
55 this._remoteObjectFormatter = formatter;
59 * @param {!Element} element
60 * @param {!WebInspector.Popover} popover
62 _showObjectPopover: function(element, popover)
65 * @param {!WebInspector.Target} target
66 * @param {!Element} anchorElement
67 * @param {!Element} popoverContentElement
68 * @param {?WebInspector.DebuggerModel.FunctionDetails} response
69 * @this {WebInspector.ObjectPopoverHelper}
71 function didGetDetails(target, anchorElement, popoverContentElement, response)
76 var container = document.createElement("div");
77 container.className = "inline-block";
79 var title = container.createChild("div", "function-popover-title source-code");
80 var functionName = title.createChild("span", "function-name");
81 functionName.textContent = response.functionName || WebInspector.UIString("(anonymous function)");
83 var rawLocation = response.location;
84 var sourceURL = response.sourceURL;
85 if (rawLocation && sourceURL) {
86 this._linkifier = new WebInspector.Linkifier();
87 var link = this._linkifier.linkifyRawLocation(rawLocation, sourceURL, "function-location-link");
88 title.appendChild(link);
91 container.appendChild(popoverContentElement);
92 popover.show(container, anchorElement);
96 * @param {!WebInspector.RemoteObject} result
97 * @param {boolean} wasThrown
98 * @param {!Element=} anchorOverride
99 * @this {WebInspector.ObjectPopoverHelper}
101 function showObjectPopover(result, wasThrown, anchorOverride)
103 if (popover.disposed)
109 this._objectTarget = result.target();
110 var anchorElement = anchorOverride || element;
111 var description = (this._remoteObjectFormatter && this._remoteObjectFormatter(result)) || result.description;
113 var popoverContentElement = null;
114 if (result.type !== "object") {
115 popoverContentElement = document.createElement("span");
116 popoverContentElement.className = "monospace console-formatted-" + result.type;
117 popoverContentElement.style.whiteSpace = "pre";
118 if (result.type === "string")
119 popoverContentElement.createTextChildren("\"", description, "\"");
121 popoverContentElement.textContent = description;
122 if (result.type === "function") {
123 result.functionDetails(didGetDetails.bind(this, result.target(), anchorElement, popoverContentElement));
126 popover.show(popoverContentElement, anchorElement);
128 if (result.subtype === "node") {
129 result.highlightAsDOMNode();
130 this._resultHighlightedAsDOM = result;
132 popoverContentElement = document.createElement("div");
133 this._titleElement = document.createElement("div");
134 this._titleElement.className = "source-frame-popover-title monospace";
135 this._titleElement.textContent = description;
136 popoverContentElement.appendChild(this._titleElement);
138 var section = new WebInspector.ObjectPropertiesSection(result);
139 // For HTML DOM wrappers, append "#id" to title, if not empty.
140 if (description.substr(0, 4) === "HTML") {
141 this._sectionUpdateProperties = section.updateProperties.bind(section);
142 section.updateProperties = this._updateHTMLId.bind(this);
144 section.expanded = true;
145 section.element.classList.add("source-frame-popover-tree");
146 section.headerElement.classList.add("hidden");
147 popoverContentElement.appendChild(section.element);
149 const popoverWidth = 300;
150 const popoverHeight = 250;
151 popover.show(popoverContentElement, anchorElement, popoverWidth, popoverHeight);
154 this._queryObject(element, showObjectPopover.bind(this), this._popoverObjectGroup);
157 _onHideObjectPopover: function()
159 if (this._resultHighlightedAsDOM) {
160 this._resultHighlightedAsDOM.target().domModel.hideDOMNodeHighlight();
161 delete this._resultHighlightedAsDOM;
163 if (this._linkifier) {
164 this._linkifier.reset();
165 delete this._linkifier;
167 if (this._onHideCallback)
168 this._onHideCallback();
169 if (this._objectTarget) {
170 this._objectTarget.runtimeAgent().releaseObjectGroup(this._popoverObjectGroup);
171 delete this._objectTarget;
175 _updateHTMLId: function(properties, rootTreeElementConstructor, rootPropertyComparer)
177 for (var i = 0; i < properties.length; ++i) {
178 if (properties[i].name === "id") {
179 if (properties[i].value.description)
180 this._titleElement.textContent += "#" + properties[i].value.description;
184 this._sectionUpdateProperties(properties, rootTreeElementConstructor, rootPropertyComparer);
187 __proto__: WebInspector.PopoverHelper.prototype