webengine/wmlengine/src/css/include/CSSVariableStyleSheet.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Map containing the Variable CSS style rules
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CCSSVariableStyleSheet_H
       
    20 #define CCSSVariableStyleSheet_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include "nw_css_defaultstylesheeti.h"
       
    25 #include "CSSRuleList.h"
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // FUNCTION PROTOTYPES
       
    32 class TCSSParser;
       
    33 struct TCSSPropertyTablePropEntry;
       
    34 
       
    35 // CLASS DECLARATION
       
    36 
       
    37 #ifdef __cplusplus
       
    38 extern "C" {
       
    39 #endif /* __cplusplus */
       
    40 
       
    41   extern NW_WBXML_Dictionary_t NW_XHTML_WBXMLDictionary;
       
    42 
       
    43 #ifdef __cplusplus
       
    44 } // extern "C" {
       
    45 #endif /* __cplusplus */
       
    46 
       
    47 
       
    48 
       
    49 /** *****************************************************************
       
    50  *  These structs are simple wrappers for the css property and string
       
    51  *  entries. They wrap the same structures found in the default style
       
    52  *  sheets. Note that a flag indicates whether they entry is a static
       
    53  *  referring to the fixed table or a dynamic one referring to the
       
    54  *  dynamic one. The dynamic (e.g. variable) entry is heap allocated and
       
    55  *  as such it and its components should be deallocated.
       
    56  *
       
    57  *  @lib css.lib
       
    58  *  @since 2.7
       
    59  ******************************************************************* */
       
    60 
       
    61 typedef struct _TCSSStringEntry{
       
    62   TBool variableEntry;
       
    63   NW_Ucs2* entry;
       
    64 }TCSSStringEntry;
       
    65 
       
    66 
       
    67 typedef struct _TCSSPropEntry{
       
    68   TInt key; // MUST BE FIRST
       
    69   TBool variableEntry;
       
    70   NW_CSS_DefaultStyleSheet_PropEntry_s* entry;
       
    71 }TCSSPropEntry;
       
    72 
       
    73 // DATA TYPES
       
    74 typedef RArray<TCSSStringEntry> CCSSStringEntryList;
       
    75 typedef RArray<TCSSPropEntry> CCSSPropEntryList;
       
    76 
       
    77 /** *****************************************************************
       
    78  *  The CCSSVariableStyleSheet is a repository for the default and
       
    79  *  variable style sheet entries. If no entries variable entries are
       
    80  *  found (i.e. file not found or corrupt) then only the default entries
       
    81  *  will be used to populate the structure.
       
    82  *
       
    83  *  @lib css.lib
       
    84  *  @since 2.7
       
    85  ******************************************************************* */
       
    86 class CCSSVariableStyleSheet : public CBase
       
    87 {
       
    88 
       
    89 
       
    90 public:   // Constructors and destructor
       
    91 
       
    92   /**
       
    93    * Two-phased constructor. It is private because it is created as a
       
    94    * singleton and shared.
       
    95    * @return CCSSVariableStyleSheet*
       
    96    */
       
    97   static CCSSVariableStyleSheet* NewL();
       
    98 
       
    99   /**
       
   100    * Creates the CCSSVariableStyleSheet singleton.
       
   101    * @since 2.7
       
   102    * @return style sheet.
       
   103    */
       
   104   static CCSSVariableStyleSheet* CreateSingleton();
       
   105 
       
   106   /**
       
   107    * Deletes the CCSSVariableStyleSheet singleton.
       
   108    * @since 2.7
       
   109    * @return void.
       
   110    */
       
   111   static void DeleteSingleton();
       
   112 
       
   113   /**
       
   114    * Get the CCSSVariableStyleSheet singleton. If it doesn't exist
       
   115    * then return NULL.
       
   116    * @since 2.7
       
   117    * @return a pointer to CCSSVariableStyleSheet
       
   118    */
       
   119   static CCSSVariableStyleSheet* GetSingleton();
       
   120 
       
   121 /**
       
   122  * Applies the combined variable and default styles to the element node
       
   123  * in the document after pattern matching. This is called frequently by
       
   124  * XHTMLElementHandler. Duplicates have already been removed so that the
       
   125  * default and variable styles do not need to be treated differently or
       
   126  * applied separately.
       
   127  *
       
   128  * @param elementNode Element node for which pattern matching needs to be done
       
   129  * @param box Box to which CSS is applied
       
   130  * @param dictionary
       
   131  * @param event event resulting in style application (for e.g. focus)
       
   132  *                This is usually NULL.
       
   133  * @param documentNode
       
   134  * @param domHelper for resolving entities
       
   135  * @since 2.7
       
   136  * @return KBrsrSuccess or KBrsrOutOfMemory
       
   137  */
       
   138 TBrowserStatusCode ApplyStyles(NW_DOM_ElementNode_t* aElementNode,
       
   139                                NW_LMgr_Box_t* aBox,
       
   140                                NW_WBXML_Dictionary_t* aDictionary,
       
   141                                const NW_Evt_Event_t* aEvent,
       
   142                                NW_HED_DocumentNode_t* aDocumentNode,
       
   143                                NW_HED_DomHelper_t* aDomHelper);
       
   144 
       
   145 /**
       
   146  * Parses the loaded variable CSS buffer stores entries in the tables.
       
   147  * @param buffer data to parse. Stored as text
       
   148  * @param length size of buffer in bytes. Does not include a null terminator
       
   149  * @return ETrue if parsed.
       
   150  */
       
   151 TBool ProcessBuffer(const TUint8* aBuffer, TUint32 aLength);
       
   152 
       
   153 /**
       
   154  * Accessor for the state of the default property sheet. It is true if
       
   155  * the values were successfully loaded.
       
   156  * @return ETrue if loaded
       
   157  */
       
   158 TBool IsStaticCSSLoaded(){
       
   159   return  iStaticCSSLoaded;
       
   160 }
       
   161 
       
   162 
       
   163 /**
       
   164  * Accessor for the state of the variable property sheet. It is true if
       
   165  * the values were successfully loaded.
       
   166  * @return ETrue if loaded
       
   167  */
       
   168 TBool IsVariableCSSLoaded(){
       
   169   return  iVariableCSSLoaded;
       
   170 }
       
   171 
       
   172 private:    // Data
       
   173 
       
   174  TBool iStaticCSSLoaded;
       
   175  TBool iVariableCSSLoaded;
       
   176  CCSSPropEntryList* iPropList;
       
   177  CCSSStringEntryList* iStringList;
       
   178 
       
   179 private:
       
   180 
       
   181 /**
       
   182  * C++ default constructor.
       
   183  */
       
   184 
       
   185  /**
       
   186   * By default Symbian 2nd phase constructor is private.
       
   187   */
       
   188 void ConstructL();
       
   189 
       
   190 
       
   191 /**
       
   192  * Destructor. It is private because it is created as a singleton.
       
   193  */
       
   194  virtual ~CCSSVariableStyleSheet();
       
   195 
       
   196 
       
   197 /**
       
   198  * Assignment operator. It is private because it should not be called.
       
   199  */
       
   200 void operator=(const CCSSVariableStyleSheet& obj);
       
   201 
       
   202 
       
   203 /**
       
   204  * Loads a file into the buffer. Looks first in on the C drive and then
       
   205  * if not found looks on the Z drive.
       
   206  * @return Pointer to buffer containing loaded file contents.
       
   207  * Otherwise returns NULL.
       
   208  */
       
   209  HBufC8* ReadVariableCSSFile();
       
   210 
       
   211 
       
   212 /**
       
   213  * Loads a file into the buffer. This is a generic utility.
       
   214  * @return Pointer to buffer containing loaded file contents.
       
   215  * Otherwise returns NULL.
       
   216  */
       
   217  HBufC8* ReadFile(const TDesC& aFile);
       
   218 
       
   219 
       
   220 /**
       
   221  * Parses the css file that has been loaded. The results are stored into
       
   222  * the variable style sheet list. Duplicates are ignored. That is, the
       
   223  * first entry is added and subsequent duplicates are ignored. This list
       
   224  * is added before the lower priority default list so if a duplicate is
       
   225  * found it is assumed to be equal or higher priority.
       
   226  * @param buffer The buffer contains the css variable file.
       
   227  * @return ETrue if successfully parsed. Otherwise it returns EFalse
       
   228  */
       
   229  TBool AddVariableStyles(HBufC8* aBuffer);
       
   230 
       
   231 
       
   232 /**
       
   233  * Loads the CSS strings from the default tables. These are placed in a
       
   234  * string table.
       
   235  */
       
   236  void AddDefaultStyleStrings();
       
   237 
       
   238 
       
   239 /**
       
   240  * Loads the default css styles. They are merged with the previously
       
   241  * loaded variable styles. That is, if a style is not found in the list
       
   242  * it is added. If it is already present the default value is
       
   243  * ignored. Duplicates are not allowed. Note that if duplicates exist in
       
   244  * this default list, only the first entry is applied.
       
   245  */
       
   246  void AddDefaultStyleProperties();
       
   247 
       
   248 
       
   249 /**
       
   250  * Initializes the property using the entry loaded from the variable table.
       
   251  * @param propEntry Default/variable entry to be applied.
       
   252  * @param prop Property that is being initialized.
       
   253  * @param box Box to which CSS is applied
       
   254  * @param val Value to apply. Requires valType for interpretation.
       
   255  * @param valType Data type
       
   256  * @return KBrsrSuccess if operation successful. Otherwise  KBrsrFailure.
       
   257  */
       
   258 TBrowserStatusCode InitProperty(const TCSSPropertyTablePropEntry* aPropEntry,
       
   259                                 NW_LMgr_Property_t* aProp,
       
   260                                 NW_LMgr_Box_t* aBox,
       
   261                                 NW_Float32 aVal,
       
   262                                 NW_Uint8 aValType);
       
   263 
       
   264 
       
   265 /**
       
   266  * Adds the styles for the element to the list.
       
   267  * @param aParser loaded parser for the style sheet
       
   268  * @param aRuleList list for this element token
       
   269  * @param aElementToken
       
   270  * @return KBrsrSuccess if operation successful. Otherwise  KBrsrFailure.
       
   271  */
       
   272 TBrowserStatusCode UpdateList(TCSSParser* aParser,
       
   273                               CCSSRules* aRuleList,
       
   274                               NW_Uint16 aElementToken);
       
   275 
       
   276 /**
       
   277  * Updates one entry in the list.
       
   278  * @param aParser The parser
       
   279  * @param aElementToken The token to add
       
   280  * @param aAsciiPatternStr Optional pattern to include with token.
       
   281  * @return Status of operation
       
   282  */
       
   283 TBrowserStatusCode UpdateEntry(TCSSParser* aParser,
       
   284                                TUint16 aElementToken,
       
   285                                char* aAsciiPatternStr);
       
   286 
       
   287 
       
   288 /**
       
   289  * Wrapper method to call the correct setting method.
       
   290  * @param aParser The parser.
       
   291  * @param aVal The property value type
       
   292  * @param  aPropertyValue The actual value.
       
   293  * @param aValStorage The text value
       
   294  * @return Property type
       
   295  */
       
   296 NW_LMgr_PropertyValueType_t SetPropertyVal(TCSSParser* aParser,
       
   297                                            const TCSSPropertyTablePropEntry* aPropEntry,
       
   298                                            NW_LMgr_PropertyValue_t* aVal,
       
   299                                            TCSSPropertyVal* aPropertyVal,
       
   300                                            TText16* aValStorage);
       
   301 
       
   302 /**
       
   303  * Inserts a value into the list. If there is an error or a duplicate
       
   304  * the value is not entered.
       
   305  * @param aPropEntry Value to enter into the list.
       
   306  * @return index of inserted value or -1 if error
       
   307  */
       
   308 TInt InsertProperty(TCSSPropEntry aPropEntry);
       
   309 
       
   310 
       
   311 /**
       
   312  * Dumps the contents of the style sheet to the log.
       
   313  */
       
   314 TBrowserStatusCode DumpVariableStyleSheet();
       
   315 
       
   316 void ConstructCSSFileName();
       
   317 
       
   318 TFileName CSS_USER_SUPPLIED_FILE;
       
   319 TFileName CSS_OPERATOR_SUPPLIED_FILE;
       
   320 
       
   321 
       
   322 
       
   323 };
       
   324 
       
   325 
       
   326 #endif /*  CCSSVariableStyleSheet_H */