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 2013/04/23 16:57:33 UTC

svn commit: r1470992 - in /myfaces/tobago/trunk: tobago-example/tobago-example-test/src/main/webapp/test/link/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ tobago-theme/tobago-th...

Author: lofwyr
Date: Tue Apr 23 14:57:32 2013
New Revision: 1470992

URL: http://svn.apache.org/r1470992
Log:
TOBAGO-1251: tc:link is calculated to narrow when using "auto", especially when images are used

Added:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/link/
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/link/link-layout.xhtml
Modified:
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/less/org/apache/myfaces/tobago/renderkit/html/speyside/standard/style/tobago.less

Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/link/link-layout.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/link/link-layout.xhtml?rev=1470992&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/link/link-layout.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/link/link-layout.xhtml Tue Apr 23 14:57:32 2013
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<f:view
+        xmlns:tc="http://myfaces.apache.org/tobago/component"
+        xmlns:f="http://java.sun.com/jsf/core">
+
+    <tc:page id="page">
+        <f:facet name="layout">
+            <tc:gridLayout rows="auto" columns="auto"/>
+        </f:facet>
+        <tc:box label="Tests the layout of links">
+
+            <f:facet name="layout">
+                <tc:gridLayout columns="auto;auto;auto;auto;auto;auto;auto"/>
+            </f:facet>
+
+            <tc:link id="l1" label="l" tip="3px"/>
+            <tc:link id="l2" label="g" tip="7px"/>
+            <tc:link id="l3" label="W" tip="11px"/>
+
+            <tc:link id="l4" label="l" image="image/feather-leaf.png" tip="16px + 4px + 3px"/>
+            <tc:link id="l5" label="g" image="image/feather-leaf.png" tip="16px + 4px + 7px"/>
+            <tc:link id="l6" label="W" image="image/feather-leaf.png" tip="16px + 4px + 11px"/>
+
+            <tc:link id="l7" image="image/feather-leaf.png" tip="16px"/>
+
+            <tc:out value="2nd row">
+                <tc:gridLayoutConstraint columnSpan="10"/>
+            </tc:out>
+
+        </tc:box>
+
+        <tc:script file="script/tobago-assert.js"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l1', 6, 26, 3, 14);"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l2', 14, 26, 7, 14);"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l3', 26, 26, 11, 14);"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l4', 42, 26, 23, 14);"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l5', 70, 26, 27, 14);"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l6', 102, 26, 31, 14);"/>
+        <tc:script onload="TobagoAssert.assertLayout('page:l7', 138, 26, 16, 14);"/>
+
+    </tc:page>
+</f:view>

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java?rev=1470992&r1=1470991&r2=1470992&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java Tue Apr 23 14:57:32 2013
@@ -24,6 +24,7 @@ import org.apache.myfaces.tobago.context
 import org.apache.myfaces.tobago.internal.component.AbstractUILink;
 import org.apache.myfaces.tobago.internal.util.AccessKeyMap;
 import org.apache.myfaces.tobago.layout.Measure;
+import org.apache.myfaces.tobago.layout.PixelMeasure;
 import org.apache.myfaces.tobago.renderkit.CommandRendererBase;
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
@@ -100,6 +101,7 @@ public class LinkRenderer extends Comman
         image = getImageWithPath(facesContext, image, disabled);
       }
       writer.startElement(HtmlElements.IMG, link);
+      writer.writeClassAttribute(Classes.create(link, "image"));
       writer.writeAttribute(HtmlAttributes.SRC, image, true);
       writer.writeAttribute(HtmlAttributes.BORDER, 0); // TODO: is border=0 setting via style possible?
       String tip = link.getTip();
@@ -140,8 +142,22 @@ public class LinkRenderer extends Comman
 
   @Override
   public Measure getPreferredWidth(FacesContext facesContext, Configurable component) {
-    AbstractUILink link = (AbstractUILink) component;
-    LabelWithAccessKey label = new LabelWithAccessKey(link);
-    return RenderUtils.calculateStringWidth(facesContext, link, label.getText());
+    final AbstractUILink link = (AbstractUILink) component;
+    final LabelWithAccessKey label = new LabelWithAccessKey(link);
+    final String text = label.getText();
+    final String image = link.getImage();
+
+    Measure width = PixelMeasure.ZERO;
+    if (text != null) {
+      final Measure m = RenderUtils.calculateStringWidth(facesContext, link, text);
+      width = width.add(m);
+    }
+    if ((text != null && image != null)) {
+      width = width.add(4);
+    }
+    if (image != null) {
+      width = width.add(16);
+    }
+    return width;
   }
 }

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/less/org/apache/myfaces/tobago/renderkit/html/speyside/standard/style/tobago.less
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/less/org/apache/myfaces/tobago/renderkit/html/speyside/standard/style/tobago.less?rev=1470992&r1=1470991&r2=1470992&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/less/org/apache/myfaces/tobago/renderkit/html/speyside/standard/style/tobago.less (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/less/org/apache/myfaces/tobago/renderkit/html/speyside/standard/style/tobago.less Tue Apr 23 14:57:32 2013
@@ -351,6 +351,10 @@
   color: #888888;
 }
 
+.tobago-link-image {
+  vertical-align: text-top;
+}
+
 /* menuBar -------------------------------------------------------- */
 
 .tobago-menuBar li,