Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/ObjectPopoverHelper.js

Issue 2712513002: DevTools: extract ObjectUI module from Components (Closed)
Patch Set: fix build.gn Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
31 /**
32 * @unrestricted
33 */
34 Components.ObjectPopoverHelper = class extends UI.PopoverHelper {
35 /**
36 * @param {!Element} panelElement
37 * @param {function(!Element, !Event):(!Element|!AnchorBox|undefined)} getAnch or
38 * @param {function(!Element, function(!SDK.RemoteObject, boolean, !Element=): undefined, string):undefined} queryObject
39 * @param {function()=} onHide
40 * @param {boolean=} disableOnClick
41 */
42 constructor(panelElement, getAnchor, queryObject, onHide, disableOnClick) {
43 super(panelElement, disableOnClick);
44 this.initializeCallbacks(getAnchor, this._showObjectPopover.bind(this), this ._onHideObjectPopover.bind(this));
45 this._queryObject = queryObject;
46 this._onHideCallback = onHide;
47 this._popoverObjectGroup = 'popover';
48 panelElement.addEventListener('scroll', this.hidePopover.bind(this), true);
49 }
50
51 /**
52 * @param {!Element} element
53 * @param {!UI.Popover} popover
54 */
55 _showObjectPopover(element, popover) {
56 /**
57 * @param {!SDK.RemoteObject} funcObject
58 * @param {!Element} popoverContentElement
59 * @param {!Element} popoverValueElement
60 * @param {!Element} anchorElement
61 * @param {?Array.<!SDK.RemoteObjectProperty>} properties
62 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties
63 * @this {Components.ObjectPopoverHelper}
64 */
65 function didGetFunctionProperties(
66 funcObject, popoverContentElement, popoverValueElement, anchorElement, p roperties, internalProperties) {
67 if (internalProperties) {
68 for (var i = 0; i < internalProperties.length; i++) {
69 if (internalProperties[i].name === '[[TargetFunction]]') {
70 funcObject = internalProperties[i].value;
71 break;
72 }
73 }
74 }
75 Components.ObjectPropertiesSection.formatObjectAsFunction(funcObject, popo verValueElement, true);
76 funcObject.debuggerModel()
77 .functionDetailsPromise(funcObject)
78 .then(didGetFunctionDetails.bind(this, popoverContentElement, anchorEl ement));
79 }
80
81 /**
82 * @param {!Element} popoverContentElement
83 * @param {!Element} anchorElement
84 * @param {?SDK.DebuggerModel.FunctionDetails} response
85 * @this {Components.ObjectPopoverHelper}
86 */
87 function didGetFunctionDetails(popoverContentElement, anchorElement, respons e) {
88 if (!response || popover.disposed)
89 return;
90
91 var container = createElementWithClass('div', 'object-popover-container');
92 var title = container.createChild('div', 'function-popover-title source-co de');
93 var functionName = title.createChild('span', 'function-name');
94 functionName.textContent = UI.beautifyFunctionName(response.functionName);
95
96 var rawLocation = response.location;
97 var linkContainer = title.createChild('div', 'function-title-link-containe r');
98 if (rawLocation && Runtime.experiments.isEnabled('continueToFirstInvocatio n')) {
99 var sectionToolbar = new UI.Toolbar('function-location-step-into', linkC ontainer);
100 var stepInto = new UI.ToolbarButton(Common.UIString('Continue to first i nvocation'), 'largeicon-step-in');
101 stepInto.addEventListener(UI.ToolbarButton.Events.Click, () => rawLocati on.continueToLocation());
102 sectionToolbar.appendToolbarItem(stepInto);
103 }
104 var sourceURL = rawLocation && rawLocation.script() ? rawLocation.script() .sourceURL : null;
105 if (rawLocation && sourceURL)
106 linkContainer.appendChild(this._lazyLinkifier().linkifyRawLocation(rawLo cation, sourceURL));
107 container.appendChild(popoverContentElement);
108 popover.showForAnchor(container, anchorElement);
109 }
110
111 /**
112 * @param {!SDK.RemoteObject} result
113 * @param {boolean} wasThrown
114 * @param {!Element=} anchorOverride
115 * @this {Components.ObjectPopoverHelper}
116 */
117 function didQueryObject(result, wasThrown, anchorOverride) {
118 if (popover.disposed)
119 return;
120 if (wasThrown) {
121 this.hidePopover();
122 return;
123 }
124 this._objectTarget = result.target();
125 var anchorElement = anchorOverride || element;
126 var description = result.description.trimEnd(Components.ObjectPopoverHelpe r.MaxPopoverTextLength);
127 var popoverContentElement = null;
128 if (result.type !== 'object') {
129 popoverContentElement = createElement('span');
130 UI.appendStyle(popoverContentElement, 'components/objectValue.css');
131 var valueElement = popoverContentElement.createChild('span', 'monospace object-value-' + result.type);
132 valueElement.style.whiteSpace = 'pre';
133
134 if (result.type === 'string')
135 valueElement.createTextChildren('"', description, '"');
136 else if (result.type !== 'function')
137 valueElement.textContent = description;
138
139 if (result.type === 'function') {
140 result.getOwnProperties(
141 false /* generatePreview */,
142 didGetFunctionProperties.bind(this, result, popoverContentElement, valueElement, anchorElement));
143 return;
144 }
145 popover.showForAnchor(popoverContentElement, anchorElement);
146 } else {
147 if (result.subtype === 'node') {
148 SDK.DOMModel.highlightObjectAsDOMNode(result);
149 this._resultHighlightedAsDOM = true;
150 }
151
152 if (result.customPreview()) {
153 var customPreviewComponent = new Components.CustomPreviewComponent(res ult);
154 customPreviewComponent.expandIfPossible();
155 popoverContentElement = customPreviewComponent.element;
156 } else {
157 popoverContentElement = createElement('div');
158 this._titleElement = popoverContentElement.createChild('div', 'monospa ce');
159 this._titleElement.createChild('span', 'source-frame-popover-title').t extContent = description;
160 var section = new Components.ObjectPropertiesSection(result, '', this. _lazyLinkifier());
161 section.element.classList.add('source-frame-popover-tree');
162 section.titleLessMode();
163 popoverContentElement.appendChild(section.element);
164 }
165 var popoverWidth = 300;
166 var popoverHeight = 250;
167 popover.showForAnchor(popoverContentElement, anchorElement, popoverWidth , popoverHeight);
168 }
169 }
170 this._queryObject(element, didQueryObject.bind(this), this._popoverObjectGro up);
171 }
172
173 _onHideObjectPopover() {
174 if (this._resultHighlightedAsDOM) {
175 SDK.DOMModel.hideDOMNodeHighlight();
176 delete this._resultHighlightedAsDOM;
177 }
178 if (this._linkifier) {
179 this._linkifier.dispose();
180 delete this._linkifier;
181 }
182 if (this._onHideCallback)
183 this._onHideCallback();
184 if (this._objectTarget) {
185 this._objectTarget.runtimeAgent().releaseObjectGroup(this._popoverObjectGr oup);
186 delete this._objectTarget;
187 }
188 }
189
190 /**
191 * @return {!Components.Linkifier}
192 */
193 _lazyLinkifier() {
194 if (!this._linkifier)
195 this._linkifier = new Components.Linkifier();
196 return this._linkifier;
197 }
198 };
199
200 Components.ObjectPopoverHelper.MaxPopoverTextLength = 10000;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698