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
parent f578184e52
commit 2d422654b1
2 changed files with 94 additions and 38 deletions

View File

@ -18,6 +18,11 @@
* Rights Reserved.
*
* 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
#define VIEW_SOURCE_HTML
//#define VIEW_SOURCE_COLORING
#define VIEW_SOURCE_COLORING
#include "nsIDTDDebug.h"
#include "nsViewSourceHTML.h"
@ -59,6 +64,15 @@
#ifdef VIEW_SOURCE_HTML
#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 "prenv.h" //this is here for debug reasons...
@ -982,6 +996,13 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
nsresult result=NS_OK;
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
if (kBeforeText[aTagType][0] != 0) {
@ -992,18 +1013,21 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
}
#ifdef VIEW_SOURCE_COLORING
nsAutoString tag;
tag.AssignWithConversion("SPAN");
nsAutoString tag (NS_LITERAL_STRING("SPAN"));
CStartToken theTagToken(eHTMLTag_span);
if (syntaxHilight)
{
theTagToken.SetStringValue(tag);
}
#endif // VIEW_SOURCE_COLORING
#else
#else // VIEW_SOURCE_HTML *UNDEFINED*
CToken theTagToken(theXMLTagName);
#endif // VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING
if (syntaxHilight)
{
theContext.mStartNode.Init(&theTagToken,mLineNumber);
#ifdef VIEW_SOURCE_HTML
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
if(theAllocator) {
@ -1017,6 +1041,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
STOP_TIMER();
mSink->OpenContainer(theContext.mStartNode); //emit <starttag>...
}
#endif // VIEW_SOURCE_COLORING
#ifdef rickgdebug
@ -1042,11 +1067,14 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
#ifdef VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING
if (syntaxHilight)
{
theContext.mStartNode.ReleaseAll();
CEndToken theEndToken(eHTMLTag_span);
theEndToken.SetStringValue(tag);
theContext.mEndNode.Init(&theEndToken,mLineNumber);
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>...
}
#endif // VIEW_SOURCE_COLORING
if (kAfterText[aTagType][0] != 0) {
nsAutoString afterText;

View File

@ -18,6 +18,11 @@
* Rights Reserved.
*
* 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
#define VIEW_SOURCE_HTML
//#define VIEW_SOURCE_COLORING
#define VIEW_SOURCE_COLORING
#include "nsIDTDDebug.h"
#include "nsViewSourceHTML.h"
@ -59,6 +64,15 @@
#ifdef VIEW_SOURCE_HTML
#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 "prenv.h" //this is here for debug reasons...
@ -982,6 +996,13 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
nsresult result=NS_OK;
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
if (kBeforeText[aTagType][0] != 0) {
@ -992,18 +1013,21 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
}
#ifdef VIEW_SOURCE_COLORING
nsAutoString tag;
tag.AssignWithConversion("SPAN");
nsAutoString tag (NS_LITERAL_STRING("SPAN"));
CStartToken theTagToken(eHTMLTag_span);
if (syntaxHilight)
{
theTagToken.SetStringValue(tag);
}
#endif // VIEW_SOURCE_COLORING
#else
#else // VIEW_SOURCE_HTML *UNDEFINED*
CToken theTagToken(theXMLTagName);
#endif // VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING
if (syntaxHilight)
{
theContext.mStartNode.Init(&theTagToken,mLineNumber);
#ifdef VIEW_SOURCE_HTML
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
if(theAllocator) {
@ -1017,6 +1041,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
STOP_TIMER();
mSink->OpenContainer(theContext.mStartNode); //emit <starttag>...
}
#endif // VIEW_SOURCE_COLORING
#ifdef rickgdebug
@ -1042,11 +1067,14 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,nsString & aText,PRIn
#ifdef VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_COLORING
if (syntaxHilight)
{
theContext.mStartNode.ReleaseAll();
CEndToken theEndToken(eHTMLTag_span);
theEndToken.SetStringValue(tag);
theContext.mEndNode.Init(&theEndToken,mLineNumber);
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>...
}
#endif // VIEW_SOURCE_COLORING
if (kAfterText[aTagType][0] != 0) {
nsAutoString afterText;