Browse Source

Accessor and caching of offset properties.

Added the method `GetOffsetProperties()` to conveniently access the `top`,
`bottom`, `left` and `right` properties of an elements style.

The addition of the method is done in the spirit of similar style accessor
methods, and comes with the addition of caching for those properties.
Fredrik Berggren 10 years ago
parent
commit
20084b7489

+ 2 - 0
Include/Rocket/Core/Element.h

@@ -227,6 +227,8 @@ public:
 	/// @return The value of this property for this element.
 	float ResolveProperty(const Property *property, float base_value);
 
+	/// Returns 'top', 'bottom', 'left' and 'right' properties from element's style or local cache.
+	void GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right );
 	/// Returns 'border-width' properties from element's style or local cache.
 	void GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **border_right_width);
 	/// Returns 'margin' properties from element's style or local cache.

+ 5 - 0
Source/Core/Element.cpp

@@ -537,6 +537,11 @@ float Element::ResolveProperty(const Property *property, float base_value)
 	return style->ResolveProperty(property, base_value);
 }
 
+void Element::GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right )
+{
+	style->GetOffsetProperties(top, bottom, left, right);
+}
+
 void Element::GetBorderWidthProperties(const Property **border_top, const Property **border_bottom, const Property **border_left, const Property **bottom_right)
 {
 	style->GetBorderWidthProperties(border_top, border_bottom, border_left, bottom_right);

+ 5 - 0
Source/Core/ElementStyle.cpp

@@ -729,6 +729,11 @@ void ElementStyle::DirtyInheritedProperties(const PropertyNameList& properties)
 	element->OnPropertyChange(properties);
 }
 
+void ElementStyle::GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right )
+{
+	cache->GetOffsetProperties(top, bottom, left, right);
+}
+
 void ElementStyle::GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **bottom_right_width)
 {
 	cache->GetBorderWidthProperties(border_top_width, border_bottom_width, border_left_width, bottom_right_width);

+ 2 - 0
Source/Core/ElementStyle.h

@@ -143,6 +143,8 @@ public:
 	// Dirties rem properties.
 	void DirtyRemProperties();
 
+	/// Returns 'top', 'bottom', 'left' and 'right' properties from element's style or local cache.
+	void GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right );	
 	/// Returns 'border-width' properties from element's style or local cache.
 	void GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **border_right_width);
 	/// Returns 'margin' properties from element's style or local cache.

+ 38 - 0
Source/Core/ElementStyleCache.cpp

@@ -33,6 +33,7 @@ namespace Rocket {
 namespace Core {
 
 ElementStyleCache::ElementStyleCache(ElementStyle *style) : style(style), 
+	top(NULL), bottom(NULL), left(NULL), right(NULL),
 	border_top_width(NULL), border_bottom_width(NULL), border_left_width(NULL), border_right_width(NULL),
 	margin_top(NULL), margin_bottom(NULL), margin_left(NULL), margin_right(NULL),
 	padding_top(NULL), padding_bottom(NULL), padding_left(NULL), padding_right(NULL),
@@ -46,6 +47,7 @@ ElementStyleCache::ElementStyleCache(ElementStyle *style) : style(style),
 
 void ElementStyleCache::Clear()
 {
+	ClearOffset();
 	ClearBorder();
 	ClearMargin();
 	ClearPadding();
@@ -65,6 +67,11 @@ void ElementStyleCache::ClearInherited()
 	ClearVerticalAlign();
 }
 
+void ElementStyleCache::ClearOffset()
+{
+	top = bottom = left = right = NULL;
+}
+
 void ElementStyleCache::ClearBorder()
 {
 	border_top_width = border_bottom_width = border_left_width = border_right_width = NULL;
@@ -131,6 +138,37 @@ void ElementStyleCache::ClearVerticalAlign()
 	vertical_align = NULL;
 }
 
+void ElementStyleCache::GetOffsetProperties(const Property **o_top, const Property **o_bottom, const Property **o_left, const Property **o_right )
+{
+	if (o_top)
+	{
+		if (!top)
+			top = style->GetProperty(TOP);
+		*o_top = top;
+	}
+
+	if (o_bottom)
+	{
+		if (!bottom)
+			bottom = style->GetProperty(BOTTOM);
+		*o_bottom = bottom;
+	}
+
+	if (o_left)
+	{
+		if (!left)
+			left = style->GetProperty(LEFT);
+		*o_left = left;
+	}
+
+	if (o_right)
+	{
+		if (!right)
+			right = style->GetProperty(RIGHT);
+		*o_right = right;
+	}
+}
+
 void ElementStyleCache::GetBorderWidthProperties(const Property **o_border_top_width, const Property **o_border_bottom_width, const Property **o_border_left_width, const Property **o_border_right_width)
 {
 	if (o_border_top_width)

+ 4 - 0
Source/Core/ElementStyleCache.h

@@ -55,6 +55,7 @@ public:
 	void ClearInherited();
 
 	/// Invalidation functions for individual and grouped non-inherited properties
+	void ClearOffset();
 	void ClearBorder();
 	void ClearMargin();
 	void ClearPadding();
@@ -71,6 +72,8 @@ public:
 	void ClearTextTransform();
 	void ClearVerticalAlign();
 
+	/// Returns 'top', 'bottom', 'left' and 'right' properties from element's style or local cache.
+	void GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right );
 	/// Returns 'border-width' properties from element's style or local cache.
 	void GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **border_right_width);
 	/// Returns 'margin' properties from element's style or local cache.
@@ -107,6 +110,7 @@ private:
 	ElementStyle *style;
 
 	/// Cached properties.
+	const Property *top, *bottom, *left, *right;
 	const Property *border_top_width, *border_bottom_width, *border_left_width, *border_right_width;
 	const Property *margin_top, *margin_bottom, *margin_left, *margin_right;
 	const Property *padding_top, *padding_bottom, *padding_left, *padding_right;