StyleSheetNode.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCORESTYLESHEETNODE_H
00029 #define ROCKETCORESTYLESHEETNODE_H
00030
00031 #include <Rocket/Core/PropertyDictionary.h>
00032 #include <Rocket/Core/StyleSheet.h>
00033 #include <Rocket/Core/Types.h>
00034
00035 namespace Rocket {
00036 namespace Core {
00037
00038 class StyleSheetNodeSelector;
00039
00040 typedef std::map< StringList, PropertyDictionary > PseudoClassPropertyMap;
00041
00048 class StyleSheetNode
00049 {
00050 public:
00051 enum NodeType
00052 {
00053 TAG = 0,
00054 CLASS,
00055 ID,
00056 PSEUDO_CLASS,
00057 STRUCTURAL_PSEUDO_CLASS,
00058 NUM_NODE_TYPES,
00059 ROOT
00060 };
00061
00063 StyleSheetNode(const String& name, NodeType type, StyleSheetNode* parent = NULL);
00065 StyleSheetNode(const String& name, StyleSheetNode* parent, StyleSheetNodeSelector* selector, int a, int b);
00066 ~StyleSheetNode();
00067
00069 void Write(Stream* stream);
00070
00072 bool MergeHierarchy(StyleSheetNode* node, int specificity_offset = 0);
00074 void BuildIndex(StyleSheet::NodeIndex& styled_index, StyleSheet::NodeIndex& complete_index);
00075
00077 const String& GetName() const;
00079 int GetSpecificity() const;
00080
00086 void ImportProperties(const PropertyDictionary& properties, int rule_specificity);
00092 void MergeProperties(const PropertyDictionary& properties, int rule_specificity_offset);
00094 const PropertyDictionary& GetProperties() const;
00095
00098 void GetPseudoClassProperties(PseudoClassPropertyMap& pseudo_class_properties) const;
00102 bool GetVolatilePseudoClasses(PseudoClassList& volatile_pseudo_classes) const;
00103
00108 StyleSheetNode* GetChildNode(const String& name, NodeType type, bool create = true);
00109
00111 bool IsApplicable(const Element* element) const;
00113 void GetApplicableDescendants(std::vector< const StyleSheetNode* >& applicable_nodes, const Element* element) const;
00114
00118 bool IsStructurallyVolatile(bool check_ancestors = true) const;
00119
00120 private:
00121
00122 StyleSheetNode* CreateStructuralChild(const String& child_name);
00123
00124 void GetPseudoClassProperties(PseudoClassPropertyMap& pseudo_class_properties, const StringList& ancestor_pseudo_classes);
00125
00126 int CalculateSpecificity();
00127
00128
00129 StyleSheetNode* parent;
00130
00131
00132 String name;
00133 NodeType type;
00134
00135
00136 StyleSheetNodeSelector* selector;
00137 int a;
00138 int b;
00139
00140
00141
00142 int specificity;
00143
00144
00145 PropertyDictionary properties;
00146
00147
00148 typedef std::map< String, StyleSheetNode* > NodeMap;
00149 NodeMap children[NUM_NODE_TYPES];
00150 };
00151
00152 }
00153 }
00154
00155 #endif