WebKit/mac/DOM/WebDOMOperations.mm
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     8  * 1.  Redistributions of source code must retain the above copyright
       
     9  *     notice, this list of conditions and the following disclaimer. 
       
    10  * 2.  Redistributions in binary form must reproduce the above copyright
       
    11  *     notice, this list of conditions and the following disclaimer in the
       
    12  *     documentation and/or other materials provided with the distribution. 
       
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission. 
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 
       
    29 #import "WebDOMOperationsPrivate.h"
       
    30 
       
    31 #import "DOMDocumentInternal.h"
       
    32 #import "DOMElementInternal.h"
       
    33 #import "DOMNodeInternal.h"
       
    34 #import "DOMRangeInternal.h"
       
    35 #import "WebArchiveInternal.h"
       
    36 #import "WebDataSourcePrivate.h"
       
    37 #import "WebFrameInternal.h"
       
    38 #import "WebFramePrivate.h"
       
    39 #import "WebKitNSStringExtras.h"
       
    40 #import <JavaScriptCore/APICast.h>
       
    41 #import <WebCore/CSSHelper.h>
       
    42 #import <WebCore/Document.h>
       
    43 #import <WebCore/JSElement.h>
       
    44 #import <WebCore/LegacyWebArchive.h>
       
    45 #import <WebCore/markup.h>
       
    46 #import <WebCore/RenderTreeAsText.h>
       
    47 #import <WebKit/DOMExtensions.h>
       
    48 #import <WebKit/DOMHTML.h>
       
    49 #import <runtime/JSLock.h>
       
    50 #import <runtime/JSValue.h>
       
    51 #import <wtf/Assertions.h>
       
    52 
       
    53 using namespace WebCore;
       
    54 using namespace JSC;
       
    55 
       
    56 @implementation DOMElement (WebDOMElementOperationsPrivate)
       
    57 
       
    58 + (DOMElement *)_DOMElementFromJSContext:(JSContextRef)context value:(JSValueRef)value
       
    59 {
       
    60     if (!context)
       
    61         return 0;
       
    62 
       
    63     if (!value)
       
    64         return 0;
       
    65 
       
    66     JSLock lock(SilenceAssertionsOnly);
       
    67     return kit(toElement(toJS(toJS(context), value)));
       
    68 }
       
    69 
       
    70 - (NSString *)_markerTextForListItem
       
    71 {
       
    72     return WebCore::markerTextForListItem(core(self));
       
    73 }
       
    74 
       
    75 @end
       
    76 
       
    77 @implementation DOMNode (WebDOMNodeOperations)
       
    78 
       
    79 - (WebArchive *)webArchive
       
    80 {
       
    81     return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core(self))] autorelease];
       
    82 }
       
    83 
       
    84 @end
       
    85 
       
    86 @implementation DOMNode (WebDOMNodeOperationsPendingPublic)
       
    87 
       
    88 - (NSString *)markupString
       
    89 {
       
    90     return createFullMarkup(core(self));
       
    91 }
       
    92 
       
    93 - (NSRect)_renderRect:(bool *)isReplaced
       
    94 {
       
    95     return NSRect(core(self)->renderRect(isReplaced));
       
    96 }
       
    97 
       
    98 @end
       
    99 
       
   100 /* This doesn't appear to be used by anyone.  We should consider removing this. */
       
   101 @implementation DOMNode (WebDOMNodeOperationsInternal)
       
   102 
       
   103 - (NSArray *)_subresourceURLs
       
   104 {
       
   105     ListHashSet<KURL> urls;
       
   106     core(self)->getSubresourceURLs(urls);
       
   107     if (!urls.size())
       
   108         return nil;
       
   109 
       
   110     NSMutableArray *array = [NSMutableArray arrayWithCapacity:urls.size()];
       
   111     ListHashSet<KURL>::iterator end = urls.end();
       
   112     for (ListHashSet<KURL>::iterator it = urls.begin(); it != end; ++it)
       
   113         [array addObject:(NSURL *)*it];
       
   114 
       
   115     return array;
       
   116 }
       
   117 
       
   118 @end
       
   119 
       
   120 @implementation DOMDocument (WebDOMDocumentOperations)
       
   121 
       
   122 - (WebFrame *)webFrame
       
   123 {
       
   124     Document* document = core(self);
       
   125     Frame* frame = document->frame();
       
   126     if (!frame)
       
   127         return nil;
       
   128     return kit(frame);
       
   129 }
       
   130 
       
   131 - (NSURL *)URLWithAttributeString:(NSString *)string
       
   132 {
       
   133     // FIXME: Is deprecatedParseURL appropriate here?
       
   134     return core(self)->completeURL(deprecatedParseURL(string));
       
   135 }
       
   136 
       
   137 @end
       
   138 
       
   139 @implementation DOMDocument (WebDOMDocumentOperationsInternal)
       
   140 
       
   141 /* This doesn't appear to be used by anyone.  We should consider removing this. */
       
   142 - (DOMRange *)_createRangeWithNode:(DOMNode *)node
       
   143 {
       
   144     DOMRange *range = [self createRange];
       
   145     [range selectNode:node];
       
   146     return range;
       
   147 }
       
   148 
       
   149 - (DOMRange *)_documentRange
       
   150 {
       
   151     return [self _createRangeWithNode:[self documentElement]];
       
   152 }
       
   153 
       
   154 @end
       
   155 
       
   156 @implementation DOMDocument (WebDOMDocumentOperationsPrivate)
       
   157 
       
   158 - (NSArray *)_focusableNodes
       
   159 {
       
   160     Vector<RefPtr<Node> > nodes;
       
   161     core(self)->getFocusableNodes(nodes);
       
   162     NSMutableArray *array = [NSMutableArray arrayWithCapacity:nodes.size()];
       
   163     for (unsigned i = 0; i < nodes.size(); ++i)
       
   164         [array addObject:kit(nodes[i].get())];
       
   165     return array;
       
   166 }
       
   167 
       
   168 @end
       
   169 
       
   170 @implementation DOMRange (WebDOMRangeOperations)
       
   171 
       
   172 - (WebArchive *)webArchive
       
   173 {
       
   174     return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core(self))] autorelease];
       
   175 }
       
   176 
       
   177 - (NSString *)markupString
       
   178 {
       
   179     return createFullMarkup(core(self));
       
   180 }
       
   181 
       
   182 @end
       
   183 
       
   184 @implementation DOMHTMLFrameElement (WebDOMHTMLFrameElementOperations)
       
   185 
       
   186 - (WebFrame *)contentFrame
       
   187 {
       
   188     return [[self contentDocument] webFrame];
       
   189 }
       
   190 
       
   191 @end
       
   192 
       
   193 @implementation DOMHTMLIFrameElement (WebDOMHTMLIFrameElementOperations)
       
   194 
       
   195 - (WebFrame *)contentFrame
       
   196 {
       
   197     return [[self contentDocument] webFrame];
       
   198 }
       
   199 
       
   200 @end
       
   201 
       
   202 @implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperations)
       
   203 
       
   204 - (WebFrame *)contentFrame
       
   205 {
       
   206     return [[self contentDocument] webFrame];
       
   207 }
       
   208 
       
   209 @end