From 675465a9c2fc4506220f615a3f8c1575044c70a4 Mon Sep 17 00:00:00 2001 From: "rbs%maths.uq.edu.au" Date: Wed, 5 Sep 2001 01:02:58 +0000 Subject: [PATCH] Back-end to allow viewsource to toggle wrapping of long lines. b=22022 r=bzbarsky sr=jst --- htmlparser/src/nsViewSourceHTML.cpp | 24 ++++++++++++++++------ htmlparser/src/nsViewSourceHTML.h | 1 + layout/html/document/src/viewsource.css | 5 ++++- layout/style/viewsource.css | 5 ++++- parser/htmlparser/src/nsViewSourceHTML.cpp | 24 ++++++++++++++++------ parser/htmlparser/src/nsViewSourceHTML.h | 1 + 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index 4c0af836ac11..90d45d683525 100644 --- a/htmlparser/src/nsViewSourceHTML.cpp +++ b/htmlparser/src/nsViewSourceHTML.cpp @@ -89,7 +89,11 @@ static int gErrorThreshold = 10; // static const char* gDumpFileName = "\\temp\\viewsource.html"; #endif // DUMP_TO_FILE -static const char* kPreClass = "viewsource"; +// bug 22022 - these are used to toggle 'Wrap Long Lines' on the viewsource +// window by selectively setting/unsetting the following class defined in +// viewsource.css; the setting is remembered between invocations using a pref. +static const char* kPreId = "viewsource"; +static const char* kPreClassWrap = "wrap"; /** * This method gets called as part of our COM-like interfaces. @@ -323,10 +327,12 @@ CViewSourceHTML::CViewSourceHTML() : mFilename(), mTags(), mErrors() { mPopupTag = VIEW_SOURCE_POPUP; nsresult result=NS_OK; mSyntaxHighlight = PR_FALSE; - // This determines the value of the boolean syntax_highlight preference. + mWrapLongLines = PR_FALSE; nsCOMPtr thePrefsService(do_GetService(NS_PREF_CONTRACTID)); - if (thePrefsService) + if (thePrefsService) { thePrefsService->GetBoolPref("view_source.syntax_highlight", &mSyntaxHighlight); + thePrefsService->GetBoolPref("view_source.wrap_long_lines", &mWrapLongLines); + } mParser=0; mSink=0; @@ -569,10 +575,16 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke nsCParserNode theNode(theToken,0,theAllocator); - theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreClass)); - theAttr->SetKey(NS_LITERAL_STRING("class")); + theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreId)); + theAttr->SetKey(NS_LITERAL_STRING("id")); theNode.AddAttribute(theAttr); - + + if (mWrapLongLines) { + theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreClassWrap)); + theAttr->SetKey(NS_LITERAL_STRING("class")); + theNode.AddAttribute(theAttr); + } + result=mSink->OpenContainer(theNode); if(NS_SUCCEEDED(result)) mHasOpenBody=PR_TRUE; } diff --git a/htmlparser/src/nsViewSourceHTML.h b/htmlparser/src/nsViewSourceHTML.h index 3e78681a9079..6acae66a66c9 100644 --- a/htmlparser/src/nsViewSourceHTML.h +++ b/htmlparser/src/nsViewSourceHTML.h @@ -255,6 +255,7 @@ protected: PRInt32 mPopupTag; PRInt32 mSummaryTag; PRBool mSyntaxHighlight; + PRBool mWrapLongLines; nsDTDMode mDTDMode; eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors... diff --git a/layout/html/document/src/viewsource.css b/layout/html/document/src/viewsource.css index ccb26bcc5e7d..05297402bf4e 100644 --- a/layout/html/document/src/viewsource.css +++ b/layout/html/document/src/viewsource.css @@ -25,13 +25,16 @@ html { background-color: white; } -.viewsource { +#viewsource { font-family: -moz-fixed; font-weight: normal; font-size: normal; color: black; white-space: pre; } +#viewsource.wrap { + white-space: -moz-pre-wrap; +} .start-tag { color: purple; font-weight: bold; diff --git a/layout/style/viewsource.css b/layout/style/viewsource.css index ccb26bcc5e7d..05297402bf4e 100644 --- a/layout/style/viewsource.css +++ b/layout/style/viewsource.css @@ -25,13 +25,16 @@ html { background-color: white; } -.viewsource { +#viewsource { font-family: -moz-fixed; font-weight: normal; font-size: normal; color: black; white-space: pre; } +#viewsource.wrap { + white-space: -moz-pre-wrap; +} .start-tag { color: purple; font-weight: bold; diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp index 4c0af836ac11..90d45d683525 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -89,7 +89,11 @@ static int gErrorThreshold = 10; // static const char* gDumpFileName = "\\temp\\viewsource.html"; #endif // DUMP_TO_FILE -static const char* kPreClass = "viewsource"; +// bug 22022 - these are used to toggle 'Wrap Long Lines' on the viewsource +// window by selectively setting/unsetting the following class defined in +// viewsource.css; the setting is remembered between invocations using a pref. +static const char* kPreId = "viewsource"; +static const char* kPreClassWrap = "wrap"; /** * This method gets called as part of our COM-like interfaces. @@ -323,10 +327,12 @@ CViewSourceHTML::CViewSourceHTML() : mFilename(), mTags(), mErrors() { mPopupTag = VIEW_SOURCE_POPUP; nsresult result=NS_OK; mSyntaxHighlight = PR_FALSE; - // This determines the value of the boolean syntax_highlight preference. + mWrapLongLines = PR_FALSE; nsCOMPtr thePrefsService(do_GetService(NS_PREF_CONTRACTID)); - if (thePrefsService) + if (thePrefsService) { thePrefsService->GetBoolPref("view_source.syntax_highlight", &mSyntaxHighlight); + thePrefsService->GetBoolPref("view_source.wrap_long_lines", &mWrapLongLines); + } mParser=0; mSink=0; @@ -569,10 +575,16 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke nsCParserNode theNode(theToken,0,theAllocator); - theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreClass)); - theAttr->SetKey(NS_LITERAL_STRING("class")); + theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreId)); + theAttr->SetKey(NS_LITERAL_STRING("id")); theNode.AddAttribute(theAttr); - + + if (mWrapLongLines) { + theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreClassWrap)); + theAttr->SetKey(NS_LITERAL_STRING("class")); + theNode.AddAttribute(theAttr); + } + result=mSink->OpenContainer(theNode); if(NS_SUCCEEDED(result)) mHasOpenBody=PR_TRUE; } diff --git a/parser/htmlparser/src/nsViewSourceHTML.h b/parser/htmlparser/src/nsViewSourceHTML.h index 3e78681a9079..6acae66a66c9 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.h +++ b/parser/htmlparser/src/nsViewSourceHTML.h @@ -255,6 +255,7 @@ protected: PRInt32 mPopupTag; PRInt32 mSummaryTag; PRBool mSyntaxHighlight; + PRBool mWrapLongLines; nsDTDMode mDTDMode; eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...