deweese 2003/12/14 10:01:11
Modified: sources/org/apache/batik/bridge SVGUseElementBridge.java
sources/org/apache/batik/css/engine CSSEngine.java
CSSImportedElementRoot.java
sources/org/apache/batik/dom/svg
SVGOMCSSImportedElementRoot.java
SVGStylableElement.java
Log:
1) No longer recascades elements in use tree from foreign documents
(when it did it would use the local documents style sheets - currently
there is no way for those elements to change anyway).
2) Class/Method typo fixes from Cameron McCormack (thanks!)
Revision Changes Path
1.39 +2 -2
xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java
Index: SVGUseElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- SVGUseElementBridge.java 14 Dec 2003 15:14:57 -0000 1.38
+++ SVGUseElementBridge.java 14 Dec 2003 18:01:11 -0000 1.39
@@ -196,7 +196,7 @@
// attach the referenced element to the current document
SVGOMCSSImportedElementRoot root;
- root = new SVGOMCSSImportedElementRoot(document, e);
+ root = new SVGOMCSSImportedElementRoot(document, e, isLocal);
root.appendChild(localRefElement);
SVGOMUseElement ue = (SVGOMUseElement)e;
1.37 +71 -55 xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java
Index: CSSEngine.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- CSSEngine.java 5 Dec 2003 18:32:37 -0000 1.36
+++ CSSEngine.java 14 Dec 2003 18:01:11 -0000 1.37
@@ -158,14 +158,11 @@
/**
* Returns the imported child of the given node, if any.
*/
- public static Node getImportedChild(Node node) {
+ public static CSSImportedElementRoot getImportedChild(Node node) {
if (node instanceof CSSImportNode) {
CSSImportNode inode = (CSSImportNode)node;
CSSImportedElementRoot r = inode.getCSSImportedElementRoot();
- if (r == null) {
- return null;
- }
- return r.getFirstChild();
+ return r;
}
return null;
}
@@ -926,15 +923,15 @@
* Interface for people interesting in having 'primary' properties
* set. Shorthand properties will be expanded "automatically".
*/
- public interface MainPropertyReciever {
+ public interface MainPropertyReceiver {
/**
* Called with a non-shorthand property name and it's value.
*/
- public void setMainPoperty(String name, Value v, boolean important);
+ public void setMainProperty(String name, Value v, boolean important);
};
public void setMainProperties
- (CSSStylableElement elt, final MainPropertyReciever dst,
+ (CSSStylableElement elt, final MainPropertyReceiver dst,
String pname, String value, boolean important){
try {
element = elt;
@@ -947,7 +944,7 @@
if (idx != -1) {
ValueManager vm = valueManagers[idx];
Value v = vm.createValue(lu, CSSEngine.this);
- dst.setMainPoperty(pname, v, important);
+ dst.setMainProperty(pname, v, important);
return;
}
idx = getShorthandIndex(pname);
@@ -1844,7 +1841,7 @@
}
if (removed) {
- invalidateProperties(elt, null, updated);
+ invalidateProperties(elt, null, updated, true);
} else {
int count = 0;
// Invalidate the relative values
@@ -1879,7 +1876,7 @@
props[count++] = i;
}
}
- invalidateProperties(elt, props, null);
+ invalidateProperties(elt, props, null, true);
}
}
break;
@@ -1907,10 +1904,12 @@
/**
* Invalidates all the properties of the given node.
+ *
*/
protected void invalidateProperties(Node node,
int [] properties,
- boolean [] updated) {
+ boolean [] updated,
+ boolean recascade) {
if (!(node instanceof CSSStylableElement))
return; // Not Stylable sub tree
@@ -1920,8 +1919,6 @@
if (style == null)
return; // Nothing to invalidate.
- StyleMap newStyle = getCascadedStyleMap(elt, null);
- elt.setComputedStyleMap(null, newStyle);
boolean [] diffs = new boolean[getNumberOfProperties()];
if (updated != null) {
for (int i=0; i< updated.length; i++) {
@@ -1934,35 +1931,42 @@
}
}
int count =0;
- for (int i=0; i< diffs.length; i++) {
- if (diffs[i])
- count++;
- }
-
- for (int i=0; i<diffs.length; i++) {
- if (diffs[i]) continue; // Already marked changed.
+ if (!recascade) {
+ for (int i=0; i<diffs.length; i++) {
+ if (diffs[i])
+ count++;
+ }
+ } else {
+ StyleMap newStyle = getCascadedStyleMap(elt, null);
+ elt.setComputedStyleMap(null, newStyle);
+ for (int i=0; i<diffs.length; i++) {
+ if (diffs[i]) {
+ count++;
+ continue; // Already marked changed.
+ }
- // Value nv = getComputedStyle(elt, null, i);
- Value nv = newStyle.getValue(i);
- Value ov = null;
- if (!style.isNullCascaded(i)) {
- ov = style.getValue(i);
- if (ov instanceof ComputedValue) {
- ov = ((ComputedValue)ov).getCascadedValue();
+ // Value nv = getComputedStyle(elt, null, i);
+ Value nv = newStyle.getValue(i);
+ Value ov = null;
+ if (!style.isNullCascaded(i)) {
+ ov = style.getValue(i);
+ if (ov instanceof ComputedValue) {
+ ov = ((ComputedValue)ov).getCascadedValue();
+ }
}
- }
- if (nv == ov) continue;
- if ((nv != null) && (ov != null)) {
- if (nv.equals(ov)) continue;
- String ovCssText = ov.getCssText();
- String nvCssText = nv.getCssText();
- if ((nvCssText == ovCssText) ||
- ((nvCssText != null) && nvCssText.equals(ovCssText)))
- continue;
+ if (nv == ov) continue;
+ if ((nv != null) && (ov != null)) {
+ if (nv.equals(ov)) continue;
+ String ovCssText = ov.getCssText();
+ String nvCssText = nv.getCssText();
+ if ((nvCssText == ovCssText) ||
+ ((nvCssText != null) && nvCssText.equals(ovCssText)))
+ continue;
+ }
+ count++;
+ diffs[i] = true;
}
- count++;
- diffs[i] = true;
}
int []props = null;
if (count != 0) {
@@ -1973,13 +1977,18 @@
props[count++] = i;
}
}
- propagateChanges(elt, props);
+ propagateChanges(elt, props, recascade);
}
/**
* Propagates the changes that occurs on the parent of the given node.
+ * Props is a list of known 'changed' properties.
+ * If recascade is true then the stylesheets will be applied
+ * again to see if the any new rules apply (or old rules don't
+ * apply).
*/
- protected void propagateChanges(Node node, int[] props) {
+ protected void propagateChanges(Node node, int[] props,
+ boolean recascade) {
if (!(node instanceof CSSStylableElement))
return;
CSSStylableElement elt = (CSSStylableElement)node;
@@ -2059,14 +2068,21 @@
}
}
- Node c = getImportedChild(node);
- if (c != null) {
- invalidateProperties(c, inherited, null);
+ CSSImportedElementRoot ier = getImportedChild(node);
+ if (ier != null) {
+ Node c = ier.getFirstChild();
+ // Don't recascade trees that have been imported.
+ // If you do it will use the stylesheets from this
+ // document instead of the original document. Also
+ // currently there isn't any supported way to modify
+ // the content imported from the other document so
+ // the cascade can't change.
+ invalidateProperties(c, inherited, null, ier.getIsLocal());
}
for (Node n = node.getFirstChild();
n != null;
n = n.getNextSibling()) {
- invalidateProperties(n, inherited, null);
+ invalidateProperties(n, inherited, null, recascade);
}
}
@@ -2169,7 +2185,7 @@
case MutationEvent.REMOVAL:
{
int [] invalid = { idx };
- invalidateProperties(elt, invalid, null);
+ invalidateProperties(elt, invalid, null, true);
return;
}
}
@@ -2207,7 +2223,7 @@
}
}
- invalidateProperties(elt, props, null);
+ invalidateProperties(elt, props, null, true);
}
/**
@@ -2221,7 +2237,7 @@
styleSheetNodes = null;
// Invalidate all the CSSStylableElements in the document.
invalidateProperties(document.getDocumentElement(),
- null, null);
+ null, null, true);
return;
}
if (et instanceof CSSStylableElement) {
@@ -2231,7 +2247,7 @@
for (Node n = ((Node)evt.getTarget()).getNextSibling();
n != null;
n = n.getNextSibling()) {
- invalidateProperties(n, null, null);
+ invalidateProperties(n, null, null, true);
}
}
}
@@ -2270,7 +2286,7 @@
// Invalidate all the CSSStylableElements in the document.
invalidateProperties(document.getDocumentElement(),
- null, null);
+ null, null, true);
} else if (removedStylableElementSibling != null) {
// Invalidate the CSSStylableElement siblings, to
// correctly match the adjacent selectors and
@@ -2278,7 +2294,7 @@
for (Node n = removedStylableElementSibling;
n != null;
n = n.getNextSibling()) {
- invalidateProperties(n, null, null);
+ invalidateProperties(n, null, null, true);
}
removedStylableElementSibling = null;
}
@@ -2295,7 +2311,7 @@
styleSheetNodes = null;
// Invalidate all the CSSStylableElements in the document.
invalidateProperties(document.getDocumentElement(),
- null, null);
+ null, null, true);
}
}
}
@@ -2354,11 +2370,11 @@
selectorAttributes.contains(name)) {
// An attribute has been modified, invalidate all the
// properties to correctly match attribute selectors.
- invalidateProperties(elt, null, null);
+ invalidateProperties(elt, null, null, true);
for (Node n = elt.getNextSibling();
n != null;
n = n.getNextSibling()) {
- invalidateProperties(n, null, null);
+ invalidateProperties(n, null, null, true);
}
}
}
1.3 +6 -1
xml-batik/sources/org/apache/batik/css/engine/CSSImportedElementRoot.java
Index: CSSImportedElementRoot.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/css/engine/CSSImportedElementRoot.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CSSImportedElementRoot.java 8 Aug 2003 11:38:54 -0000 1.2
+++ CSSImportedElementRoot.java 14 Dec 2003 18:01:11 -0000 1.3
@@ -69,4 +69,9 @@
*/
Element getCSSParentElement();
+ /**
+ * Returns true if the imported element is local to
+ * the owning document.
+ */
+ boolean getIsLocal();
}
1.4 +19 -2
xml-batik/sources/org/apache/batik/dom/svg/SVGOMCSSImportedElementRoot.java
Index: SVGOMCSSImportedElementRoot.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGOMCSSImportedElementRoot.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SVGOMCSSImportedElementRoot.java 8 Aug 2003 11:38:59 -0000 1.3
+++ SVGOMCSSImportedElementRoot.java 14 Dec 2003 18:01:11 -0000 1.4
@@ -73,6 +73,12 @@
protected Element cssParentElement;
/**
+ * Indicates if the imported css element is from
+ * this document.
+ */
+ protected boolean isLocal;
+
+ /**
* Creates a new DocumentFragment object.
*/
protected SVGOMCSSImportedElementRoot() {
@@ -82,9 +88,11 @@
* Creates a new DocumentFragment object.
*/
public SVGOMCSSImportedElementRoot(AbstractDocument owner,
- Element parent) {
+ Element parent,
+ boolean isLocal) {
ownerDocument = owner;
cssParentElement = parent;
+ this.isLocal = isLocal;
}
/**
@@ -108,6 +116,15 @@
*/
public Element getCSSParentElement() {
return cssParentElement;
+ }
+
+
+ /**
+ * Returns true if the imported CSS tree is from this
+ * 'owner' document.
+ */
+ public boolean getIsLocal() {
+ return isLocal;
}
/**
1.13 +3 -3
xml-batik/sources/org/apache/batik/dom/svg/SVGStylableElement.java
Index: SVGStylableElement.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGStylableElement.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SVGStylableElement.java 31 Oct 2003 22:39:41 -0000 1.12
+++ SVGStylableElement.java 14 Dec 2003 18:01:11 -0000 1.13
@@ -543,7 +543,7 @@
implements LiveAttributeValue,
CSSOMSVGStyleDeclaration.ValueProvider,
CSSOMSVGStyleDeclaration.ModificationHandler,
- CSSEngine.MainPropertyReciever {
+ CSSEngine.MainPropertyReceiver {
/**
* The associated CSS object.
@@ -679,7 +679,7 @@
}
}
- public void setMainPoperty(String name, Value v, boolean important) {
+ public void setMainProperty(String name, Value v, boolean important) {
int idx = cssEngine.getPropertyIndex(name);
if (idx == -1)
return; // unknown property
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]