/// niklas@protocol7.com
/// 100
///
using System;
using System.Text.RegularExpressions;
namespace SharpVectors.Dom.Css
{
///
/// The Rect interface is used to represent any rect value. This interface reflects the values in the underlying style property. Hence, modifications made to the CSSPrimitiveValue objects modify the style property.
///
public sealed class CssRect : ICssRect
{
#region Private Fields
private static Regex delim = new Regex(@"\s+,?\s*|,\s*", RegexOptions.Compiled);
private bool readOnly;
#endregion
#region Constructors
///
/// Constructs a new Rect
///
/// The string to parse that contains the Rect structure
/// Specifies if the Rect should be read-only
public CssRect(string rectString, bool readOnly)
{
this.readOnly = readOnly;
if (rectString == null)
{
rectString = String.Empty;
}
// remove leading and trailing whitespace
// NOTE: Need to check if .NET whitespace = SVG (XML) whitespace
rectString = rectString.Trim();
if (rectString.Length > 0)
{
string[] parts = rectString.Split(' ');
if (parts.Length != 4)
{
parts = delim.Split(rectString);
}
if (parts.Length == 4)
{
_top = new CssPrimitiveLengthValue(parts[0], readOnly);
_right = new CssPrimitiveLengthValue(parts[1], readOnly);
_bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
_left = new CssPrimitiveLengthValue(parts[3], readOnly);
}
else
{
throw new DomException(DomExceptionType.SyntaxErr);
}
}
}
#endregion
#region IRect Members
private CssPrimitiveValue _left;
///
/// This attribute is used for the left of the rect.
///
public ICssPrimitiveValue Left
{
get
{
return _left;
}
}
private CssPrimitiveValue _bottom;
///
/// This attribute is used for the bottom of the rect.
///
public ICssPrimitiveValue Bottom
{
get
{
return _bottom;
}
}
private CssPrimitiveValue _right;
///
/// This attribute is used for the right of the rect.
///
public ICssPrimitiveValue Right
{
get
{
return _right;
}
}
private CssPrimitiveValue _top;
///
/// This attribute is used for the top of the rect.
///
public ICssPrimitiveValue Top
{
get
{
return _top;
}
}
#endregion
}
}