You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2019/08/22 15:38:46 UTC

[myfaces-tobago] branch master updated: TOBAGO-2002 GridLayout: behavior of 'auto' is the same as '*'

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new 567d9f8  TOBAGO-2002 GridLayout: behavior of 'auto' is the same as '*'
567d9f8 is described below

commit 567d9f85e5c5fc6920355a20ab54870e70a2c464
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Aug 22 16:53:47 2019 +0200

    TOBAGO-2002 GridLayout: behavior of 'auto' is the same as '*'
    
    * a hidden '1fr' is added to grid layout column if there is an 'auto'
      value without a 'fr' value
    * test added
    * getter for stream of measureList added
---
 .../renderkit/renderer/GridLayoutRenderer.java     | 12 ++++++++
 .../apache/myfaces/tobago/layout/MeasureList.java  |  5 ++++
 .../100-auto-column/Auto-Column.test.js            | 28 +++++++++++++++++++
 .../100-auto-column/Auto-Column.xhtml              | 32 ++++++++++++++++++++++
 4 files changed, 77 insertions(+)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/GridLayoutRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/GridLayoutRenderer.java
index ecfa366..f0fc7b0 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/GridLayoutRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/GridLayoutRenderer.java
@@ -25,6 +25,7 @@ import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.internal.component.AbstractUIGridLayout;
 import org.apache.myfaces.tobago.internal.component.AbstractUIStyle;
 import org.apache.myfaces.tobago.internal.util.JsonUtils;
+import org.apache.myfaces.tobago.layout.Measure;
 import org.apache.myfaces.tobago.layout.MeasureList;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
@@ -62,6 +63,17 @@ public class GridLayoutRenderer extends RendererBase {
         facesContext, Tags.style.componentType(), RendererTypes.Style.name());
     style.setTransient(true);
 
+    /*
+     * If the column attribute contains and 'auto' value but not an 'fr' value,
+     * the behavior of the 'auto' value is the same as a 'fr' value.
+     * So if there is only an 'auto' value we add a hidden 'fr' value.
+     * https://issues.apache.org/jira/browse/TOBAGO-2002
+     */
+    if (columns.stream().anyMatch(measure -> Measure.Unit.AUTO.equals(measure.getUnit()))
+        && columns.stream().noneMatch(measure -> Measure.Unit.FR.equals(measure.getUnit()))) {
+      columns.add(new Measure(1, Measure.Unit.FR));
+    }
+
     style.setGridTemplateColumns(columns.serialize());
     style.setGridTemplateRows(rows.serialize());
     gridLayout.getChildren().add(style);
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureList.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureList.java
index fa1b0ae..468c1bb 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureList.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureList.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
+import java.util.stream.Stream;
 
 public class MeasureList implements Iterable<Measure>, Serializable {
 
@@ -37,6 +38,10 @@ public class MeasureList implements Iterable<Measure>, Serializable {
     return list.iterator();
   }
 
+  public Stream<Measure> stream() {
+    return list.stream();
+  }
+
   public static MeasureList parse(final String string) {
     final MeasureList measureList = new MeasureList();
     final StringTokenizer tokenizer = new StringTokenizer(string, "; ");
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4600-gridLayout/100-auto-column/Auto-Column.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4600-gridLayout/100-auto-column/Auto-Column.test.js
new file mode 100644
index 0000000..ef5f04f
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4600-gridLayout/100-auto-column/Auto-Column.test.js
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+import {testFrameQuerySelectorFn} from "/script/tobago-test.js";
+
+QUnit.test("test width of grid layout and 'auto' button", function (assert) {
+  assert.expect(2);
+
+  let gridLayoutFn = testFrameQuerySelectorFn("#page\\:mainForm\\:grid");
+  let buttonAutoFn = testFrameQuerySelectorFn("#page\\:mainForm\\:buttonAuto");
+
+  assert.equal(gridLayoutFn().offsetWidth, 358);
+  assert.equal(buttonAutoFn().offsetWidth, 58);
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4600-gridLayout/100-auto-column/Auto-Column.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4600-gridLayout/100-auto-column/Auto-Column.xhtml
new file mode 100644
index 0000000..a8d154e
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4600-gridLayout/100-auto-column/Auto-Column.xhtml
@@ -0,0 +1,32 @@
+<?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.
+-->
+
+<ui:composition template="/main.xhtml"
+                xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://java.sun.com/jsf/facelets">
+  <tc:box label="'auto' value">
+    <tc:style width="400px"/>
+    <p>Grid Layout - column with 'auto' but without '*'</p>
+    <tc:gridLayout id="grid" columns="100px auto">
+      <tc:button id="button100Px" label="100px"/>
+      <tc:button id="buttonAuto" label="auto"/>
+    </tc:gridLayout>
+  </tc:box>
+</ui:composition>