2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source exceptionCode must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <objc/objc-class.h>
30 #import <JavaScriptCore/WebScriptObjectPrivate.h>
32 #import "dom2_range.h"
33 #import "dom2_rangeimpl.h"
34 #import "dom2_traversal.h"
35 #import "dom2_viewsimpl.h"
37 #import "dom_docimpl.h"
38 #import "dom_element.h"
39 #import "dom_elementimpl.h"
40 #import "dom_exception.h"
42 #import "dom_nodeimpl.h"
43 #import "dom_string.h"
44 #import "dom_stringimpl.h"
46 #import "dom_textimpl.h"
48 #import "dom_xmlimpl.h"
49 #import "html_elementimpl.h"
52 #import "DOMEventsInternal.h"
54 #import "DOMInternal.h"
55 #import "DOMPrivate.h"
56 #import "KWQAssertions.h"
57 #import "KWQFoundationExtras.h"
61 using DOM::CharacterDataImpl;
62 using DOM::DocumentFragmentImpl;
63 using DOM::DocumentType;
64 using DOM::DocumentTypeImpl;
66 using DOM::DocumentImpl;
67 using DOM::DOMImplementationImpl;
69 using DOM::DOMStringImpl;
71 using DOM::ElementImpl;
72 using DOM::EntityImpl;
73 using DOM::HTMLElementImpl;
74 using DOM::NamedNodeMap;
75 using DOM::NamedNodeMapImpl;
77 using DOM::NodeFilter;
78 using DOM::NodeFilterCondition;
79 using DOM::NodeFilterImpl;
81 using DOM::NodeIteratorImpl;
82 using DOM::NodeListImpl;
83 using DOM::NotationImpl;
84 using DOM::ProcessingInstructionImpl;
86 using DOM::RangeException;
89 using DOM::TreeWalkerImpl;
91 @interface DOMAttr (WebCoreInternal)
92 + (DOMAttr *)_attrWithImpl:(AttrImpl *)impl;
93 - (AttrImpl *)_attrImpl;
96 @interface DOMImplementation (WebCoreInternal)
97 + (DOMImplementation *)_DOMImplementationWithImpl:(DOMImplementationImpl *)impl;
98 - (DOMImplementationImpl *)_DOMImplementationImpl;
101 @interface DOMNamedNodeMap (WebCoreInternal)
102 + (DOMNamedNodeMap *)_namedNodeMapWithImpl:(NamedNodeMapImpl *)impl;
105 //------------------------------------------------------------------------------------------
108 inline NamedNodeMap NamedNodeMapImpl::createInstance(NamedNodeMapImpl *impl)
110 return NamedNodeMap(impl);
113 inline Attr AttrImpl::createInstance(AttrImpl *impl)
118 inline Element ElementImpl::createInstance(ElementImpl *impl)
120 return Element(impl);
123 inline DocumentType DocumentTypeImpl::createInstance(DocumentTypeImpl *impl)
125 return DocumentType(impl);
128 inline Document DocumentImpl::createInstance(DocumentImpl *impl)
130 return Document(impl);
133 //------------------------------------------------------------------------------------------
136 @implementation DOMObject
138 // Prevent creation of DOM objects by clients who just "[[xxx alloc] init]".
141 [NSException raise:NSGenericException format:@"+[%s init]: should never be used", [self class]->name];
149 removeDOMWrapper(_internal);
157 removeDOMWrapper(_internal);
162 - (id)copyWithZone:(NSZone *)zone
164 return [self retain];
169 @implementation DOMObject (WebCoreInternal)
173 return [super _init];
178 //------------------------------------------------------------------------------------------
181 @implementation DOMNode
186 DOM_cast<NodeImpl *>(_internal)->deref();
194 DOM_cast<NodeImpl *>(_internal)->deref();
199 - (NSString *)nodeName
201 return [self _nodeImpl]->nodeName();
204 - (NSString *)nodeValue
206 // Documentation says we can raise a DOMSTRING_SIZE_ERR.
207 // However, the lower layer does not report that error up to us.
208 return [self _nodeImpl]->nodeValue();
211 - (void)setNodeValue:(NSString *)string
215 int exceptionCode = 0;
216 [self _nodeImpl]->setNodeValue(string, exceptionCode);
217 raiseOnDOMError(exceptionCode);
220 - (unsigned short)nodeType
222 return [self _nodeImpl]->nodeType();
225 - (DOMNode *)parentNode
227 return [DOMNode _nodeWithImpl:[self _nodeImpl]->parentNode()];
230 - (DOMNodeList *)childNodes
232 return [DOMNodeList _nodeListWithImpl:[self _nodeImpl]->childNodes()];
235 - (DOMNode *)firstChild
237 return [DOMNode _nodeWithImpl:[self _nodeImpl]->firstChild()];
240 - (DOMNode *)lastChild
242 return [DOMNode _nodeWithImpl:[self _nodeImpl]->lastChild()];
245 - (DOMNode *)previousSibling
247 return [DOMNode _nodeWithImpl:[self _nodeImpl]->previousSibling()];
250 - (DOMNode *)nextSibling
252 return [DOMNode _nodeWithImpl:[self _nodeImpl]->nextSibling()];
255 - (DOMNamedNodeMap *)attributes
257 // DOM level 2 core specification says:
258 // A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
262 - (DOMDocument *)ownerDocument
264 return [DOMDocument _documentWithImpl:[self _nodeImpl]->getDocument()];
267 - (DOMNode *)insertBefore:(DOMNode *)newChild :(DOMNode *)refChild
272 int exceptionCode = 0;
273 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->insertBefore([newChild _nodeImpl], [refChild _nodeImpl], exceptionCode)];
274 raiseOnDOMError(exceptionCode);
278 - (DOMNode *)replaceChild:(DOMNode *)newChild :(DOMNode *)oldChild
283 int exceptionCode = 0;
284 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->replaceChild([newChild _nodeImpl], [oldChild _nodeImpl], exceptionCode)];
285 raiseOnDOMError(exceptionCode);
289 - (DOMNode *)removeChild:(DOMNode *)oldChild
293 int exceptionCode = 0;
294 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->removeChild([oldChild _nodeImpl], exceptionCode)];
295 raiseOnDOMError(exceptionCode);
299 - (DOMNode *)appendChild:(DOMNode *)newChild
303 int exceptionCode = 0;
304 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->appendChild([newChild _nodeImpl], exceptionCode)];
305 raiseOnDOMError(exceptionCode);
309 - (BOOL)hasChildNodes
311 return [self _nodeImpl]->hasChildNodes();
314 - (DOMNode *)cloneNode:(BOOL)deep
316 return [DOMNode _nodeWithImpl:[self _nodeImpl]->cloneNode(deep)];
321 [self _nodeImpl]->normalize();
324 - (BOOL)isSupported:(NSString *)feature :(NSString *)version
329 // Method not reflected in DOM::NodeImpl interface
330 return Node([self _nodeImpl]).isSupported(feature, version);
333 - (NSString *)namespaceURI
335 // Method not reflected in DOM::NodeImpl interface
336 return Node([self _nodeImpl]).namespaceURI();
341 return [self _nodeImpl]->prefix();
344 - (void)setPrefix:(NSString *)prefix
348 int exceptionCode = 0;
349 [self _nodeImpl]->setPrefix(prefix, exceptionCode);
350 raiseOnDOMError(exceptionCode);
353 - (NSString *)localName
355 return [self _nodeImpl]->localName();
358 - (BOOL)hasAttributes
360 // Method not reflected in DOM::NodeImpl interface
361 return Node([self _nodeImpl]).hasAttributes();
364 - (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
366 ERROR("unimplemented");
369 - (void)removeEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
371 ERROR("unimplemented");
374 - (BOOL)dispatchEvent:(DOMEvent *)event
376 int exceptionCode = 0;
377 BOOL result = [self _nodeImpl]->dispatchEvent([event _eventImpl], exceptionCode);
378 raiseOnDOMError(exceptionCode);
384 @implementation DOMNode (WebCoreInternal)
386 - (id)_initWithNodeImpl:(NodeImpl *)impl
391 _internal = DOM_cast<DOMObjectInternal *>(impl);
393 addDOMWrapper(self, impl);
397 + (DOMNode *)_nodeWithImpl:(NodeImpl *)impl
403 cachedInstance = getDOMWrapper(impl);
405 return [[cachedInstance retain] autorelease];
407 Class wrapperClass = nil;
408 switch (impl->nodeType()) {
409 case Node::ELEMENT_NODE:
410 if (impl->isHTMLElement()) {
411 // FIXME: There are no identifiers for HTMLHeadingElement, HTMLModElement,
412 // HTMLTableCaptionElement, HTMLTableColElement, HTMLTableSectionElement.
413 // Find other ways to identify them.
414 switch (impl->identifier()) {
416 wrapperClass = [DOMHTMLHtmlElement class];
419 wrapperClass = [DOMHTMLHeadElement class];
422 wrapperClass = [DOMHTMLLinkElement class];
425 wrapperClass = [DOMHTMLTitleElement class];
428 wrapperClass = [DOMHTMLMetaElement class];
431 wrapperClass = [DOMHTMLBaseElement class];
434 wrapperClass = [DOMHTMLIsIndexElement class];
437 wrapperClass = [DOMHTMLStyleElement class];
440 wrapperClass = [DOMHTMLBodyElement class];
443 wrapperClass = [DOMHTMLFormElement class];
446 wrapperClass = [DOMHTMLSelectElement class];
449 wrapperClass = [DOMHTMLOptGroupElement class];
452 wrapperClass = [DOMHTMLOptionElement class];
455 wrapperClass = [DOMHTMLInputElement class];
458 wrapperClass = [DOMHTMLTextAreaElement class];
461 wrapperClass = [DOMHTMLButtonElement class];
464 wrapperClass = [DOMHTMLLabelElement class];
467 wrapperClass = [DOMHTMLFieldSetElement class];
470 wrapperClass = [DOMHTMLLegendElement class];
473 wrapperClass = [DOMHTMLUListElement class];
476 wrapperClass = [DOMHTMLOListElement class];
479 wrapperClass = [DOMHTMLDListElement class];
482 wrapperClass = [DOMHTMLDirectoryElement class];
485 wrapperClass = [DOMHTMLMenuElement class];
488 wrapperClass = [DOMHTMLLIElement class];
491 wrapperClass = [DOMHTMLDivElement class];
494 wrapperClass = [DOMHTMLParagraphElement class];
497 wrapperClass = [DOMHTMLQuoteElement class];
500 wrapperClass = [DOMHTMLPreElement class];
503 wrapperClass = [DOMHTMLBRElement class];
506 wrapperClass = [DOMHTMLFontElement class];
509 wrapperClass = [DOMHTMLFontElement class];
512 wrapperClass = [DOMHTMLHRElement class];
515 wrapperClass = [DOMHTMLAnchorElement class];
518 wrapperClass = [DOMHTMLImageElement class];
521 wrapperClass = [DOMHTMLObjectElement class];
524 wrapperClass = [DOMHTMLParamElement class];
527 wrapperClass = [DOMHTMLAppletElement class];
530 wrapperClass = [DOMHTMLMapElement class];
533 wrapperClass = [DOMHTMLAreaElement class];
536 wrapperClass = [DOMHTMLScriptElement class];
539 wrapperClass = [DOMHTMLTableElement class];
542 wrapperClass = [DOMHTMLTableCellElement class];
545 wrapperClass = [DOMHTMLTableRowElement class];
548 wrapperClass = [DOMHTMLFrameSetElement class];
551 wrapperClass = [DOMHTMLFrameElement class];
554 wrapperClass = [DOMHTMLIFrameElement class];
557 wrapperClass = [DOMHTMLElement class];
560 wrapperClass = [DOMElement class];
563 case Node::ATTRIBUTE_NODE:
564 wrapperClass = [DOMAttr class];
566 case Node::TEXT_NODE:
567 wrapperClass = [DOMText class];
569 case Node::CDATA_SECTION_NODE:
570 wrapperClass = [DOMCDATASection class];
572 case Node::ENTITY_REFERENCE_NODE:
573 wrapperClass = [DOMEntityReference class];
575 case Node::ENTITY_NODE:
576 wrapperClass = [DOMEntity class];
578 case Node::PROCESSING_INSTRUCTION_NODE:
579 wrapperClass = [DOMProcessingInstruction class];
581 case Node::COMMENT_NODE:
582 wrapperClass = [DOMComment class];
584 case Node::DOCUMENT_NODE:
585 if (static_cast<DocumentImpl *>(impl)->isHTMLDocument()) {
586 wrapperClass = [DOMHTMLDocument class];
588 wrapperClass = [DOMDocument class];
591 case Node::DOCUMENT_TYPE_NODE:
592 wrapperClass = [DOMDocumentType class];
594 case Node::DOCUMENT_FRAGMENT_NODE:
595 wrapperClass = [DOMDocumentFragment class];
597 case Node::NOTATION_NODE:
598 wrapperClass = [DOMNotation class];
601 return [[[wrapperClass alloc] _initWithNodeImpl:impl] autorelease];
604 - (NodeImpl *)_nodeImpl
606 return DOM_cast<NodeImpl *>(_internal);
609 - (BOOL)isContentEditable
611 return [self _nodeImpl]->isContentEditable();
616 //------------------------------------------------------------------------------------------
619 @implementation DOMNamedNodeMap
624 DOM_cast<NamedNodeMapImpl *>(_internal)->deref();
632 DOM_cast<NamedNodeMapImpl *>(_internal)->deref();
637 - (NamedNodeMapImpl *)_namedNodeMapImpl
639 return DOM_cast<NamedNodeMapImpl *>(_internal);
642 - (DOMNode *)getNamedItem:(NSString *)name
646 // Method not reflected in DOM::NamedNodeMapImpl interface
647 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
648 Node result(map.getNamedItem(name));
649 return [DOMNode _nodeWithImpl:result.handle()];
652 - (DOMNode *)setNamedItem:(DOMNode *)arg
656 // Method not reflected in DOM::NamedNodeMapImpl interface
658 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
659 Node result(map.setNamedItem([arg _nodeImpl]));
660 return [DOMNode _nodeWithImpl:result.handle()];
662 catch (const DOM::DOMException &e) {
663 raiseOnDOMError(e.code);
668 - (DOMNode *)removeNamedItem:(NSString *)name
672 // Method not reflected in DOM::NamedNodeMapImpl interface
674 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
675 Node result(map.removeNamedItem(name));
676 return [DOMNode _nodeWithImpl:result.handle()];
678 catch (const DOM::DOMException &e) {
679 raiseOnDOMError(e.code);
684 - (DOMNode *)item:(unsigned long)index
686 return [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->item(index)];
689 - (unsigned long)length
691 return [self _namedNodeMapImpl]->length();
694 - (DOMNode *)getNamedItemNS:(NSString *)namespaceURI :(NSString *)localName
696 if (!namespaceURI || !localName) {
700 // Method not reflected in DOM::NamedNodeMapImpl interface
701 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
702 Node result(map.getNamedItemNS(namespaceURI, localName));
703 return [DOMNode _nodeWithImpl:result.handle()];
706 - (DOMNode *)setNamedItemNS:(DOMNode *)arg
710 // Method not reflected in DOM::NamedNodeMapImpl interface
712 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
713 Node result(map.setNamedItemNS([arg _nodeImpl]));
714 return [DOMNode _nodeWithImpl:result.handle()];
716 catch (const DOM::DOMException &e) {
717 raiseOnDOMError(e.code);
722 - (DOMNode *)removeNamedItemNS:(NSString *)namespaceURI :(NSString *)localName
724 ASSERT(namespaceURI);
727 // Method not reflected in DOM::NamedNodeMapImpl interface
729 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
730 Node result(map.removeNamedItemNS(namespaceURI, localName));
731 return [DOMNode _nodeWithImpl:result.handle()];
733 catch (const DOM::DOMException &e) {
734 raiseOnDOMError(e.code);
741 @implementation DOMNamedNodeMap (WebCoreInternal)
743 - (id)_initWithNamedNodeMapImpl:(NamedNodeMapImpl *)impl
748 _internal = DOM_cast<DOMObjectInternal *>(impl);
750 addDOMWrapper(self, impl);
754 + (DOMNamedNodeMap *)_namedNodeMapWithImpl:(NamedNodeMapImpl *)impl
760 cachedInstance = getDOMWrapper(impl);
762 return [[cachedInstance retain] autorelease];
764 return [[[self alloc] _initWithNamedNodeMapImpl:impl] autorelease];
769 //------------------------------------------------------------------------------------------
772 @implementation DOMNodeList
777 DOM_cast<NodeListImpl *>(_internal)->deref();
785 DOM_cast<NodeListImpl *>(_internal)->deref();
790 - (NodeListImpl *)_nodeListImpl
792 return DOM_cast<NodeListImpl *>(_internal);
795 - (DOMNode *)item:(unsigned long)index
797 return [DOMNode _nodeWithImpl:[self _nodeListImpl]->item(index)];
800 - (unsigned long)length
802 return [self _nodeListImpl]->length();
807 @implementation DOMNodeList (WebCoreInternal)
809 - (id)_initWithNodeListImpl:(NodeListImpl *)impl
814 _internal = DOM_cast<DOMObjectInternal *>(impl);
816 addDOMWrapper(self, impl);
820 + (DOMNodeList *)_nodeListWithImpl:(NodeListImpl *)impl
826 cachedInstance = getDOMWrapper(impl);
828 return [[cachedInstance retain] autorelease];
830 return [[[self alloc] _initWithNodeListImpl:impl] autorelease];
835 //------------------------------------------------------------------------------------------
838 @implementation DOMImplementation
843 DOM_cast<DOMImplementationImpl *>(_internal)->deref();
851 DOM_cast<DOMImplementationImpl *>(_internal)->deref();
856 - (BOOL)hasFeature:(NSString *)feature :(NSString *)version
861 return [self _DOMImplementationImpl]->hasFeature(feature, version);
864 - (DOMDocumentType *)createDocumentType:(NSString *)qualifiedName :(NSString *)publicId :(NSString *)systemId
866 ASSERT(qualifiedName);
870 int exceptionCode = 0;
871 DocumentTypeImpl *impl = [self _DOMImplementationImpl]->createDocumentType(qualifiedName, publicId, systemId, exceptionCode);
872 raiseOnDOMError(exceptionCode);
873 return static_cast<DOMDocumentType *>([DOMNode _nodeWithImpl:impl]);
876 - (DOMDocument *)createDocument:(NSString *)namespaceURI :(NSString *)qualifiedName :(DOMDocumentType *)doctype
878 ASSERT(namespaceURI);
879 ASSERT(qualifiedName);
881 int exceptionCode = 0;
882 DocumentType dt = DocumentTypeImpl::createInstance(static_cast<DocumentTypeImpl *>([doctype _nodeImpl]));
883 DocumentImpl *impl = [self _DOMImplementationImpl]->createDocument(namespaceURI, qualifiedName, dt, exceptionCode);
884 raiseOnDOMError(exceptionCode);
885 return static_cast<DOMDocument *>([DOMNode _nodeWithImpl:impl]);
890 @implementation DOMImplementation (DOMImplementationCSS)
892 - (DOMCSSStyleSheet *)createCSSStyleSheet:(NSString *)title :(NSString *)media
897 int exceptionCode = 0;
898 DOMString titleString(title);
899 DOMString mediaString(media);
900 DOMCSSStyleSheet *result = [DOMCSSStyleSheet _CSSStyleSheetWithImpl:[self _DOMImplementationImpl]->createCSSStyleSheet(titleString.implementation(), mediaString.implementation(), exceptionCode)];
901 raiseOnDOMError(exceptionCode);
907 @implementation DOMImplementation (WebCoreInternal)
909 - (id)_initWithDOMImplementationImpl:(DOMImplementationImpl *)impl
914 _internal = DOM_cast<DOMObjectInternal *>(impl);
916 addDOMWrapper(self, impl);
920 + (DOMImplementation *)_DOMImplementationWithImpl:(DOMImplementationImpl *)impl
926 cachedInstance = getDOMWrapper(impl);
928 return [[cachedInstance retain] autorelease];
930 return [[[self alloc] _initWithDOMImplementationImpl:impl] autorelease];
933 - (DOMImplementationImpl *)_DOMImplementationImpl
935 return DOM_cast<DOMImplementationImpl *>(_internal);
940 //------------------------------------------------------------------------------------------
941 // DOMDocumentFragment
943 @implementation DOMDocumentFragment
947 @implementation DOMDocumentFragment (WebCoreInternal)
949 + (DOMDocumentFragment *)_documentFragmentWithImpl:(DocumentFragmentImpl *)impl
951 return static_cast<DOMDocumentFragment *>([DOMNode _nodeWithImpl:impl]);
954 - (DocumentFragmentImpl *)_fragmentImpl
956 return static_cast<DocumentFragmentImpl *>(DOM_cast<NodeImpl *>(_internal));
961 //------------------------------------------------------------------------------------------
964 @implementation DOMDocument
966 - (DOMDocumentType *)doctype
968 return static_cast<DOMDocumentType *>([DOMNode _nodeWithImpl:[self _documentImpl]->doctype()]);
971 - (DOMImplementation *)implementation
973 return [DOMImplementation _DOMImplementationWithImpl:[self _documentImpl]->implementation()];
976 - (DOMElement *)documentElement
978 return static_cast<DOMElement *>([DOMNode _nodeWithImpl:[self _documentImpl]->documentElement()]);
981 - (DOMElement *)createElement:(NSString *)tagName
985 int exceptionCode = 0;
986 DOMElement *result = static_cast<DOMElement *>([DOMNode _nodeWithImpl:[self _documentImpl]->createElement(tagName, exceptionCode)]);
987 raiseOnDOMError(exceptionCode);
991 - (DOMDocumentFragment *)createDocumentFragment
993 return static_cast<DOMDocumentFragment *>([DOMNode _nodeWithImpl:[self _documentImpl]->createDocumentFragment()]);
996 - (DOMText *)createTextNode:(NSString *)data
999 return static_cast<DOMText *>([DOMNode _nodeWithImpl:[self _documentImpl]->createTextNode(data)]);
1002 - (DOMComment *)createComment:(NSString *)data
1005 return static_cast<DOMComment *>([DOMNode _nodeWithImpl:[self _documentImpl]->createComment(data)]);
1008 - (DOMCDATASection *)createCDATASection:(NSString *)data
1012 // Documentation says we can raise a NOT_SUPPORTED_ERR.
1013 // However, the lower layer does not report that error up to us.
1014 return static_cast<DOMCDATASection *>([DOMNode _nodeWithImpl:[self _documentImpl]->createCDATASection(data)]);
1017 - (DOMProcessingInstruction *)createProcessingInstruction:(NSString *)target :(NSString *)data
1022 // Documentation says we can raise a INVALID_CHARACTER_ERR or a NOT_SUPPORTED_ERR.
1023 // However, the lower layer does not report these errors up to us.
1024 return static_cast<DOMProcessingInstruction *>([DOMNode _nodeWithImpl:[self _documentImpl]->createProcessingInstruction(target, data)]);
1027 - (DOMAttr *)createAttribute:(NSString *)name
1031 // Method not reflected in DOM::DocumentImpl interface
1033 Document doc(DocumentImpl::createInstance([self _documentImpl]));
1034 Attr result(doc.createAttribute(name));
1035 return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:result.handle()]);
1037 catch (const DOM::DOMException &e) {
1038 raiseOnDOMError(e.code);
1043 - (DOMEntityReference *)createEntityReference:(NSString *)name
1047 // Documentation says we can raise a INVALID_CHARACTER_ERR or a NOT_SUPPORTED_ERR.
1048 // However, the lower layer does not report these errors up to us.
1049 return static_cast<DOMEntityReference *>([DOMNode _nodeWithImpl:[self _documentImpl]->createEntityReference(name)]);
1052 - (DOMNodeList *)getElementsByTagName:(NSString *)tagname
1055 return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(0, DOMString(tagname).implementation())];
1058 - (DOMNode *)importNode:(DOMNode *)importedNode :(BOOL)deep
1060 int exceptionCode = 0;
1061 DOMNode *result = [DOMNode _nodeWithImpl:[self _documentImpl]->importNode([importedNode _nodeImpl], deep, exceptionCode)];
1062 raiseOnDOMError(exceptionCode);
1066 - (DOMElement *)createElementNS:(NSString *)namespaceURI :(NSString *)qualifiedName
1068 ASSERT(namespaceURI);
1069 ASSERT(qualifiedName);
1071 int exceptionCode = 0;
1072 DOMNode *result = [DOMNode _nodeWithImpl:[self _documentImpl]->createElementNS(namespaceURI, qualifiedName, exceptionCode)];
1073 raiseOnDOMError(exceptionCode);
1074 return static_cast<DOMElement *>(result);
1077 - (DOMAttr *)createAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName
1079 ASSERT(namespaceURI);
1080 ASSERT(qualifiedName);
1082 // Method not reflected in DOM::DocumentImpl interface
1084 Document doc(DocumentImpl::createInstance([self _documentImpl]));
1085 Attr result(doc.createAttributeNS(namespaceURI, qualifiedName));
1086 return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:result.handle()]);
1088 catch (const DOM::DOMException &e) {
1089 raiseOnDOMError(e.code);
1094 - (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName
1096 ASSERT(namespaceURI);
1099 return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(DOMString(namespaceURI).implementation(), DOMString(localName).implementation())];
1102 - (DOMElement *)getElementById:(NSString *)elementId
1106 return static_cast<DOMElement *>([DOMNode _nodeWithImpl:[self _documentImpl]->getElementById(elementId)]);
1111 @implementation DOMDocument (DOMDocumentRange)
1113 - (DOMRange *)createRange
1115 return [DOMRange _rangeWithImpl:[self _documentImpl]->createRange()];
1120 @implementation DOMDocument (DOMDocumentCSS)
1122 - (DOMCSSStyleDeclaration *)getComputedStyle:(DOMElement *)elt :(NSString *)pseudoElt
1124 ElementImpl *elementImpl = [elt _elementImpl];
1125 DOMString pseudoEltString(pseudoElt);
1126 return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:[self _documentImpl]->defaultView()->getComputedStyle(elementImpl, pseudoEltString.implementation())];
1129 - (DOMCSSStyleDeclaration *)getOverrideStyle:(DOMElement *)elt :(NSString *)pseudoElt;
1131 // FIXME: This is unimplemented by khtml,
1132 // so for now, we just return the computed style
1133 return [self getComputedStyle:elt :pseudoElt];
1138 @implementation DOMDocument (DOMDocumentStyle)
1140 - (DOMStyleSheetList *)styleSheets
1142 return [DOMStyleSheetList _styleSheetListWithImpl:[self _documentImpl]->styleSheets()];
1147 @implementation DOMDocument (DOMDocumentExtensions)
1149 - (DOMCSSStyleDeclaration *)createCSSStyleDeclaration;
1151 return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:[self _documentImpl]->createCSSStyleDeclaration()];
1156 @implementation DOMDocument (WebCoreInternal)
1158 + (DOMDocument *)_documentWithImpl:(DocumentImpl *)impl
1160 return static_cast<DOMDocument *>([DOMNode _nodeWithImpl:impl]);
1163 - (DocumentImpl *)_documentImpl
1165 return static_cast<DocumentImpl *>(DOM_cast<NodeImpl *>(_internal));
1168 - (DOMElement *)_ownerElement
1170 ElementImpl *element = [self _documentImpl]->ownerElement();
1171 return element ? [DOMElement _elementWithImpl:element] : nil;
1176 //------------------------------------------------------------------------------------------
1179 @implementation DOMCharacterData
1181 - (CharacterDataImpl *)_characterDataImpl
1183 return static_cast<CharacterDataImpl *>(DOM_cast<NodeImpl *>(_internal));
1188 // Documentation says we can raise a DOMSTRING_SIZE_ERR.
1189 // However, the lower layer does not report that error up to us.
1190 return [self _characterDataImpl]->data();
1193 - (void)setData:(NSString *)data
1197 int exceptionCode = 0;
1198 [self _characterDataImpl]->setData(data, exceptionCode);
1199 raiseOnDOMError(exceptionCode);
1202 - (unsigned long)length
1204 return [self _characterDataImpl]->length();
1207 - (NSString *)substringData:(unsigned long)offset :(unsigned long)count
1209 int exceptionCode = 0;
1210 NSString *result = [self _characterDataImpl]->substringData(offset, count, exceptionCode);
1211 raiseOnDOMError(exceptionCode);
1215 - (void)appendData:(NSString *)arg
1219 int exceptionCode = 0;
1220 [self _characterDataImpl]->appendData(arg, exceptionCode);
1221 raiseOnDOMError(exceptionCode);
1224 - (void)insertData:(unsigned long)offset :(NSString *)arg
1228 int exceptionCode = 0;
1229 [self _characterDataImpl]->insertData(offset, arg, exceptionCode);
1230 raiseOnDOMError(exceptionCode);
1233 - (void)deleteData:(unsigned long)offset :(unsigned long) count;
1235 int exceptionCode = 0;
1236 [self _characterDataImpl]->deleteData(offset, count, exceptionCode);
1237 raiseOnDOMError(exceptionCode);
1240 - (void)replaceData:(unsigned long)offset :(unsigned long)count :(NSString *)arg
1244 int exceptionCode = 0;
1245 [self _characterDataImpl]->replaceData(offset, count, arg, exceptionCode);
1246 raiseOnDOMError(exceptionCode);
1251 //------------------------------------------------------------------------------------------
1254 @implementation DOMAttr
1258 return [self _attrImpl]->nodeName();
1263 return [self _attrImpl]->specified();
1268 return [self _attrImpl]->nodeValue();
1271 - (void)setValue:(NSString *)value
1275 int exceptionCode = 0;
1276 [self _attrImpl]->setValue(value, exceptionCode);
1277 raiseOnDOMError(exceptionCode);
1280 - (DOMElement *)ownerElement
1282 return [DOMElement _elementWithImpl:[self _attrImpl]->ownerElement()];
1287 @implementation DOMAttr (WebCoreInternal)
1289 + (DOMAttr *)_attrWithImpl:(AttrImpl *)impl
1291 return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:impl]);
1294 - (AttrImpl *)_attrImpl
1296 return static_cast<AttrImpl *>(DOM_cast<NodeImpl *>(_internal));
1301 //------------------------------------------------------------------------------------------
1304 @implementation DOMElement
1306 - (NSString *)tagName
1308 return [self _elementImpl]->tagName();
1311 - (DOMNamedNodeMap *)attributes
1313 return [DOMNamedNodeMap _namedNodeMapWithImpl:[self _elementImpl]->attributes()];
1316 - (NSString *)getAttribute:(NSString *)name
1319 return [self _elementImpl]->getAttribute(name);
1322 - (void)setAttribute:(NSString *)name :(NSString *)value
1327 // Method not reflected in DOM::ElementImpl interface
1329 Element element(ElementImpl::createInstance([self _elementImpl]));
1330 element.setAttribute(name, value);
1332 catch (const DOM::DOMException &e) {
1333 raiseOnDOMError(e.code);
1337 - (void)removeAttribute:(NSString *)name
1341 // Method not reflected in DOM::ElementImpl interface
1343 Element element(ElementImpl::createInstance([self _elementImpl]));
1344 element.removeAttribute(name);
1346 catch (const DOM::DOMException &e) {
1347 raiseOnDOMError(e.code);
1351 - (DOMAttr *)getAttributeNode:(NSString *)name
1355 // Method not reflected in DOM::ElementImpl interface
1356 Element element(ElementImpl::createInstance([self _elementImpl]));
1357 Attr result(element.getAttributeNode(name));
1358 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1361 - (DOMAttr *)setAttributeNode:(DOMAttr *)newAttr
1365 // Method not reflected in DOM::ElementImpl interface
1367 Element element(ElementImpl::createInstance([self _elementImpl]));
1368 Attr attr(AttrImpl::createInstance([newAttr _attrImpl]));
1369 Attr result(element.setAttributeNode(attr));
1370 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1372 catch (const DOM::DOMException &e) {
1373 raiseOnDOMError(e.code);
1378 - (DOMAttr *)removeAttributeNode:(DOMAttr *)oldAttr
1382 // Method not reflected in DOM::ElementImpl interface
1384 Element element(ElementImpl::createInstance([self _elementImpl]));
1385 Attr attr(AttrImpl::createInstance([oldAttr _attrImpl]));
1386 Attr result(element.removeAttributeNode(attr));
1387 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1389 catch (const DOM::DOMException &e) {
1390 raiseOnDOMError(e.code);
1395 - (DOMNodeList *)getElementsByTagName:(NSString *)name
1399 return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(0, DOMString(name).implementation())];
1402 - (NSString *)getAttributeNS:(NSString *)namespaceURI :(NSString *)localName
1404 ASSERT(namespaceURI);
1407 Element element(ElementImpl::createInstance([self _elementImpl]));
1408 return element.getAttributeNS(namespaceURI, localName);
1411 - (void)setAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName :(NSString *)value
1413 ASSERT(namespaceURI);
1414 ASSERT(qualifiedName);
1417 // Method not reflected in DOM::ElementImpl interface
1419 Element element(ElementImpl::createInstance([self _elementImpl]));
1420 element.setAttributeNS(namespaceURI, qualifiedName, value);
1422 catch (const DOM::DOMException &e) {
1423 raiseOnDOMError(e.code);
1427 - (void)removeAttributeNS:(NSString *)namespaceURI :(NSString *)localName
1429 ASSERT(namespaceURI);
1432 // Method not reflected in DOM::ElementImpl interface
1434 Element element(ElementImpl::createInstance([self _elementImpl]));
1435 element.removeAttributeNS(namespaceURI, localName);
1437 catch (const DOM::DOMException &e) {
1438 raiseOnDOMError(e.code);
1442 - (DOMAttr *)getAttributeNodeNS:(NSString *)namespaceURI :(NSString *)localName
1444 ASSERT(namespaceURI);
1447 // Method not reflected in DOM::ElementImpl interface
1448 Element element(ElementImpl::createInstance([self _elementImpl]));
1449 Attr result(element.getAttributeNodeNS(namespaceURI, localName));
1450 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1453 - (DOMAttr *)setAttributeNodeNS:(DOMAttr *)newAttr
1457 // Method not reflected in DOM::ElementImpl interface
1459 Element element(ElementImpl::createInstance([self _elementImpl]));
1460 Attr attr(AttrImpl::createInstance([newAttr _attrImpl]));
1461 Attr result(element.setAttributeNodeNS(attr));
1462 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1464 catch (const DOM::DOMException &e) {
1465 raiseOnDOMError(e.code);
1470 - (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName
1472 ASSERT(namespaceURI);
1475 return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(DOMString(namespaceURI).implementation(), DOMString(localName).implementation())];
1478 - (BOOL)hasAttribute:(NSString *)name
1482 // Method not reflected in DOM::ElementImpl interface
1483 Element element(ElementImpl::createInstance([self _elementImpl]));
1484 return element.hasAttribute(name);
1487 - (BOOL)hasAttributeNS:(NSString *)namespaceURI :(NSString *)localName
1489 ASSERT(namespaceURI);
1492 // Method not reflected in DOM::ElementImpl interface
1493 Element element(ElementImpl::createInstance([self _elementImpl]));
1494 return element.hasAttributeNS(namespaceURI, localName);
1499 @implementation DOMElement (DOMElementCSSInlineStyle)
1501 - (DOMCSSStyleDeclaration *)style
1503 ElementImpl *impl = [self _elementImpl];
1504 if (impl->isHTMLElement())
1505 return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:static_cast<HTMLElementImpl *>(impl)->getInlineStyleDecl()];
1511 @implementation DOMElement (WebCoreInternal)
1513 + (DOMElement *)_elementWithImpl:(ElementImpl *)impl
1515 return static_cast<DOMElement *>([DOMNode _nodeWithImpl:impl]);
1518 - (ElementImpl *)_elementImpl
1520 return static_cast<ElementImpl *>(DOM_cast<NodeImpl *>(_internal));
1525 //------------------------------------------------------------------------------------------
1528 @implementation DOMText
1530 - (TextImpl *)_textImpl
1532 return static_cast<TextImpl *>(DOM_cast<NodeImpl *>(_internal));
1535 - (DOMText *)splitText:(unsigned long)offset
1537 int exceptionCode = 0;
1538 DOMNode *result = [DOMNode _nodeWithImpl:[self _textImpl]->splitText(offset, exceptionCode)];
1539 raiseOnDOMError(exceptionCode);
1540 return static_cast<DOMText *>(result);
1545 //------------------------------------------------------------------------------------------
1548 @implementation DOMComment
1552 //------------------------------------------------------------------------------------------
1555 @implementation DOMCDATASection
1559 //------------------------------------------------------------------------------------------
1562 @implementation DOMDocumentType
1564 - (DocumentTypeImpl *)_documentTypeImpl
1566 return static_cast<DocumentTypeImpl *>(DOM_cast<NodeImpl *>(_internal));
1571 return [self _documentTypeImpl]->publicId();
1574 - (DOMNamedNodeMap *)entities
1576 return [DOMNamedNodeMap _namedNodeMapWithImpl:[self _documentTypeImpl]->entities()];
1579 - (DOMNamedNodeMap *)notations
1581 return [DOMNamedNodeMap _namedNodeMapWithImpl:[self _documentTypeImpl]->notations()];
1584 - (NSString *)publicId
1586 return [self _documentTypeImpl]->publicId();
1589 - (NSString *)systemId
1591 return [self _documentTypeImpl]->systemId();
1594 - (NSString *)internalSubset
1596 return [self _documentTypeImpl]->internalSubset();
1601 //------------------------------------------------------------------------------------------
1604 @implementation DOMNotation
1606 - (NotationImpl *)_notationImpl
1608 return static_cast<NotationImpl *>(DOM_cast<NodeImpl *>(_internal));
1611 - (NSString *)publicId
1613 return [self _notationImpl]->publicId();
1616 - (NSString *)systemId
1618 return [self _notationImpl]->systemId();
1623 //------------------------------------------------------------------------------------------
1626 @implementation DOMEntity
1628 - (EntityImpl *)_entityImpl
1630 return static_cast<EntityImpl *>(DOM_cast<NodeImpl *>(_internal));
1633 - (NSString *)publicId
1635 return [self _entityImpl]->publicId();
1638 - (NSString *)systemId
1640 return [self _entityImpl]->systemId();
1643 - (NSString *)notationName
1645 return [self _entityImpl]->notationName();
1650 //------------------------------------------------------------------------------------------
1651 // DOMEntityReference
1653 @implementation DOMEntityReference
1657 //------------------------------------------------------------------------------------------
1658 // DOMProcessingInstruction
1660 @implementation DOMProcessingInstruction
1662 - (ProcessingInstructionImpl *)_processingInstructionImpl
1664 return static_cast<ProcessingInstructionImpl *>(DOM_cast<NodeImpl *>(_internal));
1667 - (NSString *)target
1669 return [self _processingInstructionImpl]->target();
1674 return [self _processingInstructionImpl]->data();
1677 - (void)setData:(NSString *)data
1681 int exceptionCode = 0;
1682 [self _processingInstructionImpl]->setData(data, exceptionCode);
1683 raiseOnDOMError(exceptionCode);
1688 //------------------------------------------------------------------------------------------
1691 @implementation DOMRange
1696 DOM_cast<RangeImpl *>(_internal)->deref();
1704 DOM_cast<RangeImpl *>(_internal)->deref();
1709 - (NSString *)description
1712 return @"DOMRange: null";
1713 return [NSString stringWithFormat:@"DOMRange: %@ %ld %@ %ld",
1714 [self startContainer], [self startOffset],
1715 [self endContainer], [self endOffset]];
1718 - (DOMNode *)startContainer
1720 int exceptionCode = 0;
1721 DOMNode *result = [DOMNode _nodeWithImpl:[self _rangeImpl]->startContainer(exceptionCode)];
1722 raiseOnDOMError(exceptionCode);
1728 int exceptionCode = 0;
1729 long result = [self _rangeImpl]->startOffset(exceptionCode);
1730 raiseOnDOMError(exceptionCode);
1734 - (DOMNode *)endContainer
1736 int exceptionCode = 0;
1737 DOMNode *result = [DOMNode _nodeWithImpl:[self _rangeImpl]->endContainer(exceptionCode)];
1738 raiseOnDOMError(exceptionCode);
1744 int exceptionCode = 0;
1745 long result = [self _rangeImpl]->endOffset(exceptionCode);
1746 raiseOnDOMError(exceptionCode);
1752 int exceptionCode = 0;
1753 BOOL result = [self _rangeImpl]->collapsed(exceptionCode);
1754 raiseOnDOMError(exceptionCode);
1758 - (DOMNode *)commonAncestorContainer
1760 int exceptionCode = 0;
1761 DOMNode *result = [DOMNode _nodeWithImpl:[self _rangeImpl]->commonAncestorContainer(exceptionCode)];
1762 raiseOnDOMError(exceptionCode);
1766 - (void)setStart:(DOMNode *)refNode :(long)offset
1768 int exceptionCode = 0;
1769 [self _rangeImpl]->setStart([refNode _nodeImpl], offset, exceptionCode);
1770 raiseOnDOMError(exceptionCode);
1773 - (void)setEnd:(DOMNode *)refNode :(long)offset
1775 int exceptionCode = 0;
1776 [self _rangeImpl]->setEnd([refNode _nodeImpl], offset, exceptionCode);
1777 raiseOnDOMError(exceptionCode);
1780 - (void)setStartBefore:(DOMNode *)refNode
1782 int exceptionCode = 0;
1783 [self _rangeImpl]->setStartBefore([refNode _nodeImpl], exceptionCode);
1784 raiseOnDOMError(exceptionCode);
1787 - (void)setStartAfter:(DOMNode *)refNode
1789 int exceptionCode = 0;
1790 [self _rangeImpl]->setStartAfter([refNode _nodeImpl], exceptionCode);
1791 raiseOnDOMError(exceptionCode);
1794 - (void)setEndBefore:(DOMNode *)refNode
1796 int exceptionCode = 0;
1797 [self _rangeImpl]->setEndBefore([refNode _nodeImpl], exceptionCode);
1798 raiseOnDOMError(exceptionCode);
1801 - (void)setEndAfter:(DOMNode *)refNode
1803 int exceptionCode = 0;
1804 [self _rangeImpl]->setEndAfter([refNode _nodeImpl], exceptionCode);
1805 raiseOnDOMError(exceptionCode);
1808 - (void)collapse:(BOOL)toStart
1810 int exceptionCode = 0;
1811 [self _rangeImpl]->collapse(toStart, exceptionCode);
1812 raiseOnDOMError(exceptionCode);
1815 - (void)selectNode:(DOMNode *)refNode
1817 int exceptionCode = 0;
1818 [self _rangeImpl]->selectNode([refNode _nodeImpl], exceptionCode);
1819 raiseOnDOMError(exceptionCode);
1822 - (void)selectNodeContents:(DOMNode *)refNode
1824 int exceptionCode = 0;
1825 [self _rangeImpl]->selectNodeContents([refNode _nodeImpl], exceptionCode);
1826 raiseOnDOMError(exceptionCode);
1829 - (short)compareBoundaryPoints:(unsigned short)how :(DOMRange *)sourceRange
1831 int exceptionCode = 0;
1832 short result = [self _rangeImpl]->compareBoundaryPoints(static_cast<Range::CompareHow>(how), [sourceRange _rangeImpl], exceptionCode);
1833 raiseOnDOMError(exceptionCode);
1837 - (void)deleteContents
1839 int exceptionCode = 0;
1840 [self _rangeImpl]->deleteContents(exceptionCode);
1841 raiseOnDOMError(exceptionCode);
1844 - (DOMDocumentFragment *)extractContents
1846 int exceptionCode = 0;
1847 DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->extractContents(exceptionCode)];
1848 raiseOnDOMError(exceptionCode);
1852 - (DOMDocumentFragment *)cloneContents
1854 int exceptionCode = 0;
1855 DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->cloneContents(exceptionCode)];
1856 raiseOnDOMError(exceptionCode);
1860 - (void)insertNode:(DOMNode *)newNode
1862 int exceptionCode = 0;
1863 [self _rangeImpl]->insertNode([newNode _nodeImpl], exceptionCode);
1864 raiseOnDOMError(exceptionCode);
1867 - (void)surroundContents:(DOMNode *)newParent
1869 int exceptionCode = 0;
1870 [self _rangeImpl]->surroundContents([newParent _nodeImpl], exceptionCode);
1871 raiseOnDOMError(exceptionCode);
1874 - (DOMRange *)cloneRange
1876 int exceptionCode = 0;
1877 DOMRange *result = [DOMRange _rangeWithImpl:[self _rangeImpl]->cloneRange(exceptionCode)];
1878 raiseOnDOMError(exceptionCode);
1882 - (NSString *)toString
1884 int exceptionCode = 0;
1885 NSString *result = [self _rangeImpl]->toString(exceptionCode);
1886 raiseOnDOMError(exceptionCode);
1892 int exceptionCode = 0;
1893 [self _rangeImpl]->detach(exceptionCode);
1894 raiseOnDOMError(exceptionCode);
1899 @implementation DOMRange (WebCoreInternal)
1901 - (id)_initWithRangeImpl:(RangeImpl *)impl
1906 _internal = DOM_cast<DOMObjectInternal *>(impl);
1908 addDOMWrapper(self, impl);
1912 + (DOMRange *)_rangeWithImpl:(RangeImpl *)impl
1918 cachedInstance = getDOMWrapper(impl);
1920 return [[cachedInstance retain] autorelease];
1922 return [[[self alloc] _initWithRangeImpl:impl] autorelease];
1925 - (RangeImpl *)_rangeImpl
1927 return DOM_cast<RangeImpl *>(_internal);
1932 @implementation DOMRange (WebPrivate)
1936 return [self _rangeImpl]->text().string().getNSString();
1941 //------------------------------------------------------------------------------------------
1943 //------------------------------------------------------------------------------------------
1945 @implementation DOMNodeFilter
1947 - (id)_initWithNodeFilterImpl:(NodeFilterImpl *)impl
1952 _internal = DOM_cast<DOMObjectInternal *>(impl);
1954 addDOMWrapper(self, impl);
1958 + (DOMNodeFilter *)_nodeFilterWithImpl:(NodeFilterImpl *)impl
1964 cachedInstance = getDOMWrapper(impl);
1966 return [[cachedInstance retain] autorelease];
1968 return [[[self alloc] _initWithNodeFilterImpl:impl] autorelease];
1971 - (NodeFilterImpl *)_nodeFilterImpl
1973 return DOM_cast<NodeFilterImpl *>(_internal);
1979 DOM_cast<NodeFilterImpl *>(_internal)->deref();
1986 DOM_cast<NodeFilterImpl *>(_internal)->deref();
1990 - (short)acceptNode:(DOMNode *)node
1992 return [self _nodeFilterImpl]->acceptNode([node _nodeImpl]);
1998 @implementation DOMNodeIterator
2000 - (id)_initWithNodeIteratorImpl:(NodeIteratorImpl *)impl filter:(id <DOMNodeFilter>)filter
2005 _internal = DOM_cast<DOMObjectInternal *>(impl);
2007 addDOMWrapper(self, impl);
2008 m_filter = [filter retain];
2012 - (NodeIteratorImpl *)_nodeIteratorImpl
2014 return DOM_cast<NodeIteratorImpl *>(_internal);
2022 DOM_cast<NodeIteratorImpl *>(_internal)->deref();
2031 DOM_cast<NodeIteratorImpl *>(_internal)->deref();
2038 return [DOMNode _nodeWithImpl:[self _nodeIteratorImpl]->root()];
2041 - (unsigned long)whatToShow
2043 return [self _nodeIteratorImpl]->whatToShow();
2046 - (id <DOMNodeFilter>)filter
2049 // This node iterator was created from the objc side
2050 return [[m_filter retain] autorelease];
2052 // This node iterator was created from the c++ side
2053 return [DOMNodeFilter _nodeFilterWithImpl:[self _nodeIteratorImpl]->filter()];
2056 - (BOOL)expandEntityReferences
2058 return [self _nodeIteratorImpl]->expandEntityReferences();
2061 - (DOMNode *)nextNode
2063 int exceptionCode = 0;
2064 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeIteratorImpl]->nextNode(exceptionCode)];
2065 raiseOnDOMError(exceptionCode);
2069 - (DOMNode *)previousNode
2071 int exceptionCode = 0;
2072 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeIteratorImpl]->previousNode(exceptionCode)];
2073 raiseOnDOMError(exceptionCode);
2079 int exceptionCode = 0;
2080 [self _nodeIteratorImpl]->detach(exceptionCode);
2081 raiseOnDOMError(exceptionCode);
2086 @implementation DOMNodeIterator(WebCoreInternal)
2088 + (DOMNodeIterator *)_nodeIteratorWithImpl:(NodeIteratorImpl *)impl filter:(id <DOMNodeFilter>)filter
2094 cachedInstance = getDOMWrapper(impl);
2096 return [[cachedInstance retain] autorelease];
2098 return [[[self alloc] _initWithNodeIteratorImpl:impl filter:filter] autorelease];
2103 @implementation DOMTreeWalker
2105 - (id)_initWithTreeWalkerImpl:(TreeWalkerImpl *)impl filter:(id <DOMNodeFilter>)filter
2110 _internal = DOM_cast<DOMObjectInternal *>(impl);
2112 addDOMWrapper(self, impl);
2113 m_filter = [filter retain];
2117 - (TreeWalkerImpl *)_treeWalkerImpl
2119 return DOM_cast<TreeWalkerImpl *>(_internal);
2127 DOM_cast<TreeWalkerImpl *>(_internal)->deref();
2135 DOM_cast<TreeWalkerImpl *>(_internal)->deref();
2142 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->root()];
2145 - (unsigned long)whatToShow
2147 return [self _treeWalkerImpl]->whatToShow();
2150 - (id <DOMNodeFilter>)filter
2153 // This tree walker was created from the objc side
2154 return [[m_filter retain] autorelease];
2156 // This tree walker was created from the c++ side
2157 return [DOMNodeFilter _nodeFilterWithImpl:[self _treeWalkerImpl]->filter()];
2160 - (BOOL)expandEntityReferences
2162 return [self _treeWalkerImpl]->expandEntityReferences();
2165 - (DOMNode *)currentNode
2167 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->currentNode()];
2170 - (void)setCurrentNode:(DOMNode *)currentNode
2172 int exceptionCode = 0;
2173 [self _treeWalkerImpl]->setCurrentNode([currentNode _nodeImpl], exceptionCode);
2174 raiseOnDOMError(exceptionCode);
2177 - (DOMNode *)parentNode
2179 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->parentNode()];
2182 - (DOMNode *)firstChild
2184 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->firstChild()];
2187 - (DOMNode *)lastChild
2189 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->lastChild()];
2192 - (DOMNode *)previousSibling
2194 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->previousSibling()];
2197 - (DOMNode *)nextSibling
2199 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->nextSibling()];
2202 - (DOMNode *)previousNode
2204 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->previousNode()];
2207 - (DOMNode *)nextNode
2209 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->nextNode()];
2214 @implementation DOMTreeWalker (WebCoreInternal)
2216 + (DOMTreeWalker *)_treeWalkerWithImpl:(TreeWalkerImpl *)impl filter:(id <DOMNodeFilter>)filter
2222 cachedInstance = getDOMWrapper(impl);
2224 return [[cachedInstance retain] autorelease];
2226 return [[[self alloc] _initWithTreeWalkerImpl:impl filter:filter] autorelease];
2231 class ObjCNodeFilterCondition : public NodeFilterCondition
2234 ObjCNodeFilterCondition(id <DOMNodeFilter>);
2235 virtual ~ObjCNodeFilterCondition();
2236 virtual short acceptNode(const Node &) const;
2239 ObjCNodeFilterCondition(const ObjCNodeFilterCondition &);
2240 ObjCNodeFilterCondition &operator=(const ObjCNodeFilterCondition &);
2242 id <DOMNodeFilter> m_filter;
2245 ObjCNodeFilterCondition::ObjCNodeFilterCondition(id <DOMNodeFilter> filter)
2252 ObjCNodeFilterCondition::~ObjCNodeFilterCondition()
2254 CFRelease(m_filter);
2257 short ObjCNodeFilterCondition::acceptNode(const Node &n) const
2260 return NodeFilter::FILTER_REJECT;
2262 return [m_filter acceptNode:[DOMNode _nodeWithImpl:n.handle()]];
2265 @implementation DOMDocument (DOMDocumentTraversal)
2267 - (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned long)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
2269 NodeFilter cppFilter;
2271 cppFilter = NodeFilter(new ObjCNodeFilterCondition(filter));
2272 int exceptionCode = 0;
2273 NodeIteratorImpl *impl = [self _documentImpl]->createNodeIterator([root _nodeImpl], whatToShow, cppFilter.handle(), expandEntityReferences, exceptionCode);
2274 raiseOnDOMError(exceptionCode);
2275 return [DOMNodeIterator _nodeIteratorWithImpl:impl filter:filter];
2278 - (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned long)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
2280 NodeFilter cppFilter;
2282 cppFilter = NodeFilter(new ObjCNodeFilterCondition(filter));
2283 int exceptionCode = 0;
2284 TreeWalkerImpl *impl = [self _documentImpl]->createTreeWalker([root _nodeImpl], whatToShow, cppFilter.handle(), expandEntityReferences, exceptionCode);
2285 raiseOnDOMError(exceptionCode);
2286 return [DOMTreeWalker _treeWalkerWithImpl:impl filter:filter];