From 9aa68303cf20f5057f8c9eb2738da0b94f7e3149 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Sat, 23 May 2015 18:17:50 -0500 Subject: [PATCH] Bug 1067325 - Control syntax highlighting via a class. r=hsivonen --- layout/style/viewsource.css | 30 +++++++++---------- parser/html/nsHtml5Highlighter.cpp | 23 -------------- parser/html/nsHtml5Highlighter.h | 5 ---- parser/html/nsHtml5ViewSourceUtils.cpp | 8 ++++- .../tests/reftest/bug482921-1-ref.html | 2 +- .../tests/reftest/bug482921-2-ref.html | 2 +- .../tests/reftest/bug535530-2-ref.html | 2 +- .../tests/reftest/bug704667-1-ref.html | 2 +- .../tests/reftest/bug731234-1-ref.html | 2 +- .../tests/reftest/bug910588-1-ref.html | 2 +- 10 files changed, 28 insertions(+), 50 deletions(-) diff --git a/layout/style/viewsource.css b/layout/style/viewsource.css index 85526fe110f..8f5b66e381d 100644 --- a/layout/style/viewsource.css +++ b/layout/style/viewsource.css @@ -40,45 +40,45 @@ span[id]:before { font-weight: normal; font-style: normal; } -.start-tag { +.highlight .start-tag { color: purple; font-weight: bold; } -.end-tag { +.highlight .end-tag { color: purple; font-weight: bold; } -.comment { +.highlight .comment { color: green; font-style: italic; } -.cdata { +.highlight .cdata { color: #CC0066; } -.doctype { +.highlight .doctype { color: steelblue; font-style: italic; } -.pi { +.highlight .pi { color: orchid; font-style: italic; } -.entity { - color:#FF4500; +.highlight .entity { + color: #FF4500; font-weight: normal; } -.text { +.highlight .text { font-weight: normal; } -.attribute-name { +.highlight .attribute-name { color: black; font-weight: bold; } -.attribute-value { +.highlight .attribute-value { color: blue; font-weight: normal; } -.markupdeclaration { +.highlight .markupdeclaration { color: steelblue; font-style: italic; } @@ -88,9 +88,9 @@ span:not(.error), a:not(.error) { span[id] { unicode-bidi: -moz-isolate; } -.error, -.error > :-moz-any(.start-tag, .end-tag, .comment, .cdata, .doctype, .pi, - .entity, .attribute-name, .attribute-value) { +.highlight .error, +.highlight .error > :-moz-any(.start-tag, .end-tag, .comment, .cdata, .doctype, + .pi, .entity, .attribute-name, .attribute-value) { color: red; font-weight: bold; } diff --git a/parser/html/nsHtml5Highlighter.cpp b/parser/html/nsHtml5Highlighter.cpp index 9ddfadd17f7..7ae96ffed05 100644 --- a/parser/html/nsHtml5Highlighter.cpp +++ b/parser/html/nsHtml5Highlighter.cpp @@ -53,8 +53,6 @@ nsHtml5Highlighter::nsHtml5Highlighter(nsAHtml5TreeOpSink* aOpSink) , mInlinesOpen(0) , mInCharacters(false) , mBuffer(nullptr) - , mSyntaxHighlight(Preferences::GetBool("view_source.syntax_highlight", - true)) , mOpSink(aOpSink) , mCurrentRun(nullptr) , mAmpersand(nullptr) @@ -713,9 +711,6 @@ nsHtml5Highlighter::AppendCharacters(const char16_t* aBuffer, void nsHtml5Highlighter::AddClass(const char16_t* aClass) { - if (!mSyntaxHighlight) { - return; - } mOpQueue.AppendElement()->InitAddClass(CurrentNode(), aClass); } @@ -751,9 +746,6 @@ nsHtml5Highlighter::AddBase(const nsString& aValue) void nsHtml5Highlighter::AddErrorToCurrentNode(const char* aMsgId) { - if (!mSyntaxHighlight) { - return; - } nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); NS_ASSERTION(treeOp, "Tree op allocation failed."); treeOp->Init(CurrentNode(), aMsgId); @@ -762,9 +754,6 @@ nsHtml5Highlighter::AddErrorToCurrentNode(const char* aMsgId) void nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId) { - if (!mSyntaxHighlight) { - return; - } NS_PRECONDITION(mCurrentRun, "Adding error to run without one!"); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); NS_ASSERTION(treeOp, "Tree op allocation failed."); @@ -775,9 +764,6 @@ void nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId, nsIAtom* aName) { - if (!mSyntaxHighlight) { - return; - } NS_PRECONDITION(mCurrentRun, "Adding error to run without one!"); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); NS_ASSERTION(treeOp, "Tree op allocation failed."); @@ -789,9 +775,6 @@ nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId, nsIAtom* aName, nsIAtom* aOther) { - if (!mSyntaxHighlight) { - return; - } NS_PRECONDITION(mCurrentRun, "Adding error to run without one!"); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); NS_ASSERTION(treeOp, "Tree op allocation failed."); @@ -801,9 +784,6 @@ nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId, void nsHtml5Highlighter::AddErrorToCurrentAmpersand(const char* aMsgId) { - if (!mSyntaxHighlight) { - return; - } NS_PRECONDITION(mAmpersand, "Adding error to ampersand without one!"); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); NS_ASSERTION(treeOp, "Tree op allocation failed."); @@ -813,9 +793,6 @@ nsHtml5Highlighter::AddErrorToCurrentAmpersand(const char* aMsgId) void nsHtml5Highlighter::AddErrorToCurrentSlash(const char* aMsgId) { - if (!mSyntaxHighlight) { - return; - } NS_PRECONDITION(mSlash, "Adding error to slash without one!"); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); NS_ASSERTION(treeOp, "Tree op allocation failed."); diff --git a/parser/html/nsHtml5Highlighter.h b/parser/html/nsHtml5Highlighter.h index c536916b35a..086cc76826e 100644 --- a/parser/html/nsHtml5Highlighter.h +++ b/parser/html/nsHtml5Highlighter.h @@ -313,11 +313,6 @@ class nsHtml5Highlighter */ nsHtml5UTF16Buffer* mBuffer; - /** - * Whether to highlight syntax visibly initially. - */ - bool mSyntaxHighlight; - /** * The outgoing tree op queue. */ diff --git a/parser/html/nsHtml5ViewSourceUtils.cpp b/parser/html/nsHtml5ViewSourceUtils.cpp index 1cb4377bf4a..f28249db6e6 100644 --- a/parser/html/nsHtml5ViewSourceUtils.cpp +++ b/parser/html/nsHtml5ViewSourceUtils.cpp @@ -15,8 +15,14 @@ nsHtml5ViewSourceUtils::NewBodyAttributes() nsString* id = new nsString(NS_LITERAL_STRING("viewsource")); bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id); + nsString* klass = new nsString(); if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) { - nsString* klass = new nsString(NS_LITERAL_STRING("wrap")); + klass->Append(NS_LITERAL_STRING("wrap ")); + } + if (mozilla::Preferences::GetBool("view_source.syntax_highlight", true)) { + klass->Append(NS_LITERAL_STRING("highlight")); + } + if (!klass->IsEmpty()) { bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass); } diff --git a/parser/htmlparser/tests/reftest/bug482921-1-ref.html b/parser/htmlparser/tests/reftest/bug482921-1-ref.html index 2d23b31c7f0..d388a14bc51 100644 --- a/parser/htmlparser/tests/reftest/bug482921-1-ref.html +++ b/parser/htmlparser/tests/reftest/bug482921-1-ref.html @@ -1,4 +1,4 @@ -
<!DOCTYPE html>
+
<!DOCTYPE html>
 <html>
 <head>
 <title>Title</title>
diff --git a/parser/htmlparser/tests/reftest/bug482921-2-ref.html b/parser/htmlparser/tests/reftest/bug482921-2-ref.html
index e2e92164582..44f6c03dff4 100644
--- a/parser/htmlparser/tests/reftest/bug482921-2-ref.html
+++ b/parser/htmlparser/tests/reftest/bug482921-2-ref.html
@@ -1,4 +1,4 @@
-
<?xml version="1.0" encoding="utf-8"?>
+
<?xml version="1.0" encoding="utf-8"?>
 <?foo bar?>
 <html>
 <head>
diff --git a/parser/htmlparser/tests/reftest/bug535530-2-ref.html b/parser/htmlparser/tests/reftest/bug535530-2-ref.html
index 636b598979a..5931b9b16be 100644
--- a/parser/htmlparser/tests/reftest/bug535530-2-ref.html
+++ b/parser/htmlparser/tests/reftest/bug535530-2-ref.html
@@ -1,4 +1,4 @@
-
<!DOCTYPE html>
+
<!DOCTYPE html>
 XX&XX
 XX&nXX
 XX&noXX
diff --git a/parser/htmlparser/tests/reftest/bug704667-1-ref.html b/parser/htmlparser/tests/reftest/bug704667-1-ref.html
index 8f57e120959..db05bd5245d 100644
--- a/parser/htmlparser/tests/reftest/bug704667-1-ref.html
+++ b/parser/htmlparser/tests/reftest/bug704667-1-ref.html
@@ -1,4 +1,4 @@
-
<!--> <!X>
+
<!--> <!X>
 
 
diff --git a/parser/htmlparser/tests/reftest/bug731234-1-ref.html b/parser/htmlparser/tests/reftest/bug731234-1-ref.html index f20ae4d654d..31b808ec4d4 100644 --- a/parser/htmlparser/tests/reftest/bug731234-1-ref.html +++ b/parser/htmlparser/tests/reftest/bug731234-1-ref.html @@ -1,4 +1,4 @@ -
<!DOCTYPE html>
+
<!DOCTYPE html>
 <body>
 <script></script>X
 <script></script >X
diff --git a/parser/htmlparser/tests/reftest/bug910588-1-ref.html b/parser/htmlparser/tests/reftest/bug910588-1-ref.html
index 38b00a38239..da9c6867ab1 100644
--- a/parser/htmlparser/tests/reftest/bug910588-1-ref.html
+++ b/parser/htmlparser/tests/reftest/bug910588-1-ref.html
@@ -1,2 +1,2 @@
-
<!DOCTYPE html><table><input type=hidden></table>
+
<!DOCTYPE html><table><input type=hidden></table>