|
1 /* |
|
2 * Copyright (C) 2005 Apple Computer, 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 "WebRenderNode.h" |
|
30 |
|
31 #import <WebKit/WebFrameBridge.h> |
|
32 #import <WebKit/WebFrameView.h> |
|
33 #import <WebKit/WebHTMLView.h> |
|
34 #import <WebKit/WebDataSourceInternal.h> |
|
35 #import <WebKit/WebNSViewExtras.h> |
|
36 #import "WebFrameInternal.h" |
|
37 |
|
38 @interface WebKitRenderTreeCopier : NSObject <WebCoreRenderTreeCopier> |
|
39 @end |
|
40 |
|
41 @implementation WebRenderNode |
|
42 |
|
43 - initWithName:(NSString *)n position: (NSPoint)p rect:(NSRect)r view:(NSView *)view children:(NSArray *)c |
|
44 { |
|
45 NSMutableArray *collectChildren; |
|
46 |
|
47 self = [super init]; |
|
48 if (!self) |
|
49 return nil; |
|
50 |
|
51 collectChildren = [c mutableCopy]; |
|
52 |
|
53 name = [n retain]; |
|
54 rect = r; |
|
55 absolutePosition = p; |
|
56 |
|
57 if ([view isKindOfClass:[NSScrollView class]]) { |
|
58 NSScrollView *scrollView = (NSScrollView *)view; |
|
59 view = [scrollView superview]; |
|
60 } |
|
61 if ([view isKindOfClass:[WebFrameView class]]) { |
|
62 WebFrameView *webFrameView = (WebFrameView *)view; |
|
63 WebRenderNode *node = [[WebRenderNode alloc] initWithWebFrameView:webFrameView]; |
|
64 [collectChildren addObject:node]; |
|
65 [node release]; |
|
66 } |
|
67 |
|
68 children = [collectChildren copy]; |
|
69 [collectChildren release]; |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 - initWithWebFrameView:(WebFrameView *)view |
|
75 { |
|
76 WebKitRenderTreeCopier *copier; |
|
77 |
|
78 [self release]; |
|
79 |
|
80 if (![[view documentView] isMemberOfClass:[WebHTMLView class]]) { |
|
81 return nil; |
|
82 } |
|
83 |
|
84 copier = [[WebKitRenderTreeCopier alloc] init]; |
|
85 self = [[[[[view webFrame] _dataSource] _bridge] copyRenderTree:copier] retain]; |
|
86 [copier release]; |
|
87 |
|
88 return self; |
|
89 } |
|
90 |
|
91 - (void)dealloc |
|
92 { |
|
93 [children release]; |
|
94 [name release]; |
|
95 [super dealloc]; |
|
96 } |
|
97 |
|
98 - (NSArray *)children |
|
99 { |
|
100 return children; |
|
101 } |
|
102 |
|
103 - (NSString *)name |
|
104 { |
|
105 return name; |
|
106 } |
|
107 |
|
108 - (NSString *)absolutePositionString |
|
109 { |
|
110 return [NSString stringWithFormat:@"(%.0f, %.0f)", absolutePosition.x, absolutePosition.y]; |
|
111 } |
|
112 |
|
113 - (NSString *)positionString |
|
114 { |
|
115 return [NSString stringWithFormat:@"(%.0f, %.0f)", rect.origin.x, rect.origin.y]; |
|
116 } |
|
117 |
|
118 - (NSString *)widthString |
|
119 { |
|
120 return [NSString stringWithFormat:@"%.0f", rect.size.width]; |
|
121 } |
|
122 |
|
123 - (NSString *)heightString |
|
124 { |
|
125 return [NSString stringWithFormat:@"%.0f", rect.size.height]; |
|
126 } |
|
127 |
|
128 @end |
|
129 |
|
130 @implementation WebKitRenderTreeCopier |
|
131 |
|
132 - (NSObject *)nodeWithName:(NSString *)name position: (NSPoint)p rect:(NSRect)rect view:(NSView *)view children:(NSArray *)children |
|
133 { |
|
134 return [[[WebRenderNode alloc] initWithName:name position: p rect:rect view:view children:children] autorelease]; |
|
135 } |
|
136 |
|
137 @end |