You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2005/09/13 15:31:09 UTC
svn commit: r280553 [7/9] - in /xmlgraphics/batik/trunk: ./
resources/org/apache/batik/apps/svgbrowser/resources/
sources/org/apache/batik/bridge/ sources/org/apache/batik/bridge/svg12/
sources/org/apache/batik/css/engine/ sources/org/apache/batik/dom/...
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractParentNode.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractParentNode.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractParentNode.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractParentNode.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2003 The Apache Software Foundation
+ Copyright 2000-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,6 +19,9 @@
import java.io.Serializable;
+import org.apache.batik.dom.events.DOMMutationEvent;
+import org.apache.batik.util.XMLConstants;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -31,7 +34,6 @@
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
* @version $Id$
*/
-
public abstract class AbstractParentNode extends AbstractNode {
/**
@@ -382,15 +384,17 @@
AbstractDocument doc = getCurrentDocument();
if (doc.getEventsEnabled()) {
DocumentEvent de = (DocumentEvent)doc;
- MutationEvent ev = (MutationEvent)de.createEvent("MutationEvents");
- ev.initMutationEvent("DOMSubtreeModified",
- true, // canBubbleArg
- false, // cancelableArg
- null, // relatedNodeArg
- null, // prevValueArg
- null, // newValueArg
- null, // attrNameArg
- MutationEvent.MODIFICATION);
+ DOMMutationEvent ev
+ = (DOMMutationEvent) de.createEvent("MutationEvents");
+ ev.initMutationEventNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMSubtreeModified",
+ true, // canBubbleArg
+ false, // cancelableArg
+ null, // relatedNodeArg
+ null, // prevValueArg
+ null, // newValueArg
+ null, // attrNameArg
+ MutationEvent.MODIFICATION);
dispatchEvent(ev);
}
}
@@ -402,15 +406,17 @@
AbstractDocument doc = getCurrentDocument();
if (doc.getEventsEnabled()) {
DocumentEvent de = (DocumentEvent)doc;
- MutationEvent ev = (MutationEvent)de.createEvent("MutationEvents");
- ev.initMutationEvent("DOMNodeInserted",
- true, // canBubbleArg
- false, // cancelableArg
- this, // relatedNodeArg
- null, // prevValueArg
- null, // newValueArg
- null, // attrNameArg
- MutationEvent.ADDITION);
+ DOMMutationEvent ev
+ = (DOMMutationEvent) de.createEvent("MutationEvents");
+ ev.initMutationEventNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeInserted",
+ true, // canBubbleArg
+ false, // cancelableArg
+ this, // relatedNodeArg
+ null, // prevValueArg
+ null, // newValueArg
+ null, // attrNameArg
+ MutationEvent.ADDITION);
AbstractNode n = (AbstractNode)node;
n.dispatchEvent(ev);
n.fireDOMNodeInsertedIntoDocumentEvent();
@@ -424,15 +430,17 @@
AbstractDocument doc = getCurrentDocument();
if (doc.getEventsEnabled()) {
DocumentEvent de = (DocumentEvent)doc;
- MutationEvent ev = (MutationEvent)de.createEvent("MutationEvents");
- ev.initMutationEvent("DOMNodeRemoved",
- true, // canBubbleArg
- false, // cancelableArg
- this, // relatedNodeArg
- null, // prevValueArg
- null, // newValueArg
- null, // attrNameArg
- MutationEvent.REMOVAL);
+ DOMMutationEvent ev
+ = (DOMMutationEvent) de.createEvent("MutationEvents");
+ ev.initMutationEventNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeRemoved",
+ true, // canBubbleArg
+ false, // cancelableArg
+ this, // relatedNodeArg
+ null, // prevValueArg
+ null, // newValueArg
+ null, // attrNameArg
+ MutationEvent.REMOVAL);
AbstractNode n = (AbstractNode)node;
n.dispatchEvent(ev);
n.fireDOMNodeRemovedFromDocumentEvent();
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtendedNode.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtendedNode.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtendedNode.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtendedNode.java Tue Sep 13 06:29:29 2005
@@ -28,7 +28,6 @@
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
* @version $Id$
*/
-
public interface ExtendedNode extends Node, NodeEventTarget {
/**
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/AbstractEvent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/AbstractEvent.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/AbstractEvent.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/AbstractEvent.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000,2002-2003 The Apache Software Foundation
+ Copyright 2000,2002-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
*/
package org.apache.batik.dom.events;
+import org.apache.batik.dom.xbl.OriginalEvent;
+
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventTarget;
@@ -27,7 +29,8 @@
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
* @version $Id$
*/
-public abstract class AbstractEvent implements Event {
+public abstract class AbstractEvent
+ implements Event, OriginalEvent, Cloneable {
/**
* The event type.
@@ -86,6 +89,21 @@
protected String namespaceURI;
/**
+ * The event from which this event was cloned for sXBL event retargetting.
+ */
+ protected Event originalEvent;
+
+ /**
+ * The number of nodes in the document this event will visit
+ * during capturing, bubbling and firing at the target.
+ * A value of 0 means to let the event be captured and bubble all
+ * the way to the document node. This field is used to handle
+ * events which should not cross sXBL shadow scopes without stopping
+ * or retargetting.
+ */
+ protected int bubbleLimit = 0;
+
+ /**
* DOM: The <code>type</code> property represents the event name
* as a string property. The string must be an XML name.
*/
@@ -158,6 +176,13 @@
}
/**
+ * Gets the event from which this event was cloned.
+ */
+ public Event getOriginalEvent() {
+ return originalEvent;
+ }
+
+ /**
* DOM: The <code>stopPropagation</code> method is used prevent
* further propagation of an event during event flow. If this
* method is called by any <code>EventListener</code> the event
@@ -288,5 +313,42 @@
public static boolean getEventPreventDefault(Event evt) {
AbstractEvent ae = (AbstractEvent)evt;
return ae.isDefaultPrevented();
+ }
+
+ /**
+ * Returns a new Event with the same field values as this object.
+ */
+ public Object clone() throws CloneNotSupportedException {
+ AbstractEvent newEvent = (AbstractEvent) super.clone();
+ newEvent.timeStamp = System.currentTimeMillis();
+ return newEvent;
+ }
+
+ /**
+ * Clones this event and sets the originalEvent field of the new event
+ * to be equal to this event.
+ */
+ public AbstractEvent cloneEvent() {
+ try {
+ AbstractEvent newEvent = (AbstractEvent) clone();
+ newEvent.originalEvent = this;
+ return newEvent;
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the bubble limit for this event.
+ */
+ public int getBubbleLimit() {
+ return bubbleLimit;
+ }
+
+ /**
+ * Set the number of nodse this event will visit.
+ */
+ public void setBubbleLimit(int n) {
+ bubbleLimit = n;
}
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/CustomEvent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/CustomEvent.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/CustomEvent.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/CustomEvent.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2001 The Apache Software Foundation
+ Copyright 2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,6 +17,11 @@
*/
package org.apache.batik.dom.events;
+import org.apache.batik.dom.xbl.OriginalEvent;
+
+import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventTarget;
+
/**
* An interface DOM 3 custom events should implement to be used with
* Batik's DOM implementation.
@@ -33,11 +38,44 @@
* does not implement this interface, reflection will be used to access
* the needed methods.
* </p>
+ * <p>
+ * This interface also has two methods--{@link #resumePropagation} and
+ * {@link #setOriginalEvent}--which allow custom events to be handled
+ * properly.
+ * </p>
*
* @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
* @version $Id$
*/
-public interface CustomEvent extends org.w3c.dom.events.CustomEvent {
+public interface CustomEvent
+ extends org.w3c.dom.events.CustomEvent, OriginalEvent {
+
+ /**
+ * Clears the 'propagationStopped' and 'immediatePropagationStopped'
+ * flags. This is needed for standard event dispatching and should
+ * only be called by the DOM Events implementation.
+ */
+ void resumePropagation();
+
+ /**
+ * Sets the target for this event. This is needed for initialization
+ * of the custom event object and should only be called by the DOM Events
+ * implementation.
+ */
+ void setTarget(EventTarget target);
+
+ /**
+ * Clones this event object and sets the 'originalEvent' field of the
+ * clone to be equal to the original event object. This is needed
+ * for sXBL event retargetting and should only be called by the
+ * DOM Events implementation.
+ */
+ CustomEvent retarget(EventTarget target);
+
+ /**
+ * Returns the event from which this event was cloned.
+ */
+ Event getOriginalEvent();
// Members inherited from DOM Level 3 Events org.w3c.dom.events.Event
// interface follow.
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/DOMMouseEvent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/DOMMouseEvent.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/DOMMouseEvent.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/DOMMouseEvent.java Tue Sep 13 06:29:29 2005
@@ -18,6 +18,7 @@
package org.apache.batik.dom.events;
import java.util.HashSet;
+import java.util.Iterator;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.events.MouseEvent;
@@ -35,10 +36,6 @@
private int screenY;
private int clientX;
private int clientY;
- private boolean ctrlKey;
- private boolean altKey;
- private boolean shiftKey;
- private boolean metaKey;
private short button;
private EventTarget relatedTarget;
@@ -152,6 +149,23 @@
}
/**
+ * Returns the modifiers string for this event.
+ */
+ public String getModifiersString() {
+ if (modifierKeys.isEmpty()) {
+ return "";
+ }
+ StringBuffer sb = new StringBuffer();
+ Iterator i = modifierKeys.iterator();
+ sb.append((String) i.next());
+ while (i.hasNext()) {
+ sb.append(' ');
+ sb.append((String) i.next());
+ }
+ return sb.toString();
+ }
+
+ /**
* DOM: The <code>initMouseEvent</code> method is used to
* initialize the value of a <code>MouseEvent</code> created
* through the <code>DocumentEvent</code> interface. This method
@@ -205,12 +219,20 @@
this.screenY = screenYArg;
this.clientX = clientXArg;
this.clientY = clientYArg;
- this.ctrlKey = ctrlKeyArg;
- this.altKey = altKeyArg;
- this.shiftKey = shiftKeyArg;
- this.metaKey = metaKeyArg;
- this.button = buttonArg;
- this.relatedTarget = relatedTargetArg;
+ if (ctrlKeyArg) {
+ modifierKeys.add(DOMKeyboardEvent.KEY_CONTROL);
+ }
+ if (altKeyArg) {
+ modifierKeys.add(DOMKeyboardEvent.KEY_ALT);
+ }
+ if (shiftKeyArg) {
+ modifierKeys.add(DOMKeyboardEvent.KEY_SHIFT);
+ }
+ if (metaKeyArg) {
+ modifierKeys.add(DOMKeyboardEvent.KEY_META);
+ }
+ this.button = buttonArg;
+ this.relatedTarget = relatedTargetArg;
}
/**
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventListenerList.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventListenerList.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventListenerList.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventListenerList.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2002 The Apache Software Foundation
+ Copyright 2000-2002,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
/**
* Total number of event listners.
*/
- int n;
+ protected int n;
/**
* Linked list of entries.
@@ -110,8 +110,7 @@
}
/**
- * Returns an array containing all event listener entries for
- * the given group.
+ * Returns an array containing all event listener entries.
*/
public Entry[] getEventListeners() {
if (listeners != null) {
@@ -126,8 +125,7 @@
}
/**
- * Returns an array of EventListeners that match the given namespace URI
- * and group.
+ * Returns an array of EventListeners that match the given namespace URI.
*/
public Entry[] getEventListeners(String namespaceURI) {
if (namespaceURI == null) {
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventSupport.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventSupport.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventSupport.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/events/EventSupport.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2003 The Apache Software Foundation
+ Copyright 2000-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -95,7 +95,7 @@
*/
public void addEventListener(String type, EventListener listener,
boolean useCapture) {
- addEventListenerNS(null, type, null, listener, useCapture);
+ addEventListenerNS(null, type, listener, useCapture, null);
}
/**
@@ -104,9 +104,9 @@
*/
public void addEventListenerNS(String namespaceURI,
String type,
- Object group,
EventListener listener,
- boolean useCapture) {
+ boolean useCapture,
+ Object group) {
HashTable listeners;
if (useCapture) {
if (capturingListeners == null) {
@@ -156,16 +156,16 @@
*/
public void removeEventListener(String type, EventListener listener,
boolean useCapture) {
- removeEventListener(null, type, listener, useCapture);
+ removeEventListenerNS(null, type, listener, useCapture);
}
/**
* Deregisters an event listener.
*/
- public void removeEventListener(String namespaceURI,
- String type,
- EventListener listener,
- boolean useCapture) {
+ public void removeEventListenerNS(String namespaceURI,
+ String type,
+ EventListener listener,
+ boolean useCapture) {
HashTable listeners;
if (useCapture) {
listeners = capturingListeners;
@@ -259,6 +259,8 @@
aevt.stopPropagation(false);
aevt.stopImmediatePropagation(false);
aevt.preventDefault(false);
+ } else {
+ ce.setTarget(target);
}
// dump the tree hierarchy from top to the target
NodeEventTarget [] ancestors = getAncestors(target);
@@ -312,26 +314,15 @@
return isCustom ? ce.isDefaultPrevented() : aevt.isDefaultPrevented();
}
- private static void fireEventListeners(NodeEventTarget node,
- Event e,
- boolean useCapture,
- HashSet stoppedGroups,
- HashSet toBeStoppedGroups,
- boolean isCustom) {
- String type = e.getType();
- EventSupport support = node.getEventSupport();
- // check if the event support has been instantiated
- if (support == null) {
- return;
- }
- EventListenerList list = support.getEventListeners(type, useCapture);
- // check if the event listeners list is not empty
- if (list == null) {
- return;
- }
- // dump event listeners, we get the registered listeners NOW
- EventListenerList.Entry[] listeners = list.getEventListeners();
- // check if event listeners with the correct event type exist
+ /**
+ * Fires the given listeners on the given event target.
+ */
+ protected void fireEventListeners(NodeEventTarget node,
+ Event e,
+ EventListenerList.Entry[] listeners,
+ HashSet stoppedGroups,
+ HashSet toBeStoppedGroups,
+ boolean isCustom) {
if (listeners == null) {
return;
}
@@ -354,25 +345,30 @@
continue;
}
Object group = listeners[i].getGroup();
- if (!stoppedGroups.contains(group)) {
+ if (stoppedGroups == null || !stoppedGroups.contains(group)) {
listeners[i].getListener().handleEvent(e);
if (isCustom) {
if (ce.isImmediatePropagationStopped()) {
- stoppedGroups.add(group);
- // XXX How to not stop other groups?
- // Need something like
- // aevt.stopImmediatePropagation(false);
+ if (stoppedGroups != null) {
+ stoppedGroups.add(group);
+ }
+ ce.resumePropagation();
} else if (ce.isPropagationStopped()) {
- toBeStoppedGroups.add(group);
- // XXX How to not stop other groups?
- // Need something like aevt.stopPropagation(false);
+ if (toBeStoppedGroups != null) {
+ toBeStoppedGroups.add(group);
+ }
+ ce.resumePropagation();
}
} else {
if (aevt.getStopImmediatePropagation()) {
- stoppedGroups.add(group);
+ if (stoppedGroups != null) {
+ stoppedGroups.add(group);
+ }
aevt.stopImmediatePropagation(false);
} else if (aevt.getStopPropagation()) {
- toBeStoppedGroups.add(group);
+ if (toBeStoppedGroups != null) {
+ toBeStoppedGroups.add(group);
+ }
aevt.stopPropagation(false);
}
}
@@ -385,8 +381,36 @@
}
}
- // Returns all ancestors of the specified node
- private static NodeEventTarget [] getAncestors(NodeEventTarget node) {
+ /**
+ * Fires the registered listeners on the given event target.
+ */
+ protected void fireEventListeners(NodeEventTarget node,
+ Event e,
+ boolean useCapture,
+ HashSet stoppedGroups,
+ HashSet toBeStoppedGroups,
+ boolean isCustom) {
+ String type = e.getType();
+ EventSupport support = node.getEventSupport();
+ // check if the event support has been instantiated
+ if (support == null) {
+ return;
+ }
+ EventListenerList list = support.getEventListeners(type, useCapture);
+ // check if the event listeners list is not empty
+ if (list == null) {
+ return;
+ }
+ // dump event listeners, we get the registered listeners NOW
+ EventListenerList.Entry[] listeners = list.getEventListeners();
+ fireEventListeners(node, e, listeners, stoppedGroups,
+ toBeStoppedGroups, isCustom);
+ }
+
+ /**
+ * Returns all ancestors of the specified node.
+ */
+ protected NodeEventTarget [] getAncestors(NodeEventTarget node) {
node = node.getParentNodeEventTarget(); // skip current node
int nancestors = 0;
for (NodeEventTarget n = node;
@@ -460,6 +484,74 @@
}
/**
+ * Calls {@link AbstractEvent#setTarget}.
+ */
+ protected void setTarget(AbstractEvent evt, NodeEventTarget target) {
+ evt.setTarget(target);
+ }
+
+ /**
+ * Calls {@link AbstractEvent#stopPropagation(boolean)}.
+ */
+ protected void stopPropagation(AbstractEvent evt, boolean b) {
+ evt.stopPropagation(b);
+ }
+
+ /**
+ * Calls {@link AbstractEvent#stopImmediatePropagation(boolean)}.
+ */
+ protected void stopImmediatePropagation(AbstractEvent evt, boolean b) {
+ evt.stopImmediatePropagation(b);
+ }
+
+ /**
+ * Calls {@link AbstractEvent#preventDefault(boolean)}.
+ */
+ protected void preventDefault(AbstractEvent evt, boolean b) {
+ evt.preventDefault(b);
+ }
+
+ /**
+ * Calls {@link AbstractEvent#setCurrentTarget}.
+ */
+ protected void setCurrentTarget(AbstractEvent evt, NodeEventTarget target) {
+ evt.setCurrentTarget(target);
+ }
+
+ /**
+ * Calls {@link AbstractEvent#setEventPhase}.
+ */
+ protected void setEventPhase(AbstractEvent evt, short phase) {
+ evt.setEventPhase(phase);
+ }
+
+ /**
+ * Returns the ultimate original event for the given event.
+ */
+ public static Event getUltimateOriginalEvent(Event evt) {
+ for (;;) {
+ if (evt instanceof AbstractEvent) {
+ AbstractEvent aevt = (AbstractEvent) evt;
+ Event origEvt = aevt.getOriginalEvent();
+ if (origEvt == null) {
+ break;
+ }
+ evt = origEvt;
+ } else if (evt instanceof CustomEvent) {
+ CustomEvent cevt = (CustomEvent) evt;
+ Event origEvt = cevt.getOriginalEvent();
+ if (origEvt == null) {
+ break;
+ }
+ evt = origEvt;
+ } else {
+ break;
+ }
+ }
+ return evt;
+ }
+
+ /**
* Wrapper class for {@link org.w3c.dom.events.CustomEvent} objects.
*/
protected class WrappedEvent implements CustomEvent {
@@ -485,17 +577,46 @@
protected Method isDefaultPreventedMethod;
/**
+ * The resumePropagation method of the wrapped event object.
+ */
+ protected Method resumePropagationMethod;
+
+ /**
+ * The retarget method of the wrapped event object.
+ */
+ protected Method retargetMethod;
+
+ /**
+ * The setTarget method of the wrapped event object.
+ */
+ protected Method setTargetMethod;
+
+ /**
+ * The getOriginalEvent method of the wrapped event object.
+ */
+ protected Method getOriginalEventMethod;
+
+ /**
* Creates a new WrappedEvent object.
*/
public WrappedEvent(org.w3c.dom.events.CustomEvent e) {
this.e = e;
Class cls = e.getClass();
try {
- getNamespaceURIMethod = cls.getMethod("getNamespaceURI", (Class[])null);
+ getNamespaceURIMethod
+ = cls.getMethod("getNamespaceURI", (Class[]) null);
stopImmediatePropagationMethod
- = cls.getMethod("stopImmediatePropagation", (Class[])null);
+ = cls.getMethod("stopImmediatePropagation", (Class[]) null);
isDefaultPreventedMethod
- = cls.getMethod("isDefaultPrevented", (Class[])null);
+ = cls.getMethod("isDefaultPrevented", (Class[]) null);
+ resumePropagationMethod
+ = cls.getMethod("resumePropagation", (Class[]) null);
+ setTargetMethod = cls.getMethod
+ ("setTarget", new Class[] { EventTarget.class });
+ retargetMethod = cls.getMethod
+ ("retarget", new Class[] { EventTarget.class });
+ getOriginalEventMethod
+ = cls.getMethod("getOriginalEvent", (Class[]) null);
} catch (NoSuchMethodException nsme) {
throw createEventException
(DOMException.NOT_SUPPORTED_ERR,
@@ -607,6 +728,69 @@
}
// CustomEvent ///////////////////////////////////////////////////////
+
+ /**
+ * Clears the 'propagationStopped' and 'immediatePropagationStopped'
+ * flags. This is needed for standard event dispatching and should
+ * only be called by the DOM Events implementation.
+ */
+ public void resumePropagation() {
+ try {
+ resumePropagationMethod.invoke(e, null);
+ } catch (InvocationTargetException ite) {
+ ite.printStackTrace();
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ }
+ }
+
+ /**
+ * Sets the target for this event. This is needed for initialization
+ * of the custom event object and should only be called by the DOM Events
+ * implementation.
+ */
+ public void setTarget(EventTarget target) {
+ try {
+ setTargetMethod.invoke(e, new Object[] { target });
+ } catch (InvocationTargetException ite) {
+ ite.printStackTrace();
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ }
+ }
+
+ /**
+ * Clones this event object and sets the 'originalEvent' field of the
+ * clone to be equal to the original event object. This is needed
+ * for sXBL event retargetting and should only be called by the
+ * DOM Events implementation.
+ */
+ public CustomEvent retarget(EventTarget target) {
+ try {
+ return new WrappedEvent
+ ((org.w3c.dom.events.CustomEvent)
+ retargetMethod.invoke(e, new Object[] { target }));
+ } catch (InvocationTargetException ite) {
+ ite.printStackTrace();
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the event from which this event was cloned.
+ */
+ public Event getOriginalEvent() {
+ try {
+ return (Event) getOriginalEventMethod.invoke(e, null);
+ } catch (InvocationTargetException ite) {
+ ite.printStackTrace();
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ }
+ return null;
+ }
/**
* Returns the namespace URI of this custom event.
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2001-2003 The Apache Software Foundation
+ Copyright 2001-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
package org.apache.batik.dom.svg;
import org.apache.batik.css.engine.CSSEngine;
+import org.apache.batik.css.engine.CSSNavigableNode;
import org.apache.batik.dom.AbstractAttr;
import org.apache.batik.dom.AbstractDocument;
import org.apache.batik.dom.events.NodeEventTarget;
@@ -36,8 +37,8 @@
* @version $Id$
*/
public abstract class AbstractElement
- extends org.apache.batik.dom.AbstractElement
- implements NodeEventTarget {
+ extends org.apache.batik.dom.AbstractElement
+ implements NodeEventTarget, CSSNavigableNode {
/**
* The live attribute values.
@@ -61,14 +62,49 @@
initializeAttributes();
}
- // NodeEventTarget ////////////////////////////////////////////////////
+ // CSSNavigableNode ///////////////////////////////////////////////////
/**
- * Implements {@link NodeEventTarget#getParentNodeEventTarget()}.
+ * Returns the CSS parent node of this node.
*/
- public NodeEventTarget getParentNodeEventTarget() {
- return (NodeEventTarget)
- CSSEngine.getLogicalParentNode(getParentNode());
+ public Node getCSSParentNode() {
+ return getXblParentNode();
+ }
+
+ /**
+ * Returns the CSS previous sibling node of this node.
+ */
+ public Node getCSSPreviousSibling() {
+ return getXblPreviousSibling();
+ }
+
+ /**
+ * Returns the CSS next sibling node of this node.
+ */
+ public Node getCSSNextSibling() {
+ return getXblNextSibling();
+ }
+
+ /**
+ * Returns the CSS first child node of this node.
+ */
+ public Node getCSSFirstChild() {
+ return getXblFirstChild();
+ }
+
+ /**
+ * Returns the CSS last child of this node.
+ */
+ public Node getCSSLastChild() {
+ return getXblLastChild();
+ }
+
+ /**
+ * Returns whether this node is the root of a (conceptual) hidden tree
+ * that selectors will not work across.
+ */
+ public boolean isHiddenFromSelectors() {
+ return false;
}
// Attributes /////////////////////////////////////////////////////////
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2003 The Apache Software Foundation
+ Copyright 2000-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -21,33 +21,34 @@
import java.io.ObjectInputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
import java.util.Locale;
import java.util.MissingResourceException;
-import org.apache.batik.css.engine.CSSEngine;
+import org.apache.batik.css.engine.CSSNavigableDocument;
+import org.apache.batik.css.engine.CSSNavigableDocumentListener;
import org.apache.batik.dom.AbstractStylableDocument;
import org.apache.batik.dom.GenericAttr;
import org.apache.batik.dom.GenericAttrNS;
import org.apache.batik.dom.GenericCDATASection;
import org.apache.batik.dom.GenericComment;
import org.apache.batik.dom.GenericDocumentFragment;
-import org.apache.batik.dom.GenericDocumentType;
import org.apache.batik.dom.GenericElement;
import org.apache.batik.dom.GenericEntityReference;
import org.apache.batik.dom.GenericProcessingInstruction;
import org.apache.batik.dom.GenericText;
import org.apache.batik.dom.StyleSheetFactory;
+import org.apache.batik.dom.events.EventSupport;
import org.apache.batik.dom.util.XMLSupport;
-import org.apache.batik.i18n.Localizable;
import org.apache.batik.i18n.LocalizableSupport;
import org.apache.batik.util.SVGConstants;
+import org.apache.batik.util.XMLConstants;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
@@ -55,6 +56,9 @@
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
+import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventListener;
+import org.w3c.dom.events.MutationEvent;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGLangSpace;
import org.w3c.dom.svg.SVGSVGElement;
@@ -68,7 +72,8 @@
public class SVGOMDocument
extends AbstractStylableDocument
implements SVGDocument,
- SVGConstants {
+ SVGConstants,
+ CSSNavigableDocument {
/**
* The error messages bundle class name.
@@ -103,6 +108,12 @@
protected boolean isSVG12;
/**
+ * Map of CSSNavigableDocumentListeners to an array of wrapper
+ * DOM listeners.
+ */
+ protected HashMap cssNavigableDocumentListeners = new HashMap();
+
+ /**
* Creates a new uninitialized document.
*/
protected SVGOMDocument() {
@@ -339,6 +350,213 @@
public boolean isId(Attr node) {
if (node.getNamespaceURI() != null) return false;
return SVG_ID_ATTRIBUTE.equals(node.getNodeName());
+ }
+
+ // CSSNavigableDocument ///////////////////////////////////////////
+
+ /**
+ * Adds an event listener for mutations on the
+ * CSSNavigableDocument tree.
+ */
+ public void addCSSNavigableDocumentListener
+ (CSSNavigableDocumentListener l) {
+ if (cssNavigableDocumentListeners.containsKey(l)) {
+ return;
+ }
+
+ DOMNodeInsertedListenerWrapper nodeInserted
+ = new DOMNodeInsertedListenerWrapper(l);
+ DOMNodeRemovedListenerWrapper nodeRemoved
+ = new DOMNodeRemovedListenerWrapper(l);
+ DOMSubtreeModifiedListenerWrapper subtreeModified
+ = new DOMSubtreeModifiedListenerWrapper(l);
+ DOMCharacterDataModifiedListenerWrapper cdataModified
+ = new DOMCharacterDataModifiedListenerWrapper(l);
+ DOMAttrModifiedListenerWrapper attrModified
+ = new DOMAttrModifiedListenerWrapper(l);
+
+ cssNavigableDocumentListeners.put
+ (l, new EventListener[] { nodeInserted,
+ nodeRemoved,
+ subtreeModified,
+ cdataModified,
+ attrModified });
+
+ addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeInserted", nodeInserted, false, null);
+ addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeRemoved", nodeRemoved, false, null);
+ addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMSubtreeModified", subtreeModified, false, null);
+ addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMCharacterDataModified", cdataModified, false,
+ null);
+ addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMAttrModified", attrModified, false, null);
+ }
+
+ /**
+ * Removes an event listener for mutations on the
+ * CSSNavigableDocument tree.
+ */
+ public void removeCSSNavigableDocumentListener
+ (CSSNavigableDocumentListener l) {
+ EventListener[] listeners
+ = (EventListener[]) cssNavigableDocumentListeners.get(l);
+ if (listeners == null) {
+ return;
+ }
+
+ removeEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeInserted", listeners[0], false);
+ removeEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeRemoved", listeners[1], false);
+ removeEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMSubtreeModified", listeners[2], false);
+ removeEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMCharacterDataModified", listeners[3], false);
+ removeEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMAttrModified", listeners[4], false);
+
+ cssNavigableDocumentListeners.remove(l);
+ }
+
+ /**
+ * DOM node inserted listener wrapper.
+ */
+ protected class DOMNodeInsertedListenerWrapper implements EventListener {
+
+ /**
+ * The CSSNavigableDocumentListener.
+ */
+ protected CSSNavigableDocumentListener listener;
+
+ /**
+ * Creates a new DOMNodeInsertedListenerWrapper.
+ */
+ public DOMNodeInsertedListenerWrapper(CSSNavigableDocumentListener l) {
+ listener = l;
+ }
+
+ /**
+ * Handles the event.
+ */
+ public void handleEvent(Event evt) {
+ evt = EventSupport.getUltimateOriginalEvent(evt);
+ listener.nodeInserted((Node) evt.getTarget());
+ }
+ }
+
+ /**
+ * DOM node removed listener wrapper.
+ */
+ protected class DOMNodeRemovedListenerWrapper implements EventListener {
+
+ /**
+ * The CSSNavigableDocumentListener.
+ */
+ protected CSSNavigableDocumentListener listener;
+
+ /**
+ * Creates a new DOMNodeRemovedListenerWrapper.
+ */
+ public DOMNodeRemovedListenerWrapper(CSSNavigableDocumentListener l) {
+ listener = l;
+ }
+
+ /**
+ * Handles the event.
+ */
+ public void handleEvent(Event evt) {
+ evt = EventSupport.getUltimateOriginalEvent(evt);
+ listener.nodeToBeRemoved((Node) evt.getTarget());
+ }
+ }
+
+ /**
+ * DOM subtree modified listener wrapper.
+ */
+ protected class DOMSubtreeModifiedListenerWrapper implements EventListener {
+
+ /**
+ * The CSSNavigableDocumentListener.
+ */
+ protected CSSNavigableDocumentListener listener;
+
+ /**
+ * Creates a new DOMSubtreeModifiedListenerWrapper.
+ */
+ public DOMSubtreeModifiedListenerWrapper
+ (CSSNavigableDocumentListener l) {
+ listener = l;
+ }
+
+ /**
+ * Handles the event.
+ */
+ public void handleEvent(Event evt) {
+ evt = EventSupport.getUltimateOriginalEvent(evt);
+ listener.subtreeModified((Node) evt.getTarget());
+ }
+ }
+
+ /**
+ * DOM character data modified listener wrapper.
+ */
+ protected class DOMCharacterDataModifiedListenerWrapper
+ implements EventListener {
+
+ /**
+ * The CSSNavigableDocumentListener.
+ */
+ protected CSSNavigableDocumentListener listener;
+
+ /**
+ * Creates a new DOMCharacterDataModifiedListenerWrapper.
+ */
+ public DOMCharacterDataModifiedListenerWrapper
+ (CSSNavigableDocumentListener l) {
+ listener = l;
+ }
+
+ /**
+ * Handles the event.
+ */
+ public void handleEvent(Event evt) {
+ evt = EventSupport.getUltimateOriginalEvent(evt);
+ listener.subtreeModified((Node) evt.getTarget());
+ }
+ }
+
+ /**
+ * DOM attribute modified listener wrapper.
+ */
+ protected class DOMAttrModifiedListenerWrapper implements EventListener {
+
+ /**
+ * The CSSNavigableDocumentListener.
+ */
+ protected CSSNavigableDocumentListener listener;
+
+ /**
+ * Creates a new DOMAttrModifiedListenerWrapper.
+ */
+ public DOMAttrModifiedListenerWrapper(CSSNavigableDocumentListener l) {
+ listener = l;
+ }
+
+ /**
+ * Handles the event.
+ */
+ public void handleEvent(Event evt) {
+ evt = EventSupport.getUltimateOriginalEvent(evt);
+ MutationEvent mevt = (MutationEvent) evt;
+ listener.attrModified((Element) evt.getTarget(),
+ (Attr) mevt.getRelatedNode(),
+ mevt.getAttrChange(),
+ mevt.getPrevValue(),
+ mevt.getNewValue());
+ }
}
// AbstractDocument ///////////////////////////////////////////////
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2003 The Apache Software Foundation
+ Copyright 2000-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
package org.apache.batik.dom.svg;
import org.apache.batik.css.engine.CSSEngine;
-import org.apache.batik.css.engine.CSSImportedElementRoot;
+import org.apache.batik.css.engine.CSSNavigableNode;
import org.apache.batik.dom.AbstractDocument;
import org.apache.batik.dom.util.DOMUtilities;
import org.apache.batik.util.ParsedURL;
@@ -196,8 +196,8 @@
base = getCascadedXMLBase((Element) n);
break;
}
- if (n instanceof CSSImportedElementRoot) {
- n = ((CSSImportedElementRoot) n).getCSSParentElement();
+ if (n instanceof CSSNavigableNode) {
+ n = ((CSSNavigableNode) n).getCSSParentNode();
} else {
n = n.getParentNode();
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMStyleElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMStyleElement.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMStyleElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMStyleElement.java Tue Sep 13 06:29:29 2005
@@ -25,6 +25,8 @@
import org.apache.batik.css.engine.StyleSheet;
import org.apache.batik.dom.AbstractDocument;
import org.apache.batik.dom.util.XMLSupport;
+import org.apache.batik.util.XMLConstants;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.events.Event;
@@ -125,9 +127,11 @@
}
String media = getAttributeNS(null, SVG_MEDIA_ATTRIBUTE);
styleSheet = e.parseStyleSheet(text, burl, media);
- addEventListener("DOMCharacterDataModified",
- domCharacterDataModifiedListener,
- false);
+ addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMCharacterDataModified",
+ domCharacterDataModifiedListener,
+ false,
+ null);
}
}
return styleSheet;
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseElement.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseElement.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2004 The Apache Software Foundation
+ Copyright 2000-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
*/
package org.apache.batik.dom.svg;
-import org.apache.batik.css.engine.CSSImportNode;
-import org.apache.batik.css.engine.CSSImportedElementRoot;
import org.apache.batik.dom.AbstractDocument;
import org.apache.batik.dom.util.XLinkSupport;
import org.apache.batik.dom.util.XMLSupport;
@@ -35,8 +33,7 @@
*/
public class SVGOMUseElement
extends SVGURIReferenceGraphicsElement
- implements SVGUseElement,
- CSSImportNode {
+ implements SVGUseElement {
/**
* The attribute initializer.
@@ -56,9 +53,9 @@
}
/**
- * Store the imported element.
+ * Store the shadow tree of the use element.
*/
- protected CSSImportedElementRoot cssImportedElementRoot;
+ protected SVGOMUseShadowRoot shadowTree;
/**
* Creates a new SVGOMUseElement object.
@@ -132,20 +129,41 @@
throw new RuntimeException(" !!! TODO: getAnimatedInstanceRoot()");
}
- // CSSImportNode //////////////////////////////////////////////////
+ // CSSNavigableNode ///////////////////////////////////////////////
/**
- * The CSSImportedElementRoot.
+ * Returns the CSS first child node of this node.
*/
- public CSSImportedElementRoot getCSSImportedElementRoot() {
- return cssImportedElementRoot;
+ public Node getCSSFirstChild() {
+ if (shadowTree != null) {
+ return shadowTree.getFirstChild();
+ }
+ return null;
}
/**
- * Sets the CSSImportedElementRoot.
+ * Returns the CSS last child of this stylable element.
*/
- public void setCSSImportedElementRoot(CSSImportedElementRoot r) {
- cssImportedElementRoot = r;
+ public Node getCSSLastChild() {
+ // use element shadow trees only ever have a single element
+ return getCSSFirstChild();
+ }
+
+ /**
+ * Returns whether this node is the root of a (conceptual) hidden tree
+ * that selectors will not work across. Returns true here, since CSS
+ * selectors cannot work in the conceptual cloned sub-tree of the
+ * content referenced by the 'use' element.
+ */
+ public boolean isHiddenFromSelectors() {
+ return true;
+ }
+
+ /**
+ * Sets the shadow tree for this 'use' element.
+ */
+ public void setUseShadowTree(SVGOMUseShadowRoot r) {
+ shadowTree = r;
}
/**
Added: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseShadowRoot.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseShadowRoot.java?rev=280553&view=auto
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseShadowRoot.java (added)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseShadowRoot.java Tue Sep 13 06:29:29 2005
@@ -0,0 +1,129 @@
+/*
+
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.dom.svg;
+
+import org.apache.batik.css.engine.CSSNavigableNode;
+import org.apache.batik.dom.AbstractDocument;
+import org.apache.batik.dom.AbstractDocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This class implements {@link org.w3c.dom.DocumentFragment} interface.
+ * It is used to implement the SVG use element behavioUr.
+ *
+ * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
+ * @version $Id$
+ */
+public class SVGOMUseShadowRoot
+ extends AbstractDocumentFragment
+ implements CSSNavigableNode {
+
+ /**
+ * The parent CSS element.
+ */
+ protected Element cssParentElement;
+
+ /**
+ * Indicates if the imported css element is from
+ * this document.
+ */
+ protected boolean isLocal;
+
+ /**
+ * Creates a new DocumentFragment object.
+ */
+ protected SVGOMUseShadowRoot() {
+ }
+
+ /**
+ * Creates a new DocumentFragment object.
+ */
+ public SVGOMUseShadowRoot(AbstractDocument owner,
+ Element parent,
+ boolean isLocal) {
+ ownerDocument = owner;
+ cssParentElement = parent;
+ this.isLocal = isLocal;
+ }
+
+ /**
+ * Tests whether this node is readonly.
+ */
+ public boolean isReadonly() {
+ return false;
+ }
+
+ /**
+ * Sets this node readonly attribute.
+ */
+ public void setReadonly(boolean v) {
+ }
+
+ // CSSNavigableNode //////////////////////////////////////////////////////
+
+ /**
+ * Returns the CSS parent node of this node.
+ */
+ public Node getCSSParentNode() {
+ return cssParentElement;
+ }
+
+ /**
+ * Returns the CSS previous sibling node of this node.
+ */
+ public Node getCSSPreviousSibling() {
+ return null;
+ }
+
+ /**
+ * Returns the CSS next sibling node of this node.
+ */
+ public Node getCSSNextSibling() {
+ return null;
+ }
+
+ /**
+ * Returns the CSS first child node of this node.
+ */
+ public Node getCSSFirstChild() {
+ return getFirstChild();
+ }
+
+ /**
+ * Returns the CSS last child of this node.
+ */
+ public Node getCSSLastChild() {
+ return getLastChild();
+ }
+
+ /**
+ * Returns whether this node is the root of a (conceptual) hidden tree
+ * that selectors will not work across.
+ */
+ public boolean isHiddenFromSelectors() {
+ return false;
+ }
+
+ /**
+ * Returns a new uninitialized instance of this object's class.
+ */
+ protected Node newNode() {
+ return new SVGOMUseShadowRoot();
+ }
+}
Propchange: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMUseShadowRoot.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGStylableElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGStylableElement.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGStylableElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGStylableElement.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2001-2004 The Apache Software Foundation
+ Copyright 2001-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -105,6 +105,9 @@
*/
public URL getCSSBase() {
try {
+ if (getXblBoundElement() != null) {
+ return null;
+ }
String bu = getBaseURI();
if (bu == null) {
return null;
Added: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/BindableElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/BindableElement.java?rev=280553&view=auto
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/BindableElement.java (added)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/BindableElement.java Tue Sep 13 06:29:29 2005
@@ -0,0 +1,133 @@
+/*
+
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.dom.svg12;
+
+import org.apache.batik.dom.AbstractDocument;
+import org.apache.batik.dom.svg.AttributeInitializer;
+import org.apache.batik.dom.svg.SVGStylableElement;
+
+import org.w3c.dom.Node;
+
+/**
+ * This class implements foreign namespace elements that can be
+ * bound with XBL.
+ *
+ * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
+ * @version $Id$
+ */
+public class BindableElement extends SVGStylableElement {
+
+ /**
+ * The namespace URI of the custom element.
+ */
+ protected String namespaceURI;
+
+ /**
+ * The local name of the custom element.
+ */
+ protected String localName;
+
+ /**
+ * The shadow tree.
+ */
+ protected XBLOMShadowTreeElement xblShadowTree;
+
+ /**
+ * Creates a new BindableElement object.
+ */
+ protected BindableElement() {
+ }
+
+ /**
+ * Creates a new BindableElement object.
+ * @param prefix The namespace prefix.
+ * @param owner The owner document.
+ * @param ns The namespace of the custom element.
+ * @param ln The local name of the custom element.
+ */
+ public BindableElement(String prefix,
+ AbstractDocument owner,
+ String ns,
+ String ln) {
+ super(prefix, owner);
+ namespaceURI = ns;
+ localName = ln;
+ }
+
+ /**
+ * <b>DOM</b>: Implements {@link Node#getNamespaceURI()}.
+ */
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ /**
+ * <b>DOM</b>: Implements {@link Node#getLocalName()}.
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
+ * Returns the AttributeInitializer for this element type.
+ * @return null if this element has no attribute with a default value.
+ */
+ protected AttributeInitializer getAttributeInitializer() {
+ return null;
+ }
+
+ /**
+ * Returns a new uninitialized instance of this object's class.
+ */
+ protected Node newNode() {
+ return new BindableElement(null, null, namespaceURI, localName);
+ }
+
+ /**
+ * Sets the shadow tree for this bindable element.
+ */
+ public void setShadowTree(XBLOMShadowTreeElement s) {
+ xblShadowTree = s;
+ }
+
+ /**
+ * Returns the shadow tree for this bindable element.
+ */
+ public XBLOMShadowTreeElement getShadowTree() {
+ return xblShadowTree;
+ }
+
+ // CSSNavigableNode ///////////////////////////////////////////////
+
+ /**
+ * Returns the shadow tree.
+ */
+ public Node getCSSFirstChild() {
+ if (xblShadowTree != null) {
+ return xblShadowTree.getFirstChild();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the shadow tree.
+ */
+ public Node getCSSLastChild() {
+ return getCSSFirstChild();
+ }
+}
Propchange: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/BindableElement.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12DOMImplementation.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12DOMImplementation.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12DOMImplementation.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12DOMImplementation.java Tue Sep 13 06:29:29 2005
@@ -1,6 +1,6 @@
/*
- Copyright 2000-2003 The Apache Software Foundation
+ Copyright 2000-2003,2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -26,16 +26,17 @@
import org.apache.batik.css.engine.value.ValueManager;
import org.apache.batik.css.parser.ExtendedParser;
import org.apache.batik.dom.AbstractDocument;
+import org.apache.batik.dom.AbstractNode;
import org.apache.batik.dom.AbstractStylableDocument;
import org.apache.batik.dom.GenericElement;
-import org.apache.batik.dom.GenericElementNS;
import org.apache.batik.dom.events.DocumentEventSupport;
+import org.apache.batik.dom.events.EventSupport;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.dom.util.HashTable;
import org.apache.batik.dom.util.DOMUtilities;
import org.apache.batik.util.SVG12Constants;
-
+import org.apache.batik.util.XBLConstants;
import org.w3c.css.sac.InputSource;
import org.w3c.dom.Document;
@@ -92,7 +93,7 @@
String qualifiedName,
DocumentType doctype)
throws DOMException {
- SVGOMDocument result = new SVGOMDocument(doctype, this);
+ SVGOMDocument result = new SVG12OMDocument(doctype, this);
result.setIsSVG12(true);
// BUG 32108: return empty document if qualifiedName is null.
if (qualifiedName != null)
@@ -111,16 +112,21 @@
if (namespaceURI == null)
return new GenericElement(qualifiedName.intern(), document);
+ String name = DOMUtilities.getLocalName(qualifiedName);
if (SVG12Constants.SVG_NAMESPACE_URI.equals(namespaceURI)) {
- String name = DOMUtilities.getLocalName(qualifiedName);
ElementFactory ef = (ElementFactory)factories.get(name);
if (ef != null)
return ef.create(DOMUtilities.getPrefix(qualifiedName),
document);
+ } else if (XBLConstants.XBL_NAMESPACE_URI.equals(namespaceURI)) {
+ ElementFactory ef = (ElementFactory)xblFactories.get(name);
+ if (ef != null)
+ return ef.create(DOMUtilities.getPrefix(qualifiedName),
+ document);
}
- return new GenericElementNS(namespaceURI.intern(),
- qualifiedName.intern(),
- document);
+
+ String prefix = DOMUtilities.getPrefix(qualifiedName);
+ return new BindableElement(prefix, document, namespaceURI, name);
}
/**
@@ -135,9 +141,22 @@
return new SVGOMWheelEvent();
}
});
+ result.registerEventFactory("ShadowTreeEvent",
+ new DocumentEventSupport.EventFactory() {
+ public Event createEvent() {
+ return new XBLOMShadowTreeEvent();
+ }
+ });
return result;
}
+ /**
+ * Creates an EventSupport object for the given node.
+ */
+ public EventSupport createEventSupport(AbstractNode n) {
+ return new XBLEventSupport(n);
+ }
+
// The element factories /////////////////////////////////////////////////
/**
@@ -377,6 +396,131 @@
*/
public Element create(String prefix, Document doc) {
return new SVGOMSubImageRefElement(prefix, (AbstractDocument)doc);
+ }
+ }
+
+ /**
+ * The XBL element factories.
+ */
+ protected static HashTable xblFactories = new HashTable();
+
+ static {
+ xblFactories.put(XBLConstants.XBL_XBL_TAG,
+ new XBLXBLElementFactory());
+
+ xblFactories.put(XBLConstants.XBL_DEFINITION_TAG,
+ new XBLDefinitionElementFactory());
+
+ xblFactories.put(XBLConstants.XBL_TEMPLATE_TAG,
+ new XBLTemplateElementFactory());
+
+ xblFactories.put(XBLConstants.XBL_CONTENT_TAG,
+ new XBLContentElementFactory());
+
+ xblFactories.put(XBLConstants.XBL_HANDLER_GROUP_TAG,
+ new XBLHandlerGroupElementFactory());
+
+ xblFactories.put(XBLConstants.XBL_IMPORT_TAG,
+ new XBLImportElementFactory());
+
+ xblFactories.put(XBLConstants.XBL_SHADOW_TREE_TAG,
+ new XBLShadowTreeElementFactory());
+ }
+
+ /**
+ * To create a 'xbl:xbl' element.
+ */
+ protected static class XBLXBLElementFactory implements ElementFactory {
+ public XBLXBLElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMXBLElement(prefix, (AbstractDocument)doc);
+ }
+ }
+
+ /**
+ * To create a 'xbl:definition' element.
+ */
+ protected static class XBLDefinitionElementFactory
+ implements ElementFactory {
+ public XBLDefinitionElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMDefinitionElement(prefix, (AbstractDocument)doc);
+ }
+ }
+
+ /**
+ * To create a 'xbl:template' element.
+ */
+ protected static class XBLTemplateElementFactory
+ implements ElementFactory {
+ public XBLTemplateElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMTemplateElement(prefix, (AbstractDocument) doc);
+ }
+ }
+
+ /**
+ * To create a 'xbl:content' element.
+ */
+ protected static class XBLContentElementFactory
+ implements ElementFactory {
+ public XBLContentElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMContentElement(prefix, (AbstractDocument)doc);
+ }
+ }
+
+ /**
+ * To create a 'xbl:handlerGroup' element.
+ */
+ protected static class XBLHandlerGroupElementFactory
+ implements ElementFactory {
+ public XBLHandlerGroupElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMHandlerGroupElement(prefix, (AbstractDocument)doc);
+ }
+ }
+
+ /**
+ * To create a 'xbl:import' element.
+ */
+ protected static class XBLImportElementFactory
+ implements ElementFactory {
+ public XBLImportElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMImportElement(prefix, (AbstractDocument)doc);
+ }
+ }
+
+ /**
+ * To create a 'xbl:shadowTree' element.
+ */
+ protected static class XBLShadowTreeElementFactory
+ implements ElementFactory {
+ public XBLShadowTreeElementFactory() {}
+ /**
+ * Creates an instance of the associated element type.
+ */
+ public Element create(String prefix, Document doc) {
+ return new XBLOMShadowTreeElement(prefix, (AbstractDocument)doc);
}
}
Added: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12OMDocument.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12OMDocument.java?rev=280553&view=auto
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12OMDocument.java (added)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12OMDocument.java Tue Sep 13 06:29:29 2005
@@ -0,0 +1,148 @@
+/*
+
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.dom.svg12;
+
+import org.apache.batik.css.engine.CSSNavigableDocumentListener;
+import org.apache.batik.dom.svg.SVGOMDocument;
+import org.apache.batik.util.XMLConstants;
+
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Node;
+import org.w3c.dom.events.EventListener;
+
+/**
+ * This class implements {@link SVGDocument} and provides support for
+ * SVG 1.2 specifics.
+ */
+public class SVG12OMDocument extends SVGOMDocument {
+
+ /**
+ * Creates a new uninitialized document.
+ */
+ protected SVG12OMDocument() {
+ }
+
+ /**
+ * Creates a new SVG12OMDocument.
+ */
+ public SVG12OMDocument(DocumentType dt, DOMImplementation impl) {
+ super(dt, impl);
+ }
+
+ // AbstractDocument ///////////////////////////////////////////////
+
+ /**
+ * Returns a new uninitialized instance of this object's class.
+ */
+ protected Node newNode() {
+ return new SVG12OMDocument();
+ }
+
+ // CSSNavigableDocument ///////////////////////////////////////////
+
+ /**
+ * Adds an event listener for mutations on the
+ * CSSNavigableDocument tree.
+ */
+ public void addCSSNavigableDocumentListener
+ (CSSNavigableDocumentListener l) {
+ if (cssNavigableDocumentListeners.containsKey(l)) {
+ return;
+ }
+
+ DOMNodeInsertedListenerWrapper nodeInserted
+ = new DOMNodeInsertedListenerWrapper(l);
+ DOMNodeRemovedListenerWrapper nodeRemoved
+ = new DOMNodeRemovedListenerWrapper(l);
+ DOMSubtreeModifiedListenerWrapper subtreeModified
+ = new DOMSubtreeModifiedListenerWrapper(l);
+ DOMCharacterDataModifiedListenerWrapper cdataModified
+ = new DOMCharacterDataModifiedListenerWrapper(l);
+ DOMAttrModifiedListenerWrapper attrModified
+ = new DOMAttrModifiedListenerWrapper(l);
+
+ cssNavigableDocumentListeners.put
+ (l, new EventListener[] { nodeInserted,
+ nodeRemoved,
+ subtreeModified,
+ cdataModified,
+ attrModified });
+
+ XBLEventSupport es = (XBLEventSupport) initializeEventSupport();
+
+ es.addImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeInserted",
+ nodeInserted, false);
+ es.addImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeRemoved",
+ nodeRemoved, false);
+ es.addImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMSubtreeModified",
+ subtreeModified, false);
+ es.addImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMCharacterDataModified",
+ cdataModified, false);
+ es.addImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMAttrModified",
+ attrModified, false);
+ }
+
+ /**
+ * Removes an event listener for mutations on the
+ * CSSNavigableDocument tree.
+ */
+ public void removeCSSNavigableDocumentListener
+ (CSSNavigableDocumentListener l) {
+ EventListener[] listeners
+ = (EventListener[]) cssNavigableDocumentListeners.get(l);
+ if (listeners == null) {
+ return;
+ }
+
+ XBLEventSupport es = (XBLEventSupport) initializeEventSupport();
+
+ es.removeImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeInserted",
+ listeners[0], false);
+ es.removeImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMNodeRemoved",
+ listeners[1], false);
+ es.removeImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMSubtreeModified",
+ listeners[2], false);
+ es.removeImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMCharacterDataModified",
+ listeners[3], false);
+ es.removeImplementationEventListenerNS
+ (XMLConstants.XML_EVENTS_NAMESPACE_URI,
+ "DOMAttrModified",
+ listeners[4], false);
+
+ cssNavigableDocumentListeners.remove(l);
+ }
+}
Propchange: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVG12OMDocument.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVGOMWheelEvent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVGOMWheelEvent.java?rev=280553&r1=280552&r2=280553&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVGOMWheelEvent.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg12/SVGOMWheelEvent.java Tue Sep 13 06:29:29 2005
@@ -19,7 +19,6 @@
import org.apache.batik.dom.events.DOMUIEvent;
-import org.w3c.dom.events.UIEvent;
import org.w3c.dom.views.AbstractView;
/**