diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index 4c0af836ac1..90d45d68352 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 3e78681a907..6acae66a66c 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 ccb26bcc5e7..05297402bf4 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 ccb26bcc5e7..05297402bf4 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 4c0af836ac1..90d45d68352 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 3e78681a907..6acae66a66c 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...