~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/bindings/objc/DOM.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

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