+2005-05-10 Darin Adler <darin@apple.com>
+
+ Reviewed by David Harrison.
+
+ - next pass of moving code from C++ DOM wrappers into the DOM impl. classes
+ (this step adds more member functions missing from the DOM impl. and
+ changes some of the Objective-C DOM to call the new ones; also changes some
+ parameter types in the DOM impl.)
+
+ * khtml/dom/dom2_events.cpp:
+ (UIEvent::initUIEvent):
+ (MouseEvent::initMouseEvent):
+ (MutationEvent::initMutationEvent):
+ (KeyboardEvent::initKeyboardEvent):
+ * khtml/dom/dom_doc.cpp:
+ (DOM::DOMImplementation::createDocument):
+ (DOM::Document::getElementsByTagName):
+ (DOM::Document::getElementsByTagNameNS):
+ * khtml/dom/dom_element.cpp:
+ (Element::removeAttributeNode):
+ (Element::getElementsByTagName):
+ (Element::getElementsByTagNameNS):
+ (Element::setAttributeNodeNS):
+ * khtml/dom/dom_node.cpp:
+ (NamedNodeMap::setNamedItemNS):
+ (NamedNodeMap::removeNamedItemNS):
+ * khtml/ecma/kjs_binding.cpp:
+ * khtml/ecma/kjs_events.cpp:
+ (ClipboardProtoFunc::tryCall):
+ * khtml/editing/jsediting.cpp:
+ * khtml/khtml_part.cpp:
+ (KHTMLPart::applyEditingStyleToBodyElement):
+ (KHTMLPart::removeEditingStyleFromBodyElement):
+ * khtml/khtmlview.cpp:
+ (KHTMLView::viewportMousePressEvent):
+ (KHTMLView::viewportMouseDoubleClickEvent):
+ (KHTMLView::viewportMouseMoveEvent):
+ (KHTMLView::viewportMouseReleaseEvent):
+ (KHTMLView::updateDragAndDrop):
+ (KHTMLView::dispatchMouseEvent):
+ * khtml/misc/shared.h:
+ (khtml::SharedPtr::reset):
+ (khtml::::operator):
+ (khtml::static_pointer_cast):
+ (khtml::const_pointer_cast):
+ * khtml/xml/dom2_eventsimpl.cpp:
+ (UIEventImpl::initUIEvent):
+ (UIEventImpl::keyCode):
+ (UIEventImpl::charCode):
+ (UIEventImpl::layerX):
+ (UIEventImpl::layerY):
+ (UIEventImpl::pageX):
+ (UIEventImpl::pageY):
+ (UIEventImpl::which):
+ (MouseRelatedEventImpl::pageX):
+ (MouseRelatedEventImpl::pageY):
+ (MouseEventImpl::initMouseEvent):
+ (MouseEventImpl::which):
+ (KeyboardEventImpl::initKeyboardEvent):
+ (KeyboardEventImpl::which):
+ (MutationEventImpl::MutationEventImpl):
+ (MutationEventImpl::initMutationEvent):
+ * khtml/xml/dom2_eventsimpl.h:
+ (DOM::MutationEventImpl::relatedNode):
+ * khtml/xml/dom2_rangeimpl.h:
+ * khtml/xml/dom2_traversalimpl.cpp:
+ (DOM::NodeFilterImpl::acceptNode):
+ * khtml/xml/dom2_traversalimpl.h:
+ * khtml/xml/dom_docimpl.cpp:
+ (DOMImplementationImpl::createDocument):
+ (DOMImplementationImpl::createCSSStyleSheet):
+ (DOMImplementationImpl::createHTMLDocument):
+ (DocumentImpl::createAttribute):
+ (DocumentImpl::createHTMLElement):
+ (DocumentImpl::getOverrideStyle):
+ (DocumentImpl::defaultEventHandler):
+ (DocumentImpl::completeURL):
+ (DocumentImpl::topDocument):
+ (DocumentImpl::createAttributeNS):
+ (DocumentImpl::images):
+ (DocumentImpl::applets):
+ (DocumentImpl::embeds):
+ (DocumentImpl::objects):
+ (DocumentImpl::links):
+ (DocumentImpl::forms):
+ (DocumentImpl::anchors):
+ (DocumentImpl::all):
+ (DocumentImpl::nameableItems):
+ (DocumentImpl::getElementsByName):
+ * khtml/xml/dom_docimpl.h:
+ (DOM::DocumentImpl::realDocType):
+ (DOM::DocumentImpl::createAttribute):
+ * khtml/xml/dom_elementimpl.cpp:
+ (AttrImpl::nodeName):
+ (AttrImpl::nodeValue):
+ (AttrImpl::name):
+ (AttrImpl::value):
+ (ElementImpl::attributes):
+ (ElementImpl::isURLAttribute):
+ (ElementImpl::setAttributeNode):
+ (ElementImpl::removeAttributeNode):
+ (ElementImpl::setAttributeNS):
+ (ElementImpl::removeAttributeNS):
+ (ElementImpl::getAttributeNodeNS):
+ (ElementImpl::hasAttributeNS):
+ (ElementImpl::style):
+ (XMLElementImpl::cloneNode):
+ (NamedAttrMapImpl::setNamedItem):
+ (NamedAttrMapImpl::removeNamedItem):
+ * khtml/xml/dom_elementimpl.h:
+ (DOM::ElementImpl::hasAttribute):
+ (DOM::ElementImpl::getAttribute):
+ (DOM::ElementImpl::setAttribute):
+ (DOM::ElementImpl::removeAttribute):
+ (DOM::ElementImpl::getAttributeNode):
+ (DOM::ElementImpl::setAttributeNodeNS):
+ * khtml/xml/dom_nodeimpl.cpp:
+ (NodeImpl::handleLocalEvents):
+ (NodeImpl::isAncestor):
+ (NodeImpl::addEventListener):
+ (NodeImpl::removeEventListener):
+ (NodeImpl::getElementsByTagNameNS):
+ (NodeImpl::isSupported):
+ (NodeImpl::ownerDocument):
+ (NodeImpl::hasAttributes):
+ (NodeImpl::attributes):
+ (ContainerNodeImpl::removeChildren):
+ (NamedNodeMapImpl::~NamedNodeMapImpl):
+ (NamedNodeMapImpl::getNamedItemNS):
+ (NamedNodeMapImpl::removeNamedItemNS):
+ * khtml/xml/dom_nodeimpl.h:
+ (DOM::NodeImpl::getElementsByTagName):
+ (DOM::NamedNodeMapImpl::NamedNodeMapImpl):
+ (DOM::NamedNodeMapImpl::getNamedItem):
+ (DOM::NamedNodeMapImpl::removeNamedItem):
+ (DOM::NamedNodeMapImpl::setNamedItemNS):
+ (DOM::NamedNodeMapImpl::isReadOnly):
+ * khtml/xml/dom_textimpl.h:
+ * khtml/xml/dom_xmlimpl.h:
+ * kwq/DOM.mm:
+ (-[DOMNode isSupported::]):
+ (-[DOMNode namespaceURI]):
+ (-[DOMNode hasAttributes]):
+ (-[DOMNamedNodeMap getNamedItem:]):
+ (-[DOMNamedNodeMap setNamedItem:]):
+ (-[DOMNamedNodeMap removeNamedItem:]):
+ (-[DOMNamedNodeMap getNamedItemNS::]):
+ (-[DOMNamedNodeMap setNamedItemNS:]):
+ (-[DOMNamedNodeMap removeNamedItemNS::]):
+ (-[DOMImplementation createDocument:::]):
+ (-[DOMImplementation createCSSStyleSheet::]):
+ (-[DOMDocument createAttribute:]):
+ (-[DOMDocument getElementsByTagName:]):
+ (-[DOMDocument createAttributeNS::]):
+ (-[DOMDocument getElementsByTagNameNS::]):
+ (-[DOMElement setAttribute::]):
+ (-[DOMElement removeAttribute:]):
+ (-[DOMElement getAttributeNode:]):
+ (-[DOMElement setAttributeNode:]):
+ (-[DOMElement removeAttributeNode:]):
+ (-[DOMElement getElementsByTagName:]):
+ (-[DOMElement getAttributeNS::]):
+ (-[DOMElement setAttributeNS:::]):
+ (-[DOMElement removeAttributeNS::]):
+ (-[DOMElement getAttributeNodeNS::]):
+ (-[DOMElement setAttributeNodeNS:]):
+ (-[DOMElement getElementsByTagNameNS::]):
+ (-[DOMElement hasAttribute:]):
+ (-[DOMElement hasAttributeNS::]):
+ (-[DOMElement style]):
+ (-[DOMDocumentType _documentTypeImpl]):
+ (ObjCNodeFilterCondition::acceptNode):
+ * kwq/DOMEvents.mm:
+ (-[DOMMutationEvent relatedNode]):
+ * kwq/KWQClipboard.h:
+ * kwq/KWQClipboard.mm:
+ (KWQClipboard::KWQClipboard):
+ (KWQClipboard::setDragImage):
+ (KWQClipboard::dragImageElement):
+ (KWQClipboard::setDragImageElement):
+ (KWQClipboard::dragNSImage):
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::khtmlMouseMoveEvent):
+ (KWQKHTMLPart::passSubframeEventToSubframe):
+ (KWQKHTMLPart::sendContextMenuEvent):
+
2005-05-10 Darin Adler <darin@apple.com>
Reviewed by David Harrison.
*
*/
+#include "dom/dom2_events.h"
+
#include "dom/dom2_views.h"
#include "dom/dom_exception.h"
#include "xml/dom2_eventsimpl.h"
throw DOMException(DOMException::INVALID_STATE_ERR);
static_cast<UIEventImpl*>(impl)->initUIEvent(typeArg,canBubbleArg,cancelableArg,
- viewArg,detailArg);
+ viewArg.handle(),detailArg);
}
// -----------------------------------------------------------------------------
throw DOMException(DOMException::INVALID_STATE_ERR);
static_cast<MouseEventImpl*>(impl)->initMouseEvent(typeArg,canBubbleArg,
- cancelableArg,viewArg,detailArg,screenXArg,screenYArg,clientXArg,
+ cancelableArg,viewArg.handle(),detailArg,screenXArg,screenYArg,clientXArg,
clientYArg,ctrlKeyArg,altKeyArg,shiftKeyArg,metaKeyArg,buttonArg,
- relatedTargetArg);
+ relatedTargetArg.handle());
}
throw DOMException(DOMException::INVALID_STATE_ERR);
static_cast<MutationEventImpl*>(impl)->initMutationEvent(typeArg,
- canBubbleArg,cancelableArg,relatedNodeArg,prevValueArg,
+ canBubbleArg,cancelableArg,relatedNodeArg.handle(),prevValueArg,
newValueArg,attrNameArg,attrChangeArg);
}
throw DOMException(DOMException::INVALID_STATE_ERR);
static_cast<KeyboardEventImpl*>(impl)->initKeyboardEvent(typeArg,canBubbleArg,
- cancelableArg,viewArg,keyIdentifierArg,keyLocationArg,ctrlKeyArg,altKeyArg,
+ cancelableArg,viewArg.handle(),keyIdentifierArg,keyLocationArg,ctrlKeyArg,altKeyArg,
shiftKeyArg,metaKeyArg,altGraphKeyArg);
}
throw DOMException(DOMException::NOT_FOUND_ERR);
int exceptioncode = 0;
- DocumentImpl *r = impl->createDocument(namespaceURI, qualifiedName, doctype, exceptioncode );
+ DocumentImpl *r = impl->createDocument(namespaceURI, qualifiedName,
+ static_cast<DocumentTypeImpl *>(doctype.handle()), exceptioncode );
if ( exceptioncode )
throw DOMException( exceptioncode );
return r;
NodeList Document::getElementsByTagName( const DOMString &tagName )
{
if (!impl) return 0;
- return static_cast<DocumentImpl*>(impl)->
- getElementsByTagNameNS(0, tagName.implementation());
+ return static_cast<DocumentImpl*>(impl)->getElementsByTagName(tagName).get();
}
NodeList Document::getElementsByTagNameNS( const DOMString &namespaceURI, const DOMString &localName )
{
if (!impl) return 0;
- return static_cast<DocumentImpl*>(impl)->
- getElementsByTagNameNS(namespaceURI.implementation(), localName.implementation());
+ return static_cast<DocumentImpl*>(impl)->getElementsByTagNameNS(namespaceURI, localName).get();
}
Node Document::importNode( const Node & importedNode, bool deep )
Attr Element::removeAttributeNode( const Attr &oldAttr )
{
- if (!impl || oldAttr.isNull() || oldAttr.ownerElement() != *this)
+ if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
- if (impl->getDocument() != oldAttr.handle()->getDocument())
- throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
-
- NodeImpl::Id attrName = static_cast<AttrImpl*>(oldAttr.handle())->attrImpl()->id();
-
int exceptioncode = 0;
- Attr r = static_cast<ElementImpl*>(impl)->attributes(true)->removeNamedItem(attrName, exceptioncode);
+ Attr r = static_cast<ElementImpl*>(impl)->removeAttributeNode(static_cast<AttrImpl *>(oldAttr.handle()), exceptioncode).get();
if ( exceptioncode )
throw DOMException( exceptioncode );
return r;
NodeList Element::getElementsByTagName( const DOMString &name )
{
if (!impl) return 0;
- return static_cast<ElementImpl*>(impl)->
- getElementsByTagNameNS(0, name.implementation());
+ return static_cast<ElementImpl*>(impl)->getElementsByTagName(name).get();
}
NodeList Element::getElementsByTagNameNS( const DOMString &namespaceURI,
const DOMString &localName )
{
if (!impl) return 0;
- return static_cast<ElementImpl*>(impl)->
- getElementsByTagNameNS(namespaceURI.implementation(), localName.implementation());
+ return static_cast<ElementImpl*>(impl)->getElementsByTagNameNS(namespaceURI, localName).get();
}
DOMString Element::getAttributeNS( const DOMString &namespaceURI,
throw DOMException(DOMException::NOT_FOUND_ERR);
int exceptioncode = 0;
- Attr r = static_cast<ElementImpl*>(impl)->attributes(false)->setNamedItem(newAttr.handle(), exceptioncode);
+ Attr r = static_cast<ElementImpl*>(impl)->setAttributeNodeNS(static_cast<AttrImpl *>(newAttr.handle()), exceptioncode).get();
if ( exceptioncode )
throw DOMException( exceptioncode );
return r;
{
if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
int exceptioncode = 0;
- Node r = impl->setNamedItem(arg.impl, exceptioncode);
+ Node r = impl->setNamedItem(arg.impl, exceptioncode).get();
if (exceptioncode)
throw DOMException(exceptioncode);
return r;
{
if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR);
int exceptioncode = 0;
- Node r = impl->removeNamedItem(impl->mapId(namespaceURI, localName, true), exceptioncode);
+ Node r = impl->removeNamedItem(impl->mapId(namespaceURI, localName, true), exceptioncode).get();
if (exceptioncode)
throw DOMException(exceptioncode);
return r;
#include "dom/dom_exception.h"
#include "dom/dom2_range.h"
+#include "dom/dom2_events.h"
#include "xml/dom2_eventsimpl.h"
#include <kdebug.h>
DOM::Node node = toNode(args[0]);
if (!node.isNull()) {
if (node.nodeType() == DOM::Node::ELEMENT_NODE) {
- cb->clipboard->setDragImageElement(node, QPoint(x,y));
+ cb->clipboard->setDragImageElement(node.handle(), QPoint(x,y));
return Undefined();
} else {
Object err = Error::create(exec, SyntaxError,"setDragImageFromElement: Invalid first argument");
#include "jsediting.h"
-#include "cssproperties.h"
+#include "css/css_valueimpl.h"
+#include "css/cssproperties.h"
+
#include "htmlediting.h"
#include "khtml_part.h"
-#include "qstring.h"
+#include <qstring.h>
#include "selection.h"
#if APPLE_CHANGES
if (!d->m_doc)
return;
- static DOMString body = "body";
- NodeListImpl *list = d->m_doc->getElementsByTagNameNS(0, body.implementation());
- list->ref();
- for (unsigned i = 0; i < list->length(); i++) {
+ SharedPtr<NodeListImpl> list = d->m_doc->getElementsByTagName("body");
+ unsigned len = list->length();
+ for (unsigned i = 0; i < len; i++) {
applyEditingStyleToElement(static_cast<ElementImpl *>(list->item(i)));
}
- list->deref();
}
void KHTMLPart::removeEditingStyleFromBodyElement() const
if (!d->m_doc)
return;
- static DOMString body = "body";
- NodeListImpl *list = d->m_doc->getElementsByTagNameNS(0, body.implementation());
- list->ref();
- for (unsigned i = 0; i < list->length(); i++) {
+ SharedPtr<NodeListImpl> list = d->m_doc->getElementsByTagName("body");
+ unsigned len = list->length();
+ for (unsigned i = 0; i < len; i++) {
removeEditingStyleFromElement(static_cast<ElementImpl *>(list->item(i)));
}
- list->deref();
}
void KHTMLPart::applyEditingStyleToElement(ElementImpl *element) const
d->clickCount = _mouse->clickCount();
if (d->clickNode)
d->clickNode->deref();
- d->clickNode = mev.innerNode.handle();
+ d->clickNode = mev.innerNode.get();
if (d->clickNode)
d->clickNode->ref();
#endif
- bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),true,
+ bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.get(),true,
d->clickCount,_mouse,true,DOM::NodeImpl::MousePress);
if (!swallowEvent) {
- khtml::MousePressEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
+ khtml::MousePressEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode.get() );
QApplication::sendEvent( m_part, &event );
#if APPLE_CHANGES
// Many AK widgets run their own event loops and consume events while the mouse is down.
d->mousePressed = false;
}
#endif
- emit m_part->nodeActivated(mev.innerNode);
+ emit m_part->nodeActivated(mev.innerNode.get());
}
}
return;
d->clickCount = _mouse->clickCount();
- bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,mev.innerNode.handle(),true,
+ bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,mev.innerNode.get(),true,
d->clickCount,_mouse,false,DOM::NodeImpl::MouseRelease);
- if (mev.innerNode.handle() == d->clickNode)
- dispatchMouseEvent(EventImpl::CLICK_EVENT,mev.innerNode.handle(),true,
+ if (mev.innerNode == d->clickNode)
+ dispatchMouseEvent(EventImpl::CLICK_EVENT,mev.innerNode.get(),true,
d->clickCount,_mouse,true,DOM::NodeImpl::MouseRelease);
// Qt delivers a release event AND a double click event.
if (!swallowEvent) {
- khtml::MouseReleaseEvent event1( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
+ khtml::MouseReleaseEvent event1( _mouse, xm, ym, mev.url, mev.target, mev.innerNode.get() );
QApplication::sendEvent( m_part, &event1 );
- khtml::MouseDoubleClickEvent event2( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
+ khtml::MouseDoubleClickEvent event2( _mouse, xm, ym, mev.url, mev.target, mev.innerNode.get() );
QApplication::sendEvent( m_part, &event2 );
}
#else
return;
#endif
- bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEMOVE_EVENT,mev.innerNode.handle(),false,
+ bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEMOVE_EVENT,mev.innerNode.get(),false,
0,_mouse,true,DOM::NodeImpl::MouseMove);
#if !APPLE_CHANGES
// execute the scheduled script. This is to make sure the mouseover events come after the mouseout events
m_part->executeScheduledScript();
- NodeImpl *node = mev.innerNode.handle();
+ NodeImpl *node = mev.innerNode.get();
RenderObject *renderer = node ? node->renderer() : 0;
RenderStyle *style = renderer ? renderer->style() : 0;
d->prevMouseY = ym;
if (!swallowEvent) {
- khtml::MouseMoveEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
+ khtml::MouseMoveEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode.get() );
QApplication::sendEvent( m_part, &event );
}
}
return;
#endif
- bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,mev.innerNode.handle(),true,
+ bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,mev.innerNode.get(),true,
d->clickCount,_mouse,false,DOM::NodeImpl::MouseRelease);
- if (d->clickCount > 0 && mev.innerNode.handle() == d->clickNode
+ if (d->clickCount > 0 && mev.innerNode == d->clickNode
#if !APPLE_CHANGES
&& QPoint(d->clickX-xm,d->clickY-ym).manhattanLength() <= QApplication::startDragDistance()
#endif
)
- dispatchMouseEvent(EventImpl::CLICK_EVENT,mev.innerNode.handle(),true,
+ dispatchMouseEvent(EventImpl::CLICK_EVENT,mev.innerNode.get(),true,
d->clickCount,_mouse,true,DOM::NodeImpl::MouseRelease);
if (!swallowEvent) {
- khtml::MouseReleaseEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
+ khtml::MouseReleaseEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode.get() );
QApplication::sendEvent( m_part, &event );
}
viewportToContents(loc.x(), loc.y(), xm, ym);
DOM::NodeImpl::MouseEvent mev(0, DOM::NodeImpl::MouseMove);
m_part->xmlDocImpl()->prepareMouseEvent(true, xm, ym, &mev);
- DOM::Node newTarget = mev.innerNode;
+ DOM::Node newTarget = mev.innerNode.get();
// Drag events should never go to text nodes (following IE, and proper mouseover/out dispatch)
if (newTarget.nodeType() == Node::TEXT_NODE) {
if (d->prevMouseX >= 0 && d->prevMouseY >= 0) {
NodeImpl::MouseEvent mev( _mouse->stateAfter(), static_cast<NodeImpl::MouseEventType>(mouseEventType));
m_part->xmlDocImpl()->prepareMouseEvent( true, d->prevMouseX, d->prevMouseY, &mev );
- oldUnder = mev.innerNode.handle();
+ oldUnder = mev.innerNode.get();
}
if (oldUnder != targetNode) {
// send mouseout event to the old node
bool notNull() const { return m_ptr != 0; }
void reset() { if (m_ptr) m_ptr->deref(); m_ptr = 0; }
+ void reset(T *o) { if (o) o->ref(); if (m_ptr) m_ptr->deref(); m_ptr = o; }
T * get() const { return m_ptr; }
T &operator*() const { return *m_ptr; }
template <class T> SharedPtr<T> &SharedPtr<T>::operator=(const SharedPtr<T> &o)
{
- if (m_ptr != o.m_ptr) {
- if (m_ptr)
- m_ptr->deref();
- m_ptr = o.m_ptr;
- if (m_ptr)
- m_ptr->ref();
- }
+ if (o.m_ptr)
+ o.m_ptr->ref();
+ if (m_ptr)
+ m_ptr->deref();
+ m_ptr = o.m_ptr;
return *this;
}
template <class T> inline bool operator!=(const SharedPtr<T> &a, const T *b) { return !(a == b); }
template <class T> inline bool operator!=(const T *a, const SharedPtr<T> &b) { return !(a == b); }
-};
+template <class T, class U> inline SharedPtr<T> static_pointer_cast(const SharedPtr<U> &p) { return SharedPtr<T>(static_cast<T *>(p.get())); }
+template <class T, class U> inline SharedPtr<T> const_pointer_cast(const SharedPtr<U> &p) { return SharedPtr<T>(const_cast<T *>(p.get())); }
+
+}
#endif
* Boston, MA 02111-1307, USA.
*/
-#include "dom/dom2_views.h"
-
#include "xml/dom2_eventsimpl.h"
+
+#include "dom/dom2_events.h"
+#include "dom/dom2_views.h"
#include "xml/dom_stringimpl.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom_docimpl.h"
+#include "xml/dom2_viewsimpl.h"
#include "rendering/render_object.h"
#include "rendering/render_layer.h"
void UIEventImpl::initUIEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const AbstractView &viewArg,
+ AbstractViewImpl *viewArg,
long detailArg)
{
EventImpl::initEvent(typeArg,canBubbleArg,cancelableArg);
if (m_view)
m_view->deref();
- m_view = viewArg.handle();
+ m_view = viewArg;
if (m_view)
m_view->ref();
m_detail = detailArg;
return true;
}
-// -----------------------------------------------------------------------------
+int UIEventImpl::keyCode() const
+{
+ return 0;
+}
+
+int UIEventImpl::charCode() const
+{
+ return 0;
+}
+
+long UIEventImpl::layerX() const
+{
+ return 0;
+}
+
+long UIEventImpl::layerY() const
+{
+ return 0;
+}
+
+long UIEventImpl::pageX() const
+{
+ return 0;
+}
+
+long UIEventImpl::pageY() const
+{
+ return 0;
+}
+
+long UIEventImpl::which() const
+{
+ return 0;
+}
// -----------------------------------------------------------------------------
}
}
+long MouseRelatedEventImpl::pageX() const
+{
+ return m_clientX;
+}
+
+long MouseRelatedEventImpl::pageY() const
+{
+ return m_clientY;
+}
+
// -----------------------------------------------------------------------------
MouseEventImpl::MouseEventImpl()
void MouseEventImpl::initMouseEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const AbstractView &viewArg,
+ AbstractViewImpl *viewArg,
long detailArg,
long screenXArg,
long screenYArg,
bool shiftKeyArg,
bool metaKeyArg,
unsigned short buttonArg,
- const Node &relatedTargetArg)
+ NodeImpl *relatedTargetArg)
{
UIEventImpl::initUIEvent(typeArg,canBubbleArg,cancelableArg,viewArg,detailArg);
m_shiftKey = shiftKeyArg;
m_metaKey = metaKeyArg;
m_button = buttonArg;
- m_relatedTarget = relatedTargetArg.handle();
+ m_relatedTarget = relatedTargetArg;
if (m_relatedTarget)
m_relatedTarget->ref();
computeLayerPos();
|| m_id == EventImpl::DRAGEND_EVENT);
}
+long MouseEventImpl::which() const
+{
+ // For KHTML, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
+ // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
+ // So we must add 1.
+ return m_button + 1;
+}
+
//---------------------------------------------------------------------------------------------
KeyboardEventImpl::KeyboardEventImpl()
void KeyboardEventImpl::initKeyboardEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const AbstractView &viewArg,
+ AbstractViewImpl *viewArg,
const DOMString &keyIdentifierArg,
unsigned long keyLocationArg,
bool ctrlKeyArg,
return true;
}
+long KeyboardEventImpl::which() const
+{
+ // Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress.
+ // That's exactly what IE's "keyCode" returns. So they are the same for keyboard events.
+ return keyCode();
+}
+
// -----------------------------------------------------------------------------
MutationEventImpl::MutationEventImpl()
MutationEventImpl::MutationEventImpl(EventId _id,
bool canBubbleArg,
bool cancelableArg,
- const Node &relatedNodeArg,
+ NodeImpl *relatedNodeArg,
const DOMString &prevValueArg,
const DOMString &newValueArg,
const DOMString &attrNameArg,
unsigned short attrChangeArg)
: EventImpl(_id,canBubbleArg,cancelableArg)
{
- m_relatedNode = relatedNodeArg.handle();
+ m_relatedNode = relatedNodeArg;
if (m_relatedNode)
m_relatedNode->ref();
m_prevValue = prevValueArg.implementation();
void MutationEventImpl::initMutationEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const Node &relatedNodeArg,
+ NodeImpl *relatedNodeArg,
const DOMString &prevValueArg,
const DOMString &newValueArg,
const DOMString &attrNameArg,
if (m_attrName)
m_attrName->deref();
- m_relatedNode = relatedNodeArg.handle();
+ m_relatedNode = relatedNodeArg;
if (m_relatedNode)
m_relatedNode->ref();
m_prevValue = prevValueArg.implementation();
#ifndef _DOM_EventsImpl_h_
#define _DOM_EventsImpl_h_
-#include "dom/dom2_events.h"
-#include "misc/shared.h"
-#include "xml/dom2_viewsimpl.h"
#include <qdatetime.h>
-#include <qevent.h>
+#include "dom/dom_node.h"
+#include "dom/dom_string.h"
+#include "misc/shared.h"
class KHTMLPart;
+class QKeyEvent;
+class QPixmap;
class QPoint;
class QStringList;
class AbstractViewImpl;
class DOMStringImpl;
+class EventListener;
class NodeImpl;
class ClipboardImpl;
void initUIEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const AbstractView &viewArg,
+ AbstractViewImpl *viewArg,
long detailArg);
virtual bool isUIEvent() const;
+ virtual int keyCode() const;
+ virtual int charCode() const;
+
+ virtual long layerX() const;
+ virtual long layerY() const;
+
+ virtual long pageX() const;
+ virtual long pageY() const;
+
+ virtual long which() const;
+
protected:
AbstractViewImpl *m_view;
long m_detail;
long clientY() const { return m_clientY; }
long layerX() const { return m_layerX; }
long layerY() const { return m_layerY; }
+ virtual long pageX() const;
+ virtual long pageY() const;
protected: // expose these so MouseEventImpl::initMouseEvent can set them
long m_screenX;
long m_screenY;
void initMouseEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const AbstractView &viewArg,
+ AbstractViewImpl *viewArg,
long detailArg,
long screenXArg,
long screenYArg,
bool shiftKeyArg,
bool metaKeyArg,
unsigned short buttonArg,
- const Node &relatedTargetArg);
+ NodeImpl *relatedTargetArg);
virtual bool isMouseEvent() const;
virtual bool isDragEvent() const;
+ virtual long which() const;
private:
unsigned short m_button;
NodeImpl *m_relatedTarget;
void initKeyboardEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const AbstractView &viewArg,
+ AbstractViewImpl *viewArg,
const DOMString &keyIdentifierArg,
unsigned long keyLocationArg,
bool ctrlKeyArg,
int charCode() const;
virtual bool isKeyboardEvent() const;
+ virtual long which() const;
private:
QKeyEvent *m_keyEvent;
MutationEventImpl(EventId _id,
bool canBubbleArg,
bool cancelableArg,
- const Node &relatedNodeArg,
+ NodeImpl *relatedNodeArg,
const DOMString &prevValueArg,
const DOMString &newValueArg,
const DOMString &attrNameArg,
unsigned short attrChangeArg);
~MutationEventImpl();
- Node relatedNode() const { return m_relatedNode; }
+ NodeImpl *relatedNode() const { return m_relatedNode; }
DOMString prevValue() const { return m_prevValue; }
DOMString newValue() const { return m_newValue; }
DOMString attrName() const { return m_attrName; }
void initMutationEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
- const Node &relatedNodeArg,
+ NodeImpl *relatedNodeArg,
const DOMString &prevValueArg,
const DOMString &newValueArg,
const DOMString &attrNameArg,
virtual QPoint dragLocation() const = 0;
virtual QPixmap dragImage() const = 0;
virtual void setDragImage(const QPixmap &, const QPoint &) = 0;
- virtual const Node dragImageElement() = 0;
- virtual void setDragImageElement(const Node &, const QPoint &) = 0;
+ virtual NodeImpl *dragImageElement() = 0;
+ virtual void setDragImageElement(NodeImpl *, const QPoint &) = 0;
};
} // namespace
#ifndef _DOM2_RangeImpl_h_
#define _DOM2_RangeImpl_h_
-#include <qptrlist.h>
#include "dom/dom2_range.h"
#include "misc/shared.h"
#include "misc/main_thread_malloc.h"
+
namespace DOM {
+class DocumentFragmentImpl;
class DocumentPtr;
class NodeImpl;
class Position;
MAIN_THREAD_ALLOCATED;
- // ### remove the get from these methods (i.e. getStartContainer() -> startContainer())
NodeImpl *startContainer(int &exceptioncode) const;
long startOffset(int &exceptioncode) const;
NodeImpl *endContainer(int &exceptioncode) const;
Position editingStartPosition() const;
-#if APPLE_CHANGES
- static Range createInstance (RangeImpl *impl);
-#endif
-
#ifndef NDEBUG
void formatForDebugger(char *buffer, unsigned length) const;
#endif
m_condition->deref();
}
-short NodeFilterImpl::acceptNode(const Node &node) const
+short NodeFilterImpl::acceptNode(NodeImpl *node) const
{
// cast to short silences "enumeral and non-enumeral types in return" warning
return m_condition ? m_condition->acceptNode(node) : static_cast<short>(NodeFilter::FILTER_ACCEPT);
#define _dom2_traversal_h
#include "dom/dom2_traversal.h"
-#include "dom/dom_node.h"
-#include "dom/dom_misc.h"
#include "misc/shared.h"
#include "misc/main_thread_malloc.h"
MAIN_THREAD_ALLOCATED;
- short acceptNode(const Node &) const;
+ short acceptNode(NodeImpl *) const;
private:
NodeFilterImpl(const NodeFilterImpl &);
* Boston, MA 02111-1307, USA.
*/
+#include "dom_docimpl.h"
+
#include "dom/dom_exception.h"
+#include "dom/dom2_events.h"
#include "xml/dom_textimpl.h"
#include "xml/dom_xmlimpl.h"
#include "xml/dom2_rangeimpl.h"
#include "xml/dom2_eventsimpl.h"
+#include "xml/dom2_viewsimpl.h"
#include "xml/xml_tokenizer.h"
#include "xml_namespace_table.h"
}
DocumentImpl *DOMImplementationImpl::createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName,
- const DocumentType &doctype, int &exceptioncode )
+ DocumentTypeImpl *doctype, int &exceptioncode )
{
exceptioncode = 0;
return 0;
}
- DocumentTypeImpl *dtype = static_cast<DocumentTypeImpl*>(doctype.handle());
// WRONG_DOCUMENT_ERR: Raised if doctype has already been used with a different document or was
// created from a different implementation.
- if (dtype && (dtype->getDocument() || dtype->implementation() != this)) {
+ if (doctype && (doctype->getDocument() || doctype->implementation() != this)) {
exceptioncode = DOMException::WRONG_DOCUMENT_ERR;
return 0;
}
DocumentImpl *doc = new DocumentImpl(this, 0);
// now get the interesting parts of the doctype
- // ### create new one if not there (currently always there)
- if (doc->doctype() && dtype)
- doc->doctype()->copyFrom(*dtype);
+ if (doctype)
+ doc->realDocType()->copyFrom(*doctype);
return doc;
}
-CSSStyleSheetImpl *DOMImplementationImpl::createCSSStyleSheet(DOMStringImpl */*title*/, DOMStringImpl *media,
- int &/*exceptioncode*/)
+CSSStyleSheetImpl *DOMImplementationImpl::createCSSStyleSheet(const DOMString &/*title*/, const DOMString &media, int &/*exception*/)
{
- // ### TODO : title should be set, and media could have wrong syntax, in which case we should
- // generate an exception.
- CSSStyleSheetImpl *parent = 0L;
- CSSStyleSheetImpl *sheet = new CSSStyleSheetImpl(parent, DOMString());
- sheet->setMedia(new MediaListImpl(sheet, media));
- return sheet;
+ // ### TODO : title should be set, and media could have wrong syntax, in which case we should generate an exception.
+ CSSStyleSheetImpl * const nullSheet = 0;
+ CSSStyleSheetImpl *sheet = new CSSStyleSheetImpl(nullSheet);
+ sheet->setMedia(new MediaListImpl(sheet, media));
+ return sheet;
}
DocumentImpl *DOMImplementationImpl::createDocument( KHTMLView *v )
return m_instance;
}
+HTMLDocumentImpl *DOMImplementationImpl::createHTMLDocument(const DOMString &title)
+{
+ HTMLDocumentImpl *d = createHTMLDocument( 0 /* ### create a view otherwise it doesn't work */);
+ d->open();
+ // FIXME: Need to escape special characters in the title?
+ d->write("<html><head><title>" + title.string() + "</title></head>");
+ return d;
+}
+
// ------------------------------------------------------------------------
KStaticDeleter< QPtrList<DocumentImpl> > s_changedDocumentsDeleter;
return new ProcessingInstructionImpl( docPtr(),target,data);
}
-Attr DocumentImpl::createAttribute( NodeImpl::Id id )
+AttrImpl *DocumentImpl::createAttribute( NodeImpl::Id id )
{
// Assume this is an HTML attribute, since createAttribute isn't namespace-aware. There's no harm to XML
// documents if we're wrong.
// ins/del
case ID_DEL:
case ID_INS:
- return new HTMLGenericElementImpl(docPtr(), tagID);
+ return new HTMLModElementImpl(docPtr(), tagID);
// anchor
case ID_A:
case ID_BR:
return new HTMLBRElementImpl(docPtr());
case ID_Q:
- return new HTMLGenericElementImpl(docPtr(), tagID);
+ return new HTMLQuoteElementImpl(docPtr());
// elements with no special representation in the DOM
assert(m_render->isCanvas());
RenderObject::NodeInfo renderInfo(readonly, ev->type == MousePress);
bool isInside = m_render->layer()->hitTest(renderInfo, _x, _y);
- ev->innerNode = renderInfo.innerNode();
+ ev->innerNode.reset(renderInfo.innerNode());
if (renderInfo.URLElement()) {
assert(renderInfo.URLElement()->isElementNode());
}
}
-CSSStyleDeclarationImpl *DocumentImpl::getOverrideStyle(ElementImpl */*elt*/, DOMStringImpl */*pseudoElt*/)
+CSSStyleDeclarationImpl *DocumentImpl::getOverrideStyle(ElementImpl */*elt*/, const DOMString &/*pseudoElt*/)
{
return 0; // ###
}
DOMString DocumentImpl::completeURL(const DOMString &URL)
{
+ if (URL.isNull())
+ return URL;
return completeURL(URL.string());
}
return doc;
}
+AttrImpl *DocumentImpl::createAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, int &exception)
+{
+ if (qualifiedName.isNull()) {
+ exception = DOMException::NAMESPACE_ERR;
+ return 0;
+ }
+
+ DOMString localName(qualifiedName.copy());
+ DOMString prefix;
+ int colonpos;
+ if ((colonpos = qualifiedName.find(':')) >= 0) {
+ prefix = qualifiedName.copy();
+ prefix.truncate(colonpos);
+ localName.remove(0, colonpos+1);
+ }
+
+ if (!isValidName(localName)) {
+ exception = DOMException::INVALID_CHARACTER_ERR;
+ return 0;
+ }
+ // ### check correctness of namespace, prefix?
+
+ Id id = attrId(namespaceURI.implementation(), localName.implementation(), false /* allocate */);
+ AttrImpl *attr = createAttribute(id);
+ if (!prefix.isNull())
+ attr->setPrefix(prefix.implementation(), exception);
+ return attr;
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::images()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_IMAGES));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::applets()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_APPLETS));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::embeds()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_EMBEDS));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::objects()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_OBJECTS));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::links()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_LINKS));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::forms()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_FORMS));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::anchors()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_ANCHORS));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::all()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_ALL));
+}
+
+SharedPtr<HTMLCollectionImpl> DocumentImpl::nameableItems()
+{
+ return SharedPtr<HTMLCollectionImpl>(new HTMLCollectionImpl(this, HTMLCollectionImpl::DOC_NAMEABLE_ITEMS));
+}
+
+SharedPtr<NameNodeListImpl> DocumentImpl::getElementsByName(const DOMString &elementName)
+{
+ return SharedPtr<NameNodeListImpl>(new NameNodeListImpl(this, elementName));
+}
+
// ----------------------------------------------------------------------------
DocumentFragmentImpl::DocumentFragmentImpl(DocumentPtr *doc) : ContainerNodeImpl(doc)
namespace khtml {
class CSSStyleSelector;
+ struct DashboardRegionValue;
class DocLoader;
class RenderImage;
class Tokenizer;
class XMLHandler;
-#if APPLE_CHANGES
- struct DashboardRegionValue;
-#endif
}
#ifndef KHTML_NO_XBL
class DocumentImpl;
class DocumentType;
class DocumentTypeImpl;
-#if APPLE_CHANGES
- class DOMImplementation;
-#endif
class EditingTextImpl;
class ElementImpl;
class EntityReferenceImpl;
class EventImpl;
class EventListener;
class GenericRONamedNodeMapImpl;
+ class HTMLCollectionImpl;
class HTMLDocumentImpl;
class HTMLElementImpl;
class HTMLImageLoader;
class StyleSheetListImpl;
class TextImpl;
class TreeWalkerImpl;
-#ifdef KHTML_XSLT
- class XSLStyleSheetImpl;
-#endif
// A range of a node within a document that is "marked", such as being misspelled
struct DocumentMarker
DocumentTypeImpl *createDocumentType( const DOMString &qualifiedName, const DOMString &publicId,
const DOMString &systemId, int &exceptioncode );
DocumentImpl *createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName,
- const DocumentType &doctype, int &exceptioncode );
+ DocumentTypeImpl *doctype, int &exceptioncode );
DOMImplementationImpl* getInterface(const DOMString& feature) const;
// From the DOMImplementationCSS interface
- CSSStyleSheetImpl *createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media, int &exceptioncode);
+ CSSStyleSheetImpl *createCSSStyleSheet(const DOMString &title, const DOMString &media, int &exceptioncode);
// From the HTMLDOMImplementation interface
HTMLDocumentImpl* createHTMLDocument( const DOMString& title);
// ever be present, and is used as a factory method for creating DocumentImpl objects
static DOMImplementationImpl *instance();
-#if APPLE_CHANGES
- static DOMImplementation createInstance (DOMImplementationImpl *impl);
-#endif
-
protected:
static DOMImplementationImpl *m_instance;
};
// DOM methods & attributes for Document
- DocumentTypeImpl *doctype() const;
+ virtual DocumentTypeImpl *doctype() const; // returns 0 for HTML documents
+ DocumentTypeImpl *realDocType() const { return m_doctype; }
DOMImplementationImpl *implementation() const;
virtual ElementImpl *documentElement() const;
CommentImpl *createComment ( const DOMString &data );
CDATASectionImpl *createCDATASection ( const DOMString &data );
ProcessingInstructionImpl *createProcessingInstruction ( const DOMString &target, const DOMString &data );
- Attr createAttribute(NodeImpl::Id id);
+ AttrImpl *createAttribute(Id id);
+ AttrImpl *createAttribute(const DOMString &name, int &exception) { return createAttributeNS(DOMString(), name, exception); }
+ AttrImpl *createAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, int &exception);
EntityReferenceImpl *createEntityReference ( const DOMString &name );
NodeImpl *importNode( NodeImpl *importedNode, bool deep, int &exceptioncode );
virtual ElementImpl *createElementNS ( const DOMString &_namespaceURI, const DOMString &_qualifiedName, int &exceptioncode );
ElementImpl *getElementById ( const DOMString &elementId ) const;
ElementImpl *elementFromPoint ( const int _x, const int _y ) const;
+ SharedPtr<NameNodeListImpl> getElementsByName(const DOMString &elementName);
+
// Actually part of HTMLDocument, but used for giving XML documents a window title as well
DOMString title() const { return m_title; }
void setTitle(DOMString _title);
+ SharedPtr<HTMLCollectionImpl> images();
+ SharedPtr<HTMLCollectionImpl> embeds();
+ SharedPtr<HTMLCollectionImpl> applets();
+ SharedPtr<HTMLCollectionImpl> links();
+ SharedPtr<HTMLCollectionImpl> forms();
+ SharedPtr<HTMLCollectionImpl> anchors();
+ SharedPtr<HTMLCollectionImpl> all();
+ SharedPtr<HTMLCollectionImpl> objects();
+ SharedPtr<HTMLCollectionImpl> nameableItems();
+
// DOM methods overridden from parent classes
virtual DOMString nodeName() const;
QString baseTarget() const { return m_baseTarget; }
void setBaseTarget(const QString& baseTarget) { m_baseTarget = baseTarget; }
-#if APPLE_CHANGES
QString completeURL(const QString &);
-#else
- QString completeURL(const QString& url) { return KURL(baseURL(),url).url(); };
-#endif
-
- DOM::DOMString completeURL(const DOM::DOMString &);
+ DOMString completeURL(const DOMString &);
// from cachedObjectClient
virtual void setStyleSheet(const DOMString &url, const DOMString &sheetStr);
bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
- CSSStyleDeclarationImpl *getOverrideStyle(ElementImpl *elt, DOMStringImpl *pseudoElt);
+ CSSStyleDeclarationImpl *getOverrideStyle(ElementImpl *elt, const DOMString &pseudoElt);
typedef QMap<QString, ProcessingInstructionImpl*> LocalStyleRefs;
LocalStyleRefs* localStyleRefs() { return &m_localStyleRefs; }
public:
KWQSignal m_finishedParsing;
- static Document createInstance (DocumentImpl *impl);
-
bool inPageCache();
void setInPageCache(bool flag);
void restoreRenderer(khtml::RenderObject* render);
virtual DOMString toString() const;
-#if APPLE_CHANGES
- static DocumentType createInstance (DocumentTypeImpl *impl);
-#endif
-
protected:
DOMImplementationImpl *m_implementation;
NamedNodeMapImpl* m_entities;
};
-}; //namespace
+} //namespace
+
#endif
DOMString AttrImpl::nodeName() const
{
- return getDocument()->attrName(m_attribute->id());
+ return name();
}
unsigned short AttrImpl::nodeType() const
m_attribute->setPrefix(_prefix.implementation());
}
-DOMString AttrImpl::nodeValue() const {
- return m_attribute->value();
+DOMString AttrImpl::nodeValue() const
+{
+ return value();
}
void AttrImpl::setValue( const DOMString &v, int &exceptioncode )
return result;
}
+DOMString AttrImpl::name() const
+{
+ return getDocument()->attrName(m_attribute->id());
+}
+
+DOMString AttrImpl::value() const
+{
+ return m_attribute->value();
+}
+
// -------------------------------------------------------------------------
ElementImpl::ElementImpl(DocumentPtr *doc)
setAttribute(id,value.implementation(),exceptioncode);
}
+// Virtual function, defined in base class.
+NamedAttrMapImpl *ElementImpl::attributes() const
+{
+ return attributes(false);
+}
+
NamedAttrMapImpl* ElementImpl::attributes(bool readonly) const
{
updateStyleAttributeIfNeeded();
-
- if (!readonly && !namedAttrMap) createAttributeMap();
+ if (!readonly && !namedAttrMap)
+ createAttributeMap();
return namedAttrMap;
}
bool ElementImpl::isURLAttribute(AttributeImpl *attr) const
{
return false;
-
}
RenderStyle *ElementImpl::styleForRenderer(RenderObject *parentRenderer)
}
#endif
+SharedPtr<AttrImpl> ElementImpl::setAttributeNode(AttrImpl *attr, int &exception)
+{
+ return static_pointer_cast<AttrImpl>(attributes(false)->setNamedItem(attr, exception));
+}
+
+SharedPtr<AttrImpl> ElementImpl::removeAttributeNode(AttrImpl *attr, int &exception)
+{
+ if (!attr || attr->ownerElement() != this) {
+ exception = DOMException::NOT_FOUND_ERR;
+ return SharedPtr<AttrImpl>();
+ }
+ if (getDocument() != attr->getDocument()) {
+ exception = DOMException::WRONG_DOCUMENT_ERR;
+ return SharedPtr<AttrImpl>();
+ }
+
+ NamedAttrMapImpl *attrs = attributes(true);
+ if (!attrs)
+ return SharedPtr<AttrImpl>();
+
+ return static_pointer_cast<AttrImpl>(attrs->removeNamedItem(attr->m_attribute->id(), exception));
+}
+
+void ElementImpl::setAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, const DOMString &value, int &exception)
+{
+ int colonpos = qualifiedName.find(':');
+ DOMString localName = qualifiedName;
+ if (colonpos >= 0) {
+ localName.remove(0, colonpos+1);
+ // ### extract and set new prefix
+ }
+
+ if (!DocumentImpl::isValidName(localName)) {
+ exception = DOMException::INVALID_CHARACTER_ERR;
+ return;
+ }
+
+ Id id = getDocument()->attrId(namespaceURI.implementation(), localName.implementation(), false /* allocate */);
+ setAttribute(id, value.implementation(), exception);
+}
+
+void ElementImpl::removeAttributeNS(const DOMString &namespaceURI, const DOMString &localName, int &exception)
+{
+ Id id = getDocument()->attrId(namespaceURI.implementation(), localName.implementation(), true);
+ if (!id)
+ return;
+ removeAttribute(id, exception);
+}
+
+AttrImpl *ElementImpl::getAttributeNodeNS(const DOMString &namespaceURI, const DOMString &localName)
+{
+ Id id = getDocument()->attrId(namespaceURI.implementation(), localName.implementation(), true);
+ if (!id)
+ return 0;
+ NamedAttrMapImpl *attrs = attributes(true);
+ if (!attrs)
+ return 0;
+ return attrs->getNamedItem(id);
+}
+
+bool ElementImpl::hasAttributeNS(const DOMString &namespaceURI, const DOMString &localName) const
+{
+ Id id = getDocument()->attrId(namespaceURI.implementation(), localName.implementation(), true);
+ if (!id)
+ return false;
+ NamedAttrMapImpl *attrs = attributes(true);
+ if (!attrs)
+ return false;
+ return attrs->getAttributeItem(id);
+}
+
+CSSStyleDeclarationImpl *ElementImpl::style()
+{
+ return 0;
+}
+
// -------------------------------------------------------------------------
XMLElementImpl::XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_tagName)
// clone attributes
if (namedAttrMap)
- *clone->attributes() = *namedAttrMap;
+ *clone->attributes(false) = *namedAttrMap;
if (deep)
cloneChildNodes(clone);
return a->attrImpl();
}
-Node NamedAttrMapImpl::setNamedItem ( NodeImpl* arg, int &exceptioncode )
+SharedPtr<NodeImpl> NamedAttrMapImpl::setNamedItem ( NodeImpl* arg, int &exceptioncode )
{
if (!element) {
exceptioncode = DOMException::NOT_FOUND_ERR;
- return 0;
+ return SharedPtr<NodeImpl>();
}
// NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
if (isReadOnly()) {
exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
- return 0;
+ return SharedPtr<NodeImpl>();
}
// WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created this map.
if (arg->getDocument() != element->getDocument()) {
exceptioncode = DOMException::WRONG_DOCUMENT_ERR;
- return 0;
+ return SharedPtr<NodeImpl>();
}
// Not mentioned in spec: throw a HIERARCHY_REQUEST_ERROR if the user passes in a non-attribute node
if (!arg->isAttributeNode()) {
exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;
- return 0;
+ return SharedPtr<NodeImpl>();
}
AttrImpl *attr = static_cast<AttrImpl*>(arg);
AttributeImpl* a = attr->attrImpl();
AttributeImpl* old = getAttributeItem(a->id());
- if (old == a) return arg; // we know about it already
+ if (old == a)
+ return SharedPtr<NodeImpl>(arg); // we know about it already
// INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object.
// The DOM user must explicitly clone Attr nodes to re-use them in other elements.
if (attr->ownerElement()) {
exceptioncode = DOMException::INUSE_ATTRIBUTE_ERR;
- return 0;
+ return SharedPtr<NodeImpl>();
}
if (a->id() == ATTR_ID) {
}
// ### slightly inefficient - resizes attribute array twice.
- Node r;
+ SharedPtr<NodeImpl> r;
if (old) {
if (!old->attrImpl())
old->allocateImpl(element);
- r = old->_impl;
+ r.reset(old->_impl);
removeAttribute(a->id());
}
// The DOM2 spec doesn't say that removeAttribute[NS] throws NOT_FOUND_ERR
// if the attribute is not found, but at this level we have to throw NOT_FOUND_ERR
// because of removeNamedItem, removeNamedItemNS, and removeAttributeNode.
-Node NamedAttrMapImpl::removeNamedItem ( NodeImpl::Id id, int &exceptioncode )
+SharedPtr<NodeImpl> NamedAttrMapImpl::removeNamedItem ( NodeImpl::Id id, int &exceptioncode )
{
// ### should this really be raised when the attribute to remove isn't there at all?
// NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
if (isReadOnly()) {
exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
- return Node();
+ return SharedPtr<NodeImpl>();
}
AttributeImpl* a = getAttributeItem(id);
if (!a) {
exceptioncode = DOMException::NOT_FOUND_ERR;
- return Node();
+ return SharedPtr<NodeImpl>();
}
if (!a->attrImpl()) a->allocateImpl(element);
- Node r(a->attrImpl());
+ SharedPtr<NodeImpl> r(a->attrImpl());
if (id == ATTR_ID) {
element->updateId(a->value(), nullAtom);
namespace DOM {
-class ElementImpl;
+class AtomicStringList;
class DocumentImpl;
+class CSSStyleDeclarationImpl;
+class ElementImpl;
class NamedAttrMapImpl;
-class AtomicStringList;
// this has no counterpart in DOM, purely internal
// representation of the nodevalue of an Attr.
public:
// DOM methods & attributes for Attr
+ DOMString name() const;
bool specified() const { return m_specified; }
ElementImpl* ownerElement() const { return m_element; }
AttributeImpl* attrImpl() const { return m_attribute; }
- //DOMString value() const;
+ DOMString value() const;
void setValue( const DOMString &v, int &exceptioncode );
// DOM methods overridden from parent classes
virtual DOMString toString() const;
-#if APPLE_CHANGES
- static Attr createInstance(AttrImpl *impl);
-#endif
-
protected:
ElementImpl* m_element;
AttributeImpl* m_attribute;
// Used to quickly determine whether or not an element has a given CSS class.
virtual const AtomicStringList* getClassList() const;
const AtomicString& getIDAttribute() const;
- const AtomicString& getAttribute( NodeImpl::Id id ) const;
- const AtomicString& getAttribute(const DOMString& localName) const { return getAttributeNS(QString::null, localName); }
- const AtomicString& getAttributeNS(const DOMString &namespaceURI,
- const DOMString &localName) const;
- void setAttribute( NodeImpl::Id id, DOMStringImpl* value, int &exceptioncode );
- void removeAttribute( NodeImpl::Id id, int &exceptioncode );
+ const AtomicString& getAttribute(Id id ) const;
+ void setAttribute( Id id, DOMStringImpl* value, int &exceptioncode );
+ void removeAttribute( Id id, int &exceptioncode );
+
bool hasAttributes() const;
+
+ bool hasAttribute(const DOMString &name) const { return hasAttributeNS(DOMString(), name); }
+ bool hasAttributeNS(const DOMString &namespaceURI, const DOMString &localName) const;
+
+ const AtomicString& getAttribute(const DOMString& name) const { return getAttributeNS(DOMString(), name); }
+ const AtomicString& getAttributeNS(const DOMString &namespaceURI, const DOMString &localName) const;
+
+ void setAttribute(const DOMString &name, const DOMString &value, int &exception) { setAttributeNS(DOMString(), name, value, exception); }
+ void setAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, const DOMString &value, int &exception);
+
+ void removeAttribute(const DOMString &name, int &exception) { removeAttributeNS(DOMString(), name, exception); }
+ void removeAttributeNS(const DOMString &namespaceURI, const DOMString &localName, int &exception);
+
+ AttrImpl *getAttributeNode(const DOMString &name) { return getAttributeNodeNS(DOMString(), name); }
+ AttrImpl *getAttributeNodeNS(const DOMString &namespaceURI, const DOMString &localName);
+ SharedPtr<AttrImpl> setAttributeNode(AttrImpl *newAttr, int &exception);
+ SharedPtr<AttrImpl> setAttributeNodeNS(AttrImpl *newAttr, int &exception) { return setAttributeNode(newAttr, exception); }
+ SharedPtr<AttrImpl> removeAttributeNode(AttrImpl *oldAttr, int &exception);
DOMString prefix() const { return m_prefix; }
void setPrefix(const DOMString &_prefix, int &exceptioncode );
+ virtual CSSStyleDeclarationImpl *style();
+
// DOM methods overridden from parent classes
virtual DOMString tagName() const;
virtual unsigned short nodeType() const;
virtual void removedFromDocument();
// convenience methods which ignore exceptions
- void setAttribute (NodeImpl::Id id, const DOMString &value);
+ void setAttribute(Id id, const DOMString &value);
- NamedAttrMapImpl* attributes(bool readonly = false) const;
+ virtual NamedAttrMapImpl *attributes() const;
+ NamedAttrMapImpl* attributes(bool readonly) const;
// This method is called whenever an attribute is added, changed or removed.
virtual void attributeChanged(AttributeImpl* attr, bool preserveDecls = false) {}
virtual bool childAllowed( NodeImpl *newChild );
virtual bool childTypeAllowed( unsigned short type );
- virtual AttributeImpl* createAttribute(NodeImpl::Id id, DOMStringImpl* value);
+ virtual AttributeImpl* createAttribute(Id id, DOMStringImpl* value);
void dispatchAttrRemovalEvent(AttributeImpl *attr);
void dispatchAttrAdditionEvent(AttributeImpl *attr);
virtual void dump(QTextStream *stream, QString ind = "") const;
#endif
-#if APPLE_CHANGES
- static Element createInstance(ElementImpl *impl);
-#endif
-
#ifndef NDEBUG
virtual void formatForDebugger(char *buffer, unsigned length) const;
#endif
// DOM methods & attributes for NamedNodeMap
virtual AttrImpl *getNamedItem ( NodeImpl::Id id ) const;
- virtual Node removeNamedItem ( NodeImpl::Id id, int &exceptioncode );
- virtual Node setNamedItem ( NodeImpl* arg, int &exceptioncode );
-
+ virtual SharedPtr<NodeImpl> removeNamedItem ( NodeImpl::Id id, int &exceptioncode );
+ virtual SharedPtr<NodeImpl> setNamedItem ( NodeImpl* arg, int &exceptioncode );
virtual AttrImpl *item ( unsigned long index ) const;
unsigned long length() const { return len; }
#include "xml/dom_nodeimpl.h"
#include "dom/dom_exception.h"
+#include "dom/dom2_events.h"
#include "misc/htmlattrs.h"
#include "misc/htmltags.h"
#include "xml/dom_elementimpl.h"
QPtrListIterator<RegisteredEventListener> it(listenersCopy);
Event ev = evt;
for (; it.current(); ++it) {
- if (it.current()->id == evt->id() && it.current()->useCapture == useCapture)
+ if (it.current()->id == evt->id() && it.current()->useCapture == useCapture) {
it.current()->listener->handleEvent(ev, false);
+ }
}
}
bool NodeImpl::isAncestor(const NodeImpl *other) const
{
// Return true if other is an ancestor of this, otherwise false
+ if (!other)
+ return false;
for (const NodeImpl *n = parentNode(); n; n = n->parentNode()) {
if (n == other)
return true;
return n ? enclosingBlockFlowElement() == n->enclosingBlockFlowElement() : false;
}
+void NodeImpl::addEventListener(const DOMString &type, EventListener *listener, bool useCapture)
+{
+ addEventListener(EventImpl::typeToId(type), listener, useCapture);
+}
+
+void NodeImpl::removeEventListener(const DOMString &type, EventListener *listener, bool useCapture)
+{
+ removeEventListener(EventImpl::typeToId(type), listener, useCapture);
+}
+
+SharedPtr<NodeListImpl> NodeImpl::getElementsByTagNameNS ( const DOMString &namespaceURI, const DOMString &localName )
+{
+ if (localName.isNull())
+ return SharedPtr<NodeListImpl>();
+
+ Id idMask = namespaceMask | localNameMask;
+ if (localName[0] == '*')
+ idMask &= ~localNameMask;
+ if (namespaceURI.isNull() || namespaceURI[0] == '*')
+ idMask &= ~namespaceMask;
+
+ Id id = 0; // 0 means "all items"
+ if ((idMask & localNameMask) || !namespaceURI.isNull()) { // not getElementsByTagName("*")
+ id = getDocument()->tagId(namespaceURI.implementation(), localName.implementation(), true);
+ if ( !id ) // not found -> we want to return an empty list, not "all items"
+ id = (Id)-1; // HACK. HEAD has a cleaner implementation of TagNodeListImpl it seems.
+ }
+
+ return SharedPtr<NodeListImpl>(new TagNodeListImpl(this, id, idMask));
+}
+
+bool NodeImpl::isSupported(const DOMString &feature, const DOMString &version)
+{
+ return DOMImplementationImpl::instance()->hasFeature(feature, version);
+}
+
+DocumentImpl *NodeImpl::ownerDocument() const
+{
+ DocumentImpl *doc = getDocument();
+ return doc == this ? 0 : doc;
+}
+
+bool NodeImpl::hasAttributes() const
+{
+ return false;
+}
+
+NamedAttrMapImpl *NodeImpl::attributes() const
+{
+ return 0;
+}
+
#if APPLE_CHANGES
NodeImpl::Id NodeImpl::identifier() const
{
void ContainerNodeImpl::removeChildren()
{
+ if (!_first)
+ return;
+
int exceptionCode;
while (NodeImpl *n = _first) {
NodeImpl *next = n->nextSibling();
}
}
-NodeListImpl* ContainerNodeImpl::getElementsByTagNameNS ( DOMStringImpl* namespaceURI,
- DOMStringImpl* localName )
-{
- if (!localName) return 0;
-
- NodeImpl::Id idMask = namespaceMask | localNameMask;
- if (localName->l && localName->s[0] == '*')
- idMask &= ~localNameMask;
- if (!namespaceURI || (namespaceURI->l && namespaceURI->s[0] == '*'))
- idMask &= ~namespaceMask;
-
- Id id = 0; // 0 means "all items"
- if ( (idMask & localNameMask) || namespaceURI ) // not getElementsByTagName("*")
- {
- id = getDocument()->tagId( namespaceURI, localName, true);
- if ( !id ) // not found -> we want to return an empty list, not "all items"
- id = (Id)-1; // HACK. HEAD has a cleaner implementation of TagNodeListImpl it seems.
- }
-
- return new TagNodeListImpl( this, id, idMask );
-}
-
// I don't like this way of implementing the method, but I didn't find any
// other way. Lars
bool ContainerNodeImpl::getUpperLeftCorner(int &xPos, int &yPos) const
// ---------------------------------------------------------------------------
-NamedNodeMapImpl::NamedNodeMapImpl()
+NamedNodeMapImpl::~NamedNodeMapImpl()
{
}
-NamedNodeMapImpl::~NamedNodeMapImpl()
+NodeImpl *NamedNodeMapImpl::getNamedItemNS(const DOMString &namespaceURI, const DOMString &localName) const
+{
+ return getNamedItem(const_cast<NamedNodeMapImpl *>(this)->mapId(namespaceURI, localName, true));
+}
+
+SharedPtr<NodeImpl> NamedNodeMapImpl::removeNamedItemNS(const DOMString &namespaceURI, const DOMString &localName, int &exception)
{
+ return removeNamedItem(mapId(namespaceURI, localName, true), exception);
}
// ----------------------------------------------------------------------------
#ifndef _DOM_NodeImpl_h_
#define _DOM_NodeImpl_h_
-#include "dom/dom_misc.h"
#include "dom/dom_string.h"
#include "dom/dom_node.h"
#include "misc/main_thread_malloc.h"
namespace DOM {
+using khtml::SharedPtr;
+
class DocumentImpl;
class ElementImpl;
class EventImpl;
+class EventListener;
class NodeListImpl;
+class NamedAttrMapImpl;
class RegisteredEventListener;
// The namespace used for XHTML elements
virtual NodeListImpl *childNodes();
virtual NodeImpl *firstChild() const;
virtual NodeImpl *lastChild() const;
+ virtual bool hasAttributes() const;
+ virtual NamedAttrMapImpl *attributes() const;
+ virtual DocumentImpl *ownerDocument() const;
virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode );
virtual NodeImpl *replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode );
virtual NodeImpl *removeChild ( NodeImpl *oldChild, int &exceptioncode );
virtual DOMString prefix() const;
virtual void setPrefix(const DOMString &_prefix, int &exceptioncode );
void normalize ();
+ static bool isSupported(const DOMString &feature, const DOMString &version);
NodeImpl *lastDescendent() const;
{
button = _button; type = _type;
url = _url; target = _target;
- innerNode = _innerNode;
+ innerNode.reset(_innerNode);
}
int button;
MouseEventType type;
DOMString url; // url under mouse or empty
DOMString target;
- Node innerNode;
+ SharedPtr<NodeImpl> innerNode;
};
// for LINK and STYLE
void setDocument(DocumentPtr *doc);
- void addEventListener(int id, EventListener *listener, const bool useCapture);
+ void addEventListener(const DOMString &, EventListener *listener, bool useCapture);
+ void removeEventListener(const DOMString &, EventListener *listener, bool useCapture);
+
+ void addEventListener(int id, EventListener *listener, bool useCapture);
void removeEventListener(int id, EventListener *listener, bool useCapture);
void removeHTMLEventListener(int id);
void setHTMLEventListener(int id, EventListener *listener);
void notifyNodeListsSubtreeModified();
void notifyLocalNodeListsSubtreeModified();
+ SharedPtr<NodeListImpl> getElementsByTagName(const DOMString &name) { return getElementsByTagNameNS(DOMString(), name); }
+ SharedPtr<NodeListImpl> getElementsByTagNameNS(const DOMString &namespaceURI, const DOMString &localName);
+
private: // members
DocumentPtr *document;
NodeImpl *m_previous;
virtual void attach();
virtual void detach();
- virtual NodeListImpl *getElementsByTagNameNS ( DOMStringImpl* namespaceURI,
- DOMStringImpl* localName );
-
virtual QRect getRect() const;
bool getUpperLeftCorner(int &xPos, int &yPos) const;
bool getLowerRightCorner(int &xPos, int &yPos) const;
void rootNodeSubtreeModified();
-#if APPLE_CHANGES
- static NodeList createInstance(NodeListImpl *impl);
-#endif
protected:
// helper functions for searching all ElementImpls in a tree
unsigned long recursiveLength(NodeImpl *start = 0) const;
class NamedNodeMapImpl : public khtml::Shared<NamedNodeMapImpl>
{
public:
- NamedNodeMapImpl();
+ NamedNodeMapImpl() { }
virtual ~NamedNodeMapImpl();
MAIN_THREAD_ALLOCATED;
+ NodeImpl *getNamedItem(const DOMString &name) const { return getNamedItemNS(DOMString(), name); }
+ SharedPtr<NodeImpl> removeNamedItem(const DOMString &name, int &exception) { return removeNamedItemNS(DOMString(), name, exception); }
+
+ NodeImpl *getNamedItemNS(const DOMString &namespaceURI, const DOMString &localName) const;
+ SharedPtr<NodeImpl> setNamedItemNS(NodeImpl *arg, int &exception) { return setNamedItem(arg, exception); }
+ SharedPtr<NodeImpl> removeNamedItemNS(const DOMString &namespaceURI, const DOMString &localName, int &exception);
+
// DOM methods & attributes for NamedNodeMap
virtual NodeImpl *getNamedItem ( NodeImpl::Id id ) const = 0;
- virtual Node removeNamedItem ( NodeImpl::Id id, int &exceptioncode ) = 0;
- virtual Node setNamedItem ( NodeImpl* arg, int &exceptioncode ) = 0;
+ virtual SharedPtr<NodeImpl> removeNamedItem ( NodeImpl::Id id, int &exceptioncode ) = 0;
+ virtual SharedPtr<NodeImpl> setNamedItem ( NodeImpl* arg, int &exceptioncode ) = 0;
virtual NodeImpl *item ( unsigned long index ) const = 0;
virtual unsigned long length( ) const = 0;
// Other methods (not part of DOM)
virtual NodeImpl::Id mapId(const DOMString& namespaceURI, const DOMString& localName, bool readonly) = 0;
virtual bool isReadOnly() { return false; }
-
-#if APPLE_CHANGES
- static NamedNodeMap createInstance(NamedNodeMapImpl *impl);
-#endif
};
virtual void dump(QTextStream *stream, QString ind = "") const;
#endif
-#if APPLE_CHANGES
- static CharacterData createInstance(CharacterDataImpl *impl);
-#endif
-
protected:
// note: since DOMStrings are shared, str should always be copied when making
// a change or returning a string
virtual DOMString toString() const;
-#if APPLE_CHANGES
- static Text createInstance(TextImpl *impl);
-#endif
-
#ifndef NDEBUG
virtual void formatForDebugger(char *buffer, unsigned length) const;
#endif
virtual DOMString toString() const;
-#if APPLE_CHANGES
- static ProcessingInstruction createInstance(ProcessingInstructionImpl *impl);
-#endif
-
protected:
DOMStringImpl *m_target;
DOMStringImpl *m_data;
#import "KWQFoundationExtras.h"
#import "KWQKHTMLPart.h"
+// Temporary: Remove when the real FilterNode is checked in.
+namespace DOM {
+ typedef const Node &FilterNode;
+}
+
using DOM::Attr;
using DOM::AttrImpl;
using DOM::CharacterDataImpl;
using DOM::Element;
using DOM::ElementImpl;
using DOM::EntityImpl;
+using DOM::FilterNode;
using DOM::HTMLElementImpl;
using DOM::NamedNodeMap;
using DOM::NamedNodeMapImpl;
using DOM::TreeWalkerImpl;
using khtml::RenderObject;
+using khtml::SharedPtr;
@interface DOMAttr (WebCoreInternal)
+ (DOMAttr *)_attrWithImpl:(AttrImpl *)impl;
- (AttrImpl *)_attrImpl;
@end
+@interface DOMDocumentType (WebCoreInternal)
+- (DOM::DocumentTypeImpl *)_documentTypeImpl;
+@end
+
@interface DOMImplementation (WebCoreInternal)
+ (DOMImplementation *)_DOMImplementationWithImpl:(DOMImplementationImpl *)impl;
- (DOMImplementationImpl *)_DOMImplementationImpl;
+ (DOMNamedNodeMap *)_namedNodeMapWithImpl:(NamedNodeMapImpl *)impl;
@end
-//------------------------------------------------------------------------------------------
-// Factory methods
-
-inline NamedNodeMap NamedNodeMapImpl::createInstance(NamedNodeMapImpl *impl)
-{
- return NamedNodeMap(impl);
-}
-
-inline Attr AttrImpl::createInstance(AttrImpl *impl)
-{
- return Attr(impl);
-}
-
-inline Element ElementImpl::createInstance(ElementImpl *impl)
-{
- return Element(impl);
-}
-
-inline DocumentType DocumentTypeImpl::createInstance(DocumentTypeImpl *impl)
-{
- return DocumentType(impl);
-}
-
-inline Document DocumentImpl::createInstance(DocumentImpl *impl)
-{
- return Document(impl);
-}
-
//------------------------------------------------------------------------------------------
// DOMObject
ASSERT(feature);
ASSERT(version);
- // Method not reflected in DOM::NodeImpl interface
- return Node([self _nodeImpl]).isSupported(feature, version);
+ return [self _nodeImpl]->isSupported(feature, version);
}
- (NSString *)namespaceURI
{
- // Method not reflected in DOM::NodeImpl interface
- return Node([self _nodeImpl]).namespaceURI();
+ return [self _nodeImpl]->namespaceURI();
}
- (NSString *)prefix
- (BOOL)hasAttributes
{
- // Method not reflected in DOM::NodeImpl interface
- return Node([self _nodeImpl]).hasAttributes();
+ return [self _nodeImpl]->hasAttributes();
}
- (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
{
ASSERT(name);
- // Method not reflected in DOM::NamedNodeMapImpl interface
- NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
- Node result(map.getNamedItem(name));
- return [DOMNode _nodeWithImpl:result.handle()];
+ return [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->getNamedItem(name)];
}
- (DOMNode *)setNamedItem:(DOMNode *)arg
{
ASSERT(arg);
- // Method not reflected in DOM::NamedNodeMapImpl interface
- try {
- NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
- Node result(map.setNamedItem([arg _nodeImpl]));
- return [DOMNode _nodeWithImpl:result.handle()];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMNode *result = [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->setNamedItem([arg _nodeImpl], exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMNode *)removeNamedItem:(NSString *)name
{
ASSERT(name);
- // Method not reflected in DOM::NamedNodeMapImpl interface
- try {
- NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
- Node result(map.removeNamedItem(name));
- return [DOMNode _nodeWithImpl:result.handle()];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMNode *result = [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->removeNamedItem(name, exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMNode *)item:(unsigned long)index
return nil;
}
- // Method not reflected in DOM::NamedNodeMapImpl interface
- NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
- Node result(map.getNamedItemNS(namespaceURI, localName));
- return [DOMNode _nodeWithImpl:result.handle()];
+ return [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->getNamedItemNS(namespaceURI, localName)];
}
- (DOMNode *)setNamedItemNS:(DOMNode *)arg
{
ASSERT(arg);
- // Method not reflected in DOM::NamedNodeMapImpl interface
- try {
- NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
- Node result(map.setNamedItemNS([arg _nodeImpl]));
- return [DOMNode _nodeWithImpl:result.handle()];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMNode *result = [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->setNamedItemNS([arg _nodeImpl], exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMNode *)removeNamedItemNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- // Method not reflected in DOM::NamedNodeMapImpl interface
- try {
- NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
- Node result(map.removeNamedItemNS(namespaceURI, localName));
- return [DOMNode _nodeWithImpl:result.handle()];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMNode *result = [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->removeNamedItemNS(namespaceURI, localName, exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
@end
ASSERT(qualifiedName);
int exceptionCode = 0;
- DocumentType dt = DocumentTypeImpl::createInstance(static_cast<DocumentTypeImpl *>([doctype _nodeImpl]));
- DocumentImpl *impl = [self _DOMImplementationImpl]->createDocument(namespaceURI, qualifiedName, dt, exceptionCode);
+ DocumentImpl *impl = [self _DOMImplementationImpl]->createDocument(namespaceURI, qualifiedName, [doctype _documentTypeImpl], exceptionCode);
raiseOnDOMError(exceptionCode);
return static_cast<DOMDocument *>([DOMNode _nodeWithImpl:impl]);
}
ASSERT(media);
int exceptionCode = 0;
- DOMString titleString(title);
- DOMString mediaString(media);
- DOMCSSStyleSheet *result = [DOMCSSStyleSheet _CSSStyleSheetWithImpl:[self _DOMImplementationImpl]->createCSSStyleSheet(titleString.implementation(), mediaString.implementation(), exceptionCode)];
+ DOMCSSStyleSheet *result = [DOMCSSStyleSheet _CSSStyleSheetWithImpl:[self _DOMImplementationImpl]->createCSSStyleSheet(title, media, exceptionCode)];
raiseOnDOMError(exceptionCode);
return result;
}
{
ASSERT(name);
- // Method not reflected in DOM::DocumentImpl interface
- try {
- Document doc(DocumentImpl::createInstance([self _documentImpl]));
- Attr result(doc.createAttribute(name));
- return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:result.handle()]);
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMAttr *result = [DOMAttr _attrWithImpl:[self _documentImpl]->createAttribute(name, exception)];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMEntityReference *)createEntityReference:(NSString *)name
- (DOMNodeList *)getElementsByTagName:(NSString *)tagname
{
ASSERT(tagname);
- return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(0, DOMString(tagname).implementation())];
+ return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagName(tagname).get()];
}
- (DOMNode *)importNode:(DOMNode *)importedNode :(BOOL)deep
ASSERT(namespaceURI);
ASSERT(qualifiedName);
- // Method not reflected in DOM::DocumentImpl interface
- try {
- Document doc(DocumentImpl::createInstance([self _documentImpl]));
- Attr result(doc.createAttributeNS(namespaceURI, qualifiedName));
- return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:result.handle()]);
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMAttr *result = [DOMAttr _attrWithImpl:[self _documentImpl]->createAttributeNS(namespaceURI, qualifiedName, exception)];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(DOMString(namespaceURI).implementation(), DOMString(localName).implementation())];
+ return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(namespaceURI, localName).get()];
}
- (DOMElement *)getElementById:(NSString *)elementId
ASSERT(name);
ASSERT(value);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- element.setAttribute(name, value);
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- }
+ int exception = 0;
+ [self _elementImpl]->setAttribute(name, value, exception);
+ raiseOnDOMError(exception);
}
- (void)removeAttribute:(NSString *)name
{
ASSERT(name);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- element.removeAttribute(name);
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- }
+ int exception = 0;
+ [self _elementImpl]->removeAttribute(name, exception);
+ raiseOnDOMError(exception);
}
- (DOMAttr *)getAttributeNode:(NSString *)name
{
ASSERT(name);
- // Method not reflected in DOM::ElementImpl interface
- Element element(ElementImpl::createInstance([self _elementImpl]));
- Attr result(element.getAttributeNode(name));
- return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
+ return [DOMAttr _attrWithImpl:[self _elementImpl]->getAttributeNode(name)];
}
- (DOMAttr *)setAttributeNode:(DOMAttr *)newAttr
{
ASSERT(newAttr);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- Attr attr(AttrImpl::createInstance([newAttr _attrImpl]));
- Attr result(element.setAttributeNode(attr));
- return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMAttr *result = [DOMAttr _attrWithImpl:[self _elementImpl]->setAttributeNode([newAttr _attrImpl], exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMAttr *)removeAttributeNode:(DOMAttr *)oldAttr
{
ASSERT(oldAttr);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- Attr attr(AttrImpl::createInstance([oldAttr _attrImpl]));
- Attr result(element.removeAttributeNode(attr));
- return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMAttr *result = [DOMAttr _attrWithImpl:[self _elementImpl]->removeAttributeNode([oldAttr _attrImpl], exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMNodeList *)getElementsByTagName:(NSString *)name
{
ASSERT(name);
- return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(0, DOMString(name).implementation())];
+ return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagName(name).get()];
}
- (NSString *)getAttributeNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- Element element(ElementImpl::createInstance([self _elementImpl]));
- return element.getAttributeNS(namespaceURI, localName);
+ return [self _elementImpl]->getAttributeNS(namespaceURI, localName);
}
- (void)setAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName :(NSString *)value
ASSERT(qualifiedName);
ASSERT(value);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- element.setAttributeNS(namespaceURI, qualifiedName, value);
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- }
+ int exception = 0;
+ [self _elementImpl]->setAttributeNS(namespaceURI, qualifiedName, value, exception);
+ raiseOnDOMError(exception);
}
- (void)removeAttributeNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- element.removeAttributeNS(namespaceURI, localName);
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- }
+ int exception = 0;
+ [self _elementImpl]->removeAttributeNS(namespaceURI, localName, exception);
+ raiseOnDOMError(exception);
}
- (DOMAttr *)getAttributeNodeNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- // Method not reflected in DOM::ElementImpl interface
- Element element(ElementImpl::createInstance([self _elementImpl]));
- Attr result(element.getAttributeNodeNS(namespaceURI, localName));
- return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
+ return [DOMAttr _attrWithImpl:[self _elementImpl]->getAttributeNodeNS(namespaceURI, localName)];
}
- (DOMAttr *)setAttributeNodeNS:(DOMAttr *)newAttr
{
ASSERT(newAttr);
- // Method not reflected in DOM::ElementImpl interface
- try {
- Element element(ElementImpl::createInstance([self _elementImpl]));
- Attr attr(AttrImpl::createInstance([newAttr _attrImpl]));
- Attr result(element.setAttributeNodeNS(attr));
- return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
- }
- catch (const DOM::DOMException &e) {
- raiseOnDOMError(e.code);
- return nil;
- }
+ int exception = 0;
+ DOMAttr *result = [DOMAttr _attrWithImpl:[self _elementImpl]->setAttributeNodeNS([newAttr _attrImpl], exception).get()];
+ raiseOnDOMError(exception);
+ return result;
}
- (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(DOMString(namespaceURI).implementation(), DOMString(localName).implementation())];
+ return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(namespaceURI, localName).get()];
}
- (BOOL)hasAttribute:(NSString *)name
{
ASSERT(name);
- // Method not reflected in DOM::ElementImpl interface
- Element element(ElementImpl::createInstance([self _elementImpl]));
- return element.hasAttribute(name);
+ return [self _elementImpl]->hasAttribute(name);
}
- (BOOL)hasAttributeNS:(NSString *)namespaceURI :(NSString *)localName
ASSERT(namespaceURI);
ASSERT(localName);
- // Method not reflected in DOM::ElementImpl interface
- Element element(ElementImpl::createInstance([self _elementImpl]));
- return element.hasAttributeNS(namespaceURI, localName);
+ return [self _elementImpl]->hasAttributeNS(namespaceURI, localName);
}
@end
- (DOMCSSStyleDeclaration *)style
{
- ElementImpl *impl = [self _elementImpl];
- if (impl->isHTMLElement())
- return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:static_cast<HTMLElementImpl *>(impl)->getInlineStyleDecl()];
- return nil;
+ return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:[self _elementImpl]->style()];
}
@end
@implementation DOMDocumentType
-- (DocumentTypeImpl *)_documentTypeImpl
-{
- return static_cast<DocumentTypeImpl *>(DOM_cast<NodeImpl *>(_internal));
-}
-
- (NSString *)name
{
return [self _documentTypeImpl]->publicId();
@end
+@implementation DOMDocumentType (WebCoreInternal)
+
+- (DocumentTypeImpl *)_documentTypeImpl
+{
+ return static_cast<DocumentTypeImpl *>(DOM_cast<NodeImpl *>(_internal));
+}
+
+@end
+
//------------------------------------------------------------------------------------------
// DOMNotation
public:
ObjCNodeFilterCondition(id <DOMNodeFilter>);
virtual ~ObjCNodeFilterCondition();
- virtual short acceptNode(const Node &) const;
+ virtual short acceptNode(FilterNode) const;
private:
ObjCNodeFilterCondition(const ObjCNodeFilterCondition &);
CFRelease(m_filter);
}
-short ObjCNodeFilterCondition::acceptNode(const Node &n) const
+short ObjCNodeFilterCondition::acceptNode(FilterNode n) const
{
if (n.isNull())
return NodeFilter::FILTER_REJECT;
#import "dom_docimpl.h"
#import "dom2_eventsimpl.h"
-#import "dom2_views.h"
#import "dom2_viewsimpl.h"
using DOM::EventImpl;
- (DOMNode *)relatedNode
{
- return [DOMNode _nodeWithImpl:[self _mutationEventImpl]->relatedNode().handle()];
+ return [DOMNode _nodeWithImpl:[self _mutationEventImpl]->relatedNode()];
}
- (NSString *)prevValue
#ifndef KWQCLIPBOARD_H_
#define KWQCLIPBOARD_H_
+#include "KWQPixmap.h"
#include "xml/dom2_eventsimpl.h"
#ifdef __OBJC__
QPoint dragLocation() const; // same point as client passed us
QPixmap dragImage() const;
void setDragImage(const QPixmap &, const QPoint &);
- const DOM::Node dragImageElement();
- void setDragImageElement(const DOM::Node &, const QPoint &);
+ DOM::NodeImpl *dragImageElement();
+ void setDragImageElement(DOM::NodeImpl *, const QPoint &);
// Methods for getting info in Cocoa's type system
NSImage *dragNSImage(NSPoint *loc); // loc converted from dragLoc, based on whole image size
void setDragHasStarted() { m_dragStarted = true; }
private:
- void setDragImage(const QPixmap &pm, const DOM::Node &, const QPoint &loc);
+ void setDragImage(const QPixmap &pm, DOM::NodeImpl *, const QPoint &loc);
NSPasteboard *m_pasteboard;
bool m_forDragging;
DOM::DOMString m_effectAllowed;
QPoint m_dragLoc;
QPixmap m_dragImage;
- DOM::Node m_dragImageElement;
+ khtml::SharedPtr<DOM::NodeImpl> m_dragImageElement;
AccessPolicy m_policy;
int m_changeCount;
bool m_dragStarted;
KWQKHTMLPart *m_part; // used on the source side to generate dragging images
};
-
#endif
#import <AppKit/AppKit.h>
using DOM::DOMString;
+using DOM::NodeImpl;
KWQClipboard::KWQClipboard(bool forDragging, NSPasteboard *pasteboard, AccessPolicy policy, KWQKHTMLPart *part)
: m_pasteboard(KWQRetain(pasteboard)), m_forDragging(forDragging),
- m_dragImageElement(0), m_policy(policy), m_dragStarted(false), m_part(part)
+ m_policy(policy), m_dragStarted(false), m_part(part)
{
m_changeCount = [m_pasteboard changeCount];
}
void KWQClipboard::setDragImage(const QPixmap &pm, const QPoint &loc)
{
- setDragImage(pm, DOM::Node(0), loc);
+ setDragImage(pm, 0, loc);
}
-const DOM::Node KWQClipboard::dragImageElement()
+DOM::NodeImpl *KWQClipboard::dragImageElement()
{
- return m_dragImageElement;
+ return m_dragImageElement.get();
}
-void KWQClipboard::setDragImageElement(const DOM::Node &node, const QPoint &loc)
+void KWQClipboard::setDragImageElement(NodeImpl *node, const QPoint &loc)
{
setDragImage(QPixmap(), node, loc);
}
-void KWQClipboard::setDragImage(const QPixmap &pm, const DOM::Node &node, const QPoint &loc)
+void KWQClipboard::setDragImage(const QPixmap &pm, NodeImpl *node, const QPoint &loc)
{
if (m_policy == ImageWritable || m_policy == Writable) {
m_dragImage = pm;
m_dragLoc = loc;
- m_dragImageElement = node;
+ m_dragImageElement.reset(node);
if (m_dragStarted && m_changeCount == [m_pasteboard changeCount]) {
NSPoint cocoaLoc;
if (m_part) {
NSRect imageRect;
NSRect elementRect;
- result = m_part->snapshotDragImage(m_dragImageElement, &imageRect, &elementRect);
+ result = m_part->snapshotDragImage(m_dragImageElement.get(), &imageRect, &elementRect);
if (loc) {
// Client specifies point relative to element, not the whole image, which may include child
// layers spread out all over the place.
if (_dragSrcIsDHTML) {
int srcX, srcY;
_dragSrc.handle()->renderer()->absolutePosition(srcX, srcY);
- _dragClipboard->setDragImageElement(_dragSrc, QPoint(_mouseDownX - srcX, _mouseDownY - srcY));
+ _dragClipboard->setDragImageElement(_dragSrc.handle(), QPoint(_mouseDownX - srcX, _mouseDownY - srcY));
}
_mouseDownMayStartDrag = dispatchDragSrcEvent(EventImpl::DRAGSTART_EVENT, QPoint(_mouseDownWinX, _mouseDownWinY));
switch ([_currentEvent type]) {
case NSLeftMouseDown: {
- NodeImpl *node = event.innerNode.handle();
+ NodeImpl *node = event.innerNode.get();
if (!node) {
return false;
}
doc->prepareMouseEvent(false, xm, ym, &mev);
bool swallowEvent = v->dispatchMouseEvent(EventImpl::CONTEXTMENU_EVENT,
- mev.innerNode.handle(), true, 0, &qev, true, NodeImpl::MousePress);
+ mev.innerNode.get(), true, 0, &qev, true, NodeImpl::MousePress);
if (!swallowEvent && !isPointInsideSelection(xm, ym) &&
- ([_bridge selectWordBeforeMenuEvent] || [_bridge isEditable] || mev.innerNode.handle()->isContentEditable())) {
- selectClosestWordFromMouseEvent(&qev, mev.innerNode, xm, ym);
+ ([_bridge selectWordBeforeMenuEvent] || [_bridge isEditable] || mev.innerNode->isContentEditable())) {
+ DOM::Node node(mev.innerNode.get());
+ selectClosestWordFromMouseEvent(&qev, node, xm, ym);
}
ASSERT(_currentEvent == event);