From 14338781effcdd0d292bf5997e929b49badc86fb Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 2 Aug 2013 23:11:51 +0900 Subject: [PATCH] Add clear --- complete.rs | 4 ++++ computed.rs | 14 ++++++++++++++ test.rs | 8 ++++++++ values.rs | 8 ++++++++ 4 files changed, 34 insertions(+) diff --git a/complete.rs b/complete.rs index 9e9ead3..1788a65 100644 --- a/complete.rs +++ b/complete.rs @@ -175,6 +175,10 @@ impl<'self> CompleteStyle<'self> { strip(self.inner.float()) } + pub fn clear(&self) -> CSSClear { + strip(self.inner.clear()) + } + // CSS 2.1, Section 10 - Visual formatting model details pub fn width(&self) -> CSSWidth { diff --git a/computed.rs b/computed.rs index 26dd5e9..e4a1fb6 100644 --- a/computed.rs +++ b/computed.rs @@ -95,6 +95,10 @@ impl<'self> ComputedStyle<'self> { convert_net_float_value(self.inner.float()) } + pub fn clear(&self) -> CSSValue { + convert_net_clear_value(self.inner.clear()) + } + // CSS 2.1, Section 10 - Visual formatting model details pub fn width(&self) -> CSSValue { @@ -266,6 +270,16 @@ fn convert_net_float_value(value: n::v::CssFloatValue) -> CSSValue { } } +fn convert_net_clear_value(value: n::v::CssClearValue) -> CSSValue { + match value { + n::v::CssClearInherit => Inherit, + n::v::CssClearNone => Specified(CSSClearNone), + n::v::CssClearLeft => Specified(CSSClearLeft), + n::v::CssClearRight => Specified(CSSClearRight), + n::v::CssClearBoth => Specified(CSSClearBoth) + } +} + fn convert_net_position_value(value: n::v::CssPositionValue) -> CSSValue { match value { n::v::CssPositionInherit => Inherit, diff --git a/test.rs b/test.rs index e0fcd9b..43b351e 100644 --- a/test.rs +++ b/test.rs @@ -266,6 +266,14 @@ fn test_float() { } } +#[test] +fn test_clear() { + let style = "div { clear: both; }"; + do single_div_test(style) |computed| { + assert!(computed.clear() == Specified(CSSClearBoth)); + } +} + #[test] fn test_position() { let style = "div { position: static; }"; diff --git a/values.rs b/values.rs index 82042f3..4a89af9 100644 --- a/values.rs +++ b/values.rs @@ -136,6 +136,14 @@ pub enum CSSFloat { CSSFloatNone } +#[deriving(Eq)] +pub enum CSSClear { + CSSClearLeft, + CSSClearRight, + CSSClearBoth, + CSSClearNone +} + #[deriving(Eq)] pub enum CSSDirection { CSSDirectionLtr,