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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 if (uiSourceCode.project().type() === WebInspector.projectTypes.Debugger) | 44 if (uiSourceCode.project().type() === WebInspector.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 WebInspector.ObjectPopoverHelper(this.textEditor.e lement, | 47 this._popoverHelper = new WebInspector.ObjectPopoverHelper(this.textEditor.e lement, |
| 48 this._getPopoverAnchor.bind(this), this._resolveObjectForPopover.bin d(this), this._onHidePopover.bind(this), true); | 48 this._getPopoverAnchor.bind(this), this._resolveObjectForPopover.bin d(this), this._onHidePopover.bind(this), true); |
| 49 | 49 |
| 50 this.textEditor.element.addEventListener("keydown", this._onKeyDown.bind(thi s), true); | 50 this.textEditor.element.addEventListener("keydown", this._onKeyDown.bind(thi s), true); |
| 51 | 51 |
| 52 this.textEditor.addEventListener(WebInspector.TextEditor.Events.GutterClick, this._handleGutterClick.bind(this), this); | 52 this.textEditor.addEventListener(WebInspector.TextEditor.Events.GutterClick, this._handleGutterClick.bind(this), this); |
| 53 | 53 |
| 54 this.textEditor.element.addEventListener("mousedown", this._onMouseDownAndCl ick.bind(this, true), true); | |
| 55 this.textEditor.element.addEventListener("click", this._onMouseDownAndClick. bind(this, false), true); | |
| 56 | |
| 57 | |
| 58 this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Even ts.BreakpointAdded, this._breakpointAdded, this); | 54 this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Even ts.BreakpointAdded, this._breakpointAdded, this); |
| 59 this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Even ts.BreakpointRemoved, this._breakpointRemoved, this); | 55 this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Even ts.BreakpointRemoved, this._breakpointRemoved, this); |
| 60 | 56 |
| 61 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Console MessageAdded, this._consoleMessageAdded, this); | 57 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Console MessageAdded, this._consoleMessageAdded, this); |
| 62 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Console MessageRemoved, this._consoleMessageRemoved, this); | 58 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Console MessageRemoved, this._consoleMessageRemoved, this); |
| 63 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Console MessagesCleared, this._consoleMessagesCleared, this); | 59 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Console MessagesCleared, this._consoleMessagesCleared, this); |
| 64 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.SourceM appingChanged, this._onSourceMappingChanged, this); | 60 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.SourceM appingChanged, this._onSourceMappingChanged, this); |
| 65 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyChanged, this._workingCopyChanged, this); | 61 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyChanged, this._workingCopyChanged, this); |
| 66 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyCommitted, this._workingCopyCommitted, this); | 62 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyCommitted, this._workingCopyCommitted, this); |
| 67 | 63 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 }, | 400 }, |
| 405 | 401 |
| 406 _onKeyDown: function(event) | 402 _onKeyDown: function(event) |
| 407 { | 403 { |
| 408 if (event.keyIdentifier === "U+001B") { // Escape key | 404 if (event.keyIdentifier === "U+001B") { // Escape key |
| 409 if (this._popoverHelper.isPopoverVisible()) { | 405 if (this._popoverHelper.isPopoverVisible()) { |
| 410 this._popoverHelper.hidePopover(); | 406 this._popoverHelper.hidePopover(); |
| 411 event.consume(); | 407 event.consume(); |
| 412 return; | 408 return; |
| 413 } | 409 } |
| 414 if (this._stepIntoMarkup && WebInspector.KeyboardShortcut.eventHasCt rlOrMeta(event)) { | |
| 415 this._stepIntoMarkup.stoptIteratingSelection(); | |
| 416 event.consume(); | |
| 417 return; | |
| 418 } | |
| 419 } | 410 } |
| 420 }, | 411 }, |
| 421 | 412 |
| 422 /** | 413 /** |
| 423 * @param {number} lineNumber | 414 * @param {number} lineNumber |
| 424 * @param {!WebInspector.BreakpointManager.Breakpoint=} breakpoint | 415 * @param {!WebInspector.BreakpointManager.Breakpoint=} breakpoint |
| 425 */ | 416 */ |
| 426 _editBreakpointCondition: function(lineNumber, breakpoint) | 417 _editBreakpointCondition: function(lineNumber, breakpoint) |
| 427 { | 418 { |
| 428 this._conditionElement = this._createConditionElement(lineNumber); | 419 this._conditionElement = this._createConditionElement(lineNumber); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 }, | 464 }, |
| 474 | 465 |
| 475 /** | 466 /** |
| 476 * @param {number} lineNumber | 467 * @param {number} lineNumber |
| 477 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 468 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame |
| 478 */ | 469 */ |
| 479 setExecutionLine: function(lineNumber, callFrame) | 470 setExecutionLine: function(lineNumber, callFrame) |
| 480 { | 471 { |
| 481 this._executionLineNumber = lineNumber; | 472 this._executionLineNumber = lineNumber; |
| 482 this._executionCallFrame = callFrame; | 473 this._executionCallFrame = callFrame; |
| 483 if (this.loaded) { | 474 if (this.loaded) |
| 484 this.textEditor.setExecutionLine(lineNumber); | 475 this.textEditor.setExecutionLine(lineNumber); |
| 485 | |
| 486 if (WebInspector.experimentsSettings.stepIntoSelection.isEnabled()) | |
| 487 callFrame.getStepIntoLocations(locationsCallback.bind(this)); | |
| 488 } | |
| 489 | |
| 490 /** | |
| 491 * @param {!Array.<!DebuggerAgent.Location>} locations | |
| 492 * @this {WebInspector.JavaScriptSourceFrame} | |
| 493 */ | |
| 494 function locationsCallback(locations) | |
| 495 { | |
| 496 if (this._executionCallFrame !== callFrame || this._stepIntoMarkup) | |
| 497 return; | |
| 498 this._stepIntoMarkup = WebInspector.JavaScriptSourceFrame.StepIntoMa rkup.create(this, locations); | |
| 499 if (this._stepIntoMarkup) | |
| 500 this._stepIntoMarkup.show(); | |
| 501 } | |
| 502 }, | 476 }, |
| 503 | 477 |
| 504 clearExecutionLine: function() | 478 clearExecutionLine: function() |
| 505 { | 479 { |
| 506 if (this._stepIntoMarkup) { | |
| 507 this._stepIntoMarkup.dispose(); | |
| 508 delete this._stepIntoMarkup; | |
| 509 } | |
| 510 | |
| 511 if (this.loaded && typeof this._executionLineNumber === "number") | 480 if (this.loaded && typeof this._executionLineNumber === "number") |
| 512 this.textEditor.clearExecutionLine(); | 481 this.textEditor.clearExecutionLine(); |
| 513 delete this._executionLineNumber; | 482 delete this._executionLineNumber; |
| 514 delete this._executionCallFrame; | 483 delete this._executionCallFrame; |
| 515 }, | 484 }, |
| 516 | 485 |
| 517 _onMouseDownAndClick: function(isMouseDown, event) | |
| 518 { | |
| 519 var markup = this._stepIntoMarkup; | |
| 520 if (!markup) | |
| 521 return; | |
| 522 var index = markup.findItemByCoordinates(event.x, event.y); | |
| 523 if (typeof index === "undefined") | |
| 524 return; | |
| 525 | |
| 526 if (isMouseDown) { | |
| 527 // Do not let text editor to spoil 'click' event that is coming for us. | |
| 528 event.consume(); | |
| 529 } else { | |
| 530 var rawLocation = markup.getRawPosition(index); | |
| 531 this._scriptsPanel.doStepIntoSelection(rawLocation); | |
| 532 } | |
| 533 }, | |
| 534 | |
| 535 /** | 486 /** |
| 536 * @return {boolean} | 487 * @return {boolean} |
| 537 */ | 488 */ |
| 538 _shouldIgnoreExternalBreakpointEvents: function() | 489 _shouldIgnoreExternalBreakpointEvents: function() |
| 539 { | 490 { |
| 540 if (this._supportsEnabledBreakpointsWhileEditing()) | 491 if (this._supportsEnabledBreakpointsWhileEditing()) |
| 541 return false; | 492 return false; |
| 542 if (this._muted) | 493 if (this._muted) |
| 543 return true; | 494 return true; |
| 544 return this._scriptFile && (this._scriptFile.isDivergingFromVM() || this ._scriptFile.isMergingToVM()); | 495 return this._scriptFile && (this._scriptFile.isDivergingFromVM() || this ._scriptFile.isMergingToVM()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 | 652 |
| 702 /** | 653 /** |
| 703 * @param {number} lineNumber | 654 * @param {number} lineNumber |
| 704 */ | 655 */ |
| 705 _continueToLine: function(lineNumber) | 656 _continueToLine: function(lineNumber) |
| 706 { | 657 { |
| 707 var rawLocation = /** @type {!WebInspector.DebuggerModel.Location} */ (t his._uiSourceCode.uiLocationToRawLocation(lineNumber, 0)); | 658 var rawLocation = /** @type {!WebInspector.DebuggerModel.Location} */ (t his._uiSourceCode.uiLocationToRawLocation(lineNumber, 0)); |
| 708 this._scriptsPanel.continueToLocation(rawLocation); | 659 this._scriptsPanel.continueToLocation(rawLocation); |
| 709 }, | 660 }, |
| 710 | 661 |
| 711 /** | |
| 712 * @return {!WebInspector.JavaScriptSourceFrame.StepIntoMarkup|undefined} | |
| 713 */ | |
| 714 stepIntoMarkup: function() | |
| 715 { | |
| 716 return this._stepIntoMarkup; | |
| 717 }, | |
| 718 | |
| 719 dispose: function() | 662 dispose: function() |
| 720 { | 663 { |
| 721 this._breakpointManager.removeEventListener(WebInspector.BreakpointManag er.Events.BreakpointAdded, this._breakpointAdded, this); | 664 this._breakpointManager.removeEventListener(WebInspector.BreakpointManag er.Events.BreakpointAdded, this._breakpointAdded, this); |
| 722 this._breakpointManager.removeEventListener(WebInspector.BreakpointManag er.Events.BreakpointRemoved, this._breakpointRemoved, this); | 665 this._breakpointManager.removeEventListener(WebInspector.BreakpointManag er.Events.BreakpointRemoved, this._breakpointRemoved, this); |
| 723 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. ConsoleMessageAdded, this._consoleMessageAdded, this); | 666 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. ConsoleMessageAdded, this._consoleMessageAdded, this); |
| 724 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. ConsoleMessageRemoved, this._consoleMessageRemoved, this); | 667 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. ConsoleMessageRemoved, this._consoleMessageRemoved, this); |
| 725 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. ConsoleMessagesCleared, this._consoleMessagesCleared, this); | 668 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. ConsoleMessagesCleared, this._consoleMessagesCleared, this); |
| 726 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. SourceMappingChanged, this._onSourceMappingChanged, this); | 669 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. SourceMappingChanged, this._onSourceMappingChanged, this); |
| 727 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this); | 670 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this); |
| 728 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this); | 671 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this); |
| 729 WebInspector.UISourceCodeFrame.prototype.dispose.call(this); | 672 WebInspector.UISourceCodeFrame.prototype.dispose.call(this); |
| 730 }, | 673 }, |
| 731 | 674 |
| 732 __proto__: WebInspector.UISourceCodeFrame.prototype | 675 __proto__: WebInspector.UISourceCodeFrame.prototype |
| 733 } | 676 } |
| 734 | |
| 735 /** | |
| 736 * @constructor | |
| 737 * @param {!Array.<!DebuggerAgent.Location>} rawPositions | |
| 738 * @param {!Array.<!WebInspector.TextRange>} editorRanges | |
| 739 * @param {number} firstToExecute | |
| 740 * @param {!WebInspector.JavaScriptSourceFrame} sourceFrame | |
| 741 */ | |
| 742 WebInspector.JavaScriptSourceFrame.StepIntoMarkup = function(rawPositions, edito rRanges, firstToExecute, sourceFrame) | |
| 743 { | |
| 744 this._positions = rawPositions; | |
| 745 this._editorRanges = editorRanges; | |
| 746 this._highlightDescriptors = new Array(rawPositions.length); | |
| 747 this._currentHighlight = undefined; | |
| 748 this._firstToExecute = firstToExecute; | |
| 749 this._currentSelection = undefined; | |
| 750 this._sourceFrame = sourceFrame; | |
| 751 }; | |
| 752 | |
| 753 WebInspector.JavaScriptSourceFrame.StepIntoMarkup.prototype = { | |
| 754 show: function() | |
| 755 { | |
| 756 var highlight = this._getVisibleHighlight(); | |
| 757 for (var i = 0; i < this._positions.length; ++i) | |
| 758 this._highlightItem(i, i === highlight); | |
| 759 this._shownVisibleHighlight = highlight; | |
| 760 }, | |
| 761 | |
| 762 startIteratingSelection: function() | |
| 763 { | |
| 764 this._currentSelection = this._positions.length | |
| 765 this._redrawHighlight(); | |
| 766 }, | |
| 767 | |
| 768 stopIteratingSelection: function() | |
| 769 { | |
| 770 this._currentSelection = undefined; | |
| 771 this._redrawHighlight(); | |
| 772 }, | |
| 773 | |
| 774 /** | |
| 775 * @param {boolean} backward | |
| 776 */ | |
| 777 iterateSelection: function(backward) | |
| 778 { | |
| 779 if (typeof this._currentSelection === "undefined") | |
| 780 return; | |
| 781 var nextSelection = backward ? this._currentSelection - 1 : this._curren tSelection + 1; | |
| 782 var modulo = this._positions.length + 1; | |
| 783 nextSelection = (nextSelection + modulo) % modulo; | |
| 784 this._currentSelection = nextSelection; | |
| 785 this._redrawHighlight(); | |
| 786 }, | |
| 787 | |
| 788 _redrawHighlight: function() | |
| 789 { | |
| 790 var visibleHighlight = this._getVisibleHighlight(); | |
| 791 if (this._shownVisibleHighlight === visibleHighlight) | |
| 792 return; | |
| 793 this._hideItemHighlight(this._shownVisibleHighlight); | |
| 794 this._hideItemHighlight(visibleHighlight); | |
| 795 this._highlightItem(this._shownVisibleHighlight, false); | |
| 796 this._highlightItem(visibleHighlight, true); | |
| 797 this._shownVisibleHighlight = visibleHighlight; | |
| 798 }, | |
| 799 | |
| 800 /** | |
| 801 * @return {number} | |
| 802 */ | |
| 803 _getVisibleHighlight: function() | |
| 804 { | |
| 805 return typeof this._currentSelection === "undefined" ? this._firstToExec ute : this._currentSelection; | |
| 806 }, | |
| 807 | |
| 808 /** | |
| 809 * @param {number} position | |
| 810 * @param {boolean} selected | |
| 811 */ | |
| 812 _highlightItem: function(position, selected) | |
| 813 { | |
| 814 if (position === this._positions.length) | |
| 815 return; | |
| 816 var styleName = selected ? "source-frame-stepin-mark-highlighted" : "sou rce-frame-stepin-mark"; | |
|
aandrey
2014/03/17 19:05:20
also clean up CSS files
| |
| 817 var textEditor = this._sourceFrame.textEditor; | |
| 818 var highlightDescriptor = textEditor.highlightRange(this._editorRanges[p osition], styleName); | |
| 819 this._highlightDescriptors[position] = highlightDescriptor; | |
| 820 }, | |
| 821 | |
| 822 /** | |
| 823 * @param {number} position | |
| 824 */ | |
| 825 _hideItemHighlight: function(position) | |
| 826 { | |
| 827 if (position === this._positions.length) | |
| 828 return; | |
| 829 var highlightDescriptor = this._highlightDescriptors[position]; | |
| 830 console.assert(highlightDescriptor); | |
| 831 var textEditor = this._sourceFrame.textEditor; | |
| 832 textEditor.removeHighlight(highlightDescriptor); | |
| 833 this._highlightDescriptors[position] = undefined; | |
| 834 }, | |
| 835 | |
| 836 dispose: function() | |
| 837 { | |
| 838 for (var i = 0; i < this._positions.length; ++i) | |
| 839 this._hideItemHighlight(i); | |
| 840 }, | |
| 841 | |
| 842 /** | |
| 843 * @param {number} x | |
| 844 * @param {number} y | |
| 845 * @return {number|undefined} | |
| 846 */ | |
| 847 findItemByCoordinates: function(x, y) | |
| 848 { | |
| 849 var textPosition = this._sourceFrame.textEditor.coordinatesToCursorPosit ion(x, y); | |
| 850 if (!textPosition) | |
| 851 return; | |
| 852 | |
| 853 var ranges = this._editorRanges; | |
| 854 | |
| 855 for (var i = 0; i < ranges.length; ++i) { | |
| 856 var nextRange = ranges[i]; | |
| 857 if (nextRange.startLine == textPosition.startLine && nextRange.startCo lumn <= textPosition.startColumn && nextRange.endColumn >= textPosition.startCol umn) | |
| 858 return i; | |
| 859 } | |
| 860 }, | |
| 861 | |
| 862 /** | |
| 863 * @return {number|undefined} | |
| 864 */ | |
| 865 getSelectedItemIndex: function() | |
| 866 { | |
| 867 if (this._currentSelection === this._positions.length) | |
| 868 return undefined; | |
| 869 return this._currentSelection; | |
| 870 }, | |
| 871 | |
| 872 /** | |
| 873 * @return {!WebInspector.DebuggerModel.Location} | |
| 874 */ | |
| 875 getRawPosition: function(position) | |
| 876 { | |
| 877 return /** @type {!WebInspector.DebuggerModel.Location} */ (this._positi ons[position]); | |
| 878 } | |
| 879 | |
| 880 }; | |
| 881 | |
| 882 /** | |
| 883 * @param {!WebInspector.JavaScriptSourceFrame} sourceFrame | |
| 884 * @param {!Array.<!DebuggerAgent.Location>} stepIntoRawLocations | |
| 885 * @return {?WebInspector.JavaScriptSourceFrame.StepIntoMarkup} | |
| 886 */ | |
| 887 WebInspector.JavaScriptSourceFrame.StepIntoMarkup.create = function(sourceFrame, stepIntoRawLocations) | |
| 888 { | |
| 889 if (!stepIntoRawLocations.length) | |
| 890 return null; | |
| 891 | |
| 892 var firstToExecute = stepIntoRawLocations[0]; | |
| 893 stepIntoRawLocations.sort(WebInspector.JavaScriptSourceFrame.StepIntoMarkup. _Comparator); | |
| 894 var firstToExecuteIndex = stepIntoRawLocations.indexOf(firstToExecute); | |
| 895 | |
| 896 var textEditor = sourceFrame.textEditor; | |
| 897 var uiRanges = []; | |
| 898 for (var i = 0; i < stepIntoRawLocations.length; ++i) { | |
| 899 var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(/** @type {!WebInspector.DebuggerModel.Location} */ (stepIntoRawLocations[i])); | |
| 900 | |
| 901 var token = textEditor.tokenAtTextPosition(uiLocation.lineNumber, uiLoca tion.columnNumber); | |
| 902 var startColumn; | |
| 903 var endColumn; | |
| 904 if (token) { | |
| 905 startColumn = token.startColumn; | |
| 906 endColumn = token.endColumn; | |
| 907 } else { | |
| 908 startColumn = uiLocation.columnNumber; | |
| 909 endColumn = uiLocation.columnNumber; | |
| 910 } | |
| 911 var range = new WebInspector.TextRange(uiLocation.lineNumber, startColum n, uiLocation.lineNumber, endColumn); | |
| 912 uiRanges.push(range); | |
| 913 } | |
| 914 | |
| 915 return new WebInspector.JavaScriptSourceFrame.StepIntoMarkup(stepIntoRawLoca tions, uiRanges, firstToExecuteIndex, sourceFrame); | |
| 916 }; | |
| 917 | |
| 918 /** | |
| 919 * @param {!DebuggerAgent.Location} locationA | |
| 920 * @param {!DebuggerAgent.Location} locationB | |
| 921 * @return {number} | |
| 922 */ | |
| 923 WebInspector.JavaScriptSourceFrame.StepIntoMarkup._Comparator = function(locatio nA, locationB) | |
| 924 { | |
| 925 if (locationA.lineNumber === locationB.lineNumber) | |
| 926 return locationA.columnNumber - locationB.columnNumber; | |
| 927 else | |
| 928 return locationA.lineNumber - locationB.lineNumber; | |
| 929 }; | |
| OLD | NEW |