kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 1 | /* |
ddkilzer | a7bfea3 | 2006-06-24 20:51:21 +0000 | [diff] [blame] | 2 | * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved. |
| 3 | * Copyright (C) 2006 James G. Speth (speth@end.com) |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 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: |
darin | 8d1badc | 2006-03-06 16:50:13 +0000 | [diff] [blame] | 9 | * 1. Redistributions of source code must retain the above copyright |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 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 | |
darin | bbe6466 | 2006-01-16 17:52:23 +0000 | [diff] [blame] | 28 | #import "config.h" |
kocienda | 49ed539 | 2004-03-11 23:37:58 +0000 | [diff] [blame] | 29 | #import "DOM.h" |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 30 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 31 | #import "CDATASection.h" |
eseidel | b3f4213 | 2006-05-16 02:08:51 +0000 | [diff] [blame] | 32 | #import "CSSStyleSheet.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 33 | #import "Comment.h" |
thatcher | 6bf9b3b | 2006-09-06 02:30:25 +0000 | [diff] [blame] | 34 | #import "DOMImplementationFront.h" |
darin | bbe6466 | 2006-01-16 17:52:23 +0000 | [diff] [blame] | 35 | #import "DOMInternal.h" |
| 36 | #import "DOMPrivate.h" |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 37 | #import "DeprecatedValueList.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 38 | #import "Document.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 39 | #import "DocumentFragment.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 40 | #import "DocumentType.h" |
eseidel | 6e4fe45 | 2006-05-15 23:53:33 +0000 | [diff] [blame] | 41 | #import "EntityReference.h" |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 42 | #import "Event.h" |
darin | 8d1badc | 2006-03-06 16:50:13 +0000 | [diff] [blame] | 43 | #import "EventListener.h" |
darin | be6eb6b | 2006-09-06 16:23:32 +0000 | [diff] [blame] | 44 | #import "FontData.h" |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 45 | #import "FoundationExtras.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 46 | #import "FrameMac.h" |
ggaren | 5711f09 | 2006-06-14 05:54:06 +0000 | [diff] [blame] | 47 | #import "HTMLDocument.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 48 | #import "HTMLNames.h" |
tomernic | f519362 | 2006-07-11 23:58:44 +0000 | [diff] [blame] | 49 | #import "HTMLPlugInElement.h" |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 50 | #import "IntRect.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 51 | #import "NodeFilter.h" |
| 52 | #import "NodeFilterCondition.h" |
| 53 | #import "NodeIterator.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 54 | #import "NodeList.h" |
eseidel | 6e4fe45 | 2006-05-15 23:53:33 +0000 | [diff] [blame] | 55 | #import "ProcessingInstruction.h" |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 56 | #import "QualifiedName.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 57 | #import "Range.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 58 | #import "RenderImage.h" |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 59 | #import "Text.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 60 | #import "TreeWalker.h" |
thatcher | 7aabf5d | 2006-07-18 00:27:46 +0000 | [diff] [blame] | 61 | #import "WebScriptObjectPrivate.h" |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 62 | #import "csshelper.h" |
darin | 644b75e | 2006-02-21 06:59:15 +0000 | [diff] [blame] | 63 | #import <objc/objc-class.h> |
weinig | ac93628 | 2006-09-29 20:29:16 +0000 | [diff] [blame] | 64 | #import <wtf/HashMap.h> |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 65 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 66 | #ifdef SVG_SUPPORT |
| 67 | #import "SVGDocument.h" |
| 68 | #import "SVGElement.h" |
| 69 | #import "SVGNames.h" |
| 70 | #endif |
darin | 8d1badc | 2006-03-06 16:50:13 +0000 | [diff] [blame] | 71 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 72 | namespace WebCore { |
| 73 | |
| 74 | class ObjCEventListener : public EventListener { |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 75 | public: |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 76 | static ObjCEventListener* find(id <DOMEventListener>); |
| 77 | static ObjCEventListener* create(id <DOMEventListener>); |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | ObjCEventListener(id <DOMEventListener>); |
| 81 | virtual ~ObjCEventListener(); |
| 82 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 83 | virtual void handleEvent(Event*, bool isWindowEvent); |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 84 | |
| 85 | id <DOMEventListener> m_listener; |
| 86 | }; |
| 87 | |
mjs | 7ad7ee6 | 2006-01-24 07:31:21 +0000 | [diff] [blame] | 88 | typedef HashMap<id, ObjCEventListener*> ListenerMap; |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 89 | static ListenerMap* listenerMap; |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 90 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 91 | } // namespace WebCore |
| 92 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 93 | |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 94 | //------------------------------------------------------------------------------------------ |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 95 | // DOMNode |
| 96 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 97 | namespace WebCore { |
| 98 | |
| 99 | typedef HashMap<const QualifiedName*, Class> ObjCClassMap; |
| 100 | static ObjCClassMap* elementClassMap; |
| 101 | |
| 102 | static void addElementClass(const QualifiedName& tag, Class objCClass) |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 103 | { |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 104 | elementClassMap->set(&tag, objCClass); |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 105 | } |
| 106 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 107 | static void createElementClassMap() |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 108 | { |
| 109 | // Create the table. |
| 110 | elementClassMap = new ObjCClassMap; |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 111 | |
| 112 | // FIXME: Reflect marquee once the API has been determined. |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 113 | |
| 114 | // Populate it with HTML and SVG element classes. |
| 115 | addElementClass(HTMLNames::aTag, [DOMHTMLAnchorElement class]); |
| 116 | addElementClass(HTMLNames::appletTag, [DOMHTMLAppletElement class]); |
| 117 | addElementClass(HTMLNames::areaTag, [DOMHTMLAreaElement class]); |
| 118 | addElementClass(HTMLNames::baseTag, [DOMHTMLBaseElement class]); |
| 119 | addElementClass(HTMLNames::basefontTag, [DOMHTMLBaseFontElement class]); |
| 120 | addElementClass(HTMLNames::bodyTag, [DOMHTMLBodyElement class]); |
| 121 | addElementClass(HTMLNames::brTag, [DOMHTMLBRElement class]); |
| 122 | addElementClass(HTMLNames::buttonTag, [DOMHTMLButtonElement class]); |
| 123 | addElementClass(HTMLNames::canvasTag, [DOMHTMLImageElement class]); |
| 124 | addElementClass(HTMLNames::captionTag, [DOMHTMLTableCaptionElement class]); |
| 125 | addElementClass(HTMLNames::colTag, [DOMHTMLTableColElement class]); |
| 126 | addElementClass(HTMLNames::colgroupTag, [DOMHTMLTableColElement class]); |
| 127 | addElementClass(HTMLNames::dirTag, [DOMHTMLDirectoryElement class]); |
| 128 | addElementClass(HTMLNames::divTag, [DOMHTMLDivElement class]); |
| 129 | addElementClass(HTMLNames::dlTag, [DOMHTMLDListElement class]); |
| 130 | addElementClass(HTMLNames::fieldsetTag, [DOMHTMLFieldSetElement class]); |
| 131 | addElementClass(HTMLNames::fontTag, [DOMHTMLFontElement class]); |
| 132 | addElementClass(HTMLNames::formTag, [DOMHTMLFormElement class]); |
| 133 | addElementClass(HTMLNames::frameTag, [DOMHTMLFrameElement class]); |
| 134 | addElementClass(HTMLNames::framesetTag, [DOMHTMLFrameSetElement class]); |
| 135 | addElementClass(HTMLNames::h1Tag, [DOMHTMLHeadingElement class]); |
| 136 | addElementClass(HTMLNames::h2Tag, [DOMHTMLHeadingElement class]); |
| 137 | addElementClass(HTMLNames::h3Tag, [DOMHTMLHeadingElement class]); |
| 138 | addElementClass(HTMLNames::h4Tag, [DOMHTMLHeadingElement class]); |
| 139 | addElementClass(HTMLNames::h5Tag, [DOMHTMLHeadingElement class]); |
| 140 | addElementClass(HTMLNames::h6Tag, [DOMHTMLHeadingElement class]); |
| 141 | addElementClass(HTMLNames::headTag, [DOMHTMLHeadElement class]); |
| 142 | addElementClass(HTMLNames::hrTag, [DOMHTMLHRElement class]); |
| 143 | addElementClass(HTMLNames::htmlTag, [DOMHTMLHtmlElement class]); |
| 144 | addElementClass(HTMLNames::iframeTag, [DOMHTMLIFrameElement class]); |
| 145 | addElementClass(HTMLNames::imgTag, [DOMHTMLImageElement class]); |
| 146 | addElementClass(HTMLNames::inputTag, [DOMHTMLInputElement class]); |
| 147 | addElementClass(HTMLNames::isindexTag, [DOMHTMLIsIndexElement class]); |
| 148 | addElementClass(HTMLNames::labelTag, [DOMHTMLLabelElement class]); |
| 149 | addElementClass(HTMLNames::legendTag, [DOMHTMLLegendElement class]); |
| 150 | addElementClass(HTMLNames::liTag, [DOMHTMLLIElement class]); |
| 151 | addElementClass(HTMLNames::linkTag, [DOMHTMLLinkElement class]); |
| 152 | addElementClass(HTMLNames::listingTag, [DOMHTMLPreElement class]); |
| 153 | addElementClass(HTMLNames::mapTag, [DOMHTMLMapElement class]); |
| 154 | addElementClass(HTMLNames::menuTag, [DOMHTMLMenuElement class]); |
| 155 | addElementClass(HTMLNames::metaTag, [DOMHTMLMetaElement class]); |
| 156 | addElementClass(HTMLNames::objectTag, [DOMHTMLObjectElement class]); |
| 157 | addElementClass(HTMLNames::olTag, [DOMHTMLOListElement class]); |
| 158 | addElementClass(HTMLNames::optgroupTag, [DOMHTMLOptGroupElement class]); |
| 159 | addElementClass(HTMLNames::optionTag, [DOMHTMLOptionElement class]); |
| 160 | addElementClass(HTMLNames::pTag, [DOMHTMLParagraphElement class]); |
| 161 | addElementClass(HTMLNames::paramTag, [DOMHTMLParamElement class]); |
| 162 | addElementClass(HTMLNames::preTag, [DOMHTMLPreElement class]); |
| 163 | addElementClass(HTMLNames::qTag, [DOMHTMLQuoteElement class]); |
| 164 | addElementClass(HTMLNames::scriptTag, [DOMHTMLScriptElement class]); |
| 165 | addElementClass(HTMLNames::selectTag, [DOMHTMLSelectElement class]); |
| 166 | addElementClass(HTMLNames::styleTag, [DOMHTMLStyleElement class]); |
| 167 | addElementClass(HTMLNames::tableTag, [DOMHTMLTableElement class]); |
| 168 | addElementClass(HTMLNames::tbodyTag, [DOMHTMLTableSectionElement class]); |
| 169 | addElementClass(HTMLNames::tdTag, [DOMHTMLTableCellElement class]); |
| 170 | addElementClass(HTMLNames::textareaTag, [DOMHTMLTextAreaElement class]); |
| 171 | addElementClass(HTMLNames::tfootTag, [DOMHTMLTableSectionElement class]); |
| 172 | addElementClass(HTMLNames::theadTag, [DOMHTMLTableSectionElement class]); |
| 173 | addElementClass(HTMLNames::titleTag, [DOMHTMLTitleElement class]); |
| 174 | addElementClass(HTMLNames::trTag, [DOMHTMLTableRowElement class]); |
| 175 | addElementClass(HTMLNames::ulTag, [DOMHTMLUListElement class]); |
| 176 | |
| 177 | #ifdef SVG_SUPPORT |
| 178 | addElementClass(SVGNames::aTag, [DOMSVGAElement class]); |
| 179 | addElementClass(SVGNames::animateTag, [DOMSVGAnimateElement class]); |
| 180 | addElementClass(SVGNames::animateColorTag, [DOMSVGAnimateColorElement class]); |
| 181 | addElementClass(SVGNames::animateTransformTag, [DOMSVGAnimateTransformElement class]); |
| 182 | addElementClass(SVGNames::circleTag, [DOMSVGCircleElement class]); |
| 183 | addElementClass(SVGNames::clipPathTag, [DOMSVGClipPathElement class]); |
| 184 | addElementClass(SVGNames::cursorTag, [DOMSVGCursorElement class]); |
| 185 | addElementClass(SVGNames::defsTag, [DOMSVGDefsElement class]); |
| 186 | addElementClass(SVGNames::descTag, [DOMSVGDescElement class]); |
| 187 | addElementClass(SVGNames::ellipseTag, [DOMSVGEllipseElement class]); |
| 188 | addElementClass(SVGNames::feBlendTag, [DOMSVGFEBlendElement class]); |
| 189 | addElementClass(SVGNames::feColorMatrixTag, [DOMSVGFEColorMatrixElement class]); |
| 190 | addElementClass(SVGNames::feComponentTransferTag, [DOMSVGFEComponentTransferElement class]); |
| 191 | addElementClass(SVGNames::feCompositeTag, [DOMSVGFECompositeElement class]); |
| 192 | addElementClass(SVGNames::feDiffuseLightingTag, [DOMSVGFEDiffuseLightingElement class]); |
| 193 | addElementClass(SVGNames::feDisplacementMapTag, [DOMSVGFEDisplacementMapElement class]); |
| 194 | addElementClass(SVGNames::feDistantLightTag, [DOMSVGFEDistantLightElement class]); |
| 195 | addElementClass(SVGNames::feFloodTag, [DOMSVGFEFloodElement class]); |
| 196 | addElementClass(SVGNames::feFuncATag, [DOMSVGFEFuncAElement class]); |
| 197 | addElementClass(SVGNames::feFuncBTag, [DOMSVGFEFuncBElement class]); |
| 198 | addElementClass(SVGNames::feFuncGTag, [DOMSVGFEFuncGElement class]); |
| 199 | addElementClass(SVGNames::feFuncRTag, [DOMSVGFEFuncRElement class]); |
| 200 | addElementClass(SVGNames::feGaussianBlurTag, [DOMSVGFEGaussianBlurElement class]); |
| 201 | addElementClass(SVGNames::feImageTag, [DOMSVGFEImageElement class]); |
| 202 | addElementClass(SVGNames::feMergeTag, [DOMSVGFEMergeElement class]); |
| 203 | addElementClass(SVGNames::feMergeNodeTag, [DOMSVGFEMergeNodeElement class]); |
| 204 | addElementClass(SVGNames::feOffsetTag, [DOMSVGFEOffsetElement class]); |
| 205 | addElementClass(SVGNames::fePointLightTag, [DOMSVGFEPointLightElement class]); |
| 206 | addElementClass(SVGNames::feSpecularLightingTag, [DOMSVGFESpecularLightingElement class]); |
| 207 | addElementClass(SVGNames::feSpotLightTag, [DOMSVGFESpotLightElement class]); |
| 208 | addElementClass(SVGNames::feTileTag, [DOMSVGFETileElement class]); |
| 209 | addElementClass(SVGNames::feTurbulenceTag, [DOMSVGFETurbulenceElement class]); |
| 210 | addElementClass(SVGNames::filterTag, [DOMSVGFilterElement class]); |
| 211 | addElementClass(SVGNames::foreignObjectTag, [DOMSVGForeignObjectElement class]); |
| 212 | addElementClass(SVGNames::gTag, [DOMSVGGElement class]); |
| 213 | addElementClass(SVGNames::imageTag, [DOMSVGImageElement class]); |
| 214 | addElementClass(SVGNames::lineTag, [DOMSVGLineElement class]); |
| 215 | addElementClass(SVGNames::linearGradientTag, [DOMSVGLinearGradientElement class]); |
| 216 | addElementClass(SVGNames::markerTag, [DOMSVGMarkerElement class]); |
| 217 | addElementClass(SVGNames::maskTag, [DOMSVGMaskElement class]); |
| 218 | addElementClass(SVGNames::metadataTag, [DOMSVGMetadataElement class]); |
| 219 | addElementClass(SVGNames::pathTag, [DOMSVGPathElement class]); |
| 220 | addElementClass(SVGNames::patternTag, [DOMSVGPatternElement class]); |
| 221 | addElementClass(SVGNames::polygonTag, [DOMSVGPolygonElement class]); |
| 222 | addElementClass(SVGNames::polylineTag, [DOMSVGPolylineElement class]); |
| 223 | addElementClass(SVGNames::radialGradientTag, [DOMSVGRadialGradientElement class]); |
| 224 | addElementClass(SVGNames::rectTag, [DOMSVGRectElement class]); |
| 225 | addElementClass(SVGNames::scriptTag, [DOMSVGScriptElement class]); |
| 226 | addElementClass(SVGNames::setTag, [DOMSVGSetElement class]); |
| 227 | addElementClass(SVGNames::stopTag, [DOMSVGStopElement class]); |
| 228 | addElementClass(SVGNames::styleTag, [DOMSVGStyleElement class]); |
| 229 | addElementClass(SVGNames::svgTag, [DOMSVGSVGElement class]); |
| 230 | addElementClass(SVGNames::switchTag, [DOMSVGSwitchElement class]); |
| 231 | addElementClass(SVGNames::symbolTag, [DOMSVGSymbolElement class]); |
| 232 | addElementClass(SVGNames::textTag, [DOMSVGTextElement class]); |
| 233 | addElementClass(SVGNames::titleTag, [DOMSVGTitleElement class]); |
| 234 | addElementClass(SVGNames::trefTag, [DOMSVGTRefElement class]); |
| 235 | addElementClass(SVGNames::tspanTag, [DOMSVGTSpanElement class]); |
| 236 | addElementClass(SVGNames::useTag, [DOMSVGUseElement class]); |
| 237 | addElementClass(SVGNames::viewTag, [DOMSVGViewElement class]); |
| 238 | #endif |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 239 | } |
| 240 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 241 | static Class elementClass(const QualifiedName& tag, Class defaultClass) |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 242 | { |
| 243 | if (!elementClassMap) |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 244 | createElementClassMap(); |
| 245 | Class objcClass = elementClassMap->get(&tag); |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 246 | if (!objcClass) |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 247 | objcClass = defaultClass; |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 248 | return objcClass; |
| 249 | } |
| 250 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 251 | } // namespace WebCore |
| 252 | |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 253 | @implementation DOMNode (WebCoreInternal) |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 254 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 255 | // FIXME: should this go in the main implementation? |
| 256 | - (NSString *)description |
| 257 | { |
weinig | c6bbaeb | 2006-09-15 22:23:50 +0000 | [diff] [blame] | 258 | if (!_internal) |
| 259 | return [NSString stringWithFormat:@"<%@: null>", [[self class] description], self]; |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 260 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 261 | NSString *value = [self nodeValue]; |
weinig | c6bbaeb | 2006-09-15 22:23:50 +0000 | [diff] [blame] | 262 | if (value) |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 263 | return [NSString stringWithFormat:@"<%@ [%@]: %p '%@'>", |
| 264 | [[self class] description], [self nodeName], _internal, value]; |
weinig | c6bbaeb | 2006-09-15 22:23:50 +0000 | [diff] [blame] | 265 | |
| 266 | return [NSString stringWithFormat:@"<%@ [%@]: %p>", [[self class] description], [self nodeName], _internal]; |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 267 | } |
| 268 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 269 | - (id)_initWithNode:(WebCore::Node *)impl |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 270 | { |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 271 | ASSERT(impl); |
kocienda | bb0f452 | 2004-03-02 17:03:56 +0000 | [diff] [blame] | 272 | |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 273 | [super _init]; |
weinig | 4f67b13 | 2006-09-24 19:34:43 +0000 | [diff] [blame] | 274 | _internal = reinterpret_cast<DOMObjectInternal*>(impl); |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 275 | impl->ref(); |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 276 | WebCore::addDOMWrapper(self, impl); |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 277 | return self; |
| 278 | } |
| 279 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 280 | + (DOMNode *)_nodeWith:(WebCore::Node *)impl |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 281 | { |
| 282 | if (!impl) |
| 283 | return nil; |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 284 | |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 285 | id cachedInstance; |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 286 | cachedInstance = WebCore::getDOMWrapper(impl); |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 287 | if (cachedInstance) |
| 288 | return [[cachedInstance retain] autorelease]; |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 289 | |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 290 | Class wrapperClass = nil; |
| 291 | switch (impl->nodeType()) { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 292 | case WebCore::Node::ELEMENT_NODE: |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 293 | if (impl->isHTMLElement()) |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 294 | wrapperClass = WebCore::elementClass(static_cast<WebCore::HTMLElement*>(impl)->tagQName(), [DOMHTMLElement class]); |
| 295 | #ifdef SVG_SUPPORT |
| 296 | else if (impl->isSVGElement()) |
| 297 | wrapperClass = WebCore::elementClass(static_cast<WebCore::SVGElement*>(impl)->tagQName(), [DOMSVGElement class]); |
| 298 | #endif |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 299 | else |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 300 | wrapperClass = [DOMElement class]; |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 301 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 302 | case WebCore::Node::ATTRIBUTE_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 303 | wrapperClass = [DOMAttr class]; |
| 304 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 305 | case WebCore::Node::TEXT_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 306 | wrapperClass = [DOMText class]; |
| 307 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 308 | case WebCore::Node::CDATA_SECTION_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 309 | wrapperClass = [DOMCDATASection class]; |
| 310 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 311 | case WebCore::Node::ENTITY_REFERENCE_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 312 | wrapperClass = [DOMEntityReference class]; |
| 313 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 314 | case WebCore::Node::ENTITY_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 315 | wrapperClass = [DOMEntity class]; |
| 316 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 317 | case WebCore::Node::PROCESSING_INSTRUCTION_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 318 | wrapperClass = [DOMProcessingInstruction class]; |
| 319 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 320 | case WebCore::Node::COMMENT_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 321 | wrapperClass = [DOMComment class]; |
| 322 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 323 | case WebCore::Node::DOCUMENT_NODE: |
| 324 | if (static_cast<WebCore::Document*>(impl)->isHTMLDocument()) |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 325 | wrapperClass = [DOMHTMLDocument class]; |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 326 | #ifdef SVG_SUPPORT |
| 327 | else if (static_cast<WebCore::Document*>(impl)->isSVGDocument()) |
| 328 | wrapperClass = [DOMSVGDocument class]; |
| 329 | #endif |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 330 | else |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 331 | wrapperClass = [DOMDocument class]; |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 332 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 333 | case WebCore::Node::DOCUMENT_TYPE_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 334 | wrapperClass = [DOMDocumentType class]; |
| 335 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 336 | case WebCore::Node::DOCUMENT_FRAGMENT_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 337 | wrapperClass = [DOMDocumentFragment class]; |
| 338 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 339 | case WebCore::Node::NOTATION_NODE: |
cblu | 6cf4a1ff | 2004-04-16 19:51:34 +0000 | [diff] [blame] | 340 | wrapperClass = [DOMNotation class]; |
| 341 | break; |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 342 | case WebCore::Node::XPATH_NAMESPACE_NODE: |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 343 | // FIXME: Create an XPath objective C wrapper |
| 344 | // See http://bugzilla.opendarwin.org/show_bug.cgi?id=8755 |
| 345 | return nil; |
kocienda | bb0f452 | 2004-03-02 17:03:56 +0000 | [diff] [blame] | 346 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 347 | return [[[wrapperClass alloc] _initWithNode:impl] autorelease]; |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 348 | } |
| 349 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 350 | - (WebCore::Node *)_node |
kocienda | f9c26e6 | 2004-03-03 00:42:49 +0000 | [diff] [blame] | 351 | { |
weinig | 4f67b13 | 2006-09-24 19:34:43 +0000 | [diff] [blame] | 352 | return reinterpret_cast<WebCore::Node*>(_internal); |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 353 | } |
| 354 | |
rjw | 3103217 | 2004-10-12 22:43:55 +0000 | [diff] [blame] | 355 | - (const KJS::Bindings::RootObject *)_executionContext |
| 356 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 357 | if (WebCore::Node *n = [self _node]) { |
| 358 | if (WebCore::FrameMac *f = Mac(n->document()->frame())) |
ggaren | 42e58c6 | 2006-03-18 02:04:37 +0000 | [diff] [blame] | 359 | return f->executionContextForDOM(); |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 360 | } |
ggaren | 42e58c6 | 2006-03-18 02:04:37 +0000 | [diff] [blame] | 361 | return 0; |
rjw | 3103217 | 2004-10-12 22:43:55 +0000 | [diff] [blame] | 362 | } |
| 363 | |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 364 | @end |
kocienda | 03a86c7 | 2004-02-26 19:16:09 +0000 | [diff] [blame] | 365 | |
weinig | 6b67533 | 2006-09-16 03:30:49 +0000 | [diff] [blame] | 366 | @implementation DOMNode (DOMNodeExtensions) |
| 367 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 368 | // FIXME: this should be implemented in the implementation |
weinig | 6b67533 | 2006-09-16 03:30:49 +0000 | [diff] [blame] | 369 | - (NSRect)boundingBox |
| 370 | { |
| 371 | WebCore::RenderObject *renderer = [self _node]->renderer(); |
| 372 | if (renderer) |
| 373 | return renderer->absoluteBoundingBoxRect(); |
| 374 | return NSZeroRect; |
| 375 | } |
| 376 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 377 | // FIXME: this should be implemented in the implementation |
weinig | 6b67533 | 2006-09-16 03:30:49 +0000 | [diff] [blame] | 378 | - (NSArray *)lineBoxRects |
| 379 | { |
| 380 | WebCore::RenderObject *renderer = [self _node]->renderer(); |
| 381 | if (renderer) { |
| 382 | Vector<WebCore::IntRect> rects; |
| 383 | renderer->lineBoxRects(rects); |
| 384 | size_t size = rects.size(); |
| 385 | NSMutableArray *results = [NSMutableArray arrayWithCapacity:size]; |
| 386 | for (size_t i = 0; i < size; ++i) |
| 387 | [results addObject:[NSValue valueWithRect:rects[i]]]; |
| 388 | return results; |
| 389 | } |
| 390 | return nil; |
| 391 | } |
| 392 | |
| 393 | @end |
| 394 | |
thatcher | 697713a | 2006-09-22 23:34:07 +0000 | [diff] [blame] | 395 | // FIXME: this should be auto-generated |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 396 | @implementation DOMNode (DOMEventTarget) |
| 397 | |
thatcher | 697713a | 2006-09-22 23:34:07 +0000 | [diff] [blame] | 398 | - (void)addEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 399 | { |
| 400 | if (![self _node]->isEventTargetNode()) |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 401 | WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR); |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 402 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 403 | WebCore::EventListener *wrapper = WebCore::ObjCEventListener::create(listener); |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 404 | WebCore::EventTargetNodeCast([self _node])->addEventListener(type, wrapper, useCapture); |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 405 | wrapper->deref(); |
| 406 | } |
| 407 | |
thatcher | 697713a | 2006-09-22 23:34:07 +0000 | [diff] [blame] | 408 | - (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture |
| 409 | { |
| 410 | // FIXME: this method can be removed once Mail changes to use the new method <rdar://problem/4746649> |
| 411 | [self addEventListener:type listener:listener useCapture:useCapture]; |
| 412 | } |
| 413 | |
| 414 | - (void)removeEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 415 | { |
| 416 | if (![self _node]->isEventTargetNode()) |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 417 | WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR); |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 418 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 419 | if (WebCore::EventListener *wrapper = WebCore::ObjCEventListener::find(listener)) |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 420 | WebCore::EventTargetNodeCast([self _node])->removeEventListener(type, wrapper, useCapture); |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 421 | } |
| 422 | |
thatcher | 697713a | 2006-09-22 23:34:07 +0000 | [diff] [blame] | 423 | - (void)removeEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture |
| 424 | { |
| 425 | // FIXME: this method can be removed once Mail changes to use the new method <rdar://problem/4746649> |
| 426 | [self removeEventListener:type listener:listener useCapture:useCapture]; |
| 427 | } |
| 428 | |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 429 | - (BOOL)dispatchEvent:(DOMEvent *)event |
| 430 | { |
| 431 | if (![self _node]->isEventTargetNode()) |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 432 | WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR); |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 433 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 434 | WebCore::ExceptionCode ec = 0; |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 435 | BOOL result = WebCore::EventTargetNodeCast([self _node])->dispatchEvent([event _event], ec); |
| 436 | WebCore::raiseOnDOMError(ec); |
darin | 80751b6 | 2006-07-15 15:09:19 +0000 | [diff] [blame] | 437 | return result; |
| 438 | } |
| 439 | |
| 440 | @end |
| 441 | |
kocienda | bb0f452 | 2004-03-02 17:03:56 +0000 | [diff] [blame] | 442 | //------------------------------------------------------------------------------------------ |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 443 | // DOMElement |
| 444 | |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 445 | // FIXME: this should be auto-generated in DOMElement.mm |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 446 | @implementation DOMElement (DOMElementAppKitExtensions) |
adele | 9988152 | 2005-11-15 02:05:45 +0000 | [diff] [blame] | 447 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 448 | // FIXME: this should be implemented in the implementation |
thatcher | 3166fbf | 2006-03-01 17:49:47 +0000 | [diff] [blame] | 449 | - (NSImage*)image |
| 450 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 451 | WebCore::RenderObject* renderer = [self _element]->renderer(); |
thatcher | 3166fbf | 2006-03-01 17:49:47 +0000 | [diff] [blame] | 452 | if (renderer && renderer->isImage()) { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 453 | WebCore::RenderImage* img = static_cast<WebCore::RenderImage*>(renderer); |
thatcher | 3166fbf | 2006-03-01 17:49:47 +0000 | [diff] [blame] | 454 | if (img->cachedImage() && !img->cachedImage()->isErrorImage()) |
| 455 | return img->cachedImage()->image()->getNSImage(); |
| 456 | } |
| 457 | return nil; |
| 458 | } |
| 459 | |
adele | 9988152 | 2005-11-15 02:05:45 +0000 | [diff] [blame] | 460 | @end |
| 461 | |
cblu | 4dc540a | 2004-12-06 23:39:15 +0000 | [diff] [blame] | 462 | @implementation DOMElement (WebPrivate) |
| 463 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 464 | // FIXME: this should be implemented in the implementation |
cblu | 4dc540a | 2004-12-06 23:39:15 +0000 | [diff] [blame] | 465 | - (NSFont *)_font |
| 466 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 467 | WebCore::RenderObject* renderer = [self _element]->renderer(); |
darin | be6eb6b | 2006-09-06 16:23:32 +0000 | [diff] [blame] | 468 | if (renderer) |
| 469 | return renderer->style()->font().primaryFont()->getNSFont(); |
cblu | 4dc540a | 2004-12-06 23:39:15 +0000 | [diff] [blame] | 470 | return nil; |
| 471 | } |
| 472 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 473 | // FIXME: this should be implemented in the implementation |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 474 | - (NSData *)_imageTIFFRepresentation |
hyatt | 3059a51 | 2006-02-02 08:40:45 +0000 | [diff] [blame] | 475 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 476 | WebCore::RenderObject* renderer = [self _element]->renderer(); |
hyatt | 3059a51 | 2006-02-02 08:40:45 +0000 | [diff] [blame] | 477 | if (renderer && renderer->isImage()) { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 478 | WebCore::RenderImage* img = static_cast<WebCore::RenderImage*>(renderer); |
hyatt | 3059a51 | 2006-02-02 08:40:45 +0000 | [diff] [blame] | 479 | if (img->cachedImage() && !img->cachedImage()->isErrorImage()) |
hyatt | 058251e | 2006-02-07 10:17:52 +0000 | [diff] [blame] | 480 | return (NSData*)(img->cachedImage()->image()->getTIFFRepresentation()); |
hyatt | 3059a51 | 2006-02-02 08:40:45 +0000 | [diff] [blame] | 481 | } |
| 482 | return nil; |
| 483 | } |
| 484 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 485 | // FIXME: this should be implemented in the implementation |
sullivan | 111f110 | 2005-02-17 00:14:30 +0000 | [diff] [blame] | 486 | - (NSURL *)_getURLAttribute:(NSString *)name |
| 487 | { |
| 488 | ASSERT(name); |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 489 | WebCore::Element* element = [self _element]; |
| 490 | ASSERT(element); |
| 491 | return WebCore::KURL(element->document()->completeURL(parseURL(element->getAttribute(name)).deprecatedString())).getNSURL(); |
sullivan | 111f110 | 2005-02-17 00:14:30 +0000 | [diff] [blame] | 492 | } |
cblu | 4dc540a | 2004-12-06 23:39:15 +0000 | [diff] [blame] | 493 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 494 | // FIXME: this should be implemented in the implementation |
thatcher | 3b93197 | 2006-07-12 00:45:06 +0000 | [diff] [blame] | 495 | - (void *)_NPObject |
tomernic | f519362 | 2006-07-11 23:58:44 +0000 | [diff] [blame] | 496 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 497 | WebCore::Element* element = [self _element]; |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 498 | if (element->hasTagName(WebCore::HTMLNames::appletTag) || element->hasTagName(WebCore::HTMLNames::embedTag) || element->hasTagName(WebCore::HTMLNames::objectTag)) |
tomernic | f519362 | 2006-07-11 23:58:44 +0000 | [diff] [blame] | 499 | return static_cast<WebCore::HTMLPlugInElement*>(element)->getNPObject(); |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 500 | return 0; |
tomernic | f519362 | 2006-07-11 23:58:44 +0000 | [diff] [blame] | 501 | } |
| 502 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 503 | // FIXME: this should be implemented in the implementation |
adele | 90285b7 | 2006-07-19 23:54:49 +0000 | [diff] [blame] | 504 | - (BOOL)isFocused |
| 505 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 506 | WebCore::Element* impl = [self _element]; |
adele | 90285b7 | 2006-07-19 23:54:49 +0000 | [diff] [blame] | 507 | if (impl->document()->focusNode() == impl) |
| 508 | return YES; |
| 509 | return NO; |
| 510 | } |
| 511 | |
sullivan | 111f110 | 2005-02-17 00:14:30 +0000 | [diff] [blame] | 512 | @end |
cblu | 4dc540a | 2004-12-06 23:39:15 +0000 | [diff] [blame] | 513 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 514 | |
kocienda | 117559f | 2004-03-01 17:04:26 +0000 | [diff] [blame] | 515 | //------------------------------------------------------------------------------------------ |
kocienda | bb0f452 | 2004-03-02 17:03:56 +0000 | [diff] [blame] | 516 | // DOMRange |
| 517 | |
weinig | c0880e7 | 2006-10-07 17:24:56 +0000 | [diff] [blame] | 518 | @implementation DOMRange (WebPrivate) |
darin | 2de03ad | 2004-06-15 07:46:22 +0000 | [diff] [blame] | 519 | |
darin | 9649a0f | 2004-09-15 05:55:43 +0000 | [diff] [blame] | 520 | - (NSString *)description |
| 521 | { |
| 522 | if (!_internal) |
darin | 02ad24b | 2005-01-20 18:05:19 +0000 | [diff] [blame] | 523 | return @"<DOMRange: null>"; |
adele | 704e8bb | 2005-09-16 22:42:30 +0000 | [diff] [blame] | 524 | return [NSString stringWithFormat:@"<DOMRange: %@ %d %@ %d>", |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 525 | [self startContainer], [self startOffset], [self endContainer], [self endOffset]]; |
darin | 9649a0f | 2004-09-15 05:55:43 +0000 | [diff] [blame] | 526 | } |
| 527 | |
weinig | c0880e7 | 2006-10-07 17:24:56 +0000 | [diff] [blame] | 528 | // FIXME: this should be removed as soon as all internal Apple uses of it have been replaced with |
| 529 | // calls to the public method - (NSString *)text. |
darin | 36cb7c2 | 2004-08-03 18:09:44 +0000 | [diff] [blame] | 530 | - (NSString *)_text |
| 531 | { |
thatcher | 2a6da87 | 2006-07-10 03:02:04 +0000 | [diff] [blame] | 532 | return [self text]; |
darin | 36cb7c2 | 2004-08-03 18:09:44 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | @end |
| 536 | |
cblu | 1846a5a | 2004-04-29 02:05:28 +0000 | [diff] [blame] | 537 | |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 538 | //------------------------------------------------------------------------------------------ |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 539 | // DOMNodeFilter |
cblu | 1846a5a | 2004-04-29 02:05:28 +0000 | [diff] [blame] | 540 | |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 541 | // FIXME: This implementation should be in it's own file. |
| 542 | |
cblu | 1846a5a | 2004-04-29 02:05:28 +0000 | [diff] [blame] | 543 | @implementation DOMNodeFilter |
| 544 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 545 | - (id)_initWithNodeFilter:(WebCore::NodeFilter *)impl |
cblu | 1846a5a | 2004-04-29 02:05:28 +0000 | [diff] [blame] | 546 | { |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 547 | ASSERT(impl); |
| 548 | |
| 549 | [super _init]; |
weinig | 4f67b13 | 2006-09-24 19:34:43 +0000 | [diff] [blame] | 550 | _internal = reinterpret_cast<DOMObjectInternal*>(impl); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 551 | impl->ref(); |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 552 | WebCore::addDOMWrapper(self, impl); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 553 | return self; |
| 554 | } |
| 555 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 556 | + (DOMNodeFilter *)_nodeFilterWith:(WebCore::NodeFilter *)impl |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 557 | { |
| 558 | if (!impl) |
| 559 | return nil; |
| 560 | |
| 561 | id cachedInstance; |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 562 | cachedInstance = WebCore::getDOMWrapper(impl); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 563 | if (cachedInstance) |
| 564 | return [[cachedInstance retain] autorelease]; |
| 565 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 566 | return [[[self alloc] _initWithNodeFilter:impl] autorelease]; |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 567 | } |
| 568 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 569 | - (WebCore::NodeFilter *)_nodeFilter |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 570 | { |
weinig | 4f67b13 | 2006-09-24 19:34:43 +0000 | [diff] [blame] | 571 | return reinterpret_cast<WebCore::NodeFilter*>(_internal); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | - (void)dealloc |
| 575 | { |
| 576 | if (_internal) |
weinig | 4f67b13 | 2006-09-24 19:34:43 +0000 | [diff] [blame] | 577 | reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref(); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 578 | [super dealloc]; |
| 579 | } |
| 580 | |
darin | 2de03ad | 2004-06-15 07:46:22 +0000 | [diff] [blame] | 581 | - (void)finalize |
| 582 | { |
| 583 | if (_internal) |
weinig | 4f67b13 | 2006-09-24 19:34:43 +0000 | [diff] [blame] | 584 | reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref(); |
darin | 2de03ad | 2004-06-15 07:46:22 +0000 | [diff] [blame] | 585 | [super finalize]; |
| 586 | } |
| 587 | |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 588 | - (short)acceptNode:(DOMNode *)node |
| 589 | { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 590 | return [self _nodeFilter]->acceptNode([node _node]); |
cblu | 1846a5a | 2004-04-29 02:05:28 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | @end |
| 594 | |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 595 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 596 | //------------------------------------------------------------------------------------------ |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 597 | // ObjCNodeFilterCondition |
| 598 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 599 | class ObjCNodeFilterCondition : public WebCore::NodeFilterCondition { |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 600 | public: |
| 601 | ObjCNodeFilterCondition(id <DOMNodeFilter>); |
| 602 | virtual ~ObjCNodeFilterCondition(); |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 603 | virtual short acceptNode(WebCore::Node*) const; |
darin | 8aa0b9c | 2004-06-15 05:33:44 +0000 | [diff] [blame] | 604 | |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 605 | private: |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 606 | ObjCNodeFilterCondition(const ObjCNodeFilterCondition&); |
| 607 | ObjCNodeFilterCondition &operator=(const ObjCNodeFilterCondition&); |
darin | 8aa0b9c | 2004-06-15 05:33:44 +0000 | [diff] [blame] | 608 | |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 609 | id <DOMNodeFilter> m_filter; |
| 610 | }; |
| 611 | |
| 612 | ObjCNodeFilterCondition::ObjCNodeFilterCondition(id <DOMNodeFilter> filter) |
| 613 | : m_filter(filter) |
| 614 | { |
| 615 | ASSERT(m_filter); |
darin | 8aa0b9c | 2004-06-15 05:33:44 +0000 | [diff] [blame] | 616 | CFRetain(m_filter); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | ObjCNodeFilterCondition::~ObjCNodeFilterCondition() |
| 620 | { |
darin | 8aa0b9c | 2004-06-15 05:33:44 +0000 | [diff] [blame] | 621 | CFRelease(m_filter); |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 622 | } |
| 623 | |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 624 | short ObjCNodeFilterCondition::acceptNode(WebCore::Node* node) const |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 625 | { |
darin | cfa71ee | 2005-05-18 21:10:26 +0000 | [diff] [blame] | 626 | if (!node) |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 627 | return WebCore::NodeFilter::FILTER_REJECT; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 628 | return [m_filter acceptNode:[DOMNode _nodeWith:node]]; |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 629 | } |
| 630 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 631 | |
| 632 | //------------------------------------------------------------------------------------------ |
| 633 | // DOMDocument (DOMDocumentTraversal) |
| 634 | |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 635 | // FIXME: this should be auto-generated in DOMDocument.mm |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 636 | @implementation DOMDocument (DOMDocumentTraversal) |
| 637 | |
thatcher | aacdbc6 | 2006-09-25 19:04:09 +0000 | [diff] [blame] | 638 | - (DOMNodeIterator *)createNodeIterator:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 639 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 640 | RefPtr<WebCore::NodeFilter> cppFilter; |
darin | 85c3a50 | 2006-02-17 01:08:41 +0000 | [diff] [blame] | 641 | if (filter) |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 642 | cppFilter = new WebCore::NodeFilter(new ObjCNodeFilterCondition(filter)); |
| 643 | WebCore::ExceptionCode ec = 0; |
| 644 | RefPtr<WebCore::NodeIterator> impl = [self _document]->createNodeIterator([root _node], whatToShow, cppFilter, expandEntityReferences, ec); |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 645 | WebCore::raiseOnDOMError(ec); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 646 | return [DOMNodeIterator _nodeIteratorWith:impl.get() filter:filter]; |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 647 | } |
| 648 | |
thatcher | aacdbc6 | 2006-09-25 19:04:09 +0000 | [diff] [blame] | 649 | - (DOMTreeWalker *)createTreeWalker:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences |
kocienda | f6ea03e | 2004-05-04 22:38:00 +0000 | [diff] [blame] | 650 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 651 | RefPtr<WebCore::NodeFilter> cppFilter; |
darin | 85c3a50 | 2006-02-17 01:08:41 +0000 | [diff] [blame] | 652 | if (filter) |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 653 | cppFilter = new WebCore::NodeFilter(new ObjCNodeFilterCondition(filter)); |
| 654 | WebCore::ExceptionCode ec = 0; |
| 655 | RefPtr<WebCore::TreeWalker> impl = [self _document]->createTreeWalker([root _node], whatToShow, cppFilter, expandEntityReferences, ec); |
weinig | b5e0816 | 2006-10-09 23:49:21 +0000 | [diff] [blame] | 656 | WebCore::raiseOnDOMError(ec); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 657 | return [DOMTreeWalker _treeWalkerWith:impl.get() filter:filter]; |
cblu | 1846a5a | 2004-04-29 02:05:28 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | @end |
| 661 | |
thatcher | aacdbc6 | 2006-09-25 19:04:09 +0000 | [diff] [blame] | 662 | @implementation DOMDocument (DOMDocumentTraversalDeprecated) |
| 663 | |
| 664 | - (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences |
| 665 | { |
| 666 | return [self createNodeIterator:root whatToShow:whatToShow filter:filter expandEntityReferences:expandEntityReferences]; |
| 667 | } |
| 668 | |
| 669 | - (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences |
| 670 | { |
| 671 | return [self createTreeWalker:root whatToShow:whatToShow filter:filter expandEntityReferences:expandEntityReferences]; |
| 672 | } |
| 673 | |
| 674 | @end |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 675 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 676 | |
weinig | a8192c0 | 2006-08-28 03:33:34 +0000 | [diff] [blame] | 677 | //------------------------------------------------------------------------------------------ |
| 678 | // ObjCEventListener |
| 679 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 680 | namespace WebCore { |
| 681 | |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 682 | ObjCEventListener* ObjCEventListener::find(id <DOMEventListener> listener) |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 683 | { |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 684 | if (ListenerMap* map = listenerMap) |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 685 | return map->get(listener); |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 686 | return 0; |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | ObjCEventListener *ObjCEventListener::create(id <DOMEventListener> listener) |
| 690 | { |
weinig | 6d74c0d | 2006-09-18 21:40:34 +0000 | [diff] [blame] | 691 | ObjCEventListener* wrapper = find(listener); |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 692 | if (!wrapper) |
| 693 | wrapper = new ObjCEventListener(listener); |
| 694 | wrapper->ref(); |
| 695 | return wrapper; |
| 696 | } |
| 697 | |
| 698 | ObjCEventListener::ObjCEventListener(id <DOMEventListener> listener) |
| 699 | : m_listener([listener retain]) |
| 700 | { |
darin | 7f1d170 | 2006-05-10 07:12:56 +0000 | [diff] [blame] | 701 | ListenerMap* map = listenerMap; |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 702 | if (!map) { |
| 703 | map = new ListenerMap; |
| 704 | listenerMap = map; |
| 705 | } |
mjs | f025068 | 2005-09-28 22:01:41 +0000 | [diff] [blame] | 706 | map->set(listener, this); |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | ObjCEventListener::~ObjCEventListener() |
| 710 | { |
| 711 | listenerMap->remove(m_listener); |
| 712 | [m_listener release]; |
| 713 | } |
| 714 | |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 715 | void ObjCEventListener::handleEvent(Event* event, bool) |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 716 | { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 717 | [m_listener handleEvent:[DOMEvent _eventWith:event]]; |
ggaren | a5ee9a4 | 2005-09-20 07:55:54 +0000 | [diff] [blame] | 718 | } |
weinig | c0f8d23 | 2006-10-11 03:46:36 +0000 | [diff] [blame^] | 719 | |
| 720 | } // namespace WebCore |