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 "DOMRangeInternal.h" 33#import "DOMElementInternal.h" 34#import "DOMNodeInternal.h" 35#import "DOMHTMLCanvasElement.h" 36#import "Frame.h" 37#import "HTMLNames.h" 38#import "HTMLElement.h" 39#import "RenderImage.h" 40#import "NodeFilter.h" 41#import "WebScriptObjectPrivate.h" 42#import <wtf/HashMap.h> 43 44#if ENABLE(SVG_DOM_OBJC_BINDINGS) 45#import "DOMSVG.h" 46#import "SVGElementInstance.h" 47#endif 48 49using namespace JSC; 50using namespace WebCore; 51 52// FIXME: Would be nice to break this up into separate files to match how other WebKit 53// code is organized. 54 55//------------------------------------------------------------------------------------------ 56// DOMNode 57 58namespace WebCore { 59 60typedef HashMap<const QualifiedName::QualifiedNameImpl*, Class> ObjCClassMap; 61static ObjCClassMap* elementClassMap; 62 63static void addElementClass(const QualifiedName& tag, Class objCClass) 64{ 65 elementClassMap->set(tag.impl(), objCClass); 66} 67 68static void createElementClassMap() 69{ 70 // Create the table. 71 elementClassMap = new ObjCClassMap; 72 73 // FIXME: Reflect marquee once the API has been determined. 74 75 // Populate it with HTML and SVG element classes. 76 addElementClass(HTMLNames::aTag, [DOMHTMLAnchorElement class]); 77 addElementClass(HTMLNames::appletTag, [DOMHTMLAppletElement class]); 78 addElementClass(HTMLNames::areaTag, [DOMHTMLAreaElement class]); 79 addElementClass(HTMLNames::baseTag, [DOMHTMLBaseElement class]); 80 addElementClass(HTMLNames::basefontTag, [DOMHTMLBaseFontElement class]); 81 addElementClass(HTMLNames::bodyTag, [DOMHTMLBodyElement class]); 82 addElementClass(HTMLNames::brTag, [DOMHTMLBRElement class]); 83 addElementClass(HTMLNames::buttonTag, [DOMHTMLButtonElement class]); 84 addElementClass(HTMLNames::canvasTag, [DOMHTMLCanvasElement class]); 85 addElementClass(HTMLNames::captionTag, [DOMHTMLTableCaptionElement class]); 86 addElementClass(HTMLNames::colTag, [DOMHTMLTableColElement class]); 87 addElementClass(HTMLNames::colgroupTag, [DOMHTMLTableColElement class]); 88 addElementClass(HTMLNames::delTag, [DOMHTMLModElement class]); 89 addElementClass(HTMLNames::dirTag, [DOMHTMLDirectoryElement class]); 90 addElementClass(HTMLNames::divTag, [DOMHTMLDivElement class]); 91 addElementClass(HTMLNames::dlTag, [DOMHTMLDListElement class]); 92 addElementClass(HTMLNames::embedTag, [DOMHTMLEmbedElement class]); 93 addElementClass(HTMLNames::fieldsetTag, [DOMHTMLFieldSetElement class]); 94 addElementClass(HTMLNames::fontTag, [DOMHTMLFontElement class]); 95 addElementClass(HTMLNames::formTag, [DOMHTMLFormElement class]); 96 addElementClass(HTMLNames::frameTag, [DOMHTMLFrameElement class]); 97 addElementClass(HTMLNames::framesetTag, [DOMHTMLFrameSetElement class]); 98 addElementClass(HTMLNames::h1Tag, [DOMHTMLHeadingElement class]); 99 addElementClass(HTMLNames::h2Tag, [DOMHTMLHeadingElement class]); 100 addElementClass(HTMLNames::h3Tag, [DOMHTMLHeadingElement class]); 101 addElementClass(HTMLNames::h4Tag, [DOMHTMLHeadingElement class]); 102 addElementClass(HTMLNames::h5Tag, [DOMHTMLHeadingElement class]); 103 addElementClass(HTMLNames::h6Tag, [DOMHTMLHeadingElement class]); 104 addElementClass(HTMLNames::headTag, [DOMHTMLHeadElement class]); 105 addElementClass(HTMLNames::hrTag, [DOMHTMLHRElement class]); 106 addElementClass(HTMLNames::htmlTag, [DOMHTMLHtmlElement class]); 107 addElementClass(HTMLNames::iframeTag, [DOMHTMLIFrameElement class]); 108 addElementClass(HTMLNames::imgTag, [DOMHTMLImageElement class]); 109 addElementClass(HTMLNames::inputTag, [DOMHTMLInputElement class]); 110 addElementClass(HTMLNames::insTag, [DOMHTMLModElement class]); 111 addElementClass(HTMLNames::isindexTag, [DOMHTMLIsIndexElement class]); 112 addElementClass(HTMLNames::labelTag, [DOMHTMLLabelElement class]); 113 addElementClass(HTMLNames::legendTag, [DOMHTMLLegendElement class]); 114 addElementClass(HTMLNames::liTag, [DOMHTMLLIElement class]); 115 addElementClass(HTMLNames::linkTag, [DOMHTMLLinkElement class]); 116 addElementClass(HTMLNames::listingTag, [DOMHTMLPreElement class]); 117 addElementClass(HTMLNames::mapTag, [DOMHTMLMapElement class]); 118 addElementClass(HTMLNames::marqueeTag, [DOMHTMLMarqueeElement class]); 119 addElementClass(HTMLNames::menuTag, [DOMHTMLMenuElement class]); 120 addElementClass(HTMLNames::metaTag, [DOMHTMLMetaElement class]); 121 addElementClass(HTMLNames::objectTag, [DOMHTMLObjectElement class]); 122 addElementClass(HTMLNames::olTag, [DOMHTMLOListElement class]); 123 addElementClass(HTMLNames::optgroupTag, [DOMHTMLOptGroupElement class]); 124 addElementClass(HTMLNames::optionTag, [DOMHTMLOptionElement class]); 125 addElementClass(HTMLNames::pTag, [DOMHTMLParagraphElement class]); 126 addElementClass(HTMLNames::paramTag, [DOMHTMLParamElement class]); 127 addElementClass(HTMLNames::preTag, [DOMHTMLPreElement class]); 128 addElementClass(HTMLNames::qTag, [DOMHTMLQuoteElement class]); 129 addElementClass(HTMLNames::scriptTag, [DOMHTMLScriptElement class]); 130 addElementClass(HTMLNames::keygenTag, [DOMHTMLSelectElement class]); 131 addElementClass(HTMLNames::selectTag, [DOMHTMLSelectElement class]); 132 addElementClass(HTMLNames::styleTag, [DOMHTMLStyleElement class]); 133 addElementClass(HTMLNames::tableTag, [DOMHTMLTableElement class]); 134 addElementClass(HTMLNames::tbodyTag, [DOMHTMLTableSectionElement class]); 135 addElementClass(HTMLNames::tdTag, [DOMHTMLTableCellElement class]); 136 addElementClass(HTMLNames::textareaTag, [DOMHTMLTextAreaElement class]); 137 addElementClass(HTMLNames::tfootTag, [DOMHTMLTableSectionElement class]); 138 addElementClass(HTMLNames::thTag, [DOMHTMLTableCellElement class]); 139 addElementClass(HTMLNames::theadTag, [DOMHTMLTableSectionElement class]); 140 addElementClass(HTMLNames::titleTag, [DOMHTMLTitleElement class]); 141 addElementClass(HTMLNames::trTag, [DOMHTMLTableRowElement class]); 142 addElementClass(HTMLNames::ulTag, [DOMHTMLUListElement class]); 143 addElementClass(HTMLNames::xmpTag, [DOMHTMLPreElement class]); 144 145#if ENABLE(SVG_DOM_OBJC_BINDINGS) 146 addElementClass(SVGNames::aTag, [DOMSVGAElement class]); 147 addElementClass(SVGNames::altGlyphTag, [DOMSVGAltGlyphElement class]); 148#if ENABLE(SVG_ANIMATION) 149 addElementClass(SVGNames::animateTag, [DOMSVGAnimateElement class]); 150 addElementClass(SVGNames::animateColorTag, [DOMSVGAnimateColorElement class]); 151 addElementClass(SVGNames::animateTransformTag, [DOMSVGAnimateTransformElement class]); 152 addElementClass(SVGNames::setTag, [DOMSVGSetElement class]); 153#endif 154 addElementClass(SVGNames::circleTag, [DOMSVGCircleElement class]); 155 addElementClass(SVGNames::clipPathTag, [DOMSVGClipPathElement class]); 156 addElementClass(SVGNames::cursorTag, [DOMSVGCursorElement class]); 157#if ENABLE(SVG_FONTS) 158 addElementClass(SVGNames::definition_srcTag, [DOMSVGDefinitionSrcElement class]); 159#endif 160 addElementClass(SVGNames::defsTag, [DOMSVGDefsElement class]); 161 addElementClass(SVGNames::descTag, [DOMSVGDescElement class]); 162 addElementClass(SVGNames::ellipseTag, [DOMSVGEllipseElement class]); 163#if ENABLE(FILTERS) 164 addElementClass(SVGNames::feBlendTag, [DOMSVGFEBlendElement class]); 165 addElementClass(SVGNames::feColorMatrixTag, [DOMSVGFEColorMatrixElement class]); 166 addElementClass(SVGNames::feComponentTransferTag, [DOMSVGFEComponentTransferElement class]); 167 addElementClass(SVGNames::feCompositeTag, [DOMSVGFECompositeElement class]); 168 addElementClass(SVGNames::feDiffuseLightingTag, [DOMSVGFEDiffuseLightingElement class]); 169 addElementClass(SVGNames::feDisplacementMapTag, [DOMSVGFEDisplacementMapElement class]); 170 addElementClass(SVGNames::feDistantLightTag, [DOMSVGFEDistantLightElement class]); 171 addElementClass(SVGNames::feFloodTag, [DOMSVGFEFloodElement class]); 172 addElementClass(SVGNames::feFuncATag, [DOMSVGFEFuncAElement class]); 173 addElementClass(SVGNames::feFuncBTag, [DOMSVGFEFuncBElement class]); 174 addElementClass(SVGNames::feFuncGTag, [DOMSVGFEFuncGElement class]); 175 addElementClass(SVGNames::feFuncRTag, [DOMSVGFEFuncRElement class]); 176 addElementClass(SVGNames::feGaussianBlurTag, [DOMSVGFEGaussianBlurElement class]); 177 addElementClass(SVGNames::feImageTag, [DOMSVGFEImageElement class]); 178 addElementClass(SVGNames::feMergeTag, [DOMSVGFEMergeElement class]); 179 addElementClass(SVGNames::feMergeNodeTag, [DOMSVGFEMergeNodeElement 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 *)textRects 363{ 364 // FIXME: Could we move this function to WebCore::Node and autogenerate? 365 core(self)->document()->updateLayoutIgnorePendingStylesheets(); 366 if (!core(self)->renderer()) 367 return nil; 368 RefPtr<Range> range = Range::create(core(self)->document()); 369 WebCore::ExceptionCode ec = 0; 370 range->selectNodeContents(core(self), ec); 371 Vector<WebCore::IntRect> rects; 372 range->textRects(rects); 373 return kit(rects); 374} 375 376- (NSArray *)lineBoxRects 377{ 378 return [self textRects]; 379} 380 381@end 382 383@implementation DOMNode (DOMNodeExtensionsPendingPublic) 384 385- (NSImage *)renderedImage 386{ 387 // FIXME: Could we move this function to WebCore::Node and autogenerate? 388 WebCore::Node* node = core(self); 389 WebCore::Frame* frame = node->document()->frame(); 390 if (!frame) 391 return nil; 392 return frame->nodeImage(node); 393} 394 395@end 396 397@implementation DOMRange (DOMRangeExtensions) 398 399- (NSRect)boundingBox 400{ 401 // FIXME: The call to updateLayoutIgnorePendingStylesheets should be moved into WebCore::Range. 402 core(self)->ownerDocument()->updateLayoutIgnorePendingStylesheets(); 403 return core(self)->boundingBox(); 404} 405 406- (NSArray *)textRects 407{ 408 // FIXME: The call to updateLayoutIgnorePendingStylesheets should be moved into WebCore::Range. 409 Vector<WebCore::IntRect> rects; 410 core(self)->ownerDocument()->updateLayoutIgnorePendingStylesheets(); 411 core(self)->textRects(rects); 412 return kit(rects); 413} 414 415- (NSArray *)lineBoxRects 416{ 417 // FIXME: Remove this once all clients stop using it and we drop Leopard support. 418 return [self textRects]; 419} 420 421@end 422 423//------------------------------------------------------------------------------------------ 424// DOMElement 425 426@implementation DOMElement (DOMElementAppKitExtensions) 427 428- (NSImage*)image 429{ 430 // FIXME: Could we move this function to WebCore::Node and autogenerate? 431 WebCore::RenderObject* renderer = core(self)->renderer(); 432 if (!renderer || !renderer->isImage()) 433 return nil; 434 WebCore::CachedImage* cachedImage = static_cast<WebCore::RenderImage*>(renderer)->cachedImage(); 435 if (!cachedImage || cachedImage->errorOccurred()) 436 return nil; 437 return cachedImage->image()->getNSImage(); 438} 439 440@end 441 442@implementation DOMElement (WebPrivate) 443 444- (NSFont *)_font 445{ 446 // FIXME: Could we move this function to WebCore::Element and autogenerate? 447 WebCore::RenderObject* renderer = core(self)->renderer(); 448 if (!renderer) 449 return nil; 450 return renderer->style()->font().primaryFont()->getNSFont(); 451} 452 453- (NSData *)_imageTIFFRepresentation 454{ 455 // FIXME: Could we move this function to WebCore::Element and autogenerate? 456 WebCore::RenderObject* renderer = core(self)->renderer(); 457 if (!renderer || !renderer->isImage()) 458 return nil; 459 WebCore::CachedImage* cachedImage = static_cast<WebCore::RenderImage*>(renderer)->cachedImage(); 460 if (!cachedImage || cachedImage->errorOccurred()) 461 return nil; 462 return (NSData *)cachedImage->image()->getTIFFRepresentation(); 463} 464 465- (NSURL *)_getURLAttribute:(NSString *)name 466{ 467 // FIXME: Could we move this function to WebCore::Element and autogenerate? 468 ASSERT(name); 469 WebCore::Element* element = core(self); 470 ASSERT(element); 471 return element->document()->completeURL(deprecatedParseURL(element->getAttribute(name))); 472} 473 474- (BOOL)isFocused 475{ 476 // FIXME: Could we move this function to WebCore::Element and autogenerate? 477 WebCore::Element* element = core(self); 478 return element->document()->focusedNode() == element; 479} 480 481@end 482 483//------------------------------------------------------------------------------------------ 484// DOMRange 485 486@implementation DOMRange (WebPrivate) 487 488- (NSString *)description 489{ 490 if (!_internal) 491 return @"<DOMRange: null>"; 492 return [NSString stringWithFormat:@"<DOMRange: %@ %d %@ %d>", 493 [self startContainer], [self startOffset], [self endContainer], [self endOffset]]; 494} 495 496// FIXME: This should be removed as soon as all internal Apple uses of it have been replaced with 497// calls to the public method - (NSString *)text. 498- (NSString *)_text 499{ 500 return [self text]; 501} 502 503@end 504 505//------------------------------------------------------------------------------------------ 506// DOMRGBColor 507 508@implementation DOMRGBColor (WebPrivate) 509 510// FIXME: This should be removed as soon as all internal Apple uses of it have been replaced with 511// calls to the public method - (NSColor *)color. 512- (NSColor *)_color 513{ 514 return [self color]; 515} 516 517@end 518 519 520//------------------------------------------------------------------------------------------ 521// DOMNodeFilter 522 523DOMNodeFilter *kit(WebCore::NodeFilter* impl) 524{ 525 if (!impl) 526 return nil; 527 528 if (DOMNodeFilter *wrapper = getDOMWrapper(impl)) 529 return [[wrapper retain] autorelease]; 530 531 DOMNodeFilter *wrapper = [[DOMNodeFilter alloc] _init]; 532 wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(impl); 533 impl->ref(); 534 addDOMWrapper(wrapper, impl); 535 return [wrapper autorelease]; 536} 537 538WebCore::NodeFilter* core(DOMNodeFilter *wrapper) 539{ 540 return wrapper ? reinterpret_cast<WebCore::NodeFilter*>(wrapper->_internal) : 0; 541} 542 543@implementation DOMNodeFilter 544 545- (void)dealloc 546{ 547 if (_internal) 548 reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref(); 549 [super dealloc]; 550} 551 552- (void)finalize 553{ 554 if (_internal) 555 reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref(); 556 [super finalize]; 557} 558 559- (short)acceptNode:(DOMNode *)node 560{ 561 return core(self)->acceptNode(core(node)); 562} 563 564@end 565