DOM.mm 17 KB
Newer Older
kocienda's avatar
kocienda committed
1
/*
darin@apple.com's avatar
darin@apple.com committed
2
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
ddkilzer's avatar
ddkilzer committed
3
 * Copyright (C) 2006 James G. Speth (speth@end.com)
weinig's avatar
weinig committed
4
 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
kocienda's avatar
kocienda committed
5 6 7 8
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
darin's avatar
darin committed
9
 * 1. Redistributions of source code must retain the above copyright
kocienda's avatar
kocienda committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

darin's avatar
darin committed
28
#import "config.h"
darin@apple.com's avatar
darin@apple.com committed
29
#import "DOMInternal.h" // import first to make the private/public trick work
kocienda's avatar
kocienda committed
30
#import "DOM.h"
kocienda's avatar
kocienda committed
31

32
#import "CachedImage.h"
darin@apple.com's avatar
darin@apple.com committed
33
#import "DOMElementInternal.h"
darin's avatar
darin committed
34
#import "DOMHTMLCanvasElement.h"
35
#import "DOMHTMLTableCellElementInternal.h"
36
#import "DOMNodeInternal.h"
37
#import "DOMPrivate.h"
38
#import "DOMRangeInternal.h"
39
#import "Font.h"
40
#import "Frame.h"
darin@apple.com's avatar
darin@apple.com committed
41
#import "HTMLElement.h"
42
#import "HTMLNames.h"
43
#import "HTMLParserIdioms.h"
44
#import "HTMLTableCellElement.h"
45
#import "Image.h"
46
#import "JSNode.h"
darin@apple.com's avatar
darin@apple.com committed
47
#import "NodeFilter.h"
48
#import "RenderImage.h"
darin@apple.com's avatar
darin@apple.com committed
49
#import "WebScriptObjectPrivate.h"
50
#import <JavaScriptCore/APICast.h>
weinig's avatar
weinig committed
51
#import <wtf/HashMap.h>
kocienda's avatar
kocienda committed
52

53
using namespace JSC;
darin@apple.com's avatar
darin@apple.com committed
54 55
using namespace WebCore;

darin@apple.com's avatar
darin@apple.com committed
56 57 58
// FIXME: Would be nice to break this up into separate files to match how other WebKit
// code is organized.

kocienda's avatar
kocienda committed
59
//------------------------------------------------------------------------------------------
kocienda's avatar
Tests:  
kocienda committed
60
// DOMNode
kocienda's avatar
kocienda committed
61

weinig's avatar
weinig committed
62 63
namespace WebCore {

64
typedef HashMap<const QualifiedName::QualifiedNameImpl*, Class> ObjCClassMap;
weinig's avatar
weinig committed
65 66 67
static ObjCClassMap* elementClassMap;

static void addElementClass(const QualifiedName& tag, Class objCClass)
68
{
69
    elementClassMap->set(tag.impl(), objCClass);
70 71
}

weinig's avatar
weinig committed
72
static void createElementClassMap()
73 74 75 76 77 78
{
    // Create the table.
    elementClassMap = new ObjCClassMap;

    // FIXME: Reflect marquee once the API has been determined.

weinig's avatar
weinig committed
79 80 81 82 83 84 85 86 87
    // Populate it with HTML and SVG element classes.
    addElementClass(HTMLNames::aTag, [DOMHTMLAnchorElement class]);
    addElementClass(HTMLNames::appletTag, [DOMHTMLAppletElement class]);
    addElementClass(HTMLNames::areaTag, [DOMHTMLAreaElement class]);
    addElementClass(HTMLNames::baseTag, [DOMHTMLBaseElement class]);
    addElementClass(HTMLNames::basefontTag, [DOMHTMLBaseFontElement class]);
    addElementClass(HTMLNames::bodyTag, [DOMHTMLBodyElement class]);
    addElementClass(HTMLNames::brTag, [DOMHTMLBRElement class]);
    addElementClass(HTMLNames::buttonTag, [DOMHTMLButtonElement class]);
darin's avatar
darin committed
88
    addElementClass(HTMLNames::canvasTag, [DOMHTMLCanvasElement class]);
weinig's avatar
weinig committed
89 90 91
    addElementClass(HTMLNames::captionTag, [DOMHTMLTableCaptionElement class]);
    addElementClass(HTMLNames::colTag, [DOMHTMLTableColElement class]);
    addElementClass(HTMLNames::colgroupTag, [DOMHTMLTableColElement class]);
darin's avatar
darin committed
92
    addElementClass(HTMLNames::delTag, [DOMHTMLModElement class]);
weinig's avatar
weinig committed
93 94 95
    addElementClass(HTMLNames::dirTag, [DOMHTMLDirectoryElement class]);
    addElementClass(HTMLNames::divTag, [DOMHTMLDivElement class]);
    addElementClass(HTMLNames::dlTag, [DOMHTMLDListElement class]);
darin's avatar
darin committed
96
    addElementClass(HTMLNames::embedTag, [DOMHTMLEmbedElement class]);
weinig's avatar
weinig committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    addElementClass(HTMLNames::fieldsetTag, [DOMHTMLFieldSetElement class]);
    addElementClass(HTMLNames::fontTag, [DOMHTMLFontElement class]);
    addElementClass(HTMLNames::formTag, [DOMHTMLFormElement class]);
    addElementClass(HTMLNames::frameTag, [DOMHTMLFrameElement class]);
    addElementClass(HTMLNames::framesetTag, [DOMHTMLFrameSetElement class]);
    addElementClass(HTMLNames::h1Tag, [DOMHTMLHeadingElement class]);
    addElementClass(HTMLNames::h2Tag, [DOMHTMLHeadingElement class]);
    addElementClass(HTMLNames::h3Tag, [DOMHTMLHeadingElement class]);
    addElementClass(HTMLNames::h4Tag, [DOMHTMLHeadingElement class]);
    addElementClass(HTMLNames::h5Tag, [DOMHTMLHeadingElement class]);
    addElementClass(HTMLNames::h6Tag, [DOMHTMLHeadingElement class]);
    addElementClass(HTMLNames::headTag, [DOMHTMLHeadElement class]);
    addElementClass(HTMLNames::hrTag, [DOMHTMLHRElement class]);
    addElementClass(HTMLNames::htmlTag, [DOMHTMLHtmlElement class]);
    addElementClass(HTMLNames::iframeTag, [DOMHTMLIFrameElement class]);
    addElementClass(HTMLNames::imgTag, [DOMHTMLImageElement class]);
    addElementClass(HTMLNames::inputTag, [DOMHTMLInputElement class]);
darin's avatar
darin committed
114
    addElementClass(HTMLNames::insTag, [DOMHTMLModElement class]);
weinig's avatar
weinig committed
115 116 117 118 119 120
    addElementClass(HTMLNames::labelTag, [DOMHTMLLabelElement class]);
    addElementClass(HTMLNames::legendTag, [DOMHTMLLegendElement class]);
    addElementClass(HTMLNames::liTag, [DOMHTMLLIElement class]);
    addElementClass(HTMLNames::linkTag, [DOMHTMLLinkElement class]);
    addElementClass(HTMLNames::listingTag, [DOMHTMLPreElement class]);
    addElementClass(HTMLNames::mapTag, [DOMHTMLMapElement class]);
weinig's avatar
weinig committed
121
    addElementClass(HTMLNames::marqueeTag, [DOMHTMLMarqueeElement class]);
weinig's avatar
weinig committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    addElementClass(HTMLNames::menuTag, [DOMHTMLMenuElement class]);
    addElementClass(HTMLNames::metaTag, [DOMHTMLMetaElement class]);
    addElementClass(HTMLNames::objectTag, [DOMHTMLObjectElement class]);
    addElementClass(HTMLNames::olTag, [DOMHTMLOListElement class]);
    addElementClass(HTMLNames::optgroupTag, [DOMHTMLOptGroupElement class]);
    addElementClass(HTMLNames::optionTag, [DOMHTMLOptionElement class]);
    addElementClass(HTMLNames::pTag, [DOMHTMLParagraphElement class]);
    addElementClass(HTMLNames::paramTag, [DOMHTMLParamElement class]);
    addElementClass(HTMLNames::preTag, [DOMHTMLPreElement class]);
    addElementClass(HTMLNames::qTag, [DOMHTMLQuoteElement class]);
    addElementClass(HTMLNames::scriptTag, [DOMHTMLScriptElement class]);
    addElementClass(HTMLNames::selectTag, [DOMHTMLSelectElement class]);
    addElementClass(HTMLNames::styleTag, [DOMHTMLStyleElement class]);
    addElementClass(HTMLNames::tableTag, [DOMHTMLTableElement class]);
    addElementClass(HTMLNames::tbodyTag, [DOMHTMLTableSectionElement class]);
    addElementClass(HTMLNames::tdTag, [DOMHTMLTableCellElement class]);
    addElementClass(HTMLNames::textareaTag, [DOMHTMLTextAreaElement class]);
    addElementClass(HTMLNames::tfootTag, [DOMHTMLTableSectionElement class]);
darin's avatar
darin committed
140
    addElementClass(HTMLNames::thTag, [DOMHTMLTableCellElement class]);
weinig's avatar
weinig committed
141 142 143 144
    addElementClass(HTMLNames::theadTag, [DOMHTMLTableSectionElement class]);
    addElementClass(HTMLNames::titleTag, [DOMHTMLTitleElement class]);
    addElementClass(HTMLNames::trTag, [DOMHTMLTableRowElement class]);
    addElementClass(HTMLNames::ulTag, [DOMHTMLUListElement class]);
darin's avatar
darin committed
145
    addElementClass(HTMLNames::xmpTag, [DOMHTMLPreElement class]);
weinig's avatar
weinig committed
146 147
}

148 149 150 151 152 153 154 155 156
static Class lookupElementClass(const QualifiedName& tag)
{
    // Do a special lookup to ignore element prefixes
    if (tag.hasPrefix())
        return elementClassMap->get(QualifiedName(nullAtom, tag.localName(), tag.namespaceURI()).impl());
    
    return elementClassMap->get(tag.impl());
}

weinig's avatar
weinig committed
157
static Class elementClass(const QualifiedName& tag, Class defaultClass)
158 159
{
    if (!elementClassMap)
weinig's avatar
weinig committed
160
        createElementClassMap();
161
    Class objcClass = lookupElementClass(tag);
162
    if (!objcClass)
weinig's avatar
weinig committed
163
        objcClass = defaultClass;
164 165 166
    return objcClass;
}

thatcher's avatar
thatcher committed
167 168 169 170 171 172 173 174 175
static NSArray *kit(const Vector<IntRect>& rects)
{
    size_t size = rects.size();
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:size];
    for (size_t i = 0; i < size; ++i)
        [array addObject:[NSValue valueWithRect:rects[i]]];
    return array;
}

weinig's avatar
weinig committed
176 177
} // namespace WebCore

kocienda's avatar
Tests:  
kocienda committed
178
@implementation DOMNode (WebCoreInternal)
kocienda's avatar
kocienda committed
179

weinig's avatar
weinig committed
180 181
- (NSString *)description
{
weinig's avatar
weinig committed
182
    if (!_internal)
183
        return [NSString stringWithFormat:@"<%@: null>", [[self class] description]];
weinig's avatar
weinig committed
184

weinig's avatar
weinig committed
185
    NSString *value = [self nodeValue];
weinig's avatar
weinig committed
186
    if (value)
weinig's avatar
weinig committed
187 188
        return [NSString stringWithFormat:@"<%@ [%@]: %p '%@'>",
            [[self class] description], [self nodeName], _internal, value];
weinig's avatar
weinig committed
189 190

    return [NSString stringWithFormat:@"<%@ [%@]: %p>", [[self class] description], [self nodeName], _internal];
weinig's avatar
weinig committed
191 192
}

darin@apple.com's avatar
darin@apple.com committed
193
- (JSC::Bindings::RootObject*)_rootObject
kocienda's avatar
kocienda committed
194
{
darin@apple.com's avatar
darin@apple.com committed
195 196 197 198
    WebCore::Frame* frame = core(self)->document()->frame();
    if (!frame)
        return 0;
    return frame->script()->bindingRootObject();
kocienda's avatar
kocienda committed
199 200
}

darin@apple.com's avatar
darin@apple.com committed
201
@end
weinig's avatar
weinig committed
202

darin@apple.com's avatar
darin@apple.com committed
203 204
Class kitClass(WebCore::Node* impl)
{
kocienda's avatar
Tests:  
kocienda committed
205
    switch (impl->nodeType()) {
weinig's avatar
weinig committed
206
        case WebCore::Node::ELEMENT_NODE:
207
            if (impl->isHTMLElement())
208
                return WebCore::elementClass(toHTMLElement(impl)->tagQName(), [DOMHTMLElement class]);
darin@apple.com's avatar
darin@apple.com committed
209
            return [DOMElement class];
weinig's avatar
weinig committed
210
        case WebCore::Node::ATTRIBUTE_NODE:
darin@apple.com's avatar
darin@apple.com committed
211
            return [DOMAttr class];
weinig's avatar
weinig committed
212
        case WebCore::Node::TEXT_NODE:
darin@apple.com's avatar
darin@apple.com committed
213
            return [DOMText class];
weinig's avatar
weinig committed
214
        case WebCore::Node::CDATA_SECTION_NODE:
darin@apple.com's avatar
darin@apple.com committed
215
            return [DOMCDATASection class];
weinig's avatar
weinig committed
216
        case WebCore::Node::ENTITY_REFERENCE_NODE:
darin@apple.com's avatar
darin@apple.com committed
217
            return [DOMEntityReference class];
weinig's avatar
weinig committed
218
        case WebCore::Node::ENTITY_NODE:
darin@apple.com's avatar
darin@apple.com committed
219
            return [DOMEntity class];
weinig's avatar
weinig committed
220
        case WebCore::Node::PROCESSING_INSTRUCTION_NODE:
darin@apple.com's avatar
darin@apple.com committed
221
            return [DOMProcessingInstruction class];
weinig's avatar
weinig committed
222
        case WebCore::Node::COMMENT_NODE:
darin@apple.com's avatar
darin@apple.com committed
223
            return [DOMComment class];
weinig's avatar
weinig committed
224 225
        case WebCore::Node::DOCUMENT_NODE:
            if (static_cast<WebCore::Document*>(impl)->isHTMLDocument())
darin@apple.com's avatar
darin@apple.com committed
226 227
                return [DOMHTMLDocument class];
            return [DOMDocument class];
weinig's avatar
weinig committed
228
        case WebCore::Node::DOCUMENT_TYPE_NODE:
darin@apple.com's avatar
darin@apple.com committed
229
            return [DOMDocumentType class];
weinig's avatar
weinig committed
230
        case WebCore::Node::DOCUMENT_FRAGMENT_NODE:
darin@apple.com's avatar
darin@apple.com committed
231
            return [DOMDocumentFragment class];
weinig's avatar
weinig committed
232
        case WebCore::Node::NOTATION_NODE:
darin@apple.com's avatar
darin@apple.com committed
233
            return [DOMNotation class];
weinig's avatar
weinig committed
234
        case WebCore::Node::XPATH_NAMESPACE_NODE:
235
            // FIXME: Create an XPath objective C wrapper
darin's avatar
darin committed
236
            // See http://bugs.webkit.org/show_bug.cgi?id=8755
237
            return nil;
kocienda's avatar
Tests:  
kocienda committed
238
    }
darin@apple.com's avatar
darin@apple.com committed
239 240
    ASSERT_NOT_REACHED();
    return nil;
kocienda's avatar
kocienda committed
241 242
}

darin@apple.com's avatar
darin@apple.com committed
243
id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
ap's avatar
ap committed
244 245 246
{
    if (!eventTarget)
        return nil;
zimmermann@webkit.org's avatar
zimmermann@webkit.org committed
247

darin@apple.com's avatar
darin@apple.com committed
248 249
    if (WebCore::Node* node = eventTarget->toNode())
        return kit(node);
ap's avatar
ap committed
250

darin@apple.com's avatar
darin@apple.com committed
251
    // We don't have an ObjC binding for XMLHttpRequest.
rjw's avatar
rjw committed
252

darin@apple.com's avatar
darin@apple.com committed
253 254
    return nil;
}
kocienda's avatar
kocienda committed
255

weinig's avatar
weinig committed
256 257 258 259
@implementation DOMNode (DOMNodeExtensions)

- (NSRect)boundingBox
{
darin@apple.com's avatar
darin@apple.com committed
260 261 262 263 264 265
    // FIXME: Could we move this function to WebCore::Node and autogenerate?
    core(self)->document()->updateLayoutIgnorePendingStylesheets();
    WebCore::RenderObject* renderer = core(self)->renderer();
    if (!renderer)
        return NSZeroRect;
    return renderer->absoluteBoundingBoxRect();
weinig's avatar
weinig committed
266 267
}

268 269 270 271 272
- (NSArray *)lineBoxRects
{
    return [self textRects];
}

zimmermann@webkit.org's avatar
zimmermann@webkit.org committed
273 274
@end

275 276 277 278
@implementation DOMNode (DOMNodeExtensionsPendingPublic)

- (NSImage *)renderedImage
{
darin@apple.com's avatar
darin@apple.com committed
279 280 281 282 283
    // FIXME: Could we move this function to WebCore::Node and autogenerate?
    WebCore::Node* node = core(self);
    WebCore::Frame* frame = node->document()->frame();
    if (!frame)
        return nil;
284
    return frame->nodeImage(node).get();
285 286
}

287 288 289 290 291 292
- (NSArray *)textRects
{
    core(self)->document()->updateLayoutIgnorePendingStylesheets();
    if (!core(self)->renderer())
        return nil;
    Vector<WebCore::IntRect> rects;
293
    core(self)->textRects(rects);
294 295
    return kit(rects);
}
296

297 298
@end

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
@implementation DOMNode (WebPrivate)

+ (id)_nodeFromJSWrapper:(JSObjectRef)jsWrapper
{
    JSObject* object = toJS(jsWrapper);

    if (!object->inherits(&JSNode::s_info))
        return nil;

    WebCore::Node* node = jsCast<JSNode*>(object)->impl();
    return kit(node);
}

@end

thatcher's avatar
thatcher committed
314 315 316 317
@implementation DOMRange (DOMRangeExtensions)

- (NSRect)boundingBox
{
darin@apple.com's avatar
darin@apple.com committed
318 319 320
    // FIXME: The call to updateLayoutIgnorePendingStylesheets should be moved into WebCore::Range.
    core(self)->ownerDocument()->updateLayoutIgnorePendingStylesheets();
    return core(self)->boundingBox();
thatcher's avatar
thatcher committed
321 322
}

323 324 325 326 327 328 329 330 331 332
- (NSImage *)renderedImageForcingBlackText:(BOOL)forceBlackText
{
    WebCore::Range* range = core(self);
    WebCore::Frame* frame = range->ownerDocument()->frame();
    if (!frame)
        return nil;

    return frame->rangeImage(range, forceBlackText);
}

333
- (NSArray *)textRects
thatcher's avatar
thatcher committed
334
{
darin@apple.com's avatar
darin@apple.com committed
335
    // FIXME: The call to updateLayoutIgnorePendingStylesheets should be moved into WebCore::Range.
thatcher's avatar
thatcher committed
336
    Vector<WebCore::IntRect> rects;
darin@apple.com's avatar
darin@apple.com committed
337
    core(self)->ownerDocument()->updateLayoutIgnorePendingStylesheets();
338
    core(self)->textRects(rects);
thatcher's avatar
thatcher committed
339 340 341
    return kit(rects);
}

342 343 344 345 346 347
- (NSArray *)lineBoxRects
{
    // FIXME: Remove this once all clients stop using it and we drop Leopard support.
    return [self textRects];
}

thatcher's avatar
thatcher committed
348 349
@end

weinig's avatar
weinig committed
350 351 352 353
//------------------------------------------------------------------------------------------
// DOMElement

@implementation DOMElement (DOMElementAppKitExtensions)
adele's avatar
adele committed
354

thatcher's avatar
thatcher committed
355 356
- (NSImage*)image
{
darin@apple.com's avatar
darin@apple.com committed
357 358 359 360 361 362 363
    // FIXME: Could we move this function to WebCore::Node and autogenerate?
    WebCore::RenderObject* renderer = core(self)->renderer();
    if (!renderer || !renderer->isImage())
        return nil;
    WebCore::CachedImage* cachedImage = static_cast<WebCore::RenderImage*>(renderer)->cachedImage();
    if (!cachedImage || cachedImage->errorOccurred())
        return nil;
364
    return cachedImage->imageForRenderer(renderer)->getNSImage();
thatcher's avatar
thatcher committed
365 366
}

adele's avatar
adele committed
367 368
@end

369 370 371 372
@implementation DOMElement (WebPrivate)

- (NSFont *)_font
{
darin@apple.com's avatar
darin@apple.com committed
373 374 375 376 377
    // FIXME: Could we move this function to WebCore::Element and autogenerate?
    WebCore::RenderObject* renderer = core(self)->renderer();
    if (!renderer)
        return nil;
    return renderer->style()->font().primaryFont()->getNSFont();
378 379
}

weinig's avatar
weinig committed
380
- (NSData *)_imageTIFFRepresentation
381
{
darin@apple.com's avatar
darin@apple.com committed
382 383 384 385 386 387 388
    // FIXME: Could we move this function to WebCore::Element and autogenerate?
    WebCore::RenderObject* renderer = core(self)->renderer();
    if (!renderer || !renderer->isImage())
        return nil;
    WebCore::CachedImage* cachedImage = static_cast<WebCore::RenderImage*>(renderer)->cachedImage();
    if (!cachedImage || cachedImage->errorOccurred())
        return nil;
389
    return (NSData *)cachedImage->imageForRenderer(renderer)->getTIFFRepresentation();
390 391
}

sullivan's avatar
sullivan committed
392 393
- (NSURL *)_getURLAttribute:(NSString *)name
{
darin@apple.com's avatar
darin@apple.com committed
394
    // FIXME: Could we move this function to WebCore::Element and autogenerate?
sullivan's avatar
sullivan committed
395
    ASSERT(name);
darin@apple.com's avatar
darin@apple.com committed
396
    WebCore::Element* element = core(self);
weinig's avatar
weinig committed
397
    ASSERT(element);
398
    return element->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(element->getAttribute(name)));
sullivan's avatar
sullivan committed
399
}
400

adele's avatar
adele committed
401 402
- (BOOL)isFocused
{
darin@apple.com's avatar
darin@apple.com committed
403 404 405
    // FIXME: Could we move this function to WebCore::Element and autogenerate?
    WebCore::Element* element = core(self);
    return element->document()->focusedNode() == element;
adele's avatar
adele committed
406 407
}

sullivan's avatar
sullivan committed
408
@end
409

kocienda's avatar
Tests:  
kocienda committed
410
//------------------------------------------------------------------------------------------
kocienda's avatar
Tests:  
kocienda committed
411
// DOMRange
kocienda's avatar
kocienda committed
412

weinig's avatar
weinig committed
413
@implementation DOMRange (WebPrivate)
darin's avatar
darin committed
414

darin's avatar
darin committed
415 416 417
- (NSString *)description
{
    if (!_internal)
darin's avatar
darin committed
418
        return @"<DOMRange: null>";
adele's avatar
adele committed
419
    return [NSString stringWithFormat:@"<DOMRange: %@ %d %@ %d>",
weinig's avatar
weinig committed
420
               [self startContainer], [self startOffset], [self endContainer], [self endOffset]];
darin's avatar
darin committed
421 422
}

darin@apple.com's avatar
darin@apple.com committed
423
// FIXME: This should be removed as soon as all internal Apple uses of it have been replaced with
weinig's avatar
weinig committed
424
// calls to the public method - (NSString *)text.
darin's avatar
darin committed
425 426
- (NSString *)_text
{
thatcher's avatar
thatcher committed
427
    return [self text];
darin's avatar
darin committed
428 429 430 431
}

@end

weinig@apple.com's avatar
weinig@apple.com committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
//------------------------------------------------------------------------------------------
// DOMRGBColor

@implementation DOMRGBColor (WebPrivate)

// FIXME: This should be removed as soon as all internal Apple uses of it have been replaced with
// calls to the public method - (NSColor *)color.
- (NSColor *)_color
{
    return [self color];
}

@end


447 448 449 450 451 452 453 454 455
@implementation DOMHTMLTableCellElement (WebPrivate)

- (DOMHTMLTableCellElement *)_cellAbove
{
    return kit(core(self)->cellAbove());
}

@end

kocienda's avatar
kocienda committed
456
//------------------------------------------------------------------------------------------
weinig's avatar
weinig committed
457
// DOMNodeFilter
kocienda's avatar
kocienda committed
458

darin@apple.com's avatar
darin@apple.com committed
459
DOMNodeFilter *kit(WebCore::NodeFilter* impl)
460
{
kocienda's avatar
kocienda committed
461 462
    if (!impl)
        return nil;
darin@apple.com's avatar
darin@apple.com committed
463 464 465 466 467 468 469 470 471
    
    if (DOMNodeFilter *wrapper = getDOMWrapper(impl))
        return [[wrapper retain] autorelease];
    
    DOMNodeFilter *wrapper = [[DOMNodeFilter alloc] _init];
    wrapper->_internal = reinterpret_cast<DOMObjectInternal*>(impl);
    impl->ref();
    addDOMWrapper(wrapper, impl);
    return [wrapper autorelease];
472 473
}

darin@apple.com's avatar
darin@apple.com committed
474
WebCore::NodeFilter* core(DOMNodeFilter *wrapper)
kocienda's avatar
kocienda committed
475
{
darin@apple.com's avatar
darin@apple.com committed
476
    return wrapper ? reinterpret_cast<WebCore::NodeFilter*>(wrapper->_internal) : 0;
kocienda's avatar
kocienda committed
477
}
478

darin@apple.com's avatar
darin@apple.com committed
479 480
@implementation DOMNodeFilter

kocienda's avatar
kocienda committed
481 482 483
- (void)dealloc
{
    if (_internal)
weinig's avatar
weinig committed
484
        reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref();
kocienda's avatar
kocienda committed
485 486
    [super dealloc];
}
487

darin's avatar
darin committed
488 489 490
- (void)finalize
{
    if (_internal)
weinig's avatar
weinig committed
491
        reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref();
darin's avatar
darin committed
492 493 494
    [super finalize];
}

kocienda's avatar
kocienda committed
495
- (short)acceptNode:(DOMNode *)node
496
{
darin@apple.com's avatar
darin@apple.com committed
497
    return core(self)->acceptNode(core(node));
498 499 500
}

@end