hillion 02/04/12 02:17:53
Modified: sources/org/apache/batik/bridge ScriptingEnvironment.java
sources/org/apache/batik/css/engine CSSEngine.java
SVGCSSEngine.java
Log:
Added support for dynamic update of the 'class' attribute.
Revision Changes Path
1.20 +72 -49
xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java
Index: ScriptingEnvironment.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ScriptingEnvironment.java 10 Apr 2002 16:19:02 -0000 1.19
+++ ScriptingEnvironment.java 12 Apr 2002 09:17:52 -0000 1.20
@@ -46,7 +46,7 @@
* This class contains the informations needed by the SVG scripting.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: ScriptingEnvironment.java,v 1.19 2002/04/10 16:19:02 hillion Exp $
+ * @version $Id: ScriptingEnvironment.java,v 1.20 2002/04/12 09:17:52 hillion Exp $
*/
public class ScriptingEnvironment extends BaseScriptingEnvironment {
@@ -56,11 +56,6 @@
protected Timer timer = new Timer(true);
/**
- * The bridge context.
- */
- protected BridgeContext context;
-
- /**
* The update manager.
*/
protected UpdateManager updateManager;
@@ -71,11 +66,6 @@
protected RunnableQueue updateRunnableQueue;
/**
- * The DOMAttrModified event listener.
- */
- protected EventListener domAttrModifiedListener;
-
- /**
* The DOMNodeInserted event listener.
*/
protected EventListener domNodeInsertedListener;
@@ -199,21 +189,14 @@
*/
public ScriptingEnvironment(BridgeContext ctx) {
super(ctx);
- context = ctx;
updateManager = ctx.getUpdateManager();
updateRunnableQueue = updateManager.getUpdateRunnableQueue();
- Document doc = ctx.getDocument();
-
// Add the scripting listeners.
- addScriptingListeners(doc.getDocumentElement());
+ addScriptingListeners(document.getDocumentElement());
// Add the listeners responsible of updating the event attributes
- EventTarget et = (EventTarget)doc;
- domAttrModifiedListener = new DOMAttrModifiedListener();
- et.addEventListener("DOMAttrModified",
- domAttrModifiedListener,
- false);
+ EventTarget et = (EventTarget)document;
domNodeInsertedListener = new DOMNodeInsertedListener();
et.addEventListener("DOMNodeInserted",
domNodeInsertedListener,
@@ -260,7 +243,17 @@
*/
public void interrupt() {
timer.cancel();
- // !!! remove the DOM listeners.
+ // Remove the scripting listeners.
+ removeScriptingListeners(document.getDocumentElement());
+
+ // Remove the listeners responsible of updating the event attributes
+ EventTarget et = (EventTarget)document;
+ et.removeEventListener("DOMNodeInserted",
+ domNodeInsertedListener,
+ false);
+ et.removeEventListener("DOMAttrRemoved",
+ domNodeRemovedListener,
+ false);
}
/**
@@ -312,7 +305,7 @@
target.addEventListener("endEvent",
endListener,
false);
- }
+ }
if (elt.hasAttributeNS(null, "onrepeat")) {
target.addEventListener("repeatEvent",
repeatListener ,
@@ -362,24 +355,64 @@
}
/**
- * To wrap an event listener.
+ * Removes the scripting listeners from the given element.
*/
- protected class EventListenerWrapper implements EventListener {
-
- /**
- * The wrapped event listener.
- */
- protected EventListener eventListener;
+ protected void removeScriptingListeners(Node node) {
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ // Detach the listeners
+ Element elt = (Element)node;
+ EventTarget target = (EventTarget)elt;
+ if (SVGConstants.SVG_NAMESPACE_URI.equals(elt.getNamespaceURI())) {
+ if (SVGConstants.SVG_SVG_TAG.equals(elt.getLocalName())) {
+ // <svg> listeners
+ target.removeEventListener("SVGAbort",
+ svgAbortListener, false);
+ target.removeEventListener("SVGError",
+ svgErrorListener, false);
+ target.removeEventListener("SVGResize",
+ svgResizeListener, false);
+ target.removeEventListener("SVGScroll",
+ svgScrollListener, false);
+ target.removeEventListener("SVGUnload",
+ svgUnloadListener, false);
+ target.removeEventListener("SVGZoom",
+ svgZoomListener, false);
+ } else {
+ String name = elt.getLocalName();
+ if (name.equals(SVGConstants.SVG_SET_TAG) ||
+ name.startsWith("animate")) {
+ // animation listeners
+ target.removeEventListener("beginEvent",
+ beginListener ,
+ false);
+ target.removeEventListener("endEvent",
+ endListener,
+ false);
+ target.removeEventListener("repeatEvent",
+ repeatListener ,
+ false);
+ return;
+ }
+ }
+ }
- /**
- * Creates a new EventListenerWrapper.
- */
- public EventListenerWrapper(EventListener el) {
- eventListener = el;
+ // UI listeners
+ target.removeEventListener("focusin", focusinListener, false);
+ target.removeEventListener("focusout", focusoutListener, false);
+ target.removeEventListener("activate", activateListener, false);
+ target.removeEventListener("click", clickListener, false);
+ target.removeEventListener("mousedown", mousedownListener, false);
+ target.removeEventListener("mouseup", mouseupListener, false);
+ target.removeEventListener("mouseover", mouseoverListener, false);
+ target.removeEventListener("mouseout", mouseoutListener, false);
+ target.removeEventListener("mousemove", mousemoveListener, false);
}
- public void handleEvent(final Event evt) {
- eventListener.handleEvent(evt);
+ // Removes the listeners from the children
+ for (Node n = node.getFirstChild();
+ n != null;
+ n = n.getNextSibling()) {
+ removeScriptingListeners(n);
}
}
@@ -605,7 +638,7 @@
text = "<svg>" + text + "</svg>";
SAXSVGDocumentFactory df = new SAXSVGDocumentFactory
(XMLResourceDescriptor.getXMLParserClassName());
- String uri = ((SVGOMDocument)context.getDocument()).
+ String uri = ((SVGOMDocument)bridgeContext.getDocument()).
getURLObject().toString();
DocumentFragment result = null;
try {
@@ -669,7 +702,7 @@
} catch (Exception e) {
updateRunnableQueue.invokeLater(new Runnable() {
public void run() {
- h.getURLDone(false, "", "");
+ h.getURLDone(false, null, null);
}
});
}
@@ -735,16 +768,6 @@
}
/**
- * To handle the element attributes modification in the associated
- * document.
- */
- protected class DOMAttrModifiedListener implements EventListener {
- public void handleEvent(Event evt) {
- // !!! Updates the listeners.
- }
- }
-
- /**
* The listener class for 'DOMNodeInserted' event.
*/
protected class DOMNodeInsertedListener implements EventListener {
@@ -758,7 +781,7 @@
*/
protected class DOMNodeRemovedListener implements EventListener {
public void handleEvent(Event evt) {
- // !!! Updates the listeners.
+ removeScriptingListeners((Node)evt.getTarget());
}
}
1.8 +43 -4 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CSSEngine.java 9 Apr 2002 16:27:18 -0000 1.7
+++ CSSEngine.java 12 Apr 2002 09:17:52 -0000 1.8
@@ -58,7 +58,7 @@
* This is the base class for all the CSS engines.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: CSSEngine.java,v 1.7 2002/04/09 16:27:18 hillion Exp $
+ * @version $Id: CSSEngine.java,v 1.8 2002/04/12 09:17:52 hillion Exp $
*/
public abstract class CSSEngine {
@@ -213,6 +213,16 @@
protected String styleLocalName;
/**
+ * The class attribute namespace URI.
+ */
+ protected String classNamespaceURI;
+
+ /**
+ * The class attribute local name.
+ */
+ protected String classLocalName;
+
+ /**
* The non CSS presentational hints.
*/
protected Set nonCSSPresentationalHints;
@@ -288,6 +298,8 @@
* elements is required.
* @param sns The namespace URI of the style attribute.
* @param sln The local name of the style attribute.
+ * @param cns The namespace URI of the class attribute.
+ * @param cln The local name of the class attribute.
* @param hints Whether the CSS engine should support non CSS
* presentational hints.
* @param hintsNS The hints namespace URI.
@@ -301,6 +313,8 @@
String[] pe,
String sns,
String sln,
+ String cns,
+ String cln,
boolean hints,
String hintsNS,
CSSContext ctx) {
@@ -310,6 +324,8 @@
pseudoElementNames = pe;
styleNamespaceURI = sns;
styleLocalName = sln;
+ classNamespaceURI = cns;
+ classLocalName = cln;
cssContext = ctx;
int len = vm.length;
@@ -1840,9 +1856,6 @@
return;
}
- // !!! TODO: class mutation
- // !!! TODO: id mutation
-
MutationEvent mevt = (MutationEvent)evt;
Node attr = mevt.getRelatedNode();
String attrNS = attr.getNamespaceURI();
@@ -1855,6 +1868,32 @@
// The style declaration attribute has been modified.
inlineStyleAttributeUpdated(elt, style, mevt);
+
+ return;
+ }
+ }
+ if ((attrNS == null && classNamespaceURI == null) ||
+ (attrNS != null && attrNS.equals(classNamespaceURI))) {
+ String name = (attrNS == null)
+ ? attr.getNodeName()
+ : attr.getLocalName();
+ if (name.equals(classLocalName)) {
+ // The class attribute has been modified...
+ // ...invalidate all the properties.
+
+ elt.setComputedStyleMap(null, null);
+
+ firePropertiesChangedEvent(elt, ALL_PROPERTIES);
+
+ for (Node n = elt.getFirstChild();
+ n != null;
+ n = n.getNextSibling()) {
+ propagateChanges(n, ALL_PROPERTIES);
+ Node c = getImportedChild(n);
+ if (c != null) {
+ propagateChanges(c, ALL_PROPERTIES);
+ }
+ }
return;
}
1.2 +5 -1 xml-batik/sources/org/apache/batik/css/engine/SVGCSSEngine.java
Index: SVGCSSEngine.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/engine/SVGCSSEngine.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SVGCSSEngine.java 18 Mar 2002 10:28:21 -0000 1.1
+++ SVGCSSEngine.java 12 Apr 2002 09:17:52 -0000 1.2
@@ -28,7 +28,7 @@
* This class provides a CSS engine initialized for SVG.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGCSSEngine.java,v 1.1 2002/03/18 10:28:21 hillion Exp $
+ * @version $Id: SVGCSSEngine.java,v 1.2 2002/04/12 09:17:52 hillion Exp $
*/
public class SVGCSSEngine extends CSSEngine {
@@ -49,6 +49,8 @@
null,
null,
"style",
+ null,
+ "class",
true,
null,
ctx);
@@ -77,6 +79,8 @@
null,
null,
"style",
+ null,
+ "class",
true,
null,
ctx);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]