|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __CHTMLTOCRTCONVACTIONPROCESSOR_H__ |
|
17 #define __CHTMLTOCRTCONVACTIONPROCESSOR_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include <txtrich.h> |
|
23 #include <txtfrmat.h> |
|
24 |
|
25 #define KDefaultTextColor KRgbBlack |
|
26 |
|
27 #include "CHtmlToCrtConvParser.h" |
|
28 #include "MHtmlToCrtConvResourceFile.h" |
|
29 |
|
30 enum THtmlToCrtConvTagType; |
|
31 enum THtmlToCrtConvAttributeType; |
|
32 |
|
33 class CHtmlToCrtConvActionProcessor : public CBase |
|
34 { |
|
35 enum TParserFlags |
|
36 { |
|
37 ENull = 0x00, |
|
38 EAlignAttribPending = 0x01, |
|
39 EBlockquotePending = 0x02, |
|
40 EListPending = 0x04, |
|
41 EIgnoreText = 0x08, |
|
42 ESeenAltAttribute = 0x10 |
|
43 }; |
|
44 |
|
45 public: |
|
46 static CHtmlToCrtConvActionProcessor* NewL(CRichText& aRichText, MHtmlToCrtConvResourceFile& aResourceFile); |
|
47 ~CHtmlToCrtConvActionProcessor(); |
|
48 |
|
49 void DoTagActionL(THtmlToCrtConvTagType aTagType, CHtmlToCrtConvParser::TTagState aTagState); |
|
50 void DoAttributeActionL(THtmlToCrtConvTagType aTagType, CHtmlToCrtConvParser::TTagState aTagState, const THtmlToCrtConvAttributeType& aType, const TDesC8& aValue, TBool& aImgTagResourceReqd); |
|
51 /** |
|
52 @fn void DoWriteTextL(const TDesC16& aText) |
|
53 Intended Usage : inserts text at the end of the CRichText object |
|
54 @param aText The text to be inserted |
|
55 @return void |
|
56 */ |
|
57 void DoWriteTextL(const TDesC16& aText); |
|
58 void InsertImgTagResourceL(); |
|
59 |
|
60 private: |
|
61 CHtmlToCrtConvActionProcessor(CRichText& aRichText, MHtmlToCrtConvResourceFile& aResourceFile); |
|
62 void ConstructL(); |
|
63 |
|
64 void TrimBufferL(TPtr& aPtr); |
|
65 /** |
|
66 @fn void DoBlockLevelTagActionL() |
|
67 Intended Usage : inserts a paragraph delimiter and applies alignment to the CRichText object. |
|
68 Should be called for each block level HTML tag |
|
69 @return void |
|
70 */ |
|
71 void DoBlockLevelTagActionL(); |
|
72 void ApplyAlignmentL(); |
|
73 void InsertParagraphDelimiterL(); |
|
74 void SetFontStrokeWeightL(TFontStrokeWeight aStrokeWeight); |
|
75 void SetFontPostureL(TFontPosture aFontPosture); |
|
76 void SetFontUnderlineL(TFontUnderline aFontUnderline); |
|
77 void SetFontPrintPositionL(TFontPrintPosition aFontPrintPosition); |
|
78 void SetFontStrikethroughL(TFontStrikethrough aFontStrikethrough); |
|
79 void SetFontTextColorL(const TRgb& aFontTextColor); |
|
80 void SetFontSizeL(TInt aFontSizeInTwips); |
|
81 // |
|
82 //tags |
|
83 // |
|
84 /** |
|
85 @fn void DoHeaderL(CHtmlToCrtConvParser::TTagState aTagState, TInt aFontSizeInTwips) |
|
86 Intended Usage : sets font stroke weight and font size in the CRichText object |
|
87 @param aTagState whether the HTML tag is an opening or closing tag |
|
88 @param aFontSizeInTwips the font size in twips |
|
89 @return void |
|
90 */ |
|
91 void DoHeaderL(CHtmlToCrtConvParser::TTagState aTagState, TInt aFontSizeInTwips); |
|
92 void DoCenterL(CHtmlToCrtConvParser::TTagState aTagState); |
|
93 void DoBlockquoteL(CHtmlToCrtConvParser::TTagState aTagState); |
|
94 /** |
|
95 @fn void DoFormL(CHtmlToCrtConvParser::TTagState aTagState) |
|
96 Intended Usage : updates the flag EIgnoreText |
|
97 @param aTagState whether the HTML tag is an opening or closing tag |
|
98 @return void |
|
99 */ |
|
100 void DoFormL(CHtmlToCrtConvParser::TTagState aTagState); |
|
101 /** |
|
102 @fn void DoUnorderedListL(CHtmlToCrtConvParser::TTagState aTagState) |
|
103 Intended Usage : applies bulleted list formatting to the CRichText object |
|
104 @param aTagState whether the HTML tag is an opening or closing tag |
|
105 @return void |
|
106 */ |
|
107 void DoUnorderedListL(CHtmlToCrtConvParser::TTagState aTagState); |
|
108 void DoParagraphL(); |
|
109 void DoTableL(); |
|
110 void DoDivisionL(); |
|
111 void DoPreformattedL(); |
|
112 void DoHorizontalRuleL(); |
|
113 void DoItalicL(CHtmlToCrtConvParser::TTagState aTagState); |
|
114 void DoBoldL(CHtmlToCrtConvParser::TTagState aTagState); |
|
115 void DoUnderlineL(CHtmlToCrtConvParser::TTagState aTagState); |
|
116 void DoSubscriptL(CHtmlToCrtConvParser::TTagState aTagState); |
|
117 void DoSuperscriptL(CHtmlToCrtConvParser::TTagState aTagState); |
|
118 void DoStrikethroughL(CHtmlToCrtConvParser::TTagState aTagState); |
|
119 void DoBreakL(CHtmlToCrtConvParser::TTagState aTagState); |
|
120 /** |
|
121 @fn void DoTitleL(CHtmlToCrtConvParser::TTagState aTagState) |
|
122 Intended Usage : renders title text as a header (H1) and inserts a paragraph delimiter |
|
123 @param aTagState whether the HTML tag is an opening or closing tag |
|
124 @return void |
|
125 */ |
|
126 void DoTitleL(CHtmlToCrtConvParser::TTagState aTagState); |
|
127 /** |
|
128 @fn void DoCaptionL(CHtmlToCrtConvParser::TTagState aTagState) |
|
129 Intended Usage : inserts a paragraph delimiter at the end of the CRichText object |
|
130 @param aTagState whether the HTML tag is an opening or closing tag |
|
131 @return void |
|
132 */ |
|
133 void DoCaptionL(CHtmlToCrtConvParser::TTagState aTagState); |
|
134 /** |
|
135 @fn void DoTableDataL(CHtmlToCrtConvParser::TTagState aTagState) |
|
136 Intended Usage : inserts a paragraph delimiter at the end of the CRichText object |
|
137 @param aTagState whether the HTML tag is an opening or closing tag |
|
138 @return void |
|
139 */ |
|
140 void DoTableDataL(CHtmlToCrtConvParser::TTagState aTagState); |
|
141 /** |
|
142 @fn void DoListItemL(CHtmlToCrtConvParser::TTagState aTagState) |
|
143 Intended Usage : updates the flag EListPending |
|
144 @param aTagState whether the HTML tag is an opening or closing tag |
|
145 @return void |
|
146 */ |
|
147 void DoListItemL(CHtmlToCrtConvParser::TTagState aTagState); |
|
148 void DoHtmlL(CHtmlToCrtConvParser::TTagState aTagState); |
|
149 |
|
150 //attributes |
|
151 void DoAlignL(const TDesC8& aValue, CHtmlToCrtConvParser::TTagState aTagState); |
|
152 /** |
|
153 @fn void DoShowUrlL(const TDesC8& aValue, CHtmlToCrtConvParser::TTagState aTagState) |
|
154 Intended Usage : inserts " ( aValue )" at the end of the CRichText object |
|
155 @param aValue the value of the Href or Src HTML tag attribute |
|
156 @param aTagState whether the HTML tag is an opening or closing tag |
|
157 @return void |
|
158 */ |
|
159 void DoShowUrlL(const TDesC8& aValue, CHtmlToCrtConvParser::TTagState aTagState, THtmlToCrtConvTagType aTagType); |
|
160 /** |
|
161 @fn void DoAltL(const TDesC8& aValue, CHtmlToCrtConvParser::TTagState aTagState) |
|
162 Intended Usage : inserts "<aValue>" at the end of the CRichText object |
|
163 @param aValue the value of the Alt HTML tag attribute |
|
164 @param aTagState whether the HTML tag is an opening or closing tag |
|
165 @param aTagType the type of HTML tag |
|
166 @return void |
|
167 */ |
|
168 void DoAltL(const TDesC8& aValue, CHtmlToCrtConvParser::TTagState aTagState); |
|
169 |
|
170 //flags |
|
171 inline void SetFlag (TParserFlags aFlag); |
|
172 inline TBool IsFlagSet (TParserFlags aFlag) const; |
|
173 inline void ClearFlag (TParserFlags aFlag); |
|
174 |
|
175 private: |
|
176 CRichText& iText;//reference to rich text object owned by converter |
|
177 TInt iTextPosition; |
|
178 TInt iAlignmentStartPosition; |
|
179 TInt iBlockquoteStartPosition; |
|
180 TInt iListStartPosition; |
|
181 TUint iFlags; |
|
182 |
|
183 TCharFormatMask iCharFormatMask; |
|
184 TCharFormat iCharFormat; |
|
185 TParaFormatMask iParaFormatMask; |
|
186 CParaFormat* iParaFormat; |
|
187 MHtmlToCrtConvResourceFile& iResourceFile; |
|
188 }; |
|
189 |
|
190 void CHtmlToCrtConvActionProcessor::SetFlag (TParserFlags aFlag) |
|
191 { |
|
192 iFlags |= aFlag; |
|
193 } |
|
194 |
|
195 TBool CHtmlToCrtConvActionProcessor::IsFlagSet (TParserFlags aFlag) const |
|
196 { |
|
197 return (iFlags & aFlag); |
|
198 } |
|
199 |
|
200 void CHtmlToCrtConvActionProcessor::ClearFlag (TParserFlags aFlag) |
|
201 { |
|
202 iFlags &= ~aFlag; |
|
203 } |
|
204 |
|
205 #endif |