diff options
author | Michael Stahl <mst@openoffice.org> | 2011-01-19 20:27:23 +0100 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2011-01-19 20:27:23 +0100 |
commit | 8ab417f83b7a6ee8a11deb5f534d6fc6c6fd9899 (patch) | |
tree | 7a6695580f4dfa2c04b64f7cb7e5a04ee5e0a553 /unoxml/source | |
parent | xmlfix3: #i113682#: unoxml: no mutex necessary for CDocument::importNode (diff) | |
download | core-8ab417f83b7a6ee8a11deb5f534d6fc6c6fd9899.tar.gz core-8ab417f83b7a6ee8a11deb5f534d6fc6c6fd9899.zip |
xmlfix3: #i113682#: unoxml: no more globals in CEventDispatcher:
instead CDocument now has a CEventDispatcher member.
Diffstat (limited to 'unoxml/source')
-rw-r--r-- | unoxml/source/dom/document.cxx | 8 | ||||
-rw-r--r-- | unoxml/source/dom/document.hxx | 10 | ||||
-rw-r--r-- | unoxml/source/dom/node.cxx | 34 | ||||
-rw-r--r-- | unoxml/source/dom/node.hxx | 5 | ||||
-rw-r--r-- | unoxml/source/events/eventdispatcher.cxx | 46 | ||||
-rw-r--r-- | unoxml/source/events/eventdispatcher.hxx | 22 |
6 files changed, 81 insertions, 44 deletions
diff --git a/unoxml/source/dom/document.cxx b/unoxml/source/dom/document.cxx index eeab43bb4963..404dd9add82d 100644 --- a/unoxml/source/dom/document.cxx +++ b/unoxml/source/dom/document.cxx @@ -45,6 +45,7 @@ #include "../events/mutationevent.hxx" #include "../events/uievent.hxx" #include "../events/mouseevent.hxx" +#include "../events/eventdispatcher.hxx" #include <string.h> @@ -63,9 +64,16 @@ namespace DOM NodeType_DOCUMENT_NODE, reinterpret_cast<xmlNodePtr>(aDocPtr)) , m_aDocPtr(aDocPtr) , m_streamListeners() + , m_pEventDispatcher(new events::CEventDispatcher()) { } + events::CEventDispatcher & CDocument::GetEventDispatcher() + { + return *m_pEventDispatcher; + } + + void SAL_CALL CDocument::saxify( const Reference< XDocumentHandler >& i_xHandler) { i_xHandler->startDocument(); diff --git a/unoxml/source/dom/document.hxx b/unoxml/source/dom/document.hxx index 92793cecc308..2477efa7f26b 100644 --- a/unoxml/source/dom/document.hxx +++ b/unoxml/source/dom/document.hxx @@ -30,6 +30,8 @@ #include <list> #include <set> +#include <memory> + #include <sal/types.h> #include <cppuhelper/implbase6.hxx> #include <com/sun/star/uno/Reference.h> @@ -66,6 +68,10 @@ using namespace com::sun::star::xml::dom::events; namespace DOM { + namespace events { + class CEventDispatcher; + } + typedef ::cppu::ImplInheritanceHelper6< CNode, XDocument, XDocumentEvent, XActiveDataControl, XActiveDataSource, @@ -85,9 +91,13 @@ namespace DOM listenerlist_t m_streamListeners; Reference< XOutputStream > m_rOutputStream; + ::std::auto_ptr<events::CEventDispatcher> const m_pEventDispatcher; + protected: CDocument(xmlDocPtr aDocPtr); + events::CEventDispatcher & GetEventDispatcher(); + public: virtual ~CDocument(); diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx index 776158bab190..3554811d8b45 100644 --- a/unoxml/source/dom/node.cxx +++ b/unoxml/source/dom/node.cxx @@ -285,7 +285,7 @@ namespace DOM // keep containing document alive // (but not if this is a document; that would create a leak!) , m_xDocument( (m_aNodePtr->type != XML_DOCUMENT_NODE) - ? getOwnerDocument() : 0 ) + ? GetOwnerDocument_Impl() : 0 ) { OSL_ASSERT(m_aNodePtr); } @@ -308,6 +308,18 @@ namespace DOM invalidate(); } + ::rtl::Reference< CDocument > CNode::GetOwnerDocument_Impl() + { + if (0 == m_aNodePtr) { + return 0; + } + ::rtl::Reference< CDocument > const xDoc( + dynamic_cast<CDocument *>(CNode::getCNode( + reinterpret_cast<xmlNodePtr>(m_aNodePtr->doc)).get())); + return xDoc; + } + + static void _nsexchange(const xmlNodePtr aNode, xmlNsPtr oldNs, xmlNsPtr newNs) { // recursively exchange any references to oldNs with references to newNs @@ -687,13 +699,7 @@ namespace DOM Reference< XDocument > SAL_CALL CNode::getOwnerDocument() throw (RuntimeException) { - if (0 == m_aNodePtr) { - return 0; - } - Reference< XDocument > const xDoc( - static_cast<XNode*>(CNode::getCNode( - reinterpret_cast<xmlNodePtr>(m_aNodePtr->doc)).get()), - UNO_QUERY_THROW); + Reference< XDocument > const xDoc(GetOwnerDocument_Impl().get()); return xDoc; } @@ -1016,7 +1022,9 @@ namespace DOM sal_Bool useCapture) throw (RuntimeException) { - events::CEventDispatcher::addListener(m_aNodePtr, eventType, listener, useCapture); + events::CEventDispatcher & rDispatcher( + m_xDocument->GetEventDispatcher()); + rDispatcher.addListener(m_aNodePtr, eventType, listener, useCapture); } void SAL_CALL CNode::removeEventListener(const OUString& eventType, @@ -1024,13 +1032,17 @@ namespace DOM sal_Bool useCapture) throw (RuntimeException) { - events::CEventDispatcher::removeListener(m_aNodePtr, eventType, listener, useCapture); + events::CEventDispatcher & rDispatcher( + m_xDocument->GetEventDispatcher()); + rDispatcher.removeListener(m_aNodePtr, eventType, listener, useCapture); } sal_Bool SAL_CALL CNode::dispatchEvent(const Reference< XEvent >& evt) throw(RuntimeException, EventException) { - events::CEventDispatcher::dispatchEvent(m_aNodePtr, evt); + events::CEventDispatcher & rDispatcher( + m_xDocument->GetEventDispatcher()); + rDispatcher.dispatchEvent(this, evt); return sal_True; } diff --git a/unoxml/source/dom/node.hxx b/unoxml/source/dom/node.hxx index 1d1ebdca0586..6fc6c5059d6b 100644 --- a/unoxml/source/dom/node.hxx +++ b/unoxml/source/dom/node.hxx @@ -113,6 +113,7 @@ namespace DOM /// add namespaces on this node to context void addNamespaces(Context& io_rContext, xmlNodePtr pNode); + class CDocument; class CNode : public cppu::WeakImplHelper3< XNode, XUnoTunnel, XEventTarget > { @@ -131,7 +132,7 @@ namespace DOM /// libxml node; NB: not const, because invalidate may reset it to 0! xmlNodePtr m_aNodePtr; - Reference< XDocument > const m_xDocument; + ::rtl::Reference< CDocument > const m_xDocument; // for initialization by classes derived through ImplInheritanceHelper CNode(NodeType const& reNodeType, xmlNodePtr const& rpNode); @@ -139,6 +140,8 @@ namespace DOM void dispatchSubtreeModified(); + ::rtl::Reference< CDocument > GetOwnerDocument_Impl(); + public: virtual ~CNode(); diff --git a/unoxml/source/events/eventdispatcher.cxx b/unoxml/source/events/eventdispatcher.cxx index 198e357914ad..c6e5bc4aebf2 100644 --- a/unoxml/source/events/eventdispatcher.cxx +++ b/unoxml/source/events/eventdispatcher.cxx @@ -34,13 +34,10 @@ namespace DOM { namespace events { - TypeListenerMap CEventDispatcher::captureListeners; - TypeListenerMap CEventDispatcher::targetListeners; - void CEventDispatcher::addListener(xmlNodePtr pNode, OUString aType, const Reference<XEventListener>& aListener, sal_Bool bCapture) { - TypeListenerMap* pTMap = &targetListeners; - if (bCapture) pTMap = &captureListeners; + TypeListenerMap *const pTMap = (bCapture) + ? (& m_CaptureListeners) : (& m_TargetListeners); // get the multimap for the specified type ListenerMap *pMap = 0; @@ -58,8 +55,8 @@ namespace DOM { namespace events { void CEventDispatcher::removeListener(xmlNodePtr pNode, OUString aType, const Reference<XEventListener>& aListener, sal_Bool bCapture) { - TypeListenerMap *pTMap = &targetListeners; - if (bCapture) pTMap = &captureListeners; + TypeListenerMap *const pTMap = (bCapture) + ? (& m_CaptureListeners) : (& m_TargetListeners); // get the multimap for the specified type TypeListenerMap::const_iterator tIter = pTMap->find(aType); @@ -82,10 +79,12 @@ namespace DOM { namespace events { } } - void CEventDispatcher::callListeners(xmlNodePtr pNode, OUString aType, const Reference< XEvent >& xEvent, sal_Bool bCapture) + void CEventDispatcher::callListeners(xmlNodePtr const pNode, + OUString aType, Reference< XEvent > const& xEvent, + sal_Bool const bCapture) const { - TypeListenerMap *pTMap = &targetListeners; - if (bCapture) pTMap = &captureListeners; + TypeListenerMap const*const pTMap = (bCapture) + ? (& m_CaptureListeners) : (& m_TargetListeners); // get the multimap for the specified type TypeListenerMap::const_iterator tIter = pTMap->find(aType); @@ -101,12 +100,12 @@ namespace DOM { namespace events { } } - sal_Bool CEventDispatcher::dispatchEvent(xmlNodePtr aNodePtr, const Reference< XEvent >& aEvent) + bool CEventDispatcher::dispatchEvent(Reference<XNode> const& xNode, + Reference< XEvent > const& i_xEvent) const { CEvent *pEvent = 0; // pointer to internal event representation - Reference< XEvent > xEvent; // reference to the event being dispatched; - OUString aType = aEvent->getType(); + OUString const aType = i_xEvent->getType(); if (aType.compareToAscii("DOMSubtreeModified") == 0|| aType.compareToAscii("DOMNodeInserted") == 0|| aType.compareToAscii("DOMNodeRemoved") == 0|| @@ -115,7 +114,8 @@ namespace DOM { namespace events { aType.compareToAscii("DOMAttrModified") == 0|| aType.compareToAscii("DOMCharacterDataModified") == 0) { - Reference< XMutationEvent > aMEvent(aEvent, UNO_QUERY); + Reference< XMutationEvent > const aMEvent(i_xEvent, + UNO_QUERY_THROW); // dispatch a mutation event // we need to clone the event in order to have complete control // over the implementation @@ -131,7 +131,7 @@ namespace DOM { namespace events { aType.compareToAscii("DOMFocusOut") == 0|| aType.compareToAscii("DOMActivate") == 0) { - Reference< XUIEvent > aUIEvent(aEvent, UNO_QUERY); + Reference< XUIEvent > const aUIEvent(i_xEvent, UNO_QUERY_THROW); CUIEvent* pUIEvent = new CUIEvent; pUIEvent->initUIEvent(aType, aUIEvent->getBubbles(), aUIEvent->getCancelable(), @@ -145,7 +145,8 @@ namespace DOM { namespace events { aType.compareToAscii("mousemove") == 0|| aType.compareToAscii("mouseout") == 0) { - Reference< XMouseEvent > aMouseEvent(aEvent, UNO_QUERY); + Reference< XMouseEvent > const aMouseEvent(i_xEvent, + UNO_QUERY_THROW); CMouseEvent *pMouseEvent = new CMouseEvent; pMouseEvent->initMouseEvent(aType, aMouseEvent->getBubbles(), aMouseEvent->getCancelable(), @@ -161,16 +162,15 @@ namespace DOM { namespace events { { pEvent = new CEvent; pEvent->initEvent( - aType, aEvent->getBubbles(), aEvent->getCancelable()); + aType, i_xEvent->getBubbles(), i_xEvent->getCancelable()); } - pEvent->m_target = - Reference< XEventTarget >(DOM::CNode::getCNode(aNodePtr).get()); - pEvent->m_currentTarget = aEvent->getCurrentTarget(); - pEvent->m_time = aEvent->getTimeStamp(); + pEvent->m_target.set(xNode, UNO_QUERY_THROW); + pEvent->m_currentTarget = i_xEvent->getCurrentTarget(); + pEvent->m_time = i_xEvent->getTimeStamp(); // create the reference to the provate event implementation // that will be dispatched to the listeners - xEvent = Reference< XEvent >(pEvent); + Reference< XEvent > const xEvent(pEvent); // build the path from target node to the root NodeVector captureVector; @@ -211,7 +211,7 @@ namespace DOM { namespace events { if (pEvent->m_canceled) return sal_True; // bubbeling phase inode++; - if (aEvent->getBubbles()) { + if (i_xEvent->getBubbles()) { pEvent->m_phase = PhaseType_BUBBLING_PHASE; while (inode != captureVector.end()) { diff --git a/unoxml/source/events/eventdispatcher.hxx b/unoxml/source/events/eventdispatcher.hxx index cd3f9e033c57..5160256ac493 100644 --- a/unoxml/source/events/eventdispatcher.hxx +++ b/unoxml/source/events/eventdispatcher.hxx @@ -36,6 +36,7 @@ #include <rtl/ustring.hxx> #include <com/sun/star/uno/Reference.h> +#include <com/sun/star/xml/dom/XNode.hpp> #include <com/sun/star/xml/dom/events/EventType.hpp> #include <com/sun/star/xml/dom/events/PhaseType.hpp> #include <com/sun/star/xml/dom/events/XEvent.hpp> @@ -56,30 +57,33 @@ typedef std::vector<ListenerMap::value_type> ListenerPairVector; class CEventDispatcher { private: - static TypeListenerMap captureListeners; - static TypeListenerMap targetListeners; + TypeListenerMap m_CaptureListeners; + TypeListenerMap m_TargetListeners; public: - static sal_Bool dispatchEvent(xmlNodePtr aNode, const Reference< XEvent >& aEvent); - - static void addListener( + void addListener( xmlNodePtr pNode, ::rtl::OUString aType, const Reference<com::sun::star::xml::dom::events::XEventListener>& aListener, sal_Bool bCapture); - static void removeListener( + void removeListener( xmlNodePtr pNode, ::rtl::OUString aType, const Reference<com::sun::star::xml::dom::events::XEventListener>& aListener, sal_Bool bCapture); - static void callListeners( - xmlNodePtr pNode, + void callListeners( + xmlNodePtr const pNode, ::rtl::OUString aType, const Reference< XEvent >& xEvent, - sal_Bool bCapture); + sal_Bool const bCapture) const; + + bool dispatchEvent( + Reference<XNode> const& xNode, + Reference< XEvent > const& xEvent) const; }; + }} #endif |