ElementStyle.h

00001 /*
00002  * This source file is part of libRocket, the HTML/CSS Interface Middleware
00003  *
00004  * For the latest information, see http://www.librocket.com
00005  *
00006  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  */
00027 
00028 #ifndef ROCKETCOREELEMENTSTYLE_H
00029 #define ROCKETCOREELEMENTSTYLE_H
00030 
00031 #include "ElementDefinition.h"
00032 #include <Rocket/Core/Types.h>
00033 
00034 namespace Rocket {
00035 namespace Core {
00036 
00042 class ElementStyle
00043 {
00044 public:
00047         ElementStyle(Element* element);
00048         ~ElementStyle();
00049 
00051         const ElementDefinition* GetDefinition();
00052         
00054         void UpdateDefinition();
00055 
00059         void SetPseudoClass(const String& pseudo_class, bool activate);
00063         bool IsPseudoClassSet(const String& pseudo_class) const;
00065         const PseudoClassList& GetActivePseudoClasses() const;
00066 
00070         void SetClass(const String& class_name, bool activate);
00074         bool IsClassSet(const String& class_name) const;
00077         void SetClassNames(const String& class_names);
00080         String GetClassNames() const;
00081 
00085         bool SetProperty(const String& name, const String& value);
00089         bool SetProperty(const String& name, const Property& property);
00093         void RemoveProperty(const String& name);
00098         const Property* GetProperty(const String& name);
00103         const Property* GetLocalProperty(const String& name);
00109         float ResolveProperty(const String& name, float base_value);
00110 
00117         bool IterateProperties(int& index, PseudoClassList& pseudo_classes, String& name, const Property*& property);
00118 
00120         StyleSheet* GetStyleSheet() const;
00121 
00123         void DirtyDefinition();
00125         void DirtyChildDefinitions();
00126 
00127         // Dirties every property.
00128         void DirtyProperties();
00129         // Dirties em-relative properties.
00130         void DirtyEmProperties();
00131         // Dirties font-size on child elements if appropriate.
00132         void DirtyInheritedEmProperties();
00133 
00134 private:
00135         // Sets a single property as dirty.
00136         void DirtyProperty(const String& property);
00137         // Sets a list of properties as dirty.
00138         void DirtyProperties(const PropertyNameList& properties);
00139         // Sets a list of our potentially inherited properties as dirtied by an ancestor.
00140         void DirtyInheritedProperties(const PropertyNameList& properties);
00141 
00142         // Element these properties belong to
00143         Element* element;
00144 
00145         // The list of classes applicable to this object.
00146         StringList classes;
00147         // This element's current pseudo-classes.
00148         PseudoClassList pseudo_classes;
00149 
00150         // Any properties that have been overridden in this element;
00151         PropertyDictionary* local_properties;
00152         // The definition of this element; if this is NULL one will be fetched from the element's style.
00153         ElementDefinition* definition;
00154         // Set if a new element definition should be fetched from the style.
00155         bool definition_dirty;
00156         // Set if a child element has a dirty style definition
00157         bool child_definition_dirty;
00158 };
00159 
00160 }
00161 }
00162 
00163 #endif