From 8a45280e017a8724e8b49e4f5327512c3878d184 Mon Sep 17 00:00:00 2001 From: Julien Dramaix Date: Thu, 27 Jan 2011 00:13:16 +0000 Subject: [PATCH] Refactoring of CSS part of GQuery. Add implementation of many css properties --- .../com/google/gwt/query/client/GQuery.java | 111 ++- .../google/gwt/query/client/LazyGQuery.java | 81 +- .../query/client/css/AbstractCssProperty.java | 38 + .../client/css/BackgroundAttachment.java | 72 -- .../css/BackgroundAttachmentProperty.java | 64 ++ ...olor.java => BackgroundColorProperty.java} | 15 +- .../client/css/BackgroundImageProperty.java | 36 + .../css/BackgroundPositionProperty.java | 99 +++ .../query/client/css/BackgroundProperty.java | 66 ++ .../client/css/BackgroundRepeatProperty.java | 97 +++ .../query/client/css/BorderColorProperty.java | 48 ++ .../gwt/query/client/css/BorderProperty.java | 62 ++ .../query/client/css/BorderStyleProperty.java | 122 +++ .../query/client/css/BorderWidthProperty.java | 93 +++ .../com/google/gwt/query/client/css/CSS.java | 510 +++---------- .../css/{Color.java => ColorProperty.java} | 18 +- .../gwt/query/client/css/CssProperty.java | 17 +- ...entage.java => CssShorthandProperty3.java} | 8 +- ...perty4.java => CssShorthandProperty5.java} | 8 +- .../google/gwt/query/client/css/Cursor.java | 94 --- .../gwt/query/client/css/CursorProperty.java | 37 + .../google/gwt/query/client/css/Display.java | 84 --- .../gwt/query/client/css/DisplayProperty.java | 37 + .../google/gwt/query/client/css/Float.java | 73 -- .../gwt/query/client/css/FloatProperty.java | 45 ++ .../query/client/css/FontSizeProperty.java | 144 ++++ .../query/client/css/FontStyleProperty.java | 37 + .../query/client/css/FontVariantProperty.java | 73 ++ .../query/client/css/FontWeightProperty.java | 37 + .../css/{Height.java => HeightProperty.java} | 26 +- .../gwt/query/client/css/ImageValue.java | 47 ++ .../google/gwt/query/client/css/Inherit.java | 52 -- .../google/gwt/query/client/css/Length.java | 79 +- .../client/css/ListStyleImageProperty.java | 35 + .../client/css/ListStylePositionProperty.java | 76 ++ .../query/client/css/ListStyleProperty.java | 60 ++ .../client/css/ListStyleTypeProperty.java | 37 + .../gwt/query/client/css/MarginProperty.java | 47 ++ .../gwt/query/client/css/PaddingProperty.java | 48 ++ .../gwt/query/client/css/Percentage.java | 56 -- .../google/gwt/query/client/css/RGBColor.java | 97 +-- .../gwt/query/client/css/TakeCssValue.java | 32 + .../gwt/query/client/css/TakesLength.java | 6 +- .../gwt/query/client/css/TextAlign.java | 72 -- .../query/client/css/TextAlignProperty.java | 87 +++ .../gwt/query/client/css/VerticalAlign.java | 88 --- .../client/css/VerticalAlignProperty.java | 45 ++ .../gwt/query/client/css/Visibility.java | 74 -- .../query/client/css/VisibilityProperty.java | 40 + .../css/{Width.java => WidthProperty.java} | 26 +- .../gwt/query/client/GQueryCssTest.java | 708 ++++++++++++++++++ .../gwt/query/client/GQueryEventsTest.java | 3 +- 52 files changed, 2815 insertions(+), 1252 deletions(-) create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/AbstractCssProperty.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachment.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java rename gwtquery-core/src/main/java/com/google/gwt/query/client/css/{BackgroundColor.java => BackgroundColorProperty.java} (72%) create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderColorProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java rename gwtquery-core/src/main/java/com/google/gwt/query/client/css/{Color.java => ColorProperty.java} (72%) rename gwtquery-core/src/main/java/com/google/gwt/query/client/css/{TakesPercentage.java => CssShorthandProperty3.java} (79%) rename gwtquery-core/src/main/java/com/google/gwt/query/client/css/{CssProperty4.java => CssShorthandProperty5.java} (76%) delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/Cursor.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/Display.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/DisplayProperty.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/Float.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/FloatProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontSizeProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontStyleProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontVariantProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontWeightProperty.java rename gwtquery-core/src/main/java/com/google/gwt/query/client/css/{Height.java => HeightProperty.java} (66%) create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/ImageValue.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/Inherit.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleImageProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleTypeProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/Percentage.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakeCssValue.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlign.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlign.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/Visibility.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java rename gwtquery-core/src/main/java/com/google/gwt/query/client/css/{Width.java => WidthProperty.java} (73%) create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 0b64490a..ce6dc7f3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -19,11 +19,6 @@ import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.plugins.Events.Events; import static com.google.gwt.query.client.plugins.Widgets.Widgets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; @@ -38,13 +33,14 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.Style.Display; import com.google.gwt.dom.client.TextAreaElement; +import com.google.gwt.dom.client.Style.Display; import com.google.gwt.query.client.css.CssProperty; +import com.google.gwt.query.client.css.CssShorthandProperty3; +import com.google.gwt.query.client.css.CssShorthandProperty5; import com.google.gwt.query.client.css.Length; -import com.google.gwt.query.client.css.Percentage; +import com.google.gwt.query.client.css.TakeCssValue; import com.google.gwt.query.client.css.TakesLength; -import com.google.gwt.query.client.css.TakesPercentage; import com.google.gwt.query.client.impl.DocumentStyleImpl; import com.google.gwt.query.client.plugins.EventsListener; import com.google.gwt.user.client.DOM; @@ -53,6 +49,11 @@ import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + /** * GwtQuery is a GWT clone of the popular jQuery library. */ @@ -943,6 +944,34 @@ public class GQuery implements Lazy { public String css(String name) { return styleImpl.curCSS(get(0), name, false); } + + /** + * Return a style property on the first matched element using type-safe + * enumerations. + * + * Ex : $("#myId").css(CSS.BACKGROUND_COLOR); + */ + public String css(CssProperty property) { + return css(property, false); + } + + /** + * Return a style property on the first matched element using type-safe + * enumerations. + * + * The parameter force has a special meaning here: - When force is false, + * returns the value of the css property defined in the style attribute of the + * element. - Otherwise it returns the real computed value. + * + * For instance if you define 'display=none' not in the element style but in + * the css stylesheet, it returns an empty string unless you pass the + * parameter force=true. + * + * Ex : $("#myId").css(CSS.WIDTH, true); + */ + public String css(CssProperty property, boolean force) { + return css(property.getCssName(), force); + } /** * Return a style property on the first matched element. @@ -971,9 +1000,10 @@ public class GQuery implements Lazy { } /** - * Set CSS property on every matched element using type-safe enumerations. + * Set CSS a single style property on every matched element using type-safe + * enumerations. */ - public > GQuery css(T cssProperty, S value) { + public > GQuery css(T cssProperty, S value) { for (Element e : elements()) { cssProperty.set(e.getStyle(), value); } @@ -981,25 +1011,43 @@ public class GQuery implements Lazy { } /** - * Set CSS property on every matched element using type-safe enumerations. + * Set CSS a single style property on every matched element using type-safe + * enumerations. */ public GQuery css(TakesLength cssProperty, Length value) { for (Element e : elements()) { - cssProperty.setLength(e.getStyle(), value); + cssProperty.set(e.getStyle(), value); } return this; } /** - * Set CSS property on every matched element using type-safe enumerations. + * Set a multiple style property on every matched element using type-safe + * enumerations. ex : $("#id").css(CSS.BORDER, BorderWidth.thick(), + * BorderStyle.DASHED, RGBColor.BLACK); */ - public GQuery css(TakesPercentage cssProperty, Percentage value) { + public > GQuery css( + T cssProperty, X value1, Y value2, Z value3) { for (Element e : elements()) { - cssProperty.setPercentage(e.getStyle(), value); + cssProperty.set(e.getStyle(), value1, value2, value3); } return this; } - + + /** + * Set a multiple style property on every matched element using type-safe + * enumerations. ex : $("#id").css(CSS.BACKGROUND, RGBColor.TRANSPARENT, + * BackgroundImage.url("back.jpg"), BackgroundRepeat.NO_REPEAT, + * BackgroundAttachment.SCROLL, BackgroundPosition.CENTER); + */ + public > GQuery css( + T cssProperty, V value1, W value2, X value3, Y value4, Z value5) { + for (Element e : elements()) { + cssProperty.set(e.getStyle(), value1, value2, value3, value4, value5); + } + return this; + } + /** * Returns the numeric value of a css property. */ @@ -2170,7 +2218,7 @@ public class GQuery implements Lazy { /** * Set CSS property on the first element. */ - public > GQuery setCss(T cssProperty, S value) { + public > GQuery setCss(T cssProperty, S value) { cssProperty.set(elements.getItem(0).getStyle(), value); return this; } @@ -2179,15 +2227,36 @@ public class GQuery implements Lazy { * Set CSS property on first matched element using type-safe enumerations. */ public GQuery setCss(TakesLength cssProperty, Length value) { - cssProperty.setLength(elements.getItem(0).getStyle(), value); + cssProperty.set(elements.getItem(0).getStyle(), value); return this; } /** - * Set CSS property on first matched element using type-safe enumerations. + * Set a multiple style property on first matched element using type-safe + * enumerations. + * + * ex : $("#id").css(CSS.BORDER, BorderWidth.thick(), BorderStyle.DASHED, + * RGBColor.BLACK); */ - public GQuery setCss(TakesPercentage cssProperty, Percentage value) { - cssProperty.setPercentage(elements.getItem(0).getStyle(), value); + public > GQuery setCss( + T cssProperty, X value1, Y value2, Z value3) { + cssProperty.set(get(0).getStyle(), value1, value2, value3); + + return this; + } + + /** + * Set a multiple style property on first matched element using type-safe + * enumerations. + * + * ex : $("#id").css(CSS.BACKGROUND, RGBColor.TRANSPARENT, + * BackgroundImage.url("back.jpg"), BackgroundRepeat.NO_REPEAT, + * BackgroundAttachment.SCROLL, BackgroundPosition.CENTER); + */ + public > GQuery setCss( + T cssProperty, V value1, W value2, X value3, Y value4, Z value5) { + cssProperty.set(get(0).getStyle(), value1, value2, value3, value4, value5); + return this; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 53b19a47..f3cbbca5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -17,10 +17,6 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.plugins.Events.Events; import static com.google.gwt.query.client.plugins.Widgets.Widgets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; @@ -35,13 +31,14 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.Style.Display; import com.google.gwt.dom.client.TextAreaElement; +import com.google.gwt.dom.client.Style.Display; import com.google.gwt.query.client.css.CssProperty; +import com.google.gwt.query.client.css.CssShorthandProperty3; +import com.google.gwt.query.client.css.CssShorthandProperty5; import com.google.gwt.query.client.css.Length; -import com.google.gwt.query.client.css.Percentage; +import com.google.gwt.query.client.css.TakeCssValue; import com.google.gwt.query.client.css.TakesLength; -import com.google.gwt.query.client.css.TakesPercentage; import com.google.gwt.query.client.impl.DocumentStyleImpl; import com.google.gwt.query.client.plugins.EventsListener; import com.google.gwt.user.client.DOM; @@ -49,6 +46,10 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; import com.google.gwt.query.client.LazyBase; public interface LazyGQuery extends LazyBase{ @@ -292,6 +293,30 @@ public interface LazyGQuery extends LazyBase{ */ String css(String name); + /** + * Return a style property on the first matched element using type-safe + * enumerations. + * + * Ex : $("#myId").css(CSS.BACKGROUND_COLOR); + */ + String css(CssProperty property); + + /** + * Return a style property on the first matched element using type-safe + * enumerations. + * + * The parameter force has a special meaning here: - When force is false, + * returns the value of the css property defined in the style attribute of the + * element. - Otherwise it returns the real computed value. + * + * For instance if you define 'display=none' not in the element style but in + * the css stylesheet, it returns an empty string unless you pass the + * parameter force=true. + * + * Ex : $("#myId").css(CSS.WIDTH, true); + */ + String css(CssProperty property, boolean force); + /** * Return a style property on the first matched element. * @@ -312,19 +337,31 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery css(String prop, String val); /** - * Set CSS property on every matched element using type-safe enumerations. + * Set CSS a single style property on every matched element using type-safe + * enumerations. */ - > LazyGQuery css(T cssProperty, S value); + > LazyGQuery css(T cssProperty, S value); /** - * Set CSS property on every matched element using type-safe enumerations. + * Set CSS a single style property on every matched element using type-safe + * enumerations. */ LazyGQuery css(TakesLength cssProperty, Length value); /** - * Set CSS property on every matched element using type-safe enumerations. + * Set a multiple style property on every matched element using type-safe + * enumerations. ex : $("#id").css(CSS.BORDER, BorderWidth.thick(), + * BorderStyle.DASHED, RGBColor.BLACK); + */ + > LazyGQuery css( T cssProperty, X value1, Y value2, Z value3); + + /** + * Set a multiple style property on every matched element using type-safe + * enumerations. ex : $("#id").css(CSS.BACKGROUND, RGBColor.TRANSPARENT, + * BackgroundImage.url("back.jpg"), BackgroundRepeat.NO_REPEAT, + * BackgroundAttachment.SCROLL, BackgroundPosition.CENTER); */ - LazyGQuery css(TakesPercentage cssProperty, Percentage value); + > LazyGQuery css( T cssProperty, V value1, W value2, X value3, Y value4, Z value5); /** * Returns the numeric value of a css property. @@ -1013,7 +1050,7 @@ public interface LazyGQuery extends LazyBase{ /** * Set CSS property on the first element. */ - > LazyGQuery setCss(T cssProperty, S value); + > LazyGQuery setCss(T cssProperty, S value); /** * Set CSS property on first matched element using type-safe enumerations. @@ -1021,9 +1058,23 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery setCss(TakesLength cssProperty, Length value); /** - * Set CSS property on first matched element using type-safe enumerations. + * Set a multiple style property on first matched element using type-safe + * enumerations. + * + * ex : $("#id").css(CSS.BORDER, BorderWidth.thick(), BorderStyle.DASHED, + * RGBColor.BLACK); + */ + > LazyGQuery setCss( T cssProperty, X value1, Y value2, Z value3); + + /** + * Set a multiple style property on first matched element using type-safe + * enumerations. + * + * ex : $("#id").css(CSS.BACKGROUND, RGBColor.TRANSPARENT, + * BackgroundImage.url("back.jpg"), BackgroundRepeat.NO_REPEAT, + * BackgroundAttachment.SCROLL, BackgroundPosition.CENTER); */ - LazyGQuery setCss(TakesPercentage cssProperty, Percentage value); + > LazyGQuery setCss( T cssProperty, V value1, W value2, X value3, Y value4, Z value5); void setPreviousObject(GQuery previousObject); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/AbstractCssProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/AbstractCssProperty.java new file mode 100644 index 00000000..06e79fa4 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/AbstractCssProperty.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * Base class for Css property + * + * @param Class of the value associated with the css property + */ +public abstract class AbstractCssProperty implements + TakeCssValue { + + public String get(Style s) { + return s.getProperty(getCssName()); + } + + public abstract String getCssName(); + + public void set(Style s, T value) { + s.setProperty(getCssName(), value.getCssName()); + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachment.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachment.java deleted file mode 100644 index 76748b9f..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachment.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; - -/** - * This property affects the vertical positioning inside a line box of the boxes - * generated by an inline-level element. - */ -public class BackgroundAttachment - implements CssProperty { - - public static void init() { - CSS.BACKGROUND_ATTACHMENT = new BackgroundAttachment(); - CSS.FIXED = AttachValue.create("fixed"); - CSS.SCROLL = AttachValue.create("scroll"); - } - - public void set(Style s, AttachValue value) { - s.setProperty("backgroundAttachment", value.value()); - } - - public String get(Style s) { - return s.getProperty("backgroundAttachment"); - } - - final static public class AttachValue extends JavaScriptObject { - - protected AttachValue() { - } - - protected static AttachValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private static native AttachValue createWeb(String val) /*-{ - return val; - }-*/; - - private static native AttachValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java new file mode 100644 index 00000000..7974efe2 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java @@ -0,0 +1,64 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * This property affects the vertical positioning inside a line box of the boxes + * generated by an inline-level element. + */ +public class BackgroundAttachmentProperty extends + AbstractCssProperty { + + public static enum BackgroundAttachment implements HasCssName { + /** + * Background image is fixed. + */ + FIXED { + @Override + public String getCssName() { + return FIXED_VALUE; + } + }, + /** + * Background image scrolls when viewport is scrolled. + */ + SCROLL { + @Override + public String getCssName() { + return SCROLL_VALUE; + } + }; + + public abstract String getCssName(); + + } + private static final String CSS_PROPERTY = "backgroundAttachment"; + private static final String FIXED_VALUE = "fixed"; + + private static final String SCROLL_VALUE = "scroll"; + + public static void init() { + CSS.BACKGROUND_ATTACHMENT = new BackgroundAttachmentProperty(); + } + + private BackgroundAttachmentProperty() {} + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundColor.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundColorProperty.java similarity index 72% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundColor.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundColorProperty.java index 484fcb2d..e9359506 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundColor.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundColorProperty.java @@ -15,23 +15,22 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.dom.client.Style; - /** * This property sets the background color of an element, either a value * or the keyword 'transparent', to make the underlying colors shine through. */ -public class BackgroundColor implements CssProperty { +public class BackgroundColorProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "backgroundColor"; public static void init() { - CSS.BACKGROUND_COLOR = new BackgroundColor(); + CSS.BACKGROUND_COLOR = new BackgroundColorProperty(); } - public void set(Style s, RGBColor value) { - s.setProperty("backgroundColor", value.value()); + private BackgroundColorProperty() { } - public String get(Style s) { - return s.getProperty("backgroundColor"); + public String getCssName() { + return CSS_PROPERTY; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java new file mode 100644 index 00000000..11c97263 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java @@ -0,0 +1,36 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +/** + * This property sets the background image of an element, + */ +public class BackgroundImageProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "backgroundImage"; + + public static void init() { + CSS.BACKGROUND_IMAGE = new BackgroundImageProperty(); + } + + private BackgroundImageProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java new file mode 100644 index 00000000..b5733160 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java @@ -0,0 +1,99 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import static com.google.gwt.query.client.css.CSS.INHERIT_VALUE; + +import com.google.gwt.dom.client.Style.HasCssName; +import com.google.gwt.dom.client.Style.Unit; + +/** + * The {@link BackgroundPositionProperty} define the position of a + * background-image. + */ +public class BackgroundPositionProperty extends + AbstractCssProperty { + + public static class BackgroundPosition implements HasCssName { + public static BackgroundPosition CENTER; + public static BackgroundPosition CENTER_BOTTOM; + public static BackgroundPosition CENTER_CENTER; + public static BackgroundPosition CENTER_TOP; + public static BackgroundPosition INHERIT; + public static BackgroundPosition LEFT; + public static BackgroundPosition LEFT_BOTTOM; + public static BackgroundPosition LEFT_CENTER; + public static BackgroundPosition LEFT_TOP; + public static BackgroundPosition RIGHT; + public static BackgroundPosition RIGHT_BOTTOM; + public static BackgroundPosition RIGHT_CENTER; + public static BackgroundPosition RIGHT_TOP; + + private static final String BOTTOM_VALUE = "bottom"; + private static final String CENTER_VALUE = "center"; + private static final String LEFT_VALUE = "left"; + private static final String RIGHT_VALUE = "right"; + private static final String TOP_VALUE = "top"; + + static { + + CENTER_BOTTOM = new BackgroundPosition(CENTER_VALUE + " " + BOTTOM_VALUE); + CENTER_CENTER = new BackgroundPosition(CENTER_VALUE + " " + CENTER_VALUE); + CENTER = new BackgroundPosition(CENTER_VALUE); + CENTER_TOP = new BackgroundPosition(CENTER_VALUE + " " + TOP_VALUE); + LEFT_BOTTOM = new BackgroundPosition(LEFT_VALUE + " " + BOTTOM_VALUE); + LEFT_CENTER = new BackgroundPosition(LEFT_VALUE + " " + CENTER_VALUE); + LEFT = new BackgroundPosition(LEFT_VALUE); + LEFT_TOP = new BackgroundPosition(LEFT_VALUE + " " + TOP_VALUE); + RIGHT_BOTTOM = new BackgroundPosition(RIGHT_VALUE + " " + BOTTOM_VALUE); + RIGHT_CENTER = new BackgroundPosition(RIGHT_VALUE + " " + CENTER_VALUE); + RIGHT = new BackgroundPosition(RIGHT_VALUE); + RIGHT_TOP = new BackgroundPosition(RIGHT_VALUE + " " + TOP_VALUE); + INHERIT = new BackgroundPosition(INHERIT_VALUE); + } + + public static BackgroundPosition position(int xpos, int ypos, Unit unit) { + if (unit == null) { + unit = Unit.PX; + } + return new BackgroundPosition("" + xpos + unit.getType() + " " + ypos + + unit.getType()); + } + + private String cssValue; + + private BackgroundPosition(String cssValue) { + this.cssValue = cssValue; + } + + public String getCssName() { + return cssValue; + } + } + + private static final String CSS_PROPERTY = "backgroundPosition"; + + public static void init() { + CSS.BACKGROUND_POSITION = new BackgroundPositionProperty(); + } + + private BackgroundPositionProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundProperty.java new file mode 100644 index 00000000..32e681dd --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundProperty.java @@ -0,0 +1,66 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.HasCssName; +import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment; +import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition; +import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat; + +public class BackgroundProperty + implements + CssShorthandProperty5 { + + private static final String CSS_PROPERTY = "background"; + + static void init() { + CSS.BACKGROUND = new BackgroundProperty(); + BackgroundAttachmentProperty.init(); + BackgroundColorProperty.init(); + BackgroundImageProperty.init(); + BackgroundRepeatProperty.init(); + BackgroundPositionProperty.init(); + } + + private BackgroundProperty() { + } + + public String get(Style s) { + return s.getProperty(CSS_PROPERTY); + } + + public String getCssName() { + return CSS_PROPERTY; + } + + public void set(Style s, RGBColor backgroundColor, + ImageValue backgroundImage, BackgroundRepeat backgroundRepeat, + BackgroundAttachment backgroundAttachment, + BackgroundPosition backgroundPosition) { + + String value = notNull(backgroundColor) + notNull(backgroundImage) + + notNull(backgroundRepeat) + notNull(backgroundAttachment) + + notNull(backgroundPosition).trim(); + s.setProperty(CSS_PROPERTY, value); + + } + + private String notNull(HasCssName value) { + return value != null ? value.getCssName() + " " : ""; + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java new file mode 100644 index 00000000..d3810e17 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java @@ -0,0 +1,97 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * The background-repeat property sets if/how a background image will be + * repeated. By default, a background-image is repeated both vertically and + * horizontally. + */ +public class BackgroundRepeatProperty extends + AbstractCssProperty { + + public static enum BackgroundRepeat implements HasCssName { + /** + * Specifies that the setting of the background-repeat property should be + * inherited from the parent element + */ + INHERIT { + @Override + public String getCssName() { + return INHERIT_VALUE; + } + }, + /** + * The background-image will not be repeated + */ + NO_REPEAT { + @Override + public String getCssName() { + return NO_REPEAT_VALUE; + } + }, + /** + * The background image will be repeated both vertically and horizontally. + */ + REPEAT { + @Override + public String getCssName() { + return REPEAT_VALUE; + } + }, + /** + * The background image will be repeated only horizontally + */ + REPEAT_X { + @Override + public String getCssName() { + return REPEAT_X_VALUE; + } + }, + /** + * The background image will be repeated only vertically + */ + REPEAT_Y { + @Override + public String getCssName() { + return REPEAT_Y_VALUE; + } + }; + + public abstract String getCssName(); + } + + private static final String CSS_PROPERTY = "backgroundRepeat"; + private static final String INHERIT_VALUE = "inherit"; + private static final String NO_REPEAT_VALUE = "no-repeat"; + private static final String REPEAT_VALUE = "repeat"; + private static final String REPEAT_X_VALUE = "repeat-x"; + + private static final String REPEAT_Y_VALUE = "repeat-y"; + + public static void init() { + CSS.BACKGROUND_REPEAT = new BackgroundRepeatProperty(); + } + + private BackgroundRepeatProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderColorProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderColorProperty.java new file mode 100644 index 00000000..5785e142 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderColorProperty.java @@ -0,0 +1,48 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +/** + * This property describes the foreground color of an element's text content. + */ +public class BorderColorProperty extends AbstractCssProperty { + + private static final String BORDER_BOTTOM_COLOR_PROPERTY = "borderBottomColor"; + private static final String BORDER_COLOR_PROPERTY = "borderColor"; + private static final String BORDER_LEFT_COLOR_PROPERTY = "borderLeftColor"; + private static final String BORDER_RIGHT_COLOR_PROPERTY = "borderRightColor"; + private static final String BORDER_TOP_COLOR_PROPERTY = "borderTopColor"; + + public static void init() { + CSS.BORDER_COLOR = new BorderColorProperty(BORDER_COLOR_PROPERTY); + CSS.BORDER_BOTTOM_COLOR = new BorderColorProperty( + BORDER_BOTTOM_COLOR_PROPERTY); + CSS.BORDER_LEFT_COLOR = new BorderColorProperty(BORDER_LEFT_COLOR_PROPERTY); + CSS.BORDER_RIGHT_COLOR = new BorderColorProperty( + BORDER_RIGHT_COLOR_PROPERTY); + CSS.BORDER_TOP_COLOR = new BorderColorProperty(BORDER_TOP_COLOR_PROPERTY); + } + + private String cssName; + + private BorderColorProperty(String value) { + this.cssName = value; + } + + public String getCssName() { + return cssName; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java new file mode 100644 index 00000000..dd20cab0 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java @@ -0,0 +1,62 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.HasCssName; +import com.google.gwt.query.client.css.BorderStyleProperty.BorderStyle; +import com.google.gwt.query.client.css.BorderWidthProperty.BorderWidth; + +/** + * + * + */ +public class BorderProperty + implements + CssShorthandProperty3 { + + private static final String CSS_PROPERTY = "border"; + + static void init() { + CSS.BORDER = new BorderProperty(); + BorderColorProperty.init(); + BorderStyleProperty.init(); + BorderWidthProperty.init(); + } + + private BorderProperty() { + } + + public String get(Style s) { + return s.getProperty(CSS_PROPERTY); + } + + public String getCssName() { + return CSS_PROPERTY; + } + + public void set(Style s, BorderWidth borderWidth, BorderStyle borderStyle, + RGBColor borderColor) { + String value = notNull(borderWidth) + notNull(borderStyle) + + notNull(borderColor).trim(); + s.setProperty(CSS_PROPERTY, value); + } + + private String notNull(HasCssName value) { + return value != null ? value.getCssName() + " " : ""; + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java new file mode 100644 index 00000000..cdc2213f --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java @@ -0,0 +1,122 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * This property describes the foreground color of an element's text content. + */ +public class BorderStyleProperty extends + AbstractCssProperty { + + public static enum BorderStyle implements HasCssName { + DASHED { + @Override + public String getCssName() { + return "dashed"; + } + }, + DOTTED { + @Override + public String getCssName() { + return "dotted"; + } + }, + DOUBLE { + @Override + public String getCssName() { + return "double"; + } + }, + GROOVE { + @Override + public String getCssName() { + return "groove"; + } + }, + HIDDEN { + @Override + public String getCssName() { + return "hidden"; + } + }, + INHERIT { + @Override + public String getCssName() { + return CSS.INHERIT_VALUE; + } + }, + INSET { + @Override + public String getCssName() { + return "inset"; + } + }, + NONE { + @Override + public String getCssName() { + return "none"; + } + }, + OUTSET { + @Override + public String getCssName() { + return "outset"; + } + }, + RIDGE { + @Override + public String getCssName() { + return "ridge"; + } + }, + SOLID { + @Override + public String getCssName() { + return "solid"; + } + }; + + public abstract String getCssName(); + } + private static final String BORDER_BOTTOM_STYLE_PROPERTY = "borderBottomStyle"; + private static final String BORDER_LEFT_STYLE_PROPERTY = "borderLeftStyle"; + private static final String BORDER_RIGHT_STYLE_PROPERTY = "borderRightStyle"; + private static final String BORDER_STYLE_PROPERTY = "borderStyle"; + + private static final String BORDER_TOP_STYLE_PROPERTY = "borderTopStyle"; + + public static void init() { + CSS.BORDER_STYLE = new BorderStyleProperty(BORDER_STYLE_PROPERTY); + CSS.BORDER_BOTTOM_STYLE = new BorderStyleProperty( + BORDER_BOTTOM_STYLE_PROPERTY); + CSS.BORDER_LEFT_STYLE = new BorderStyleProperty(BORDER_LEFT_STYLE_PROPERTY); + CSS.BORDER_RIGHT_STYLE = new BorderStyleProperty( + BORDER_RIGHT_STYLE_PROPERTY); + CSS.BORDER_TOP_STYLE = new BorderStyleProperty(BORDER_TOP_STYLE_PROPERTY); + } + + private String cssName; + + private BorderStyleProperty(String value) { + this.cssName = value; + } + + public String getCssName() { + return cssName; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java new file mode 100644 index 00000000..9b8aee82 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java @@ -0,0 +1,93 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.HasCssName; +import com.google.gwt.dom.client.Style.Unit; + +/** + * This property set the width of an element's border. + */ +public class BorderWidthProperty extends + AbstractCssProperty implements TakesLength { + + public static class BorderWidth implements HasCssName { + + public static BorderWidth INHERIT; + public static BorderWidth MEDIUM; + public static BorderWidth THICK; + public static BorderWidth THIN; + + static { + MEDIUM = new BorderWidth("medium"); + THICK = new BorderWidth("thick"); + THIN = new BorderWidth("thin"); + INHERIT = new BorderWidth(CSS.INHERIT_VALUE); + + } + + public static BorderWidth length(int l, Unit unit) { + return new BorderWidth("" + l + (unit != null ? unit.getType() : "")); + } + + public static BorderWidth length(Length l) { + return new BorderWidth(l.getCssName()); + } + + private String cssValue; + + private BorderWidth(String value) { + cssValue = value; + } + + public String getCssName() { + return cssValue; + } + + } + + private static final String BORDER_BOTTOM_WIDTH_PROPERTY = "borderBottomWidth"; + private static final String BORDER_LEFT_WIDTH_PROPERTY = "borderLeftWidth"; + private static final String BORDER_RIGHT_WIDTH_PROPERTY = "borderRightWidth"; + private static final String BORDER_TOP_WIDTH_PROPERTY = "borderTopWidth"; + private static final String BORDER_WIDTH_PROPERTY = "borderWidth"; + + public static void init() { + CSS.BORDER_WIDTH = new BorderWidthProperty(BORDER_WIDTH_PROPERTY); + CSS.BORDER_BOTTOM_WIDTH = new BorderWidthProperty( + BORDER_BOTTOM_WIDTH_PROPERTY); + CSS.BORDER_LEFT_WIDTH = new BorderWidthProperty(BORDER_LEFT_WIDTH_PROPERTY); + CSS.BORDER_RIGHT_WIDTH = new BorderWidthProperty( + BORDER_RIGHT_WIDTH_PROPERTY); + CSS.BORDER_TOP_WIDTH = new BorderWidthProperty(BORDER_TOP_WIDTH_PROPERTY); + } + + private String cssName; + + private BorderWidthProperty(String value) { + this.cssName = value; + } + + public String getCssName() { + return cssName; + } + + public void set(Style s, Length p) { + s.setProperty(cssName, p.getCssName()); + + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java index 282e3553..af10896b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java @@ -15,466 +15,184 @@ */ package com.google.gwt.query.client.css; - /** * Created by IntelliJ IDEA. User: ray Date: May 2, 2009 Time: 12:56:09 AM To * change this template use File | Settings | File Templates. */ public class CSS { - /** - * This property affects the vertical positioning inside a line box of the - * boxes generated by an inline-level element. - */ - public static VerticalAlign VERTICAL_ALIGN; - - /** - * Align the line box with the left side of the containing box. - */ - public static TextAlign.TAlignValue LEFT; - - /** - * Align the line box with the right side of the containing box. - */ - public static TextAlign.TAlignValue RIGHT; - - /** - * This property describes how inline content of a block is aligned. - */ - public static TextAlign TEXT_ALIGN; - - /** - * Align the top of the aligned subtree with the top of the line box. - */ - public static VerticalAlign.VAlignValue TOP; - - /** - * Align the bottom of the aligned subtree with the bottom of the line box. - */ - public static VerticalAlign.VAlignValue BOTTOM; - - /** - * Align the baseline of the box with the baseline of the parent box. If the - * box doesn't have a baseline, align the bottom margin edge with the parent's - * baseline. - */ - public static VerticalAlign.VAlignValue BASELINE; - - /** - * Lower the baseline of the box to the proper position for subscripts of the - * parent's box. (This value has no effect on the font size of the element's - * text.) - */ - public static VerticalAlign.VAlignValue SUB; - - /** - * Raise the baseline of the box to the proper position for superscripts of - * the parent's box. (This value has no effect on the font size of the - * element's text.) - */ - public static VerticalAlign.VAlignValue SUPER; - - /** - * Align the top of the box with the top of the parent's content area. - */ - public static VerticalAlign.VAlignValue TEXT_TOP; - - /** - * Align the vertical midpoint of the box with the baseline of the parent box - * plus half the x-height of the parent. - */ - public static VerticalAlign.VAlignValue MIDDLE; - - /** - * Align the bottom of the box with the bottom of the parent's content area. - */ - public static VerticalAlign.VAlignValue TEXT_BOTTOM; - - /** - * Inherit value from parent elements. - */ - public static Inherit INHERIT; - - /** - * Align the line box with the left side of the containing box. - */ - public static TextAlign.TAlignValue CENTER; - - /** - * this property specifies that the inline boxes are to be made flush with - * both sides of the block. If the computed value of text-align is 'justify' - * while the computed value of white-space is 'pre' or 'pre-line', the actual - * value of text-align is set to the initial value. - */ - public static TextAlign.TAlignValue JUSTIFY; - + public static BackgroundProperty BACKGROUND; + /** * background image is specified, this property specifies whether it is fixed * with regard to the viewport ('fixed') or scrolls along with the containing * block ('scroll'). */ - public static BackgroundAttachment BACKGROUND_ATTACHMENT; + public static BackgroundAttachmentProperty BACKGROUND_ATTACHMENT; - /** - * Background image is fixed. - */ - public static BackgroundAttachment.AttachValue FIXED; - - /** - * Background image scrolls when viewport is scrolled. - */ - public static BackgroundAttachment.AttachValue SCROLL; - - public static BackgroundColor BACKGROUND_COLOR; - - public static RGBColor AQUA; - - public static RGBColor BLACK; + public static BackgroundColorProperty BACKGROUND_COLOR; - public static RGBColor FUSCHIA; + public static BackgroundImageProperty BACKGROUND_IMAGE; - public static RGBColor GRAY; + public static BackgroundPositionProperty BACKGROUND_POSITION; - public static RGBColor GREEN; + public static BackgroundRepeatProperty BACKGROUND_REPEAT; - public static RGBColor LIME; + public static BorderProperty BORDER; - public static RGBColor MAROON; + public static BorderColorProperty BORDER_BOTTOM_COLOR; - public static RGBColor NAVY; + public static BorderStyleProperty BORDER_BOTTOM_STYLE; - public static RGBColor OLIVE; + public static BorderWidthProperty BORDER_BOTTOM_WIDTH; - public static RGBColor ORANGE; + public static BorderColorProperty BORDER_COLOR; - public static RGBColor PURPLE; + public static BorderColorProperty BORDER_LEFT_COLOR; - public static RGBColor RED; + public static BorderStyleProperty BORDER_LEFT_STYLE; - public static RGBColor SILVER; + public static BorderWidthProperty BORDER_LEFT_WIDTH; + + public static BorderColorProperty BORDER_RIGHT_COLOR; + + public static BorderStyleProperty BORDER_RIGHT_STYLE; + + public static BorderWidthProperty BORDER_RIGHT_WIDTH; + + public static BorderStyleProperty BORDER_STYLE; - public static RGBColor TEAL; + public static BorderColorProperty BORDER_TOP_COLOR; + + public static BorderStyleProperty BORDER_TOP_STYLE; + + public static BorderWidthProperty BORDER_TOP_WIDTH; - public static RGBColor WHITE; - - public static RGBColor YELLOW; - - public static RGBColor TRANSPARENT; + public static BorderWidthProperty BORDER_WIDTH; /** * This property describes the foreground color of an element's text content. */ - public static Color COLOR; - - /** - * This property specifies whether a box should float to the left, right, or - * not at all. It may be set for any element, but only applies to elements - * that generate boxes that are not absolutely positioned. - */ - public static Float FLOAT; - - /** - * The element generates a block box that is floated to the left. Content - * flows on the right side of the box, starting at the top (subject to the - * 'clear' property). - */ - public static Float.FloatValue FLOAT_LEFT; - - /** - * Similar to 'left', except the box is floated to the right, and content - * flows on the left side of the box, starting at the top. - */ - public static Float.FloatValue FLOAT_RIGHT; - - /** - * The box is not floated. - */ - public static Float.FloatValue FLOAT_NONE; + public static ColorProperty COLOR; /** * This property specifies the type of cursor to be displayed for the pointing * device. */ - public static Cursor CURSOR; - - /** - * The UA determines the cursor to display based on the current context. - */ - public static Cursor.CursorValue CURSOR_AUTO; - - /** - * A simple crosshair (e.g., short line segments resembling a "+" sign). - */ - public static Cursor.CursorValue CURSOR_CROSSHAIR; - - /** - * The platform-dependent default cursor. Often rendered as an arrow. - */ - public static Cursor.CursorValue CURSOR_DEFAULT; - - /** - * The cursor is a pointer that indicates a link. - */ - public static Cursor.CursorValue CURSOR_POINTER; - - /** - * Indicates something is to be moved. - */ - public static Cursor.CursorValue CURSOR_MOVE; - - /** - * Indicates text that may be selected. Often rendered as an I-beam. - */ - public static Cursor.CursorValue CURSOR_TEXT; - - /** - * Indicates that the program is busy and the user should wait. Often rendered - * as a watch or hourglass. - */ - public static Cursor.CursorValue CURSOR_WAIT; - - /** - * A progress indicator. The program is performing some processing, but is - * different from 'wait' in that the user may still interact with the program. - * Often rendered as a spinning beach ball, or an arrow with a watch or - * hourglass. - */ - public static Cursor.CursorValue CURSOR_PROGRESS; - - /** - * Help is available for the object under the cursor. Often rendered as a - * question mark or a balloon. - */ - public static Cursor.CursorValue CURSOR_HELP; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_E_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_NE_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_NW_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_N_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_SE_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_SW_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_S_RESIZE; - - /** - * Indicate that some edge is to be moved. For example, the 'se-resize' cursor - * is used when the movement starts from the south-east corner of the box. - */ - public static Cursor.CursorValue CURSOR_W_RESIZE; - + public static CursorProperty CURSOR; /** * This property specifies the mechanism by which elements are rendered. */ - public static Display DISPLAY; - - /** - * This value causes an element to generate a block box. - */ - public static Display.DisplayValue BLOCK; - - /** - * This value causes an element to generate one or more inline boxes. - */ - public static Display.DisplayValue INLINE; - - /** - * This value causes an element to generate a block box, which itself is - * flowed as a single inline box, similar to a replaced element. The inside of - * an inline-block is formatted as a block box, and the element itself is - * formatted as an inline replaced element. - */ - public static Display.DisplayValue INLINE_BLOCK; - - /** - * This value causes an element (e.g., LI in HTML) to generate a principal - * block box and a list-item inline box. For information about lists and - * examples of list formatting, please consult the section on lists. - */ - public static Display.DisplayValue LIST_ITEM; - - /** - * This value causes an element to not appear in the formatting structure - * (i.e., in visual media the element generates no boxes and has no effect on - * layout). Descendant elements do not generate any boxes either; the element - * and its content are removed from the formatting structure entirely. This - * behavior cannot be overridden by setting the 'display' property on the - * descendants. Please note that a display of 'none' does not create an - * invisible box; it creates no box at all. CSS includes mechanisms that - * enable an element to generate boxes in the formatting structure that affect - * formatting but are not visible themselves. Please consult the section on - * visibility for details. - */ - public static Display.DisplayValue NONE; - - /** - * This value creates either block or inline boxes, depending on context. - * Properties apply to run-in boxes based on their final status (inline-level - * or block-level). - */ - public static Display.DisplayValue RUN_IN; - - /** - * Specifies that an element defines a block-level table: it is a rectangular - * block that participates in a block formatting context. - */ - public static Display.DisplayValue TABLE; - - /** - * Specifies that an element defines an inline-level table: it is a - * rectangular block that participates in an inline formatting context). - */ - public static Display.DisplayValue INLINE_TABLE; - + public static DisplayProperty DISPLAY; /** - * Specifies that an element groups one or more rows. - */ - public static Display.DisplayValue TABLE_ROW_GROUP; - - /** - * Specifies that an element groups one or more columns. - */ - public static Display.DisplayValue TABLE_COLUMN_GROUP; - - /** - * Specifies that an element describes a column of cells. - */ - public static Display.DisplayValue TABLE_COLUMN; - - /** - * Like 'table-row-group', but for visual formatting, the row group is always - * displayed before all other rows and row groups and after any top captions. - * Print user agents may repeat header rows on each page spanned by a table. - * If a table contains multiple elements with 'display: table-header-group', - * only the first is rendered as a header; the others are treated as if they - * had 'display: table-row-group'. - */ - public static Display.DisplayValue TABLE_HEADER_GROUP; - - /** - * Like 'table-row-group', but for visual formatting, the row group is always - * displayed after all other rows and row groups and before any bottom - * captions. Print user agents may repeat footer rows on each page spanned by - * a table. If a table contains multiple elements with 'display: - * table-footer-group', only the first is rendered as a footer; the others are - * treated as if they had 'display: table-row-group'. + * This property specifies whether a box should float to the left, right, or + * not at all. It may be set for any element, but only applies to elements + * that generate boxes that are not absolutely positioned. */ - public static Display.DisplayValue TABLE_FOOTER_GROUP; - + public static FloatProperty FLOAT; + + public static FontSizeProperty FONT_SIZE; + + public static FontStyleProperty FONT_STYLE; + + public static FontVariantProperty FONT_VARIANT; + + public static FontWeightProperty FONT_WEIGHT; + /** - * Specifies that an element is a row of cells. + * This property specifies the content height of boxes generated by + * block-level, inline-block and replaced elements. + * + * This property does not apply to non-replaced inline-level elements. See the + * section on computing heights and margins for non-replaced inline elements + * for the rules used instead. */ - public static Display.DisplayValue TABLE_ROW; - + public static HeightProperty HEIGHT; + + public static final String INHERIT_VALUE = "inherit"; + + public static ListStyleProperty LIST_STYLE; + + public static ListStyleImageProperty LIST_STYLE_IMAGE; + + public static ListStylePositionProperty LIST_STYLE_POSITION; + + public static ListStyleTypeProperty LIST_STYLE_TYPE; + + public static MarginProperty MARGIN; + + public static MarginProperty MARGIN_BOTTOM; + + public static MarginProperty MARGIN_LEFT; + + public static MarginProperty MARGIN_RIGHT; + + public static MarginProperty MARGIN_TOP; + + public static PaddingProperty PADDING; + + public static PaddingProperty PADDING_BOTTOM; + + public static PaddingProperty PADDING_LEFT; + + public static PaddingProperty PADDING_RIGHT; + + public static PaddingProperty PADDING_TOP; + /** - * Specifies that an element represents a table cell. + * This property describes how inline content of a block is aligned. */ - public static Display.DisplayValue TABLE_CELL; - + public static TextAlignProperty TEXT_ALIGN; + /** - * Specifies a caption for the table. All elements with 'display: - * table-caption' must be rendered, as described in section 17.4. + * This property affects the vertical positioning inside a line box of the + * boxes generated by an inline-level element. */ - public static Display.DisplayValue TABLE_CAPTION; - + public static VerticalAlignProperty VERTICAL_ALIGN; + /** * The 'visibility' property specifies whether the boxes generated by an * element are rendered. Invisible boxes still affect layout (set the * 'display' property to 'none' to suppress box generation altogether). */ - public static Visibility VISIBILITY; - - /** - * The generated box is visible. - */ - public static Visibility.VisibilityValue VISIBLE; - - /** - * The generated box is invisible (fully transparent, nothing is drawn), but - * still affects layout. Furthermore, descendents of the element will be - * visible if they have 'visibility: visible'. - */ - public static Visibility.VisibilityValue HIDDEN; - - /** - * Please consult the CSS spec on dynamic row and column effects in tables. If - * used on elements other than rows, row groups, columns, or column groups, - * 'collapse' has the same meaning as 'hidden'. - */ - public static Visibility.VisibilityValue COLLAPSE; - + public static VisibilityProperty VISIBILITY; + /** * This property specifies the content width of boxes generated by block-level * and replaced elements. - * + * * This property does not apply to non-replaced inline-level elements. The * content width of a non-replaced inline element's boxes is that of the * rendered content within them (before any relative offset of children). * Recall that inline boxes flow into line boxes. The width of line boxes is * given by the their containing block, but may be shorted by the presence of * floats. - * + * * The width of a replaced element's box is intrinsic and may be scaled by the * user agent if the value of this property is different than 'auto'. */ - public static Width WIDTH; - - /** - * This property specifies the content height of boxes generated by - * block-level, inline-block and replaced elements. - * - * This property does not apply to non-replaced inline-level elements. See the - * section on computing heights and margins for non-replaced inline elements - * for the rules used instead. - */ - public static Height HEIGHT; + public static WidthProperty WIDTH; static { - INHERIT = Inherit.create(); - BackgroundAttachment.init(); - BackgroundColor.init(); - Color.init(); - Cursor.init(); - Display.init(); - Float.init(); - Height.init(); - RGBColor.init(); - TextAlign.init(); - VerticalAlign.init(); - Visibility.init(); - Width.init(); + BackgroundProperty.init(); + BorderProperty.init(); + ColorProperty.init(); + CursorProperty.init(); + DisplayProperty.init(); + FloatProperty.init(); + FontStyleProperty.init(); + FontVariantProperty.init(); + FontWeightProperty.init(); + FontSizeProperty.init(); + HeightProperty.init(); + ListStyleProperty.init(); + MarginProperty.init(); + PaddingProperty.init(); + TextAlignProperty.init(); + VerticalAlignProperty.init(); + VisibilityProperty.init(); + WidthProperty.init(); + } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Color.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ColorProperty.java similarity index 72% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/css/Color.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/css/ColorProperty.java index 4e23d0c0..5df4daa9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Color.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ColorProperty.java @@ -15,25 +15,21 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.dom.client.Style; - /** * This property describes the foreground color of an element's text content. */ -public class Color implements CssProperty { +public class ColorProperty extends AbstractCssProperty { - public static void init() { - CSS.COLOR = new Color(); - } + private static final String CSS_PROPERTY = "color"; - public Color() { + public static void init() { + CSS.COLOR = new ColorProperty(); } - public String get(Style s) { - return s.getProperty("color"); + private ColorProperty() { } - public void set(Style s, RGBColor value) { - s.setProperty("color", value.value()); + public String getCssName() { + return CSS_PROPERTY; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java index c43ae473..71c86521 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java @@ -18,20 +18,19 @@ package com.google.gwt.query.client.css; import com.google.gwt.dom.client.Style; /** - * An enumerated CSS property with values of type T. + * Minimal contract for an object defining a css property + * */ -public interface CssProperty { - - /** - * Set the style to the given value. - * - * @param value a value from the enumerated type T - */ - void set(Style s, T value); +public interface CssProperty { /** * Return the value of the property as an enumerated type, or null, if the * value falls outside the enumerated set. */ String get(Style s); + + /** + * Return the css name of this property + */ + String getCssName(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesPercentage.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssShorthandProperty3.java similarity index 79% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesPercentage.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssShorthandProperty3.java index 436ca7ab..c91d889b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesPercentage.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssShorthandProperty3.java @@ -18,9 +18,11 @@ package com.google.gwt.query.client.css; import com.google.gwt.dom.client.Style; /** - * Interface to be implemented by properties which take percentage units. + * + * An enumerated CSS property with values of type X,Y,Z. */ -public interface TakesPercentage { +public interface CssShorthandProperty3 extends CssProperty{ + + void set(Style s, X value1, Y value2, Z value3); - void setPercentage(Style s, Percentage p); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty4.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssShorthandProperty5.java similarity index 76% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty4.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssShorthandProperty5.java index 8e2dd0d7..2f60da62 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty4.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssShorthandProperty5.java @@ -18,11 +18,11 @@ package com.google.gwt.query.client.css; import com.google.gwt.dom.client.Style; /** - * An enumerated CSS property with values of type X,Y,W,Z. + * + * An enumerated CSS property with values of type V, W, X,Y,Z. */ -public interface CssProperty4 { +public interface CssShorthandProperty5 extends CssProperty { - void set(Style s, X value1, Y value2, Z value3, W value4); + void set(Style s, V value1, W value2, X value3, Y value4, Z value5); - String get(Style s); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Cursor.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Cursor.java deleted file mode 100644 index 8a657a23..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Cursor.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; - -/** - * This property specifies whether a box should float to the left, right, or not - * at all. It may be set for any element, but only applies to elements that - * generate boxes that are not absolutely positioned. - */ -public class Cursor implements CssProperty { - - final static public class CursorValue extends JavaScriptObject { - - protected static CursorValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - private static native CursorValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private static native CursorValue createWeb(String val) /*-{ - return val; - }-*/; - - protected CursorValue() { - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - } - - /** - * Returns a cursor located at the given uri. - */ - public static CursorValue cursor(String uri) { - return CursorValue.create("uri(" + uri + ")"); - } - - public static void init() { - CSS.CURSOR = new Cursor(); - CSS.CURSOR_AUTO = CursorValue.create("auto"); - CSS.CURSOR_CROSSHAIR = CursorValue.create("crosshair"); - CSS.CURSOR_DEFAULT = CursorValue.create("default"); - CSS.CURSOR_POINTER = CursorValue.create("pointer"); - CSS.CURSOR_MOVE = CursorValue.create("move"); - CSS.CURSOR_TEXT = CursorValue.create("text"); - CSS.CURSOR_WAIT = CursorValue.create("wait"); - CSS.CURSOR_PROGRESS = CursorValue.create("progress"); - CSS.CURSOR_HELP = CursorValue.create("help"); - CSS.CURSOR_E_RESIZE = CursorValue.create("e-resize"); - CSS.CURSOR_NE_RESIZE = CursorValue.create("ne-resize"); - CSS.CURSOR_NW_RESIZE = CursorValue.create("nw-resize"); - CSS.CURSOR_N_RESIZE = CursorValue.create("n-resize"); - CSS.CURSOR_SE_RESIZE = CursorValue.create("se-resize"); - CSS.CURSOR_SW_RESIZE = CursorValue.create("sw-resize"); - CSS.CURSOR_S_RESIZE = CursorValue.create("s-resize"); - CSS.CURSOR_W_RESIZE = CursorValue.create("w-resize"); - } - - public String get(Style s) { - return s.getProperty("cursor"); - } - - public void set(Style s, CursorValue value) { - s.setProperty("cursor", value.value()); - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java new file mode 100644 index 00000000..8bc13746 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.Cursor; + +/** + * This property specifies all possible value for cursor. + */ +public class CursorProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "cursor"; + + public static void init() { + CSS.CURSOR = new CursorProperty(); + } + + private CursorProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Display.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Display.java deleted file mode 100644 index 292b06bc..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Display.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; - -/** - * This property specifies the mechanism by which elements are rendered. - */ -public class Display implements CssProperty { - - final static public class DisplayValue extends JavaScriptObject { - - protected static DisplayValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - private static native DisplayValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private static native DisplayValue createWeb(String val) /*-{ - return val; - }-*/; - - protected DisplayValue() { - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - } - - public static void init() { - CSS.DISPLAY = new Display(); - CSS.BLOCK = DisplayValue.create("block"); - CSS.INLINE = DisplayValue.create("inline"); - CSS.INLINE_BLOCK = DisplayValue.create("inline-block"); - CSS.LIST_ITEM = DisplayValue.create("list-item"); - CSS.NONE = DisplayValue.create("none"); - CSS.RUN_IN = DisplayValue.create("run-in"); - CSS.TABLE = DisplayValue.create("table"); - CSS.INLINE_TABLE = DisplayValue.create("inline-table"); - CSS.TABLE_ROW_GROUP = DisplayValue.create("table-row-group"); - CSS.TABLE_COLUMN = DisplayValue.create("table-column"); - CSS.TABLE_COLUMN_GROUP = DisplayValue.create("table-column-group"); - CSS.TABLE_HEADER_GROUP = DisplayValue.create("table-header-group"); - CSS.TABLE_FOOTER_GROUP = DisplayValue.create("table-footer-group"); - CSS.TABLE_ROW = DisplayValue.create("table-row"); - CSS.TABLE_CELL = DisplayValue.create("table-cell"); - CSS.TABLE_CAPTION = DisplayValue.create("table-caption"); - } - - public String get(Style s) { - return s.getProperty("display"); - } - - public void set(Style s, DisplayValue value) { - s.setProperty("display", value.value()); - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DisplayProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DisplayProperty.java new file mode 100644 index 00000000..6b2ddf37 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DisplayProperty.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.Display; + +/** + * This property specifies the mechanism by which elements are rendered. + */ +public class DisplayProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "display"; + + public static void init() { + CSS.DISPLAY = new DisplayProperty(); + } + + private DisplayProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Float.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Float.java deleted file mode 100644 index 117f5bc9..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Float.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; - -/** - * This property specifies whether a box should float to the left, right, or not - * at all. It may be set for any element, but only applies to elements that - * generate boxes that are not absolutely positioned. - */ -public class Float implements CssProperty { - - public static void init() { - CSS.FLOAT = new Float(); - CSS.FLOAT_LEFT = FloatValue.create("left"); - CSS.FLOAT_RIGHT = FloatValue.create("right"); - CSS.FLOAT_NONE = FloatValue.create("none"); - } - - public void set(Style s, FloatValue value) { - s.setProperty("float", value.value()); - } - - public String get(Style s) { - return s.getProperty("float"); - } - - final static public class FloatValue extends JavaScriptObject { - - protected FloatValue() { - } - - protected static FloatValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private static native FloatValue createWeb(String val) /*-{ - return val; - }-*/; - - private static native FloatValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FloatProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FloatProperty.java new file mode 100644 index 00000000..adf03062 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FloatProperty.java @@ -0,0 +1,45 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.Float; + +/** + * This property specifies whether a box should float to the left, right, or not + * at all. It may be set for any element, but only applies to elements that + * generate boxes that are not absolutely positioned. + */ +public class FloatProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "float"; + + public static void init() { + CSS.FLOAT = new FloatProperty(); + } + + private FloatProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } + + @Override + public void set(Style s, Float value) { + s.setFloat(value); + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontSizeProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontSizeProperty.java new file mode 100644 index 00000000..2c498554 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontSizeProperty.java @@ -0,0 +1,144 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * This property specifies the size of a font. + */ +public class FontSizeProperty extends + AbstractCssProperty implements TakesLength { + + /** + * Enum for the font-size property. + */ + public static enum FontSize implements HasCssName { + /** + * Specifies that the font size should be inherited from the parent element + */ + INHERIT { + @Override + public String getCssName() { + return CSS.INHERIT_VALUE; + } + }, + /** + * Sets the font-size to a large size + */ + LARGE { + @Override + public String getCssName() { + return "large"; + } + }, + /** + * Sets the font-size to a larger size than the parent element + */ + LARGER { + @Override + public String getCssName() { + return "larger"; + } + }, + /** + * Sets the font-size to a medium size + */ + MEDIUM { + @Override + public String getCssName() { + return "medium"; + } + }, + /** + * Sets the font-size to a small size + */ + SMALL { + @Override + public String getCssName() { + return "small"; + } + }, + /** + * Sets the font-size to a smaller size than the parent element + */ + SMALLER { + @Override + public String getCssName() { + return "smaller"; + } + }, + /** + * Sets the font-size to an extra large size + */ + X_LARGE { + @Override + public String getCssName() { + return "x-large"; + } + }, + /** + * Sets the font-size to an extra small size + */ + X_SMALL { + @Override + public String getCssName() { + return "x-small"; + } + }, + /** + * Sets the font-size to an extra extra large size + */ + XX_LARGE { + @Override + public String getCssName() { + return "xx-large"; + } + }, + /** + * Sets the font-size to an extra extra small size + */ + XX_SMALL { + @Override + public String getCssName() { + return "xx-small"; + } + }; + public abstract String getCssName(); + } + + private static final String CSS_PROPERTY = "fontSize"; + + public static void init() { + CSS.FONT_SIZE = new FontSizeProperty(); + } + + private FontSizeProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } + + /** + * Sets the font-size to a fixed size in px, cm,.. + */ + public void set(Style s, Length p) { + s.setProperty(CSS_PROPERTY, p.getCssName()); + + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontStyleProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontStyleProperty.java new file mode 100644 index 00000000..2bcc2b83 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontStyleProperty.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.FontStyle; + +/** + * This property specifies the mechanism by which elements are rendered. + */ +public class FontStyleProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "fontStyle"; + + public static void init() { + CSS.FONT_STYLE = new FontStyleProperty(); + } + + private FontStyleProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontVariantProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontVariantProperty.java new file mode 100644 index 00000000..eb409b56 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontVariantProperty.java @@ -0,0 +1,73 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * This property specifies the mechanism by which elements are rendered. + */ +public class FontVariantProperty extends + AbstractCssProperty { + + /** + * Enum for the font-variant property. + */ + public static enum FontVariant implements HasCssName { + /** + * Specifies that the font variant should be inherited from the parent + * element + */ + INHERIT { + @Override + public String getCssName() { + return CSS.INHERIT_VALUE; + } + }, + /** + * The browser displays a normal font + */ + NORMAL { + @Override + public String getCssName() { + return "normal"; + } + }, + /** + * The browser displays a small-caps font + */ + SMALL_CAPS { + @Override + public String getCssName() { + return "small-caps"; + } + }; + public abstract String getCssName(); + } + + private static final String CSS_PROPERTY = "fontVariant"; + + public static void init() { + CSS.FONT_VARIANT = new FontVariantProperty(); + } + + private FontVariantProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontWeightProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontWeightProperty.java new file mode 100644 index 00000000..788e8aae --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/FontWeightProperty.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.FontWeight; + +/** + * This property specifies the mechanism by which elements are rendered. + */ +public class FontWeightProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "fontWeight"; + + public static void init() { + CSS.FONT_WEIGHT = new FontWeightProperty(); + } + + private FontWeightProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Height.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java similarity index 66% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/css/Height.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java index 242d41fc..6f23b419 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Height.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java @@ -15,38 +15,26 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.dom.client.Style; - /** * This property specifies the content height of boxes generated by block-level, * inline-block and replaced elements. - * + * * This property does not apply to non-replaced inline-level elements. See the * section on computing heights and margins for non-replaced inline elements for * the rules used instead. */ -public class Height implements TakesLength, TakesPercentage { +public class HeightProperty extends AbstractCssProperty { - public Height() { - } + private static final String CSS_PROPERTY = "height"; public static void init() { - CSS.HEIGHT = new Height(); - } - - public void set(Style s, Length value) { - s.setProperty("height", value.value()); - } - - public String get(Style s) { - return s.getProperty("height"); + CSS.HEIGHT = new HeightProperty(); } - public void setLength(Style s, Length p) { - s.setProperty("height", p.value()); + private HeightProperty() { } - public void setPercentage(Style s, Percentage p) { - s.setProperty("height", p.value()); + public String getCssName() { + return CSS_PROPERTY; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ImageValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ImageValue.java new file mode 100644 index 00000000..d7740007 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ImageValue.java @@ -0,0 +1,47 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * Image as css value + */ +public class ImageValue implements HasCssName { + + public static final ImageValue INHERIT; + public static final ImageValue NONE; + + static { + NONE = new ImageValue("none"); + INHERIT = new ImageValue(CSS.INHERIT_VALUE); + } + + public static ImageValue url(String url) { + return new ImageValue("url('" + url + "')"); + } + + private String value; + + private ImageValue(String value) { + this.value = value; + } + + public String getCssName() { + return value; + } + +} \ No newline at end of file diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Inherit.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Inherit.java deleted file mode 100644 index 5d31bef0..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Inherit.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; - -/** - * A special value for inherited CSS properties, - */ -public class Inherit extends JavaScriptObject { - - protected Inherit() { - } - - public static Inherit create() { - return GWT.isScript() ? createWeb() : createHosted(); - } - - private static native Inherit createWeb() /*-{ - return "inherit"; - }-*/; - - private static native Inherit createHosted() /*-{ - return ["inherit"]; - }-*/; - - final public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Length.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Length.java index 5f022afa..18194c72 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Length.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Length.java @@ -15,83 +15,92 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.dom.client.Style.HasCssName; +import com.google.gwt.dom.client.Style.Unit; /** * Length type constructors. */ -public class Length extends JavaScriptObject { - - protected Length() { - } +public class Length implements HasCssName { /** - * Size in pixels. + * Size in centimeters. */ - public static Length px(int amt) { - return GWT.isScript() ? createWeb(amt + "px") : createHosted(amt + "px"); + public static Length cm(int amt) { + return new Length(amt + Unit.CM.getType()); } /** * Size as multiple of the 'font-size' of the relevant font. */ public static Length em(int amt) { - return GWT.isScript() ? createWeb(amt + "em") : createHosted(amt + "em"); + return new Length(amt + Unit.EM.getType()); } /** * Size as multiple of the 'x-height' of the relevant font. */ public static Length ex(int amt) { - return GWT.isScript() ? createWeb(amt + "ex") : createHosted(amt + "ex"); + return new Length(amt + Unit.EX.getType()); } /** - * Size in picas. + * Size in inches. */ - public static Length pc(int amt) { - return GWT.isScript() ? createWeb(amt + "pc") : createHosted(amt + "pc"); + public static Length in(int amt) { + return new Length(amt + Unit.IN.getType()); } /** * Size in millimeters. */ public static Length mm(int amt) { - return GWT.isScript() ? createWeb(amt + "mm") : createHosted(amt + "mm"); + return new Length(amt + Unit.MM.getType()); } /** - * Size in centimeters. + * Size in picas. */ - public static Length cm(int amt) { - return GWT.isScript() ? createWeb(amt + "cm") : createHosted(amt + "cm"); + public static Length pc(int amt) { + return new Length(amt + Unit.PC.getType()); } /** - * Size in inches. + * Size in percentage units. */ - public static Length in(int amt) { - return GWT.isScript() ? createWeb(amt + "in") : createHosted(amt + "in"); + public static Length pct(int amt) { + return new Length(amt + Unit.PCT.getType()); } - private static native Length createWeb(String pct) /*-{ - return pct; - }-*/; + /** + * Size in point. + */ + public static Length pt(int amt) { + return new Length(amt + Unit.PT.getType()); + } + + /** + * Size in pixels. + */ + public static Length px(int amt) { + return new Length(amt + Unit.PX.getType()); + } - private static native Length createHosted(String pct) /*-{ - return [pct]; - }-*/; + private String value; - final public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); + protected Length(String value) { + this.value = value; } - private native String valueWeb() /*-{ - return this; - }-*/; + public String getCssName() { + return value; + } - private native String valueHosted() /*-{ - return this[0]; - }-*/; + /** + * @deprecated use {@link Length#getCssName()} instead + */ + @Deprecated + public String value() { + return getCssName(); + } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleImageProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleImageProperty.java new file mode 100644 index 00000000..564f4b7f --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleImageProperty.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +/** + * This property sets an image as the list-item marker. + */ +public class ListStyleImageProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "listStyleImage"; + + public static void init() { + CSS.LIST_STYLE_IMAGE = new ListStyleImageProperty(); + } + + private ListStyleImageProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java new file mode 100644 index 00000000..a3934efa --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java @@ -0,0 +1,76 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * This property specifies if the list-item markers should appear inside or + * outside the content flow. + */ +public class ListStylePositionProperty extends + AbstractCssProperty { + + public static enum ListStylePosition implements HasCssName { + + /** + * Specifies that the value of the list-style-position property should be + * inherited from the parent element + */ + INHERIT { + @Override + public String getCssName() { + return "inherit"; + } + }, + /** + * Indents the marker and the text. The bullets appear inside the content + * flow + */ + INSIDE { + @Override + public String getCssName() { + return "inside"; + } + }, + /** + * Keeps the marker to the left of the text. The bullets appears outside the + * content flow. This is default + */ + OUTSIDE { + @Override + public String getCssName() { + return "outside"; + } + }; + + public abstract String getCssName(); + + } + + private static final String CSS_PROPERTY = "listStylePosition"; + + public static void init() { + CSS.LIST_STYLE_POSITION = new ListStylePositionProperty(); + } + + private ListStylePositionProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java new file mode 100644 index 00000000..5b61e779 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java @@ -0,0 +1,60 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.HasCssName; +import com.google.gwt.dom.client.Style.ListStyleType; +import com.google.gwt.query.client.css.ListStylePositionProperty.ListStylePosition; + +/** + * This property sets all list properties in one declaration. + */ +public class ListStyleProperty implements + CssShorthandProperty3 { + + private static final String CSS_PROPERTY = "listStyle"; + + static void init() { + CSS.LIST_STYLE = new ListStyleProperty(); + ListStyleImageProperty.init(); + ListStylePositionProperty.init(); + ListStyleTypeProperty.init(); + } + + private ListStyleProperty() { + } + + public String get(Style s) { + return s.getProperty(CSS_PROPERTY); + } + + public String getCssName() { + return CSS_PROPERTY; + } + + public void set(Style s, ListStyleType listStyleType, + ListStylePosition listStylePosition, ImageValue listStyleImage) { + String value = notNull(listStyleType) + notNull(listStylePosition) + + notNull(listStyleImage).trim(); + s.setProperty(CSS_PROPERTY, value); + } + + private String notNull(HasCssName value) { + return value != null ? value.getCssName() + " " : ""; + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleTypeProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleTypeProperty.java new file mode 100644 index 00000000..c1c6ece5 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleTypeProperty.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.ListStyleType; + +/** + * This property sets the type of the list-item marker. + */ +public class ListStyleTypeProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "listStyleType"; + + public static void init() { + CSS.LIST_STYLE_TYPE = new ListStyleTypeProperty(); + } + + private ListStyleTypeProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} 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 new file mode 100644 index 00000000..f9054f4c --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java @@ -0,0 +1,47 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +/** + * The margin property sets the margins of an element. + */ +public class MarginProperty extends AbstractCssProperty { + + private static String MARGIN_BOTTOM_PROPERTY = "marginBottom"; + private static String MARGIN_LEFT_PROPERTY = "marginLeft"; + private static String MARGIN_PROPERTY = "margin"; + private static String MARGIN_RIGHT_PROPERTY = "marginRight"; + private static String MARGIN_TOP_PROPERTY = "marginTop"; + + public static void init() { + CSS.MARGIN = new MarginProperty(MARGIN_PROPERTY); + CSS.MARGIN_LEFT = new MarginProperty(MARGIN_LEFT_PROPERTY); + CSS.MARGIN_RIGHT = new MarginProperty(MARGIN_RIGHT_PROPERTY); + CSS.MARGIN_TOP = new MarginProperty(MARGIN_TOP_PROPERTY); + CSS.MARGIN_BOTTOM = new MarginProperty(MARGIN_BOTTOM_PROPERTY); + } + + private String cssName; + + private MarginProperty(String cssName) { + this.cssName = cssName; + } + + public String getCssName() { + return cssName; + } + +} 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 new file mode 100644 index 00000000..085f5c57 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java @@ -0,0 +1,48 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +/** + * The padding properties define the space between the element border and the + * element content. + */ +public class PaddingProperty extends AbstractCssProperty { + + private static String PADDING_BOTTOM_PROPERTY = "paddingBottom"; + private static String PADDING_LEFT_PROPERTY = "paddingLeft"; + private static String PADDING_PROPERTY = "padding"; + private static String PADDING_RIGHT_PROPERTY = "paddingRight"; + private static String PADDING_TOP_PROPERTY = "paddingTop"; + + public static void init() { + CSS.PADDING = new PaddingProperty(PADDING_PROPERTY); + CSS.PADDING_LEFT = new PaddingProperty(PADDING_LEFT_PROPERTY); + CSS.PADDING_RIGHT = new PaddingProperty(PADDING_RIGHT_PROPERTY); + CSS.PADDING_TOP = new PaddingProperty(PADDING_TOP_PROPERTY); + CSS.PADDING_BOTTOM = new PaddingProperty(PADDING_BOTTOM_PROPERTY); + } + + private String cssName; + + private PaddingProperty(String cssName) { + this.cssName = cssName; + } + + public String getCssName() { + return cssName; + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Percentage.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Percentage.java deleted file mode 100644 index 7c9d0917..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Percentage.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; - -/** - * Percentage type constructors. - */ -public class Percentage extends JavaScriptObject { - - protected Percentage() { - } - - /** - * Size in percentage units. - */ - public static Percentage pct(int amt) { - return GWT.isScript() ? createWeb(amt + "%") : createHosted(amt + "%"); - } - - private static native Percentage createWeb(String pct) /*-{ - return pct; - }-*/; - - private static native Percentage createHosted(String pct) /*-{ - return [pct]; - }-*/; - - final public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; -} - diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/RGBColor.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/RGBColor.java index c73bc583..478db618 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/RGBColor.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/RGBColor.java @@ -15,73 +15,78 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.dom.client.Style.HasCssName; /** * Color type constructors. */ -public class RGBColor extends JavaScriptObject { +public class RGBColor implements HasCssName { - protected RGBColor() { - } + public static RGBColor AQUA; + public static RGBColor BLACK; + public static RGBColor FUSCHIA; + public static RGBColor GRAY; + public static RGBColor GREEN; + public static RGBColor INHERIT; + public static RGBColor LIME; + public static RGBColor MAROON; + public static RGBColor NAVY; + public static RGBColor OLIVE; + public static RGBColor ORANGE; + public static RGBColor PURPLE; + public static RGBColor RED; + public static RGBColor SILVER; + public static RGBColor TEAL; + public static RGBColor TRANSPARENT; + public static RGBColor WHITE; + public static RGBColor YELLOW; - public static void init() { - CSS.AQUA = rgb("aqua"); - CSS.BLACK = rgb("black"); - CSS.FUSCHIA = rgb("fuschia"); - CSS.GRAY = rgb("gray"); - CSS.GREEN = rgb("green"); - CSS.LIME = rgb("lime"); - CSS.MAROON = rgb("lime"); - CSS.NAVY = rgb("navy"); - CSS.OLIVE = rgb("olive"); - CSS.ORANGE = rgb("orange"); - CSS.PURPLE = rgb("purple"); - CSS.RED = rgb("red"); - CSS.SILVER = rgb("silver"); - CSS.TEAL = rgb("teal"); - CSS.WHITE = rgb("white"); - CSS.YELLOW = rgb("yellow"); - CSS.TRANSPARENT = rgb("transparent"); + static { + AQUA = rgb("aqua"); + BLACK = rgb("black"); + FUSCHIA = rgb("fuschia"); + GRAY = rgb("gray"); + GREEN = rgb("green"); + LIME = rgb("lime"); + MAROON = rgb("maroon"); + NAVY = rgb("navy"); + OLIVE = rgb("olive"); + ORANGE = rgb("orange"); + PURPLE = rgb("purple"); + RED = rgb("red"); + SILVER = rgb("silver"); + TEAL = rgb("teal"); + WHITE = rgb("white"); + YELLOW = rgb("yellow"); + TRANSPARENT = rgb("transparent"); + INHERIT = rgb(CSS.INHERIT_VALUE); } /** - * RGB color in hexidecimal. + * RGB color as r,g,b triple. */ - public static RGBColor rgb(String hex) { - return GWT.isScript() ? createWeb(hex) : createHosted(hex); + public static RGBColor rgb(int r, int g, int b) { + return new RGBColor(makeRgb(r, g, b)); } /** - * RGB color as r,g,b triple. + * RGB color in hexidecimal. */ - public static RGBColor rgb(int r, int g, int b) { - return GWT.isScript() ? createWeb(makeRgb(r, g, b)) - : createHosted(makeRgb(r, g, b)); + public static RGBColor rgb(String hex) { + return new RGBColor(hex); } private static String makeRgb(int r, int g, int b) { return "rgb(" + r + "," + g + "," + b + ")"; } - private static native RGBColor createWeb(String pct) /*-{ - return pct; - }-*/; + private String value; - private static native RGBColor createHosted(String pct) /*-{ - return [pct]; - }-*/; - - final public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); + private RGBColor(String value) { + this.value = value; } - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; + public String getCssName() { + return value; + } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakeCssValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakeCssValue.java new file mode 100644 index 00000000..ae02c1b0 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakeCssValue.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; + +/** + * An CSS property with values of type T. + */ +public interface TakeCssValue extends CssProperty { + + /** + * Set the style to the given value. + * + * @param value a value from the enumerated type T + */ + void set(Style s, T value); + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesLength.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesLength.java index e0b3c15b..b089a3bc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesLength.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesLength.java @@ -18,9 +18,11 @@ package com.google.gwt.query.client.css; import com.google.gwt.dom.client.Style; /** - * Interface to be implemented by properties which take length units. + * Interface to be implemented by properties which take length units in addition + * to an other type. If the properties takes only length units, please use + * {@link TakeCssValue} instead. */ public interface TakesLength { - void setLength(Style s, Length p); + void set(Style s, Length p); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlign.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlign.java deleted file mode 100644 index a8fb35b2..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlign.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; - -/** - * This property describes how inline content of a block is aligned. - */ -public class TextAlign implements CssProperty { - - public static void init() { - CSS.TEXT_ALIGN = new TextAlign(); - CSS.LEFT = TAlignValue.create("left"); - CSS.RIGHT = TAlignValue.create("right"); - CSS.CENTER = TAlignValue.create("center"); - CSS.JUSTIFY = TAlignValue.create("justify"); - } - - public void set(Style s, TAlignValue value) { - s.setProperty("textAlign", value.value()); - } - - public String get(Style s) { - return s.getProperty("textAlign"); - } - - final static public class TAlignValue extends JavaScriptObject { - - protected TAlignValue() { - } - - protected static TAlignValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private static native TAlignValue createWeb(String val) /*-{ - return val; - }-*/; - - private static native TAlignValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java new file mode 100644 index 00000000..52fa3fe2 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java @@ -0,0 +1,87 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.HasCssName; + +/** + * This property describes how inline content of a block is aligned. + */ +public class TextAlignProperty extends + AbstractCssProperty { + + public static enum TextAlign implements HasCssName { + /** + * Align the line box with the left side of the containing box. + */ + CENTER { + @Override + public String getCssName() { + return TEXT_ALIGN_CENTER; + } + }, + /** + * this property specifies that the inline boxes are to be made flush with + * both sides of the block. If the computed value of text-align is 'justify' + * while the computed value of white-space is 'pre' or 'pre-line', the + * actual value of text-align is set to the initial value. + */ + JUSTIFY { + @Override + public String getCssName() { + return TEXT_ALIGN_JUSTIFY; + } + }, + /** + * Align the line box with the left side of the containing box. + */ + LEFT { + @Override + public String getCssName() { + return TEXT_ALIGN_LEFT; + } + }, + /** + * Align the line box with the right side of the containing box. + */ + RIGHT { + @Override + public String getCssName() { + return TEXT_ALIGN_RIGHT; + } + }; + + public abstract String getCssName(); + } + private static final String CSS_PROPERTY = "textAlign"; + private static final String TEXT_ALIGN_CENTER = "center"; + private static final String TEXT_ALIGN_JUSTIFY = "justify"; + private static final String TEXT_ALIGN_LEFT = "left"; + + private static final String TEXT_ALIGN_RIGHT = "right"; + + public static void init() { + CSS.TEXT_ALIGN = new TextAlignProperty(); + } + + private TextAlignProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlign.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlign.java deleted file mode 100644 index 74fef491..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlign.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; -import static com.google.gwt.query.client.css.VerticalAlign.VAlignValue.create; - -/** - * This property affects the vertical positioning inside a line box of the boxes - * generated by an inline-level element. - */ -public class VerticalAlign - implements CssProperty, TakesPercentage, - TakesLength { - - public static void init() { - CSS.VERTICAL_ALIGN = new VerticalAlign(); - CSS.TOP = create("top"); - CSS.BOTTOM = create("bottom"); - CSS.BASELINE = create("baseline"); - CSS.SUB = create("sub"); - CSS.SUPER = create("super"); - CSS.TEXT_TOP = create("text-top"); - CSS.MIDDLE = create("middle"); - CSS.TEXT_BOTTOM = create("text-bottom"); - } - - public void set(Style s, VAlignValue value) { - s.setProperty("verticalAlign", value.value()); - } - - public String get(Style s) { - return s.getProperty("verticalAlign"); - } - - public void setPercentage(Style s, Percentage p) { - s.setProperty("verticalAlign", p.value()); - } - - public void setLength(Style s, Length p) { - s.setProperty("verticalAlign", p.value()); - } - - final static public class VAlignValue extends JavaScriptObject { - - protected VAlignValue() { - } - - protected static VAlignValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private static native VAlignValue createWeb(String val) /*-{ - return val; - }-*/; - - private static native VAlignValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java new file mode 100644 index 00000000..3ace339c --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java @@ -0,0 +1,45 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.VerticalAlign; + +/** + * This property affects the vertical positioning inside a line box of the boxes + * generated by an inline-level element. + */ +public class VerticalAlignProperty extends AbstractCssProperty + implements TakesLength { + + private static final String CSS_PROPERTY = "verticalAlign"; + + public static void init() { + CSS.VERTICAL_ALIGN = new VerticalAlignProperty(); + } + + private VerticalAlignProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } + + public void set(Style s, Length p) { + s.setProperty(CSS_PROPERTY, p.getCssName()); + } + +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Visibility.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Visibility.java deleted file mode 100644 index 1f6fabc8..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Visibility.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client.css; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.dom.client.Style; - -/** - * The 'visibility' property specifies whether the boxes generated by an element - * are rendered. Invisible boxes still affect layout (set the 'display' property - * to 'none' to suppress box generation altogether). Values have the following - * meanings: - */ -public class Visibility implements CssProperty { - - public static void init() { - CSS.VISIBILITY = new Visibility(); - CSS.VISIBLE = VisibilityValue.create("visible"); - CSS.HIDDEN = VisibilityValue.create("hidden"); - CSS.COLLAPSE = VisibilityValue.create("collapse"); - } - - public void set(Style s, VisibilityValue value) { - s.setProperty("visibility", value.value()); - } - - public String get(Style s) { - return s.getProperty("visibilityat"); - } - - final static public class VisibilityValue extends JavaScriptObject { - - protected VisibilityValue() { - } - - protected static VisibilityValue create(String val) { - return GWT.isScript() ? createWeb(val) : createHosted(val); - } - - public String value() { - return GWT.isScript() ? valueWeb() : valueHosted(); - } - - private static native VisibilityValue createWeb(String val) /*-{ - return val; - }-*/; - - private static native VisibilityValue createHosted(String val) /*-{ - return [val]; - }-*/; - - private native String valueWeb() /*-{ - return this; - }-*/; - - private native String valueHosted() /*-{ - return this[0]; - }-*/; - } -} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java new file mode 100644 index 00000000..97cdaa4f --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java @@ -0,0 +1,40 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client.css; + +import com.google.gwt.dom.client.Style.Visibility; + +/** + * The 'visibility' property specifies whether the boxes generated by an element + * are rendered. Invisible boxes still affect layout (set the 'display' property + * to 'none' to suppress box generation altogether). Values have the following + * meanings: + */ +public class VisibilityProperty extends AbstractCssProperty { + + private static final String CSS_PROPERTY = "visibility"; + + public static void init() { + CSS.VISIBILITY = new VisibilityProperty(); + } + + private VisibilityProperty() { + } + + public String getCssName() { + return CSS_PROPERTY; + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Width.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java similarity index 73% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/css/Width.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java index f7c23ccf..a3c52cb4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/Width.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java @@ -15,40 +15,32 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.dom.client.Style; - /** * This property specifies the content width of boxes generated by block-level * and replaced elements. - * + * * This property does not apply to non-replaced inline-level elements. The * content width of a non-replaced inline element's boxes is that of the * rendered content within them (before any relative offset of children). Recall * that inline boxes flow into line boxes. The width of line boxes is given by * the their containing block, but may be shorted by the presence of floats. - * + * * The width of a replaced element's box is intrinsic and may be scaled by the * user agent if the value of this property is different than 'auto'. */ -public class Width implements TakesLength, TakesPercentage { +public class WidthProperty extends AbstractCssProperty { - public static void init() { - CSS.WIDTH = new Width(); - } + private static final String CSS_PROPERTY = "width"; - public void set(Style s, Length value) { - s.setProperty("width", value.value()); + public static void init() { + CSS.WIDTH = new WidthProperty(); } - public String get(Style s) { - return s.getProperty("width"); + private WidthProperty() { } - public void setLength(Style s, Length p) { - s.setProperty("width", p.value()); + public String getCssName() { + return CSS_PROPERTY; } - public void setPercentage(Style s, Percentage p) { - s.setProperty("width", p.value()); - } } 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 new file mode 100644 index 00000000..e11fbe83 --- /dev/null +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java @@ -0,0 +1,708 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client; + +import static com.google.gwt.query.client.GQuery.$; + +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Style.Cursor; +import com.google.gwt.dom.client.Style.Display; +import com.google.gwt.dom.client.Style.Float; +import com.google.gwt.dom.client.Style.FontStyle; +import com.google.gwt.dom.client.Style.ListStyleType; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.dom.client.Style.VerticalAlign; +import com.google.gwt.dom.client.Style.Visibility; +import com.google.gwt.junit.client.GWTTestCase; +import com.google.gwt.query.client.css.CSS; +import com.google.gwt.query.client.css.ImageValue; +import com.google.gwt.query.client.css.Length; +import com.google.gwt.query.client.css.RGBColor; +import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment; +import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition; +import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat; +import com.google.gwt.query.client.css.BorderStyleProperty.BorderStyle; +import com.google.gwt.query.client.css.BorderWidthProperty.BorderWidth; +import com.google.gwt.query.client.css.FontSizeProperty.FontSize; +import com.google.gwt.query.client.css.FontVariantProperty.FontVariant; +import com.google.gwt.query.client.css.ListStylePositionProperty.ListStylePosition; +import com.google.gwt.query.client.css.TextAlignProperty.TextAlign; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.RootPanel; + +/** + * Test class for testing css part. + */ +public class GQueryCssTest extends GWTTestCase { + + static Element e = null; + + static HTML testPanel = null; + + public String getModuleName() { + return "com.google.gwt.query.Query"; + } + + public void gwtSetUp() { + if (e == null) { + testPanel = new HTML(); + RootPanel.get().add(testPanel); + e = testPanel.getElement(); + e.setId("core-tst"); + } else { + e.setInnerHTML(""); + } + } + + public void testBackgroundAttachmentProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BACKGROUND_ATTACHMENT, BackgroundAttachment.FIXED); + + assertEquals("fixed", $("#test").css("backgroundAttachment")); + assertEquals("fixed", $("#test").css(CSS.BACKGROUND_ATTACHMENT)); + + $("#test").css(CSS.BACKGROUND_ATTACHMENT, BackgroundAttachment.SCROLL); + + assertEquals("scroll", $("#test").css("backgroundAttachment")); + assertEquals("scroll", $("#test").css(CSS.BACKGROUND_ATTACHMENT)); + + } + + public void testBackgroundColorProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BACKGROUND_COLOR, RGBColor.AQUA); + + assertEquals("aqua", $("#test").css("backgroundColor")); + assertEquals("aqua", $("#test").css(CSS.BACKGROUND_COLOR)); + + $("#test").css(CSS.BACKGROUND_COLOR, RGBColor.rgb("#112233")); + + assertEquals("#112233", $("#test").css("backgroundColor")); + assertEquals("#112233", $("#test").css(CSS.BACKGROUND_COLOR)); + + $("#test").css(CSS.BACKGROUND_COLOR, RGBColor.rgb(35, 45, 55)); + assertEquals("rgb(35,45,55)", $("#test").css("backgroundColor")); + assertEquals("rgb(35,45,55)", $("#test").css(CSS.BACKGROUND_COLOR)); + + } + + public void testBackgroundImageProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BACKGROUND_IMAGE, ImageValue.url("image.jpg")); + + assertEquals("url('image.jpg')", $("#test").css("backgroundImage")); + assertEquals("url('image.jpg')", $("#test").css(CSS.BACKGROUND_IMAGE)); + } + + public void testBackgroundPositionProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.CENTER); + assertEquals("center", $("#test").css("backgroundPosition")); + assertEquals("center", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.CENTER_CENTER); + assertEquals("center center", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.CENTER_TOP); + assertEquals("center top", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.CENTER_BOTTOM); + assertEquals("center bottom", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.LEFT); + assertEquals("left", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.LEFT_TOP); + assertEquals("left top", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.LEFT_CENTER); + assertEquals("left center", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.LEFT_BOTTOM); + assertEquals("left bottom", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.RIGHT); + assertEquals("right", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.RIGHT_TOP); + assertEquals("right top", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.RIGHT_CENTER); + assertEquals("right center", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, BackgroundPosition.RIGHT_BOTTOM); + assertEquals("right bottom", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, + BackgroundPosition.position(12, 12, Unit.PX)); + assertEquals("12px 12px", $("#test").css(CSS.BACKGROUND_POSITION)); + + $("#test").css(CSS.BACKGROUND_POSITION, + BackgroundPosition.position(12, 12, Unit.PCT)); + assertEquals("12% 12%", $("#test").css(CSS.BACKGROUND_POSITION)); + + } + + public void testBackgroundProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BACKGROUND, RGBColor.TRANSPARENT, + ImageValue.url("back.jpg"), BackgroundRepeat.NO_REPEAT, + BackgroundAttachment.SCROLL, BackgroundPosition.CENTER); + assertEquals("transparent url('back.jpg') no-repeat scroll center", $( + "#test").css("background")); + assertEquals("transparent url('back.jpg') no-repeat scroll center", $( + "#test").css(CSS.BACKGROUND)); + + } + + public void testBackgroundRepeatProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BACKGROUND_REPEAT, BackgroundRepeat.REPEAT_X); + + assertEquals("repeat-x", $("#test").css("backgroundRepeat")); + assertEquals("repeat-x", $("#test").css(CSS.BACKGROUND_REPEAT)); + } + + public void testBorderColorProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BORDER_COLOR, RGBColor.AQUA); + assertEquals("aqua", $("#test").css("borderColor")); + assertEquals("aqua", $("#test").css(CSS.BORDER_COLOR)); + + $("#test").css(CSS.BORDER_BOTTOM_COLOR, RGBColor.BLACK); + assertEquals("black", $("#test").css("borderBottomColor")); + assertEquals("black", $("#test").css(CSS.BORDER_BOTTOM_COLOR)); + + $("#test").css(CSS.BORDER_TOP_COLOR, RGBColor.FUSCHIA); + assertEquals("fuschia", $("#test").css("borderTopColor")); + assertEquals("fuschia", $("#test").css(CSS.BORDER_TOP_COLOR)); + + $("#test").css(CSS.BORDER_LEFT_COLOR, RGBColor.GRAY); + assertEquals("gray", $("#test").css("borderLeftColor")); + assertEquals("gray", $("#test").css(CSS.BORDER_LEFT_COLOR)); + + $("#test").css(CSS.BORDER_RIGHT_COLOR, RGBColor.WHITE); + assertEquals("white", $("#test").css("borderRightColor")); + assertEquals("white", $("#test").css(CSS.BORDER_RIGHT_COLOR)); + + } + + public void testBorderProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BORDER, BorderWidth.THICK, BorderStyle.DASHED, + RGBColor.BLACK); + assertEquals("thick dashed black", $("#test").css("border")); + assertEquals("thick dashed black", $("#test").css(CSS.BORDER)); + + $("#test").css(CSS.BORDER, BorderWidth.length(15, Unit.PX), + BorderStyle.SOLID, RGBColor.rgb("#000000")); + assertEquals("15px solid #000000", $("#test").css("border")); + assertEquals("15px solid #000000", $("#test").css(CSS.BORDER)); + + } + + public void testBorderStyleProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BORDER_STYLE, BorderStyle.DOTTED); + assertEquals("dotted", $("#test").css("borderStyle")); + assertEquals("dotted", $("#test").css(CSS.BORDER_STYLE)); + + $("#test").css(CSS.BORDER_BOTTOM_STYLE, BorderStyle.DASHED); + assertEquals("dashed", $("#test").css("borderBottomStyle")); + assertEquals("dashed", $("#test").css(CSS.BORDER_BOTTOM_STYLE)); + + $("#test").css(CSS.BORDER_TOP_STYLE, BorderStyle.DOUBLE); + assertEquals("double", $("#test").css("borderTopStyle")); + assertEquals("double", $("#test").css(CSS.BORDER_TOP_STYLE)); + + $("#test").css(CSS.BORDER_LEFT_STYLE, BorderStyle.HIDDEN); + assertEquals("hidden", $("#test").css("borderLeftStyle")); + assertEquals("hidden", $("#test").css(CSS.BORDER_LEFT_STYLE)); + + $("#test").css(CSS.BORDER_RIGHT_STYLE, BorderStyle.SOLID); + assertEquals("solid", $("#test").css("borderRightStyle")); + assertEquals("solid", $("#test").css(CSS.BORDER_RIGHT_STYLE)); + + } + + public void testBorderWidthProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.BORDER_WIDTH, BorderWidth.MEDIUM); + assertEquals("medium", $("#test").css("borderWidth")); + assertEquals("medium", $("#test").css(CSS.BORDER_WIDTH)); + + $("#test").css(CSS.BORDER_WIDTH, Length.px(15)); + assertEquals("15px", $("#test").css(CSS.BORDER_WIDTH)); + + $("#test").css(CSS.BORDER_WIDTH, BorderWidth.length(Length.px(20))); + assertEquals("20px", $("#test").css(CSS.BORDER_WIDTH)); + + $("#test").css(CSS.BORDER_WIDTH, BorderWidth.length(20, Unit.MM)); + assertEquals("20mm", $("#test").css(CSS.BORDER_WIDTH)); + + $("#test").css(CSS.BORDER_BOTTOM_WIDTH, BorderWidth.THICK); + assertEquals("thick", $("#test").css("borderBottomWidth")); + assertEquals("thick", $("#test").css(CSS.BORDER_BOTTOM_WIDTH)); + + $("#test").css(CSS.BORDER_TOP_WIDTH, BorderWidth.THIN); + assertEquals("thin", $("#test").css("borderTopWidth")); + assertEquals("thin", $("#test").css(CSS.BORDER_TOP_WIDTH)); + + $("#test").css(CSS.BORDER_LEFT_WIDTH, BorderWidth.THIN); + assertEquals("thin", $("#test").css("borderLeftWidth")); + assertEquals("thin", $("#test").css(CSS.BORDER_LEFT_WIDTH)); + + $("#test").css(CSS.BORDER_RIGHT_WIDTH, BorderWidth.THICK); + assertEquals("thick", $("#test").css("borderRightWidth")); + assertEquals("thick", $("#test").css(CSS.BORDER_RIGHT_WIDTH)); + + } + + public void testColorProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.COLOR, RGBColor.AQUA); + + assertEquals("aqua", $("#test").css("color")); + assertEquals("aqua", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.rgb("#112233")); + + assertEquals("#112233", $("#test").css("color")); + assertEquals("#112233", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.rgb(35, 45, 55)); + assertEquals("rgb(35,45,55)", $("#test").css("color")); + assertEquals("rgb(35,45,55)", $("#test").css(CSS.COLOR)); + + } + + public void testColorValue() { + + $(e).html("
Content
"); + + $("#test").css(CSS.COLOR, RGBColor.AQUA); + assertEquals("aqua", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.BLACK); + assertEquals("black", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.FUSCHIA); + assertEquals("fuschia", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.GRAY); + assertEquals("gray", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.GREEN); + assertEquals("green", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.INHERIT); + assertEquals("inherit", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.LIME); + assertEquals("lime", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.MAROON); + assertEquals("maroon", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.NAVY); + assertEquals("navy", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.OLIVE); + assertEquals("olive", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.ORANGE); + assertEquals("orange", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.PURPLE); + assertEquals("purple", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.RED); + assertEquals("red", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.SILVER); + assertEquals("silver", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.TEAL); + assertEquals("teal", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.TRANSPARENT); + assertEquals("transparent", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.WHITE); + assertEquals("white", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.YELLOW); + assertEquals("yellow", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.rgb("#112233")); + assertEquals("#112233", $("#test").css(CSS.COLOR)); + + $("#test").css(CSS.COLOR, RGBColor.rgb(35, 45, 55)); + assertEquals("rgb(35,45,55)", $("#test").css(CSS.COLOR)); + + } + + public void testCursorProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.CURSOR, Cursor.WAIT); + + assertEquals("wait", $("#test").css("cursor")); + assertEquals("wait", $("#test").css(CSS.CURSOR)); + + } + + public void testDisplayProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.DISPLAY, Display.INLINE); + + assertEquals("inline", $("#test").css("display")); + assertEquals("inline", $("#test").css(CSS.DISPLAY)); + + } + + public void testFloatProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.FLOAT, Float.LEFT); + + assertEquals("left", $("#test").css("float")); + assertEquals("left", $("#test").css(CSS.FLOAT)); + + } + + public void testFontSizeProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.FONT_SIZE, FontSize.LARGER); + assertEquals("larger", $("#test").css("fontSize")); + assertEquals("larger", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.LARGE); + assertEquals("large", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.MEDIUM); + assertEquals("medium", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.SMALL); + assertEquals("small", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.SMALLER); + assertEquals("smaller", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.X_LARGE); + assertEquals("x-large", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.X_SMALL); + assertEquals("x-small", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.XX_LARGE); + assertEquals("xx-large", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, FontSize.XX_SMALL); + assertEquals("xx-small", $("#test").css(CSS.FONT_SIZE)); + + $("#test").css(CSS.FONT_SIZE, Length.px(16)); + assertEquals("16px", $("#test").css(CSS.FONT_SIZE)); + } + + public void testFontStyleProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.FONT_STYLE, FontStyle.ITALIC); + assertEquals("italic", $("#test").css("fontStyle")); + assertEquals("italic", $("#test").css(CSS.FONT_STYLE)); + + } + + public void testFontVariantProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.FONT_VARIANT, FontVariant.SMALL_CAPS); + assertEquals("small-caps", $("#test").css("fontVariant")); + assertEquals("small-caps", $("#test").css(CSS.FONT_VARIANT)); + + } + + public void testHeightProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.HEIGHT, Length.px(10)); + + assertEquals("10px", $("#test").css("height")); + assertEquals("10px", $("#test").css(CSS.HEIGHT)); + } + + public void testLengthValue() { + + $(e).html("
Content
"); + + $("#test").css(CSS.HEIGHT, Length.px(10)); + assertEquals("10px", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.cm(10)); + assertEquals("10cm", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.em(10)); + assertEquals("10em", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.ex(10)); + assertEquals("10ex", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.in(10)); + assertEquals("10in", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.mm(10)); + assertEquals("10mm", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.pc(10)); + assertEquals("10pc", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.pct(10)); + assertEquals("10%", $("#test").css(CSS.HEIGHT)); + + $("#test").css(CSS.HEIGHT, Length.pt(10)); + assertEquals("10pt", $("#test").css(CSS.HEIGHT)); + + } + + public void testListStyleImageProperty() { + + $(e).html("
  • Content
"); + + $("#test").css(CSS.LIST_STYLE_IMAGE, ImageValue.url("arrow.jpg")); + assertEquals("url('arrow.jpg')", $("#test").css("listStyleImage")); + assertEquals("url('arrow.jpg')", $("#test").css(CSS.LIST_STYLE_IMAGE)); + + } + + public void testListStylePositionProperty() { + + $(e).html("
  • Content
"); + + $("#test").css(CSS.LIST_STYLE_POSITION, ListStylePosition.INSIDE); + assertEquals("inside", $("#test").css("listStylePosition")); + assertEquals("inside", $("#test").css(CSS.LIST_STYLE_POSITION)); + + $("#test").css(CSS.LIST_STYLE_POSITION, ListStylePosition.OUTSIDE); + assertEquals("outside", $("#test").css("listStylePosition")); + assertEquals("outside", $("#test").css(CSS.LIST_STYLE_POSITION)); + + } + + public void testListStyleTypeProperty() { + + $(e).html("
  • Content
"); + + $("#test").css(CSS.LIST_STYLE_TYPE, ListStyleType.DISC); + assertEquals("disc", $("#test").css("listStyleType")); + assertEquals("disc", $("#test").css(CSS.LIST_STYLE_TYPE)); + + } + + public void testListStyleProperty() { + + $(e).html("
  • Content
"); + + $("#test").css(CSS.LIST_STYLE, ListStyleType.DISC, ListStylePosition.OUTSIDE, ImageValue.NONE); + assertEquals("disc outside none", $("#test").css("listStyle")); + assertEquals("disc outside none", $("#test").css(CSS.LIST_STYLE)); + + $("#test").css(CSS.LIST_STYLE, ListStyleType.DISC, null, ImageValue.NONE); + assertEquals("disc none", $("#test").css("listStyle")); + assertEquals("disc none", $("#test").css(CSS.LIST_STYLE)); + + $("#test").css(CSS.LIST_STYLE, null, ListStylePosition.OUTSIDE, ImageValue.NONE); + assertEquals("outside none", $("#test").css("listStyle")); + assertEquals("outside none", $("#test").css(CSS.LIST_STYLE)); + + } + + public void testMarginProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.MARGIN, Length.px(10)); + + assertEquals("10px", $("#test").css("margin")); + assertEquals("10px", $("#test").css(CSS.MARGIN)); + + $("#test").css(CSS.MARGIN_TOP, Length.px(20)); + + assertEquals("20px", $("#test").css("marginTop")); + assertEquals("20px", $("#test").css(CSS.MARGIN_TOP)); + + $("#test").css(CSS.MARGIN_BOTTOM, Length.px(30)); + + assertEquals("30px", $("#test").css("marginBottom")); + assertEquals("30px", $("#test").css(CSS.MARGIN_BOTTOM)); + + $("#test").css(CSS.MARGIN_LEFT, Length.px(40)); + + assertEquals("40px", $("#test").css("marginLeft")); + assertEquals("40px", $("#test").css(CSS.MARGIN_LEFT)); + + $("#test").css(CSS.MARGIN_RIGHT, Length.px(50)); + + assertEquals("50px", $("#test").css("marginRight")); + assertEquals("50px", $("#test").css(CSS.MARGIN_RIGHT)); + } + + public void testPaddingProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.PADDING, Length.px(10)); + + assertEquals("10px", $("#test").css("padding")); + assertEquals("10px", $("#test").css(CSS.PADDING)); + + $("#test").css(CSS.PADDING_TOP, Length.px(20)); + + assertEquals("20px", $("#test").css("paddingTop")); + assertEquals("20px", $("#test").css(CSS.PADDING_TOP)); + + $("#test").css(CSS.PADDING_BOTTOM, Length.px(30)); + + assertEquals("30px", $("#test").css("paddingBottom")); + assertEquals("30px", $("#test").css(CSS.PADDING_BOTTOM)); + + $("#test").css(CSS.PADDING_LEFT, Length.px(40)); + + assertEquals("40px", $("#test").css("paddingLeft")); + assertEquals("40px", $("#test").css(CSS.PADDING_LEFT)); + + $("#test").css(CSS.PADDING_RIGHT, Length.px(50)); + + assertEquals("50px", $("#test").css("paddingRight")); + assertEquals("50px", $("#test").css(CSS.PADDING_RIGHT)); + } + + public void testTextAlignProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.TEXT_ALIGN, TextAlign.CENTER); + assertEquals("center", $("#test").css("textAlign")); + assertEquals("center", $("#test").css(CSS.TEXT_ALIGN)); + + $("#test").css(CSS.TEXT_ALIGN, TextAlign.JUSTIFY); + assertEquals("justify", $("#test").css("textAlign")); + assertEquals("justify", $("#test").css(CSS.TEXT_ALIGN)); + + $("#test").css(CSS.TEXT_ALIGN, TextAlign.LEFT); + assertEquals("left", $("#test").css("textAlign")); + assertEquals("left", $("#test").css(CSS.TEXT_ALIGN)); + + $("#test").css(CSS.TEXT_ALIGN, TextAlign.RIGHT); + assertEquals("right", $("#test").css("textAlign")); + assertEquals("right", $("#test").css(CSS.TEXT_ALIGN)); + + } + + public void testVerticalAlignProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.BASELINE); + assertEquals("baseline", $("#test").css("verticalAlign")); + assertEquals("baseline", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.BOTTOM); + assertEquals("bottom", $("#test").css("verticalAlign")); + assertEquals("bottom", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.MIDDLE); + assertEquals("middle", $("#test").css("verticalAlign")); + assertEquals("middle", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.SUB); + assertEquals("sub", $("#test").css("verticalAlign")); + assertEquals("sub", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.SUPER); + assertEquals("super", $("#test").css("verticalAlign")); + assertEquals("super", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.TEXT_BOTTOM); + assertEquals("text-bottom", $("#test").css("verticalAlign")); + assertEquals("text-bottom", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.TEXT_TOP); + assertEquals("text-top", $("#test").css("verticalAlign")); + assertEquals("text-top", $("#test").css(CSS.VERTICAL_ALIGN)); + + $("#test").css(CSS.VERTICAL_ALIGN, VerticalAlign.TOP); + assertEquals("top", $("#test").css("verticalAlign")); + assertEquals("top", $("#test").css(CSS.VERTICAL_ALIGN)); + + } + + public void testVisibilityProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.VISIBILITY, Visibility.HIDDEN); + assertEquals("hidden", $("#test").css("visibility")); + assertEquals("hidden", $("#test").css(CSS.VISIBILITY)); + + $("#test").css(CSS.VISIBILITY, Visibility.VISIBLE); + assertEquals("visible", $("#test").css("visibility")); + assertEquals("visible", $("#test").css(CSS.VISIBILITY)); + + } + + public void testWidthProperty() { + + $(e).html("
Content
"); + + $("#test").css(CSS.WIDTH, Length.px(20)); + assertEquals("20px", $("#test").css("width")); + assertEquals("20px", $("#test").css(CSS.WIDTH)); + + } + +} diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java index 4dea5f52..bc1936b6 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java @@ -26,6 +26,7 @@ import com.google.gwt.junit.DoNotRunWith; import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.css.CSS; +import com.google.gwt.query.client.css.RGBColor; import com.google.gwt.query.client.plugins.Events; import com.google.gwt.query.client.plugins.EventsListener; import com.google.gwt.user.client.Event; @@ -191,7 +192,7 @@ public class GQueryEventsTest extends GWTTestCase { $(e).click(); assertEquals("red", $(e).css("color")); - $(e).click(lazy().css(CSS.COLOR, CSS.BLACK).done()); + $(e).click(lazy().css(CSS.COLOR, RGBColor.BLACK).done()); $(e).click(); assertEquals("black", $(e).css("color")); } -- 2.39.5