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