/platform/external/webkit/WebCore/bindings/objc/DOM.mm

https://github.com/aharish/totoro-gb-opensource-update2 · Objective C++ · 563 lines · 431 code · 72 blank · 60 comment · 33 complexity · 5d00c6f97aa293793d7e57efd2701aba MD5 · raw file

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