Back-end to allow viewsource to toggle wrapping of long lines. b=22022 r=bzbarsky sr=jst

This commit is contained in:
rbs%maths.uq.edu.au 2001-09-05 01:02:58 +00:00
parent ded8f34015
commit 675465a9c2
6 changed files with 46 additions and 14 deletions

View File

@ -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<nsIPref> 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;
}

View File

@ -255,6 +255,7 @@ protected:
PRInt32 mPopupTag;
PRInt32 mSummaryTag;
PRBool mSyntaxHighlight;
PRBool mWrapLongLines;
nsDTDMode mDTDMode;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...

View File

@ -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;

View File

@ -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;

View File

@ -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<nsIPref> 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;
}

View File

@ -255,6 +255,7 @@ protected:
PRInt32 mPopupTag;
PRInt32 mSummaryTag;
PRBool mSyntaxHighlight;
PRBool mWrapLongLines;
nsDTDMode mDTDMode;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...