1/*
2 * Copyright (C) 2011 Google Inc. 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 are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31WebInspector.ObjectPopoverHelper = function(panelElement, getAnchor, queryObject, onHide, disableOnClick)
32{
33 WebInspector.PopoverHelper.call(this, panelElement, getAnchor, this._showObjectPopover.bind(this), onHide, disableOnClick);
34 this._queryObject = queryObject;
35 panelElement.addEventListener("scroll", this.hidePopover.bind(this), true);
36};
37
38WebInspector.ObjectPopoverHelper.prototype = {
39 _showObjectPopover: function(element, popover)
40 {
41 function showObjectPopover(result, wasThrown)
42 {
43 if (popover.disposed)
44 return;
45 if (wasThrown) {
46 this.hidePopover();
47 return;
48 }
49 var popoverContentElement = null;
50 if (result.type !== "object") {
51 popoverContentElement = document.createElement("span");
52 popoverContentElement.className = "monospace console-formatted-" + result.type;
53 popoverContentElement.style.whiteSpace = "pre";
54 popoverContentElement.textContent = result.description;
55 if (result.type === "string")
56 popoverContentElement.textContent = "\"" + popoverContentElement.textContent + "\"";
57 popover.show(popoverContentElement, element);
58 } else {
59 popoverContentElement = document.createElement("div");
60
61 var titleElement = document.createElement("div");
62 titleElement.className = "source-frame-popover-title monospace";
63 titleElement.textContent = result.description;
64 popoverContentElement.appendChild(titleElement);
65
66 var section = new WebInspector.ObjectPropertiesSection(result);
67 // For HTML DOM wrappers, append "#id" to title, if not empty.
68 if (result.description.substr(0, 4) === "HTML") {
69 var oldUpdateProperties = section.updateProperties;
70 section.updateProperties = function(properties, rootTreeElementConstructor, rootPropertyComparer)
71 {
72 for (var i = 0; i < properties.length; ++i) {
73 if (properties[i].name === "id") {
74 if (properties[i].value.description)
75 titleElement.textContent += "#" + properties[i].value.description;
76 break;
77 }
78 }
79 oldUpdateProperties.call(this, properties, rootTreeElementConstructor, rootPropertyComparer);
80 };
81 }
82 section.expanded = true;
83 section.element.addStyleClass("source-frame-popover-tree");
84 section.headerElement.addStyleClass("hidden");
85 popoverContentElement.appendChild(section.element);
86
87 const popoverWidth = 300;
88 const popoverHeight = 250;
89 popover.show(popoverContentElement, element, popoverWidth, popoverHeight);
90 }
91 }
92 this._queryObject(element, showObjectPopover.bind(this));
93 }
94}
95
96WebInspector.ObjectPopoverHelper.prototype.__proto__ = WebInspector.PopoverHelper.prototype;