diff options
Diffstat (limited to 'gnu/javax/swing')
-rw-r--r-- | gnu/javax/swing/text/html/css/BorderStyle.java | 64 | ||||
-rw-r--r-- | gnu/javax/swing/text/html/css/BorderWidth.java | 12 | ||||
-rw-r--r-- | gnu/javax/swing/text/html/css/FontSize.java | 8 | ||||
-rw-r--r-- | gnu/javax/swing/text/html/css/Length.java | 155 | ||||
-rw-r--r-- | gnu/javax/swing/text/html/css/Selector.java | 17 | ||||
-rw-r--r-- | gnu/javax/swing/text/html/parser/support/Parser.java | 40 |
6 files changed, 279 insertions, 17 deletions
diff --git a/gnu/javax/swing/text/html/css/BorderStyle.java b/gnu/javax/swing/text/html/css/BorderStyle.java new file mode 100644 index 000000000..d75beea52 --- /dev/null +++ b/gnu/javax/swing/text/html/css/BorderStyle.java @@ -0,0 +1,64 @@ +/* BorderStyle.java -- Utility for dealing with border styles + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.swing.text.html.css; + +/** + * Utility class for handling border styles. + */ +public class BorderStyle +{ + + /** + * Determines if a given value makes up a valid border style value. + * + * @param value the value to check + * + * @return <code>true</code> when this is a valid border style, + * <code>false</code> otherwise + */ + public static boolean isValidStyle(String value) + { + return value.equals("none") || value.equals("hidden") + || value.equals("dotted") || value.equals("dashed") + || value.equals("solid") || value.equals("double") + || value.equals("groove") || value.equals("ridge") + || value.equals("inset") || value.equals("outset"); + + } +} diff --git a/gnu/javax/swing/text/html/css/BorderWidth.java b/gnu/javax/swing/text/html/css/BorderWidth.java index b717020e3..ae64c2110 100644 --- a/gnu/javax/swing/text/html/css/BorderWidth.java +++ b/gnu/javax/swing/text/html/css/BorderWidth.java @@ -63,4 +63,16 @@ public class BorderWidth floatValue = 3.F; } + /** + * Checks if the specified value makes up a valid border-width value. + * + * @param value the value to check + * + * @return <code>true</code> if the value is a valid border-width + */ + public static boolean isValid(String value) + { + return value.equals("thin") || value.equals("medium") + || value.equals("thick") || Length.isValid(value); + } } diff --git a/gnu/javax/swing/text/html/css/FontSize.java b/gnu/javax/swing/text/html/css/FontSize.java index 7dc8d46c6..2795b6784 100644 --- a/gnu/javax/swing/text/html/css/FontSize.java +++ b/gnu/javax/swing/text/html/css/FontSize.java @@ -255,13 +255,13 @@ public class FontSize private int mapRelative(int par) { - if (value.contains("%")) + if (value.indexOf('%') != -1) size = mapPercent(par); - else if (value.contains("em")) + else if (value.indexOf("em") != -1) size = mapEM(par); - else if (value.contains("larger")) + else if (value.indexOf("larger") != -1) size = mapLarger(par); - else if (value.contains("smaller")) + else if (value.indexOf("smaller") != -1) size = mapSmaller(par); return size; } diff --git a/gnu/javax/swing/text/html/css/Length.java b/gnu/javax/swing/text/html/css/Length.java index 339e2a2e0..06fa36e3d 100644 --- a/gnu/javax/swing/text/html/css/Length.java +++ b/gnu/javax/swing/text/html/css/Length.java @@ -62,15 +62,40 @@ public class Length private boolean isPercentage; /** + * Indicates a length value that is relative to the font size (em). + */ + private boolean isFontEMRelative; + + /** + * Indicates a length value that is relative to the font size (ex). + */ + private boolean isFontEXRelative; + + /** + * The EM base size. + */ + private float emBase; + + /** + * The EX base size. + */ + private float exBase; + + /** * Creates a new length converter instance. * * @param val the CSS value */ public Length(String val) { + isFontEMRelative = false; + isFontEXRelative = false; + isPercentage = false; value = val; int i = value.indexOf("px"); int percent = value.indexOf("%"); + int em = value.indexOf("em"); + int ex = value.indexOf("ex"); try { floatValue = 0.0F; @@ -85,13 +110,24 @@ public class Length String sub = value.substring(0, percent); floatValue = Float.parseFloat(sub) / 100; } + else if (em != -1) + { + isFontEMRelative = true; + String sub = value.substring(0, em); + floatValue = Float.parseFloat(sub); + } + else if (ex != -1) + { + isFontEXRelative = true; + String sub = value.substring(0, ex); + floatValue = Float.parseFloat(sub); + } else { - // TODO: Implement other length options. floatValue = Float.parseFloat(value); } } - catch (NumberFormatException ex) + catch (NumberFormatException exc) { // Don't let such small problems interrupt CSS parsing. System.err.println("couldn't parse: " + val); @@ -112,19 +148,79 @@ public class Length * Returns the absolute span for the case when this length value is * a relative value. * - * @param available the target span + * @param base the base span * * @return the absolute span */ - public float getValue(float available) + public float getValue(float base) { float span = floatValue; if (isPercentage) - span *= available; + span *= base; + else if (isFontEMRelative) + span *= emBase; + else if (isFontEXRelative) + span *= exBase; return span; } /** + * Sets the font relative EM base. + * + * @param base the font relative EM base + */ + public void setEMBase(float base) + { + emBase = base; + } + + /** + * Sets the font relative EX base. + * + * @param base the font relative EX base + */ + public void setEXBase(float base) + { + exBase = base; + } + + /** + * Sets the font relative base values. + * + * @param emBase the EM base + * @param exBase the EX base + */ + public void setFontBases(float emBase, float exBase) + { + setEMBase(emBase); + setEXBase(exBase); + } + + /** + * Returns true when this length value is an em font relative value. In + * order to get correct results, you need the exBase property set up + * correctly. + * + * @return true when this length value is an ex font relative value + */ + public boolean isFontEMRelative() + { + return isFontEMRelative; + } + + /** + * Returns true when this length value is an ex font relative value. In + * order to get correct results, you need the emBase property set up + * correctly. + * + * @return true when this length value is an ex font relative value + */ + public boolean isFontEXRelative() + { + return isFontEXRelative; + } + + /** * Returns <code>true</code> when the length value is a percentage * value, <code>false</code> otherwise. * @@ -135,4 +231,53 @@ public class Length { return isPercentage; } + + /** + * Checks if the specified value makes up a valid length value. + * + * @param value the value to check + * + * @return <code>true</code> if the value is a valid length + */ + public static boolean isValid(String value) + { + boolean isValid = true; + int px = value.indexOf("px"); + int em = value.indexOf("em"); + int ex = value.indexOf("ex"); + int pc = value.indexOf('%'); + try + { + if (px != -1) + { + Integer.parseInt(value.substring(0, px)); + } + else if (em != -1) + { + Integer.parseInt(value.substring(0, em)); + } + else if (ex != -1) + { + Integer.parseInt(value.substring(0, ex)); + } + else if (pc != -1) + { + Integer.parseInt(value.substring(0, ex)); + } + else + { + Integer.parseInt(value); + } + } + catch (NumberFormatException nfe) + { + isValid = false; + } + return isValid; + } + + public String toString() + { + return value; + } } diff --git a/gnu/javax/swing/text/html/css/Selector.java b/gnu/javax/swing/text/html/css/Selector.java index b8128233b..210df3a7b 100644 --- a/gnu/javax/swing/text/html/css/Selector.java +++ b/gnu/javax/swing/text/html/css/Selector.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.javax.swing.text.html.css; +import java.util.Map; import java.util.StringTokenizer; /** @@ -98,7 +99,7 @@ public class Selector * @return <code>true</code> when this selector matches the element path, * <code>false</code> otherwise */ - public boolean matches(String[] tags, String[] pathClasses, String[] pathIds) + public boolean matches(String[] tags, Map[] attributes) { // TODO: This implements class, id and descendent matching. These are // the most commonly used selector matchers in CSS together with HTML. @@ -119,15 +120,22 @@ public class Selector boolean tagMatch = false; for (; tagIndex < numTags && tagMatch == false; tagIndex++) { + Object pathClass = attributes[tagIndex].get("class"); + // Try pseudo class too. + Object pseudoClass = attributes[tagIndex].get("_pseudo"); + Object dynClass = attributes[tagIndex].get("_dynamic"); + Object pathId = attributes[tagIndex].get("id"); String tag = elements[j]; String clazz = classes[j]; String id = ids[j]; tagMatch = tag.equals("") || tag.equals("*") || tag.equals(tags[tagIndex]); tagMatch = tagMatch && (clazz.equals("*") - || clazz.equals(pathClasses[tagIndex])); + || clazz.equals(dynClass) + || clazz.equals(pseudoClass) + || clazz.equals(pathClass)); tagMatch = tagMatch && (id.equals("*") - || id.equals(pathIds[tagIndex])); + || id.equals(pathId)); // For the last element in the selector we must not look // further. if (j == 0) @@ -190,6 +198,9 @@ public class Selector { String sel = selector[i]; int clazzIndex = sel.indexOf('.'); + // Try pseudo class too. + if (clazzIndex == -1) + clazzIndex = sel.indexOf(':'); int idIndex = sel.indexOf('#'); String clazz; if (clazzIndex == -1) diff --git a/gnu/javax/swing/text/html/parser/support/Parser.java b/gnu/javax/swing/text/html/parser/support/Parser.java index 98058e503..f04c58138 100644 --- a/gnu/javax/swing/text/html/parser/support/Parser.java +++ b/gnu/javax/swing/text/html/parser/support/Parser.java @@ -498,6 +498,9 @@ public class Parser mustBe(t.kind); } hTag = new Token(start, last); + + // Consume any whitespace immediately following a comment. + optional(WS); handleComment(); } @@ -983,13 +986,15 @@ public class Parser + next.getImage() + "'"); attrValue = value.getImage(); } - else if (next.kind == SLASH) - // The slash in this context is treated as the ordinary - // character, not as a token. The slash may be part of + else if (next.kind == SLASH || next.kind == OTHER) + // The slash and other characters (like %) in this context is + // treated as the ordinary + // character, not as a token. The character may be part of // the unquoted URL. { StringBuffer image = new StringBuffer(value.getImage()); - while (next.kind == NUMTOKEN || next.kind == SLASH) + while (next.kind == NUMTOKEN || next.kind == SLASH + || next.kind == OTHER) { image.append(getNextToken().getImage()); next = getTokenAhead(); @@ -1181,6 +1186,13 @@ public class Parser { validator.validateTag(tag, attributes); handleEmptyTag(tag); + HTML.Tag h = tag.getHTMLTag(); + // When a block tag is closed, consume whitespace that follows after + // it. + // For some unknown reason a FRAME tag is not treated as block element. + // However in this case it should be treated as such. + if (isBlock(h)) + optional(WS); } catch (ChangedCharSetException ex) { @@ -1219,7 +1231,7 @@ public class Parser // When a block tag is closed, consume whitespace that follows after // it. - if (h.isBlock()) + if (isBlock(h)) optional(WS); if (h == HTML.Tag.TITLE) @@ -1248,6 +1260,9 @@ public class Parser HTML.Tag h = tag.getHTMLTag(); + if (isBlock(h)) + optional(WS); + if (h.isPreformatted()) preformatted++; @@ -1495,4 +1510,19 @@ public class Parser { error("Whitespace here is not permitted"); } + + /** + * Returns true when the specified tag should be considered a block tag + * wrt whitespace handling. We need this special handling, since there + * are a couple of tags that we must treat as block tags but which aren't + * officially block tags. + * + * @param tag the tag to check + * @return true when the specified tag should be considered a block tag + * wrt whitespace handling + */ + private boolean isBlock(HTML.Tag tag) + { + return tag.isBlock() || tag == HTML.Tag.STYLE || tag == HTML.Tag.FRAME; + } } |