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 "khtml_part.h"
54 #import "DOMEventsInternal.h"
56 #import "DOMInternal.h"
57 #import "DOMPrivate.h"
58 #import "KWQAssertions.h"
59 #import "KWQFoundationExtras.h"
60 #import "KWQKHTMLPart.h"
64 using DOM::CharacterDataImpl;
65 using DOM::DocumentFragmentImpl;
66 using DOM::DocumentType;
67 using DOM::DocumentTypeImpl;
69 using DOM::DocumentImpl;
70 using DOM::DOMImplementationImpl;
72 using DOM::DOMStringImpl;
74 using DOM::ElementImpl;
75 using DOM::EntityImpl;
76 using DOM::HTMLElementImpl;
77 using DOM::NamedNodeMap;
78 using DOM::NamedNodeMapImpl;
80 using DOM::NodeFilter;
81 using DOM::NodeFilterCondition;
82 using DOM::NodeFilterImpl;
84 using DOM::NodeIteratorImpl;
85 using DOM::NodeListImpl;
86 using DOM::NotationImpl;
87 using DOM::ProcessingInstructionImpl;
89 using DOM::RangeException;
92 using DOM::TreeWalkerImpl;
94 @interface DOMAttr (WebCoreInternal)
95 + (DOMAttr *)_attrWithImpl:(AttrImpl *)impl;
96 - (AttrImpl *)_attrImpl;
99 @interface DOMImplementation (WebCoreInternal)
100 + (DOMImplementation *)_DOMImplementationWithImpl:(DOMImplementationImpl *)impl;
101 - (DOMImplementationImpl *)_DOMImplementationImpl;
104 @interface DOMNamedNodeMap (WebCoreInternal)
105 + (DOMNamedNodeMap *)_namedNodeMapWithImpl:(NamedNodeMapImpl *)impl;
108 //------------------------------------------------------------------------------------------
111 inline NamedNodeMap NamedNodeMapImpl::createInstance(NamedNodeMapImpl *impl)
113 return NamedNodeMap(impl);
116 inline Attr AttrImpl::createInstance(AttrImpl *impl)
121 inline Element ElementImpl::createInstance(ElementImpl *impl)
123 return Element(impl);
126 inline DocumentType DocumentTypeImpl::createInstance(DocumentTypeImpl *impl)
128 return DocumentType(impl);
131 inline Document DocumentImpl::createInstance(DocumentImpl *impl)
133 return Document(impl);
136 //------------------------------------------------------------------------------------------
139 @implementation DOMObject
141 // Prevent creation of DOM objects by clients who just "[[xxx alloc] init]".
144 [NSException raise:NSGenericException format:@"+[%s init]: should never be used", [self class]->name];
152 removeDOMWrapper(_internal);
160 removeDOMWrapper(_internal);
165 - (id)copyWithZone:(NSZone *)zone
167 return [self retain];
172 @implementation DOMObject (WebCoreInternal)
176 return [super _init];
181 //------------------------------------------------------------------------------------------
184 @implementation DOMNode
189 DOM_cast<NodeImpl *>(_internal)->deref();
197 DOM_cast<NodeImpl *>(_internal)->deref();
202 - (NSString *)nodeName
204 return [self _nodeImpl]->nodeName();
207 - (NSString *)nodeValue
209 // Documentation says we can raise a DOMSTRING_SIZE_ERR.
210 // However, the lower layer does not report that error up to us.
211 return [self _nodeImpl]->nodeValue();
214 - (void)setNodeValue:(NSString *)string
218 int exceptionCode = 0;
219 [self _nodeImpl]->setNodeValue(string, exceptionCode);
220 raiseOnDOMError(exceptionCode);
223 - (unsigned short)nodeType
225 return [self _nodeImpl]->nodeType();
228 - (DOMNode *)parentNode
230 return [DOMNode _nodeWithImpl:[self _nodeImpl]->parentNode()];
233 - (DOMNodeList *)childNodes
235 return [DOMNodeList _nodeListWithImpl:[self _nodeImpl]->childNodes()];
238 - (DOMNode *)firstChild
240 return [DOMNode _nodeWithImpl:[self _nodeImpl]->firstChild()];
243 - (DOMNode *)lastChild
245 return [DOMNode _nodeWithImpl:[self _nodeImpl]->lastChild()];
248 - (DOMNode *)previousSibling
250 return [DOMNode _nodeWithImpl:[self _nodeImpl]->previousSibling()];
253 - (DOMNode *)nextSibling
255 return [DOMNode _nodeWithImpl:[self _nodeImpl]->nextSibling()];
258 - (DOMNamedNodeMap *)attributes
260 // DOM level 2 core specification says:
261 // A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
265 - (DOMDocument *)ownerDocument
267 return [DOMDocument _documentWithImpl:[self _nodeImpl]->getDocument()];
270 - (DOMNode *)insertBefore:(DOMNode *)newChild :(DOMNode *)refChild
275 int exceptionCode = 0;
276 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->insertBefore([newChild _nodeImpl], [refChild _nodeImpl], exceptionCode)];
277 raiseOnDOMError(exceptionCode);
281 - (DOMNode *)replaceChild:(DOMNode *)newChild :(DOMNode *)oldChild
286 int exceptionCode = 0;
287 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->replaceChild([newChild _nodeImpl], [oldChild _nodeImpl], exceptionCode)];
288 raiseOnDOMError(exceptionCode);
292 - (DOMNode *)removeChild:(DOMNode *)oldChild
296 int exceptionCode = 0;
297 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->removeChild([oldChild _nodeImpl], exceptionCode)];
298 raiseOnDOMError(exceptionCode);
302 - (DOMNode *)appendChild:(DOMNode *)newChild
306 int exceptionCode = 0;
307 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeImpl]->appendChild([newChild _nodeImpl], exceptionCode)];
308 raiseOnDOMError(exceptionCode);
312 - (BOOL)hasChildNodes
314 return [self _nodeImpl]->hasChildNodes();
317 - (DOMNode *)cloneNode:(BOOL)deep
319 return [DOMNode _nodeWithImpl:[self _nodeImpl]->cloneNode(deep)];
324 [self _nodeImpl]->normalize();
327 - (BOOL)isSupported:(NSString *)feature :(NSString *)version
332 // Method not reflected in DOM::NodeImpl interface
333 return Node([self _nodeImpl]).isSupported(feature, version);
336 - (NSString *)namespaceURI
338 // Method not reflected in DOM::NodeImpl interface
339 return Node([self _nodeImpl]).namespaceURI();
344 return [self _nodeImpl]->prefix();
347 - (void)setPrefix:(NSString *)prefix
351 int exceptionCode = 0;
352 [self _nodeImpl]->setPrefix(prefix, exceptionCode);
353 raiseOnDOMError(exceptionCode);
356 - (NSString *)localName
358 return [self _nodeImpl]->localName();
361 - (BOOL)hasAttributes
363 // Method not reflected in DOM::NodeImpl interface
364 return Node([self _nodeImpl]).hasAttributes();
367 - (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
369 ERROR("unimplemented");
372 - (void)removeEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
374 ERROR("unimplemented");
377 - (BOOL)dispatchEvent:(DOMEvent *)event
379 int exceptionCode = 0;
380 BOOL result = [self _nodeImpl]->dispatchEvent([event _eventImpl], exceptionCode);
381 raiseOnDOMError(exceptionCode);
387 @implementation DOMNode (WebCoreInternal)
389 - (id)_initWithNodeImpl:(NodeImpl *)impl
394 _internal = DOM_cast<DOMObjectInternal *>(impl);
396 addDOMWrapper(self, impl);
400 + (DOMNode *)_nodeWithImpl:(NodeImpl *)impl
406 cachedInstance = getDOMWrapper(impl);
408 return [[cachedInstance retain] autorelease];
410 Class wrapperClass = nil;
411 switch (impl->nodeType()) {
412 case Node::ELEMENT_NODE:
413 if (impl->isHTMLElement()) {
414 // FIXME: There are no identifiers for HTMLHeadingElement, HTMLModElement,
415 // HTMLTableCaptionElement, HTMLTableColElement, HTMLTableSectionElement.
416 // Find other ways to identify them.
417 switch (impl->identifier()) {
419 wrapperClass = [DOMHTMLHtmlElement class];
422 wrapperClass = [DOMHTMLHeadElement class];
425 wrapperClass = [DOMHTMLLinkElement class];
428 wrapperClass = [DOMHTMLTitleElement class];
431 wrapperClass = [DOMHTMLMetaElement class];
434 wrapperClass = [DOMHTMLBaseElement class];
437 wrapperClass = [DOMHTMLIsIndexElement class];
440 wrapperClass = [DOMHTMLStyleElement class];
443 wrapperClass = [DOMHTMLBodyElement class];
446 wrapperClass = [DOMHTMLFormElement class];
449 wrapperClass = [DOMHTMLSelectElement class];
452 wrapperClass = [DOMHTMLOptGroupElement class];
455 wrapperClass = [DOMHTMLOptionElement class];
458 wrapperClass = [DOMHTMLInputElement class];
461 wrapperClass = [DOMHTMLTextAreaElement class];
464 wrapperClass = [DOMHTMLButtonElement class];
467 wrapperClass = [DOMHTMLLabelElement class];
470 wrapperClass = [DOMHTMLFieldSetElement class];
473 wrapperClass = [DOMHTMLLegendElement class];
476 wrapperClass = [DOMHTMLUListElement class];
479 wrapperClass = [DOMHTMLOListElement class];
482 wrapperClass = [DOMHTMLDListElement class];
485 wrapperClass = [DOMHTMLDirectoryElement class];
488 wrapperClass = [DOMHTMLMenuElement class];
491 wrapperClass = [DOMHTMLLIElement class];
494 wrapperClass = [DOMHTMLDivElement class];
497 wrapperClass = [DOMHTMLParagraphElement class];
500 wrapperClass = [DOMHTMLQuoteElement class];
503 wrapperClass = [DOMHTMLPreElement class];
506 wrapperClass = [DOMHTMLBRElement class];
509 wrapperClass = [DOMHTMLFontElement class];
512 wrapperClass = [DOMHTMLFontElement class];
515 wrapperClass = [DOMHTMLHRElement class];
518 wrapperClass = [DOMHTMLAnchorElement class];
521 wrapperClass = [DOMHTMLImageElement class];
524 wrapperClass = [DOMHTMLObjectElement class];
527 wrapperClass = [DOMHTMLParamElement class];
530 wrapperClass = [DOMHTMLAppletElement class];
533 wrapperClass = [DOMHTMLMapElement class];
536 wrapperClass = [DOMHTMLAreaElement class];
539 wrapperClass = [DOMHTMLScriptElement class];
542 wrapperClass = [DOMHTMLTableElement class];
545 wrapperClass = [DOMHTMLTableCellElement class];
548 wrapperClass = [DOMHTMLTableRowElement class];
551 wrapperClass = [DOMHTMLFrameSetElement class];
554 wrapperClass = [DOMHTMLFrameElement class];
557 wrapperClass = [DOMHTMLIFrameElement class];
560 wrapperClass = [DOMHTMLElement class];
563 wrapperClass = [DOMElement class];
566 case Node::ATTRIBUTE_NODE:
567 wrapperClass = [DOMAttr class];
569 case Node::TEXT_NODE:
570 wrapperClass = [DOMText class];
572 case Node::CDATA_SECTION_NODE:
573 wrapperClass = [DOMCDATASection class];
575 case Node::ENTITY_REFERENCE_NODE:
576 wrapperClass = [DOMEntityReference class];
578 case Node::ENTITY_NODE:
579 wrapperClass = [DOMEntity class];
581 case Node::PROCESSING_INSTRUCTION_NODE:
582 wrapperClass = [DOMProcessingInstruction class];
584 case Node::COMMENT_NODE:
585 wrapperClass = [DOMComment class];
587 case Node::DOCUMENT_NODE:
588 if (static_cast<DocumentImpl *>(impl)->isHTMLDocument()) {
589 wrapperClass = [DOMHTMLDocument class];
591 wrapperClass = [DOMDocument class];
594 case Node::DOCUMENT_TYPE_NODE:
595 wrapperClass = [DOMDocumentType class];
597 case Node::DOCUMENT_FRAGMENT_NODE:
598 wrapperClass = [DOMDocumentFragment class];
600 case Node::NOTATION_NODE:
601 wrapperClass = [DOMNotation class];
604 return [[[wrapperClass alloc] _initWithNodeImpl:impl] autorelease];
607 - (NodeImpl *)_nodeImpl
609 return DOM_cast<NodeImpl *>(_internal);
612 - (BOOL)isContentEditable
614 return [self _nodeImpl]->isContentEditable();
617 - (const KJS::Bindings::RootObject *)_executionContext
619 NodeImpl *n = [self _nodeImpl];
623 DocumentImpl *doc = n->getDocument();
627 KWQKHTMLPart *p = KWQ(doc->part());
631 return p->executionContextForDOM();
636 //------------------------------------------------------------------------------------------
639 @implementation DOMNamedNodeMap
644 DOM_cast<NamedNodeMapImpl *>(_internal)->deref();
652 DOM_cast<NamedNodeMapImpl *>(_internal)->deref();
657 - (NamedNodeMapImpl *)_namedNodeMapImpl
659 return DOM_cast<NamedNodeMapImpl *>(_internal);
662 - (DOMNode *)getNamedItem:(NSString *)name
666 // Method not reflected in DOM::NamedNodeMapImpl interface
667 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
668 Node result(map.getNamedItem(name));
669 return [DOMNode _nodeWithImpl:result.handle()];
672 - (DOMNode *)setNamedItem:(DOMNode *)arg
676 // Method not reflected in DOM::NamedNodeMapImpl interface
678 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
679 Node result(map.setNamedItem([arg _nodeImpl]));
680 return [DOMNode _nodeWithImpl:result.handle()];
682 catch (const DOM::DOMException &e) {
683 raiseOnDOMError(e.code);
688 - (DOMNode *)removeNamedItem:(NSString *)name
692 // Method not reflected in DOM::NamedNodeMapImpl interface
694 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
695 Node result(map.removeNamedItem(name));
696 return [DOMNode _nodeWithImpl:result.handle()];
698 catch (const DOM::DOMException &e) {
699 raiseOnDOMError(e.code);
704 - (DOMNode *)item:(unsigned long)index
706 return [DOMNode _nodeWithImpl:[self _namedNodeMapImpl]->item(index)];
709 - (unsigned long)length
711 return [self _namedNodeMapImpl]->length();
714 - (DOMNode *)getNamedItemNS:(NSString *)namespaceURI :(NSString *)localName
716 if (!namespaceURI || !localName) {
720 // Method not reflected in DOM::NamedNodeMapImpl interface
721 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
722 Node result(map.getNamedItemNS(namespaceURI, localName));
723 return [DOMNode _nodeWithImpl:result.handle()];
726 - (DOMNode *)setNamedItemNS:(DOMNode *)arg
730 // Method not reflected in DOM::NamedNodeMapImpl interface
732 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
733 Node result(map.setNamedItemNS([arg _nodeImpl]));
734 return [DOMNode _nodeWithImpl:result.handle()];
736 catch (const DOM::DOMException &e) {
737 raiseOnDOMError(e.code);
742 - (DOMNode *)removeNamedItemNS:(NSString *)namespaceURI :(NSString *)localName
744 ASSERT(namespaceURI);
747 // Method not reflected in DOM::NamedNodeMapImpl interface
749 NamedNodeMap map = NamedNodeMapImpl::createInstance([self _namedNodeMapImpl]);
750 Node result(map.removeNamedItemNS(namespaceURI, localName));
751 return [DOMNode _nodeWithImpl:result.handle()];
753 catch (const DOM::DOMException &e) {
754 raiseOnDOMError(e.code);
761 @implementation DOMNamedNodeMap (WebCoreInternal)
763 - (id)_initWithNamedNodeMapImpl:(NamedNodeMapImpl *)impl
768 _internal = DOM_cast<DOMObjectInternal *>(impl);
770 addDOMWrapper(self, impl);
774 + (DOMNamedNodeMap *)_namedNodeMapWithImpl:(NamedNodeMapImpl *)impl
780 cachedInstance = getDOMWrapper(impl);
782 return [[cachedInstance retain] autorelease];
784 return [[[self alloc] _initWithNamedNodeMapImpl:impl] autorelease];
789 //------------------------------------------------------------------------------------------
792 @implementation DOMNodeList
797 DOM_cast<NodeListImpl *>(_internal)->deref();
805 DOM_cast<NodeListImpl *>(_internal)->deref();
810 - (NodeListImpl *)_nodeListImpl
812 return DOM_cast<NodeListImpl *>(_internal);
815 - (DOMNode *)item:(unsigned long)index
817 return [DOMNode _nodeWithImpl:[self _nodeListImpl]->item(index)];
820 - (unsigned long)length
822 return [self _nodeListImpl]->length();
827 @implementation DOMNodeList (WebCoreInternal)
829 - (id)_initWithNodeListImpl:(NodeListImpl *)impl
834 _internal = DOM_cast<DOMObjectInternal *>(impl);
836 addDOMWrapper(self, impl);
840 + (DOMNodeList *)_nodeListWithImpl:(NodeListImpl *)impl
846 cachedInstance = getDOMWrapper(impl);
848 return [[cachedInstance retain] autorelease];
850 return [[[self alloc] _initWithNodeListImpl:impl] autorelease];
855 //------------------------------------------------------------------------------------------
858 @implementation DOMImplementation
863 DOM_cast<DOMImplementationImpl *>(_internal)->deref();
871 DOM_cast<DOMImplementationImpl *>(_internal)->deref();
876 - (BOOL)hasFeature:(NSString *)feature :(NSString *)version
881 return [self _DOMImplementationImpl]->hasFeature(feature, version);
884 - (DOMDocumentType *)createDocumentType:(NSString *)qualifiedName :(NSString *)publicId :(NSString *)systemId
886 ASSERT(qualifiedName);
890 int exceptionCode = 0;
891 DocumentTypeImpl *impl = [self _DOMImplementationImpl]->createDocumentType(qualifiedName, publicId, systemId, exceptionCode);
892 raiseOnDOMError(exceptionCode);
893 return static_cast<DOMDocumentType *>([DOMNode _nodeWithImpl:impl]);
896 - (DOMDocument *)createDocument:(NSString *)namespaceURI :(NSString *)qualifiedName :(DOMDocumentType *)doctype
898 ASSERT(namespaceURI);
899 ASSERT(qualifiedName);
901 int exceptionCode = 0;
902 DocumentType dt = DocumentTypeImpl::createInstance(static_cast<DocumentTypeImpl *>([doctype _nodeImpl]));
903 DocumentImpl *impl = [self _DOMImplementationImpl]->createDocument(namespaceURI, qualifiedName, dt, exceptionCode);
904 raiseOnDOMError(exceptionCode);
905 return static_cast<DOMDocument *>([DOMNode _nodeWithImpl:impl]);
910 @implementation DOMImplementation (DOMImplementationCSS)
912 - (DOMCSSStyleSheet *)createCSSStyleSheet:(NSString *)title :(NSString *)media
917 int exceptionCode = 0;
918 DOMString titleString(title);
919 DOMString mediaString(media);
920 DOMCSSStyleSheet *result = [DOMCSSStyleSheet _CSSStyleSheetWithImpl:[self _DOMImplementationImpl]->createCSSStyleSheet(titleString.implementation(), mediaString.implementation(), exceptionCode)];
921 raiseOnDOMError(exceptionCode);
927 @implementation DOMImplementation (WebCoreInternal)
929 - (id)_initWithDOMImplementationImpl:(DOMImplementationImpl *)impl
934 _internal = DOM_cast<DOMObjectInternal *>(impl);
936 addDOMWrapper(self, impl);
940 + (DOMImplementation *)_DOMImplementationWithImpl:(DOMImplementationImpl *)impl
946 cachedInstance = getDOMWrapper(impl);
948 return [[cachedInstance retain] autorelease];
950 return [[[self alloc] _initWithDOMImplementationImpl:impl] autorelease];
953 - (DOMImplementationImpl *)_DOMImplementationImpl
955 return DOM_cast<DOMImplementationImpl *>(_internal);
960 //------------------------------------------------------------------------------------------
961 // DOMDocumentFragment
963 @implementation DOMDocumentFragment
967 @implementation DOMDocumentFragment (WebCoreInternal)
969 + (DOMDocumentFragment *)_documentFragmentWithImpl:(DocumentFragmentImpl *)impl
971 return static_cast<DOMDocumentFragment *>([DOMNode _nodeWithImpl:impl]);
974 - (DocumentFragmentImpl *)_fragmentImpl
976 return static_cast<DocumentFragmentImpl *>(DOM_cast<NodeImpl *>(_internal));
981 //------------------------------------------------------------------------------------------
984 @implementation DOMDocument
986 - (DOMDocumentType *)doctype
988 return static_cast<DOMDocumentType *>([DOMNode _nodeWithImpl:[self _documentImpl]->doctype()]);
991 - (DOMImplementation *)implementation
993 return [DOMImplementation _DOMImplementationWithImpl:[self _documentImpl]->implementation()];
996 - (DOMElement *)documentElement
998 return static_cast<DOMElement *>([DOMNode _nodeWithImpl:[self _documentImpl]->documentElement()]);
1001 - (DOMElement *)createElement:(NSString *)tagName
1005 int exceptionCode = 0;
1006 DOMElement *result = static_cast<DOMElement *>([DOMNode _nodeWithImpl:[self _documentImpl]->createElement(tagName, exceptionCode)]);
1007 raiseOnDOMError(exceptionCode);
1011 - (DOMDocumentFragment *)createDocumentFragment
1013 return static_cast<DOMDocumentFragment *>([DOMNode _nodeWithImpl:[self _documentImpl]->createDocumentFragment()]);
1016 - (DOMText *)createTextNode:(NSString *)data
1019 return static_cast<DOMText *>([DOMNode _nodeWithImpl:[self _documentImpl]->createTextNode(data)]);
1022 - (DOMComment *)createComment:(NSString *)data
1025 return static_cast<DOMComment *>([DOMNode _nodeWithImpl:[self _documentImpl]->createComment(data)]);
1028 - (DOMCDATASection *)createCDATASection:(NSString *)data
1032 // Documentation says we can raise a NOT_SUPPORTED_ERR.
1033 // However, the lower layer does not report that error up to us.
1034 return static_cast<DOMCDATASection *>([DOMNode _nodeWithImpl:[self _documentImpl]->createCDATASection(data)]);
1037 - (DOMProcessingInstruction *)createProcessingInstruction:(NSString *)target :(NSString *)data
1042 // Documentation says we can raise a INVALID_CHARACTER_ERR or a NOT_SUPPORTED_ERR.
1043 // However, the lower layer does not report these errors up to us.
1044 return static_cast<DOMProcessingInstruction *>([DOMNode _nodeWithImpl:[self _documentImpl]->createProcessingInstruction(target, data)]);
1047 - (DOMAttr *)createAttribute:(NSString *)name
1051 // Method not reflected in DOM::DocumentImpl interface
1053 Document doc(DocumentImpl::createInstance([self _documentImpl]));
1054 Attr result(doc.createAttribute(name));
1055 return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:result.handle()]);
1057 catch (const DOM::DOMException &e) {
1058 raiseOnDOMError(e.code);
1063 - (DOMEntityReference *)createEntityReference:(NSString *)name
1067 // Documentation says we can raise a INVALID_CHARACTER_ERR or a NOT_SUPPORTED_ERR.
1068 // However, the lower layer does not report these errors up to us.
1069 return static_cast<DOMEntityReference *>([DOMNode _nodeWithImpl:[self _documentImpl]->createEntityReference(name)]);
1072 - (DOMNodeList *)getElementsByTagName:(NSString *)tagname
1075 return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(0, DOMString(tagname).implementation())];
1078 - (DOMNode *)importNode:(DOMNode *)importedNode :(BOOL)deep
1080 int exceptionCode = 0;
1081 DOMNode *result = [DOMNode _nodeWithImpl:[self _documentImpl]->importNode([importedNode _nodeImpl], deep, exceptionCode)];
1082 raiseOnDOMError(exceptionCode);
1086 - (DOMElement *)createElementNS:(NSString *)namespaceURI :(NSString *)qualifiedName
1088 ASSERT(namespaceURI);
1089 ASSERT(qualifiedName);
1091 int exceptionCode = 0;
1092 DOMNode *result = [DOMNode _nodeWithImpl:[self _documentImpl]->createElementNS(namespaceURI, qualifiedName, exceptionCode)];
1093 raiseOnDOMError(exceptionCode);
1094 return static_cast<DOMElement *>(result);
1097 - (DOMAttr *)createAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName
1099 ASSERT(namespaceURI);
1100 ASSERT(qualifiedName);
1102 // Method not reflected in DOM::DocumentImpl interface
1104 Document doc(DocumentImpl::createInstance([self _documentImpl]));
1105 Attr result(doc.createAttributeNS(namespaceURI, qualifiedName));
1106 return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:result.handle()]);
1108 catch (const DOM::DOMException &e) {
1109 raiseOnDOMError(e.code);
1114 - (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName
1116 ASSERT(namespaceURI);
1119 return [DOMNodeList _nodeListWithImpl:[self _documentImpl]->getElementsByTagNameNS(DOMString(namespaceURI).implementation(), DOMString(localName).implementation())];
1122 - (DOMElement *)getElementById:(NSString *)elementId
1126 return static_cast<DOMElement *>([DOMNode _nodeWithImpl:[self _documentImpl]->getElementById(elementId)]);
1131 @implementation DOMDocument (DOMDocumentRange)
1133 - (DOMRange *)createRange
1135 return [DOMRange _rangeWithImpl:[self _documentImpl]->createRange()];
1140 @implementation DOMDocument (DOMDocumentCSS)
1142 - (DOMCSSStyleDeclaration *)getComputedStyle:(DOMElement *)elt :(NSString *)pseudoElt
1144 ElementImpl *elementImpl = [elt _elementImpl];
1145 DOMString pseudoEltString(pseudoElt);
1146 return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:[self _documentImpl]->defaultView()->getComputedStyle(elementImpl, pseudoEltString.implementation())];
1149 - (DOMCSSStyleDeclaration *)getOverrideStyle:(DOMElement *)elt :(NSString *)pseudoElt;
1151 // FIXME: This is unimplemented by khtml,
1152 // so for now, we just return the computed style
1153 return [self getComputedStyle:elt :pseudoElt];
1158 @implementation DOMDocument (DOMDocumentStyle)
1160 - (DOMStyleSheetList *)styleSheets
1162 return [DOMStyleSheetList _styleSheetListWithImpl:[self _documentImpl]->styleSheets()];
1167 @implementation DOMDocument (DOMDocumentExtensions)
1169 - (DOMCSSStyleDeclaration *)createCSSStyleDeclaration;
1171 return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:[self _documentImpl]->createCSSStyleDeclaration()];
1176 @implementation DOMDocument (WebCoreInternal)
1178 + (DOMDocument *)_documentWithImpl:(DocumentImpl *)impl
1180 return static_cast<DOMDocument *>([DOMNode _nodeWithImpl:impl]);
1183 - (DocumentImpl *)_documentImpl
1185 return static_cast<DocumentImpl *>(DOM_cast<NodeImpl *>(_internal));
1188 - (DOMElement *)_ownerElement
1190 ElementImpl *element = [self _documentImpl]->ownerElement();
1191 return element ? [DOMElement _elementWithImpl:element] : nil;
1196 //------------------------------------------------------------------------------------------
1199 @implementation DOMCharacterData
1201 - (CharacterDataImpl *)_characterDataImpl
1203 return static_cast<CharacterDataImpl *>(DOM_cast<NodeImpl *>(_internal));
1208 // Documentation says we can raise a DOMSTRING_SIZE_ERR.
1209 // However, the lower layer does not report that error up to us.
1210 return [self _characterDataImpl]->data();
1213 - (void)setData:(NSString *)data
1217 int exceptionCode = 0;
1218 [self _characterDataImpl]->setData(data, exceptionCode);
1219 raiseOnDOMError(exceptionCode);
1222 - (unsigned long)length
1224 return [self _characterDataImpl]->length();
1227 - (NSString *)substringData:(unsigned long)offset :(unsigned long)count
1229 int exceptionCode = 0;
1230 NSString *result = [self _characterDataImpl]->substringData(offset, count, exceptionCode);
1231 raiseOnDOMError(exceptionCode);
1235 - (void)appendData:(NSString *)arg
1239 int exceptionCode = 0;
1240 [self _characterDataImpl]->appendData(arg, exceptionCode);
1241 raiseOnDOMError(exceptionCode);
1244 - (void)insertData:(unsigned long)offset :(NSString *)arg
1248 int exceptionCode = 0;
1249 [self _characterDataImpl]->insertData(offset, arg, exceptionCode);
1250 raiseOnDOMError(exceptionCode);
1253 - (void)deleteData:(unsigned long)offset :(unsigned long) count;
1255 int exceptionCode = 0;
1256 [self _characterDataImpl]->deleteData(offset, count, exceptionCode);
1257 raiseOnDOMError(exceptionCode);
1260 - (void)replaceData:(unsigned long)offset :(unsigned long)count :(NSString *)arg
1264 int exceptionCode = 0;
1265 [self _characterDataImpl]->replaceData(offset, count, arg, exceptionCode);
1266 raiseOnDOMError(exceptionCode);
1271 //------------------------------------------------------------------------------------------
1274 @implementation DOMAttr
1278 return [self _attrImpl]->nodeName();
1283 return [self _attrImpl]->specified();
1288 return [self _attrImpl]->nodeValue();
1291 - (void)setValue:(NSString *)value
1295 int exceptionCode = 0;
1296 [self _attrImpl]->setValue(value, exceptionCode);
1297 raiseOnDOMError(exceptionCode);
1300 - (DOMElement *)ownerElement
1302 return [DOMElement _elementWithImpl:[self _attrImpl]->ownerElement()];
1307 @implementation DOMAttr (WebCoreInternal)
1309 + (DOMAttr *)_attrWithImpl:(AttrImpl *)impl
1311 return static_cast<DOMAttr *>([DOMNode _nodeWithImpl:impl]);
1314 - (AttrImpl *)_attrImpl
1316 return static_cast<AttrImpl *>(DOM_cast<NodeImpl *>(_internal));
1321 //------------------------------------------------------------------------------------------
1324 @implementation DOMElement
1326 - (NSString *)tagName
1328 return [self _elementImpl]->tagName();
1331 - (DOMNamedNodeMap *)attributes
1333 return [DOMNamedNodeMap _namedNodeMapWithImpl:[self _elementImpl]->attributes()];
1336 - (NSString *)getAttribute:(NSString *)name
1339 return [self _elementImpl]->getAttribute(name);
1342 - (void)setAttribute:(NSString *)name :(NSString *)value
1347 // Method not reflected in DOM::ElementImpl interface
1349 Element element(ElementImpl::createInstance([self _elementImpl]));
1350 element.setAttribute(name, value);
1352 catch (const DOM::DOMException &e) {
1353 raiseOnDOMError(e.code);
1357 - (void)removeAttribute:(NSString *)name
1361 // Method not reflected in DOM::ElementImpl interface
1363 Element element(ElementImpl::createInstance([self _elementImpl]));
1364 element.removeAttribute(name);
1366 catch (const DOM::DOMException &e) {
1367 raiseOnDOMError(e.code);
1371 - (DOMAttr *)getAttributeNode:(NSString *)name
1375 // Method not reflected in DOM::ElementImpl interface
1376 Element element(ElementImpl::createInstance([self _elementImpl]));
1377 Attr result(element.getAttributeNode(name));
1378 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1381 - (DOMAttr *)setAttributeNode:(DOMAttr *)newAttr
1385 // Method not reflected in DOM::ElementImpl interface
1387 Element element(ElementImpl::createInstance([self _elementImpl]));
1388 Attr attr(AttrImpl::createInstance([newAttr _attrImpl]));
1389 Attr result(element.setAttributeNode(attr));
1390 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1392 catch (const DOM::DOMException &e) {
1393 raiseOnDOMError(e.code);
1398 - (DOMAttr *)removeAttributeNode:(DOMAttr *)oldAttr
1402 // Method not reflected in DOM::ElementImpl interface
1404 Element element(ElementImpl::createInstance([self _elementImpl]));
1405 Attr attr(AttrImpl::createInstance([oldAttr _attrImpl]));
1406 Attr result(element.removeAttributeNode(attr));
1407 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1409 catch (const DOM::DOMException &e) {
1410 raiseOnDOMError(e.code);
1415 - (DOMNodeList *)getElementsByTagName:(NSString *)name
1419 return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(0, DOMString(name).implementation())];
1422 - (NSString *)getAttributeNS:(NSString *)namespaceURI :(NSString *)localName
1424 ASSERT(namespaceURI);
1427 Element element(ElementImpl::createInstance([self _elementImpl]));
1428 return element.getAttributeNS(namespaceURI, localName);
1431 - (void)setAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName :(NSString *)value
1433 ASSERT(namespaceURI);
1434 ASSERT(qualifiedName);
1437 // Method not reflected in DOM::ElementImpl interface
1439 Element element(ElementImpl::createInstance([self _elementImpl]));
1440 element.setAttributeNS(namespaceURI, qualifiedName, value);
1442 catch (const DOM::DOMException &e) {
1443 raiseOnDOMError(e.code);
1447 - (void)removeAttributeNS:(NSString *)namespaceURI :(NSString *)localName
1449 ASSERT(namespaceURI);
1452 // Method not reflected in DOM::ElementImpl interface
1454 Element element(ElementImpl::createInstance([self _elementImpl]));
1455 element.removeAttributeNS(namespaceURI, localName);
1457 catch (const DOM::DOMException &e) {
1458 raiseOnDOMError(e.code);
1462 - (DOMAttr *)getAttributeNodeNS:(NSString *)namespaceURI :(NSString *)localName
1464 ASSERT(namespaceURI);
1467 // Method not reflected in DOM::ElementImpl interface
1468 Element element(ElementImpl::createInstance([self _elementImpl]));
1469 Attr result(element.getAttributeNodeNS(namespaceURI, localName));
1470 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1473 - (DOMAttr *)setAttributeNodeNS:(DOMAttr *)newAttr
1477 // Method not reflected in DOM::ElementImpl interface
1479 Element element(ElementImpl::createInstance([self _elementImpl]));
1480 Attr attr(AttrImpl::createInstance([newAttr _attrImpl]));
1481 Attr result(element.setAttributeNodeNS(attr));
1482 return [DOMAttr _attrWithImpl:static_cast<AttrImpl *>(result.handle())];
1484 catch (const DOM::DOMException &e) {
1485 raiseOnDOMError(e.code);
1490 - (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName
1492 ASSERT(namespaceURI);
1495 return [DOMNodeList _nodeListWithImpl:[self _elementImpl]->getElementsByTagNameNS(DOMString(namespaceURI).implementation(), DOMString(localName).implementation())];
1498 - (BOOL)hasAttribute:(NSString *)name
1502 // Method not reflected in DOM::ElementImpl interface
1503 Element element(ElementImpl::createInstance([self _elementImpl]));
1504 return element.hasAttribute(name);
1507 - (BOOL)hasAttributeNS:(NSString *)namespaceURI :(NSString *)localName
1509 ASSERT(namespaceURI);
1512 // Method not reflected in DOM::ElementImpl interface
1513 Element element(ElementImpl::createInstance([self _elementImpl]));
1514 return element.hasAttributeNS(namespaceURI, localName);
1519 @implementation DOMElement (DOMElementCSSInlineStyle)
1521 - (DOMCSSStyleDeclaration *)style
1523 ElementImpl *impl = [self _elementImpl];
1524 if (impl->isHTMLElement())
1525 return [DOMCSSStyleDeclaration _styleDeclarationWithImpl:static_cast<HTMLElementImpl *>(impl)->getInlineStyleDecl()];
1531 @implementation DOMElement (WebCoreInternal)
1533 + (DOMElement *)_elementWithImpl:(ElementImpl *)impl
1535 return static_cast<DOMElement *>([DOMNode _nodeWithImpl:impl]);
1538 - (ElementImpl *)_elementImpl
1540 return static_cast<ElementImpl *>(DOM_cast<NodeImpl *>(_internal));
1545 //------------------------------------------------------------------------------------------
1548 @implementation DOMText
1550 - (TextImpl *)_textImpl
1552 return static_cast<TextImpl *>(DOM_cast<NodeImpl *>(_internal));
1555 - (DOMText *)splitText:(unsigned long)offset
1557 int exceptionCode = 0;
1558 DOMNode *result = [DOMNode _nodeWithImpl:[self _textImpl]->splitText(offset, exceptionCode)];
1559 raiseOnDOMError(exceptionCode);
1560 return static_cast<DOMText *>(result);
1565 //------------------------------------------------------------------------------------------
1568 @implementation DOMComment
1572 //------------------------------------------------------------------------------------------
1575 @implementation DOMCDATASection
1579 //------------------------------------------------------------------------------------------
1582 @implementation DOMDocumentType
1584 - (DocumentTypeImpl *)_documentTypeImpl
1586 return static_cast<DocumentTypeImpl *>(DOM_cast<NodeImpl *>(_internal));
1591 return [self _documentTypeImpl]->publicId();
1594 - (DOMNamedNodeMap *)entities
1596 return [DOMNamedNodeMap _namedNodeMapWithImpl:[self _documentTypeImpl]->entities()];
1599 - (DOMNamedNodeMap *)notations
1601 return [DOMNamedNodeMap _namedNodeMapWithImpl:[self _documentTypeImpl]->notations()];
1604 - (NSString *)publicId
1606 return [self _documentTypeImpl]->publicId();
1609 - (NSString *)systemId
1611 return [self _documentTypeImpl]->systemId();
1614 - (NSString *)internalSubset
1616 return [self _documentTypeImpl]->internalSubset();
1621 //------------------------------------------------------------------------------------------
1624 @implementation DOMNotation
1626 - (NotationImpl *)_notationImpl
1628 return static_cast<NotationImpl *>(DOM_cast<NodeImpl *>(_internal));
1631 - (NSString *)publicId
1633 return [self _notationImpl]->publicId();
1636 - (NSString *)systemId
1638 return [self _notationImpl]->systemId();
1643 //------------------------------------------------------------------------------------------
1646 @implementation DOMEntity
1648 - (EntityImpl *)_entityImpl
1650 return static_cast<EntityImpl *>(DOM_cast<NodeImpl *>(_internal));
1653 - (NSString *)publicId
1655 return [self _entityImpl]->publicId();
1658 - (NSString *)systemId
1660 return [self _entityImpl]->systemId();
1663 - (NSString *)notationName
1665 return [self _entityImpl]->notationName();
1670 //------------------------------------------------------------------------------------------
1671 // DOMEntityReference
1673 @implementation DOMEntityReference
1677 //------------------------------------------------------------------------------------------
1678 // DOMProcessingInstruction
1680 @implementation DOMProcessingInstruction
1682 - (ProcessingInstructionImpl *)_processingInstructionImpl
1684 return static_cast<ProcessingInstructionImpl *>(DOM_cast<NodeImpl *>(_internal));
1687 - (NSString *)target
1689 return [self _processingInstructionImpl]->target();
1694 return [self _processingInstructionImpl]->data();
1697 - (void)setData:(NSString *)data
1701 int exceptionCode = 0;
1702 [self _processingInstructionImpl]->setData(data, exceptionCode);
1703 raiseOnDOMError(exceptionCode);
1708 //------------------------------------------------------------------------------------------
1711 @implementation DOMRange
1716 DOM_cast<RangeImpl *>(_internal)->deref();
1724 DOM_cast<RangeImpl *>(_internal)->deref();
1729 - (NSString *)description
1732 return @"DOMRange: null";
1733 return [NSString stringWithFormat:@"DOMRange: %@ %ld %@ %ld",
1734 [self startContainer], [self startOffset],
1735 [self endContainer], [self endOffset]];
1738 - (DOMNode *)startContainer
1740 int exceptionCode = 0;
1741 DOMNode *result = [DOMNode _nodeWithImpl:[self _rangeImpl]->startContainer(exceptionCode)];
1742 raiseOnDOMError(exceptionCode);
1748 int exceptionCode = 0;
1749 long result = [self _rangeImpl]->startOffset(exceptionCode);
1750 raiseOnDOMError(exceptionCode);
1754 - (DOMNode *)endContainer
1756 int exceptionCode = 0;
1757 DOMNode *result = [DOMNode _nodeWithImpl:[self _rangeImpl]->endContainer(exceptionCode)];
1758 raiseOnDOMError(exceptionCode);
1764 int exceptionCode = 0;
1765 long result = [self _rangeImpl]->endOffset(exceptionCode);
1766 raiseOnDOMError(exceptionCode);
1772 int exceptionCode = 0;
1773 BOOL result = [self _rangeImpl]->collapsed(exceptionCode);
1774 raiseOnDOMError(exceptionCode);
1778 - (DOMNode *)commonAncestorContainer
1780 int exceptionCode = 0;
1781 DOMNode *result = [DOMNode _nodeWithImpl:[self _rangeImpl]->commonAncestorContainer(exceptionCode)];
1782 raiseOnDOMError(exceptionCode);
1786 - (void)setStart:(DOMNode *)refNode :(long)offset
1788 int exceptionCode = 0;
1789 [self _rangeImpl]->setStart([refNode _nodeImpl], offset, exceptionCode);
1790 raiseOnDOMError(exceptionCode);
1793 - (void)setEnd:(DOMNode *)refNode :(long)offset
1795 int exceptionCode = 0;
1796 [self _rangeImpl]->setEnd([refNode _nodeImpl], offset, exceptionCode);
1797 raiseOnDOMError(exceptionCode);
1800 - (void)setStartBefore:(DOMNode *)refNode
1802 int exceptionCode = 0;
1803 [self _rangeImpl]->setStartBefore([refNode _nodeImpl], exceptionCode);
1804 raiseOnDOMError(exceptionCode);
1807 - (void)setStartAfter:(DOMNode *)refNode
1809 int exceptionCode = 0;
1810 [self _rangeImpl]->setStartAfter([refNode _nodeImpl], exceptionCode);
1811 raiseOnDOMError(exceptionCode);
1814 - (void)setEndBefore:(DOMNode *)refNode
1816 int exceptionCode = 0;
1817 [self _rangeImpl]->setEndBefore([refNode _nodeImpl], exceptionCode);
1818 raiseOnDOMError(exceptionCode);
1821 - (void)setEndAfter:(DOMNode *)refNode
1823 int exceptionCode = 0;
1824 [self _rangeImpl]->setEndAfter([refNode _nodeImpl], exceptionCode);
1825 raiseOnDOMError(exceptionCode);
1828 - (void)collapse:(BOOL)toStart
1830 int exceptionCode = 0;
1831 [self _rangeImpl]->collapse(toStart, exceptionCode);
1832 raiseOnDOMError(exceptionCode);
1835 - (void)selectNode:(DOMNode *)refNode
1837 int exceptionCode = 0;
1838 [self _rangeImpl]->selectNode([refNode _nodeImpl], exceptionCode);
1839 raiseOnDOMError(exceptionCode);
1842 - (void)selectNodeContents:(DOMNode *)refNode
1844 int exceptionCode = 0;
1845 [self _rangeImpl]->selectNodeContents([refNode _nodeImpl], exceptionCode);
1846 raiseOnDOMError(exceptionCode);
1849 - (short)compareBoundaryPoints:(unsigned short)how :(DOMRange *)sourceRange
1851 int exceptionCode = 0;
1852 short result = [self _rangeImpl]->compareBoundaryPoints(static_cast<Range::CompareHow>(how), [sourceRange _rangeImpl], exceptionCode);
1853 raiseOnDOMError(exceptionCode);
1857 - (void)deleteContents
1859 int exceptionCode = 0;
1860 [self _rangeImpl]->deleteContents(exceptionCode);
1861 raiseOnDOMError(exceptionCode);
1864 - (DOMDocumentFragment *)extractContents
1866 int exceptionCode = 0;
1867 DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->extractContents(exceptionCode)];
1868 raiseOnDOMError(exceptionCode);
1872 - (DOMDocumentFragment *)cloneContents
1874 int exceptionCode = 0;
1875 DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->cloneContents(exceptionCode)];
1876 raiseOnDOMError(exceptionCode);
1880 - (void)insertNode:(DOMNode *)newNode
1882 int exceptionCode = 0;
1883 [self _rangeImpl]->insertNode([newNode _nodeImpl], exceptionCode);
1884 raiseOnDOMError(exceptionCode);
1887 - (void)surroundContents:(DOMNode *)newParent
1889 int exceptionCode = 0;
1890 [self _rangeImpl]->surroundContents([newParent _nodeImpl], exceptionCode);
1891 raiseOnDOMError(exceptionCode);
1894 - (DOMRange *)cloneRange
1896 int exceptionCode = 0;
1897 DOMRange *result = [DOMRange _rangeWithImpl:[self _rangeImpl]->cloneRange(exceptionCode)];
1898 raiseOnDOMError(exceptionCode);
1902 - (NSString *)toString
1904 int exceptionCode = 0;
1905 NSString *result = [self _rangeImpl]->toString(exceptionCode);
1906 raiseOnDOMError(exceptionCode);
1912 int exceptionCode = 0;
1913 [self _rangeImpl]->detach(exceptionCode);
1914 raiseOnDOMError(exceptionCode);
1919 @implementation DOMRange (WebCoreInternal)
1921 - (id)_initWithRangeImpl:(RangeImpl *)impl
1926 _internal = DOM_cast<DOMObjectInternal *>(impl);
1928 addDOMWrapper(self, impl);
1932 + (DOMRange *)_rangeWithImpl:(RangeImpl *)impl
1938 cachedInstance = getDOMWrapper(impl);
1940 return [[cachedInstance retain] autorelease];
1942 return [[[self alloc] _initWithRangeImpl:impl] autorelease];
1945 - (RangeImpl *)_rangeImpl
1947 return DOM_cast<RangeImpl *>(_internal);
1952 @implementation DOMRange (WebPrivate)
1956 return [self _rangeImpl]->text().string().getNSString();
1961 //------------------------------------------------------------------------------------------
1963 //------------------------------------------------------------------------------------------
1965 @implementation DOMNodeFilter
1967 - (id)_initWithNodeFilterImpl:(NodeFilterImpl *)impl
1972 _internal = DOM_cast<DOMObjectInternal *>(impl);
1974 addDOMWrapper(self, impl);
1978 + (DOMNodeFilter *)_nodeFilterWithImpl:(NodeFilterImpl *)impl
1984 cachedInstance = getDOMWrapper(impl);
1986 return [[cachedInstance retain] autorelease];
1988 return [[[self alloc] _initWithNodeFilterImpl:impl] autorelease];
1991 - (NodeFilterImpl *)_nodeFilterImpl
1993 return DOM_cast<NodeFilterImpl *>(_internal);
1999 DOM_cast<NodeFilterImpl *>(_internal)->deref();
2006 DOM_cast<NodeFilterImpl *>(_internal)->deref();
2010 - (short)acceptNode:(DOMNode *)node
2012 return [self _nodeFilterImpl]->acceptNode([node _nodeImpl]);
2018 @implementation DOMNodeIterator
2020 - (id)_initWithNodeIteratorImpl:(NodeIteratorImpl *)impl filter:(id <DOMNodeFilter>)filter
2025 _internal = DOM_cast<DOMObjectInternal *>(impl);
2027 addDOMWrapper(self, impl);
2028 m_filter = [filter retain];
2032 - (NodeIteratorImpl *)_nodeIteratorImpl
2034 return DOM_cast<NodeIteratorImpl *>(_internal);
2042 DOM_cast<NodeIteratorImpl *>(_internal)->deref();
2051 DOM_cast<NodeIteratorImpl *>(_internal)->deref();
2058 return [DOMNode _nodeWithImpl:[self _nodeIteratorImpl]->root()];
2061 - (unsigned long)whatToShow
2063 return [self _nodeIteratorImpl]->whatToShow();
2066 - (id <DOMNodeFilter>)filter
2069 // This node iterator was created from the objc side
2070 return [[m_filter retain] autorelease];
2072 // This node iterator was created from the c++ side
2073 return [DOMNodeFilter _nodeFilterWithImpl:[self _nodeIteratorImpl]->filter()];
2076 - (BOOL)expandEntityReferences
2078 return [self _nodeIteratorImpl]->expandEntityReferences();
2081 - (DOMNode *)nextNode
2083 int exceptionCode = 0;
2084 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeIteratorImpl]->nextNode(exceptionCode)];
2085 raiseOnDOMError(exceptionCode);
2089 - (DOMNode *)previousNode
2091 int exceptionCode = 0;
2092 DOMNode *result = [DOMNode _nodeWithImpl:[self _nodeIteratorImpl]->previousNode(exceptionCode)];
2093 raiseOnDOMError(exceptionCode);
2099 int exceptionCode = 0;
2100 [self _nodeIteratorImpl]->detach(exceptionCode);
2101 raiseOnDOMError(exceptionCode);
2106 @implementation DOMNodeIterator(WebCoreInternal)
2108 + (DOMNodeIterator *)_nodeIteratorWithImpl:(NodeIteratorImpl *)impl filter:(id <DOMNodeFilter>)filter
2114 cachedInstance = getDOMWrapper(impl);
2116 return [[cachedInstance retain] autorelease];
2118 return [[[self alloc] _initWithNodeIteratorImpl:impl filter:filter] autorelease];
2123 @implementation DOMTreeWalker
2125 - (id)_initWithTreeWalkerImpl:(TreeWalkerImpl *)impl filter:(id <DOMNodeFilter>)filter
2130 _internal = DOM_cast<DOMObjectInternal *>(impl);
2132 addDOMWrapper(self, impl);
2133 m_filter = [filter retain];
2137 - (TreeWalkerImpl *)_treeWalkerImpl
2139 return DOM_cast<TreeWalkerImpl *>(_internal);
2147 DOM_cast<TreeWalkerImpl *>(_internal)->deref();
2155 DOM_cast<TreeWalkerImpl *>(_internal)->deref();
2162 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->root()];
2165 - (unsigned long)whatToShow
2167 return [self _treeWalkerImpl]->whatToShow();
2170 - (id <DOMNodeFilter>)filter
2173 // This tree walker was created from the objc side
2174 return [[m_filter retain] autorelease];
2176 // This tree walker was created from the c++ side
2177 return [DOMNodeFilter _nodeFilterWithImpl:[self _treeWalkerImpl]->filter()];
2180 - (BOOL)expandEntityReferences
2182 return [self _treeWalkerImpl]->expandEntityReferences();
2185 - (DOMNode *)currentNode
2187 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->currentNode()];
2190 - (void)setCurrentNode:(DOMNode *)currentNode
2192 int exceptionCode = 0;
2193 [self _treeWalkerImpl]->setCurrentNode([currentNode _nodeImpl], exceptionCode);
2194 raiseOnDOMError(exceptionCode);
2197 - (DOMNode *)parentNode
2199 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->parentNode()];
2202 - (DOMNode *)firstChild
2204 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->firstChild()];
2207 - (DOMNode *)lastChild
2209 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->lastChild()];
2212 - (DOMNode *)previousSibling
2214 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->previousSibling()];
2217 - (DOMNode *)nextSibling
2219 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->nextSibling()];
2222 - (DOMNode *)previousNode
2224 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->previousNode()];
2227 - (DOMNode *)nextNode
2229 return [DOMNode _nodeWithImpl:[self _treeWalkerImpl]->nextNode()];
2234 @implementation DOMTreeWalker (WebCoreInternal)
2236 + (DOMTreeWalker *)_treeWalkerWithImpl:(TreeWalkerImpl *)impl filter:(id <DOMNodeFilter>)filter
2242 cachedInstance = getDOMWrapper(impl);
2244 return [[cachedInstance retain] autorelease];
2246 return [[[self alloc] _initWithTreeWalkerImpl:impl filter:filter] autorelease];
2251 class ObjCNodeFilterCondition : public NodeFilterCondition
2254 ObjCNodeFilterCondition(id <DOMNodeFilter>);
2255 virtual ~ObjCNodeFilterCondition();
2256 virtual short acceptNode(const Node &) const;
2259 ObjCNodeFilterCondition(const ObjCNodeFilterCondition &);
2260 ObjCNodeFilterCondition &operator=(const ObjCNodeFilterCondition &);
2262 id <DOMNodeFilter> m_filter;
2265 ObjCNodeFilterCondition::ObjCNodeFilterCondition(id <DOMNodeFilter> filter)
2272 ObjCNodeFilterCondition::~ObjCNodeFilterCondition()
2274 CFRelease(m_filter);
2277 short ObjCNodeFilterCondition::acceptNode(const Node &n) const
2280 return NodeFilter::FILTER_REJECT;
2282 return [m_filter acceptNode:[DOMNode _nodeWithImpl:n.handle()]];
2285 @implementation DOMDocument (DOMDocumentTraversal)
2287 - (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned long)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
2289 NodeFilter cppFilter;
2291 cppFilter = NodeFilter(new ObjCNodeFilterCondition(filter));
2292 int exceptionCode = 0;
2293 NodeIteratorImpl *impl = [self _documentImpl]->createNodeIterator([root _nodeImpl], whatToShow, cppFilter.handle(), expandEntityReferences, exceptionCode);
2294 raiseOnDOMError(exceptionCode);
2295 return [DOMNodeIterator _nodeIteratorWithImpl:impl filter:filter];
2298 - (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned long)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
2300 NodeFilter cppFilter;
2302 cppFilter = NodeFilter(new ObjCNodeFilterCondition(filter));
2303 int exceptionCode = 0;
2304 TreeWalkerImpl *impl = [self _documentImpl]->createTreeWalker([root _nodeImpl], whatToShow, cppFilter.handle(), expandEntityReferences, exceptionCode);
2305 raiseOnDOMError(exceptionCode);
2306 return [DOMTreeWalker _treeWalkerWithImpl:impl filter:filter];