//--------------------------------------
//               PowerUI
//
//        For documentation or 
//    if you have any issues, visit
//        powerUI.kulestar.com
//
//    Copyright  2013 Kulestar Ltd
//          www.kulestar.com
//--------------------------------------

using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Css{

	/// <summary>
	/// Contains methods for interacting with a CSS class applied to the computed style.
	/// </summary>

	public partial class ComputedStyle{
		
		/// <summary>This is called to change a CSS property from an element.
		/// For example, font color=".." uses this. It sets a specifity of 0 as required by 
		/// https://www.w3.org/TR/CSS2/cascade.html 6.4.4</summary>
		/// <param name="cssProperty">The css property being changed.</param>
		/// <param name="newValue">The new property value.</param>
		public void ChangeTagProperty(string cssProperty,Css.Value newValue,bool requestLayout){
			
			// Resolve the property:
			CssProperty property=CssProperties.Get(cssProperty);
			
			if(property==null){
				return;
			}
			
			Renderman rm=(Element.document as Css.ReflowDocument).Renderer;
			
			bool layoutState=rm.DoLayout;
			
			// Apply now:
			ChangeProperty(property,newValue);
			
			// Restore layout state:
			if(!requestLayout){
				rm.DoLayout=layoutState;
			}
			
		}
		
		/// <summary>This is called to change a CSS property from an element.
		/// For example, font color=".." uses this. It sets a specifity of 0 as required by 
		/// https://www.w3.org/TR/CSS2/cascade.html 6.4.4</summary>
		/// <param name="cssProperty">The css property being changed.</param>
		/// <param name="newValue">The new property value.</param>
		public void ChangeTagProperty(string cssProperty,Css.Value newValue){
			
			// Resolve the property:
			CssProperty property=CssProperties.Get(cssProperty);
			
			if(property==null){
				return;
			}
			
			// Apply now:
			ChangeProperty(property,newValue);
			
		}
		
		/// <summary>This is called to change a CSS property from an element.
		/// For example, font color=".." uses this. It sets a specifity of 0 as required by 
		/// https://www.w3.org/TR/CSS2/cascade.html 6.4.4</summary>
		/// <param name="cssProperty">The css property being changed.</param>
		/// <param name="newValue">The new property value.</param>
		public Css.Value ChangeTagProperty(string cssProperty,string newValue){
			
			// Resolve the property:
			CssProperty property=CssProperties.Get(cssProperty);
			
			if(property==null){
				return null;
			}
			
			Css.Value val=Css.Value.Load(newValue);
			
			// Apply now:
			ChangeProperty(property,val);
			
			return val;
			
		}
		
	}
	
}