From 67e1cb2bbb897ddd6f260e4ac406f200b72e032a Mon Sep 17 00:00:00 2001 From: "rbs%maths.uq.edu.au" Date: Tue, 17 Apr 2001 07:23:04 +0000 Subject: [PATCH] Improve the speed of viewsource - Patch of Boris Zbarsky b=74486 r=rbs r=attinasi --- build/mac/build_scripts/MozillaBuildList.pm | 1 + embedding/config/basebrowser-unix | 3 +- embedding/config/basebrowser-win | 3 +- htmlparser/src/nsViewSourceHTML.cpp | 82 +++++------ htmlparser/src/nsViewSourceHTML.h | 1 + layout/build/nsLayoutDLF.cpp | 38 ++++- layout/build/nsLayoutModule.cpp | 2 + layout/build/nsLayoutModule.h | 2 + layout/html/document/src/Makefile.in | 4 +- layout/html/document/src/makefile.win | 2 + layout/html/document/src/ua.css | 1 + layout/html/document/src/viewsource.css | 153 +++++++------------- layout/style/ua.css | 1 + layout/style/viewsource.css | 153 +++++++------------- parser/htmlparser/src/nsViewSourceHTML.cpp | 82 +++++------ parser/htmlparser/src/nsViewSourceHTML.h | 1 + xpinstall/packager/packages-mac | 1 + xpinstall/packager/packages-unix | 1 + xpinstall/packager/packages-win | 1 + 19 files changed, 234 insertions(+), 298 deletions(-) diff --git a/build/mac/build_scripts/MozillaBuildList.pm b/build/mac/build_scripts/MozillaBuildList.pm index 483ca549f389..94a29d9a2001 100644 --- a/build/mac/build_scripts/MozillaBuildList.pm +++ b/build/mac/build_scripts/MozillaBuildList.pm @@ -197,6 +197,7 @@ sub InstallNonChromeResources() MakeAlias(":mozilla:layout:html:document:src:html.css", "$resource_dir"); MakeAlias(":mozilla:layout:html:document:src:forms.css", "$resource_dir"); MakeAlias(":mozilla:layout:html:document:src:quirk.css", "$resource_dir"); + MakeAlias(":mozilla:layout:html:document:src:viewsource.css", "$resource_dir"); MakeAlias(":mozilla:layout:html:document:src:arrow.gif", "$resource_dir"); MakeAlias(":mozilla:webshell:tests:viewer:resources:viewer.properties", "$resource_dir"); MakeAlias(":mozilla:intl:uconv:src:charsetalias.properties", "$resource_dir"); diff --git a/embedding/config/basebrowser-unix b/embedding/config/basebrowser-unix index c34234c502b6..b63ae828efc5 100644 --- a/embedding/config/basebrowser-unix +++ b/embedding/config/basebrowser-unix @@ -218,7 +218,8 @@ chrome/embed.jar ; res: ; res/html.css -res/quirk.css +res/quirk.css +res/viewsource.css res/ua.css res/forms.css res/builtin/* diff --git a/embedding/config/basebrowser-win b/embedding/config/basebrowser-win index d68632ddc0ba..6165705d00fb 100644 --- a/embedding/config/basebrowser-win +++ b/embedding/config/basebrowser-win @@ -218,7 +218,8 @@ chrome\embed.jar ; res: ; res\html.css -res\quirk.css +res\quirk.css +res\viewsource.css res\ua.css res\forms.css res\builtin\* diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index c1db06a844e9..cb1c003949d6 100644 --- a/htmlparser/src/nsViewSourceHTML.cpp +++ b/htmlparser/src/nsViewSourceHTML.cpp @@ -48,7 +48,6 @@ #endif #define VIEW_SOURCE_HTML -#define VIEW_SOURCE_COLORING #include "nsIDTDDebug.h" #include "nsViewSourceHTML.h" @@ -65,13 +64,11 @@ #include "nsHTMLEntities.h" #endif // VIEW_SOURCE_HTML -#ifdef VIEW_SOURCE_COLORING // For Coloring pref only // If we aren't going to define it, then should save on bloat. #include "nsIPref.h" #include "nsIServiceManager.h" static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); -#endif // VIEW_SOURCE_COLORING #include "COtherDTD.h" #include "nsElementTable.h" @@ -100,7 +97,7 @@ static int gErrorThreshold = 10; #endif #ifdef VIEW_SOURCE_HTML -static const char* kPreStyle = "font-family: -moz-fixed; font-weight:normal; color:black; padding-top:4px; margin-left:4px;"; +static const char* kPreClass = "viewsource"; #endif // VIEW_SOURCE_HTML /** @@ -229,23 +226,21 @@ enum { VIEW_SOURCE_MARKUPDECLARATION = 12 }; -#ifdef VIEW_SOURCE_COLORING -static char* kElementStyles[] = { - "color: purple; font-weight:bold;", - "color: purple; font-weight:bold;", - "color: green; font-style:italic;", - "color: #CC0066;", - "color:steelblue; font-style:italic;", - "color:orchid; font-style:italic;", - "color:#FF4500; font-weight:normal;", - "font-weight: normal;", - "color: black; font-weight:bold;", - "color: blue; font-weight:normal;", - "display:block; background-color:#FFFFCC; width:90%; border:solid; border-width:1pt; font-family: Sans-serif;", - "font-weight: normal;", - "color:steelblue; font-style:italic;" +static char* kElementClasses[] = { + "start-tag", + "end-tag", + "comment", + "cdata", + "doctype", + "pi", + "entity", + "text", + "attribute-name", + "attribute-value", + "summary", + "popup", + "markupdeclaration" }; -#endif static char* kBeforeText[] = { "<", @@ -305,6 +300,12 @@ CViewSourceHTML::CViewSourceHTML() : mTags(), mErrors() { mValue = VIEW_SOURCE_ATTRIBUTE_VALUE; mSummaryTag = VIEW_SOURCE_SUMMARY; mPopupTag = VIEW_SOURCE_POPUP; + nsresult result=NS_OK; + mSyntaxHighlight = PR_FALSE; + // This determines the value of the boolean syntax_highlight preference. + NS_WITH_SERVICE(nsIPref, thePrefsService, kPrefCID, &result); + if (NS_SUCCEEDED(result) && thePrefsService) + thePrefsService->GetBoolPref("view_source.syntax_highlight", &mSyntaxHighlight); #else mStartTag.AssignWithConversion("start"); mEndTag.AssignWithConversion("end"); @@ -433,7 +434,7 @@ nsresult CViewSourceHTML::WillBuildModel( const CParserContext& aParserContext, if((!aParserContext.mPrevContext) && (mSink)) { mTags.Truncate(); - mErrors.AssignWithConversion(" HTML 4.0 Strict-DTD validation (enabled); [Should use Transitional?].\n"); + mErrors.Assign(NS_LITERAL_STRING(" HTML 4.0 Strict-DTD validation (enabled); [Should use Transitional?].\n")); mValidator=aParserContext.mValidator; mDocType=aParserContext.mDocType; @@ -483,12 +484,12 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke // token allocator, because there are no attributes on the tokens. nsAutoString tag; - tag.AssignWithConversion("HTML"); + tag.Assign(NS_LITERAL_STRING("HTML")); CStartToken htmlToken(tag, eHTMLTag_html); nsCParserNode htmlNode(&htmlToken,0,0/*stack token*/); mSink->OpenHTML(htmlNode); - tag.AssignWithConversion("BODY"); + tag.Assign(NS_LITERAL_STRING("BODY")); CStartToken bodyToken(tag, eHTMLTag_body); nsCParserNode bodyNode(&bodyToken,0,0/*stack token*/); mSink->OpenBody(bodyNode); @@ -501,7 +502,7 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); if(theAllocator) { #ifdef VIEW_SOURCE_HTML - tag.AssignWithConversion("PRE"); + tag.Assign(NS_LITERAL_STRING("PRE")); CStartToken* theToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_pre,tag)); #else //now let's automatically open the root container... @@ -514,8 +515,8 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke nsCParserNode theNode(theToken,0,theAllocator); #ifdef VIEW_SOURCE_HTML - theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreStyle)); - theAttr->SetKey(NS_LITERAL_STRING("style")); + theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreClass)); + theAttr->SetKey(NS_LITERAL_STRING("class")); #else theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_LITERAL_STRING("http://www.mozilla.org/viewsource")); theAttr->SetKey(NS_LITERAL_STRING("xmlns")); @@ -876,13 +877,6 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri nsresult result=NS_OK; CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); -#ifdef VIEW_SOURCE_COLORING - // This determines the value of the boolean syntax_highlight preference. - PRBool syntaxHighlight = PR_FALSE; - NS_WITH_SERVICE(nsIPref, thePrefsService, kPrefCID, &result); - if (NS_SUCCEEDED(result) && thePrefsService) - thePrefsService->GetBoolPref("view_source.syntax_highlight", &syntaxHighlight); -#endif // VIEW_SOURCE_COLORING nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); NS_ASSERTION(0!=theAllocator,"Error: no allocator"); @@ -898,31 +892,25 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri mSink->AddLeaf(theNode); } -#ifdef VIEW_SOURCE_COLORING - nsAutoString tag (NS_LITERAL_STRING("SPAN")); - CStartToken* theTagToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_span,tag)); -#endif // VIEW_SOURCE_COLORING + CStartToken* theTagToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_span,NS_LITERAL_STRING("SPAN"))); #else CStartToken* theTagToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_unknown,theXMLTagName)); #endif // VIEW_SOURCE_HTML -#ifdef VIEW_SOURCE_COLORING - if (syntaxHighlight) + if (mSyntaxHighlight) { - theContext.mStartNode.Init(theTagToken,mLineNumber,theAllocator); + theContext.mStartNode.Init(theTagToken,mLineNumber,theAllocator); #ifdef VIEW_SOURCE_HTML - CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kElementStyles[aTagType])); - theAttr->SetKey(NS_LITERAL_STRING("style")); + CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kElementClasses[aTagType])); + theAttr->SetKey(NS_LITERAL_STRING("class")); theContext.mStartNode.AddAttribute(theAttr); - } #endif // VIEW_SOURCE_HTML + } STOP_TIMER(); mSink->OpenContainer(theContext.mStartNode); //emit ... -#endif // VIEW_SOURCE_COLORING - #ifdef rickgdebug if(aNewlineRequired) { @@ -946,15 +934,13 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri } #ifdef VIEW_SOURCE_HTML -#ifdef VIEW_SOURCE_COLORING - if (syntaxHighlight) + if (mSyntaxHighlight) { theContext.mStartNode.ReleaseAll(); CEndToken theEndToken(eHTMLTag_span); theContext.mEndNode.Init(&theEndToken,mLineNumber,0/*stack token*/); mSink->CloseContainer(theContext.mEndNode); //emit ... } -#endif // VIEW_SOURCE_COLORING if (kAfterText[aTagType][0] != 0) { nsAutoString afterText; afterText.AssignWithConversion(kAfterText[aTagType]); diff --git a/htmlparser/src/nsViewSourceHTML.h b/htmlparser/src/nsViewSourceHTML.h index 5ee4b48c8843..e8911c1b0e54 100644 --- a/htmlparser/src/nsViewSourceHTML.h +++ b/htmlparser/src/nsViewSourceHTML.h @@ -274,6 +274,7 @@ protected: PRInt32 mValue; PRInt32 mPopupTag; PRInt32 mSummaryTag; + PRBool mSyntaxHighlight; #else nsAutoString mStartTag; nsAutoString mEndTag; diff --git a/layout/build/nsLayoutDLF.cpp b/layout/build/nsLayoutDLF.cpp index 152dcc563a5d..11918e8ed6f8 100644 --- a/layout/build/nsLayoutDLF.cpp +++ b/layout/build/nsLayoutDLF.cpp @@ -48,6 +48,8 @@ static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID); // URL for the "user agent" style sheet #define UA_CSS_URL "resource:/res/ua.css" +// URL for the "view source" style sheet +#define VIEW_SOURCE_CSS_URL "resource:/res/viewsource.css" // Factory code for creating variations on html documents @@ -198,14 +200,28 @@ nsLayoutDLF::CreateInstance(const char *aCommand, nsresult rv = NS_OK; if (!GetUAStyleSheet()) { // Load the UA style sheet - nsCOMPtr uaURL; - rv = NS_NewURI(getter_AddRefs(uaURL), UA_CSS_URL); + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), UA_CSS_URL); if (NS_SUCCEEDED(rv)) { nsCOMPtr cssLoader(do_CreateInstance(kCSSLoaderCID,&rv)); if (cssLoader) { PRBool complete; - rv = cssLoader->LoadAgentSheet(uaURL, nsLayoutModule::gUAStyleSheet, complete, - nsnull); + rv = cssLoader->LoadAgentSheet(uri, nsLayoutModule::gUAStyleSheet, + complete, nsnull); + if (NS_SUCCEEDED(rv)) { + // also cache the view source stylesheet + if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), VIEW_SOURCE_CSS_URL))) { + PRBool bHasSheet = PR_FALSE; + nsLayoutModule::gUAStyleSheet-> + ContainsStyleSheet(uri, + bHasSheet, + &nsLayoutModule::gViewSourceStyleSheet); + // assert if we found a stylesheet but it's nsnull -- should not happen + NS_ASSERTION(!bHasSheet || nsLayoutModule::gViewSourceStyleSheet, + "gViewSourceStyleSheet must be set: ContainsStyleSheet is hosed"); + + } + } } } if (NS_FAILED(rv)) { @@ -261,6 +277,20 @@ nsLayoutDLF::CreateInstance(const char *aCommand, else aContentType=gXMLTypes[0]; #endif + + if (nsLayoutModule::gViewSourceStyleSheet) { +#ifdef DEBUG + printf( "Enabling View Source StyleSheet\n"); +#endif + nsLayoutModule::gViewSourceStyleSheet->SetEnabled(PR_TRUE); + } + } else { + if (nsLayoutModule::gViewSourceStyleSheet) { +#ifdef DEBUG + printf( "Disabling View Source StyleSheet\n"); +#endif + nsLayoutModule::gViewSourceStyleSheet->SetEnabled(PR_FALSE); + } } // Try html diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 8f5a3143cbb5..876cce33bf96 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -174,6 +174,7 @@ LayoutScriptNameSet::AddNameSet(nsIScriptContext* aScriptContext) nsIScriptNameSetRegistry* nsLayoutModule::gRegistry; nsICSSStyleSheet* nsLayoutModule::gUAStyleSheet = nsnull; +nsIStyleSheet* nsLayoutModule::gViewSourceStyleSheet = nsnull; nsLayoutModule::nsLayoutModule() : mInitialized(PR_FALSE) @@ -279,6 +280,7 @@ nsLayoutModule::Shutdown() NS_IF_RELEASE(gRegistry); NS_IF_RELEASE(gUAStyleSheet); + NS_IF_RELEASE(gViewSourceStyleSheet); } NS_IMETHODIMP diff --git a/layout/build/nsLayoutModule.h b/layout/build/nsLayoutModule.h index d73d38e70719..6a6d6829730a 100644 --- a/layout/build/nsLayoutModule.h +++ b/layout/build/nsLayoutModule.h @@ -25,6 +25,7 @@ #include "nslayout.h" #include "nsIModule.h" +class nsIStyleSheet; class nsICSSStyleSheet; class nsIScriptNameSetRegistry; @@ -58,6 +59,7 @@ protected: public: static nsICSSStyleSheet* gUAStyleSheet; + static nsIStyleSheet* gViewSourceStyleSheet; }; //---------------------------------------------------------------------- diff --git a/layout/html/document/src/Makefile.in b/layout/html/document/src/Makefile.in index d53f90735ee8..efc705841ef7 100644 --- a/layout/html/document/src/Makefile.in +++ b/layout/html/document/src/Makefile.in @@ -49,10 +49,10 @@ INCLUDES += \ -I$(srcdir)/../../content/src \ $(NULL) -GARBAGE += $(DIST)/bin/res/ua.css $(DIST)/bin/res/html.css $(DIST)/bin/res/forms.css $(DIST)/bin/res/quirk.css $(DIST)/bin/res/arrow.gif +GARBAGE += $(DIST)/bin/res/ua.css $(DIST)/bin/res/html.css $(DIST)/bin/res/forms.css $(DIST)/bin/res/quirk.css $(DIST)/bin/res/viewsource.css $(DIST)/bin/res/arrow.gif install:: $(TARGETS) - $(INSTALL) $(srcdir)/html.css $(srcdir)/forms.css $(srcdir)/quirk.css $(srcdir)/arrow.gif $(DIST)/bin/res + $(INSTALL) $(srcdir)/html.css $(srcdir)/forms.css $(srcdir)/quirk.css $(srcdir)/viewsource.css $(srcdir)/arrow.gif $(DIST)/bin/res rm -f $(DIST)/bin/res/ua.css cp $(srcdir)/ua.css $(DIST)/bin/res diff --git a/layout/html/document/src/makefile.win b/layout/html/document/src/makefile.win index e4d5d021b101..731a3f52e21b 100644 --- a/layout/html/document/src/makefile.win +++ b/layout/html/document/src/makefile.win @@ -62,6 +62,7 @@ install:: $(LIBRARY) $(MAKE_INSTALL) html.css $(DIST)\bin\res $(MAKE_INSTALL) forms.css $(DIST)\bin\res $(MAKE_INSTALL) quirk.css $(DIST)\bin\res + $(MAKE_INSTALL) viewsource.css $(DIST)\bin\res $(MAKE_INSTALL) arrow.gif $(DIST)\bin\res $(MAKE_INSTALL) arrowd.gif $(DIST)\bin\res @@ -71,5 +72,6 @@ clobber:: rm -f $(DIST)\bin\res\html.css rm -f $(DIST)\bin\res\forms.css rm -f $(DIST)\bin\res\quirk.css + rm -f $(DIST)\bin\res\viewsource.css rm -f $(DIST)\bin\res\arrow.gif rm -f $(DIST)\bin\res\arrowd.gif diff --git a/layout/html/document/src/ua.css b/layout/html/document/src/ua.css index 3b0c7cb555ec..e2aa9de47a92 100644 --- a/layout/html/document/src/ua.css +++ b/layout/html/document/src/ua.css @@ -22,6 +22,7 @@ @import url(resource:/res/html.css); @import url(chrome://global/content/xul.css); @import url(resource:/res/quirk.css); +@import url(resource:/res/viewsource.css); parsererror { display: block; diff --git a/layout/html/document/src/viewsource.css b/layout/html/document/src/viewsource.css index 034ef6399781..f5f0b58ba8a1 100644 --- a/layout/html/document/src/viewsource.css +++ b/layout/html/document/src/viewsource.css @@ -20,108 +20,67 @@ * Blake Ross */ -@namespace url(http://www.mozilla.org/viewsource); +@namespace url(http://www.w3.org/1999/xhtml); /* set default namespace to HTML */ -viewsource { - font-family: monospace; - font-weight: normal; - color: black; +.viewsource { + font-family: monospace; + font-weight: normal; + color: black; white-space: pre; - font-size: 12px; + font-size: 12px; padding-top: 8px; margin-left: 8px; -} - -summary { - display: block; - background-color: #FFFFCC; - width: 90%; - border: solid; - border-width: 1px; - font-family: sans-serif; -} - -key { - font-weight:bold; } - -key:before { - color: black; -} - -val { - color: blue; - font-weight:normal; -} - -val:before { - content: "="; - color: black; -} - -entity { - color:#FF4500; - font-weight:normal; -} - -entity:before { - content: "&"; -} - -comment { - color: green; - font-style:italic; -} - -cdata { - color: #CC0066; -} - -doctype { - color: steelblue; - font-style: italic; -} - -pi { - color: orchid; - font-style: italic; +.start-tag { + color: purple; + font-weight: bold; } - -start { - color: purple; - font-weight:bold; -} - -start:before { - content: "<"; - color: black; -} - -start:after { - content: ">"; - color: black; -} - -end { - color: purple; - font-weight:bold; -} - -end:before { - content: ""; - color: black; +.end-tag { + color: purple; + font-weight: bold; } - -txt { - font-weight: normal; +.comment { + color: green; + font-style: italic; +} +.cdata { + color: #CC0066; +} +.doctype { + color: steelblue; + font-style: italic; +} +.pi { + color: orchid; + font-style: italic; +} +.entity { + color:#FF4500; + font-weight: normal; +} +.text { + font-weight: normal; +} +.attribute-name { + color: black; + font-weight: bold; +} +.attribute-value { + color: blue; + font-weight: normal; +} +.summary { + display: block; + background-color: #FFFFCC; + width: 90%; + border: solid; + border-width: 1pt; + font-family: sans-serif; +} +.popup { + font-weight: normal; +} +.markupdeclaration { + color: steelblue; + font-style: italic; } - -error { - background-color: #FFFFCC; - font-weight: bold; -} diff --git a/layout/style/ua.css b/layout/style/ua.css index 3b0c7cb555ec..e2aa9de47a92 100644 --- a/layout/style/ua.css +++ b/layout/style/ua.css @@ -22,6 +22,7 @@ @import url(resource:/res/html.css); @import url(chrome://global/content/xul.css); @import url(resource:/res/quirk.css); +@import url(resource:/res/viewsource.css); parsererror { display: block; diff --git a/layout/style/viewsource.css b/layout/style/viewsource.css index 034ef6399781..f5f0b58ba8a1 100644 --- a/layout/style/viewsource.css +++ b/layout/style/viewsource.css @@ -20,108 +20,67 @@ * Blake Ross */ -@namespace url(http://www.mozilla.org/viewsource); +@namespace url(http://www.w3.org/1999/xhtml); /* set default namespace to HTML */ -viewsource { - font-family: monospace; - font-weight: normal; - color: black; +.viewsource { + font-family: monospace; + font-weight: normal; + color: black; white-space: pre; - font-size: 12px; + font-size: 12px; padding-top: 8px; margin-left: 8px; -} - -summary { - display: block; - background-color: #FFFFCC; - width: 90%; - border: solid; - border-width: 1px; - font-family: sans-serif; -} - -key { - font-weight:bold; } - -key:before { - color: black; -} - -val { - color: blue; - font-weight:normal; -} - -val:before { - content: "="; - color: black; -} - -entity { - color:#FF4500; - font-weight:normal; -} - -entity:before { - content: "&"; -} - -comment { - color: green; - font-style:italic; -} - -cdata { - color: #CC0066; -} - -doctype { - color: steelblue; - font-style: italic; -} - -pi { - color: orchid; - font-style: italic; +.start-tag { + color: purple; + font-weight: bold; } - -start { - color: purple; - font-weight:bold; -} - -start:before { - content: "<"; - color: black; -} - -start:after { - content: ">"; - color: black; -} - -end { - color: purple; - font-weight:bold; -} - -end:before { - content: ""; - color: black; +.end-tag { + color: purple; + font-weight: bold; } - -txt { - font-weight: normal; +.comment { + color: green; + font-style: italic; +} +.cdata { + color: #CC0066; +} +.doctype { + color: steelblue; + font-style: italic; +} +.pi { + color: orchid; + font-style: italic; +} +.entity { + color:#FF4500; + font-weight: normal; +} +.text { + font-weight: normal; +} +.attribute-name { + color: black; + font-weight: bold; +} +.attribute-value { + color: blue; + font-weight: normal; +} +.summary { + display: block; + background-color: #FFFFCC; + width: 90%; + border: solid; + border-width: 1pt; + font-family: sans-serif; +} +.popup { + font-weight: normal; +} +.markupdeclaration { + color: steelblue; + font-style: italic; } - -error { - background-color: #FFFFCC; - font-weight: bold; -} diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp index c1db06a844e9..cb1c003949d6 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -48,7 +48,6 @@ #endif #define VIEW_SOURCE_HTML -#define VIEW_SOURCE_COLORING #include "nsIDTDDebug.h" #include "nsViewSourceHTML.h" @@ -65,13 +64,11 @@ #include "nsHTMLEntities.h" #endif // VIEW_SOURCE_HTML -#ifdef VIEW_SOURCE_COLORING // For Coloring pref only // If we aren't going to define it, then should save on bloat. #include "nsIPref.h" #include "nsIServiceManager.h" static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); -#endif // VIEW_SOURCE_COLORING #include "COtherDTD.h" #include "nsElementTable.h" @@ -100,7 +97,7 @@ static int gErrorThreshold = 10; #endif #ifdef VIEW_SOURCE_HTML -static const char* kPreStyle = "font-family: -moz-fixed; font-weight:normal; color:black; padding-top:4px; margin-left:4px;"; +static const char* kPreClass = "viewsource"; #endif // VIEW_SOURCE_HTML /** @@ -229,23 +226,21 @@ enum { VIEW_SOURCE_MARKUPDECLARATION = 12 }; -#ifdef VIEW_SOURCE_COLORING -static char* kElementStyles[] = { - "color: purple; font-weight:bold;", - "color: purple; font-weight:bold;", - "color: green; font-style:italic;", - "color: #CC0066;", - "color:steelblue; font-style:italic;", - "color:orchid; font-style:italic;", - "color:#FF4500; font-weight:normal;", - "font-weight: normal;", - "color: black; font-weight:bold;", - "color: blue; font-weight:normal;", - "display:block; background-color:#FFFFCC; width:90%; border:solid; border-width:1pt; font-family: Sans-serif;", - "font-weight: normal;", - "color:steelblue; font-style:italic;" +static char* kElementClasses[] = { + "start-tag", + "end-tag", + "comment", + "cdata", + "doctype", + "pi", + "entity", + "text", + "attribute-name", + "attribute-value", + "summary", + "popup", + "markupdeclaration" }; -#endif static char* kBeforeText[] = { "<", @@ -305,6 +300,12 @@ CViewSourceHTML::CViewSourceHTML() : mTags(), mErrors() { mValue = VIEW_SOURCE_ATTRIBUTE_VALUE; mSummaryTag = VIEW_SOURCE_SUMMARY; mPopupTag = VIEW_SOURCE_POPUP; + nsresult result=NS_OK; + mSyntaxHighlight = PR_FALSE; + // This determines the value of the boolean syntax_highlight preference. + NS_WITH_SERVICE(nsIPref, thePrefsService, kPrefCID, &result); + if (NS_SUCCEEDED(result) && thePrefsService) + thePrefsService->GetBoolPref("view_source.syntax_highlight", &mSyntaxHighlight); #else mStartTag.AssignWithConversion("start"); mEndTag.AssignWithConversion("end"); @@ -433,7 +434,7 @@ nsresult CViewSourceHTML::WillBuildModel( const CParserContext& aParserContext, if((!aParserContext.mPrevContext) && (mSink)) { mTags.Truncate(); - mErrors.AssignWithConversion(" HTML 4.0 Strict-DTD validation (enabled); [Should use Transitional?].\n"); + mErrors.Assign(NS_LITERAL_STRING(" HTML 4.0 Strict-DTD validation (enabled); [Should use Transitional?].\n")); mValidator=aParserContext.mValidator; mDocType=aParserContext.mDocType; @@ -483,12 +484,12 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke // token allocator, because there are no attributes on the tokens. nsAutoString tag; - tag.AssignWithConversion("HTML"); + tag.Assign(NS_LITERAL_STRING("HTML")); CStartToken htmlToken(tag, eHTMLTag_html); nsCParserNode htmlNode(&htmlToken,0,0/*stack token*/); mSink->OpenHTML(htmlNode); - tag.AssignWithConversion("BODY"); + tag.Assign(NS_LITERAL_STRING("BODY")); CStartToken bodyToken(tag, eHTMLTag_body); nsCParserNode bodyNode(&bodyToken,0,0/*stack token*/); mSink->OpenBody(bodyNode); @@ -501,7 +502,7 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); if(theAllocator) { #ifdef VIEW_SOURCE_HTML - tag.AssignWithConversion("PRE"); + tag.Assign(NS_LITERAL_STRING("PRE")); CStartToken* theToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_pre,tag)); #else //now let's automatically open the root container... @@ -514,8 +515,8 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke nsCParserNode theNode(theToken,0,theAllocator); #ifdef VIEW_SOURCE_HTML - theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreStyle)); - theAttr->SetKey(NS_LITERAL_STRING("style")); + theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreClass)); + theAttr->SetKey(NS_LITERAL_STRING("class")); #else theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_LITERAL_STRING("http://www.mozilla.org/viewsource")); theAttr->SetKey(NS_LITERAL_STRING("xmlns")); @@ -876,13 +877,6 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri nsresult result=NS_OK; CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); -#ifdef VIEW_SOURCE_COLORING - // This determines the value of the boolean syntax_highlight preference. - PRBool syntaxHighlight = PR_FALSE; - NS_WITH_SERVICE(nsIPref, thePrefsService, kPrefCID, &result); - if (NS_SUCCEEDED(result) && thePrefsService) - thePrefsService->GetBoolPref("view_source.syntax_highlight", &syntaxHighlight); -#endif // VIEW_SOURCE_COLORING nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); NS_ASSERTION(0!=theAllocator,"Error: no allocator"); @@ -898,31 +892,25 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri mSink->AddLeaf(theNode); } -#ifdef VIEW_SOURCE_COLORING - nsAutoString tag (NS_LITERAL_STRING("SPAN")); - CStartToken* theTagToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_span,tag)); -#endif // VIEW_SOURCE_COLORING + CStartToken* theTagToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_span,NS_LITERAL_STRING("SPAN"))); #else CStartToken* theTagToken=NS_STATIC_CAST(CStartToken*,theAllocator->CreateTokenOfType(eToken_start,eHTMLTag_unknown,theXMLTagName)); #endif // VIEW_SOURCE_HTML -#ifdef VIEW_SOURCE_COLORING - if (syntaxHighlight) + if (mSyntaxHighlight) { - theContext.mStartNode.Init(theTagToken,mLineNumber,theAllocator); + theContext.mStartNode.Init(theTagToken,mLineNumber,theAllocator); #ifdef VIEW_SOURCE_HTML - CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kElementStyles[aTagType])); - theAttr->SetKey(NS_LITERAL_STRING("style")); + CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kElementClasses[aTagType])); + theAttr->SetKey(NS_LITERAL_STRING("class")); theContext.mStartNode.AddAttribute(theAttr); - } #endif // VIEW_SOURCE_HTML + } STOP_TIMER(); mSink->OpenContainer(theContext.mStartNode); //emit ... -#endif // VIEW_SOURCE_COLORING - #ifdef rickgdebug if(aNewlineRequired) { @@ -946,15 +934,13 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri } #ifdef VIEW_SOURCE_HTML -#ifdef VIEW_SOURCE_COLORING - if (syntaxHighlight) + if (mSyntaxHighlight) { theContext.mStartNode.ReleaseAll(); CEndToken theEndToken(eHTMLTag_span); theContext.mEndNode.Init(&theEndToken,mLineNumber,0/*stack token*/); mSink->CloseContainer(theContext.mEndNode); //emit ... } -#endif // VIEW_SOURCE_COLORING if (kAfterText[aTagType][0] != 0) { nsAutoString afterText; afterText.AssignWithConversion(kAfterText[aTagType]); diff --git a/parser/htmlparser/src/nsViewSourceHTML.h b/parser/htmlparser/src/nsViewSourceHTML.h index 5ee4b48c8843..e8911c1b0e54 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.h +++ b/parser/htmlparser/src/nsViewSourceHTML.h @@ -274,6 +274,7 @@ protected: PRInt32 mValue; PRInt32 mPopupTag; PRInt32 mSummaryTag; + PRBool mSyntaxHighlight; #else nsAutoString mStartTag; nsAutoString mEndTag; diff --git a/xpinstall/packager/packages-mac b/xpinstall/packager/packages-mac index c178161ef692..8ca10a453c19 100644 --- a/xpinstall/packager/packages-mac +++ b/xpinstall/packager/packages-mac @@ -235,6 +235,7 @@ viewer:defaults:wallet:StateSchema.tbl viewer:res:html:* viewer:res:html.css viewer:res:quirk.css +viewer:res:viewsource.css viewer:res:maccharset.properties viewer:res:rdf:article.gif viewer:res:rdf:collapser.gif diff --git a/xpinstall/packager/packages-unix b/xpinstall/packager/packages-unix index 12c53c74c564..6f622b803b38 100644 --- a/xpinstall/packager/packages-unix +++ b/xpinstall/packager/packages-unix @@ -255,6 +255,7 @@ bin/res/langGroups.properties bin/res/language.properties bin/res/html.css bin/res/quirk.css +bin/res/viewsource.css bin/res/html/* bin/res/rdf/article.gif bin/res/rdf/document.gif diff --git a/xpinstall/packager/packages-win b/xpinstall/packager/packages-win index f7bee7f8ea64..d1f2b389e7bb 100644 --- a/xpinstall/packager/packages-win +++ b/xpinstall/packager/packages-win @@ -248,6 +248,7 @@ bin\res\html.css bin\res\ua.css bin\res\forms.css bin\res\quirk.css +bin\res\viewsource.css bin\res\arrow.gif bin\res\html\* bin\defaults\wallet\VcardSchema.tbl