2
* Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3
* Copyright (C) 2006 James G. Speth (speth@end.com)
4
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
#import "CDATASection.h"
33
#import "CSSStyleSheet.h"
35
#import "DOMHTMLCanvasElement.h"
36
#import "DOMInternal.h"
37
#import "DOMPrivate.h"
39
#import "DocumentFragment.h"
40
#import "DocumentType.h"
41
#import "EntityReference.h"
43
#import "EventListener.h"
44
#import "EventTarget.h"
45
#import "ExceptionHandlers.h"
47
#import "FoundationExtras.h"
50
#import "HTMLDocument.h"
52
#import "HTMLPlugInElement.h"
55
#import "NodeFilter.h"
56
#import "NodeFilterCondition.h"
57
#import "NodeIterator.h"
59
#import "ProcessingInstruction.h"
60
#import "QualifiedName.h"
62
#import "RenderImage.h"
63
#import "RenderView.h"
65
#import "TreeWalker.h"
66
#import "WebScriptObjectPrivate.h"
67
#import <objc/objc-class.h>
68
#import <wtf/HashMap.h>
71
#import "SVGDocument.h"
72
#import "SVGElement.h"
78
class ObjCEventListener : public EventListener {
80
static ObjCEventListener* find(id <DOMEventListener>);
81
static ObjCEventListener* create(id <DOMEventListener>);
84
ObjCEventListener(id <DOMEventListener>);
85
virtual ~ObjCEventListener();
87
virtual void handleEvent(Event*, bool isWindowEvent);
89
id <DOMEventListener> m_listener;
92
typedef HashMap<id, ObjCEventListener*> ListenerMap;
93
static ListenerMap* listenerMap;
95
} // namespace WebCore
98
//------------------------------------------------------------------------------------------
103
typedef HashMap<const QualifiedName::QualifiedNameImpl*, Class> ObjCClassMap;
104
static ObjCClassMap* elementClassMap;
106
static void addElementClass(const QualifiedName& tag, Class objCClass)
108
elementClassMap->set(tag.impl(), objCClass);
111
static void createElementClassMap()
114
elementClassMap = new ObjCClassMap;
116
// FIXME: Reflect marquee once the API has been determined.
118
// Populate it with HTML and SVG element classes.
119
addElementClass(HTMLNames::aTag, [DOMHTMLAnchorElement class]);
120
addElementClass(HTMLNames::appletTag, [DOMHTMLAppletElement class]);
121
addElementClass(HTMLNames::areaTag, [DOMHTMLAreaElement class]);
122
addElementClass(HTMLNames::baseTag, [DOMHTMLBaseElement class]);
123
addElementClass(HTMLNames::basefontTag, [DOMHTMLBaseFontElement class]);
124
addElementClass(HTMLNames::bodyTag, [DOMHTMLBodyElement class]);
125
addElementClass(HTMLNames::brTag, [DOMHTMLBRElement class]);
126
addElementClass(HTMLNames::buttonTag, [DOMHTMLButtonElement class]);
127
addElementClass(HTMLNames::canvasTag, [DOMHTMLCanvasElement class]);
128
addElementClass(HTMLNames::captionTag, [DOMHTMLTableCaptionElement class]);
129
addElementClass(HTMLNames::colTag, [DOMHTMLTableColElement class]);
130
addElementClass(HTMLNames::colgroupTag, [DOMHTMLTableColElement class]);
131
addElementClass(HTMLNames::delTag, [DOMHTMLModElement class]);
132
addElementClass(HTMLNames::dirTag, [DOMHTMLDirectoryElement class]);
133
addElementClass(HTMLNames::divTag, [DOMHTMLDivElement class]);
134
addElementClass(HTMLNames::dlTag, [DOMHTMLDListElement class]);
135
addElementClass(HTMLNames::embedTag, [DOMHTMLEmbedElement class]);
136
addElementClass(HTMLNames::fieldsetTag, [DOMHTMLFieldSetElement class]);
137
addElementClass(HTMLNames::fontTag, [DOMHTMLFontElement class]);
138
addElementClass(HTMLNames::formTag, [DOMHTMLFormElement class]);
139
addElementClass(HTMLNames::frameTag, [DOMHTMLFrameElement class]);
140
addElementClass(HTMLNames::framesetTag, [DOMHTMLFrameSetElement class]);
141
addElementClass(HTMLNames::h1Tag, [DOMHTMLHeadingElement class]);
142
addElementClass(HTMLNames::h2Tag, [DOMHTMLHeadingElement class]);
143
addElementClass(HTMLNames::h3Tag, [DOMHTMLHeadingElement class]);
144
addElementClass(HTMLNames::h4Tag, [DOMHTMLHeadingElement class]);
145
addElementClass(HTMLNames::h5Tag, [DOMHTMLHeadingElement class]);
146
addElementClass(HTMLNames::h6Tag, [DOMHTMLHeadingElement class]);
147
addElementClass(HTMLNames::headTag, [DOMHTMLHeadElement class]);
148
addElementClass(HTMLNames::hrTag, [DOMHTMLHRElement class]);
149
addElementClass(HTMLNames::htmlTag, [DOMHTMLHtmlElement class]);
150
addElementClass(HTMLNames::iframeTag, [DOMHTMLIFrameElement class]);
151
addElementClass(HTMLNames::imgTag, [DOMHTMLImageElement class]);
152
addElementClass(HTMLNames::inputTag, [DOMHTMLInputElement class]);
153
addElementClass(HTMLNames::insTag, [DOMHTMLModElement class]);
154
addElementClass(HTMLNames::isindexTag, [DOMHTMLIsIndexElement class]);
155
addElementClass(HTMLNames::labelTag, [DOMHTMLLabelElement class]);
156
addElementClass(HTMLNames::legendTag, [DOMHTMLLegendElement class]);
157
addElementClass(HTMLNames::liTag, [DOMHTMLLIElement class]);
158
addElementClass(HTMLNames::linkTag, [DOMHTMLLinkElement class]);
159
addElementClass(HTMLNames::listingTag, [DOMHTMLPreElement class]);
160
addElementClass(HTMLNames::mapTag, [DOMHTMLMapElement class]);
161
addElementClass(HTMLNames::marqueeTag, [DOMHTMLMarqueeElement class]);
162
addElementClass(HTMLNames::menuTag, [DOMHTMLMenuElement class]);
163
addElementClass(HTMLNames::metaTag, [DOMHTMLMetaElement class]);
164
addElementClass(HTMLNames::objectTag, [DOMHTMLObjectElement class]);
165
addElementClass(HTMLNames::olTag, [DOMHTMLOListElement class]);
166
addElementClass(HTMLNames::optgroupTag, [DOMHTMLOptGroupElement class]);
167
addElementClass(HTMLNames::optionTag, [DOMHTMLOptionElement class]);
168
addElementClass(HTMLNames::pTag, [DOMHTMLParagraphElement class]);
169
addElementClass(HTMLNames::paramTag, [DOMHTMLParamElement class]);
170
addElementClass(HTMLNames::preTag, [DOMHTMLPreElement class]);
171
addElementClass(HTMLNames::qTag, [DOMHTMLQuoteElement class]);
172
addElementClass(HTMLNames::scriptTag, [DOMHTMLScriptElement class]);
173
addElementClass(HTMLNames::keygenTag, [DOMHTMLSelectElement class]);
174
addElementClass(HTMLNames::selectTag, [DOMHTMLSelectElement class]);
175
addElementClass(HTMLNames::styleTag, [DOMHTMLStyleElement class]);
176
addElementClass(HTMLNames::tableTag, [DOMHTMLTableElement class]);
177
addElementClass(HTMLNames::tbodyTag, [DOMHTMLTableSectionElement class]);
178
addElementClass(HTMLNames::tdTag, [DOMHTMLTableCellElement class]);
179
addElementClass(HTMLNames::textareaTag, [DOMHTMLTextAreaElement class]);
180
addElementClass(HTMLNames::tfootTag, [DOMHTMLTableSectionElement class]);
181
addElementClass(HTMLNames::thTag, [DOMHTMLTableCellElement class]);
182
addElementClass(HTMLNames::theadTag, [DOMHTMLTableSectionElement class]);
183
addElementClass(HTMLNames::titleTag, [DOMHTMLTitleElement class]);
184
addElementClass(HTMLNames::trTag, [DOMHTMLTableRowElement class]);
185
addElementClass(HTMLNames::ulTag, [DOMHTMLUListElement class]);
186
addElementClass(HTMLNames::xmpTag, [DOMHTMLPreElement class]);
189
addElementClass(SVGNames::aTag, [DOMSVGAElement class]);
190
#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
191
addElementClass(SVGNames::animateTag, [DOMSVGAnimateElement class]);
192
addElementClass(SVGNames::animateColorTag, [DOMSVGAnimateColorElement class]);
193
addElementClass(SVGNames::animateTransformTag, [DOMSVGAnimateTransformElement class]);
195
addElementClass(SVGNames::circleTag, [DOMSVGCircleElement class]);
196
addElementClass(SVGNames::clipPathTag, [DOMSVGClipPathElement class]);
197
addElementClass(SVGNames::cursorTag, [DOMSVGCursorElement class]);
198
addElementClass(SVGNames::defsTag, [DOMSVGDefsElement class]);
199
addElementClass(SVGNames::descTag, [DOMSVGDescElement class]);
200
addElementClass(SVGNames::ellipseTag, [DOMSVGEllipseElement class]);
201
#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
202
addElementClass(SVGNames::feBlendTag, [DOMSVGFEBlendElement class]);
203
addElementClass(SVGNames::feColorMatrixTag, [DOMSVGFEColorMatrixElement class]);
204
addElementClass(SVGNames::feComponentTransferTag, [DOMSVGFEComponentTransferElement class]);
205
addElementClass(SVGNames::feCompositeTag, [DOMSVGFECompositeElement class]);
206
addElementClass(SVGNames::feDiffuseLightingTag, [DOMSVGFEDiffuseLightingElement class]);
207
addElementClass(SVGNames::feDisplacementMapTag, [DOMSVGFEDisplacementMapElement class]);
208
addElementClass(SVGNames::feDistantLightTag, [DOMSVGFEDistantLightElement class]);
209
addElementClass(SVGNames::feFloodTag, [DOMSVGFEFloodElement class]);
210
addElementClass(SVGNames::feFuncATag, [DOMSVGFEFuncAElement class]);
211
addElementClass(SVGNames::feFuncBTag, [DOMSVGFEFuncBElement class]);
212
addElementClass(SVGNames::feFuncGTag, [DOMSVGFEFuncGElement class]);
213
addElementClass(SVGNames::feFuncRTag, [DOMSVGFEFuncRElement class]);
214
addElementClass(SVGNames::feGaussianBlurTag, [DOMSVGFEGaussianBlurElement class]);
215
addElementClass(SVGNames::feImageTag, [DOMSVGFEImageElement class]);
216
addElementClass(SVGNames::feMergeTag, [DOMSVGFEMergeElement class]);
217
addElementClass(SVGNames::feMergeNodeTag, [DOMSVGFEMergeNodeElement class]);
218
addElementClass(SVGNames::feOffsetTag, [DOMSVGFEOffsetElement class]);
219
addElementClass(SVGNames::fePointLightTag, [DOMSVGFEPointLightElement class]);
220
addElementClass(SVGNames::feSpecularLightingTag, [DOMSVGFESpecularLightingElement class]);
221
addElementClass(SVGNames::feSpotLightTag, [DOMSVGFESpotLightElement class]);
222
addElementClass(SVGNames::feTileTag, [DOMSVGFETileElement class]);
223
addElementClass(SVGNames::feTurbulenceTag, [DOMSVGFETurbulenceElement class]);
224
addElementClass(SVGNames::filterTag, [DOMSVGFilterElement class]);
225
addElementClass(SVGNames::foreignObjectTag, [DOMSVGForeignObjectElement class]);
227
addElementClass(SVGNames::gTag, [DOMSVGGElement class]);
228
addElementClass(SVGNames::imageTag, [DOMSVGImageElement class]);
229
addElementClass(SVGNames::lineTag, [DOMSVGLineElement class]);
230
addElementClass(SVGNames::linearGradientTag, [DOMSVGLinearGradientElement class]);
231
addElementClass(SVGNames::markerTag, [DOMSVGMarkerElement class]);
232
addElementClass(SVGNames::maskTag, [DOMSVGMaskElement class]);
233
addElementClass(SVGNames::metadataTag, [DOMSVGMetadataElement class]);
234
addElementClass(SVGNames::pathTag, [DOMSVGPathElement class]);
235
addElementClass(SVGNames::patternTag, [DOMSVGPatternElement class]);
236
addElementClass(SVGNames::polygonTag, [DOMSVGPolygonElement class]);
237
addElementClass(SVGNames::polylineTag, [DOMSVGPolylineElement class]);
238
addElementClass(SVGNames::radialGradientTag, [DOMSVGRadialGradientElement class]);
239
addElementClass(SVGNames::rectTag, [DOMSVGRectElement class]);
240
addElementClass(SVGNames::scriptTag, [DOMSVGScriptElement class]);
241
addElementClass(SVGNames::setTag, [DOMSVGSetElement class]);
242
addElementClass(SVGNames::stopTag, [DOMSVGStopElement class]);
243
addElementClass(SVGNames::styleTag, [DOMSVGStyleElement class]);
244
addElementClass(SVGNames::svgTag, [DOMSVGSVGElement class]);
245
addElementClass(SVGNames::switchTag, [DOMSVGSwitchElement class]);
246
addElementClass(SVGNames::symbolTag, [DOMSVGSymbolElement class]);
247
addElementClass(SVGNames::textTag, [DOMSVGTextElement class]);
248
addElementClass(SVGNames::titleTag, [DOMSVGTitleElement class]);
249
addElementClass(SVGNames::trefTag, [DOMSVGTRefElement class]);
250
addElementClass(SVGNames::tspanTag, [DOMSVGTSpanElement class]);
251
addElementClass(SVGNames::useTag, [DOMSVGUseElement class]);
252
addElementClass(SVGNames::viewTag, [DOMSVGViewElement class]);
256
static Class elementClass(const QualifiedName& tag, Class defaultClass)
258
if (!elementClassMap)
259
createElementClassMap();
260
Class objcClass = elementClassMap->get(tag.impl());
262
objcClass = defaultClass;
266
static NSArray *kit(const Vector<IntRect>& rects)
268
size_t size = rects.size();
269
NSMutableArray *array = [NSMutableArray arrayWithCapacity:size];
270
for (size_t i = 0; i < size; ++i)
271
[array addObject:[NSValue valueWithRect:rects[i]]];
275
} // namespace WebCore
277
@implementation DOMNode (WebCoreInternal)
279
// FIXME: should this go in the main implementation?
280
- (NSString *)description
283
return [NSString stringWithFormat:@"<%@: null>", [[self class] description], self];
285
NSString *value = [self nodeValue];
287
return [NSString stringWithFormat:@"<%@ [%@]: %p '%@'>",
288
[[self class] description], [self nodeName], _internal, value];
290
return [NSString stringWithFormat:@"<%@ [%@]: %p>", [[self class] description], [self nodeName], _internal];
293
- (id)_initWithNode:(WebCore::Node *)impl
298
_internal = reinterpret_cast<DOMObjectInternal*>(impl);
300
WebCore::addDOMWrapper(self, impl);
304
+ (DOMNode *)_wrapNode:(WebCore::Node *)impl
310
cachedInstance = WebCore::getDOMWrapper(impl);
312
return [[cachedInstance retain] autorelease];
314
Class wrapperClass = nil;
315
switch (impl->nodeType()) {
316
case WebCore::Node::ELEMENT_NODE:
317
if (impl->isHTMLElement())
318
wrapperClass = WebCore::elementClass(static_cast<WebCore::HTMLElement*>(impl)->tagQName(), [DOMHTMLElement class]);
320
else if (impl->isSVGElement())
321
wrapperClass = WebCore::elementClass(static_cast<WebCore::SVGElement*>(impl)->tagQName(), [DOMSVGElement class]);
324
wrapperClass = [DOMElement class];
326
case WebCore::Node::ATTRIBUTE_NODE:
327
wrapperClass = [DOMAttr class];
329
case WebCore::Node::TEXT_NODE:
330
wrapperClass = [DOMText class];
332
case WebCore::Node::CDATA_SECTION_NODE:
333
wrapperClass = [DOMCDATASection class];
335
case WebCore::Node::ENTITY_REFERENCE_NODE:
336
wrapperClass = [DOMEntityReference class];
338
case WebCore::Node::ENTITY_NODE:
339
wrapperClass = [DOMEntity class];
341
case WebCore::Node::PROCESSING_INSTRUCTION_NODE:
342
wrapperClass = [DOMProcessingInstruction class];
344
case WebCore::Node::COMMENT_NODE:
345
wrapperClass = [DOMComment class];
347
case WebCore::Node::DOCUMENT_NODE:
348
if (static_cast<WebCore::Document*>(impl)->isHTMLDocument())
349
wrapperClass = [DOMHTMLDocument class];
351
else if (static_cast<WebCore::Document*>(impl)->isSVGDocument())
352
wrapperClass = [DOMSVGDocument class];
355
wrapperClass = [DOMDocument class];
357
case WebCore::Node::DOCUMENT_TYPE_NODE:
358
wrapperClass = [DOMDocumentType class];
360
case WebCore::Node::DOCUMENT_FRAGMENT_NODE:
361
wrapperClass = [DOMDocumentFragment class];
363
case WebCore::Node::NOTATION_NODE:
364
wrapperClass = [DOMNotation class];
366
case WebCore::Node::XPATH_NAMESPACE_NODE:
367
// FIXME: Create an XPath objective C wrapper
368
// See http://bugs.webkit.org/show_bug.cgi?id=8755
371
return [[[wrapperClass alloc] _initWithNode:impl] autorelease];
374
+ (id <DOMEventTarget>)_wrapEventTarget:(WebCore::EventTarget *)eventTarget
379
// We don't have an ObjC binding for XMLHttpRequest
380
return [DOMNode _wrapNode:eventTarget->toNode()];
383
- (WebCore::Node *)_node
385
return reinterpret_cast<WebCore::Node*>(_internal);
388
- (KJS::Bindings::RootObject*)_rootObject
390
if (WebCore::Node *n = [self _node]) {
391
if (WebCore::Frame* frame = n->document()->frame())
392
return frame->bindingRootObject();
399
@implementation DOMNode (DOMNodeExtensions)
401
// FIXME: This should be implemented in Node so we don't have to fetch the renderer.
402
// If it was, we could even autogenerate.
403
- (NSRect)boundingBox
405
[self _node]->document()->updateLayoutIgnorePendingStylesheets();
406
WebCore::RenderObject *renderer = [self _node]->renderer();
408
return renderer->absoluteBoundingBoxRect();
412
// FIXME: This should be implemented in Node so we don't have to fetch the renderer.
413
// If it was, we could even autogenerate.
414
- (NSArray *)lineBoxRects
416
[self _node]->document()->updateLayoutIgnorePendingStylesheets();
417
WebCore::RenderObject *renderer = [self _node]->renderer();
419
Vector<WebCore::IntRect> rects;
420
renderer->addLineBoxRects(rects);
428
@implementation DOMRange (DOMRangeExtensions)
430
- (NSRect)boundingBox
432
[self _range]->ownerDocument()->updateLayoutIgnorePendingStylesheets();
433
return [self _range]->boundingBox();
436
- (NSArray *)lineBoxRects
438
Vector<WebCore::IntRect> rects;
439
[self _range]->ownerDocument()->updateLayoutIgnorePendingStylesheets();
440
[self _range]->addLineBoxRects(rects);
446
// FIXME: this should be auto-generated
447
@implementation DOMNode (DOMEventTarget)
449
- (void)addEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture
451
if (![self _node]->isEventTargetNode())
452
WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR);
454
WebCore::EventListener *wrapper = WebCore::ObjCEventListener::create(listener);
455
WebCore::EventTargetNodeCast([self _node])->addEventListener(type, wrapper, useCapture);
459
- (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
461
// FIXME: this method can be removed once Mail changes to use the new method <rdar://problem/4746649>
462
[self addEventListener:type listener:listener useCapture:useCapture];
465
- (void)removeEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture
467
if (![self _node]->isEventTargetNode())
468
WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR);
470
if (WebCore::EventListener *wrapper = WebCore::ObjCEventListener::find(listener))
471
WebCore::EventTargetNodeCast([self _node])->removeEventListener(type, wrapper, useCapture);
474
- (void)removeEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
476
// FIXME: this method can be removed once Mail changes to use the new method <rdar://problem/4746649>
477
[self removeEventListener:type listener:listener useCapture:useCapture];
480
- (BOOL)dispatchEvent:(DOMEvent *)event
482
if (![self _node]->isEventTargetNode())
483
WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR);
485
WebCore::ExceptionCode ec = 0;
486
BOOL result = WebCore::EventTargetNodeCast([self _node])->dispatchEvent([event _event], ec);
487
WebCore::raiseOnDOMError(ec);
493
//------------------------------------------------------------------------------------------
496
// FIXME: this should be auto-generated in DOMElement.mm
497
@implementation DOMElement (DOMElementAppKitExtensions)
499
// FIXME: this should be implemented in the implementation
502
WebCore::RenderObject* renderer = [self _element]->renderer();
503
if (renderer && renderer->isImage()) {
504
WebCore::RenderImage* img = static_cast<WebCore::RenderImage*>(renderer);
505
if (img->cachedImage() && !img->cachedImage()->errorOccurred())
506
return img->cachedImage()->image()->getNSImage();
513
@implementation DOMElement (WebPrivate)
515
// FIXME: this should be implemented in the implementation
518
WebCore::RenderObject* renderer = [self _element]->renderer();
520
return renderer->style()->font().primaryFont()->getNSFont();
524
// FIXME: this should be implemented in the implementation
525
- (NSData *)_imageTIFFRepresentation
527
WebCore::RenderObject* renderer = [self _element]->renderer();
528
if (renderer && renderer->isImage()) {
529
WebCore::RenderImage* img = static_cast<WebCore::RenderImage*>(renderer);
530
if (img->cachedImage() && !img->cachedImage()->errorOccurred())
531
return (NSData*)(img->cachedImage()->image()->getTIFFRepresentation());
536
- (NSRect)_windowClipRect
538
WebCore::RenderObject* renderer = [self _element]->renderer();
539
if (renderer && renderer->view()) {
540
WebCore::FrameView* frameView = renderer->view()->frameView();
542
return WebCore::IntRect();
543
return frameView->windowClipRectForLayer(renderer->enclosingLayer(), true);
545
return WebCore::IntRect();
548
// FIXME: this should be implemented in the implementation
549
- (NSURL *)_getURLAttribute:(NSString *)name
552
WebCore::Element* element = [self _element];
554
return WebCore::KURL(element->document()->completeURL(parseURL(element->getAttribute(name)).deprecatedString())).getNSURL();
557
// FIXME: this should be implemented in the implementation
561
WebCore::Element* element = [self _element];
562
if (element->hasTagName(WebCore::HTMLNames::appletTag) || element->hasTagName(WebCore::HTMLNames::embedTag) || element->hasTagName(WebCore::HTMLNames::objectTag))
563
return static_cast<WebCore::HTMLPlugInElement*>(element)->getNPObject();
568
// FIXME: this should be implemented in the implementation
571
WebCore::Element* impl = [self _element];
572
if (impl->document()->focusedNode() == impl)
580
//------------------------------------------------------------------------------------------
583
@implementation DOMRange (WebPrivate)
585
- (NSString *)description
588
return @"<DOMRange: null>";
589
return [NSString stringWithFormat:@"<DOMRange: %@ %d %@ %d>",
590
[self startContainer], [self startOffset], [self endContainer], [self endOffset]];
593
// FIXME: this should be removed as soon as all internal Apple uses of it have been replaced with
594
// calls to the public method - (NSString *)text.
603
//------------------------------------------------------------------------------------------
606
// FIXME: This implementation should be in it's own file.
608
@implementation DOMNodeFilter
610
- (id)_initWithNodeFilter:(WebCore::NodeFilter *)impl
615
_internal = reinterpret_cast<DOMObjectInternal*>(impl);
617
WebCore::addDOMWrapper(self, impl);
621
+ (DOMNodeFilter *)_wrapNodeFilter:(WebCore::NodeFilter *)impl
627
cachedInstance = WebCore::getDOMWrapper(impl);
629
return [[cachedInstance retain] autorelease];
631
return [[[self alloc] _initWithNodeFilter:impl] autorelease];
634
- (WebCore::NodeFilter *)_nodeFilter
636
return reinterpret_cast<WebCore::NodeFilter*>(_internal);
642
reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref();
649
reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref();
653
- (short)acceptNode:(DOMNode *)node
655
return [self _nodeFilter]->acceptNode([node _node]);
661
//------------------------------------------------------------------------------------------
662
// ObjCNodeFilterCondition
664
class ObjCNodeFilterCondition : public WebCore::NodeFilterCondition {
666
ObjCNodeFilterCondition(id <DOMNodeFilter>);
667
virtual ~ObjCNodeFilterCondition();
668
virtual short acceptNode(WebCore::Node*) const;
671
ObjCNodeFilterCondition(const ObjCNodeFilterCondition&);
672
ObjCNodeFilterCondition &operator=(const ObjCNodeFilterCondition&);
674
id <DOMNodeFilter> m_filter;
677
ObjCNodeFilterCondition::ObjCNodeFilterCondition(id <DOMNodeFilter> filter)
681
HardRetain(m_filter);
684
ObjCNodeFilterCondition::~ObjCNodeFilterCondition()
686
HardRelease(m_filter);
689
short ObjCNodeFilterCondition::acceptNode(WebCore::Node* node) const
692
return WebCore::NodeFilter::FILTER_REJECT;
693
return [m_filter acceptNode:[DOMNode _wrapNode:node]];
697
//------------------------------------------------------------------------------------------
698
// DOMDocument (DOMDocumentTraversal)
700
// FIXME: this should be auto-generated in DOMDocument.mm
701
@implementation DOMDocument (DOMDocumentTraversal)
703
- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences
705
WebCore::NodeFilter* cppFilter = 0;
707
cppFilter = new WebCore::NodeFilter(new ObjCNodeFilterCondition(filter));
708
WebCore::ExceptionCode ec = 0;
709
RefPtr<WebCore::NodeIterator> impl = [self _document]->createNodeIterator([root _node], whatToShow, cppFilter, expandEntityReferences, ec);
710
WebCore::raiseOnDOMError(ec);
711
return [DOMNodeIterator _wrapNodeIterator:impl.get() filter:filter];
714
- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences
716
WebCore::NodeFilter* cppFilter = 0;
718
cppFilter = new WebCore::NodeFilter(new ObjCNodeFilterCondition(filter));
719
WebCore::ExceptionCode ec = 0;
720
RefPtr<WebCore::TreeWalker> impl = [self _document]->createTreeWalker([root _node], whatToShow, cppFilter, expandEntityReferences, ec);
721
WebCore::raiseOnDOMError(ec);
722
return [DOMTreeWalker _wrapTreeWalker:impl.get() filter:filter];
727
@implementation DOMDocument (DOMDocumentTraversalDeprecated)
729
- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
731
return [self createNodeIterator:root whatToShow:whatToShow filter:filter expandEntityReferences:expandEntityReferences];
734
- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
736
return [self createTreeWalker:root whatToShow:whatToShow filter:filter expandEntityReferences:expandEntityReferences];
742
//------------------------------------------------------------------------------------------
747
ObjCEventListener* ObjCEventListener::find(id <DOMEventListener> listener)
749
if (ListenerMap* map = listenerMap)
750
return map->get(listener);
754
ObjCEventListener *ObjCEventListener::create(id <DOMEventListener> listener)
756
ObjCEventListener* wrapper = find(listener);
758
wrapper = new ObjCEventListener(listener);
763
ObjCEventListener::ObjCEventListener(id <DOMEventListener> listener)
764
: m_listener([listener retain])
766
ListenerMap* map = listenerMap;
768
map = new ListenerMap;
771
map->set(listener, this);
774
ObjCEventListener::~ObjCEventListener()
776
listenerMap->remove(m_listener);
777
[m_listener release];
780
void ObjCEventListener::handleEvent(Event* event, bool)
782
[m_listener handleEvent:[DOMEvent _wrapEvent:event]];
785
} // namespace WebCore