diff --git a/jdk/src/share/classes/javax/swing/text/html/CSS.java b/jdk/src/share/classes/javax/swing/text/html/CSS.java
index 60efa6cc013..f0f8cb2de11 100644
--- a/jdk/src/share/classes/javax/swing/text/html/CSS.java
+++ b/jdk/src/share/classes/javax/swing/text/html/CSS.java
@@ -806,15 +806,11 @@ public class CSS implements Serializable {
// translate border width into the cells, if it has non-zero value.
AttributeSet tableAttr = elem.getParentElement().
getParentElement().getAttributes();
- int borderWidth;
- try {
- borderWidth = Integer.parseInt(
- (String) tableAttr.getAttribute(HTML.Attribute.BORDER));
- } catch (NumberFormatException e) {
- borderWidth = 0;
- }
+
+ int borderWidth = getTableBorder(tableAttr);
if (borderWidth > 0) {
- translateAttribute(HTML.Attribute.BORDER, tableAttr, cssAttrSet);
+ // If table contains the BORDER attribute cells should have border width equals 1
+ translateAttribute(HTML.Attribute.BORDER, "1", cssAttrSet);
}
String pad = (String)tableAttr.getAttribute(HTML.Attribute.CELLPADDING);
if (pad != null) {
@@ -850,6 +846,21 @@ public class CSS implements Serializable {
return cssAttrSet;
}
+ private static int getTableBorder(AttributeSet tableAttr) {
+ String borderValue = (String) tableAttr.getAttribute(HTML.Attribute.BORDER);
+
+ if (borderValue == HTML.NULL_ATTRIBUTE_VALUE || "".equals(borderValue)) {
+ // Some browsers accept
and with the same semantics as BORDER=1
+ return 1;
+ }
+
+ try {
+ return Integer.parseInt(borderValue);
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
private static final Hashtable attributeMap = new Hashtable();
private static final Hashtable valueMap = new Hashtable();
@@ -1400,17 +1411,20 @@ public class CSS implements Serializable {
}
}
} else {
-
- /*
- * The html size attribute has a mapping in the CSS world only
- * if it is par of a font or base font tag.
- */
-
if (key == HTML.Attribute.SIZE && !isHTMLFontTag(tag)) {
- continue;
- }
+ /*
+ * The html size attribute has a mapping in the CSS world only
+ * if it is par of a font or base font tag.
+ */
+ } else if (tag == HTML.Tag.TABLE && key == HTML.Attribute.BORDER) {
+ int borderWidth = getTableBorder(htmlAttrSet);
- translateAttribute(key, htmlAttrSet, cssAttrSet);
+ if (borderWidth > 0) {
+ translateAttribute(HTML.Attribute.BORDER, Integer.toString(borderWidth), cssAttrSet);
+ }
+ } else {
+ translateAttribute(key, (String) htmlAttrSet.getAttribute(key), cssAttrSet);
+ }
}
} else if (name instanceof CSS.Attribute) {
cssAttrSet.addAttribute(name, htmlAttrSet.getAttribute(name));
@@ -1419,7 +1433,7 @@ public class CSS implements Serializable {
}
private void translateAttribute(HTML.Attribute key,
- AttributeSet htmlAttrSet,
+ String htmlAttrValue,
MutableAttributeSet cssAttrSet) {
/*
* In the case of all remaining HTML.Attribute's they
@@ -1427,8 +1441,6 @@ public class CSS implements Serializable {
*/
CSS.Attribute[] cssAttrList = getCssAttribute(key);
- String htmlAttrValue = (String)htmlAttrSet.getAttribute(key);
-
if (cssAttrList == null || htmlAttrValue == null) {
return;
}
diff --git a/jdk/src/share/classes/javax/swing/text/html/TableView.java b/jdk/src/share/classes/javax/swing/text/html/TableView.java
index a941fbdfa78..65f4fc01ae2 100644
--- a/jdk/src/share/classes/javax/swing/text/html/TableView.java
+++ b/jdk/src/share/classes/javax/swing/text/html/TableView.java
@@ -242,7 +242,8 @@ import javax.swing.text.*;
if (lv != null) {
cellSpacing = (int) lv.getValue();
} else {
- cellSpacing = 0;
+ // Default cell spacing equals 2
+ cellSpacing = 2;
}
lv = (CSS.LengthValue)
attr.getAttribute(CSS.Attribute.BORDER_TOP_WIDTH);
@@ -251,8 +252,7 @@ import javax.swing.text.*;
} else {
borderWidth = 0;
}
-
- }
+ }
}
/**
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/bug7030332.html b/jdk/test/javax/swing/text/html/TableView/7030332/bug7030332.html
new file mode 100644
index 00000000000..9a62f793008
--- /dev/null
+++ b/jdk/test/javax/swing/text/html/TableView/7030332/bug7030332.html
@@ -0,0 +1,12 @@
+
+
+
+
+Compare Golden Images with rendered JEditorPane.
+They should looks simalar in each line. Pay attention to:
+
+1. Border width around tables
+2. Border width around cells
+
+
+
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/bug7030332.java b/jdk/test/javax/swing/text/html/TableView/7030332/bug7030332.java
new file mode 100644
index 00000000000..7038edb2465
--- /dev/null
+++ b/jdk/test/javax/swing/text/html/TableView/7030332/bug7030332.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ @bug 7030332
+ @summary Default borders in tables looks incorrect JEditorPane
+ @author Pavel Porvatov
+ * @run applet/manual=yesno bug7030332.html
+*/
+
+import javax.swing.*;
+import java.awt.*;
+import java.net.URL;
+
+public class bug7030332 extends JApplet {
+ public static final String[] HTML_SAMPLES = new String[]{
+ "",
+ "",
+ "",
+ "",
+ };
+
+ public static void main(String[] args) throws Exception {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ JFrame frame = new JFrame();
+
+ frame.setContentPane(createContentPane());
+ frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame.setSize(600, 400);
+ frame.setLocationRelativeTo(null);
+
+ frame.setVisible(true);
+
+ }
+ });
+ }
+
+ public void init() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ setContentPane(createContentPane());
+ }
+ });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static Container createContentPane() {
+ JPanel result = new JPanel(new GridLayout(HTML_SAMPLES.length + 1, 3, 10, 10));
+
+ result.add(new JLabel("Html code"));
+ result.add(new JLabel("Golden image"));
+ result.add(new JLabel("JEditorPane"));
+
+ for (int i = 0; i < HTML_SAMPLES.length; i++) {
+ String htmlSample = HTML_SAMPLES[i];
+
+ JTextArea textArea = new JTextArea(htmlSample);
+
+ textArea.setLineWrap(true);
+
+ result.add(textArea);
+
+ String imageName = "sample" + i + ".png";
+ URL resource = bug7030332.class.getResource(imageName);
+
+ result.add(resource == null ? new JLabel(imageName + " not found") :
+ new JLabel(new ImageIcon(resource), SwingConstants.LEFT));
+
+ result.add(new JEditorPane("text/html", htmlSample));
+ }
+
+ return result;
+ }
+}
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/sample0.png b/jdk/test/javax/swing/text/html/TableView/7030332/sample0.png
new file mode 100644
index 00000000000..e18c9bb2362
Binary files /dev/null and b/jdk/test/javax/swing/text/html/TableView/7030332/sample0.png differ
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/sample1.png b/jdk/test/javax/swing/text/html/TableView/7030332/sample1.png
new file mode 100644
index 00000000000..e18c9bb2362
Binary files /dev/null and b/jdk/test/javax/swing/text/html/TableView/7030332/sample1.png differ
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/sample2.png b/jdk/test/javax/swing/text/html/TableView/7030332/sample2.png
new file mode 100644
index 00000000000..e18c9bb2362
Binary files /dev/null and b/jdk/test/javax/swing/text/html/TableView/7030332/sample2.png differ
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/sample3.png b/jdk/test/javax/swing/text/html/TableView/7030332/sample3.png
new file mode 100644
index 00000000000..7f876058e0d
Binary files /dev/null and b/jdk/test/javax/swing/text/html/TableView/7030332/sample3.png differ
diff --git a/jdk/test/javax/swing/text/html/TableView/7030332/sample4.png b/jdk/test/javax/swing/text/html/TableView/7030332/sample4.png
new file mode 100644
index 00000000000..7f876058e0d
Binary files /dev/null and b/jdk/test/javax/swing/text/html/TableView/7030332/sample4.png differ