Changeset 53795 in webkit


Ignore:
Timestamp:
Jan 25, 2010 2:58:01 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2010-01-24 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: Add support for addMessage/clearMessages to SourceFrame2.

https://bugs.webkit.org/show_bug.cgi?id=33904

  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • inspector/front-end/SourceFrame2.js: (WebInspector.SourceFrame2): (WebInspector.SourceFrame2.prototype.addMessage): (WebInspector.SourceFrame2.prototype.clearMessages): (WebInspector.SourceFrame2.prototype._incrementMessageRepeatCount): (WebInspector.SourceFrame2.prototype._addExistingMessagesToSource): (WebInspector.SourceFrame2.prototype._addMessageToSource): (WebInspector.SourceFrame2.prototype.resize):
  • inspector/front-end/TextEditor.js: (WebInspector.TextEditor): (WebInspector.TextEditor.prototype.setDivDecoration): (WebInspector.TextEditor.prototype._lineHeight): (WebInspector.TextEditor.prototype._highlightChanged): (WebInspector.TextEditor.prototype.packAndRepaintAll): (WebInspector.TextEditor.prototype._updateSize): (WebInspector.TextEditor.prototype._repaintAll): (WebInspector.TextEditor.prototype._paint): (WebInspector.TextEditor.prototype._paintLinesContinuation): (WebInspector.TextEditor.prototype._mouseOut): (WebInspector.TextEditor.prototype._updateDivDecorations): (WebInspector.TextEditor.prototype._positionDivDecoration): (WebInspector.TextEditor.prototype._paintSelection): (WebInspector.TextEditor.prototype._replaceSelectionWith):
  • inspector/front-end/TextEditorHighlighter.js: (WebInspector.TextEditorHighlighter.prototype.updateHighlight):
  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.css:
  • inspector/front-end/inspector.html:
  • inspector/front-end/textEditor.css: Added.
Location:
trunk/WebCore
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53794 r53795  
     12010-01-24  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Add support for addMessage/clearMessages to SourceFrame2.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=33904
     8
     9        * WebCore.gypi:
     10        * WebCore.vcproj/WebCore.vcproj:
     11        * inspector/front-end/SourceFrame2.js:
     12        (WebInspector.SourceFrame2):
     13        (WebInspector.SourceFrame2.prototype.addMessage):
     14        (WebInspector.SourceFrame2.prototype.clearMessages):
     15        (WebInspector.SourceFrame2.prototype._incrementMessageRepeatCount):
     16        (WebInspector.SourceFrame2.prototype._addExistingMessagesToSource):
     17        (WebInspector.SourceFrame2.prototype._addMessageToSource):
     18        (WebInspector.SourceFrame2.prototype.resize):
     19        * inspector/front-end/TextEditor.js:
     20        (WebInspector.TextEditor):
     21        (WebInspector.TextEditor.prototype.setDivDecoration):
     22        (WebInspector.TextEditor.prototype._lineHeight):
     23        (WebInspector.TextEditor.prototype._highlightChanged):
     24        (WebInspector.TextEditor.prototype.packAndRepaintAll):
     25        (WebInspector.TextEditor.prototype._updateSize):
     26        (WebInspector.TextEditor.prototype._repaintAll):
     27        (WebInspector.TextEditor.prototype._paint):
     28        (WebInspector.TextEditor.prototype._paintLinesContinuation):
     29        (WebInspector.TextEditor.prototype._mouseOut):
     30        (WebInspector.TextEditor.prototype._updateDivDecorations):
     31        (WebInspector.TextEditor.prototype._positionDivDecoration):
     32        (WebInspector.TextEditor.prototype._paintSelection):
     33        (WebInspector.TextEditor.prototype._replaceSelectionWith):
     34        * inspector/front-end/TextEditorHighlighter.js:
     35        (WebInspector.TextEditorHighlighter.prototype.updateHighlight):
     36        * inspector/front-end/WebKit.qrc:
     37        * inspector/front-end/inspector.css:
     38        * inspector/front-end/inspector.html:
     39        * inspector/front-end/textEditor.css: Added.
     40
    1412010-01-24  Pavel Feldman  <pfeldman@chromium.org>
    242
     
    7435674396         (WebCore::RenderThemeQt::adjustButtonStyle):
    7435774397
    74358 === End merge of nitro-extreme branch 2009-07-30 ===
    74359 
    74360743982009-05-11  Geoffrey Garen  <ggaren@apple.com>
    7436174399
     
    7436974407        * bindings/scripts/CodeGeneratorJS.pm:
    7437074408        * bridge/c/c_instance.cpp:
    74371 
    74372 === Start merge of nitro-extreme branch 2009-07-30 ===
    7437374409
    74374744102009-07-30  Dean McNamee  <deanm@chromium.org>
  • trunk/WebCore/WebCore.gypi

    r53690 r53795  
    37613761            'inspector/front-end/inspector.css',
    37623762            'inspector/front-end/inspectorSyntaxHighlight.css',
     3763            'inspector/front-end/textEditor.css',
    37633764        ],
    37643765        'webinspector_image_files': [
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r53690 r53795  
    4307743077                                </File>
    4307843078                                <File
     43079                                        RelativePath="..\inspector\front-end\textEditor.css"
     43080                                        >
     43081                                </File>
     43082                                <File
    4307943083                                        RelativePath="..\inspector\front-end\TextPrompt.js"
    4308043084                                        >
  • trunk/WebCore/inspector/front-end/SourceFrame2.js

    r53205 r53795  
    3636    this._editor.lineDecorator = new WebInspector.ExecutionLineDecorator(this);
    3737    this._editor.readOnly = true;
     38    this._messages = [];
     39    this._rowMessages = {};
     40    this._messageBubbles = {};
    3841    this.element = this._editor.element;
    3942}
     
    4346    {
    4447        this._editor.text = text;
     48    },
     49
     50    addMessage: function(msg)
     51    {
     52        // Don't add the message if there is no message or valid line or if the msg isn't an error or warning.
     53        if (!msg.message || msg.line <= 0 || !msg.isErrorOrWarning())
     54            return;
     55        this._messages.push(msg);
     56        this._addMessageToSource(msg);
     57    },
     58
     59    clearMessages: function()
     60    {
     61        for (var line in this._messageBubbles) {
     62            var bubble = this._messageBubbles[line];
     63            bubble.parentNode.removeChild(bubble);
     64        }
     65
     66        this._messages = [];
     67        this._rowMessages = {};
     68        this._messageBubbles = {};
     69        this._editor.packAndRepaintAll();
     70    },
     71
     72    _incrementMessageRepeatCount: function(msg, repeatDelta)
     73    {
     74        if (!msg._resourceMessageLineElement)
     75            return;
     76
     77        if (!msg._resourceMessageRepeatCountElement) {
     78            var repeatedElement = document.createElement("span");
     79            msg._resourceMessageLineElement.appendChild(repeatedElement);
     80            msg._resourceMessageRepeatCountElement = repeatedElement;
     81        }
     82
     83        msg.repeatCount += repeatDelta;
     84        msg._resourceMessageRepeatCountElement.textContent = WebInspector.UIString(" (repeated %d times)", msg.repeatCount);
     85    },
     86
     87    _addExistingMessagesToSource: function()
     88    {
     89        var length = this._messages.length;
     90        for (var i = 0; i < length; ++i)
     91            this._addMessageToSource(this._messages[i]);
     92    },
     93
     94    _addMessageToSource: function(msg)
     95    {
     96        if (msg.line >= this._textModel.linesCount)
     97            return;
     98
     99        var messageBubbleElement = this._messageBubbles[msg.line];
     100        if (!messageBubbleElement || messageBubbleElement.nodeType !== Node.ELEMENT_NODE || !messageBubbleElement.hasStyleClass("webkit-html-message-bubble")) {
     101            messageBubbleElement = document.createElement("div");
     102            messageBubbleElement.className = "webkit-html-message-bubble";
     103            this._messageBubbles[msg.line] = messageBubbleElement;
     104            this._editor.setDivDecoration(msg.line, messageBubbleElement);
     105        }
     106
     107        var rowMessages = this._rowMessages[msg.line];
     108        if (!rowMessages) {
     109            rowMessages = [];
     110            this._rowMessages[msg.line] = rowMessages;
     111        }
     112
     113        for (var i = 0; i < rowMessages.length; ++i) {
     114            if (rowMessages[i].isEqual(msg, true)) {
     115                this._incrementMessageRepeatCount(rowMessages[i], msg.repeatDelta);
     116                this._editor.packAndRepaintAll();
     117                return;
     118            }
     119        }
     120
     121        rowMessages.push(msg);
     122
     123        var imageURL;
     124        switch (msg.level) {
     125            case WebInspector.ConsoleMessage.MessageLevel.Error:
     126                messageBubbleElement.addStyleClass("webkit-html-error-message");
     127                imageURL = "Images/errorIcon.png";
     128                break;
     129            case WebInspector.ConsoleMessage.MessageLevel.Warning:
     130                messageBubbleElement.addStyleClass("webkit-html-warning-message");
     131                imageURL = "Images/warningIcon.png";
     132                break;
     133        }
     134
     135        var messageLineElement = document.createElement("div");
     136        messageLineElement.className = "webkit-html-message-line";
     137        messageBubbleElement.appendChild(messageLineElement);
     138
     139        // Create the image element in the Inspector's document so we can use relative image URLs.
     140        var image = document.createElement("img");
     141        image.src = imageURL;
     142        image.className = "webkit-html-message-icon";
     143        messageLineElement.appendChild(image);
     144        messageLineElement.appendChild(document.createTextNode(msg.message));
     145
     146        msg._resourceMessageLineElement = messageLineElement;
     147
     148        this._editor.packAndRepaintAll();
    45149    },
    46150
     
    71175    resize: function()
    72176    {
    73         this._editor.updateCanvasSize();
     177        this._editor.packAndRepaintAll();
    74178    }
    75179}
  • trunk/WebCore/inspector/front-end/TextEditor.js

    r53242 r53795  
    5959    this._cursor = new WebInspector.TextCursor(cursorElement);
    6060
    61     this._container.addEventListener("scroll", this._scroll.bind(this));
    62     this._sheet.addEventListener("mouseup", this._mouseUp.bind(this));
    63     this._sheet.addEventListener("mousedown", this._mouseDown.bind(this));
    64     this._sheet.addEventListener("mousemove", this._mouseMove.bind(this));
    65     this._sheet.addEventListener("mouseout", this._mouseOut.bind(this));
    66     this._sheet.addEventListener("dblclick", this._dblClick.bind(this));
    67     this.element.addEventListener("keydown", this._keyDown.bind(this));
    68     this.element.addEventListener("textInput", this._textInput.bind(this));
    69     this.element.addEventListener("beforecopy", this._beforeCopy.bind(this));
    70     this.element.addEventListener("copy", this._copy.bind(this));
    71     this.element.addEventListener("beforecut", this._beforeCut.bind(this));
    72     this.element.addEventListener("cut", this._cut.bind(this));
    73     this.element.addEventListener("beforepaste", this._beforePaste.bind(this));
    74     this.element.addEventListener("paste", this._paste.bind(this));
     61    this._container.addEventListener("scroll", this._scroll.bind(this), false);
     62    this._sheet.addEventListener("mouseup", this._mouseUp.bind(this), false);
     63    this._sheet.addEventListener("mousedown", this._mouseDown.bind(this), false);
     64    this._sheet.addEventListener("mousemove", this._mouseMove.bind(this), false);
     65    this._sheet.addEventListener("mouseout", this._mouseOut.bind(this), false);
     66    this._sheet.addEventListener("dblclick", this._dblClick.bind(this), false);
     67    this.element.addEventListener("keydown", this._keyDown.bind(this), false);
     68    this.element.addEventListener("textInput", this._textInput.bind(this), false);
     69    this.element.addEventListener("beforecopy", this._beforeCopy.bind(this), false);
     70    this.element.addEventListener("copy", this._copy.bind(this), false);
     71    this.element.addEventListener("beforecut", this._beforeCut.bind(this), false);
     72    this.element.addEventListener("cut", this._cut.bind(this), false);
     73    this.element.addEventListener("beforepaste", this._beforePaste.bind(this), false);
     74    this.element.addEventListener("paste", this._paste.bind(this), false);
    7575
    7676    this._desiredCaretColumn = 0;
     
    136136        this._selection.setStart(start.line, start.column);
    137137        this._setSelectionEnd(endLine, endColumn);
     138    },
     139
     140    setDivDecoration: function(lineNumber, element)
     141    {
     142        var divDecoration = this._textModel.getAttribute(lineNumber, "div-decoration");
     143        if (divDecoration && divDecoration.element && divDecoration.element.parentNode)
     144            divDecoration.element.parentNode.removeChild(divDecoration.element);
     145
     146        divDecoration = { element: element };
     147        this.element.appendChild(element);
     148
     149        this._textModel.setAttribute(lineNumber, "div-decoration", divDecoration);
     150        this.packAndRepaintAll();
    138151    },
    139152
     
    180193    _lineHeight: function(lineNumber)
    181194    {
    182         return this._debugMode ? this._textLineHeight * (1 + lineNumber % 3) : this._textLineHeight;
     195        var divDecoration = this._textModel.getAttribute(lineNumber, "div-decoration");
     196        if (divDecoration)
     197            return 2 * this._textLineHeight + divDecoration.element.clientHeight;
     198        return this._textLineHeight;
    183199    },
    184200
     
    240256    _highlightChanged: function(fromLine, toLine)
    241257    {
     258        if (this._muteHighlightListener)
     259            return;
     260
    242261        this._invalidateLines(fromLine, toLine);
    243262        this._paint();
    244263    },
    245264
     265    packAndRepaintAll: function()
     266    {
     267        this._setCoalescingUpdate(true);
     268        this._lineOffsetsCache = [0];
     269        this._updateSize(0, this._textModel.linesCount);
     270        this._repaintAll();
     271        this._setCoalescingUpdate(false);
     272    },
     273
    246274    _updateSize: function(startLine, endLine)
    247275    {
     276        this._setCoalescingUpdate(true);
    248277        var guardedEndLine = Math.min(this._textModel.linesCount, endLine + 1);
    249278        var newMaximum = false;
     
    281310            this._repaintAll();
    282311        }
    283        
     312
    284313        // Changes to size can change the client area (scrollers can appear/disappear)
    285314        this.updateCanvasSize();
     315        this._setCoalescingUpdate(false);
    286316    },
    287317
     
    298328    {
    299329        this._invalidateLines(0, this._textModel.linesCount);
    300         this.paintLineNumbers();
    301330        this._paint();
    302         this._updateCursor(this._selection.endLine, this._selection.endColumn);
    303331    },
    304332
     
    325353            return;
    326354
     355        this.paintLineNumbers();
     356
    327357        for (var i = 0; this._damage && i < this._damage.length; ++i)
    328358            this._paintLines(this._damage[i].startLine, this._damage[i].endLine);
    329359        delete this._damage;
     360
     361        this._updateDivDecorations();
     362        this._updateCursor(this._selection.endLine, this._selection.endColumn);
    330363    },
    331364
     
    375408        this._paintSelection(firstLine, lastLine);
    376409
    377         if (this._highlightingEnabled)
     410        if (this._highlightingEnabled) {
     411            this._muteHighlightListener = true;
    378412            this._highlighter.highlight(lastLine);
    379 
     413            delete this._muteHighlightListener;
     414        }
    380415        for (var i = firstLine; i < lastLine; ++i) {
    381416            var line = this._textModel.line(i);
     
    384419            if (this._lineDecorator)
    385420                this._lineDecorator.decorate(i, this._ctx, this._lineNumberWidth - 1, lineOffset, this._canvas.width - this._lineNumberWidth + 1, this._lineHeight(i), this._textLineHeight);
     421
     422            var divDecoration = this._textModel.getAttribute(i, "div-decoration");
     423            if (divDecoration)
     424                this._positionDivDecoration(i, divDecoration, true);
    386425
    387426            if (!this._highlightingEnabled) {
     
    495534    _mouseOut: function(e)
    496535    {
    497         this._isDragging = false;
    498536    },
    499537
     
    679717    },
    680718
     719    _updateDivDecorations: function()
     720    {
     721        var firstLine = this._offsetToLine(this._scrollTop) - 1;
     722        var lastLine = this._offsetToLine(this._scrollTop + this._canvas.height) + 1;
     723
     724        var linesCount = this._textModel.linesCount;
     725        for (var i = 0; i < linesCount; ++i) {
     726            var divDecoration = this._textModel.getAttribute(i, "div-decoration");
     727            if (divDecoration)
     728                this._positionDivDecoration(i, divDecoration, i > firstLine && i < lastLine);
     729        }
     730    },
     731
     732    _positionDivDecoration: function(lineNumber, divDecoration, visible)
     733    {
     734        divDecoration.element.style.position = "absolute";
     735        divDecoration.element.style.top = this._lineToOffset(lineNumber) - this._scrollTop + this._textLineHeight + "px";
     736        divDecoration.element.style.left = this._lineNumberWidth + "px";
     737        divDecoration.element.style.setProperty("max-width", (this._canvas.width - 200) + "px");
     738    },
     739
    681740    _updateCursor: function(line, column)
    682741    {
     
    724783                to = this._canvas.width;
    725784
    726             this._ctx.fillRect(from, this._lineToOffset(i) - this._scrollTop, to - from, this._textLineHeight);
     785            this._ctx.fillRect(from, this._lineToOffset(i) - this._scrollTop, to - from, this._lineHeight(i));
    727786        }
    728787        this._ctx.fillStyle = "rgb(0, 0, 0)";
     
    781840    {
    782841        var range = overrideRange || this._selection.range();
    783 
    784842        this._setCoalescingUpdate(true);
    785843        var newRange = this._textModel.setText(range, newText);
  • trunk/WebCore/inspector/front-end/TextEditorHighlighter.js

    r53205 r53795  
    107107    {
    108108        // Start line was edited, we should highlight everything until endLine synchronously.
    109         var state = this._textModel.getAttribute(startLine, "highlighter-state");
    110         if (!state || state.outOfDate) {
    111             // Highlighter did not reach this point yet, nothing to update. It will reach it on subsequent timer tick and do the job.
    112             return;
     109        if (startLine) {
     110            var state = this._textModel.getAttribute(startLine - 1, "highlighter-state");
     111            if (!state || state.outOfDate) {
     112                // Highlighter did not reach this point yet, nothing to update. It will reach it on subsequent timer tick and do the job.
     113                return;
     114            }
    113115        }
    114116
  • trunk/WebCore/inspector/front-end/WebKit.qrc

    r53328 r53795  
    9090    <file>inspector.css</file>
    9191    <file>inspectorSyntaxHighlight.css</file>
     92    <file>textEditor.css</file>
    9293    <file>Images/back.png</file>
    9394    <file>Images/checker.png</file>
  • trunk/WebCore/inspector/front-end/inspector.css

    r53794 r53795  
    38183818}
    38193819
    3820 .text-editor-sheet, .text-editor-clip {
     3820.text-editor-clip {
    38213821    opacity: 0;
     3822    position: absolute;
     3823    top:0;
     3824    left:0;
     3825    pointer-events: none;
    38223826}
    38233827
  • trunk/WebCore/inspector/front-end/inspector.html

    r53328 r53795  
    3131    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    3232    <link rel="stylesheet" type="text/css" href="audits.css">
     33    <link rel="stylesheet" type="text/css" href="textEditor.css">
    3334    <link rel="stylesheet" type="text/css" href="inspector.css">
    3435    <link rel="stylesheet" type="text/css" href="inspectorSyntaxHighlight.css">
Note: See TracChangeset for help on using the changeset viewer.