You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by hi...@apache.org on 2001/03/15 14:59:28 UTC
cvs commit: xml-batik/sources/org/apache/batik/css AbstractViewCSS.java CSSOMReadOnlyStyleDeclaration.java
hillion 01/03/15 05:59:27
Modified: sources/org/apache/batik/css AbstractViewCSS.java
CSSOMReadOnlyStyleDeclaration.java
Log:
- CSS engine optimizations,
- implemented two methods for direct access to the computed style by the bridge.
Revision Changes Path
1.9 +12 -3 xml-batik/sources/org/apache/batik/css/AbstractViewCSS.java
Index: AbstractViewCSS.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/AbstractViewCSS.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractViewCSS.java 2001/03/13 16:28:39 1.8
+++ AbstractViewCSS.java 2001/03/15 13:59:24 1.9
@@ -41,7 +41,7 @@
* {@link org.w3c.dom.css.ViewCSS} interface.
*
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: AbstractViewCSS.java,v 1.8 2001/03/13 16:28:39 hillion Exp $
+ * @version $Id: AbstractViewCSS.java,v 1.9 2001/03/15 13:59:24 hillion Exp $
*/
public abstract class AbstractViewCSS implements ViewCSS {
/**
@@ -101,12 +101,21 @@
*/
public CSSStyleDeclaration getComputedStyle(Element elt,
String pseudoElt) {
+ return getComputedStyleInternal(elt, pseudoElt);
+ }
+
+ /**
+ * Internal version of getComputedStyle().
+ */
+ public CSSOMReadOnlyStyleDeclaration getComputedStyleInternal(Element elt,
+ String pseudoElt) {
Map m = (Map)styles.get(elt);
if (m == null) {
styles.put(elt, m = new HashMap(11));
}
pseudoElt = (pseudoElt == null) ? "" : pseudoElt;
- CSSStyleDeclaration result = (CSSStyleDeclaration)m.get(pseudoElt);
+ CSSOMReadOnlyStyleDeclaration result =
+ (CSSOMReadOnlyStyleDeclaration)m.get(pseudoElt);
if (result == null) {
result = computeStyle(elt, pseudoElt);
@@ -162,7 +171,7 @@
/**
* Computes the cascaded style for the given element and pseudo element.
*/
- public CSSStyleDeclaration computeStyle(Element elt,
+ public CSSOMReadOnlyStyleDeclaration computeStyle(Element elt,
String pseudoElt) {
CSSOMReadOnlyStyleDeclaration result;
result = new CSSOMReadOnlyStyleDeclaration(this, elt);
1.8 +223 -151 xml-batik/sources/org/apache/batik/css/CSSOMReadOnlyStyleDeclaration.java
Index: CSSOMReadOnlyStyleDeclaration.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/CSSOMReadOnlyStyleDeclaration.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CSSOMReadOnlyStyleDeclaration.java 2000/12/12 13:11:51 1.7
+++ CSSOMReadOnlyStyleDeclaration.java 2001/03/15 13:59:25 1.8
@@ -29,7 +29,7 @@
* interface.
*
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: CSSOMReadOnlyStyleDeclaration.java,v 1.7 2000/12/12 13:11:51 hillion Exp $
+ * @version $Id: CSSOMReadOnlyStyleDeclaration.java,v 1.8 2001/03/15 13:59:25 hillion Exp $
*/
public class CSSOMReadOnlyStyleDeclaration implements CSSStyleDeclaration {
/**
@@ -55,7 +55,7 @@
/**
* The ViewCSS.
*/
- protected ViewCSS viewCSS;
+ protected AbstractViewCSS viewCSS;
/**
* The associated parent element.
@@ -65,14 +65,14 @@
/**
* Creates a new CSSOMReadOnlyStyleDeclaration object.
*/
- public CSSOMReadOnlyStyleDeclaration(ViewCSS v, Element elt) {
+ public CSSOMReadOnlyStyleDeclaration(AbstractViewCSS v, Element elt) {
setContext(v, elt);
}
/**
* Sets the declaration context.
*/
- public void setContext(ViewCSS v, Element elt) {
+ public void setContext(AbstractViewCSS v, Element elt) {
viewCSS = v;
parentElement = HiddenChildElementSupport.getParentElement(elt);
}
@@ -85,9 +85,9 @@
String result = "";
for (int i = properties.size() - 1; i >= 0; i--) {
result += " " + properties.key(i) + ": ";
- ValueEntry ve = (ValueEntry)properties.item(i);
- if (ve.getValue() != null) {
- result += ((CSSValue)ve.getValue()).getCssText();
+ ValueEntry ve = properties.item(i);
+ if (ve.value != null) {
+ result += ve.value.getCssText();
}
result += ve.getPriority() + ";\n";
}
@@ -112,17 +112,17 @@
*/
public String getPropertyValue(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
+ ValueEntry ve = properties.get(s);
if (ve == null) {
return "";
}
- if (ve.getValue() == null ||
- ve.getValue() == ImmutableInherit.INSTANCE) {
+ if (ve.value == null) { // ||
+ //ve.value.getImmutableValue() == ImmutableInherit.INSTANCE) {
CSSStyleDeclaration sd;
sd = viewCSS.getComputedStyle(parentElement, null);
return sd.getPropertyCSSValue(s).getCssText();
} else {
- return ve.getValue().getCssText();
+ return ve.value.getCssText();
}
}
@@ -132,30 +132,46 @@
*/
public CSSValue getPropertyCSSValue(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
+ ValueEntry ve = properties.get(s);
if (ve == null) {
return null;
}
- if (ve.getValue() == null) {
+ if (ve.value == null) {
CSSStyleDeclaration sd;
sd = viewCSS.getComputedStyle(parentElement, null);
CSSOMReadOnlyValue v =
(CSSOMReadOnlyValue)sd.getPropertyCSSValue(s);
- CSSOMReadOnlyValue res;
- ve.setValue(res = new CSSOMReadOnlyValue(v.getImmutableValue()));
- return res;
+ return ve.value = new CSSOMReadOnlyValue(v.getImmutableValue());
} else {
- return ve.getValue();
+ return ve.value;
}
}
/**
+ * Internal version of getPropertyCSSValue().
+ */
+ public CSSOMReadOnlyValue getPropertyCSSValueInternal(String propertyName) {
+ ValueEntry ve = properties.get(propertyName);
+ if (ve == null) {
+ return null;
+ }
+ if (ve.value == null) {
+ CSSOMReadOnlyStyleDeclaration sd;
+ sd = viewCSS.getComputedStyleInternal(parentElement, null);
+ CSSOMReadOnlyValue v = sd.getPropertyCSSValueInternal(propertyName);
+ return ve.value = new CSSOMReadOnlyValue(v.getImmutableValue());
+ } else {
+ return ve.value;
+ }
+ }
+
+ /**
* Returns the local CSSValue.
*/
public CSSValue getLocalPropertyCSSValue(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
- return (ve == null) ? null : ve.getValue();
+ ValueEntry ve = properties.get(s);
+ return (ve == null) ? null : ve.value;
}
/**
@@ -166,7 +182,8 @@
String imp,
int orig) {
/*ValueEntry ve = (ValueEntry)*/
- properties.put(propertyName, createValueEntry(v, imp, orig));
+ properties.put(propertyName, createValueEntry((CSSOMReadOnlyValue)v,
+ imp, orig));
}
/**
@@ -174,12 +191,12 @@
*/
public int getPropertyOrigin(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
+ ValueEntry ve = properties.get(s);
if (ve == null) {
return AUTHOR_ORIGIN;
}
- if (ve.getValue() == null ||
- ve.getValue() == ImmutableInherit.INSTANCE) {
+ if (ve.value == null) { // ||
+ //ve.value.getImmutableValue() == ImmutableInherit.INSTANCE) {
CSSStyleDeclaration sd;
sd = viewCSS.getComputedStyle(parentElement, null);
return ((CSSOMReadOnlyStyleDeclaration)
@@ -194,7 +211,7 @@
*/
public int getLocalPropertyOrigin(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
+ ValueEntry ve = properties.get(s);
return (ve == null) ? AUTHOR_ORIGIN : ve.getOrigin();
}
@@ -215,12 +232,12 @@
*/
public String getPropertyPriority(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
+ ValueEntry ve = properties.get(s);
if (ve == null) {
return "";
}
- if (ve.getValue() == null ||
- ve.getValue() == ImmutableInherit.INSTANCE) {
+ if (ve.value == null) { // ||
+ //ve.value.getImmutableValue() == ImmutableInherit.INSTANCE) {
CSSStyleDeclaration sd;
sd = viewCSS.getComputedStyle(parentElement, null);
return ((CSSOMReadOnlyStyleDeclaration)
@@ -235,7 +252,7 @@
*/
public String getLocalPropertyPriority(String propertyName) {
String s = propertyName.toLowerCase().intern();
- ValueEntry ve = (ValueEntry)properties.get(s);
+ ValueEntry ve = properties.get(s);
return (ve == null) ? "" : ve.getPriority();
}
@@ -264,7 +281,7 @@
* org.w3c.dom.css.CSSStyleDeclaration#item(int)}.
*/
public String item(int index) {
- String result = (String)properties.key(index);
+ String result = properties.key(index);
return (result == null) ? "" : result;
}
@@ -280,7 +297,7 @@
/**
* Creates a new value entry.
*/
- protected ValueEntry createValueEntry(CSSValue v, String s, int p) {
+ protected ValueEntry createValueEntry(CSSOMReadOnlyValue v, String s, int p) {
switch (p) {
case USER_AGENT_ORIGIN:
if (s.length() == 0) {
@@ -308,56 +325,58 @@
/**
* This interface represents a value entry in the table.
*/
- protected interface ValueEntry {
+ protected abstract static class ValueEntry {
+
/**
- * Returns the CSS value.
+ * Returns the priority.
*/
- CSSValue getValue();
+ public abstract String getPriority();
/**
- * Sets the CSS value.
+ * Returns the value origin.
*/
- void setValue(CSSValue v);
+ public abstract int getOrigin();
+ /**
+ * The hash code
+ */
+ public int hash;
+
+ /**
+ * The key
+ */
+ public String key;
+
/**
- * Returns the priority.
+ * The value.
*/
- String getPriority();
+ public CSSOMReadOnlyValue value;
+ /**
+ * The next entry
+ */
+ public ValueEntry next;
+
/**
- * Returns the value origin.
+ * Initializes the value.
*/
- int getOrigin();
+ public void initialize(int h, String k, ValueEntry n) {
+ hash = h;
+ key = k;
+ next = n;
+ }
}
/**
* To store an important user-agent value.
*/
protected static class ImportantUserAgentValueEntry
- implements ValueEntry {
- /**
- * The CSS value.
- */
- protected CSSValue value;
+ extends ValueEntry {
/**
* Creates a new value entry.
- */
- public ImportantUserAgentValueEntry(CSSValue v) {
- value = v;
- }
-
- /**
- * Returns the CSS value.
- */
- public CSSValue getValue() {
- return value;
- }
-
- /**
- * Sets the CSS value.
*/
- public void setValue(CSSValue v) {
+ public ImportantUserAgentValueEntry(CSSOMReadOnlyValue v) {
value = v;
}
@@ -380,34 +399,16 @@
* To store a user-agent value.
*/
protected static class UserAgentValueEntry
- implements ValueEntry {
- /**
- * The CSS value.
- */
- protected CSSValue value;
+ extends ValueEntry {
/**
* Creates a new value entry.
*/
- public UserAgentValueEntry(CSSValue v) {
+ public UserAgentValueEntry(CSSOMReadOnlyValue v) {
value = v;
}
/**
- * Returns the CSS value.
- */
- public CSSValue getValue() {
- return value;
- }
-
- /**
- * Sets the CSS value.
- */
- public void setValue(CSSValue v) {
- value = v;
- }
-
- /**
* Returns the priority.
*/
public String getPriority() {
@@ -426,34 +427,16 @@
* To store an important user value.
*/
protected static class ImportantUserValueEntry
- implements ValueEntry {
- /**
- * The CSS value.
- */
- protected CSSValue value;
+ extends ValueEntry {
/**
* Creates a new value entry.
*/
- public ImportantUserValueEntry(CSSValue v) {
+ public ImportantUserValueEntry(CSSOMReadOnlyValue v) {
value = v;
}
/**
- * Returns the CSS value.
- */
- public CSSValue getValue() {
- return value;
- }
-
- /**
- * Sets the CSS value.
- */
- public void setValue(CSSValue v) {
- value = v;
- }
-
- /**
* Returns the priority.
*/
public String getPriority() {
@@ -472,30 +455,12 @@
* To store a user value.
*/
protected static class UserValueEntry
- implements ValueEntry {
- /**
- * The CSS value.
- */
- protected CSSValue value;
+ extends ValueEntry {
/**
* Creates a new value entry.
- */
- public UserValueEntry(CSSValue v) {
- value = v;
- }
-
- /**
- * Returns the CSS value.
*/
- public CSSValue getValue() {
- return value;
- }
-
- /**
- * Sets the CSS value.
- */
- public void setValue(CSSValue v) {
+ public UserValueEntry(CSSOMReadOnlyValue v) {
value = v;
}
@@ -518,38 +483,49 @@
* To store an important author value.
*/
protected static class ImportantAuthorValueEntry
- implements ValueEntry {
- /**
- * The CSS value.
- */
- protected CSSValue value;
+ extends ValueEntry {
/**
* Creates a new value entry.
*/
- public ImportantAuthorValueEntry(CSSValue v) {
+ public ImportantAuthorValueEntry(CSSOMReadOnlyValue v) {
value = v;
}
/**
- * Returns the CSS value.
+ * Returns the priority.
*/
- public CSSValue getValue() {
- return value;
+ public String getPriority() {
+ return "!important";
}
/**
- * Sets the CSS value.
+ * Returns the value origin.
*/
- public void setValue(CSSValue v) {
+ public int getOrigin() {
+ return AUTHOR_ORIGIN;
+ }
+ }
+
+ /**
+ * To store a author value.
+ */
+ protected static class AuthorValueEntry
+ extends ValueEntry {
+
+ /**
+ * Creates a new value entry.
+ */
+ public AuthorValueEntry(CSSOMReadOnlyValue v) {
value = v;
}
+
/**
* Returns the priority.
*/
public String getPriority() {
- return "!important";
+ return "";
}
/**
@@ -561,48 +537,144 @@
}
/**
- * To store a author value.
+ * To store the values.
*/
- protected static class AuthorValueEntry
- implements ValueEntry {
+ protected static class PropertyMap {
+
/**
- * The CSS value.
+ * The initial capacity
*/
- protected CSSValue value;
+ protected final static int INITIAL_CAPACITY = 11;
/**
- * Creates a new value entry.
+ * The underlying array
*/
- public AuthorValueEntry(CSSValue v) {
- value = v;
+ protected ValueEntry[] table;
+
+ /**
+ * The number of entries
+ */
+ protected int count;
+
+ /**
+ * Creates a new table.
+ */
+ public PropertyMap() {
+ table = new ValueEntry[INITIAL_CAPACITY];
}
+ /**
+ * Returns the size of this table.
+ */
+ public int size() {
+ return count;
+ }
+
/**
- * Returns the CSS value.
+ * Gets the value of a variable
+ * @return the value or null
*/
- public CSSValue getValue() {
- return value;
+ public ValueEntry get(String key) {
+ int hash = key.hashCode() & 0x7FFFFFFF;
+ int index = hash % table.length;
+
+ for (ValueEntry e = table[index]; e != null; e = e.next) {
+ if ((e.hash == hash) && e.key == key) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Sets a new value for the given variable
+ * @return the old value or null
+ */
+ public void put(String key, ValueEntry valueEntry) {
+ int hash = key.hashCode() & 0x7FFFFFFF;
+ int index = hash % table.length;
+
+ for (ValueEntry e = table[index]; e != null; e = e.next) {
+ if ((e.hash == hash) && e.key == key) {
+ e.value = valueEntry.value;
+ }
+ }
+
+ // The key is not in the hash table
+ int len = table.length;
+ if (count++ >= (len * 3) >>> 2) {
+ rehash();
+ index = hash % table.length;
+ }
+
+ valueEntry.initialize(hash, key, table[index]);
+ table[index] = valueEntry;
}
/**
- * Sets the CSS value.
+ * Returns the key at the given position or null.
*/
- public void setValue(CSSValue v) {
- value = v;
+ public String key(int index) {
+ if (index < 0 || index >= count) {
+ return null;
+ }
+ int j = 0;
+ for (int i = 0; i < table.length; i++) {
+ ValueEntry e = table[i];
+ if (e == null) {
+ continue;
+ }
+ do {
+ if (j++ == index) {
+ return e.key;
+ }
+ e = e.next;
+ } while (e != null);
+ }
+ return null;
}
/**
- * Returns the priority.
+ * Returns the item at the given position.
*/
- public String getPriority() {
- return "";
+ public ValueEntry item(int index) {
+ if (index < 0 || index >= count) {
+ return null;
+ }
+ int j = 0;
+ for (int i = 0; i < table.length; i++) {
+ ValueEntry e = table[i];
+ if (e == null) {
+ continue;
+ }
+ do {
+ if (j++ == index) {
+ return e;
+ }
+ e = e.next;
+ } while (e != null);
+ }
+ return null;
}
/**
- * Returns the value origin.
+ * Rehash the table
*/
- public int getOrigin() {
- return AUTHOR_ORIGIN;
+ protected void rehash () {
+ ValueEntry[] oldTable = table;
+
+ table = new ValueEntry[oldTable.length * 2 + 1];
+
+ for (int i = oldTable.length-1; i >= 0; i--) {
+ for (ValueEntry old = oldTable[i]; old != null;) {
+ ValueEntry e = old;
+ old = old.next;
+
+ int index = e.hash % table.length;
+ e.next = table[index];
+ table[index] = e;
+ }
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org