Changeset 76009 in webkit
- Timestamp:
- Jan 18, 2011 2:15:32 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r76007 r76009 1 2011-01-11 Pavel Podivilov <podivilov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: implement script beautifier prototype. 6 https://bugs.webkit.org/show_bug.cgi?id=51588 7 8 * WebCore.gypi: 9 * WebCore.vcproj/WebCore.vcproj: 10 * inspector/front-end/ScriptFormatter.js: Added. 11 (WebInspector.ScriptFormatter): Implements JavaScript source beautification and conversion between original and 12 formatted line numbers 13 (WebInspector.ScriptFormatter.findLineEndings): 14 (WebInspector.ScriptFormatter.locationToPosition): 15 (WebInspector.ScriptFormatter.positionToLocation): 16 (WebInspector.ScriptFormatter.upperBound): 17 (WebInspector.ScriptFormatter.prototype.format): 18 (WebInspector.ScriptFormatter.prototype.originalLineNumberToFormattedLineNumber): 19 (WebInspector.ScriptFormatter.prototype.formattedLineNumberToOriginalLineNumber): 20 (WebInspector.ScriptFormatter.prototype.originalPositionToFormattedLineNumber): 21 (WebInspector.ScriptFormatter.prototype.formattedLineNumberToOriginalPosition): 22 (WebInspector.ScriptFormatter.prototype._convertPosition): 23 * inspector/front-end/ScriptsPanel.js: 24 (WebInspector.ScriptsPanel): 25 (WebInspector.ScriptsPanel.prototype._clearCurrentExecutionLine): 26 (WebInspector.ScriptsPanel.prototype._callFrameSelected): 27 (WebInspector.ScriptsPanel.prototype._formatScript): 28 * inspector/front-end/SourceFrame.js: Convert original line numbers to UI line numbers and vice versa 29 * inspector/front-end/WebKit.qrc: 30 * inspector/front-end/inspector.html: 31 1 32 2011-01-18 Philippe Normand <pnormand@igalia.com> 2 33 -
trunk/Source/WebCore/WebCore.gypi
r76004 r76009 4678 4678 'inspector/front-end/ScopeChainSidebarPane.js', 4679 4679 'inspector/front-end/Script.js', 4680 'inspector/front-end/ScriptFormatter.js', 4680 4681 'inspector/front-end/ScriptsPanel.js', 4681 4682 'inspector/front-end/ScriptView.js', -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r76005 r76009 65598 65598 </File> 65599 65599 <File 65600 RelativePath="..\inspector\front-end\ScriptFormatter.js" 65601 > 65602 </File> 65603 <File 65600 65604 RelativePath="..\inspector\front-end\ScriptsPanel.js" 65601 65605 > -
trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js
r75939 r76009 64 64 // this.topStatusBar.appendChild(this.functionsSelectElement); 65 65 66 this.formatButton = document.createElement("button"); 67 this.formatButton.className = "status-bar-item"; 68 this.formatButton.id = "format-script"; 69 this.formatButton.title = WebInspector.UIString("Format script."); 70 this.formatButton.appendChild(document.createElement("img")); 71 this.formatButton.addEventListener("click", this._formatScript.bind(this), false); 72 if (Preferences.debugMode) 73 this.topStatusBar.appendChild(this.formatButton); 74 66 75 this.sidebarButtonsElement = document.createElement("div"); 67 76 this.sidebarButtonsElement.id = "scripts-sidebar-buttons"; … … 678 687 { 679 688 if (this._executionSourceFrame) 680 this._executionSourceFrame. executionLine = 0;689 this._executionSourceFrame.clearExecutionLine(); 681 690 delete this._executionSourceFrame; 682 691 }, … … 700 709 this._executionSourceFrame = this._sourceFrameForScriptOrResource(scriptOrResource); 701 710 if (this._executionSourceFrame) 702 this._executionSourceFrame. executionLine = currentFrame.line;711 this._executionSourceFrame.setExecutionLine(currentFrame.line); 703 712 }, 704 713 … … 834 843 }, 835 844 845 _formatScript: function() 846 { 847 if (this.visibleView && this.visibleView.sourceFrame) 848 this.visibleView.sourceFrame.formatSource(); 849 }, 850 836 851 _enableDebugging: function() 837 852 { -
trunk/Source/WebCore/inspector/front-end/SourceFrame.js
r75937 r76009 72 72 }, 73 73 74 get executionLine()75 {76 return this._executionLine;77 },78 79 set executionLine(x)80 {81 if (this._executionLine === x)82 return;83 84 var previousLine = this._executionLine;85 this._executionLine = x;86 87 if (this._textViewer)88 this._updateExecutionLine(previousLine);89 },90 91 74 markDiff: function(diffData) 92 75 { … … 173 156 this._content = content; 174 157 this._textModel.setText(null, content); 158 this._formatter = new WebInspector.ScriptFormatter(content); 175 159 176 160 this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url); … … 185 169 186 170 this._textViewer.mimeType = mimeType; 187 this._addExistingMessagesToSource(); 188 this._updateExecutionLine(); 189 this._updateDiffDecorations(); 190 this._textViewer.resize(); 171 this._setTextViewerDecorations(); 191 172 192 173 if (this._lineNumberToReveal) { … … 211 192 } 212 193 194 this._textViewer.endUpdates(); 195 196 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointAdded, this._breakpointAdded, this); 197 198 if (this._canEditScripts) 199 this._textViewer.editCallback = this._editLine.bind(this); 200 }, 201 202 _setTextViewerDecorations: function() 203 { 204 this._rowMessages = {}; 205 this._messageBubbles = {}; 206 207 this._textViewer.beginUpdates(); 208 209 this._addExistingMessagesToSource(); 210 this._updateDiffDecorations(); 211 212 if (this._executionLine) 213 this.setExecutionLine(this._executionLine); 214 213 215 var breakpoints = this._breakpoints(); 214 216 for (var i = 0; i < breakpoints.length; ++i) 215 217 this._addBreakpoint(breakpoints[i]); 216 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointAdded, this._breakpointAdded, this); 218 219 this._textViewer.resize(); 217 220 218 221 this._textViewer.endUpdates(); 219 220 if (this._canEditScripts)221 this._textViewer.editCallback = this._editLine.bind(this);222 222 }, 223 223 … … 301 301 }, 302 302 303 _updateExecutionLine: function(previousLine) 304 { 305 if (previousLine) { 306 if (previousLine - 1 < this._textModel.linesCount) 307 this._textViewer.removeDecoration(previousLine - 1, "webkit-execution-line"); 308 } 309 310 if (!this._executionLine) 311 return; 312 313 if (this._executionLine < this._textModel.linesCount) 314 this._textViewer.addDecoration(this._executionLine - 1, "webkit-execution-line"); 303 setExecutionLine: function(lineNumber) 304 { 305 this._executionLine = lineNumber; 306 if (!this._textViewer) 307 return; 308 var textViewerLineNumber = this._formatter.originalLineNumberToFormattedLineNumber(this._executionLine - 1); 309 this._textViewer.addDecoration(textViewerLineNumber, "webkit-execution-line"); 310 }, 311 312 clearExecutionLine: function() 313 { 314 if (!this._textViewer) 315 return; 316 var textViewerLineNumber = this._formatter.originalLineNumberToFormattedLineNumber(this._executionLine - 1); 317 this._textViewer.removeDecoration(textViewerLineNumber, "webkit-execution-line"); 318 delete this._executionLine; 315 319 }, 316 320 … … 413 417 _addBreakpoint: function(breakpoint) 414 418 { 415 if (breakpoint.line > this._textModel.linesCount) 419 var textViewerLineNumber = this._formatter.originalLineNumberToFormattedLineNumber(breakpoint.line - 1); 420 if (textViewerLineNumber >= this._textModel.linesCount) 416 421 return; 417 422 … … 420 425 breakpoint.addEventListener("removed", this._breakpointRemoved, this); 421 426 422 this._setBreakpointDecoration( breakpoint.line, breakpoint.enabled, !!breakpoint.condition);427 this._setBreakpointDecoration(textViewerLineNumber, breakpoint.enabled, !!breakpoint.condition); 423 428 }, 424 429 … … 431 436 breakpoint.removeEventListener("removed", null, this); 432 437 433 this._removeBreakpointDecoration(breakpoint.line); 438 var textViewerLineNumber = this._formatter.originalLineNumberToFormattedLineNumber(breakpoint.line - 1); 439 this._removeBreakpointDecoration(textViewerLineNumber); 434 440 }, 435 441 … … 437 443 { 438 444 var breakpoint = event.target; 439 this._setBreakpointDecoration(breakpoint.line, breakpoint.enabled, !!breakpoint.condition); 445 var textViewerLineNumber = this._formatter.originalLineNumberToFormattedLineNumber(breakpoint.line - 1); 446 this._setBreakpointDecoration(textViewerLineNumber, breakpoint.enabled, !!breakpoint.condition); 440 447 }, 441 448 442 449 _setBreakpointDecoration: function(lineNumber, enabled, hasCondition) 443 450 { 444 lineNumber -= 1;445 451 this._textViewer.beginUpdates(); 446 452 this._textViewer.addDecoration(lineNumber, "webkit-breakpoint"); … … 458 464 _removeBreakpointDecoration: function(lineNumber) 459 465 { 460 lineNumber -= 1;461 466 this._textViewer.beginUpdates(); 462 467 this._textViewer.removeDecoration(lineNumber, "webkit-breakpoint"); … … 474 479 if (!target) 475 480 return; 476 var lineNumber = target.parentElement.lineNumber + 1; 481 var textViewerLineNumber = target.parentElement.lineNumber; 482 var originalLineNumber = this._formatter.formattedLineNumberToOriginalLineNumber(textViewerLineNumber); 477 483 478 484 var contextMenu = new WebInspector.ContextMenu(); 479 485 480 contextMenu.appendItem(WebInspector.UIString("Continue to Here"), this._continueToLine.bind(this, lineNumber));481 482 var breakpoint = this._findBreakpoint( lineNumber);486 contextMenu.appendItem(WebInspector.UIString("Continue to Here"), this._continueToLine.bind(this, originalLineNumber)); 487 488 var breakpoint = this._findBreakpoint(originalLineNumber); 483 489 if (!breakpoint) { 484 490 // This row doesn't have a breakpoint: We want to show Add Breakpoint and Add and Edit Breakpoint. 485 contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._setBreakpoint.bind(this, lineNumber, "", true));491 contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._setBreakpoint.bind(this, originalLineNumber, "", true)); 486 492 487 493 function addConditionalBreakpoint() 488 494 { 489 this._setBreakpointDecoration( lineNumber, true, true);495 this._setBreakpointDecoration(textViewerLineNumber, true, true); 490 496 function didEditBreakpointCondition(committed, condition) 491 497 { 492 this._removeBreakpointDecoration( lineNumber);498 this._removeBreakpointDecoration(textViewerLineNumber); 493 499 if (committed) 494 this._setBreakpoint( lineNumber, true, condition);500 this._setBreakpoint(originalLineNumber, true, condition); 495 501 } 496 this._editBreakpointCondition( lineNumber, "", didEditBreakpointCondition.bind(this));502 this._editBreakpointCondition(textViewerLineNumber, "", didEditBreakpointCondition.bind(this)); 497 503 } 498 504 contextMenu.appendItem(WebInspector.UIString("Add Conditional Breakpoint…"), addConditionalBreakpoint.bind(this)); … … 506 512 if (committed) { 507 513 breakpoint.remove(); 508 this._setBreakpoint( breakpoint.line, breakpoint.enabled, condition);514 this._setBreakpoint(originalLineNumber, breakpoint.enabled, condition); 509 515 } 510 516 } 511 this._editBreakpointCondition( lineNumber, breakpoint.condition, didEditBreakpointCondition.bind(this));517 this._editBreakpointCondition(textViewerLineNumber, breakpoint.condition, didEditBreakpointCondition.bind(this)); 512 518 } 513 519 contextMenu.appendItem(WebInspector.UIString("Edit Breakpoint…"), editBreakpointCondition.bind(this)); … … 515 521 { 516 522 breakpoint.remove(); 517 this._setBreakpoint( breakpoint.line, enabled, breakpoint.condition);523 this._setBreakpoint(originalLineNumber, enabled, breakpoint.condition); 518 524 } 519 525 if (breakpoint.enabled) … … 539 545 if (!target) 540 546 return; 541 var lineNumber = target.parentElement.lineNumber + 1;542 543 var breakpoint = this._findBreakpoint( lineNumber);547 var originalLineNumber = this._formatter.formattedLineNumberToOriginalLineNumber(target.parentElement.lineNumber); 548 549 var breakpoint = this._findBreakpoint(originalLineNumber); 544 550 if (breakpoint) { 545 551 breakpoint.remove(); 546 552 if (event.shiftKey) 547 this._setBreakpoint( breakpoint.line, !breakpoint.enabled, breakpoint.condition);553 this._setBreakpoint(originalLineNumber, !breakpoint.enabled, breakpoint.condition); 548 554 } else 549 this._setBreakpoint( lineNumber, true, "");555 this._setBreakpoint(originalLineNumber, true, ""); 550 556 event.preventDefault(); 551 557 }, … … 711 717 _editBreakpointCondition: function(lineNumber, condition, callback) 712 718 { 713 lineNumber -= 1;714 719 this._conditionElement = this._createConditionElement(lineNumber); 715 720 this._textViewer.addDecoration(lineNumber, this._conditionElement); … … 777 782 }, 778 783 784 formatSource: function() 785 { 786 if (!this._formatter) 787 return; 788 789 this._textModel.setText(null, this._formatter.format()); 790 this._setTextViewerDecorations(); 791 }, 792 779 793 _continueToLine: function(lineNumber) 780 794 { … … 782 796 if (!sourceID) 783 797 return; 784 WebInspector.debuggerModel.continueToLine(sourceID, lineNumber );798 WebInspector.debuggerModel.continueToLine(sourceID, lineNumber + 1); 785 799 }, 786 800 787 801 _editLine: function(lineNumber, newContent, cancelEditingCallback) 788 802 { 789 lineNumber += 1;790 791 803 var lines = []; 792 804 var oldLines = this._content.split('\n'); 793 805 for (var i = 0; i < oldLines.length; ++i) { 794 if (i === lineNumber - 1)806 if (i === lineNumber) 795 807 lines.push(newContent); 796 808 else … … 801 813 editData.sourceID = this._sourceIDForLine(lineNumber); 802 814 editData.content = lines.join("\n"); 803 editData.line = lineNumber ;815 editData.line = lineNumber + 1; 804 816 editData.linesCountToShift = newContent.split("\n").length - 1; 805 817 this._doEditLine(editData, cancelEditingCallback); … … 827 839 if (!sourceID) 828 840 return; 829 WebInspector.debuggerModel.setBreakpoint(sourceID, lineNumber , enabled, condition);841 WebInspector.debuggerModel.setBreakpoint(sourceID, lineNumber + 1, enabled, condition); 830 842 if (!WebInspector.panels.scripts.breakpointsActivated) 831 843 WebInspector.panels.scripts.toggleBreakpointsClicked(); … … 841 853 { 842 854 var sourceID = this._sourceIDForLine(lineNumber); 843 return WebInspector.debuggerModel.findBreakpoint(sourceID, lineNumber );855 return WebInspector.debuggerModel.findBreakpoint(sourceID, lineNumber + 1); 844 856 }, 845 857 … … 850 862 var scripts = this._contentProvider.scripts(); 851 863 for (var i = 0; i < scripts.length; ++i) { 852 var startingLine = scripts[i].startingLine;853 if ( startingLine <= lineNumber && startingLine>= closestStartingLine) {854 closestStartingLine = startingLine;864 var lineOffset = scripts[i].lineOffset; 865 if (lineOffset <= lineNumber && lineOffset >= closestStartingLine) { 866 closestStartingLine = lineOffset; 855 867 sourceIDForLine = scripts[i].sourceID; 856 868 } -
trunk/Source/WebCore/inspector/front-end/WebKit.qrc
r75715 r76009 82 82 <file>ScopeChainSidebarPane.js</file> 83 83 <file>Script.js</file> 84 <file>ScriptFormatter.js</file> 84 85 <file>ScriptsPanel.js</file> 85 86 <file>ScriptView.js</file> -
trunk/Source/WebCore/inspector/front-end/inspector.html
r75715 r76009 122 122 <script type="text/javascript" src="ResourceView.js"></script> 123 123 <script type="text/javascript" src="SourceFrame.js"></script> 124 <script type="text/javascript" src="ScriptFormatter.js"></script> 124 125 <script type="text/javascript" src="DOMSyntaxHighlighter.js"></script> 125 126 <script type="text/javascript" src="TextEditorModel.js"></script>
Note: See TracChangeset
for help on using the changeset viewer.