You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/11/04 12:56:17 UTC

svn commit: r832711 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/config/ core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ core/src/main/java/org/apache/myfaces/tobago/webapp/ sandbox/src/main/java/org/apache/myfa...

Author: lofwyr
Date: Wed Nov  4 11:56:16 2009
New Revision: 832711

URL: http://svn.apache.org/viewvc?rev=832711&view=rev
Log:
TOBAGO-812: Refactor Style Handling of components: Don't put style in the component attributes

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/config/ThemeConfig.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
    myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/config/ThemeConfig.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/config/ThemeConfig.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/config/ThemeConfig.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/config/ThemeConfig.java Wed Nov  4 11:56:16 2009
@@ -71,6 +71,27 @@
     }
   }
 
+  public static Measure getMeasure(FacesContext facesContext, String rendererType, String name) {
+    CacheKey key = new CacheKey(facesContext.getViewRoot(), rendererType, name);
+    Map<CacheKey, Integer> cache
+        = (Map<CacheKey, Integer>) facesContext.getExternalContext().getApplicationMap().get(THEME_CONFIG_CACHE);
+
+    Integer value = cache.get(key);
+    if (value == null) {
+      ResourceManager resourceManager = ResourceManagerFactory.getResourceManager(facesContext);
+      UIViewRoot viewRoot = facesContext.getViewRoot();
+      String property = resourceManager.getThemeProperty(viewRoot, "tobago-theme-config", rendererType + "." + name);
+      if (property != null) {
+        value = new Integer(property); // todo: Measure
+      }
+      cache.put(key, value);
+    }
+    if (value != null) {
+      return new PixelMeasure(value);
+    }
+    return null;
+  }
+
   private static int getValue0(FacesContext facesContext, UIComponent component, String name) {
     CacheKey key = new CacheKey(facesContext.getViewRoot(), component, name);
     Map<CacheKey, Integer> cache
@@ -165,6 +186,17 @@
       this.name = name;
     }
 
+    public CacheKey(UIViewRoot viewRoot, String rendererType, String name) {
+      this.clientProperties = ClientProperties.getInstance(viewRoot).getId();
+      this.locale = viewRoot.getLocale();
+      if (rendererType != null) {
+        this.rendererType = rendererType;
+      } else {
+        this.rendererType = "DEFAULT";
+      }
+      this.name = name;
+    }
+
     @Override
     public boolean equals(Object o) {
       if (this == o) {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java Wed Nov  4 11:56:16 2009
@@ -17,9 +17,13 @@
  * limitations under the License.
  */
 
+import org.apache.myfaces.tobago.config.ThemeConfig;
 import org.apache.myfaces.tobago.layout.Display;
+import org.apache.myfaces.tobago.layout.LayoutComponent;
 import org.apache.myfaces.tobago.layout.Measure;
+import org.apache.myfaces.tobago.renderkit.css.CssProperties;
 
+import javax.faces.context.FacesContext;
 import java.io.Serializable;
 
 public class HtmlStyleMap implements Serializable {
@@ -54,6 +58,42 @@
     this.paddingBottom = map.paddingBottom;
   }
 
+//  public HtmlStyleMap(FacesContext facesContext, UIComponent component) {
+//    this(facesContext, (LayoutComponent)component);
+//  }
+  
+  public HtmlStyleMap(FacesContext facesContext, LayoutComponent layout) {
+
+    String rendererType = layout.getRendererType();
+    
+    width = layout.getWidth();
+    if (width != null) {
+      // TODO: Make configurable: this is needed if the box-sizing is border-box, not content-box (see CSS3)
+      width = width.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.border-left-width"));
+      width = width.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.padding-left"));
+      width = width.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.padding-right"));
+      width = width.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.border-right-width"));
+    }
+    height = layout.getHeight();
+    if (height != null) {
+      // TODO: Make configurable: this is needed if the box-sizing is border-box, not content-box (see CSS3)
+      height = height.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.border-top-width"));
+      height = height.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.padding-top"));
+      height = height.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.padding-bottom"));
+      height = height.substractNotNegative(ThemeConfig.getMeasure(facesContext, rendererType, "css.border-bottom-width"));
+    }
+    this.left = layout.getLeft();
+    this.top = layout.getTop();
+
+    // if there are a position coordinates, activate absolute positioning
+    // XXX String "Page" is not nice here
+    if ((left != null || top != null) && !rendererType.contains("Page")) {
+      position = CssProperties.Position.ABSOLUTE;
+    }
+
+    display = layout.getDisplay();
+  }
+
   public String encode() {
     StringBuilder buf = new StringBuilder();
     if (width != null) {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java Wed Nov  4 11:56:16 2009
@@ -154,6 +154,7 @@
   /**
    * Write the style attribute. The value will not escaped.
    */
+  @Deprecated
   public abstract void writeStyleAttribute() throws IOException;
 
   public void writeJavascript(String script) throws IOException {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java Wed Nov  4 11:56:16 2009
@@ -399,6 +399,7 @@
     }
   }
 
+  @Deprecated
   public void writeStyleAttribute() throws IOException {
 
     HtmlStyleMap styles = (HtmlStyleMap) component.getAttributes().get(Attributes.STYLE);
@@ -410,6 +411,7 @@
     }
   }
 
+  @Deprecated
   private HtmlStyleMap addLayout(HtmlStyleMap styles) {
     if (component instanceof LayoutComponent) {
       LayoutComponent layoutComponent = (LayoutComponent) component;

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java Wed Nov  4 11:56:16 2009
@@ -18,7 +18,7 @@
  */
 
 import org.apache.myfaces.tobago.TobagoConstants;
-import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.UIInputNumberSlider;
 import org.apache.myfaces.tobago.config.ThemeConfig;
 import org.apache.myfaces.tobago.context.ResourceManager;
 import org.apache.myfaces.tobago.context.ResourceManagerFactory;
@@ -54,20 +54,21 @@
 
   public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
 
-    String id = component.getClientId(facesContext);
-    String currentValue = getCurrentValue(facesContext, component);
-    boolean readonly = ComponentUtils.getBooleanAttribute(component, Attributes.READONLY);
-    boolean disabled = ComponentUtils.getBooleanAttribute(component, Attributes.DISABLED);
-    Integer min = ComponentUtils.getIntAttribute(component, "min");
-    Integer max = ComponentUtils.getIntAttribute(component, "max");
+    UIInputNumberSlider slider = (UIInputNumberSlider) component;
+    
+    String id = slider.getClientId(facesContext);
+    String currentValue = getCurrentValue(facesContext, slider);
+    boolean readonly = slider.isReadonly();
+    boolean disabled = slider.isDisabled();
+    Integer min = ComponentUtils.getIntAttribute(slider, "min");
+    Integer max = ComponentUtils.getIntAttribute(slider, "max");
     TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
 
-
-    HtmlStyleMap style = HtmlRendererUtils.ensureStyleAttributeMap(component);
+    HtmlStyleMap style = new HtmlStyleMap(facesContext, slider);
     int width = -1;
     int sliderWidthPerc = 33;
-    if (ThemeConfig.hasValue(facesContext, component, SLIDER_WIDTH_PERCENT)) {
-      sliderWidthPerc = ThemeConfig.getValue(facesContext, component, SLIDER_WIDTH_PERCENT);
+    if (ThemeConfig.hasValue(facesContext, slider, SLIDER_WIDTH_PERCENT)) {
+      sliderWidthPerc = ThemeConfig.getValue(facesContext, slider, SLIDER_WIDTH_PERCENT);
       if (sliderWidthPerc <= 25) {
         sliderWidthPerc = 25;
       }
@@ -77,15 +78,15 @@
     }
     int sliderWidth = 100; // fixme
     int inputWidth = 50; // fixme;
-    if (style != null && style.getWidth() != null && style.getWidth().getPixel() >= 0) {
+    if (style.getWidth() != null && style.getWidth().getPixel() >= 0) {
       sliderWidth = (width * sliderWidthPerc) / 100;
       inputWidth = (width * (100 - sliderWidthPerc)) / 100;
     }
 
-    writer.startElement(HtmlConstants.TABLE, component);
+    writer.startElement(HtmlConstants.TABLE, slider);
     writer.writeIdAttribute(id);
     writer.writeClassAttribute();
-    writer.writeStyleAttribute();
+    writer.writeStyleAttribute(style);
     //writer.writeAttribute("border","1",false);
 
     StyleClasses styleClasses = new StyleClasses();
@@ -125,7 +126,7 @@
     writer.writeClassAttribute("tobago-in-default");
     widthStyle.setWidth(new PixelMeasure(inputWidth));
     writer.writeStyleAttribute(widthStyle);
-    String inputIdAndName = getIdForInputField(facesContext, component);
+    String inputIdAndName = getIdForInputField(facesContext, slider);
     writer.writeNameAttribute(inputIdAndName);
     writer.writeIdAttribute(inputIdAndName);
     if (currentValue != null) {
@@ -145,11 +146,11 @@
     //track
     writer.startElement(HtmlConstants.DIV, null);
     writer.writeClassAttribute("tobago-inputNumberSlider-slider-default");
-    writer.writeIdAttribute(getIdForSliderTrack(facesContext, component));
+    writer.writeIdAttribute(getIdForSliderTrack(facesContext, slider));
 
     // handle
     writer.startElement(HtmlConstants.DIV, null);
-    writer.writeIdAttribute(getIdForSliderHandle(facesContext, component));
+    writer.writeIdAttribute(getIdForSliderHandle(facesContext, slider));
     writer.writeStyleAttribute("position:relative; top:-6px; width:12px; height:6px");
     writer.startElement(HtmlConstants.IMG, null);
     writer.writeAttribute(HtmlAttributes.SRC, getAbsoluteImagePath(facesContext, "image/sliderTriangle.gif"), true);
@@ -160,8 +161,8 @@
     writer.endElement(HtmlConstants.TR);
     writer.endElement(HtmlConstants.TABLE);
 
-    writeSliderJavaScript(facesContext, component, writer);
-    //HtmlRendererUtils.renderFocusId(facesContext, component);
+    writeSliderJavaScript(facesContext, slider, writer);
+    //HtmlRendererUtils.renderFocusId(facesContext, slider);
   }
 
   public void decode(FacesContext context, UIComponent component) {

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Wed Nov  4 11:56:16 2009
@@ -113,8 +113,8 @@
     writer.startElement(HtmlConstants.DIV, data);
     writer.writeIdAttribute(sheetId + "_outer_div");
     writer.writeClassAttribute("tobago-sheet-outer-div");
-// todo    HtmlStyleMap style = HtmlRendererUtils.createStyle(data);
-    writer.writeStyleAttribute();
+    HtmlStyleMap style = new HtmlStyleMap(facesContext, data);
+    writer.writeStyleAttribute(style);
     UICommand clickAction = null;
     UICommand dblClickAction = null;
     int columnSelectorIndex = -1;
@@ -243,10 +243,8 @@
       writer.startElement(HtmlConstants.DIV, null);
       writer.writeIdAttribute(sheetId + "_header_div");
       writer.writeClassAttribute("tobago-sheet-header-div");
-      HtmlStyleMap headerStyle = new HtmlStyleMap();
-      if (headerStyle != null) {
-        writer.writeStyleAttribute(headerStyle);
-      }
+      // todo: style is empty in the moment
+      writer.writeStyleAttribute(new HtmlStyleMap());
 
       int columnCount = 0;
       final int sortMarkerWidth = getAscendingMarkerWidth(facesContext, data);

Modified: myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java?rev=832711&r1=832710&r2=832711&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java (original)
+++ myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java Wed Nov  4 11:56:16 2009
@@ -17,11 +17,6 @@
  * limitations under the License.
  */
 
-/*
- * Created 07.02.2003 16:00:00.
- * $Id$
- */
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
@@ -83,7 +78,7 @@
     HtmlRendererUtils.renderDojoDndItem(box, writer, true);
     writer.writeClassAttribute();
     writer.writeIdAttribute(clientId);
-    writer.writeStyleAttribute();
+    writer.writeStyleAttribute(new HtmlStyleMap(facesContext, box));
     writer.writeJavascript("Tobago.addAjaxComponent(\"" + clientId + "\");");
     encodeBox(facesContext, writer, box);
   }
@@ -91,36 +86,28 @@
   private void encodeBox(FacesContext facesContext, TobagoResponseWriter writer, UIBox box) throws IOException {
 
     // shadow begin
-//    {
-      writer.startElement(HtmlConstants.DIV, box);
+    writer.startElement(HtmlConstants.DIV, box);
 
-      StyleClasses classes = new StyleClasses();
-      classes.addClass("box", "shadow");
-      // XXX should this be done everywhere?
-//      classes.addMarkupClass((SupportsMarkup) box, "box", "shadow");
-      writer.writeClassAttribute(classes);
-
-      HtmlStyleMap shadow = new HtmlStyleMap();
-      shadow.setWidth(box.getWidth().subtract(1));
-      shadow.setHeight(box.getHeight().subtract(1));
-      writer.writeStyleAttribute(shadow);
-//    }
+    StyleClasses classes = new StyleClasses();
+    classes.addClass("box", "shadow");
+    writer.writeClassAttribute(classes);
+
+    HtmlStyleMap shadow = new HtmlStyleMap();
+    shadow.setWidth(box.getWidth().subtract(1));
+    shadow.setHeight(box.getHeight().subtract(1));
+    writer.writeStyleAttribute(shadow);
 
     // border begin
-//    {
-      writer.startElement(HtmlConstants.DIV, box);
+    writer.startElement(HtmlConstants.DIV, box);
 
-      /*StyleClasses*/ classes = new StyleClasses();
-      classes.addClass("box", "border");
-      writer.writeClassAttribute(classes);
-      // XXX should this be done everywhere?
-//      classes.addMarkupClass((SupportsMarkup) box, "box", "border");
-
-      HtmlStyleMap border = new HtmlStyleMap();
-      border.setWidth(box.getWidth().subtract(3));
-      border.setHeight(box.getHeight().subtract(3));
-      writer.writeStyleAttribute(border);
-//    }
+    classes = new StyleClasses();
+    classes.addClass("box", "border");
+    writer.writeClassAttribute(classes);
+
+    HtmlStyleMap border = new HtmlStyleMap();
+    border.setWidth(box.getWidth().subtract(3));
+    border.setHeight(box.getHeight().subtract(3));
+    writer.writeStyleAttribute(border);
 
     renderBoxHeader(facesContext, writer, box);