/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/**
* Defines a set of
* <a href="http://www.w3.org/TR/REC-CSS1">CSS attributes</a>
* as a typesafe enumeration. The HTML View implementations use
* CSS attributes to determine how they will render. This also defines
* methods to map between CSS/HTML/StyleConstants. Any shorthand
* properties, such as font, are mapped to the intrinsic properties.
* <p>The following describes the CSS properties that are suppored by the
* rendering engine:
* <ul><li>font-family
* <li>font-style
* <li>font-size (supports relative units)
* <li>font-weight
* <li>font
* <li>color
* <li>background-color (with the exception of transparent)
* <li>background-image
* <li>background-repeat
* <li>background-position
* <li>background
* <li>text-decoration (with the exception of blink and overline)
* <li>vertical-align (only sup and super)
* <li>text-align (justify is treated as center)
* <li>margin-top
* <li>margin-right
* <li>margin-bottom
* <li>margin-left
* <li>margin
* <li>padding-top
* <li>padding-right
* <li>padding-bottom
* <li>padding-left
* <li>padding
* <li>border-top-style
* <li>border-right-style
* <li>border-bottom-style
* <li>border-left-style
* <li>border-style (only supports inset, outset and none)
* <li>border-top-color
* <li>border-right-color
* <li>border-bottom-color
* <li>border-left-color
* <li>border-color
* <li>list-style-image
* <li>list-style-type
* <li>list-style-position
* </ul>
* The following are modeled, but currently not rendered.
* <ul><li>font-variant
* <li>background-attachment (background always treated as scroll)
* <li>word-spacing
* <li>letter-spacing
* <li>text-indent
* <li>text-transform
* <li>line-height
* <li>border-top-width (this is used to indicate if a border should be used)
* <li>border-right-width
* <li>border-bottom-width
* <li>border-left-width
* <li>border-width
* <li>border-top
* <li>border-right
* <li>border-bottom
* <li>border-left
* <li>border
* <li>width
* <li>height
* <li>float
* <li>clear
* <li>display
* <li>white-space
* <li>list-style
* </ul>
* <p><b>Note: for the time being we do not fully support relative units,
* unless noted, so that
* p { margin-top: 10% } will be treated as if no margin-top was specified.
*
* @author Timothy Prinzing
* @author Scott Violet
* @see StyleSheet
*/
/**
* Definitions to be used as a key on AttributeSet's
* that might hold CSS attributes. Since this is a
* closed set (i.e. defined exactly by the specification),
* it is final and cannot be extended.
*/
public static final class Attribute {
this.defaultValue = defaultValue;
}
/**
* The string representation of the attribute. This
* should exactly match the string specified in the
* CSS specification.
*/
return name;
}
/**
* Fetch the default value for the attribute.
* If there is no default value (such as for
* composite attributes), null will be returned.
*/
return defaultValue;
}
/**
* Indicates if the attribute should be inherited
* from the parent or not.
*/
public boolean isInherited() {
return inherited;
}
private boolean inherited;
/*
* made up css attributes to describe orientation depended
* margins. used for <dir>, <menu>, <ul> etc. see
* 5088268 for more details
*/
new Attribute("margin-left-ltr",
new Attribute("margin-left-rtl",
new Attribute("margin-right-ltr",
new Attribute("margin-right-rtl",
// All possible CSS attribute keys.
};
}
static final class Value {
}
/**
* The string representation of the attribute. This
* should exactly match the string specified in the
* CSS specification.
*/
return name;
}
// Lists.
// background-repeat
// background-attachment
};
}
public CSS() {
// setup the css conversion table
new BackgroundImage());
new BackgroundPosition());
for (int i = 0; i < n; i++) {
}
}
}
/**
* Sets the base font size. <code>sz</code> is a CSS value, and is
* not necessarily the point size. Use getPointSize to determine the
* point size corresponding to <code>sz</code>.
*/
if (sz < 1)
baseFontSize = 0;
else if (sz > 7)
baseFontSize = 7;
else
baseFontSize = sz;
}
/**
* Sets the base font size from the passed in string.
*/
} else {
}
}
}
/**
* Returns the base font size.
*/
int getBaseFontSize() {
return baseFontSize;
}
/**
* Parses the CSS property <code>key</code> with value
* <code>value</code> placing the result in <code>att</code>.
*/
}
}
}
}
}
}
}
}
else {
}
}
}
/**
* Gets the internal CSS representation of <code>value</code> which is
* a CSS value of the CSS attribute named <code>key</code>. The receiver
* should not modify <code>value</code>, and the first <code>count</code>
* strings are valid.
*/
}
/**
* Maps from a StyleConstants to a CSS Attribute.
*/
}
/**
* Maps from a StyleConstants value to a CSS value.
*/
Object styleValue) {
}
return null;
}
/**
* Converts the passed in CSS value to a StyleConstants value.
* <code>key</code> identifies the CSS attribute being mapped.
*/
}
return null;
}
/**
* Returns the font for the values in the passed in AttributeSet.
* It is assumed the keys will be CSS.Attribute keys.
* <code>sc</code> is the StyleContext that will be messaged to get
* the font once the size, name and style have been determined.
*/
/*
* If the vertical alignment is set to either superscirpt or
* subscript we reduce the font size by 2 points.
*/
size -= 2;
}
}
}
}
}
if (f == null
}
return f;
}
// PENDING(prinz) this is a 1.1 based implementation, need to also
// have a 1.2 version.
: defaultSize;
}
/**
* Takes a set of attributes and turn it into a color
* specification. This might be used to specify things
* like brighter, more hue, etc.
* This will return null if there is no value for <code>key</code>.
*
* @param key CSS.Attribute identifying where color is stored.
* @param a the set of attributes
* @return the color
*/
}
return null;
}
/**
* Returns the size of a font from the passed in string.
*
* @param size CSS string describing font size
* @param baseFontSize size to use for relative units.
*/
} else {
}
}
return 0;
}
/**
* Returns the length of the attribute in <code>a</code> with
* key <code>key</code>.
*/
return len;
}
/**
* Convert a set of HTML attributes to an equivalent
* set of CSS attributes.
*
* @param htmlAttrSet AttributeSet containing the HTML attributes.
* @return AttributeSet containing the corresponding CSS attributes.
* The AttributeSet will be empty if there are no mapping
* CSS attributes.
*/
// translate border width into the cells, if it has non-zero value.
if (borderWidth > 0) {
// If table contains the BORDER attribute cells should have border width equals 1
}
LengthValue v =
}
}
} else {
}
/*
* Navigator uses ALIGN for caption placement and IE uses VALIGN.
*/
} else {
if (v != null) {
}
}
}
return cssAttrSet;
}
// Some browsers accept <TABLE BORDER> and <TABLE BORDER=""> with the same semantics as BORDER=1
return 1;
}
try {
} catch (NumberFormatException e) {
return 0;
}
}
private static final Hashtable<String, Attribute> attributeMap = new Hashtable<String, Attribute>();
/**
* The hashtable and the static initalization block below,
* set up a mapping from well-known HTML attributes to
* CSS attributes. For the most part, there is a 1-1 mapping
* between the two. However in the case of certain HTML
* attributes for example HTML.Attribute.VSPACE or
* HTML.Attribute.HSPACE, end up mapping to two CSS.Attribute's.
* Therefore, the value associated with each HTML.Attribute.
* key ends up being an array of CSS.Attribute.* objects.
*/
private static final Hashtable<HTML.Attribute, CSS.Attribute[]> htmlAttrToCssAttrMap = new Hashtable<HTML.Attribute, CSS.Attribute[]>(20);
/**
* The hashtable and static initialization that follows sets
* up a translation from StyleConstants (i.e. the <em>well known</em>
* attributes) to the associated CSS attributes.
*/
private static final Hashtable<Object, Attribute> styleConstantToCssMap = new Hashtable<Object, Attribute>(17);
/** Maps from HTML value to a CSS value. Used in internal mapping. */
private static final Hashtable<String, CSS.Value> htmlValueToCssValueMap = new Hashtable<String, CSS.Value>(8);
/** Maps from CSS value (string) to internal value. */
private static final Hashtable<String, CSS.Value> cssValueToInternalValueMap = new Hashtable<String, CSS.Value>(13);
static {
// load the attribute map
Attribute.allAttributes[i]);
}
// load the value map
}
new CSS.Attribute[]{CSS.Attribute.BORDER_TOP_WIDTH, CSS.Attribute.BORDER_RIGHT_WIDTH, CSS.Attribute.BORDER_BOTTOM_WIDTH, CSS.Attribute.BORDER_LEFT_WIDTH});
// initialize StyleConstants mapping
// HTML->CSS
// CSS-> internal CSS
// Register all the CSS attribute keys for archival/unarchival
try {
}
} catch (Throwable e) {
e.printStackTrace();
}
// Register all the CSS Values for archival/unarchival
try {
}
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* Return the set of all possible CSS attribute keys.
*/
return keys;
}
/**
* Translates a string to a <code>CSS.Attribute</code> object.
* This will return <code>null</code> if there is no attribute
* by the given name.
*
* @param name the name of the CSS attribute to fetch the
* typesafe enumeration for
* @return the <code>CSS.Attribute</code> object,
* or <code>null</code> if the string
* doesn't represent a valid attribute key
*/
}
/**
* Translates a string to a <code>CSS.Value</code> object.
* This will return <code>null</code> if there is no value
* by the given name.
*
* @param name the name of the CSS value to fetch the
* typesafe enumeration for
* @return the <code>CSS.Value</code> object,
* or <code>null</code> if the string
* doesn't represent a valid CSS value name; this does
* not mean that it doesn't represent a valid CSS value
*/
}
//
//
/**
* Returns a URL for the given CSS url string. If relative,
* <code>base</code> is used as the parent. If a valid URL can not
* be found, this will not throw a MalformedURLException, instead
* null will be returned.
*/
return null;
}
}
// Absolute first
try {
return url;
}
} catch (MalformedURLException mue) {
}
// Then relative
// Relative URL, try from base
try {
return url;
}
catch (MalformedURLException muee) {
}
}
return null;
}
/**
* Converts a type Color to a hex string
* in the format "#RRGGBB"
*/
// Red
else
// Green
else
// Blue
else
return colorstr;
}
/**
* Convert a "#FFFFFF" hex string to a Color.
* If the color specification is bad, an attempt
* will be made to fix it up.
*/
} else {
}
Color c;
try {
} catch (NumberFormatException nfe) {
c = null;
}
return c;
}
/**
* Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)"
* to a Color.
*/
return null;
}
}
else
return color;
}
/**
* Parses a String in the format <code>rgb(r, g, b)</code> where
* each of the Color components is either an integer, or a floating number
* with a % after indicating a percentage value of 255. Values are
* constrained to fit with 0-255. The resulting Color is returned.
*/
// Find the next numeric char
int[] index = new int[1];
}
/**
* Returns the next integer value from <code>string</code> starting
* at <code>index[0]</code>. The value can either can an integer, or
* a percentage (floating number ending with %), in which case it is
* multiplied by 255.
*/
char aChar;
// Skip non-decimal chars
index[0]++;
}
index[0]++;
}
index[0]++;
}
// Decimal value
index[0]++;
index[0]++;
}
}
try {
index[0]++;
}
} catch (NumberFormatException nfe) {
// Treat as 0
}
}
return 0;
}
return i + 1;
}
}
/**
* @return an array of all the strings in <code>value</code>
* that are separated by whitespace.
*/
current = 0;
// Skip ws
current++;
}
current++;
}
}
current++;
}
return retValue;
}
/**
* Return the point size, given a size index. Legal HTML index sizes
* are 1-7.
*/
--index;
if (index < 0)
return sizeMap[0];
else
}
// HR needs special handling due to us treating it as a leaf.
}
while (keys.hasMoreElements()) {
if (o != null && o instanceof AttributeSet) {
}
}
}
}
while (names.hasMoreElements()) {
/*
* HTML.Attribute.ALIGN needs special processing.
* It can map to to 1 of many(3) possible CSS attributes
* depending on the nature of the tag the attribute is
* part off and depending on the value of the attribute.
*/
if (htmlAttrValue != null) {
if (o != null) {
}
}
}
} 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 (borderWidth > 0) {
}
} else {
}
}
}
}
}
/*
* In the case of all remaining HTML.Attribute's they
* map to 1 or more CCS.Attribute.
*/
return;
}
if (o != null) {
}
}
}
/**
* Given a CSS.Attribute object and its corresponding HTML.Attribute's
* value, this method returns a CssValue object to associate with the
* CSS attribute.
*
* @param the CSS.Attribute
* @param a String containing the value associated HTML.Attribtue.
*/
return o;
}
/**
* Maps an HTML.Attribute object to its appropriate CSS.Attributes.
*
* @param HTML.Attribute
* @return CSS.Attribute[]
*/
}
/**
* Maps HTML.Attribute.ALIGN to either:
* CSS.Attribute.TEXT_ALIGN
* CSS.Attribute.FLOAT
* CSS.Attribute.VERTICAL_ALIGN
* based on the tag associated with the attribute and the
* value of the attribute.
*
* @param AttributeSet containing HTML attributes.
* @return CSS.Attribute mapping for HTML.Attribute.ALIGN.
*/
/*
String htmlAttrValue = (String)htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
CSS.Attribute cssAttr = CSS.Attribute.TEXT_ALIGN;
if (htmlAttrValue != null && htmlAttrSet instanceof Element) {
Element elem = (Element)htmlAttrSet;
if (!elem.isLeaf() && tag.isBlock() && validTextAlignValue(htmlAttrValue)) {
return CSS.Attribute.TEXT_ALIGN;
} else if (isFloater(htmlAttrValue)) {
return CSS.Attribute.FLOAT;
} else if (elem.isLeaf()) {
return CSS.Attribute.VERTICAL_ALIGN;
}
}
return null;
*/
}
/**
* Fetches the tag associated with the HTML AttributeSet.
*
* @param AttributeSet containing the HTML attributes.
* @return HTML.Tag
*/
return tag;
}
return null;
}
}
}
}
/**
* Base class to CSS values in the attribute sets. This
* formats.
* <p>
* The CSS parser uses the parseCssValue method to convert
* a string to whatever format is appropriate a given key
* (i.e. these convertors are stored in a map using the
* CSS.Attribute as a key and the CssValue as the value).
* <p>
* The HTML to CSS conversion process first converts the
* HTML.Attribute to a CSS.Attribute, and then calls
* the parseHtmlValue method on the value of the HTML
* attribute to produce the corresponding CSS value.
* <p>
* The StyleConstants to CSS conversion process first
* converts the StyleConstants attribute to a
* CSS.Attribute, and then calls the fromStyleConstants
* method to convert the StyleConstants value to a
* CSS value.
* <p>
* The CSS to StyleConstants conversion process first
* converts the StyleConstants attribute to a
* CSS.Attribute, and then calls the toStyleConstants
* method to convert the CSS value to a StyleConstants
* value.
*/
/**
* Convert a CSS value string to the internal format
* (for fast processing) used in the attribute sets.
* The fallback storage for any value that we don't
* have a special binary format for is a String.
*/
return value;
}
/**
* Convert an HTML attribute value to a CSS attribute
* value. If there is no conversion, return null.
* This is implemented to simply forward to the CSS
* parsing by default (since some of the attribute
* values are the same). If the attribute value
* isn't recognized as a CSS value it is generally
* returned as null.
*/
return parseCssValue(value);
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion,
* returns <code>null</code>. By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
return null;
}
/**
* Converts a CSS attribute value to a
* <code>StyleConstants</code>
* value. If there is no conversion, returns
* <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param v the view containing <code>AttributeSet</code>
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
return null;
}
/**
* Return the CSS format of the value
*/
return svalue;
}
/**
* The value as a string... before conversion to a
* binary format.
*/
}
/**
* By default CSS attributes are represented as simple
* StyleConstants by default. This class represents the
* value as a string (via the superclass), but
* provides StyleConstants conversion support for the
* CSS attributes that are held as strings.
*/
/**
* Convert a CSS value string to the internal format
* (for fast processing) used in the attribute sets.
* This produces a StringValue, so that it can be
* used to convert from CSS to StyleConstants values.
*/
return sv;
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion
* returns <code>null</code>.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
return parseCssValue("italic");
}
return parseCssValue("");
return parseCssValue("underline");
}
return parseCssValue("");
switch(align) {
case StyleConstants.ALIGN_LEFT:
ta = "left";
break;
case StyleConstants.ALIGN_RIGHT:
ta = "right";
break;
case StyleConstants.ALIGN_CENTER:
ta = "center";
break;
ta = "justify";
break;
default:
ta = "left";
}
return parseCssValue(ta);
return parseCssValue("line-through");
}
return parseCssValue("");
return parseCssValue("super");
}
return parseCssValue("");
return parseCssValue("sub");
}
return parseCssValue("");
}
return null;
}
/**
* Converts a CSS attribute value to a
* <code>StyleConstants</code> value.
* If there is no conversion, returns <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
}
}
}
}
}
}
}
return null;
}
// Used by ViewAttributeSet
boolean isItalic() {
}
boolean isStrike() {
}
boolean isUnderline() {
}
boolean isSub() {
}
boolean isSup() {
}
}
/**
* Represents a value for the CSS.FONT_SIZE attribute.
* The binary format of the value can be one of several
* types. If the type is Float,
* the value is specified in terms of point or
* percentage, depending upon the ending of the
* associated string.
* If the type is Integer, the value is specified
* in terms of a size index.
*/
/**
* Returns the size in points. This is ultimately
* a Font object.
*
* @param a the attribute set the value is being
* requested from. We may need to walk up the
* resolve hierarchy if it's relative.
*/
if (index) {
// it's an index, translate from size table
}
}
else {
}
if (a != null) {
if (resolveParent != null) {
float retValue;
}
else {
}
}
}
// a is null, or no resolve parent.
return 12;
}
}
try {
} else {
}
// relative sizes, larger | smaller (adjust from parent by
// 1.5 pixels)
// em, ex refer to parent sizes
// lengths: pt, mm, cm, pc, in, px
// em (font height 3em would be 3 times font height)
// ex (height of X)
// lengths are (+/-) followed by a number and two letter
// unit identifier
} catch (NumberFormatException nfe) {
}
return fs;
}
return null;
}
try {
/*
* relative sizes in the size attribute are relative
* to the <basefont>'s size.
*/
int baseFontSize = getBaseFontSize();
} else {
}
}
} catch (NumberFormatException nfe) {
}
return fs;
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion
* returns <code>null</code>. By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
return fs;
}
}
/**
* Converts a CSS attribute value to a <code>StyleConstants</code>
* value. If there is no conversion, returns <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
if (v != null) {
}
}
float value;
boolean index;
}
/**
* Returns the font family to use.
*/
return family;
}
if (cIndex == -1) {
}
else {
boolean done = false;
int lastIndex;
cIndex = 0;
while (!done) {
// skip ws.
cIndex++;
// Find next ','
if (cIndex == -1) {
}
int lastCharIndex = cIndex;
}
(lastIndex, lastCharIndex));
}
cIndex++;
}
else {
done = true;
}
}
}
}
return ff;
}
}
// TBD
return parseCssValue(value);
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion
* returns <code>null</code>. By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
}
/**
* Converts a CSS attribute value to a <code>StyleConstants</code>
* value. If there is no conversion, returns <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
return family;
}
}
int getValue() {
return weight;
}
} else {
// PENDING(prinz) add support for relative values
try {
} catch (NumberFormatException nfe) {
}
}
return fw;
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion
* returns <code>null</code>. By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
return parseCssValue("bold");
}
return parseCssValue("normal");
}
/**
* Converts a CSS attribute value to a <code>StyleConstants</code>
* value. If there is no conversion, returns <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
}
boolean isBold() {
return (weight > 500);
}
int weight;
}
/**
* Returns the color to use.
*/
return c;
}
if (c != null) {
cv.c = c;
return cv;
}
return null;
}
return parseCssValue(value);
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion
* returns <code>null</code>. By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
return colorValue;
}
/**
* Converts a CSS attribute value to a <code>StyleConstants</code>
* value. If there is no conversion, returns <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
return c;
}
Color c;
}
return style;
}
return bs;
}
}
return null;
}
throws IOException {
s.defaultWriteObject();
s.writeObject(null);
}
else {
}
}
throws ClassNotFoundException, IOException {
s.defaultReadObject();
}
}
// CSS.Values are static, don't archive it.
}
/**
* if this length value may be negative.
*/
boolean mayBeNegative;
LengthValue() {
this(false);
}
this.mayBeNegative = mayBeNegative;
}
/**
* Returns the length (span) to use.
*/
float getValue() {
return getValue(false);
}
}
/**
* Returns the length (span) to use. If the value represents
* a percentage, it is scaled based on <code>currentValue</code>.
*/
return getValue(currentValue, false);
}
if (percentage) {
return span * currentValue;
}
}
/**
* Returns true if the length represents a percentage of the
* containing box.
*/
boolean isPercentage() {
return percentage;
}
try {
// Assume pixels
lv = new LengthValue();
} catch (NumberFormatException nfe) {
// Not pixels, use LengthUnit
0);
// PENDING: currently, we only support absolute values and
// percentages.
case 0:
// Absolute
lv = new LengthValue();
break;
case 1:
// %
lv = new LengthValue();
lv.percentage = true;
break;
default:
return null;
}
}
return lv;
}
value = "1";
}
return parseCssValue(value);
}
/**
* Converts a <code>StyleConstants</code> attribute value to
* a CSS attribute value. If there is no conversion,
* returns <code>null</code>. By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @param value the value of a <code>StyleConstants</code>
* attribute to be converted
* @return the CSS value that represents the
* <code>StyleConstants</code> value
*/
LengthValue v = new LengthValue();
return v;
}
/**
* Converts a CSS attribute value to a <code>StyleConstants</code>
* value. If there is no conversion, returns <code>null</code>.
* By default, there is no conversion.
*
* @param key the <code>StyleConstants</code> attribute
* @return the <code>StyleConstants</code> attribute value that
* represents the CSS attribute value
*/
}
/** If true, span is a percentage value, and that to determine
* the length another value needs to be passed in. */
boolean percentage;
/** Either the absolute value (percentage == false) or
* a percentage value. */
float span;
}
/**
* BorderWidthValue is used to model BORDER_XXX_WIDTH and adds support
*/
percentage = false;
}
}
}
}
}
// Assume its a length.
return super.parseCssValue(value);
}
return parseCssValue("medium");
}
return parseCssValue(value);
}
/** Values used to represent border width. */
}
/**
* Handles uniquing of CSS values, like lists, and background image
* repeating.
*/
}
return retValue;
}
}
return retValue;
}
}
/**
* Used for background images, to represent the position.
*/
float horizontalPosition;
float verticalPosition;
// bitmask: bit 0, horizontal relative, bit 1 horizontal relative to
// font size, 2 vertical relative to size, 3 vertical relative to
// font size.
//
short relative;
// 'top left' and 'left top' both mean the same as '0% 0%'.
// 'top', 'top center' and 'center top' mean the same as '50% 0%'.
// 'right top' and 'top right' mean the same as '100% 0%'.
// 'left', 'left center' and 'center left' mean the same as
// '0% 50%'.
// 'center' and 'center center' mean the same as '50% 50%'.
// 'right', 'right center' and 'center right' mean the same as
// '100% 50%'.
// 'bottom left' and 'left bottom' mean the same as '0% 100%'.
// 'bottom', 'bottom center' and 'center bottom' mean the same as
// '50% 100%'.
// 'bottom right' and 'right bottom' mean the same as '100% 100%'.
if (count > 0) {
// bit 0 for vert, 1 hor, 2 for center
short found = 0;
int index = 0;
// First, check for keywords
found |= 4;
continue;
}
else {
found |= 1;
}
found |= 1;
continue;
}
}
found |= 2;
}
found |= 2;
}
}
}
}
if (found != 0) {
// vert and no horiz.
}
}
// horiz and no vert.
}
else {
// no horiz, no vert, but center
}
}
else {
// Assume lengths
}
}
}
if (count > 1) {
}
}
}
}
else {
}
}
}
return bp;
}
boolean isHorizontalPositionRelativeToSize() {
}
boolean isHorizontalPositionRelativeToFontSize() {
}
float getHorizontalPosition() {
return horizontalPosition;
}
boolean isVerticalPositionRelativeToSize() {
}
boolean isVerticalPositionRelativeToFontSize() {
}
float getVerticalPosition() {
return verticalPosition;
}
}
/**
* Used for BackgroundImages.
*/
private boolean loadedImage;
return retValue;
}
return parseCssValue(value);
}
// PENDING: this base is wrong for linked style sheets.
if (!loadedImage) {
synchronized(this) {
if (!loadedImage) {
loadedImage = true;
}
}
}
}
}
return image;
}
}
/**
* Parses a length value, this is used internally, and never added
* to an AttributeSet or returned to the developer.
*/
static {
// Not sure about 1.3, determined by experiementation.
int res = 72;
try {
} catch (HeadlessException e) {
}
// mapping according to the CSS2 spec
}
}
type = defaultType;
this.value = defaultValue;
try {
floatValue() / 100.0f;
type = 1;
}
catch (NumberFormatException nfe) { }
}
if (length >= 2) {
try {
type = 0;
}
catch (NumberFormatException nfe) { }
}
try {
type = 3;
}
catch (NumberFormatException nfe) { }
}
this.value = 2f;
type = 2;
}
this.value = -2;
type = 2;
}
else {
// treat like points.
try {
type = 0;
} catch (NumberFormatException nfe) {}
}
}
else if (length > 0) {
// treat like points.
try {
type = 0;
} catch (NumberFormatException nfe) {}
}
}
float scale = 1;
if (scaleFloat != null) {
}
}
}
float scale = 1;
if (scaleFloat != null) {
}
}
}
}
// 0 - value indicates real value
// 1 - % value, value relative to depends upon key.
// 50% will have a value = .5
// 2 - add value to parent value.
// font-size, which is relative to parent).
short type;
float value;
}
/**
* Class used to parse font property. The font property is shorthand
* for the other font properties. This expands the properties, placing
* them in the attributeset.
*/
static class ShorthandFontParser {
/**
* Parses the shorthand font string <code>value</code>, placing the
* result in <code>attr</code>.
*/
// font is of the form:
// [ <font-style> || <font-variant> || <font-weight> ]? <font-size>
// [ / <line-height> ]? <font-family>
int index = 0;
// bitmask, 1 for style, 2 for variant, 3 for weight
short found = 0;
// Check for font-style font-variant font-weight
found |= 1;
}
found |= 2;
}
found |= 4;
}
index++;
}
else {
break;
}
}
"normal");
}
"normal");
}
"normal");
}
// string at index should be the font-size
if (slashIndex != -1) {
}
else {
index++;
}
fontSize);
}
else {
"medium");
}
// Check for line height
}
}
else {
}
// line height
if (lineHeight != null) {
}
else {
"normal");
}
}
else {
"normal");
}
// remainder of strings are font-family
}
family);
}
else {
}
}
}
}
return true;
}
// test for 100-900
}
}
/**
* Parses the background property into its intrinsic values.
*/
static class ShorthandBackgroundParser {
/**
* Parses the shorthand font string <code>value</code>, placing the
* result in <code>attr</code>.
*/
int index = 0;
// bitmask: 0 for image, 1 repeat, 2 attachment, 3 position,
// 4 color
short found = 0;
found |= 1;
}
found |= 2;
}
found |= 4;
}
string + " " +
}
else {
}
found |= 8;
}
found |= 16;
}
}
null);
}
"repeat");
}
BACKGROUND_ATTACHMENT, "scroll");
}
}
// Currently, there is no good way to express this.
/*
if ((found & 16) == 0) {
css.addInternalCSSValue(attr, CSS.Attribute.BACKGROUND_COLOR,
null);
}
*/
}
}
}
}
}
}
}
/**
* Used to parser margin and padding.
*/
static class ShorthandMarginParser {
/**
* <code>value</code>, placing the result in <code>attr</code>.
* <code>names</code> give the 4 instrinsic property names.
*/
int index = 0;
switch (count) {
case 0:
// empty string
return;
case 1:
// Identifies all values.
}
break;
case 2:
// 0 & 2 = strings[0], 1 & 3 = strings[1]
break;
case 3:
break;
default:
}
break;
}
}
}
static class ShorthandBorderParser {
};
boolean valid = false;
if (v != null) {
parts[i] = v;
valid = true;
}
break;
}
}
if (!valid) {
// Part is non-parseable or occured more than once.
return;
}
}
// Unspecified parts get default values.
}
}
// Dispatch collected values to individual properties.
}
}
}
}
}
/**
* Calculate the requirements needed to tile the requirements
* given by the iterator that would be tiled. The calculation
* takes into consideration margin and border spacing.
*/
long minimum = 0;
long maximum = 0;
long preferred = 0;
int lastMargin = 0;
int totalSpacing = 0;
for (int i = 0; i < n; i++) {
int margin0 = lastMargin;
}
// adjust for the spacing area
minimum += totalSpacing;
maximum += totalSpacing;
// set return value
if (r == null) {
r = new SizeRequirements();
}
return r;
}
/**
* Calculate a tiled layout for the given iterator.
* This should be done collapsing the neighboring
* margins to be a total of the maximum of the two
* neighboring margin areas as described in the CSS spec.
*/
/*
* first pass, calculate the preferred sizes, adjustments needed because
* of margin collapsing, and the flexibility to adjust the sizes.
*/
long preferred = 0;
long currentPreferred;
int lastMargin = 0;
int totalSpacing = 0;
//max gain we can get adjusting elements with adjustmentWeight <= i
long gain[] = new long[adjustmentWeightsCount];
//max loss we can get adjusting elements with adjustmentWeight <= i
long loss[] = new long[adjustmentWeightsCount];
for (int i = 0; i < adjustmentWeightsCount; i++) {
}
for (int i = 0; i < n; i++) {
int margin0 = lastMargin;
}
for (int i = 1; i < adjustmentWeightsCount; i++) {
}
/*
* Second pass, expand or contract by as much as possible to reach
* the target span. This takes the margin collapsing into account
* prior to adjusting the span.
*/
// determine the adjustment to be made
int adjustmentLevel = 0;
adjustmentLevel++) {
// adjustmentsArray[] is sorted. I do not bother about
// binary search though
break;
}
}
float adjustmentFactor = 0.0f;
if (desiredAdjustment != 0) {
float maximumAdjustment =
((adjustmentLevel > 0) ?
);
}
}
// make the adjustments
for (int i = 0; i < n; i++) {
)
);
}
}
// while rounding we could lose several pixels.
(int)iter.getTrailingCollapseSpan() -
(int)iter.getBorderWidth();
roundError *= adj;
boolean canAdjust = true;
// check for infinite loop
canAdjust = false;
int offsetAdjust = 0;
// try to distribute roundError. one pixel per cell
for (int i = 0; i < n; i++) {
if (roundError > 0) {
if (boundGap >= 1) {
canAdjust = true;
offsetAdjust += adj;
roundError--;
}
}
}
}
}
/**
* An iterator to express the requirements to use when computing
* layout.
*/
interface LayoutIterator {
int getOffset();
int getSpan();
int getCount();
void setIndex(int i);
//float getAlignment();
float getBorderWidth();
float getLeadingCollapseSpan();
float getTrailingCollapseSpan();
}
//
// Serialization support
//
throws IOException
{
s.defaultWriteObject();
// Determine what values in valueConvertor need to be written out.
while (keys.hasMoreElements()) {
if (!(key instanceof Serializable) &&
// Should we throw an exception here?
}
else if (!(value instanceof Serializable) &&
// Should we throw an exception here?
}
s.writeObject(key);
s.writeObject(value);
}
}
}
throws ClassNotFoundException, IOException
{
s.defaultReadObject();
// Reconstruct the hashtable.
while (numValues-- > 0) {
}
if (staticValue != null) {
value = staticValue;
}
}
}
}
/*
* we need StyleSheet for resolving lenght units. (see
* isW3CLengthUnits)
* we can not pass stylesheet for handling relative sizes. (do not
* think changing public API is necessary)
* CSS is not likely to be accessed from more then one thread.
* Having local storage for StyleSheet for resolving relative
* sizes is safe
*
* idk 08/30/2004
*/
styleSheet = ss;
}
return styleSheet;
}
//
// Instance variables
//
/** Maps from CSS key to CssValue. */
/** Size used for relative units. */
private int baseFontSize;
}