webengine/wmlengine/src/css/include/CSSReader.h
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CSS Lexer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TCSSReader_H
       
    20 #define TCSSReader_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include "nwx_defs.h"
       
    24 #include "nw_string_string.h"
       
    25 #include <e32std.h>
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // DATA TYPES
       
    32 
       
    33 enum TCSSReaderTokenType{
       
    34   SPACE = 1,
       
    35   ATKEYWORD,
       
    36   HASH,
       
    37   ASTERISK,
       
    38   COMMA,
       
    39   DOT,
       
    40   COLON,
       
    41   HYPHEN,
       
    42   SEMI_COLON,
       
    43   LEFT_BRACE,
       
    44   RIGHT_BRACE,
       
    45   LEFT_BRACKET,
       
    46   RIGHT_BRACKET,
       
    47   EQUALS,
       
    48   CHARSET_RULE,
       
    49   IMPORT_RULE,
       
    50   MEDIA_RULE,
       
    51   LINK_PSEUDO_CLASS,
       
    52   VISITED_PSEUDO_CLASS,
       
    53   FOCUS_PSEUDO_CLASS,
       
    54   ACTIVE_PSEUDO_CLASS,
       
    55   CACHED_PSEUDO_CLASS,
       
    56   IMPORTANT,
       
    57   VERTICAL_LINE,
       
    58   CDO,
       
    59   CDC,
       
    60   BUFFER_END,
       
    61   IDENTIFIER,
       
    62   EMS,
       
    63   EXS,
       
    64   PXS,
       
    65   INS,
       
    66   CMS,
       
    67   MMS,
       
    68   PTS,
       
    69   PERCENTAGE,
       
    70   PCS,
       
    71   NUMBER,
       
    72   URI,
       
    73   RGB,
       
    74   STRING,
       
    75   RIGHT_PARENTHESIS,
       
    76   DIGIT,
       
    77   ALPHA,
       
    78   INVALID
       
    79 };
       
    80 
       
    81 // FUNCTION PROTOTYPES
       
    82 
       
    83 // FORWARD DECLARATIONS
       
    84 
       
    85 // CLASS DECLARATION
       
    86 
       
    87 /**
       
    88 *  This class is a unit of text
       
    89 *  @lib css.lib
       
    90 *  @since 2.1
       
    91 */
       
    92 class TCSSReaderUnit
       
    93 {
       
    94   public:
       
    95     // constructor
       
    96 	  TCSSReaderUnit(TText8* aStorage, TUint32 aLength, TUint32 aNumChars)
       
    97       {
       
    98         iStorage = aStorage;
       
    99         iLength = aLength;
       
   100         iNumChars = aNumChars;
       
   101       }
       
   102 
       
   103     TCSSReaderUnit()
       
   104       {
       
   105         iStorage = NULL;
       
   106         iLength = 0;
       
   107         iNumChars = 0;
       
   108       }
       
   109 
       
   110 	  void Init(TText8* aStorage, TUint32 aLength, TUint32 aNumChars)
       
   111       {
       
   112         iStorage = aStorage;
       
   113         iLength = aLength;
       
   114         iNumChars = aNumChars;
       
   115       }
       
   116     /**
       
   117     * Converts the text to unicode
       
   118     * @since 2.1
       
   119     * @param aEncoding: encoding of the document being parsed
       
   120     * return unicode String
       
   121     */
       
   122     TText16* GetUnicodeL(TUint32 aEncoding);
       
   123     TText16* GetUnicode(TUint32 aEncoding);
       
   124 
       
   125   public: //data
       
   126     // pointer to beginning of text
       
   127     TText8* iStorage;
       
   128     // length of storage
       
   129     TUint32 iLength;
       
   130     // number of character
       
   131     TUint32 iNumChars;
       
   132 };
       
   133 // CLASS DECLARATION
       
   134 
       
   135 /**
       
   136 *  This class is the lexer for CSS syntax
       
   137 *  @lib css.lib
       
   138 *  @since 2.1
       
   139 */
       
   140 class TCSSReader
       
   141 {
       
   142   public:
       
   143     // constructor
       
   144 	  TCSSReader(TText8* aBuffer, TUint32 aLength, TUint32 aEncoding)
       
   145       {
       
   146         iBuffer = aBuffer;
       
   147         iLength = aLength;
       
   148         iEncoding = aEncoding;
       
   149         iPosition = 0;
       
   150       }
       
   151 
       
   152     TCSSReader()
       
   153       {
       
   154         iBuffer = NULL;
       
   155         iLength = 0;
       
   156         iEncoding = 0;
       
   157         iPosition = 0;
       
   158       }
       
   159 
       
   160     void Init(TText8* aBuffer, TUint32 aLength, TUint32 aEncoding)
       
   161       {
       
   162         iBuffer = aBuffer;
       
   163         iLength = aLength;
       
   164         iEncoding = aEncoding;
       
   165         iPosition = 0;
       
   166       }
       
   167 
       
   168     /**
       
   169     * Skips white space as defined by CSS2 Spec
       
   170     * @since 2.1
       
   171     * return void
       
   172     */
       
   173     void SkipWhiteSpaces();
       
   174 
       
   175     /**
       
   176     * Finds if the media type is valid (all or handheld)
       
   177     * @since 2.1
       
   178     * @param aMedia: media to be evaluated
       
   179     * return ETrue if media is valid else EFalse
       
   180     */
       
   181     TBool IsValidMedia(TCSSReaderUnit* aMedia);
       
   182 
       
   183     TInt8 ReadNextToken(TCSSReaderUnit* aStr);
       
   184 
       
   185     TInt8 GetPseudoClass();
       
   186 
       
   187     TInt8 ReadNumberToken(TCSSReaderUnit* aStr);
       
   188 
       
   189     TBool ReadIdentifier(TCSSReaderUnit* aStr);
       
   190 
       
   191     TBool ReadString(TCSSReaderUnit* aStr);
       
   192 
       
   193     TBool ReadName(TCSSReaderUnit* aStr);
       
   194 
       
   195     TBool ReadURI(TCSSReaderUnit* aStr);
       
   196 
       
   197     TBool ReadCharset();
       
   198 
       
   199     TBrowserStatusCode GoToToken(TUint8 aTokenType, TText8** aPosition);
       
   200 
       
   201     /**
       
   202     * Ignores the At-rule of CSS starting at given position
       
   203     * @since 2.1
       
   204     * @param aPosition - starting of At-Rule
       
   205     * return void
       
   206     */
       
   207     TBool IgnoreAtRule(TUint32 aPosition);
       
   208 
       
   209     /**
       
   210     * Sets position of the reader
       
   211     * @since 2.1
       
   212     * @param aPosition - position of reader
       
   213     * return void
       
   214     */
       
   215     inline void SetPosition(TUint32 aPosition){iPosition = aPosition;}
       
   216 
       
   217     /**
       
   218     * Returns pointer to the buffer
       
   219     * @since 2.1
       
   220     * return pointer to the buffer
       
   221     */
       
   222     inline TText8* GetBuffer(){return iBuffer;}
       
   223 
       
   224     /**
       
   225     * Returns length of buffer
       
   226     * @since 2.1
       
   227     * return length of buffer
       
   228     */
       
   229     inline TUint32 GetLength(){return iLength;}
       
   230 
       
   231     /**
       
   232     * Returns current position of reader
       
   233     * @since 2.1
       
   234     * return current position of reader
       
   235     */
       
   236     inline TUint32 GetPosition(){return iPosition;}
       
   237 
       
   238     /**
       
   239     * Returns encoding of buffer
       
   240     * @since 2.1
       
   241     * return encoding of buffer
       
   242     */
       
   243     inline TUint32 GetEncoding(){return iEncoding;}
       
   244 
       
   245     /**
       
   246     * Advances the buffer by certain number of bytes
       
   247     * @since 2.1
       
   248     * @param aNumBytes - number of bytes to advance
       
   249     * return void
       
   250     */
       
   251     TBool Advance(TUint32 aNumBytes);
       
   252 
       
   253     /**
       
   254     * Sets encoding of the document
       
   255     * @since 2.1
       
   256     * @param aEncoding - encoding of buffer
       
   257     * return void
       
   258     */
       
   259     inline void SetEncoding(TUint32 aEncoding){iEncoding = aEncoding;}
       
   260 
       
   261     /**
       
   262     * Returns pointer to the buffer storage where reader is positioned
       
   263     * @since 2.1
       
   264     * return pointer to the buffer storage where reader is positioned
       
   265     */
       
   266     inline TText8* GetBufferPointer(){return (iBuffer+iPosition);}
       
   267 
       
   268     /**
       
   269     * Gets the encoding associated with the text
       
   270     * @since 2.1
       
   271     * return encoding of the document being parsed
       
   272     */
       
   273     TUint32 GetCharsetVal();
       
   274 
       
   275     /**
       
   276     * Reads a character
       
   277     * @since 2.1
       
   278     * return encoding of the document being parsed
       
   279     */
       
   280     TInt32 ReadChar(TText16* aChar);
       
   281 
       
   282     TUint16 ReadEscape(TText16* aOutChar);
       
   283 
       
   284   private:    // Functions
       
   285 
       
   286     TBool Equals(const TText16* aStr, TBool aCaseInsensitive);
       
   287 
       
   288     TBool ReadBlock(TText16 aClosingChar);
       
   289 
       
   290   private:    // Data
       
   291 
       
   292     // pointer to the CSS buffer
       
   293     TText8* iBuffer;
       
   294     // length of buffer
       
   295     TUint32 iLength;
       
   296     // encoding of buffer
       
   297     TUint32 iEncoding;
       
   298     // position in the buffer
       
   299     TUint32 iPosition;
       
   300 };
       
   301 
       
   302 #endif /* TCSSReader_H */
       
   303