From c7e822557f7433e5d2ae15bbc63ccc9e019bc623 Mon Sep 17 00:00:00 2001 From: Julien Dramaix Date: Tue, 1 Mar 2011 13:32:07 +0000 Subject: [PATCH] margin and padding shorthand properties can be defined with either one, two, three or four Length --- .../gwt/query/client/css/MarginProperty.java | 33 +++++++++++++- .../gwt/query/client/css/PaddingProperty.java | 44 ++++++++++++++++--- .../gwt/query/client/GQueryCssTest.java | 21 ++++++--- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java index 9b2af0e6..ecc8ba4a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java @@ -27,14 +27,43 @@ public class MarginProperty extends CssProperty { private ShorthandMarginProperty() { } + public String getCssName() { + return MARGIN_PROPERTY; + } + public String getCssValue(Style s) { return s.getMargin(); } - public String getCssName() { - return MARGIN_PROPERTY; + /** + * Apply the same margin to all sides + */ + public CssSetter with(Length margin) { + return new MultipleValueCssSetter(getCssName(), margin); + + } + + /** + * The top and bottom margins are set to the first value and the right and + * left margins are set to the second + */ + public CssSetter with(Length topAndBottom, Length leftAndRight) { + return new MultipleValueCssSetter(getCssName(), topAndBottom, leftAndRight); + + } + + /** + * The top margin is set to the first value, the left and right margins are + * set to the second, and the bottom margin is set to the third + */ + public CssSetter with(Length top, Length leftAndRight, Length bottom) { + return new MultipleValueCssSetter(getCssName(), top, leftAndRight, bottom); + } + /** + * Apply the margin to all sides. + */ public CssSetter with(Length margin1, Length margin2, Length margin3, Length margin4) { return new MultipleValueCssSetter(getCssName(), margin1, margin2, diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java index 9eb5c9e5..e594fdb1 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java @@ -28,19 +28,49 @@ public class PaddingProperty extends CssProperty { private ShorthandPaddingProperty() { } - public CssSetter with(Length padding1, Length padding2, Length padding3, - Length padding4) { - return new MultipleValueCssSetter(getCssName(), padding1, padding2, - padding3, padding4); - + public String getCssName() { + return PADDING_PROPERTY; } public String getCssValue(Style s) { return s.getPadding(); } - public String getCssName() { - return PADDING_PROPERTY; + /** + * Apply the same padding to all sides + */ + public CssSetter with(Length padding) { + return new MultipleValueCssSetter(getCssName(), padding); + + } + + /** + * The top and bottom paddings are set to the first value and the right and + * left paddings are set to the second + */ + public CssSetter with(Length topAndBottom, Length leftAndRight) { + return new MultipleValueCssSetter(getCssName(), topAndBottom, + leftAndRight); + + } + + /** + * The top padding is set to the first value, the left and right paddings + * are set to the second, and the bottom padding is set to the third + */ + public CssSetter with(Length top, Length leftAndRight, Length bottom) { + return new MultipleValueCssSetter(getCssName(), top, leftAndRight, bottom); + + } + + /** + * Apply padding to all sides. + */ + public CssSetter with(Length padding1, Length padding2, Length padding3, + Length padding4) { + return new MultipleValueCssSetter(getCssName(), padding1, padding2, + padding3, padding4); + } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java index f22b2bb4..79627094 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java @@ -784,12 +784,17 @@ public class GQueryCssTest extends GWTTestCase { $(e).html("
Content
"); - $("#test").css(CSS.MARGIN.with(Length.px(10), Length.px(20), null, null)); + $("#test").css(CSS.MARGIN.with(Length.px(10), Length.px(20))); assertEquals("10px 20px", $("#test").css("margin")); assertEquals("10px 20px", $("#test").css(CSS.MARGIN)); + + $("#test").css(CSS.MARGIN.with(Length.px(10), Length.px(20), Length.px(30))); + + assertEquals("10px 20px 30px", $("#test").css("margin")); + assertEquals("10px 20px 30px", $("#test").css(CSS.MARGIN)); - $("#test").css(CSS.MARGIN.with(Length.px(10), null, null, null)); + $("#test").css(CSS.MARGIN.with(Length.px(10))); assertEquals("10px", $("#test").css("margin")); assertEquals("10px", $("#test").css(CSS.MARGIN)); @@ -874,19 +879,19 @@ public class GQueryCssTest extends GWTTestCase { $(e).html("
Content
"); - $("#test").css(CSS.PADDING.with(Length.px(10), null, null, null)); + $("#test").css(CSS.PADDING.with(Length.px(10))); assertEquals("10px", $("#test").css("padding")); assertEquals("10px", $("#test").css(CSS.PADDING)); $("#test").css( - CSS.PADDING.with(Length.px(10), Length.px(20), null, null)); + CSS.PADDING.with(Length.px(10), Length.px(20))); assertEquals("10px 20px", $("#test").css("padding")); assertEquals("10px 20px", $("#test").css(CSS.PADDING)); $("#test").css( - CSS.PADDING.with(Length.px(10), Length.px(20), Length.px(30), null)); + CSS.PADDING.with(Length.px(10), Length.px(20), Length.px(30))); assertEquals("10px 20px 30px", $("#test").css("padding")); assertEquals("10px 20px 30px", $("#test").css(CSS.PADDING)); @@ -1016,7 +1021,11 @@ public class GQueryCssTest extends GWTTestCase { public void testVerticalAlignProperty() { $(e).html("
Content
"); - + + $("#test").css(CSS.VERTICAL_ALIGN.with(Length.px(120))); + assertEquals("120px", $("#test").css("verticalAlign")); + assertEquals("120px", $("#test").css(CSS.VERTICAL_ALIGN)); + $("#test").css(CSS.VERTICAL_ALIGN.with(VerticalAlign.BASELINE)); assertEquals("baseline", $("#test").css("verticalAlign")); assertEquals("baseline", $("#test").css(CSS.VERTICAL_ALIGN)); -- 2.39.5