1/* 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 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) 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 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. 26 */ 27 28#import "config.h" 29#import "DOMInternal.h" // import first to make the private/public trick work 30#import "DOM.h" 31 32#import "DOMElementInternal.h" 33#import "DOMHTMLCanvasElement.h" 34#import "DOMNodeInternal.h" 35#import "DOMPrivate.h" 36#import "DOMRangeInternal.h" 37#import "Frame.h" 38#import "HTMLElement.h" 39#import "HTMLNames.h" 40#import "NodeFilter.h" 41#import "RenderImage.h" 42#import "WebScriptObjectPrivate.h" 43#import <wtf/HashMap.h> 44 45#if ENABLE(SVG_DOM_OBJC_BINDINGS) 46#import "DOMSVG.h" 47#import "SVGElementInstance.h" 48#import "SVGNames.h" 49#endif 50 51using namespace JSC; 52using namespace WebCore; 53 54// FIXME: Would be nice to break this up into separate files to match how other WebKit 55// code is organized. 56 57//------------------------------------------------------------------------------------------ 58// DOMNode 59 60namespace WebCore { 61 62typedef HashMap<const QualifiedName::QualifiedNameImpl*, Class> ObjCClassMap; 63static ObjCClassMap* elementClassMap; 64 65static void addElementClass(const QualifiedName& tag, Class objCClass) 66{ 67 elementClassMap->set(tag.impl(), objCClass); 68} 69 70static void createElementClassMap() 71{ 72 // Create the table. 73 elementClassMap = new ObjCClassMap; 74 75 // FIXME: Reflect marquee once the API has been determined. 76 77 // Populate it with HTML and SVG element classes. 78 addElementClass(HTMLNames::aTag, [DOMHTMLAnchorElement class]); 79 addElementClass(HTMLNames::appletTag, [DOMHTMLAppletElement class]); 80 addElementClass(HTMLNames::areaTag, [DOMHTMLAreaElement class]); 81 addElementClass(HTMLNames::baseTag, [DOMHTMLBaseElement class]); 82 addElementClass(HTMLNames::basefontTag, [DOMHTMLBaseFontElement class]); 83 addElementClass(HTMLNames::bodyTag, [DOMHTMLBodyElement class]); 84 addElementClass(HTMLNames::brTag, [DOMHTMLBRElement class]); 85 addElementClass(HTMLNames::buttonTag, [DOMHTMLButtonElement class]); 86 addElementClass(HTMLNames::canvasTag, [DOMHTMLCanvasElement class]); 87 addElementClass(HTMLNames::captionTag, [DOMHTMLTableCaptionElement class]); 88 addElementClass(HTMLNames::colTag, [DOMHTMLTableColElement class]); 89 addElementClass(HTMLNames::colgroupTag, [DOMHTMLTableColElement class]); 90 addElementClass(HTMLNames::delTag, [DOMHTMLModElement class]); 91 addElementClass(HTMLNames::dirTag, [DOMHTMLDirectoryElement class]); 92 addElementClass(HTMLNames::divTag, [DOMHTMLDivElement class]); 93 addElementClass(HTMLNames::dlTag, [DOMHTMLDListElement class]); 94 addElementClass(HTMLNames::embedTag, [DOMHTMLEmbedElement class]); 95 addElementClass(HTMLNames::fieldsetTag, [DOMHTMLFieldSetElement class]); 96 addElementClass(HTMLNames::fontTag, [DOMHTMLFontElement class]); 97 addElementClass(HTMLNames::formTag, [DOMHTMLFormElement class]); 98 addElementClass(HTMLNames::frameTag, [DOMHTMLFrameElement class]); 99 addElementClass(HTMLNames::framesetTag, [DOMHTMLFrameSetElement class]); 100 addElementClass(HTMLNames::h1Tag, [DOMHTMLHeadingElement class]); 101 addElementClass(HTMLNames::h2Tag, [DOMHTMLHeadingElement class]); 102 addElementClass(HTMLNames::h3Tag, [DOMHTMLHeadingElement class]); 103 addElementClass(HTMLNames::h4Tag, [DOMHTMLHeadingElement class]); 104 addElementClass(HTMLNames::h5Tag, [DOMHTMLHeadingElement class]); 105 addElementClass(HTMLNames::h6Tag, [DOMHTMLHeadingElement class]); 106 addElementClass(HTMLNames::headTag, [DOMHTMLHeadElement class]); 107 addElementClass(HTMLNames::hrTag, [DOMHTMLHRElement class]); 108 addElementClass(HTMLNames::htmlTag, [DOMHTMLHtmlElement class]); 109 addElementClass(HTMLNames::iframeTag, [DOMHTMLIFrameElement class]); 110 addElementClass(HTMLNames::imgTag, [DOMHTMLImageElement class]); 111 addElementClass(HTMLNames::inputTag, [DOMHTMLInputElement class]); 112 addElementClass(HTMLNames::insTag, [DOMHTMLModElement class]); 113 addElementClass(HTMLNames::isindexTag, [DOMHTMLIsIndexElement class]); 114 addElementClass(HTMLNames::labelTag, [DOMHTMLLabelElement class]); 115 addElementClass(HTMLNames::legendTag, [DOMHTMLLegendElement class]); 116 addElementClass(HTMLNames::liTag, [DOMHTMLLIElement class]); 117 addElementClass(HTMLNames::linkTag, [DOMHTMLLinkElement class]); 118 addElementClass(HTMLNames::listingTag, [DOMHTMLPreElement class]); 119 addElementClass(HTMLNames::mapTag, [DOMHTMLMapElement class]); 120 addElementClass(HTMLNames::marqueeTag, [DOMHTMLMarqueeElement class]); 121 addElementClass(HTMLNames::menuTag, [DOMHTMLMenuElement class]); 122 addElementClass(HTMLNames::metaTag, [DOMHTMLMetaElement class]); 123 addElementClass(HTMLNames::objectTag, [DOMHTMLObjectElement class]); 124 addElementClass(HTMLNames::olTag, [DOMHTMLOListElement class]); 125 addElementClass(HTMLNames::optgroupTag, [DOMHTMLOptGroupElement class]); 126 addElementClass(HTMLNames::optionTag, [DOMHTMLOptionElement class]); 127 addElementClass(HTMLNames::pTag, [DOMHTMLParagraphElement class]); 128 addElementClass(HTMLNames::paramTag, [DOMHTMLParamElement class]); 129 addElementClass(HTMLNames::preTag, [DOMHTMLPreElement class]); 130 addElementClass(HTMLNames::qTag, [DOMHTMLQuoteElement class]); 131 addElementClass(HTMLNames::scriptTag, [DOMHTMLScriptElement class]); 132 addElementClass(HTMLNames::keygenTag, [DOMHTMLSelectElement class]); 133 addElementClass(HTMLNames::selectTag, [DOMHTMLSelectElement class]); 134 addElementClass(HTMLNames::styleTag, [DOMHTMLStyleElement class]); 135 addElementClass(HTMLNames::tableTag, [DOMHTMLTableElement class]); 136 addElementClass(HTMLNames::tbodyTag, [DOMHTMLTableSectionElement class]); 137 addElementClass(HTMLNames::tdTag, [DOMHTMLTableCellElement class]); 138 addElementClass(HTMLNames::textareaTag, [DOMHTMLTextAreaElement class]); 139 addElementClass(HTMLNames::tfootTag, [DOMHTMLTableSectionElement class]); 140 addElementClass(HTMLNames::thTag, [DOMHTMLTableCellElement class]); 141 addElementClass(HTMLNames::theadTag, [DOMHTMLTableSectionElement class]); 142 addElementClass(HTMLNames::titleTag, [DOMHTMLTitleElement class]); 143 addElementClass(HTMLNames::trTag, [DOMHTMLTableRowElement class]); 144 addElementClass(HTMLNames::ulTag, [DOMHTMLUListElement class]); 145 addElementClass(HTMLNames::xmpTag, [DOMHTMLPreElement class]); 146 147#if ENABLE(SVG_DOM_OBJC_BINDINGS) 148 addElementClass(SVGNames::aTag, [DOMSVGAElement class]); 149 addElementClass(SVGNames::altGlyphTag, [DOMSVGAltGlyphElement class]); 150#if ENABLE(SVG_ANIMATION) 151 addElementClass(SVGNames::animateTag, [DOMSVGAnimateElement class]); 152 addElementClass(SVGNames::animateColorTag, [DOMSVGAnimateColorElement class]); 153 addElementClass(SVGNames::animateTransformTag, [DOMSVGAnimateTransformElement class]); 154 addElementClass(SVGNames::setTag, [DOMSVGSetElement class]); 155#endif 156 addElementClass(SVGNames::circleTag, [DOMSVGCircleElement class]); 157 addElementClass(SVGNames::clipPathTag, [DOMSVGClipPathElement class]); 158 addElementClass(SVGNames::cursorTag, [DOMSVGCursorElement class]); 159 addElementClass(SVGNames::defsTag, [DOMSVGDefsElement class]); 160 addElementClass(SVGNames::descTag, [DOMSVGDescElement class]); 161 addElementClass(SVGNames::ellipseTag, [DOMSVGEllipseElement class]); 162#if ENABLE(FILTERS) 163 addElementClass(SVGNames::feBlendTag, [DOMSVGFEBlendElement class]); 164 addElementClass(SVGNames::feColorMatrixTag, [DOMSVGFEColorMatrixElement class]); 165 addElementClass(SVGNames::feComponentTransferTag, [DOMSVGFEComponentTransferElement class]); 166 addElementClass(SVGNames::feCompositeTag, [DOMSVGFECompositeElement class]); 167 addElementClass(SVGNames::feDiffuseLightingTag, [DOMSVGFEDiffuseLightingElement class]); 168 addElementClass(SVGNames::feDisplacementMapTag, [DOMSVGFEDisplacementMapElement class]); 169 addElementClass(SVGNames::feDistantLightTag, [DOMSVGFEDistantLightElement class]); 170 addElementClass(SVGNames::feFloodTag, [DOMSVGFEFloodElement class]); 171 addElementClass(SVGNames::feFuncATag, [DOMSVGFEFuncAElement class]); 172 addElementClass(SVGNames::feFuncBTag, [DOMSVGFEFuncBElement class]); 173 addElementClass(SVGNames::feFuncGTag, [DOMSVGFEFuncGElement class]); 174 addElementClass(SVGNames::feFuncRTag, [DOMSVGFEFuncRElement class]); 175 addElementClass(SVGNames::feGaussianBlurTag, [DOMSVGFEGaussianBlurElement class]); 176 addElementClass(SVGNames::feImageTag, [DOMSVGFEImageElement class]); 177 addElementClass(SVGNames::feMergeTag, [DOMSVGFEMergeElement class]); 178 addElementClass(SVGNames::feMergeNodeTag, [DOMSVGFEMergeNodeElement class]); 179 addElementClass(SVGNames::feMorphologyTag, [DOMSVGFEMorphologyElement class]); 180 addElementClass(SVGNames::feOffsetTag, [DOMSVGFEOffsetElement class]); 181 addElementClass(SVGNames::fePointLightTag, [DOMSVGFEPointLightElement class]); 182 addElementClass(SVGNames::feSpecularLightingTag, [DOMSVGFESpecularLightingElement class]); 183 addElementClass(SVGNames::feSpotLightTag, [DOMSVGFESpotLightElement class]); 184 addElementClass(SVGNames::feTileTag, [DOMSVGFETileElement class]); 185 addElementClass(SVGNames::feTurbulenceTag, [DOMSVGFETurbulenceElement class]); 186 addElementClass(SVGNames::filterTag, [DOMSVGFilterElement class]); 187#endif 188#if ENABLE(SVG_FONTS) 189 addElementClass(SVGNames::fontTag, [DOMSVGFontElement class]); 190 addElementClass(SVGNames::font_faceTag, [DOMSVGFontFaceElement class]); 191 addElementClass(SVGNames::font_face_formatTag, [DOMSVGFontFaceFormatElement class]); 192 addElementClass(SVGNames::font_face_nameTag, [DOMSVGFontFaceNameElement class]); 193 addElementClass(SVGNames::font_face_srcTag, [DOMSVGFontFaceSrcElement class]); 194 addElementClass(SVGNames::font_face_uriTag, [DOMSVGFontFaceUriElement class]); 195 addElementClass(SVGNames::glyphTag, [DOMSVGGlyphElement class]); 196#endif 197 addElementClass(SVGNames::gTag, [DOMSVGGElement class]); 198 addElementClass(SVGNames::imageTag, [DOMSVGImageElement class]); 199 addElementClass(SVGNames::lineTag, [DOMSVGLineElement class]); 200 addElementClass(SVGNames::linearGradientTag, [DOMSVGLinearGradientElement class]); 201 addElementClass(SVGNames::markerTag, [DOMSVGMarkerElement class]); 202 addElementClass(SVGNames::maskTag, [DOMSVGMaskElement class]); 203 addElementClass(SVGNames::metadataTag, [DOMSVGMetadataElement class]); 204#if ENABLE(SVG_FONTS) 205 addElementClass(SVGNames::missing_glyphTag, [DOMSVGMissingGlyphElement class]); 206#endif 207 addElementClass(SVGNames::pathTag, [DOMSVGPathElement class]); 208 addElementClass(SVGNames::patternTag, [DOMSVGPatternElement class]); 209 addElementClass(SVGNames::polygonTag, [DOMSVGPolygonElement class]); 210 addElementClass(SVGNames::polylineTag, [DOMSVGPolylineElement class]); 211 addElementClass(SVGNames::radialGradientTag, [DOMSVGRadialGradientElement class]); 212 addElementClass(SVGNames::rectTag, [DOMSVGRectElement class]); 213 addElementClass(SVGNames::scriptTag, [DOMSVGScriptElement class]); 214 addElementClass(SVGNames::stopTag, [DOMSVGStopElement class]); 215 addElementClass(SVGNames::styleTag, [DOMSVGStyleElement class]); 216 addElementClass(SVGNames::svgTag, [DOMSVGSVGElement class]); 217 addElementClass(SVGNames::switchTag, [DOMSVGSwitchElement class]); 218 addElementClass(SVGNames::symbolTag, [DOMSVGSymbolElement class]); 219 addElementClass(SVGNames::textTag, [DOMSVGTextElement class]); 220 addElementClass(SVGNames::titleTag, [DOMSVGTitleElement class]); 221 addElementClass(SVGNames::trefTag, [DOMSVGTRefElement class]); 222 addElementClass(SVGNames::tspanTag, [DOMSVGTSpanElement class]); 223 addElementClass(SVGNames::textPathTag, [DOMSVGTextPathElement class]); 224 addElementClass(SVGNames::useTag, [DOMSVGUseElement class]); 225 addElementClass(SVGNames::viewTag, [DOMSVGViewElement class]); 226#endif 227} 228 229static Class lookupElementClass(const QualifiedName& tag) 230{ 231 // Do a special lookup to ignore element prefixes 232 if (tag.hasPrefix()) 233 return elementClassMap->get(QualifiedName(nullAtom, tag.localName(), tag.namespaceURI()).impl()); 234 235 return elementClassMap->get(tag.impl()); 236} 237 238static Class elementClass(const QualifiedName& tag, Class defaultClass) 239{ 240 if (!elementClassMap) 241 createElementClassMap(); 242 Class objcClass = lookupElementClass(tag); 243 if (!objcClass) 244 objcClass = defaultClass; 245 return objcClass; 246} 247 248static NSArray *kit(const Vector<IntRect>& rects) 249{ 250 size_t size = rects.size(); 251 NSMutableArray *array = [NSMutableArray arrayWithCapacity:size]; 252 for (size_t i = 0; i < size; ++i) 253 [array addObject:[NSValue valueWithRect:rects[i]]]; 254 return array; 255} 256 257} // namespace WebCore 258 259@implementation DOMNode (WebCoreInternal) 260 261- (NSString *)description 262{ 263 if (!_internal) 264 return [NSString stringWithFormat:@"<%@: null>", [[self class] description], self]; 265 266 NSString *value = [self nodeValue]; 267 if (value) 268 return [NSString stringWithFormat:@"<%@ [%@]: %p '%@'>", 269 [[self class] description], [self nodeName], _internal, value]; 270 271 return [NSString stringWithFormat:@"<%@ [%@]: %p>", [[self class] description], [self nodeName], _internal]; 272} 273 274- (JSC::Bindings::RootObject*)_rootObject 275{ 276 WebCore::Frame* frame = core(self)->document()->frame(); 277 if (!frame) 278 return 0; 279 return frame->script()->bindingRootObject(); 280} 281 282@end 283 284Class kitClass(WebCore::Node* impl) 285{ 286 switch (impl->nodeType()) { 287 case WebCore::Node::ELEMENT_NODE: 288 if (impl->isHTMLElement()) 289 return WebCore::elementClass(static_cast<WebCore::HTMLElement*>(impl)->tagQName(), [DOMHTMLElement class]); 290#if ENABLE(SVG_DOM_OBJC_BINDINGS) 291 if (impl->isSVGElement()) 292 return WebCore::elementClass(static_cast<WebCore::SVGElement*>(impl)->tagQName(), [DOMSVGElement class]); 293#endif 294 return [DOMElement class]; 295 case WebCore::Node::ATTRIBUTE_NODE: 296 return [DOMAttr class]; 297 case WebCore::Node::TEXT_NODE: 298 return [DOMText class]; 299 case WebCore::Node::CDATA_SECTION_NODE: 300 return [DOMCDATASection class]; 301 case WebCore::Node::ENTITY_REFERENCE_NODE: 302 return [DOMEntityReference class]; 303 case WebCore::Node::ENTITY_NODE: 304 return [DOMEntity class]; 305 case WebCore::Node::PROCESSING_INSTRUCTION_NODE: 306 return [DOMProcessingInstruction class]; 307 case WebCore::Node::COMMENT_NODE: 308 return [DOMComment class]; 309 case WebCore::Node::DOCUMENT_NODE: 310 if (static_cast<WebCore::Document*>(impl)->isHTMLDocument()) 311 return [DOMHTMLDocument class]; 312#if ENABLE(SVG_DOM_OBJC_BINDINGS) 313 if (static_cast<WebCore::Document*>(impl)->isSVGDocument()) 314 return [DOMSVGDocument class]; 315#endif 316 return [DOMDocument class]; 317 case WebCore::Node::DOCUMENT_TYPE_NODE: 318 return [DOMDocumentType class]; 319 case WebCore::Node::DOCUMENT_FRAGMENT_NODE: 320 return [DOMDocumentFragment class]; 321 case WebCore::Node::NOTATION_NODE: 322 return [DOMNotation class]; 323 case WebCore::Node::XPATH_NAMESPACE_NODE: 324 // FIXME: Create an XPath objective C wrapper 325 // See http://bugs.webkit.org/show_bug.cgi?id=8755 326 return nil; 327 } 328 ASSERT_NOT_REACHED(); 329 return nil; 330} 331 332id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget) 333{ 334 if (!eventTarget) 335 return nil; 336 337 if (WebCore::Node* node = eventTarget->toNode()) 338 return kit(node); 339 340#if ENABLE(SVG_DOM_OBJC_BINDINGS) 341 if (WebCore::SVGElementInstance* svgElementInstance = eventTarget->toSVGElementInstance()) 342 return kit(svgElementInstance); 343#endif 344 345 // We don't have an ObjC binding for XMLHttpRequest. 346 347 return nil; 348} 349 350@implementation DOMNode (DOMNodeExtensions) 351 352- (NSRect)boundingBox 353{ 354 // FIXME: Could we move this function to WebCore::Node and autogenerate? 355 core(self)->document()->updateLayoutIgnorePendingStylesheets(); 356 WebCore::RenderObject* renderer = core(self)->renderer(); 357 if (!renderer) 358 return NSZeroRect; 359 return renderer->absoluteBoundingBoxRect(); 360} 361 362- (NSArray *)lineBoxRects 363{ 364 return [self textRects]; 365} 366 367@end 368 369@implementation DOMNode (DOMNodeExtensionsPendingPublic) 370 371- (NSImage *)renderedImage 372{ 373 // FIXME: Could we move this function to WebCore::Node and autogenerate? 374 WebCore::Node* node = core(self); 375 WebCore::Frame* frame = node->document()->frame(); 376 if (!frame) 377 return nil; 378 return frame->nodeImage(node); 379} 380 381- (NSArray *)textRects 382{ 383 // FIXME: Could we move this function to WebCore::Node and autogenerate? 384 core(self)->document()->updateLayoutIgnorePendingStylesheets(); 385 if (!core(self)->renderer()) 386 return nil; 387 RefPtr<Range> range = Range::create(core(self)->document()); 388 WebCore::ExceptionCode ec = 0; 389 range->selectNodeContents(core(self), ec); 390 Vector<WebCore::IntRect> rects; 391 range->textRects(rects); 392 return kit(rects); 393} 394@end 395 396@implementation DOMRange (DOMRangeExtensions) 397 398- (NSRect)boundingBox 399{ 400 // FIXME: The call to updateLayoutIgnorePendingStylesheets should be moved into WebCore::Range. 401 core(self)->ownerDocument()->updateLayoutIgnorePendingStylesheets(); 402 return core(self)->boundingBox(); 403} 404 405- (NSArray *)textRects 406{ 407 // FIXME: The call to updateLayoutIgnorePendingStylesheets should be moved into WebCore::Range. 408 Vector<WebCore::IntRect> rects; 409 core(self)->ownerDocument()->updateLayoutIgnorePendingStylesheets(); 410 core(self)->textRects(rects); 411 return kit(rects); 412} 413 414- (NSArray *)lineBoxRects 415{ 416 // FIXME: Remove this once all clients stop using it and we drop Leopard support. 417 return [self textRects]; 418} 419 420@end 421 422//------------------------------------------------------------------------------------------ 423// DOMElement 424 425@implementation DOMElement (DOMElementAppKitExtensions) 426 427- (NSImage*)image 428{ 429 // FIXME: Could we move this function to WebCore::Node and autogenerate? 430 WebCore::RenderObject* renderer = core(self)->renderer(); 431 if (!renderer || !renderer->isImage()) 432 return nil; 433 WebCore::CachedImage* cachedImage = static_cast<WebCore::RenderImage*>(renderer)->cachedImage(); 434 if (!cachedImage || cachedImage->errorOccurred()) 435 return nil; 436 return cachedImage->image()->getNSImage(); 437} 438 439@end 440 441@implementation DOMElement (WebPrivate) 442 443- (NSFont *)_font 444{ 445 // FIXME: Could we move this function to WebCore::Element and autogenerate? 446 WebCore::RenderObject* renderer = core(self)->renderer(); 447 if (!renderer) 448 return nil; 449 return renderer->style()->font().primaryFont()->getNSFont(); 450} 451 452- (NSData *)_imageTIFFRepresentation 453{ 454 // FIXME: Could we move this function to WebCore::Element and autogenerate? 455 WebCore::RenderObject* renderer = core(self)->renderer(); 456 if (!renderer || !renderer->isImage()) 457 return nil; 458 WebCore::CachedImage* cachedImage = static_cast<WebCore::RenderImage*>(renderer)->cachedImage(); 459 if (!cachedImage || cachedImage->errorOccurred()) 460 return nil; 461 return (NSData *)cachedImage->image()->getTIFFRepresentation(); 462} 463 464- (NSURL *)_getURLAttribute:(NSString *)name 465{ 466 // FIXME: Could we move this function to WebCore::Element and autogenerate? 467 ASSERT(name); 468 WebCore::Element* element = core(self); 469 ASSERT(element); 470 return element->document()->completeURL(deprecatedParseURL(element->getAttribute(name))); 471} 472 473- (BOOL)isFocused 474{ 475 // FIXME: Could we move this function to WebCore::Element and autogenerate? 476 WebCore::Element* element = core(self); 477 return element->document()->focusedNode() == element; 478} 479 480@end 481 482//------------------------------------------------------------------------------------------ 483// DOMRange 484 485@implementation DOMRange (WebPrivate) 486 487- (NSString *)description 488{ 489 if (!_internal) 490 return @"<DOMRange: null>"; 491 return [NSString stringWithFormat:@"<DOMRange: %@ %d %@ %d>", 492 [self startContainer], [self startOffset], [self endContainer], [self endOffset]]; 493} 494 495// FIXME: This should be removed as soon as all internal Apple uses of it have been replaced with 496// calls to the public method - (NSString *)text. 497- (NSString *)_text 498{ 499 return [self text]; 500} 501 502@end 503 504//------------------------------------------------------------------------------------------ 505// DOMRGBColor 506 507@implementation DOMRGBColor (WebPrivate) 508 509// FIXME: This should be removed as soon as all internal Apple uses of it have been replaced with 510// calls to the public method - (NSColor *)color. 511- (NSColor *)_color 512{ 513 return [self color]; 514} 515 516@end 517 518 519//------------------------------------------------------------------------------------------ 520// DOMNodeFilter 521 522DOMNodeFilter *kit(WebCore::NodeFilter* impl) 523{ 524 if (!impl) 525 return nil; 526 527 if (DOMNodeFilter *wrapper = getDOMWrapper(impl)) 528 return [[wrapper retain] autorelease]; 529 530 DOMNodeFilter *wrapper = [[DOMNodeFilter alloc] _init]; 531 wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(impl); 532 impl->ref(); 533 addDOMWrapper(wrapper, impl); 534 return [wrapper autorelease]; 535} 536 537WebCore::NodeFilter* core(DOMNodeFilter *wrapper) 538{ 539 return wrapper ? reinterpret_cast<WebCore::NodeFilter*>(wrapper->_internal) : 0; 540} 541 542@implementation DOMNodeFilter 543 544- (void)dealloc 545{ 546 if (_internal) 547 reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref(); 548 [super dealloc]; 549} 550 551- (void)finalize 552{ 553 if (_internal) 554 reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref(); 555 [super finalize]; 556} 557 558- (short)acceptNode:(DOMNode *)node 559{ 560 return core(self)->acceptNode(core(node)); 561} 562 563@end 564