浏览代码

Use the Dictionary on OnAttributeChange to avoid copies and double map lookup

Michael Ragazzon 6 年之前
父节点
当前提交
9380fb5970

+ 1 - 1
Include/Rocket/Controls/ElementFormControl.h

@@ -77,7 +77,7 @@ public:
 protected:
 	/// Checks for changes to the 'disabled' attribute.
 	/// @param[in] changed_attributes List of changed attributes on the element.
-	virtual void OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual void OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 };
 
 }

+ 1 - 1
Include/Rocket/Controls/ElementFormControlDataSelect.h

@@ -63,7 +63,7 @@ protected:
 
 	/// Checks for changes to the data source or formatting attributes.
 	/// @param[in] changed_attributes List of changed attributes on the element.
-	virtual void OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual void OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 
 	/// Detaches from the data source and rebuilds the options.
 	virtual void OnDataSourceDestroy(DataSource* data_source);

+ 5 - 5
Include/Rocket/Controls/ElementFormControlInput.h

@@ -71,17 +71,17 @@ protected:
 
 	/// Checks for necessary functional changes in the control as a result of changed attributes.
 	/// @param[in] changed_attributes The list of changed attributes.
-	virtual void OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual void OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 	/// Called when properties on the control are changed.
 	/// @param[in] changed_properties The properties changed on the element.
-	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties);
+	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties) override;
 
 	/// If we are the added element, this will pass the call onto our type handler.
 	/// @param[in] child The new member of the hierarchy.
-	virtual void OnChildAdd(Rocket::Core::Element* child);
+	virtual void OnChildAdd(Rocket::Core::Element* child) override;
 	/// If we are the removed element, this will pass the call onto our type handler.
 	/// @param[in] child The member of the hierarchy that was just removed.
-	virtual void OnChildRemove(Rocket::Core::Element* child);
+	virtual void OnChildRemove(Rocket::Core::Element* child) override;
 
 	/// Checks for necessary functional changes in the control as a result of the event.
 	/// @param[in] event The event to process.
@@ -89,7 +89,7 @@ protected:
 
 	/// Sizes the dimensions to the element's inherent size.
 	/// @return True.
-	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions);
+	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions) override;
 
 private:
 	InputType* type;

+ 6 - 6
Include/Rocket/Controls/ElementFormControlTextArea.h

@@ -54,10 +54,10 @@ public:
 	/// Returns a string representation of the current value of the form control. This is the value of the control
 	/// regardless of whether it has been selected / checked (as appropriate for the control).
 	/// @return The value of the form control.
-	virtual Rocket::Core::String GetValue() const;
+	virtual Rocket::Core::String GetValue() const override;
 	/// Sets the current value of the form control.
 	/// @param[in] value The new value of the form control.
-	virtual void SetValue(const Rocket::Core::String& value);
+	virtual void SetValue(const Rocket::Core::String& value) override;
 
 	/// Sets the number of characters visible across the text area. Note that this will only be precise when using
 	/// a fixed-width font.
@@ -91,7 +91,7 @@ public:
 
 	/// Returns the control's inherent size, based on the length of the input field and the current font size.
 	/// @return True.
-	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions);
+	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions) override;
 
 protected:
 	/// Updates the control's widget.
@@ -102,14 +102,14 @@ protected:
 	void OnLayout();
 
 	/// Called when attributes on the element are changed.
-	virtual void OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual void OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 	/// Called when properties on the control are changed.
 	/// @param[in] changed_properties The properties changed on the element.
-	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties);
+	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties) override;
 
 	/// Returns the text content of the element.
 	/// @param[out] content The content of the element.
-	virtual void GetInnerRML(Rocket::Core::String& content) const;
+	virtual void GetInnerRML(Rocket::Core::String& content) const override;
 
 private:
 	WidgetTextInput* widget;		

+ 3 - 3
Include/Rocket/Core/Element.h

@@ -311,7 +311,7 @@ public:
 	void RemoveAttribute(const String& name);
 	/// Set a group of attributes.
 	/// @param[in] attributes Attributes to set.
-	void SetAttributes(const ElementAttributes* attributes);
+	void SetAttributes(const ElementAttributes& attributes);
 	/// Get the attributes of the element.
 	/// @return The attributes
 	const ElementAttributes& GetAttributes() const { return attributes; }
@@ -596,8 +596,8 @@ protected:
 	virtual void OnLayout();
 
 	/// Called when attributes on the element are changed.
-	/// @param[in] changed_attributes The attributes changed on the element.
-	virtual void OnAttributeChange(const AttributeNameList& changed_attributes);
+	/// @param[in] changed_attributes Dictionary of attributes changed on the element. Attribute value will be empty if it was unset.
+	virtual void OnAttributeChange(const ElementAttributes& changed_attributes);
 	/// Called when properties on the element are changed.
 	/// @param[in] changed_properties The properties changed on the element.
 	virtual void OnPropertyChange(const PropertyNameList& changed_properties);

+ 3 - 2
Include/Rocket/Core/Element.inl

@@ -42,8 +42,9 @@ T Element::GetProperty(const String& name)
 template< typename T >
 void Element::SetAttribute(const String& name, const T& value)
 {
-	attributes[name] = Variant(value);
-	AttributeNameList changed_attributes = { name };
+	Variant variant(value);
+	attributes[name] = variant;
+	ElementAttributes changed_attributes = { {name, variant} };
 	OnAttributeChange(changed_attributes);
 }
 

+ 2 - 1
Include/Rocket/Core/Variant.h

@@ -99,9 +99,10 @@ public:
 
 	/// Templatised data accessor. TypeConverters will be used to attempt to convert from the
 	/// internal representation to the requested representation.
+	/// @param[in] default_value The value returned if the conversion failed.
 	/// @return Data in the requested type.
 	template< typename T >
-	T Get() const;
+	T Get(T default_value = T()) const;
 
 	/// Templatised data accessor. TypeConverters will be used to attempt to convert from the
 	/// internal representation to the requested representation.

+ 3 - 4
Include/Rocket/Core/Variant.inl

@@ -127,11 +127,10 @@ bool Variant::GetInto(T& value) const
 
 // Templatised data accessor.
 template< typename T >
-T Variant::Get() const
+T Variant::Get(T default_value) const
 {
-	T value;
-	GetInto(value);
-	return value;
+	GetInto(default_value);
+	return default_value;
 }
 
 }

+ 1 - 1
Source/Controls/ElementFormControl.cpp

@@ -74,7 +74,7 @@ void ElementFormControl::SetDisabled(bool disable)
 }
 
 // Checks for changes to the 'disabled' attribute.
-void ElementFormControl::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+void ElementFormControl::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	Core::Element::OnAttributeChange(changed_attributes);
 

+ 1 - 1
Source/Controls/ElementFormControlDataSelect.cpp

@@ -72,7 +72,7 @@ void ElementFormControlDataSelect::OnUpdate()
 }
 
 // Checks for changes to the data source or formatting attributes.
-void ElementFormControlDataSelect::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+void ElementFormControlDataSelect::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	ElementFormControlSelect::OnAttributeChange(changed_attributes);
 

+ 7 - 6
Source/Controls/ElementFormControlInput.cpp

@@ -92,17 +92,18 @@ void ElementFormControlInput::OnResize()
 }
 
 // Checks for necessary functional changes in the control as a result of changed attributes.
-void ElementFormControlInput::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+void ElementFormControlInput::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	ElementFormControl::OnAttributeChange(changed_attributes);
 
 	Rocket::Core::String new_type_name;
 
-	if (changed_attributes.find("type") != changed_attributes.end())
+	auto it_type = changed_attributes.find("type");
+	if (it_type != changed_attributes.end())
 	{
-		new_type_name = GetAttribute< Rocket::Core::String >("type", "text");
+		new_type_name = it_type->second.Get<Core::String>("text");
 	}
-	else if (type == NULL)
+	else if (!type)
 	{
 		// Ref. comment in constructor.
 		new_type_name = "text";
@@ -110,7 +111,7 @@ void ElementFormControlInput::OnAttributeChange(const Core::AttributeNameList& c
 
 	if (!new_type_name.empty() && new_type_name != type_name)
 	{
-		InputType* new_type = NULL;
+		InputType* new_type = nullptr;
 
 		if (new_type_name == "password")
 			new_type = new InputTypeText(this, Rocket::Controls::InputTypeText::OBSCURED);
@@ -127,7 +128,7 @@ void ElementFormControlInput::OnAttributeChange(const Core::AttributeNameList& c
 		else if (new_type_name == "text")
 			new_type = new InputTypeText(this);
 
-		if (new_type != NULL)
+		if (new_type)
 		{
 			delete type;
 			type = new_type;

+ 1 - 1
Source/Controls/ElementFormControlTextArea.cpp

@@ -144,7 +144,7 @@ void ElementFormControlTextArea::OnLayout()
 }
 
 // Called when attributes on the element are changed.
-void ElementFormControlTextArea::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+void ElementFormControlTextArea::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	ElementFormControl::OnAttributeChange(changed_attributes);
 

+ 1 - 1
Source/Controls/InputType.cpp

@@ -66,7 +66,7 @@ void InputType::OnResize()
 }
 
 // Checks for necessary functional changes in the control as a result of changed attributes.
-bool InputType::OnAttributeChange(const Core::AttributeNameList& ROCKET_UNUSED_PARAMETER(changed_attributes))
+bool InputType::OnAttributeChange(const Core::ElementAttributes& ROCKET_UNUSED_PARAMETER(changed_attributes))
 {
 	ROCKET_UNUSED(changed_attributes);
 

+ 1 - 1
Source/Controls/InputType.h

@@ -69,7 +69,7 @@ public:
 	/// Checks for necessary functional changes in the control as a result of changed attributes.
 	/// @param[in] changed_attributes The list of changed attributes.
 	/// @return True if no layout is required, false if the layout needs to be dirtied.
-	virtual bool OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual bool OnAttributeChange(const Core::ElementAttributes& changed_attributes);
 	/// Called when properties on the control are changed.
 	/// @param[in] changed_properties The properties changed on the element.
 	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties);

+ 1 - 1
Source/Controls/InputTypeCheckbox.cpp

@@ -46,7 +46,7 @@ bool InputTypeCheckbox::IsSubmitted()
 }
 
 // Checks for necessary functional changes in the control as a result of changed attributes.
-bool InputTypeCheckbox::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+bool InputTypeCheckbox::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	// Check if maxlength has been defined.
 	if (changed_attributes.find("checked") != changed_attributes.end())

+ 3 - 3
Source/Controls/InputTypeCheckbox.h

@@ -47,12 +47,12 @@ public:
 
 	/// Returns if this value should be submitted with the form.
 	/// @return True if the form control is to be submitted, false otherwise.
-	virtual bool IsSubmitted();
+	virtual bool IsSubmitted() override;
 
 	/// Checks for necessary functional changes in the control as a result of changed attributes.
 	/// @param[in] changed_attributes The list of changed attributes.
 	/// @return True if no layout is required, false if the layout needs to be dirtied.
-	virtual bool OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual bool OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 
 	/// Checks for necessary functional changes in the control as a result of the event.
 	/// @param[in] event The event to process.
@@ -60,7 +60,7 @@ public:
 
 	/// Sizes the dimensions to the element's inherent size.
 	/// @return True.
-	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions);
+	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions) override;
 };
 
 }

+ 1 - 1
Source/Controls/InputTypeRadio.cpp

@@ -50,7 +50,7 @@ bool InputTypeRadio::IsSubmitted()
 }
 
 // Checks for necessary functional changes in the control as a result of changed attributes.
-bool InputTypeRadio::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+bool InputTypeRadio::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	// Check if maxlength has been defined.
 	if (changed_attributes.find("checked") != changed_attributes.end())

+ 4 - 4
Source/Controls/InputTypeRadio.h

@@ -47,15 +47,15 @@ public:
 
 	/// Returns if this value should be submitted with the form.
 	/// @return True if the form control is to be submitted, false otherwise.
-	virtual bool IsSubmitted();
+	virtual bool IsSubmitted() override;
 
 	/// Checks for necessary functional changes in the control as a result of changed attributes.
 	/// @param[in] changed_attributes The list of changed attributes.
 	/// @return True if no layout is required, false if the layout needs to be dirtied.
-	virtual bool OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual bool OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 
 	/// Pops the element's radio set if we are checked.
-	virtual void OnChildAdd();
+	virtual void OnChildAdd() override;
 
 	/// Checks for necessary functional changes in the control as a result of the event.
 	/// @param[in] event The event to process.
@@ -63,7 +63,7 @@ public:
 
 	/// Sizes the dimensions to the element's inherent size.
 	/// @return True.
-	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions);
+	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions) override;
 
 private:
 	/// Pops all other radio buttons in our form that share our name.

+ 16 - 11
Source/Controls/InputTypeRange.cpp

@@ -61,32 +61,37 @@ void InputTypeRange::OnResize()
 }
 
 // Checks for necessary functional changes in the control as a result of changed attributes.
-bool InputTypeRange::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+bool InputTypeRange::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	bool dirty_layout = false;
 
 	// Check if maxlength has been defined.
-	if (changed_attributes.find("orientation") != changed_attributes.end())
+	auto it_orientation = changed_attributes.find("orientation");
+	if (it_orientation != changed_attributes.end())
 	{
-		widget->SetOrientation(element->GetAttribute< Rocket::Core::String >("orientation", "horizontal") == "horizontal" ? WidgetSliderInput::HORIZONTAL : WidgetSliderInput::VERTICAL);
+		widget->SetOrientation(it_orientation->second.Get<Rocket::Core::String>("horizontal") == "horizontal" ? WidgetSliderInput::HORIZONTAL : WidgetSliderInput::VERTICAL);
 		dirty_layout = true;
 	}
 
 	// Check if size has been defined.
-	if (changed_attributes.find("step") != changed_attributes.end())
-		widget->SetStep(element->GetAttribute< float >("step", 1.0f));
+	auto it_step = changed_attributes.find("step");
+	if (it_step != changed_attributes.end())
+		widget->SetStep(it_step->second.Get(1.0f));
 
 	// Check if min has been defined.
-	if (changed_attributes.find("min") != changed_attributes.end())
-		widget->SetMinValue(element->GetAttribute< float >("min", 0.0f));
+	auto it_min = changed_attributes.find("min");
+	if (it_min != changed_attributes.end())
+		widget->SetMinValue(it_min->second.Get(0.0f));
 
 	// Check if max has been defined.
-	if (changed_attributes.find("max") != changed_attributes.end())
-		widget->SetMaxValue(element->GetAttribute< float >("max", 100.0f));
+	auto it_max = changed_attributes.find("max");
+	if (it_max != changed_attributes.end())
+		widget->SetMaxValue(it_max->second.Get(100.f));
 
 	// Check if the value has been changed.
-	if (changed_attributes.find("value") != changed_attributes.end())
-		widget->SetValue(element->GetAttribute< float >("value", 0.0f));
+	auto it_value = changed_attributes.find("value");
+	if (it_value != changed_attributes.end())
+		widget->SetValue(it_value->second.Get(0.0f));
 
 	return !dirty_layout;
 }

+ 3 - 3
Source/Controls/InputTypeRange.h

@@ -52,7 +52,7 @@ public:
 	virtual Rocket::Core::String GetValue() const;
 
 	/// Called every update from the host element.
-	virtual void OnUpdate();
+	virtual void OnUpdate() override;
 
 	/// Called every time the host element's size changes.
 	virtual void OnResize() override;
@@ -60,7 +60,7 @@ public:
 	/// Checks for necessary functional changes in the control as a result of changed attributes.
 	/// @param[in] changed_attributes The list of changed attributes.
 	/// @return True if no layout is required, false if the layout needs to be dirtied.
-	virtual bool OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual bool OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 
 	/// Checks for necessary functional changes in the control as a result of the event.
 	/// @param[in] event The event to process.
@@ -68,7 +68,7 @@ public:
 
 	/// Sizes the dimensions to the element's inherent size.
 	/// @return True.
-	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions);
+	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions) override;
 
 private:
 	WidgetSliderInput* widget;

+ 10 - 7
Source/Controls/InputTypeText.cpp

@@ -70,24 +70,27 @@ void InputTypeText::OnResize()
 }
 
 // Checks for necessary functional changes in the control as a result of changed attributes.
-bool InputTypeText::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
+bool InputTypeText::OnAttributeChange(const Core::ElementAttributes& changed_attributes)
 {
 	bool dirty_layout = false;
 
 	// Check if maxlength has been defined.
-	if (changed_attributes.find("maxlength") != changed_attributes.end())
-		widget->SetMaxLength(element->GetAttribute< int >("maxlength", -1));
+	auto it = changed_attributes.find("maxlength");
+	if (it != changed_attributes.end())
+		widget->SetMaxLength(it->second.Get(-1));
 
 	// Check if size has been defined.
-	if (changed_attributes.find("size") != changed_attributes.end())
+	it = changed_attributes.find("size");
+	if (it != changed_attributes.end())
 	{
-		size = element->GetAttribute< int >("size", 20);
+		size = it->second.Get(20);
 		dirty_layout = true;
 	}
 
 	// Check if the value has been changed.
-	if (changed_attributes.find("value") != changed_attributes.end())
-		widget->SetValue(element->GetAttribute< Rocket::Core::String >("value", ""));
+	it = changed_attributes.find("value");
+	if (it != changed_attributes.end())
+		widget->SetValue(it->second.Get<Core::String>());
 
 	return !dirty_layout;
 }

+ 6 - 6
Source/Controls/InputTypeText.h

@@ -54,21 +54,21 @@ public:
 	virtual ~InputTypeText();
 
 	/// Called every update from the host element.
-	virtual void OnUpdate();
+	virtual void OnUpdate() override;
 
 	/// Called every render from the host element.
-	virtual void OnRender();
+	virtual void OnRender() override;
 
 	/// Called when the parent element's size changes.
-	virtual void OnResize();
+	virtual void OnResize() override;
 
 	/// Checks for necessary functional changes in the control as a result of changed attributes.
 	/// @param[in] changed_attributes The list of changed attributes.
 	/// @return True if no layout is required, false if the layout needs to be dirtied.
-	virtual bool OnAttributeChange(const Core::AttributeNameList& changed_attributes);
+	virtual bool OnAttributeChange(const Core::ElementAttributes& changed_attributes) override;
 	/// Called when properties on the control are changed.
 	/// @param[in] changed_properties The properties changed on the element.
-	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties);
+	virtual void OnPropertyChange(const Core::PropertyNameList& changed_properties) override;
 
 	/// Checks for necessary functional changes in the control as a result of the event.
 	/// @param[in] event The event to process.
@@ -76,7 +76,7 @@ public:
 
 	/// Sizes the dimensions to the element's inherent size.
 	/// @return True.
-	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions);
+	virtual bool GetIntrinsicDimensions(Rocket::Core::Vector2f& dimensions) override;
 
 private:
 	int size;

+ 1 - 1
Source/Controls/WidgetSliderInput.cpp

@@ -52,7 +52,7 @@ void WidgetSliderInput::SetValue(float value)
 	SetBarPosition(SetValueInternal(new_value));
 }
 
-float WidgetSliderInput::GetValue()
+float WidgetSliderInput::GetValue() const
 {
 	return value;
 }

+ 6 - 6
Source/Controls/WidgetSliderInput.h

@@ -50,7 +50,7 @@ public:
 	void SetValue(float value);
 	/// Returns the current value of the slider.
 	/// @return The current value of the slider.
-	float GetValue();
+	float GetValue() const;
 
 	/// Sets the minimum value of the slider.
 	/// @param[in] min_value The new minimum value of the slider.
@@ -69,23 +69,23 @@ protected:
 	/// Called when the slider's bar position is set or dragged.
 	/// @param bar_position[in] The new position of the bar (0 representing the start of the track, 1 representing the end).
 	/// @return The new position of the bar.
-	virtual float OnBarChange(float bar_position);
+	virtual float OnBarChange(float bar_position) override;
 	/// Called when the slider is incremented by one 'line', either by the down / right key or a mouse-click on the
 	/// increment arrow.
 	/// @return The new position of the bar.
-	virtual float OnLineIncrement();
+	virtual float OnLineIncrement() override;
 	/// Called when the slider is decremented by one 'line', either by the up / left key or a mouse-click on the
 	/// decrement arrow.
 	/// @return The new position of the bar.
-	virtual float OnLineDecrement();
+	virtual float OnLineDecrement() override;
 	/// Called when the slider is incremented by one 'page', either by the page-up key or a mouse-click on the
 	/// track below / right of the bar.
 	/// @return The new position of the bar.
-	virtual float OnPageIncrement(float click_position);
+	virtual float OnPageIncrement(float click_position) override;
 	/// Called when the slider is incremented by one 'page', either by the page-down key or a mouse-click on the
 	/// track above / left of the bar.
 	/// @return The new position of the bar.
-	virtual float OnPageDecrement(float click_position);
+	virtual float OnPageDecrement(float click_position) override;
 
 private:
 	/// Clamps the new value, sets it on the slider and returns it as a number from 0 to 1, 0 being the minimum

+ 16 - 18
Source/Core/Element.cpp

@@ -928,9 +928,8 @@ void Element::RemoveAttribute(const String& name)
 	{
 		attributes.erase(it);
 
-		AttributeNameList changed_attributes;
-		changed_attributes.insert(name);
-
+		ElementAttributes changed_attributes;
+		changed_attributes.emplace(name, Variant());
 		OnAttributeChange(changed_attributes);
 	}
 }
@@ -963,17 +962,13 @@ Context* Element::GetContext() const
 }
 
 // Set a group of attributes
-void Element::SetAttributes(const ElementAttributes* _attributes)
+void Element::SetAttributes(const ElementAttributes& _attributes)
 {
-	attributes.reserve(attributes.size() + _attributes->size());
-	for (auto& pair : *_attributes)
+	attributes.reserve(attributes.size() + _attributes.size());
+	for (auto& pair : _attributes)
 		attributes[pair.first] = pair.second;
 
-	AttributeNameList changed_attributes;
-	changed_attributes.reserve(_attributes->size());
-	for (auto& pair : *_attributes)
-		changed_attributes.insert(pair.first);
-	OnAttributeChange(changed_attributes);
+	OnAttributeChange(_attributes);
 }
 
 // Returns the number of attributes on the element.
@@ -1689,25 +1684,28 @@ void Element::OnLayout()
 }
 
 // Called when attributes on the element are changed.
-void Element::OnAttributeChange(const AttributeNameList& changed_attributes)
+void Element::OnAttributeChange(const ElementAttributes& changed_attributes)
 {
-	if (changed_attributes.find("id") != changed_attributes.end())
+	auto it = changed_attributes.find("id");
+	if (it != changed_attributes.end())
 	{
-		id = GetAttribute< String >("id", "");
+		id = it->second.Get<String>();
 		style->DirtyDefinition();
 	}
 
-	if (changed_attributes.find("class") != changed_attributes.end())
+	it = changed_attributes.find("class");
+	if (it != changed_attributes.end())
 	{
-		style->SetClassNames(GetAttribute< String >("class", ""));
+		style->SetClassNames(it->second.Get<String>());
 	}
 
 	// Add any inline style declarations.
-	if (changed_attributes.find("style") != changed_attributes.end())
+	it = changed_attributes.find("style");
+	if (it != changed_attributes.end())
 	{
 		PropertyDictionary properties;
 		StyleSheetParser parser;
-		parser.ParseProperties(properties, GetAttribute< String >("style", ""));
+		parser.ParseProperties(properties, it->second.Get<String>());
 
 		Rocket::Core::PropertyMap property_map = properties.GetProperties();
 		for (Rocket::Core::PropertyMap::iterator i = property_map.begin(); i != property_map.end(); ++i)

+ 1 - 1
Source/Core/ElementHandle.cpp

@@ -49,7 +49,7 @@ ElementHandle::~ElementHandle()
 {
 }
 
-void ElementHandle::OnAttributeChange(const AttributeNameList& changed_attributes)
+void ElementHandle::OnAttributeChange(const ElementAttributes& changed_attributes)
 {
 	Element::OnAttributeChange(changed_attributes);
 

+ 1 - 1
Source/Core/ElementHandle.h

@@ -49,7 +49,7 @@ public:
 	virtual ~ElementHandle();
 
 protected:
-	virtual void OnAttributeChange(const AttributeNameList& changed_attributes) override;
+	virtual void OnAttributeChange(const ElementAttributes& changed_attributes) override;
 	virtual void ProcessDefaultAction(Event& event) override;
 
 	Vector2i drag_start;

+ 1 - 1
Source/Core/ElementImage.cpp

@@ -88,7 +88,7 @@ void ElementImage::OnRender()
 }
 
 // Called when attributes on the element are changed.
-void ElementImage::OnAttributeChange(const Rocket::Core::AttributeNameList& changed_attributes)
+void ElementImage::OnAttributeChange(const Rocket::Core::ElementAttributes& changed_attributes)
 {
 	// Call through to the base element's OnAttributeChange().
 	Rocket::Core::Element::OnAttributeChange(changed_attributes);

+ 2 - 2
Source/Core/ElementImage.h

@@ -78,14 +78,14 @@ public:
 
 protected:
 	/// Renders the image.
-	virtual void OnRender();
+	virtual void OnRender() override;
 
 	/// Regenerates the element's geometry.
 	virtual void OnResize() override;
 
 	/// Checks for changes to the image's source or dimensions.
 	/// @param[in] changed_attributes A list of attributes changed on the element.
-	virtual void OnAttributeChange(const AttributeNameList& changed_attributes) override;
+	virtual void OnAttributeChange(const ElementAttributes& changed_attributes) override;
 
 	/// Called when properties on the element are changed.
 	/// @param[in] changed_properties The properties changed on the element.

+ 1 - 1
Source/Core/Factory.cpp

@@ -218,7 +218,7 @@ Element* Factory::InstanceElement(Element* parent, const String& instancer_name,
 		if (element)
 		{
 			element->SetInstancer(instancer);
-			element->SetAttributes(&attributes);
+			element->SetAttributes(attributes);
 			ElementUtilities::BindEventAttributes(element);
 
 			PluginRegistry::NotifyElementCreate(element);

+ 1 - 1
Source/Core/XMLNodeHandlerBody.cpp

@@ -58,7 +58,7 @@ Element* XMLNodeHandlerBody::ElementStart(XMLParser* parser, const String& ROCKE
 	// Apply any attributes to the document
 	ElementDocument* document = parser->GetParseFrame()->element->GetOwnerDocument();
 	if (document)
-		document->SetAttributes(&attributes);
+		document->SetAttributes(attributes);
 
 	// Tell the parser to use the element handler for all children
 	parser->PushDefaultHandler();