Adding a new CommonResources class that provides access to commonly used styles in GWT. For now, the only style defined is a cross browser implementation of inline block, but we can expand to include more common styles later. Review at http://gwt-code-reviews.appspot.com/1106801 Review by: sbrubaker@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9228 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/resources/client/CommonResources.java b/user/src/com/google/gwt/resources/client/CommonResources.java new file mode 100644 index 0000000..6987bea --- /dev/null +++ b/user/src/com/google/gwt/resources/client/CommonResources.java
@@ -0,0 +1,71 @@ +/* + * Copyright 2010 Google Inc. + * + * 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.resources.client; + +import com.google.gwt.core.client.GWT; + +/** + * Generally useful styles and resources used throughout GWT widgets and cells. + */ +public class CommonResources { + + /** + * The {@link ClientBundle} of resources. + */ + static interface Bundle extends ClientBundle { + + @Source("inline-block.css") + InlineBlockStyle inlineBlockStyle(); + } + + /** + * Cross-browser implementation of the "display: inline-block" CSS property. + */ + static interface InlineBlockStyle extends CssResource { + + /** + * The inline block style. + */ + String inlineBlock(); + } + + /** + * Lazily loaded singleton. + */ + private static Bundle instance; + + /** + * Ensure that the shared {@link Bundle} is created and return it. + * + * @return the {@link Bundle} of resources + */ + private static Bundle ensureResources() { + if (instance == null) { + instance = GWT.create(Bundle.class); + } + return instance; + } + + /** + * Get the style class name that simulates a "display: inline-block" effect + * across browsers. + */ + public static String getInlineBlockStyle() { + InlineBlockStyle style = ensureResources().inlineBlockStyle(); + style.ensureInjected(); + return style.inlineBlock(); + } +}
diff --git a/user/src/com/google/gwt/resources/client/inline-block.css b/user/src/com/google/gwt/resources/client/inline-block.css new file mode 100644 index 0000000..2aa4767 --- /dev/null +++ b/user/src/com/google/gwt/resources/client/inline-block.css
@@ -0,0 +1,59 @@ +/* + * Copyright 2010 Google Inc. + * + * 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. + */ + +/* + * Cross-browser implementation of the "display: inline-block" CSS property. + * See http://www.w3.org/TR/CSS21/visuren.html#propdef-display for details. + * Tested on IE 6 & 7, FF 2.0 & 3.0, Safari 2 & 3, Webkit, Chrome and Opera 9. + * + * Original author: attila@google.com (Attila Bodis) + */ + +/* + * Firefox hack is needed for versions < FF3. But since the user.agent property + * does not allow us to specify directly for (versions < FF3), we will need to + * use the following two rules to workaround. + */ +/* Firefox versions >= FF 1.5 */ +@if user.agent gecko1_8 { + .inlineBlock { + /* + * Note on funny syntax: what we really need is this: "display: -moz-inline-box;" + * but "\\" is needed to make GWT's CssResource escape the "-" character properly. + */ + display: \\-moz-inline-box; /* This is ignored by FF3 and later*/ + } +} + +/* Default rule; only Safari, Webkit, Opera, FF3 handle it without hacks. */ +.inlineBlock { + position: relative; + display: inline-block; +} + +/* + * IE specific rules (for IE version IE6/7) + * On IE, "display: inline-block" only gives the element layout, but doesn't + * give it inline behavior. Subsequently setting display to inline does the + * trick. + */ +@if user.agent ie6 { + .inlineBlock { + /* workaround to make IE "hasLayout" */ + zoom: 1; + display: inline; + } +}