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

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

Issue 2745903003: [DevTools] Do not inherit ObjectPopoverHelper from PopoverHelper. (Closed)
Patch Set: addressed review comments Created 3 years, 9 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
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 ObjectUI.ObjectPopoverHelper = class {
32 * @unrestricted
33 */
34 ObjectUI.ObjectPopoverHelper = class extends UI.PopoverHelper {
35 /** 32 /**
36 * @param {!Element} panelElement 33 * @param {?Components.Linkifier} linkifier
37 * @param {function(!Element, !Event):(!Element|!AnchorBox|undefined)} getAnch or 34 * @param {boolean} resultHighlightedAsDOM
38 * @param {function(!Element, function(!SDK.RemoteObject, boolean, !Element=): undefined, string):undefined} queryObject
39 * @param {function()=} onHide
40 * @param {boolean=} disableOnClick
41 */ 35 */
42 constructor(panelElement, getAnchor, queryObject, onHide, disableOnClick) { 36 constructor(linkifier, resultHighlightedAsDOM) {
43 super(panelElement, disableOnClick); 37 this._linkifier = linkifier;
44 this.initializeCallbacks(getAnchor, this._showObjectPopover.bind(this), this ._onHideObjectPopover.bind(this)); 38 this._resultHighlightedAsDOM = resultHighlightedAsDOM;
45 this.setHasPadding(true); 39 }
46 this._queryObject = queryObject; 40
47 this._onHideCallback = onHide; 41 dispose() {
48 this._popoverObjectGroup = 'popover'; 42 if (this._resultHighlightedAsDOM)
49 panelElement.addEventListener('scroll', this.hidePopover.bind(this), true); 43 SDK.DOMModel.hideDOMNodeHighlight();
44 if (this._linkifier)
45 this._linkifier.dispose();
50 } 46 }
51 47
52 /** 48 /**
53 * @param {!Element} element 49 * @param {!SDK.RemoteObject} result
54 * @param {!UI.GlassPane} popover 50 * @param {!UI.GlassPane} popover
55 * @return {!Promise<boolean>} 51 * @return {!Promise<?ObjectUI.ObjectPopoverHelper>}
56 */ 52 */
57 _showObjectPopover(element, popover) { 53 static buildObjectPopover(result, popover) {
58 var fulfill; 54 var fulfill;
59 var promise = new Promise(x => fulfill = x); 55 var promise = new Promise(x => fulfill = x);
60 56
61 /** 57 /**
62 * @param {!SDK.RemoteObject} funcObject 58 * @param {!SDK.RemoteObject} funcObject
63 * @param {!Element} popoverContentElement 59 * @param {!Element} popoverContentElement
64 * @param {!Element} popoverValueElement 60 * @param {!Element} popoverValueElement
65 * @param {?Array.<!SDK.RemoteObjectProperty>} properties 61 * @param {?Array.<!SDK.RemoteObjectProperty>} properties
66 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties 62 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties
67 * @this {ObjectUI.ObjectPopoverHelper}
68 */ 63 */
69 function didGetFunctionProperties( 64 function didGetFunctionProperties(
70 funcObject, popoverContentElement, popoverValueElement, properties, inte rnalProperties) { 65 funcObject, popoverContentElement, popoverValueElement, properties, inte rnalProperties) {
71 if (internalProperties) { 66 if (internalProperties) {
72 for (var i = 0; i < internalProperties.length; i++) { 67 for (var i = 0; i < internalProperties.length; i++) {
73 if (internalProperties[i].name === '[[TargetFunction]]') { 68 if (internalProperties[i].name === '[[TargetFunction]]') {
74 funcObject = internalProperties[i].value; 69 funcObject = internalProperties[i].value;
75 break; 70 break;
76 } 71 }
77 } 72 }
78 } 73 }
79 ObjectUI.ObjectPropertiesSection.formatObjectAsFunction(funcObject, popove rValueElement, true); 74 ObjectUI.ObjectPropertiesSection.formatObjectAsFunction(funcObject, popove rValueElement, true);
80 funcObject.debuggerModel() 75 funcObject.debuggerModel()
81 .functionDetailsPromise(funcObject) 76 .functionDetailsPromise(funcObject)
82 .then(didGetFunctionDetails.bind(this, popoverContentElement)); 77 .then(didGetFunctionDetails.bind(null, popoverContentElement));
83 } 78 }
84 79
85 /** 80 /**
86 * @param {!Element} popoverContentElement 81 * @param {!Element} popoverContentElement
87 * @param {?SDK.DebuggerModel.FunctionDetails} response 82 * @param {?SDK.DebuggerModel.FunctionDetails} response
88 * @this {ObjectUI.ObjectPopoverHelper}
89 */ 83 */
90 function didGetFunctionDetails(popoverContentElement, response) { 84 function didGetFunctionDetails(popoverContentElement, response) {
91 if (!response || this._disposed) { 85 if (!response) {
92 fulfill(false); 86 fulfill(null);
93 return; 87 return;
94 } 88 }
95 89
96 var container = createElementWithClass('div', 'object-popover-container'); 90 var container = createElementWithClass('div', 'object-popover-container');
97 var title = container.createChild('div', 'function-popover-title source-co de'); 91 var title = container.createChild('div', 'function-popover-title source-co de');
98 var functionName = title.createChild('span', 'function-name'); 92 var functionName = title.createChild('span', 'function-name');
99 functionName.textContent = UI.beautifyFunctionName(response.functionName); 93 functionName.textContent = UI.beautifyFunctionName(response.functionName);
100 94
101 var rawLocation = response.location; 95 var rawLocation = response.location;
102 var linkContainer = title.createChild('div', 'function-title-link-containe r'); 96 var linkContainer = title.createChild('div', 'function-title-link-containe r');
103 var sourceURL = rawLocation && rawLocation.script() ? rawLocation.script() .sourceURL : null; 97 var sourceURL = rawLocation && rawLocation.script() ? rawLocation.script() .sourceURL : null;
104 if (rawLocation && sourceURL) 98 var linkifier = null;
105 linkContainer.appendChild(this._lazyLinkifier().linkifyRawLocation(rawLo cation, sourceURL)); 99 if (rawLocation && sourceURL) {
100 linkifier = new Components.Linkifier();
101 linkContainer.appendChild(linkifier.linkifyRawLocation(rawLocation, sour ceURL));
102 }
106 container.appendChild(popoverContentElement); 103 container.appendChild(popoverContentElement);
107 popover.contentElement.appendChild(container); 104 popover.contentElement.appendChild(container);
108 fulfill(true); 105 fulfill(new ObjectUI.ObjectPopoverHelper(linkifier, false));
109 } 106 }
110 107
111 /** 108 var description = result.description.trimEnd(ObjectUI.ObjectPopoverHelper.Ma xPopoverTextLength);
112 * @param {!SDK.RemoteObject} result 109 var popoverContentElement = null;
113 * @param {boolean} wasThrown 110 if (result.type !== 'object') {
114 * @param {!Element|!AnchorBox=} anchorOverride 111 popoverContentElement = createElement('span');
115 * @this {ObjectUI.ObjectPopoverHelper} 112 UI.appendStyle(popoverContentElement, 'object_ui/objectValue.css');
116 */ 113 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css');
117 function didQueryObject(result, wasThrown, anchorOverride) { 114 var valueElement = popoverContentElement.createChild('span', 'monospace ob ject-value-' + result.type);
118 if (this._disposed) { 115 valueElement.style.whiteSpace = 'pre';
119 fulfill(false); 116
120 return; 117 if (result.type === 'string')
118 valueElement.createTextChildren('"', description, '"');
119 else if (result.type !== 'function')
120 valueElement.textContent = description;
121
122 if (result.type === 'function') {
123 result.getOwnProperties(
124 false /* generatePreview */,
125 didGetFunctionProperties.bind(null, result, popoverContentElement, v alueElement));
126 return promise;
121 } 127 }
122 if (wasThrown) { 128 popover.contentElement.appendChild(popoverContentElement);
123 this.hidePopover(); 129 fulfill(new ObjectUI.ObjectPopoverHelper(null, false));
124 fulfill(false); 130 } else {
125 return; 131 var linkifier = null;
132 var resultHighlightedAsDOM = false;
133 if (result.subtype === 'node') {
134 SDK.DOMModel.highlightObjectAsDOMNode(result);
135 resultHighlightedAsDOM = true;
126 } 136 }
127 this._objectTarget = result.target(); 137
128 var anchor = anchorOverride || element; 138 if (result.customPreview()) {
129 popover.setContentAnchorBox(anchor instanceof AnchorBox ? anchor : anchor. boxInWindow()); 139 var customPreviewComponent = new ObjectUI.CustomPreviewComponent(result) ;
130 var description = result.description.trimEnd(ObjectUI.ObjectPopoverHelper. MaxPopoverTextLength); 140 customPreviewComponent.expandIfPossible();
131 var popoverContentElement = null; 141 popoverContentElement = customPreviewComponent.element;
132 if (result.type !== 'object') { 142 } else {
133 popoverContentElement = createElement('span'); 143 popoverContentElement = createElementWithClass('div', 'object-popover-co ntent');
134 UI.appendStyle(popoverContentElement, 'object_ui/objectValue.css');
135 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css'); 144 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css');
136 var valueElement = popoverContentElement.createChild('span', 'monospace object-value-' + result.type); 145 var titleElement = popoverContentElement.createChild('div', 'monospace o bject-popover-title');
137 valueElement.style.whiteSpace = 'pre'; 146 titleElement.createChild('span').textContent = description;
138 147 linkifier = new Components.Linkifier();
139 if (result.type === 'string') 148 var section = new ObjectUI.ObjectPropertiesSection(result, '', linkifier );
140 valueElement.createTextChildren('"', description, '"'); 149 section.element.classList.add('object-popover-tree');
141 else if (result.type !== 'function') 150 section.titleLessMode();
142 valueElement.textContent = description; 151 popoverContentElement.appendChild(section.element);
143
144 if (result.type === 'function') {
145 result.getOwnProperties(
146 false /* generatePreview */,
147 didGetFunctionProperties.bind(this, result, popoverContentElement, valueElement));
148 return;
149 }
150 popover.contentElement.appendChild(popoverContentElement);
151 fulfill(true);
152 } else {
153 if (result.subtype === 'node') {
154 SDK.DOMModel.highlightObjectAsDOMNode(result);
155 this._resultHighlightedAsDOM = true;
156 }
157
158 if (result.customPreview()) {
159 var customPreviewComponent = new ObjectUI.CustomPreviewComponent(resul t);
160 customPreviewComponent.expandIfPossible();
161 popoverContentElement = customPreviewComponent.element;
162 } else {
163 popoverContentElement = createElementWithClass('div', 'object-popover- content');
164 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css');
165 var titleElement = popoverContentElement.createChild('div', 'monospace object-popover-title');
166 titleElement.createChild('span').textContent = description;
167 var section = new ObjectUI.ObjectPropertiesSection(result, '', this._l azyLinkifier());
168 section.element.classList.add('object-popover-tree');
169 section.titleLessMode();
170 popoverContentElement.appendChild(section.element);
171 }
172 popover.setMaxContentSize(new UI.Size(300, 250));
173 popover.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactSize);
174 popover.contentElement.appendChild(popoverContentElement);
175 fulfill(true);
176 } 152 }
153 popover.setMaxContentSize(new UI.Size(300, 250));
154 popover.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactSize);
155 popover.contentElement.appendChild(popoverContentElement);
156 fulfill(new ObjectUI.ObjectPopoverHelper(linkifier, resultHighlightedAsDOM ));
177 } 157 }
178 this._disposed = false;
179 this._queryObject(element, didQueryObject.bind(this), this._popoverObjectGro up);
180 return promise; 158 return promise;
181 } 159 }
182
183 _onHideObjectPopover() {
184 this._disposed = true;
185 if (this._resultHighlightedAsDOM) {
186 SDK.DOMModel.hideDOMNodeHighlight();
187 delete this._resultHighlightedAsDOM;
188 }
189 if (this._linkifier) {
190 this._linkifier.dispose();
191 delete this._linkifier;
192 }
193 if (this._onHideCallback)
194 this._onHideCallback();
195 if (this._objectTarget) {
196 this._objectTarget.runtimeModel.releaseObjectGroup(this._popoverObjectGrou p);
197 delete this._objectTarget;
198 }
199 }
200
201 /**
202 * @return {!Components.Linkifier}
203 */
204 _lazyLinkifier() {
205 if (!this._linkifier)
206 this._linkifier = new Components.Linkifier();
207 return this._linkifier;
208 }
209 }; 160 };
210 161
211 ObjectUI.ObjectPopoverHelper.MaxPopoverTextLength = 10000; 162 ObjectUI.ObjectPopoverHelper.MaxPopoverTextLength = 10000;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698