1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
45 #ifndef __NS_VIEWSOURCE_HTML_
46 #define __NS_VIEWSOURCE_HTML_
49 #include "nsISupports.h"
50 #include "nsHTMLTokens.h"
51 #include "nsIHTMLContentSink.h"
52 #include "nsDTDUtils.h"
53 #include "nsParserNode.h"
60 class CIndirectTextToken
: public CTextToken
{
62 CIndirectTextToken() : CTextToken() {
66 void SetIndirectString(const nsSubstring
& aString
) {
67 mIndirectString
=&aString
;
70 virtual const nsSubstring
& GetStringValue(void){
71 return (const nsSubstring
&)*mIndirectString
;
74 const nsSubstring
* mIndirectString
;
78 class CViewSourceHTML
: public nsIDTD
86 virtual ~CViewSourceHTML();
89 * Set this to TRUE if you want the DTD to verify its
91 * @update gess 7/23/98
95 virtual void SetVerification(PRBool aEnable
);
98 nsresult
WriteTag(PRInt32 tagType
,
99 const nsSubstring
&aText
,
103 nsresult
WriteAttributes(const nsAString
& tagName
,
104 nsTokenAllocator
* allocator
, PRInt32 attrCount
, PRBool aOwnerInError
);
105 void StartNewPreBlock(void);
106 // Utility method for adding attributes to the nodes we generate
107 void AddAttrToNode(nsCParserStartNode
& aNode
,
108 nsTokenAllocator
* aAllocator
,
109 const nsAString
& aAttrName
,
110 const nsAString
& aAttrValue
);
112 PRBool
IsUrlAttribute(const nsAString
& tagName
,
113 const nsAString
& attrName
, const nsAString
& attrValue
);
114 void WriteHrefAttribute(nsTokenAllocator
* allocator
, const nsAString
& href
);
115 nsresult
CreateViewSourceURL(const nsAString
& linkUrl
, nsString
& viewSourceUrl
);
116 void WriteTextInSpan(const nsAString
& text
, nsTokenAllocator
* allocator
,
117 const nsAString
& attrName
, const nsAString
& attrValue
);
118 void WriteTextInAnchor(const nsAString
& text
, nsTokenAllocator
* allocator
,
119 const nsAString
& attrName
, const nsAString
&attrValue
);
120 void WriteTextInElement(const nsAString
& tagName
, eHTMLTags tagType
,
121 const nsAString
& text
, nsTokenAllocator
* allocator
,
122 const nsAString
& attrName
, const nsAString
& attrValue
);
123 const nsDependentSubstring
TrimTokenValue(const nsAString
& tokenValue
);
124 void TrimTokenValue(nsAString::const_iterator
& start
,
125 nsAString::const_iterator
& end
);
126 PRBool
IsTokenValueTrimmableCharacter(PRUnichar ch
);
127 nsresult
GetBaseURI(nsIURI
**result
);
128 nsresult
SetBaseURI(const nsAString
& baseSpec
);
133 nsIHTMLContentSink
* mSink
;
135 nsITokenizer
* mTokenizer
; // weak
137 PRPackedBool mSyntaxHighlight
;
138 PRPackedBool mWrapLongLines
;
139 PRPackedBool mHasOpenRoot
;
140 PRPackedBool mHasOpenBody
;
143 eParserCommands mParserCommand
; //tells us to viewcontent/viewsource/viewerrors...
144 eParserDocType mDocType
;
148 nsCOMPtr
<nsIURI
> mBaseURI
; // lazy -- always use GetBaseURI().
150 PRUint32 mTokenCount
;
152 nsCParserStartNode mStartNode
;
153 nsCParserStartNode mTokenNode
;
154 CIndirectTextToken mITextToken
;
155 nsCParserStartNode mErrorNode
;