Browse Source

Replacing GetLocalProperty

Michael Ragazzon 6 years ago
parent
commit
390b6e07ba

+ 1 - 1
Source/Controls/WidgetDropDown.cpp

@@ -331,7 +331,7 @@ void WidgetDropDown::ProcessEvent(Core::Event& event)
 				element = element->GetParentNode();
 			}
 
-			if (selection_element->GetProperty< int >("visibility") == Core::VISIBILITY_HIDDEN)
+			if (selection_element->GetComputedValues().visibility == Core::Style::Visibility::Hidden)
 				ShowSelectBox(true);
 			else
 				ShowSelectBox(false);

+ 8 - 7
Source/Controls/WidgetSlider.cpp

@@ -310,11 +310,12 @@ void WidgetSlider::FormatBar(float bar_length)
 {
 	Core::Box bar_box;
 	Core::ElementUtilities::BuildBox(bar_box, parent->GetBox().GetSize(), bar);
+	auto& computed = bar->GetComputedValues();
 
 	Rocket::Core::Vector2f bar_box_content = bar_box.GetSize();
 	if (orientation == HORIZONTAL)
 	{
-		if (bar->GetLocalProperty("height") == NULL)
+		if (computed.height.value == Core::Style::Height::Auto)
 			bar_box_content.y = parent->GetBox().GetSize().y;
 	}
 
@@ -326,16 +327,16 @@ void WidgetSlider::FormatBar(float bar_length)
 		{
 			float track_length = track_size.y - (bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::TOP) + bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::BOTTOM));
 
-			if (bar->GetLocalProperty("height") == NULL)
+			if (computed.height.value == Core::Style::Height::Auto)
 			{
 				bar_box_content.y = track_length * bar_length;
 
 				// Check for 'min-height' restrictions.
-				float min_track_length = bar->ResolveProperty("min-height", track_length);
+				float min_track_length = Core::ResolveProperty(computed.min_height, track_length);
 				bar_box_content.y = Rocket::Core::Math::Max(min_track_length, bar_box_content.y);
 
 				// Check for 'max-height' restrictions.
-				float max_track_length = bar->ResolveProperty("max-height", track_length);
+				float max_track_length = Core::ResolveProperty(computed.max_height, track_length);
 				if (max_track_length > 0)
 					bar_box_content.y = Rocket::Core::Math::Min(max_track_length, bar_box_content.y);
 			}
@@ -347,16 +348,16 @@ void WidgetSlider::FormatBar(float bar_length)
 		{
 			float track_length = track_size.x - (bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::LEFT) + bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::RIGHT));
 
-			if (bar->GetLocalProperty("width") == NULL)
+			if (computed.width.value == Core::Style::Height::Auto)
 			{
 				bar_box_content.x = track_length * bar_length;
 
 				// Check for 'min-width' restrictions.
-				float min_track_length = bar->ResolveProperty("min-width", track_length);
+				float min_track_length = Core::ResolveProperty(computed.min_width, track_length);
 				bar_box_content.x = Rocket::Core::Math::Max(min_track_length, bar_box_content.x);
 
 				// Check for 'max-width' restrictions.
-				float max_track_length = bar->ResolveProperty("max-width", track_length);
+				float max_track_length = Core::ResolveProperty(computed.max_width, track_length);
 				if (max_track_length > 0)
 					bar_box_content.x = Rocket::Core::Math::Min(max_track_length, bar_box_content.x);
 			}

+ 9 - 8
Source/Controls/WidgetTextInput.cpp

@@ -157,7 +157,7 @@ void WidgetTextInput::UpdateSelectionColours()
 		colour = colour_property->Get< Rocket::Core::Colourb >();
 	else
 	{
-		colour = parent->GetProperty< Rocket::Core::Colourb >("color");
+		colour = parent->GetComputedValues().color;
 		colour.red = 255 - colour.red;
 		colour.green = 255 - colour.green;
 		colour.blue = 255 - colour.blue;
@@ -674,18 +674,19 @@ void WidgetTextInput::ShowCursor(bool show, bool move_to_cursor)
 // Formats the element, laying out the text and inserting scrollbars as appropriate.
 void WidgetTextInput::FormatElement()
 {
+	using namespace Core::Style;
 	Core::ElementScroll* scroll = parent->GetElementScroll();
 	float width = parent->GetBox().GetSize(Core::Box::PADDING).x;
 
-	int x_overflow_property = parent->GetProperty< int >("overflow-x");
-	int y_overflow_property = parent->GetProperty< int >("overflow-y");
+	Overflow x_overflow_property = parent->GetComputedValues().overflow_x;
+	Overflow y_overflow_property = parent->GetComputedValues().overflow_y;
 
-	if (x_overflow_property == Core::OVERFLOW_SCROLL)
+	if (x_overflow_property == Overflow::Scroll)
 		scroll->EnableScrollbar(Core::ElementScroll::HORIZONTAL, width);
 	else
 		scroll->DisableScrollbar(Core::ElementScroll::HORIZONTAL);
 
-	if (y_overflow_property == Core::OVERFLOW_SCROLL)
+	if (y_overflow_property == Overflow::Scroll)
 		scroll->EnableScrollbar(Core::ElementScroll::VERTICAL, width);
 	else
 		scroll->DisableScrollbar(Core::ElementScroll::VERTICAL);
@@ -694,21 +695,21 @@ void WidgetTextInput::FormatElement()
 	Rocket::Core::Vector2f content_area = FormatText();
 
 	// If we're set to automatically generate horizontal scrollbars, check for that now.
-	if (x_overflow_property == Core::OVERFLOW_AUTO)
+	if (x_overflow_property == Overflow::Auto)
 	{
 		if (parent->GetClientWidth() < content_area.x)
 			scroll->EnableScrollbar(Core::ElementScroll::HORIZONTAL, width);
 	}
 
 	// Now check for vertical overflow. If we do turn on the scrollbar, this will cause a reflow.
-	if (y_overflow_property == Core::OVERFLOW_AUTO)
+	if (y_overflow_property == Overflow::Auto)
 	{
 		if (parent->GetClientHeight() < content_area.y)
 		{
 			scroll->EnableScrollbar(Core::ElementScroll::VERTICAL, width);
 			content_area = FormatText();
 
-			if (x_overflow_property == Core::OVERFLOW_AUTO &&
+			if (x_overflow_property == Overflow::Auto &&
 				parent->GetClientWidth() < content_area.y)
 			{
 				scroll->EnableScrollbar(Core::ElementScroll::HORIZONTAL, width);

+ 8 - 8
Source/Core/Context.cpp

@@ -595,7 +595,7 @@ void Context::ProcessMouseMove(int x, int y, int key_modifier_state)
 static Element* FindFocusElement(Element* element)
 {
 	ElementDocument* owner_document = element->GetOwnerDocument();
-	if (!owner_document || owner_document->GetProperty< int >(FOCUS) == FOCUS_NONE)
+	if (!owner_document || owner_document->GetComputedValues().focus == Style::Focus::None)
 		return NULL;
 	
 	while (element && element->GetProperty< int >(FOCUS) == FOCUS_NONE)
@@ -669,12 +669,12 @@ void Context::ProcessMouseButtonDown(int button_index, int key_modifier_state)
 			drag = hover;
 			while (drag)
 			{
-				int drag_style = drag->GetProperty(DRAG)->value.Get< int >();
+				Style::Drag drag_style = drag->GetComputedValues().drag;
 				switch (drag_style)
 				{
-					case DRAG_NONE:		drag = drag->GetParentNode(); continue;
-					case DRAG_BLOCK:	drag = NULL; continue;
-					default:			drag_verbose = (drag_style == DRAG_DRAG_DROP || drag_style == DRAG_CLONE);
+				case Style::Drag::None:		drag = drag->GetParentNode(); continue;
+				case Style::Drag::Block:	drag = NULL; continue;
+				default: drag_verbose = (drag_style == Style::Drag::DragDrop || drag_style == Style::Drag::Clone);
 				}
 
 				break;
@@ -939,7 +939,7 @@ void Context::UpdateHoverChain(const Dictionary& parameters, const Dictionary& d
 				drag->DispatchEvent(DRAGSTART, drag_start_parameters);
 				drag_started = true;
 
-				if (drag->GetProperty< int >(DRAG) == DRAG_CLONE)
+				if (drag->GetComputedValues().drag == Style::Drag::Clone)
 				{
 					// Clone the element and attach it to the mouse cursor.
 					CreateDragClone(*drag);
@@ -956,8 +956,8 @@ void Context::UpdateHoverChain(const Dictionary& parameters, const Dictionary& d
 	{
 		String new_mouse_cursor;
 
-		if (hover && hover->GetProperty(CURSOR)->unit != Property::KEYWORD)
-			new_mouse_cursor = hover->GetProperty< String >(CURSOR);
+		if (hover)
+			new_mouse_cursor = hover->GetComputedValues().cursor;
 
 		GetSystemInterface()->SetMouseCursor(new_mouse_cursor);
 	}

+ 2 - 4
Source/Core/Element.cpp

@@ -2428,13 +2428,11 @@ void Element::UpdateAnimation()
 {
 	if (dirty_animation)
 	{
-		const Property* property = style->GetLocalProperty(ANIMATION);
+		const auto& animation_list = element_meta->computed_values.animation;
 		StyleSheet* stylesheet = nullptr;
 
-		if (property && (stylesheet = GetStyleSheet()))
+		if (!animation_list.empty() && (stylesheet = GetStyleSheet()))
 		{
-			auto animation_list = property->Get<AnimationList>();
-
 			for (auto& animation : animation_list)
 			{
 				Keyframes* keyframes_ptr = stylesheet->GetKeyframes(animation.name);

+ 10 - 12
Source/Core/ElementDocument.cpp

@@ -345,21 +345,19 @@ void ElementDocument::UpdatePosition()
 		// Work out our containing block; relative offsets are calculated against it.
 		Vector2f containing_block = GetParentNode()->GetBox().GetSize(Box::CONTENT);
 
-		const Property *left = GetLocalProperty(LEFT);
-		const Property *right = GetLocalProperty(RIGHT);
-		if (left != NULL && left->unit != Property::KEYWORD)
-			position.x = ResolveProperty(LEFT, containing_block.x);
-		else if (right != NULL && right->unit != Property::KEYWORD)
-			position.x = (containing_block.x - GetBox().GetSize(Box::MARGIN).x) - ResolveProperty(RIGHT, containing_block.x);
+		auto& computed = GetComputedValues();
+
+		if (computed.left.type != Style::Left::Auto)
+			position.x = ::Rocket::Core::ResolveProperty(computed.left, containing_block.x);
+		else if (computed.right.type != Style::Right::Auto)
+			position.x = (containing_block.x - GetBox().GetSize(Box::MARGIN).x) - ::Rocket::Core::ResolveProperty(computed.right, containing_block.x);
 		else
 			position.x = GetBox().GetEdge(Box::MARGIN, Box::LEFT);
 
-		const Property *top = GetLocalProperty(TOP);
-		const Property *bottom = GetLocalProperty(BOTTOM);
-		if (top != NULL && top->unit != Property::KEYWORD)
-			position.y = ResolveProperty(TOP, containing_block.y);
-		else if (bottom != NULL && bottom->unit != Property::KEYWORD)
-			position.y = (containing_block.y - GetBox().GetSize(Box::MARGIN).y) - ResolveProperty(BOTTOM, containing_block.y);
+		if (computed.top.type != Style::Top::Auto)
+			position.y = ::Rocket::Core::ResolveProperty(computed.top, containing_block.y);
+		else if (computed.bottom.type != Style::Bottom::Auto)
+			position.y = (containing_block.y - GetBox().GetSize(Box::MARGIN).y) - ::Rocket::Core::ResolveProperty(computed.bottom, containing_block.y);
 		else
 			position.y = GetBox().GetEdge(Box::MARGIN, Box::TOP);
 

+ 1 - 1
Source/Core/ElementUtilities.cpp

@@ -333,7 +333,7 @@ static void SetBox(Element* element)
 	LayoutEngine::BuildBox(box, containing_block, element);
 
 	const Property *local_height = element->GetLocalProperty(HEIGHT);
-	if (local_height == NULL)
+	if (element->GetComputedValues().height.type != Style::Height::Auto)
 		box.SetContent(Vector2f(box.GetSize().x, containing_block.y));
 
 	element->SetBox(box);

+ 11 - 13
Source/Core/LayoutBlockBox.cpp

@@ -545,23 +545,21 @@ float LayoutBlockBox::InternalContentWidth() const
 		//  Alternative solution: Add some 'intrinsic_width' property to  every 'LayoutBlockBox' and have that propagate up to the nearest 'inline-block'.
 		if (element)
 		{
-			const Property* width = element->GetLocalProperty(WIDTH);
-			const Property* min_width = element->GetLocalProperty("min-width");
-			const Property* max_width = element->GetLocalProperty("max-width");
-			if(width)
+			auto& computed = element->GetComputedValues();
+			const float block_width = box.GetSize(Box::CONTENT).x;
+
+			if(computed.width.type != Style::Width::Auto)
 			{
-				float w_value = element->ResolveProperty(width, box.GetSize(Box::CONTENT).x);
+				float w_value = ResolveProperty(computed.width, block_width);
 				content_width = Math::Max(content_width, w_value);
 			}
-			float block_width = box.GetSize(Box::CONTENT).x;
-			if (min_width)
-			{
-				float value = element->ResolveProperty(min_width, block_width);
-				content_width = Math::Max(content_width, value);
-			}
-			if (max_width)
+
+			float min_width = ResolveProperty(computed.min_width, block_width);
+			content_width = Math::Max(content_width, min_width);
+			
+			if (computed.max_width.value >= 0.f)
 			{
-				float value = element->ResolveProperty(max_width, block_width);
+				float value = ResolveProperty(computed.max_width, block_width);
 				content_width = Math::Min(content_width, value);
 			}
 		}