| 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 26 matching lines...) Expand all Loading... |
| 37 */ | 37 */ |
| 38 constructor(uiSourceCode) { | 38 constructor(uiSourceCode) { |
| 39 super(uiSourceCode); | 39 super(uiSourceCode); |
| 40 this._debuggerSourceCode = uiSourceCode; | 40 this._debuggerSourceCode = uiSourceCode; |
| 41 | 41 |
| 42 this._scriptsPanel = Sources.SourcesPanel.instance(); | 42 this._scriptsPanel = Sources.SourcesPanel.instance(); |
| 43 this._breakpointManager = Bindings.breakpointManager; | 43 this._breakpointManager = Bindings.breakpointManager; |
| 44 if (uiSourceCode.project().type() === Workspace.projectTypes.Debugger) | 44 if (uiSourceCode.project().type() === Workspace.projectTypes.Debugger) |
| 45 this.element.classList.add('source-frame-debugger-script'); | 45 this.element.classList.add('source-frame-debugger-script'); |
| 46 | 46 |
| 47 this._popoverHelper = new ObjectUI.ObjectPopoverHelper( | 47 this._popoverHelper = new UI.PopoverHelper(this._scriptsPanel.element, true)
; |
| 48 this._scriptsPanel.element, this._getPopoverAnchor.bind(this), this._res
olveObjectForPopover.bind(this), | 48 this._popoverHelper.initializeCallbacks( |
| 49 this._onHidePopover.bind(this), true); | 49 this._getPopoverAnchor.bind(this), this._showObjectPopover.bind(this), t
his._onHidePopover.bind(this)); |
| 50 this._popoverHelper.setTimeout(250, 250); | 50 this._popoverHelper.setTimeout(250, 250); |
| 51 this._popoverHelper.setHasPadding(true); |
| 52 this._scriptsPanel.element.addEventListener( |
| 53 'scroll', this._popoverHelper.hidePopover.bind(this._popoverHelper), tru
e); |
| 51 | 54 |
| 52 this.textEditor.element.addEventListener('keydown', this._onKeyDown.bind(thi
s), true); | 55 this.textEditor.element.addEventListener('keydown', this._onKeyDown.bind(thi
s), true); |
| 53 | 56 |
| 54 this.textEditor.addEventListener( | 57 this.textEditor.addEventListener( |
| 55 SourceFrame.SourcesTextEditor.Events.GutterClick, this._handleGutterClic
k.bind(this), this); | 58 SourceFrame.SourcesTextEditor.Events.GutterClick, this._handleGutterClic
k.bind(this), this); |
| 56 | 59 |
| 57 this._breakpointManager.addEventListener( | 60 this._breakpointManager.addEventListener( |
| 58 Bindings.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded
, this); | 61 Bindings.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded
, this); |
| 59 this._breakpointManager.addEventListener( | 62 this._breakpointManager.addEventListener( |
| 60 Bindings.BreakpointManager.Events.BreakpointRemoved, this._breakpointRem
oved, this); | 63 Bindings.BreakpointManager.Events.BreakpointRemoved, this._breakpointRem
oved, this); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 418 |
| 416 var leftCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, tok
en.startColumn); | 419 var leftCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, tok
en.startColumn); |
| 417 var rightCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, to
ken.endColumn - 1); | 420 var rightCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, to
ken.endColumn - 1); |
| 418 var anchorBox = new AnchorBox(leftCorner.x, leftCorner.y, rightCorner.x - le
ftCorner.x, leftCorner.height); | 421 var anchorBox = new AnchorBox(leftCorner.x, leftCorner.y, rightCorner.x - le
ftCorner.x, leftCorner.height); |
| 419 | 422 |
| 420 anchorBox.highlight = {lineNumber: lineNumber, startColumn: token.startColum
n, endColumn: token.endColumn - 1}; | 423 anchorBox.highlight = {lineNumber: lineNumber, startColumn: token.startColum
n, endColumn: token.endColumn - 1}; |
| 421 | 424 |
| 422 return anchorBox; | 425 return anchorBox; |
| 423 } | 426 } |
| 424 | 427 |
| 425 _resolveObjectForPopover(anchorBox, showCallback, objectGroupName) { | 428 /** |
| 429 * @param {!AnchorBox} anchorBox |
| 430 * @return {!Promise<?SDK.RemoteObject>} |
| 431 */ |
| 432 _resolveObjectForPopover(anchorBox) { |
| 426 var selectedCallFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); | 433 var selectedCallFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); |
| 427 if (!selectedCallFrame) { | 434 if (!selectedCallFrame) |
| 428 this._popoverHelper.hidePopover(); | 435 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null)); |
| 429 return; | |
| 430 } | |
| 431 var lineNumber = anchorBox.highlight.lineNumber; | 436 var lineNumber = anchorBox.highlight.lineNumber; |
| 432 var startHighlight = anchorBox.highlight.startColumn; | 437 var startHighlight = anchorBox.highlight.startColumn; |
| 433 var endHighlight = anchorBox.highlight.endColumn; | 438 var endHighlight = anchorBox.highlight.endColumn; |
| 434 var line = this.textEditor.line(lineNumber); | 439 var line = this.textEditor.line(lineNumber); |
| 435 if (!anchorBox.forSelection) { | 440 if (!anchorBox.forSelection) { |
| 436 while (startHighlight > 1 && line.charAt(startHighlight - 1) === '.') { | 441 while (startHighlight > 1 && line.charAt(startHighlight - 1) === '.') { |
| 437 var token = this.textEditor.tokenAtTextPosition(lineNumber, startHighlig
ht - 2); | 442 var token = this.textEditor.tokenAtTextPosition(lineNumber, startHighlig
ht - 2); |
| 438 if (!token || !token.type) { | 443 if (!token || !token.type) |
| 439 this._popoverHelper.hidePopover(); | 444 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null)); |
| 440 return; | |
| 441 } | |
| 442 startHighlight = token.startColumn; | 445 startHighlight = token.startColumn; |
| 443 } | 446 } |
| 444 } | 447 } |
| 445 var evaluationText = line.substring(startHighlight, endHighlight + 1); | 448 var evaluationText = line.substring(startHighlight, endHighlight + 1); |
| 446 Sources.SourceMapNamesResolver | 449 return Sources.SourceMapNamesResolver |
| 447 .resolveExpression( | 450 .resolveExpression( |
| 448 selectedCallFrame, evaluationText, this._debuggerSourceCode, lineNum
ber, startHighlight, endHighlight) | 451 selectedCallFrame, evaluationText, this._debuggerSourceCode, lineNum
ber, startHighlight, endHighlight) |
| 449 .then(onResolve.bind(this)); | 452 .then(onResolve.bind(this)); |
| 450 | 453 |
| 451 /** | 454 /** |
| 452 * @param {?string=} text | 455 * @param {?string=} text |
| 456 * @return {!Promise<?SDK.RemoteObject>} |
| 453 * @this {Sources.JavaScriptSourceFrame} | 457 * @this {Sources.JavaScriptSourceFrame} |
| 454 */ | 458 */ |
| 455 function onResolve(text) { | 459 function onResolve(text) { |
| 460 var fulfill; |
| 461 var promise = new Promise(x => fulfill = x); |
| 456 selectedCallFrame.evaluate( | 462 selectedCallFrame.evaluate( |
| 457 text || evaluationText, objectGroupName, false, true, false, false, sh
owObjectPopover.bind(this)); | 463 text || evaluationText, 'popover', false, true, false, false, showObje
ctPopover.bind(this, fulfill)); |
| 464 return promise; |
| 458 } | 465 } |
| 459 | 466 |
| 460 /** | 467 /** |
| 468 * @param {function(?SDK.RemoteObject)} fulfill |
| 461 * @param {?Protocol.Runtime.RemoteObject} result | 469 * @param {?Protocol.Runtime.RemoteObject} result |
| 462 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails | 470 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails |
| 463 * @this {Sources.JavaScriptSourceFrame} | 471 * @this {Sources.JavaScriptSourceFrame} |
| 464 */ | 472 */ |
| 465 function showObjectPopover(result, exceptionDetails) { | 473 function showObjectPopover(fulfill, result, exceptionDetails) { |
| 466 var target = UI.context.flavor(SDK.Target); | 474 var target = UI.context.flavor(SDK.Target); |
| 467 var potentiallyUpdatedCallFrame = UI.context.flavor(SDK.DebuggerModel.Call
Frame); | 475 var potentiallyUpdatedCallFrame = UI.context.flavor(SDK.DebuggerModel.Call
Frame); |
| 468 if (selectedCallFrame !== potentiallyUpdatedCallFrame || !result) { | 476 if (selectedCallFrame !== potentiallyUpdatedCallFrame || !result || except
ionDetails) { |
| 469 this._popoverHelper.hidePopover(); | 477 fulfill(null); |
| 470 return; | 478 return; |
| 471 } | 479 } |
| 472 this._popoverAnchorBox = anchorBox; | 480 this._popoverAnchorBox = anchorBox; |
| 473 showCallback(target.runtimeModel.createRemoteObject(result), !!exceptionDe
tails, this._popoverAnchorBox); | 481 this._popoverTarget = target; |
| 474 // Popover may have been removed by showCallback(). | 482 var highlightRange = new Common.TextRange(lineNumber, startHighlight, line
Number, endHighlight); |
| 475 if (this._popoverAnchorBox) { | 483 this._popoverAnchorBox._highlightDescriptor = |
| 476 var highlightRange = new Common.TextRange(lineNumber, startHighlight, li
neNumber, endHighlight); | 484 this.textEditor.highlightRange(highlightRange, 'source-frame-eval-expr
ession'); |
| 477 this._popoverAnchorBox._highlightDescriptor = | 485 fulfill(target.runtimeModel.createRemoteObject(result)); |
| 478 this.textEditor.highlightRange(highlightRange, 'source-frame-eval-ex
pression'); | |
| 479 } | |
| 480 } | 486 } |
| 481 } | 487 } |
| 482 | 488 |
| 489 /** |
| 490 * @param {!AnchorBox|!Element} anchorBox |
| 491 * @param {!UI.GlassPane} popover |
| 492 * @return {!Promise<boolean>} |
| 493 */ |
| 494 _showObjectPopover(anchorBox, popover) { |
| 495 return this._resolveObjectForPopover(/** @type {!AnchorBox} */ (anchorBox)).
then(object => { |
| 496 if (!object) |
| 497 return false; |
| 498 return ObjectUI.ObjectPopoverHelper.buildObjectPopover(object, popover).th
en(objectPopoverHelper => { |
| 499 if (!objectPopoverHelper) { |
| 500 this._onHidePopover(); // Cleanup artifacts from _resolveObjectForPop
over. |
| 501 return false; |
| 502 } |
| 503 this._objectPopoverHelper = objectPopoverHelper; |
| 504 return true; |
| 505 }); |
| 506 }); |
| 507 } |
| 508 |
| 483 _onHidePopover() { | 509 _onHidePopover() { |
| 484 if (!this._popoverAnchorBox) | 510 if (this._objectPopoverHelper) { |
| 485 return; | 511 this._objectPopoverHelper.dispose(); |
| 486 if (this._popoverAnchorBox._highlightDescriptor) | 512 delete this._objectPopoverHelper; |
| 487 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto
r); | 513 } |
| 488 delete this._popoverAnchorBox; | 514 if (this._popoverTarget) { |
| 515 this._popoverTarget.runtimeModel.releaseObjectGroup('popover'); |
| 516 delete this._popoverTarget; |
| 517 } |
| 518 if (this._popoverAnchorBox) { |
| 519 if (this._popoverAnchorBox._highlightDescriptor) |
| 520 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescrip
tor); |
| 521 delete this._popoverAnchorBox; |
| 522 } |
| 489 } | 523 } |
| 490 | 524 |
| 491 _onKeyDown(event) { | 525 _onKeyDown(event) { |
| 492 if (event.key === 'Escape') { | 526 if (event.key === 'Escape') { |
| 493 if (this._popoverHelper.isPopoverVisible()) { | 527 if (this._popoverHelper.isPopoverVisible()) { |
| 494 this._popoverHelper.hidePopover(); | 528 this._popoverHelper.hidePopover(); |
| 495 event.consume(); | 529 event.consume(); |
| 496 } | 530 } |
| 497 } | 531 } |
| 498 } | 532 } |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 return; | 1504 return; |
| 1471 this.bookmark.clear(); | 1505 this.bookmark.clear(); |
| 1472 this.bookmark = null; | 1506 this.bookmark = null; |
| 1473 } | 1507 } |
| 1474 }; | 1508 }; |
| 1475 | 1509 |
| 1476 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol = Symbol('book
mark'); | 1510 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol = Symbol('book
mark'); |
| 1477 Sources.JavaScriptSourceFrame.BreakpointDecoration._elementSymbolForTest = Symbo
l('element'); | 1511 Sources.JavaScriptSourceFrame.BreakpointDecoration._elementSymbolForTest = Symbo
l('element'); |
| 1478 | 1512 |
| 1479 Sources.JavaScriptSourceFrame.continueToLocationDecorationSymbol = Symbol('bookm
ark'); | 1513 Sources.JavaScriptSourceFrame.continueToLocationDecorationSymbol = Symbol('bookm
ark'); |
| OLD | NEW |