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 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._objectPopoverHelper = new ObjectUI.ObjectPopoverHelper(); | |
| 53 this._scriptsPanel.element.addEventListener( | |
| 54 'scroll', this._popoverHelper.hidePopover.bind(this._popoverHelper), tru e); | |
| 51 | 55 |
| 52 this.textEditor.element.addEventListener('keydown', this._onKeyDown.bind(thi s), true); | 56 this.textEditor.element.addEventListener('keydown', this._onKeyDown.bind(thi s), true); |
| 53 | 57 |
| 54 this.textEditor.addEventListener( | 58 this.textEditor.addEventListener( |
| 55 SourceFrame.SourcesTextEditor.Events.GutterClick, this._handleGutterClic k.bind(this), this); | 59 SourceFrame.SourcesTextEditor.Events.GutterClick, this._handleGutterClic k.bind(this), this); |
| 56 | 60 |
| 57 this._breakpointManager.addEventListener( | 61 this._breakpointManager.addEventListener( |
| 58 Bindings.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded , this); | 62 Bindings.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded , this); |
| 59 this._breakpointManager.addEventListener( | 63 this._breakpointManager.addEventListener( |
| 60 Bindings.BreakpointManager.Events.BreakpointRemoved, this._breakpointRem oved, this); | 64 Bindings.BreakpointManager.Events.BreakpointRemoved, this._breakpointRem oved, this); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 419 |
| 416 var leftCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, tok en.startColumn); | 420 var leftCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, tok en.startColumn); |
| 417 var rightCorner = this.textEditor.cursorPositionToCoordinates(lineNumber, to ken.endColumn - 1); | 421 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); | 422 var anchorBox = new AnchorBox(leftCorner.x, leftCorner.y, rightCorner.x - le ftCorner.x, leftCorner.height); |
| 419 | 423 |
| 420 anchorBox.highlight = {lineNumber: lineNumber, startColumn: token.startColum n, endColumn: token.endColumn - 1}; | 424 anchorBox.highlight = {lineNumber: lineNumber, startColumn: token.startColum n, endColumn: token.endColumn - 1}; |
| 421 | 425 |
| 422 return anchorBox; | 426 return anchorBox; |
| 423 } | 427 } |
| 424 | 428 |
| 425 _resolveObjectForPopover(anchorBox, showCallback, objectGroupName) { | 429 /** |
| 430 * @param {!AnchorBox} anchorBox | |
| 431 * @return {!Promise<?SDK.RemoteObject>} | |
| 432 */ | |
| 433 _resolveObjectForPopover(anchorBox) { | |
| 426 var selectedCallFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); | 434 var selectedCallFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); |
| 427 if (!selectedCallFrame) { | 435 if (!selectedCallFrame) |
| 428 this._popoverHelper.hidePopover(); | 436 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null)); |
| 429 return; | |
| 430 } | |
| 431 var lineNumber = anchorBox.highlight.lineNumber; | 437 var lineNumber = anchorBox.highlight.lineNumber; |
| 432 var startHighlight = anchorBox.highlight.startColumn; | 438 var startHighlight = anchorBox.highlight.startColumn; |
| 433 var endHighlight = anchorBox.highlight.endColumn; | 439 var endHighlight = anchorBox.highlight.endColumn; |
| 434 var line = this.textEditor.line(lineNumber); | 440 var line = this.textEditor.line(lineNumber); |
| 435 if (!anchorBox.forSelection) { | 441 if (!anchorBox.forSelection) { |
| 436 while (startHighlight > 1 && line.charAt(startHighlight - 1) === '.') { | 442 while (startHighlight > 1 && line.charAt(startHighlight - 1) === '.') { |
| 437 var token = this.textEditor.tokenAtTextPosition(lineNumber, startHighlig ht - 2); | 443 var token = this.textEditor.tokenAtTextPosition(lineNumber, startHighlig ht - 2); |
| 438 if (!token || !token.type) { | 444 if (!token || !token.type) |
| 439 this._popoverHelper.hidePopover(); | 445 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null)); |
| 440 return; | |
| 441 } | |
| 442 startHighlight = token.startColumn; | 446 startHighlight = token.startColumn; |
| 443 } | 447 } |
| 444 } | 448 } |
| 445 var evaluationText = line.substring(startHighlight, endHighlight + 1); | 449 var evaluationText = line.substring(startHighlight, endHighlight + 1); |
| 446 Sources.SourceMapNamesResolver | 450 return Sources.SourceMapNamesResolver |
| 447 .resolveExpression( | 451 .resolveExpression( |
| 448 selectedCallFrame, evaluationText, this._debuggerSourceCode, lineNum ber, startHighlight, endHighlight) | 452 selectedCallFrame, evaluationText, this._debuggerSourceCode, lineNum ber, startHighlight, endHighlight) |
| 449 .then(onResolve.bind(this)); | 453 .then(onResolve.bind(this)); |
| 450 | 454 |
| 451 /** | 455 /** |
| 452 * @param {?string=} text | 456 * @param {?string=} text |
| 457 * @return {!Promise<?SDK.RemoteObject>} | |
| 453 * @this {Sources.JavaScriptSourceFrame} | 458 * @this {Sources.JavaScriptSourceFrame} |
| 454 */ | 459 */ |
| 455 function onResolve(text) { | 460 function onResolve(text) { |
| 461 var fulfill; | |
| 462 var promise = new Promise(x => fulfill = x); | |
| 456 selectedCallFrame.evaluate( | 463 selectedCallFrame.evaluate( |
| 457 text || evaluationText, objectGroupName, false, true, false, false, sh owObjectPopover.bind(this)); | 464 text || evaluationText, 'popover', false, true, false, false, showObje ctPopover.bind(this, fulfill)); |
| 465 return promise; | |
| 458 } | 466 } |
| 459 | 467 |
| 460 /** | 468 /** |
| 469 * @param {function(?SDK.RemoteObject)} fulfill | |
| 461 * @param {?Protocol.Runtime.RemoteObject} result | 470 * @param {?Protocol.Runtime.RemoteObject} result |
| 462 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails | 471 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails |
| 463 * @this {Sources.JavaScriptSourceFrame} | 472 * @this {Sources.JavaScriptSourceFrame} |
| 464 */ | 473 */ |
| 465 function showObjectPopover(result, exceptionDetails) { | 474 function showObjectPopover(fulfill, result, exceptionDetails) { |
| 466 var target = UI.context.flavor(SDK.Target); | 475 var target = UI.context.flavor(SDK.Target); |
| 467 var potentiallyUpdatedCallFrame = UI.context.flavor(SDK.DebuggerModel.Call Frame); | 476 var potentiallyUpdatedCallFrame = UI.context.flavor(SDK.DebuggerModel.Call Frame); |
| 468 if (selectedCallFrame !== potentiallyUpdatedCallFrame || !result) { | 477 if (selectedCallFrame !== potentiallyUpdatedCallFrame || !result || except ionDetails) { |
| 469 this._popoverHelper.hidePopover(); | 478 fulfill(null); |
| 470 return; | 479 return; |
| 471 } | 480 } |
| 472 this._popoverAnchorBox = anchorBox; | 481 this._popoverAnchorBox = anchorBox; |
| 473 showCallback(target.runtimeModel.createRemoteObject(result), !!exceptionDe tails, this._popoverAnchorBox); | 482 this._popoverTarget = target; |
| 474 // Popover may have been removed by showCallback(). | 483 fulfill(target.runtimeModel.createRemoteObject(result)); |
| 484 // Popover may have been removed by callback(). | |
|
lushnikov
2017/03/13 17:55:02
since with your change the callback will run in a
dgozman
2017/03/13 19:57:24
Done.
| |
| 475 if (this._popoverAnchorBox) { | 485 if (this._popoverAnchorBox) { |
| 476 var highlightRange = new Common.TextRange(lineNumber, startHighlight, li neNumber, endHighlight); | 486 var highlightRange = new Common.TextRange(lineNumber, startHighlight, li neNumber, endHighlight); |
| 477 this._popoverAnchorBox._highlightDescriptor = | 487 this._popoverAnchorBox._highlightDescriptor = |
| 478 this.textEditor.highlightRange(highlightRange, 'source-frame-eval-ex pression'); | 488 this.textEditor.highlightRange(highlightRange, 'source-frame-eval-ex pression'); |
| 479 } | 489 } |
| 480 } | 490 } |
| 481 } | 491 } |
| 482 | 492 |
| 493 /** | |
| 494 * @param {!AnchorBox|!Element} anchorBox | |
| 495 * @param {!UI.GlassPane} popover | |
| 496 * @return {!Promise<boolean>} | |
| 497 */ | |
| 498 _showObjectPopover(anchorBox, popover) { | |
| 499 return this._resolveObjectForPopover(/** @type {!AnchorBox} */ (anchorBox)). then(object => { | |
| 500 if (!object) | |
| 501 return false; | |
| 502 return this._objectPopoverHelper.buildObjectPopover(object, popover); | |
| 503 }); | |
| 504 } | |
| 505 | |
| 483 _onHidePopover() { | 506 _onHidePopover() { |
| 507 this._objectPopoverHelper.dispose(); | |
|
lushnikov
2017/03/13 17:55:02
the this._objectPopoverHelper is created in the JS
dgozman
2017/03/13 19:57:24
Done.
| |
| 508 if (this._popoverTarget) { | |
| 509 this._popoverTarget.runtimeModel.releaseObjectGroup('popover'); | |
| 510 delete this._popoverTarget; | |
| 511 } | |
| 484 if (!this._popoverAnchorBox) | 512 if (!this._popoverAnchorBox) |
| 485 return; | 513 return; |
| 486 if (this._popoverAnchorBox._highlightDescriptor) | 514 if (this._popoverAnchorBox._highlightDescriptor) |
| 487 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto r); | 515 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto r); |
| 488 delete this._popoverAnchorBox; | 516 delete this._popoverAnchorBox; |
| 489 } | 517 } |
| 490 | 518 |
| 491 _onKeyDown(event) { | 519 _onKeyDown(event) { |
| 492 if (event.key === 'Escape') { | 520 if (event.key === 'Escape') { |
| 493 if (this._popoverHelper.isPopoverVisible()) { | 521 if (this._popoverHelper.isPopoverVisible()) { |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1463 return; | 1491 return; |
| 1464 this.bookmark.clear(); | 1492 this.bookmark.clear(); |
| 1465 this.bookmark = null; | 1493 this.bookmark = null; |
| 1466 } | 1494 } |
| 1467 }; | 1495 }; |
| 1468 | 1496 |
| 1469 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol = Symbol('book mark'); | 1497 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol = Symbol('book mark'); |
| 1470 Sources.JavaScriptSourceFrame.BreakpointDecoration._elementSymbolForTest = Symbo l('element'); | 1498 Sources.JavaScriptSourceFrame.BreakpointDecoration._elementSymbolForTest = Symbo l('element'); |
| 1471 | 1499 |
| 1472 Sources.JavaScriptSourceFrame.continueToLocationDecorationSymbol = Symbol('bookm ark'); | 1500 Sources.JavaScriptSourceFrame.continueToLocationDecorationSymbol = Symbol('bookm ark'); |
| OLD | NEW |