52154: make view source highlighting prefable. Contribution from jce2@po.cwru.edu, r=me, a=brendan

This commit is contained in:
akkana%netscape.com 2000-09-14 18:51:05 +00:00
Родитель c097ee7045
Коммит f9e95edf2e
2 изменённых файлов: 94 добавлений и 38 удалений

Просмотреть файл

@ -18,6 +18,11 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* jce2@po.cwru.edu <Jason Eager>: Added pref to turn on/off
* syntax hilighting in view source
* window.
*
*
*/ */
/** /**
@ -43,7 +48,7 @@
#endif #endif
#define VIEW_SOURCE_HTML #define VIEW_SOURCE_HTML
//#define VIEW_SOURCE_COLORING #define VIEW_SOURCE_COLORING
#include "nsIDTDDebug.h" #include "nsIDTDDebug.h"
#include "nsViewSourceHTML.h" #include "nsViewSourceHTML.h"
@ -59,6 +64,15 @@
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
#include "nsHTMLEntities.h" #include "nsHTMLEntities.h"
#endif // VIEW_SOURCE_HTML #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 "COtherDTD.h"
#include "prenv.h" //this is here for debug reasons... #include "prenv.h" //this is here for debug reasons...
@ -982,6 +996,13 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
nsresult result=NS_OK; nsresult result=NS_OK;
CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); CSharedVSContext& theContext=CSharedVSContext::GetSharedContext();
#ifdef VIEW_SOURCE_COLORING
// This determines the value of the boolean syntax_highlight preference.
PRBool syntaxHilight = PR_FALSE;
NS_WITH_SERVICE(nsIPref, thePrefsService, kPrefCID, &result);
if (NS_SUCCEEDED(result) && thePrefsService)
thePrefsService->GetBoolPref("browser.view_source.syntax_highlight", &syntaxHilight);
#endif // VIEW_SOURCE_COLORING
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
if (kBeforeText[aTagType][0] != 0) { if (kBeforeText[aTagType][0] != 0) {
@ -992,31 +1013,35 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
} }
#ifdef VIEW_SOURCE_COLORING #ifdef VIEW_SOURCE_COLORING
nsAutoString tag; nsAutoString tag (NS_LITERAL_STRING("SPAN"));
tag.AssignWithConversion("SPAN");
CStartToken theTagToken(eHTMLTag_span); CStartToken theTagToken(eHTMLTag_span);
theTagToken.SetStringValue(tag); if (syntaxHilight)
{
theTagToken.SetStringValue(tag);
}
#endif // VIEW_SOURCE_COLORING #endif // VIEW_SOURCE_COLORING
#else #else // VIEW_SOURCE_HTML *UNDEFINED*
CToken theTagToken(theXMLTagName); CToken theTagToken(theXMLTagName);
#endif // VIEW_SOURCE_HTML #endif // VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING #ifdef VIEW_SOURCE_COLORING
theContext.mStartNode.Init(&theTagToken,mLineNumber); if (syntaxHilight)
{
theContext.mStartNode.Init(&theTagToken,mLineNumber);
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
if(theAllocator) { if(theAllocator) {
CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertToString(kElementStyles[aTagType])); CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertToString(kElementStyles[aTagType]));
nsString& theKey=theAttr->GetKey(); nsString& theKey=theAttr->GetKey();
theKey=NS_ConvertToString("style"); theKey=NS_ConvertToString("style");
theContext.mStartNode.AddAttribute(theAttr); theContext.mStartNode.AddAttribute(theAttr);
} }
#endif // VIEW_SOURCE_HTML #endif // VIEW_SOURCE_HTML
STOP_TIMER(); STOP_TIMER();
mSink->OpenContainer(theContext.mStartNode); //emit <starttag>... mSink->OpenContainer(theContext.mStartNode); //emit <starttag>...
}
#endif // VIEW_SOURCE_COLORING #endif // VIEW_SOURCE_COLORING
#ifdef rickgdebug #ifdef rickgdebug
@ -1042,11 +1067,14 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING #ifdef VIEW_SOURCE_COLORING
theContext.mStartNode.ReleaseAll(); if (syntaxHilight)
CEndToken theEndToken(eHTMLTag_span); {
theEndToken.SetStringValue(tag); theContext.mStartNode.ReleaseAll();
theContext.mEndNode.Init(&theEndToken,mLineNumber); CEndToken theEndToken(eHTMLTag_span);
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>... theEndToken.SetStringValue(tag);
theContext.mEndNode.Init(&theEndToken,mLineNumber);
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>...
}
#endif // VIEW_SOURCE_COLORING #endif // VIEW_SOURCE_COLORING
if (kAfterText[aTagType][0] != 0) { if (kAfterText[aTagType][0] != 0) {
nsAutoString afterText; nsAutoString afterText;

Просмотреть файл

@ -18,6 +18,11 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* jce2@po.cwru.edu <Jason Eager>: Added pref to turn on/off
* syntax hilighting in view source
* window.
*
*
*/ */
/** /**
@ -43,7 +48,7 @@
#endif #endif
#define VIEW_SOURCE_HTML #define VIEW_SOURCE_HTML
//#define VIEW_SOURCE_COLORING #define VIEW_SOURCE_COLORING
#include "nsIDTDDebug.h" #include "nsIDTDDebug.h"
#include "nsViewSourceHTML.h" #include "nsViewSourceHTML.h"
@ -59,6 +64,15 @@
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
#include "nsHTMLEntities.h" #include "nsHTMLEntities.h"
#endif // VIEW_SOURCE_HTML #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 "COtherDTD.h"
#include "prenv.h" //this is here for debug reasons... #include "prenv.h" //this is here for debug reasons...
@ -982,6 +996,13 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
nsresult result=NS_OK; nsresult result=NS_OK;
CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); CSharedVSContext& theContext=CSharedVSContext::GetSharedContext();
#ifdef VIEW_SOURCE_COLORING
// This determines the value of the boolean syntax_highlight preference.
PRBool syntaxHilight = PR_FALSE;
NS_WITH_SERVICE(nsIPref, thePrefsService, kPrefCID, &result);
if (NS_SUCCEEDED(result) && thePrefsService)
thePrefsService->GetBoolPref("browser.view_source.syntax_highlight", &syntaxHilight);
#endif // VIEW_SOURCE_COLORING
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
if (kBeforeText[aTagType][0] != 0) { if (kBeforeText[aTagType][0] != 0) {
@ -992,31 +1013,35 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
} }
#ifdef VIEW_SOURCE_COLORING #ifdef VIEW_SOURCE_COLORING
nsAutoString tag; nsAutoString tag (NS_LITERAL_STRING("SPAN"));
tag.AssignWithConversion("SPAN");
CStartToken theTagToken(eHTMLTag_span); CStartToken theTagToken(eHTMLTag_span);
theTagToken.SetStringValue(tag); if (syntaxHilight)
{
theTagToken.SetStringValue(tag);
}
#endif // VIEW_SOURCE_COLORING #endif // VIEW_SOURCE_COLORING
#else #else // VIEW_SOURCE_HTML *UNDEFINED*
CToken theTagToken(theXMLTagName); CToken theTagToken(theXMLTagName);
#endif // VIEW_SOURCE_HTML #endif // VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING #ifdef VIEW_SOURCE_COLORING
theContext.mStartNode.Init(&theTagToken,mLineNumber); if (syntaxHilight)
{
theContext.mStartNode.Init(&theTagToken,mLineNumber);
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
if(theAllocator) { if(theAllocator) {
CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertToString(kElementStyles[aTagType])); CAttributeToken* theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertToString(kElementStyles[aTagType]));
nsString& theKey=theAttr->GetKey(); nsString& theKey=theAttr->GetKey();
theKey=NS_ConvertToString("style"); theKey=NS_ConvertToString("style");
theContext.mStartNode.AddAttribute(theAttr); theContext.mStartNode.AddAttribute(theAttr);
} }
#endif // VIEW_SOURCE_HTML #endif // VIEW_SOURCE_HTML
STOP_TIMER(); STOP_TIMER();
mSink->OpenContainer(theContext.mStartNode); //emit <starttag>... mSink->OpenContainer(theContext.mStartNode); //emit <starttag>...
}
#endif // VIEW_SOURCE_COLORING #endif // VIEW_SOURCE_COLORING
#ifdef rickgdebug #ifdef rickgdebug
@ -1042,11 +1067,14 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
#ifdef VIEW_SOURCE_HTML #ifdef VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING #ifdef VIEW_SOURCE_COLORING
theContext.mStartNode.ReleaseAll(); if (syntaxHilight)
CEndToken theEndToken(eHTMLTag_span); {
theEndToken.SetStringValue(tag); theContext.mStartNode.ReleaseAll();
theContext.mEndNode.Init(&theEndToken,mLineNumber); CEndToken theEndToken(eHTMLTag_span);
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>... theEndToken.SetStringValue(tag);
theContext.mEndNode.Init(&theEndToken,mLineNumber);
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>...
}
#endif // VIEW_SOURCE_COLORING #endif // VIEW_SOURCE_COLORING
if (kAfterText[aTagType][0] != 0) { if (kAfterText[aTagType][0] != 0) {
nsAutoString afterText; nsAutoString afterText;