Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 13 matching lines...) Expand all Loading... | |
| 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 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 ObjectUI.ObjectPopoverHelper = class extends UI.PopoverHelper { | 34 ObjectUI.ObjectPopoverHelper = class { |
| 35 /** | 35 constructor() { |
|
lushnikov
2017/03/13 17:55:02
let's create an instnace with popover and remote o
dgozman
2017/03/13 19:57:24
Done.
| |
| 36 * @param {!Element} panelElement | 36 this._disposed = false; |
| 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.setHasPadding(true); | |
| 46 this._queryObject = queryObject; | |
| 47 this._onHideCallback = onHide; | |
| 48 this._popoverObjectGroup = 'popover'; | |
| 49 panelElement.addEventListener('scroll', this.hidePopover.bind(this), true); | |
| 50 } | 37 } |
| 51 | 38 |
| 52 /** | 39 /** |
| 53 * @param {!Element} element | 40 * @param {!SDK.RemoteObject} result |
| 54 * @param {!UI.GlassPane} popover | 41 * @param {!UI.GlassPane} popover |
| 55 * @return {!Promise<boolean>} | 42 * @return {!Promise<boolean>} |
| 56 */ | 43 */ |
| 57 _showObjectPopover(element, popover) { | 44 buildObjectPopover(result, popover) { |
|
lushnikov
2017/03/13 17:55:02
maybe you can even make this a static factory whic
dgozman
2017/03/13 19:57:24
Done.
| |
| 45 this._disposed = false; | |
| 46 | |
| 58 var fulfill; | 47 var fulfill; |
| 59 var promise = new Promise(x => fulfill = x); | 48 var promise = new Promise(x => fulfill = x); |
| 60 | 49 |
| 61 /** | 50 /** |
| 62 * @param {!SDK.RemoteObject} funcObject | 51 * @param {!SDK.RemoteObject} funcObject |
| 63 * @param {!Element} popoverContentElement | 52 * @param {!Element} popoverContentElement |
| 64 * @param {!Element} popoverValueElement | 53 * @param {!Element} popoverValueElement |
| 65 * @param {?Array.<!SDK.RemoteObjectProperty>} properties | 54 * @param {?Array.<!SDK.RemoteObjectProperty>} properties |
| 66 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties | 55 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties |
| 67 * @this {ObjectUI.ObjectPopoverHelper} | 56 * @this {ObjectUI.ObjectPopoverHelper} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 var rawLocation = response.location; | 90 var rawLocation = response.location; |
| 102 var linkContainer = title.createChild('div', 'function-title-link-containe r'); | 91 var linkContainer = title.createChild('div', 'function-title-link-containe r'); |
| 103 var sourceURL = rawLocation && rawLocation.script() ? rawLocation.script() .sourceURL : null; | 92 var sourceURL = rawLocation && rawLocation.script() ? rawLocation.script() .sourceURL : null; |
| 104 if (rawLocation && sourceURL) | 93 if (rawLocation && sourceURL) |
| 105 linkContainer.appendChild(this._lazyLinkifier().linkifyRawLocation(rawLo cation, sourceURL)); | 94 linkContainer.appendChild(this._lazyLinkifier().linkifyRawLocation(rawLo cation, sourceURL)); |
| 106 container.appendChild(popoverContentElement); | 95 container.appendChild(popoverContentElement); |
| 107 popover.contentElement.appendChild(container); | 96 popover.contentElement.appendChild(container); |
| 108 fulfill(true); | 97 fulfill(true); |
| 109 } | 98 } |
| 110 | 99 |
| 111 /** | 100 var description = result.description.trimEnd(ObjectUI.ObjectPopoverHelper.Ma xPopoverTextLength); |
| 112 * @param {!SDK.RemoteObject} result | 101 var popoverContentElement = null; |
| 113 * @param {boolean} wasThrown | 102 if (result.type !== 'object') { |
|
lushnikov
2017/03/13 17:55:02
brief examination didn't reveal any code changes h
dgozman
2017/03/13 19:57:24
Exactly.
| |
| 114 * @param {!Element|!AnchorBox=} anchorOverride | 103 popoverContentElement = createElement('span'); |
| 115 * @this {ObjectUI.ObjectPopoverHelper} | 104 UI.appendStyle(popoverContentElement, 'object_ui/objectValue.css'); |
| 116 */ | 105 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css'); |
| 117 function didQueryObject(result, wasThrown, anchorOverride) { | 106 var valueElement = popoverContentElement.createChild('span', 'monospace ob ject-value-' + result.type); |
| 118 if (this._disposed) { | 107 valueElement.style.whiteSpace = 'pre'; |
| 119 fulfill(false); | 108 |
| 120 return; | 109 if (result.type === 'string') |
| 110 valueElement.createTextChildren('"', description, '"'); | |
| 111 else if (result.type !== 'function') | |
| 112 valueElement.textContent = description; | |
| 113 | |
| 114 if (result.type === 'function') { | |
| 115 result.getOwnProperties( | |
| 116 false /* generatePreview */, | |
| 117 didGetFunctionProperties.bind(this, result, popoverContentElement, v alueElement)); | |
| 118 return promise; | |
| 121 } | 119 } |
| 122 if (wasThrown) { | 120 popover.contentElement.appendChild(popoverContentElement); |
| 123 this.hidePopover(); | 121 fulfill(true); |
| 124 fulfill(false); | 122 } else { |
| 125 return; | 123 if (result.subtype === 'node') { |
| 124 SDK.DOMModel.highlightObjectAsDOMNode(result); | |
| 125 this._resultHighlightedAsDOM = true; | |
| 126 } | 126 } |
| 127 this._objectTarget = result.target(); | 127 |
| 128 var anchor = anchorOverride || element; | 128 if (result.customPreview()) { |
| 129 popover.setContentAnchorBox(anchor instanceof AnchorBox ? anchor : anchor. boxInWindow()); | 129 var customPreviewComponent = new ObjectUI.CustomPreviewComponent(result) ; |
| 130 var description = result.description.trimEnd(ObjectUI.ObjectPopoverHelper. MaxPopoverTextLength); | 130 customPreviewComponent.expandIfPossible(); |
| 131 var popoverContentElement = null; | 131 popoverContentElement = customPreviewComponent.element; |
| 132 if (result.type !== 'object') { | 132 } else { |
| 133 popoverContentElement = createElement('span'); | 133 popoverContentElement = createElementWithClass('div', 'object-popover-co ntent'); |
| 134 UI.appendStyle(popoverContentElement, 'object_ui/objectValue.css'); | |
| 135 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css'); | 134 UI.appendStyle(popoverContentElement, 'object_ui/objectPopover.css'); |
| 136 var valueElement = popoverContentElement.createChild('span', 'monospace object-value-' + result.type); | 135 var titleElement = popoverContentElement.createChild('div', 'monospace o bject-popover-title'); |
| 137 valueElement.style.whiteSpace = 'pre'; | 136 titleElement.createChild('span').textContent = description; |
| 138 | 137 var section = new ObjectUI.ObjectPropertiesSection(result, '', this._laz yLinkifier()); |
| 139 if (result.type === 'string') | 138 section.element.classList.add('object-popover-tree'); |
| 140 valueElement.createTextChildren('"', description, '"'); | 139 section.titleLessMode(); |
| 141 else if (result.type !== 'function') | 140 popoverContentElement.appendChild(section.element); |
| 142 valueElement.textContent = description; | |
| 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 } | 141 } |
| 142 popover.setMaxContentSize(new UI.Size(300, 250)); | |
| 143 popover.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactSize); | |
| 144 popover.contentElement.appendChild(popoverContentElement); | |
| 145 fulfill(true); | |
| 177 } | 146 } |
| 178 this._disposed = false; | |
| 179 this._queryObject(element, didQueryObject.bind(this), this._popoverObjectGro up); | |
| 180 return promise; | 147 return promise; |
| 181 } | 148 } |
| 182 | 149 |
| 183 _onHideObjectPopover() { | 150 dispose() { |
| 184 this._disposed = true; | 151 this._disposed = true; |
| 185 if (this._resultHighlightedAsDOM) { | 152 if (this._resultHighlightedAsDOM) { |
| 186 SDK.DOMModel.hideDOMNodeHighlight(); | 153 SDK.DOMModel.hideDOMNodeHighlight(); |
| 187 delete this._resultHighlightedAsDOM; | 154 delete this._resultHighlightedAsDOM; |
| 188 } | 155 } |
| 189 if (this._linkifier) { | 156 if (this._linkifier) { |
| 190 this._linkifier.dispose(); | 157 this._linkifier.dispose(); |
| 191 delete this._linkifier; | 158 delete this._linkifier; |
| 192 } | 159 } |
| 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 } | 160 } |
| 200 | 161 |
| 201 /** | 162 /** |
| 202 * @return {!Components.Linkifier} | 163 * @return {!Components.Linkifier} |
| 203 */ | 164 */ |
| 204 _lazyLinkifier() { | 165 _lazyLinkifier() { |
| 205 if (!this._linkifier) | 166 if (!this._linkifier) |
| 206 this._linkifier = new Components.Linkifier(); | 167 this._linkifier = new Components.Linkifier(); |
| 207 return this._linkifier; | 168 return this._linkifier; |
| 208 } | 169 } |
| 209 }; | 170 }; |
| 210 | 171 |
| 211 ObjectUI.ObjectPopoverHelper.MaxPopoverTextLength = 10000; | 172 ObjectUI.ObjectPopoverHelper.MaxPopoverTextLength = 10000; |
| OLD | NEW |