Commit ab0fd135 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

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

        Reviewed by Timothy Hatcher.

        Web Inspector: Syntax highlighting in source view of
        Resources pane stops half-way.

        There were two problems here: (1) styles for html highlighter were not
        added into the css file (they used to be injected manually in the
        SourceFrame before). (2) 'Tag' needed to be lexer's state, not parser's.
        Otherwise unbalanced quotes in the text nodes were matching too match
        into the string tokens.

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

        * inspector/front-end/NativeTextViewer.js:
        (WebInspector.NativeTextViewer.prototype._createLineDivs):
        (WebInspector.NativeTextViewer.prototype._lineHeight):
        (WebInspector.NativeTextViewer.prototype.initFontMetrics):
        * inspector/front-end/SourceFrame.js:
        (WebInspector.SourceFrame.prototype._createEditorIfNeeded):
        * inspector/front-end/SourceHTMLTokenizer.js:
        (WebInspector.SourceHTMLTokenizer):
        (WebInspector.SourceHTMLTokenizer.prototype.nextToken):
        * inspector/front-end/SourceHTMLTokenizer.re2js:
        * inspector/front-end/TextEditor.js:
        (WebInspector.TextEditor.prototype.initFontMetrics):
        (WebInspector.TextEditor.prototype._registerShortcuts):
        * inspector/front-end/inspectorSyntaxHighlight.css:


git-svn-id: svn://svn.chromium.org/blink/trunk@54139 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f18574d2
2010-02-01 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Timothy Hatcher.
Web Inspector: Syntax highlighting in source view of
Resources pane stops half-way.
There were two problems here: (1) styles for html highlighter were not
added into the css file (they used to be injected manually in the
SourceFrame before). (2) 'Tag' needed to be lexer's state, not parser's.
Otherwise unbalanced quotes in the text nodes were matching too match
into the string tokens.
https://bugs.webkit.org/show_bug.cgi?id=34359
* inspector/front-end/NativeTextViewer.js:
(WebInspector.NativeTextViewer.prototype._createLineDivs):
(WebInspector.NativeTextViewer.prototype._lineHeight):
(WebInspector.NativeTextViewer.prototype.initFontMetrics):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype._createEditorIfNeeded):
* inspector/front-end/SourceHTMLTokenizer.js:
(WebInspector.SourceHTMLTokenizer):
(WebInspector.SourceHTMLTokenizer.prototype.nextToken):
* inspector/front-end/SourceHTMLTokenizer.re2js:
* inspector/front-end/TextEditor.js:
(WebInspector.TextEditor.prototype.initFontMetrics):
(WebInspector.TextEditor.prototype._registerShortcuts):
* inspector/front-end/inspectorSyntaxHighlight.css:
2010-02-01 Ben Murdoch <benm@google.com>
Reviewed by Darin Adler.
......
......@@ -58,6 +58,7 @@ WebInspector.NativeTextViewer.prototype = {
lineDiv.style.minHeight = this._textLineHeight + "px";
this._sheet.appendChild(lineDiv);
this._textModel.setAttribute(i, "line-div", lineDiv);
this._textModel.removeAttribute(i, "div-highlighted");
}
this._container.appendChild(this._sheet);
},
......@@ -143,8 +144,8 @@ WebInspector.NativeTextViewer.prototype = {
if (lineNumber + 1 < this._textModel.linesCount) {
var nextElement = this._textModel.getAttribute(lineNumber + 1, "line-div");
return nextElement.offsetTop - element.offsetTop;
} else
return element.parentElement.offsetHeight - element.offsetTop;
}
return element.parentElement.offsetHeight - element.offsetTop;
},
_paintLine: function(lineNumber, lineOffset)
......@@ -213,9 +214,9 @@ WebInspector.NativeTextViewer.prototype = {
this.revalidateDecorationsAndPaint();
},
_initFontMetrics: function()
initFontMetrics: function()
{
WebInspector.TextEditor.prototype._initFontMetrics.call(this);
WebInspector.TextEditor.prototype.initFontMetrics.call(this);
for (var i = 0; i < this._textModel.linesCount; ++i) {
var lineDiv = this._textModel.getAttribute(i, "line-div");
if (!this._textModel.line(i))
......
......@@ -144,7 +144,7 @@ WebInspector.SourceFrame.prototype = {
this._element = this._editor.element;
this._element.addEventListener("keydown", this._keyDown.bind(this), true);
this._parentElement.appendChild(this._element);
this._editor._initFontMetrics();
this._editor.initFontMetrics();
this._editor.mimeType = this._mimeType;
......
......@@ -44,29 +44,30 @@ WebInspector.SourceHTMLTokenizer = function()
{
WebInspector.SourceTokenizer.call(this);
// The order is determined by the generated code.
this._lexConditions = {
INITIAL: 0,
COMMENT: 1,
DSTRING: 2,
SSTRING: 3
TAG: 2,
DSTRING: 4,
SSTRING: 5
};
this.case_INITIAL = 1000;
this.case_COMMENT = 1001;
this.case_TAG = 1002;
this.case_DSTRING = 1004;
this.case_SSTRING = 1005;
this._parseConditions = {
INITIAL: 0,
TAG: 1,
ATTRIBUTE: 2,
ATTRIBUTE_VALUE: 3,
SCRIPT: 4,
SCRIPT_ATTRIBUTE: 5,
SCRIPT_ATTRIBUTE_VALUE: 6,
DOCTYPE: 7
ATTRIBUTE: 1,
ATTRIBUTE_VALUE: 2,
SCRIPT: 3,
SCRIPT_ATTRIBUTE: 4,
SCRIPT_ATTRIBUTE_VALUE: 5,
DOCTYPE: 6
};
this.case_INITIAL = 1000;
this.case_COMMENT = 1001;
this.case_DSTRING = 1002;
this.case_SSTRING = 1003;
this.initialCondition = { lexCondition: this._lexConditions.INITIAL, parseCondition: this._parseConditions.INITIAL };
}
......@@ -157,40 +158,43 @@ WebInspector.SourceHTMLTokenizer.prototype = {
<COMMENT> CommentContent => COMMENT { this.tokenType = "html-comment"; return cursor; }
<COMMENT> CommentEnd => INITIAL { this.tokenType = "html-comment"; return cursor; }
<INITIAL> DocTypeLT => INITIAL
<INITIAL> DocTypeLT => TAG
{
this.tokenType = "html-doctype";
this._parseCondition = this._parseConditions.DOCTYPE;
return cursor;
}
<INITIAL> ScriptStart => INITIAL
<INITIAL> ScriptStart => TAG
{
this.tokenType = "html-tag";
this._parseCondition = this._parseConditions.SCRIPT_ATTRIBUTE;
return cursor;
}
<INITIAL> ScriptEnd => INITIAL
<INITIAL> ScriptEnd => TAG
{
this.tokenType = "html-tag";
this._parseCondition = this._parseConditions.INITIAL;
return cursor;
}
<INITIAL> LT => INITIAL
<INITIAL> LT
{
if (this._parseCondition === this._parseConditions.SCRIPT) {
this.tokenType = null;
return cursor;
}
// Only make lexer transition if not in script tag.
this.setLexCondition(this._lexConditions.TAG);
this.tokenType = "html-tag";
this._parseCondition = this._parseConditions.TAG;
this._parseCondition = this._parseConditions.INITIAL;
return cursor;
}
<INITIAL> GT => INITIAL
<TAG> GT => INITIAL
{
if (this._parseCondition === this._parseConditions.SCRIPT) {
this.tokenType = null;
......@@ -209,15 +213,15 @@ WebInspector.SourceHTMLTokenizer.prototype = {
return cursor;
}
<INITIAL> StringLiteral { return this._stringToken(cursor, true); }
<INITIAL> DoubleStringStart => DSTRING { return this._stringToken(cursor); }
<TAG> StringLiteral { return this._stringToken(cursor, true); }
<TAG> DoubleStringStart => DSTRING { return this._stringToken(cursor); }
<DSTRING> DoubleStringContent => DSTRING { return this._stringToken(cursor); }
<DSTRING> DoubleStringEnd => INITIAL { return this._stringToken(cursor, true); }
<INITIAL> SingleStringStart => SSTRING { return this._stringToken(cursor); }
<DSTRING> DoubleStringEnd => TAG { return this._stringToken(cursor, true); }
<TAG> SingleStringStart => SSTRING { return this._stringToken(cursor); }
<SSTRING> SingleStringContent => SSTRING { return this._stringToken(cursor); }
<SSTRING> SingleStringEnd => INITIAL { return this._stringToken(cursor, true); }
<SSTRING> SingleStringEnd => TAG { return this._stringToken(cursor, true); }
<INITIAL> EqualSign => INITIAL
<TAG> EqualSign => TAG
{
if (this._isAttribute()) {
this.tokenType = null;
......@@ -229,14 +233,14 @@ WebInspector.SourceHTMLTokenizer.prototype = {
return cursor;
}
<INITIAL> Identifier
<TAG> Identifier
{
if (this._parseCondition === this._parseConditions.SCRIPT) {
this.tokenType = null;
return cursor;
}
if (this._parseCondition === this._parseConditions.TAG) {
if (this._parseCondition === this._parseConditions.INITIAL) {
this.tokenType = "html-tag";
this._parseCondition = this._parseConditions.ATTRIBUTE;
} else if (this._isAttribute())
......
......@@ -976,7 +976,7 @@ WebInspector.TextEditor.prototype = {
this._updateCursor(this._selection.endLine, this._selection.endColumn);
},
_initFontMetrics: function()
initFontMetrics: function()
{
var computedStyle = window.getComputedStyle(this.element);
this._font = computedStyle.fontSize + " " + computedStyle.fontFamily;
......@@ -998,7 +998,6 @@ WebInspector.TextEditor.prototype = {
this._shortcuts[WebInspector.KeyboardShortcut.makeKey("d", modifiers.Ctrl | modifiers.Alt)] = this._handleToggleDebugMode.bind(this);
this._shortcuts[WebInspector.KeyboardShortcut.makeKey("h", modifiers.Ctrl | modifiers.Alt)] = this._handleToggleHighlightMode.bind(this);
this._shortcuts[WebInspector.KeyboardShortcut.makeKey("m", modifiers.Ctrl | modifiers.Alt)] = this._handleToggleMonospaceMode.bind(this);
},
_handleUndo: function()
......
......@@ -65,3 +65,24 @@
.webkit-javascript-string, .webkit-javascript-regexp {
color: rgb(196, 26, 22);
}
/* Keep this in sync with view-source.css */
.webkit-html-tag {
color: rgb(136, 18, 128);
}
.webkit-html-attr-name {
color: rgb(153, 69, 0);
}
.webkit-html-attr-value {
color: rgb(26, 26, 166);
}
.webkit-html-comment {
color: rgb(35, 110, 37);
}
.webkit-html-doctype {
color: rgb(192, 192, 192);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment