Commit 7c79e17d authored by mjs's avatar mjs

Reviewed by Eric.

	- moved frame traversal logic from WebFrame to WebBridge
	http://bugzilla.opendarwin.org/show_bug.cgi?id=6341

	To do this, I had to invert the ownership so that WebBridge now
	owns WebFrame instead of vice versa. As a result, WebView now owns
	a WebBridge pointer and does not have a direct WebFrame pointer.

        * WebCoreSupport.subproj/WebBridge.h:
        * WebCoreSupport.subproj/WebBridge.m:
        (-[WebBridge initWithFrameName:view:]): The initializer is now responsible for creating
	the frame, so pass it what it needs to do that.
        (-[WebBridge dealloc]): The bridge now owns the frame, so release it.
        (-[WebBridge close]): ditto
        (-[WebBridge firstChild]): Moved from WebFrame
        (-[WebBridge lastChild]): ditto
        (-[WebBridge childCount]): ditto
        (-[WebBridge previousSibling]): ditto
        (-[WebBridge nextSibling]): ditto
        (-[WebBridge isDescendantOfFrame:]): ditto
        (-[WebBridge traverseNextFrameStayWithin:]): ditto
        (-[WebBridge appendChild:]): ditto
        (-[WebBridge removeChild:]): ditto
        * WebView.subproj/WebFrame.m:
        (-[WebFrame _removeChild::]): Call WebBridge version
        (-[WebFramePrivate dealloc]): ditto
        (-[WebFrame _firstChildFrame]): ditto
        (-[WebFrame _lastChildFrame]): ditto
        (-[WebFrame _childFrameCount]): ditto
        (-[WebFrame _previousSiblingFrame]): ditto
        (-[WebFrame _nextSiblingFrame]): ditto
        (-[WebFrame _traverseNextFrameStayWithin:]): ditto
        (-[WebFrame _appendChild:]): ditto
        (-[WebFrame _removeChild:]): ditto
        (-[WebFrame _isDescendantOfFrame:]): ditto,
        (-[WebFrame _detachFromParent]): reorder a bit to avoid losing our bridge
	pointer before the bridge is due to release us, and don't release the
	bridge any more since it now owns us
        (-[WebFrame _initWithName:webFrameView:webView:bridge:]): new initializer,
	we no longer create the bridge, instead it is passed in
        (-[WebFrame initWithName:webFrameView:webView:]): Call the new designated
	initializer, but this method is no longer viable and should be deprecated.
        * WebView.subproj/WebFrameInternal.h:

	* WebView.subproj/WebView.m: WebView was changed to hold onto
	the WebBridge for the main frame instead of the WebFrame.

        (-[WebViewPrivate dealloc]): update for the fact that we hold
	a bridge now, not a frame.
        (-[WebView _close]): ditto
        (-[WebView _createFrameNamed:inParent:allowsScrolling:]): Create
	a bridge, not a frame.
        (-[WebView _commonInitializationWithFrameName:groupName:]): ditto.
        (-[WebView setDefersCallbacks:]): get mainFrame via method
        (-[WebView mainFrame]): Update to get the main frame properly


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@11851 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bf2dc456
2006-01-02 Maciej Stachowiak <mjs@apple.com>
Reviewed by Eric.
- moved frame traversal logic from WebFrame to WebBridge
http://bugzilla.opendarwin.org/show_bug.cgi?id=6341
To do this, I had to invert the ownership so that WebBridge now
owns WebFrame instead of vice versa. As a result, WebView now owns
a WebBridge pointer and does not have a direct WebFrame pointer.
* WebCoreSupport.subproj/WebBridge.h:
* WebCoreSupport.subproj/WebBridge.m:
(-[WebBridge initWithFrameName:view:]): The initializer is now responsible for creating
the frame, so pass it what it needs to do that.
(-[WebBridge dealloc]): The bridge now owns the frame, so release it.
(-[WebBridge close]): ditto
(-[WebBridge firstChild]): Moved from WebFrame
(-[WebBridge lastChild]): ditto
(-[WebBridge childCount]): ditto
(-[WebBridge previousSibling]): ditto
(-[WebBridge nextSibling]): ditto
(-[WebBridge isDescendantOfFrame:]): ditto
(-[WebBridge traverseNextFrameStayWithin:]): ditto
(-[WebBridge appendChild:]): ditto
(-[WebBridge removeChild:]): ditto
* WebView.subproj/WebFrame.m:
(-[WebFrame _removeChild::]): Call WebBridge version
(-[WebFramePrivate dealloc]): ditto
(-[WebFrame _firstChildFrame]): ditto
(-[WebFrame _lastChildFrame]): ditto
(-[WebFrame _childFrameCount]): ditto
(-[WebFrame _previousSiblingFrame]): ditto
(-[WebFrame _nextSiblingFrame]): ditto
(-[WebFrame _traverseNextFrameStayWithin:]): ditto
(-[WebFrame _appendChild:]): ditto
(-[WebFrame _removeChild:]): ditto
(-[WebFrame _isDescendantOfFrame:]): ditto,
(-[WebFrame _detachFromParent]): reorder a bit to avoid losing our bridge
pointer before the bridge is due to release us, and don't release the
bridge any more since it now owns us
(-[WebFrame _initWithName:webFrameView:webView:bridge:]): new initializer,
we no longer create the bridge, instead it is passed in
(-[WebFrame initWithName:webFrameView:webView:]): Call the new designated
initializer, but this method is no longer viable and should be deprecated.
* WebView.subproj/WebFrameInternal.h:
* WebView.subproj/WebView.m: WebView was changed to hold onto
the WebBridge for the main frame instead of the WebFrame.
(-[WebViewPrivate dealloc]): update for the fact that we hold
a bridge now, not a frame.
(-[WebView _close]): ditto
(-[WebView _createFrameNamed:inParent:allowsScrolling:]): Create
a bridge, not a frame.
(-[WebView _commonInitializationWithFrameName:groupName:]): ditto.
(-[WebView setDefersCallbacks:]): get mainFrame via method
(-[WebView mainFrame]): Update to get the main frame properly
2005-12-30 Mitz Pettel <opendarwin.org@mitzpettel.com>
Reviewed by Darin, landed by ap.
......@@ -34,7 +34,10 @@
@interface WebBridge : WebCoreBridge <WebCoreBridge>
{
WebBridge *_parentBridge;
WebBridge *_nextSibling;
WebBridge *_previousSibling;
NSMutableArray *_children;
WebFrame *_frame;
WebCoreKeyboardUIMode _keyboardUIMode;
BOOL _keyboardUIModeAccessed;
......@@ -45,7 +48,7 @@
NSDictionary *lastDashboardRegions;
}
- (id)initWithWebFrame:(WebFrame *)webFrame;
- (id)initWithFrameName:(NSString *)name view:(WebFrameView *)view ;
- (void)close;
- (void)receivedData:(NSData *)data textEncodingName:(NSString *)textEncodingName;
......@@ -54,4 +57,17 @@
- (WebFrame *)webFrame;
- (WebBridge *)firstChild;
- (WebBridge *)lastChild;
- (WebBridge *)previousSibling;
- (WebBridge *)nextSibling;
- (void)appendChild:(WebBridge *)child;
- (void)removeChild:(WebBridge *)child;
- (unsigned)childCount;
- (BOOL)isDescendantOfFrame:(WebBridge *)ancestor;
- (WebBridge *)traverseNextFrameStayWithin:(WebBridge *)stayWithin;
@end
......@@ -115,20 +115,17 @@ - (jobject)pollForAppletInWindow: (NSWindow *)window;
@implementation WebBridge
- (id)initWithWebFrame:(WebFrame *)webFrame
- (id)initWithFrameName:(NSString *)name view:(WebFrameView *)view
{
self = [super init];
++WebBridgeCount;
WebView *webView = [webFrame webView];
// Non-retained because data source owns representation owns bridge.
// But WebFrame will call close on us before it goes away, which
// guarantees we will not have a stale reference.
_frame = webFrame;
WebView *webView = [view _webView];
_frame = [[WebFrame alloc] _initWithName:name webFrameView:view webView:webView bridge:self];
[self setName:[webFrame name]];
[self setName:[_frame name]];
[self initializeSettings:[webView _settings]];
[self setTextSizeMultiplier:[webView textSizeMultiplier]];
......@@ -152,6 +149,8 @@ - (void)fini
- (void)dealloc
{
[lastDashboardRegions release];
[_frame release];
[_children release];
[self fini];
[super dealloc];
......@@ -641,6 +640,7 @@ - (void)reportClientRedirectCancelled:(BOOL)cancelWithLoadInProgress
- (void)close
{
[_frame release];
_frame = nil;
}
......@@ -1726,4 +1726,103 @@ - (void)handledOnloadEvents
[_frame _handledOnloadEvents];
}
- (WebBridge *)firstChild
{
if (![_children count])
return nil;
return [_children objectAtIndex:0];
}
- (WebBridge *)lastChild
{
return [_children lastObject];
}
- (unsigned)childCount
{
return [_children count];
}
- (WebBridge *)previousSibling;
{
return _previousSibling;
}
- (WebBridge *)nextSibling;
{
return _nextSibling;
}
- (BOOL)isDescendantOfFrame:(WebBridge *)ancestor
{
for (WebBridge *frame = self; frame; frame = (WebBridge *)[frame parent])
if (frame == ancestor)
return YES;
return NO;
}
- (WebBridge *)traverseNextFrameStayWithin:(WebBridge *)stayWithin
{
WebBridge *firstChild = [self firstChild];
if (firstChild) {
ASSERT(!stayWithin || [firstChild isDescendantOfFrame:stayWithin]);
return firstChild;
}
if (self == stayWithin)
return 0;
WebBridge *nextSibling = [self nextSibling];
if (nextSibling) {
assert(!stayWithin || [nextSibling isDescendantOfFrame:stayWithin]);
return nextSibling;
}
WebBridge *frame = self;
while (frame && !nextSibling && (!stayWithin || [frame parent] != stayWithin)) {
frame = (WebBridge *)[frame parent];
nextSibling = [frame nextSibling];
}
if (frame) {
ASSERT(!stayWithin || !nextSibling || [nextSibling isDescendantOfFrame:stayWithin]);
return nextSibling;
}
return nil;
}
- (void)appendChild:(WebBridge *)child
{
[child setParent:self];
if (_children == nil)
_children = [[NSMutableArray alloc] init];
WebBridge *previous = [self lastChild];
if (previous) {
previous->_nextSibling = child;
child->_previousSibling = previous;
}
ASSERT(child->_nextSibling == nil);
[_children addObject:child];
}
- (void)removeChild:(WebBridge *)child
{
if (child->_previousSibling)
child->_previousSibling->_nextSibling = child->_nextSibling;
if (child->_nextSibling)
child->_nextSibling->_previousSibling = child->_previousSibling;
child->_previousSibling = nil;
child->_nextSibling = nil;
[_children removeObject:child];
}
@end
......@@ -128,36 +128,6 @@ - (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)objec
@end
@interface NSArray (WebSafeMakePerform)
- (void)_web_safeMakeObjectsPerformSelector:(SEL)aSelector;
@end
@implementation NSArray (WebSafeMakePerform)
- (void)_web_safeMakeObjectsPerformSelector:(SEL)aSelector
{
unsigned count = [self count];
if (0 == count)
return;
if (count > 128) {
[[self copy] makeObjectsPerformSelector:aSelector];
return;
}
id batch[128];
[self getObjects:batch range:NSMakeRange(0, count)];
unsigned i;
for (i = 0; i < count; i++) {
objc_msgSend(batch[i], aSelector);
}
}
@end
// One day we might want to expand the use of this kind of class such that we'd receive one
// over the bridge, and possibly hand it on through to the FormsDelegate.
// Today it is just used internally to keep some state as we make our way through a bunch
......@@ -202,9 +172,6 @@ - (void)_removeChild:(WebFrame *)child;
@interface WebFramePrivate : NSObject
{
@public
WebFrame *nextSibling;
WebFrame *previousSibling;
NSString *name;
WebFrameView *webFrameView;
WebDataSource *dataSource;
......@@ -213,7 +180,6 @@ @interface WebFramePrivate : NSObject
WebView *webView;
WebFrameState state;
WebFrameLoadType loadType;
NSMutableArray *children;
WebHistoryItem *currentItem; // BF item for our current content
WebHistoryItem *provisionalItem; // BF item for where we're trying to go
// (only known when navigating to a pre-existing BF item)
......@@ -284,8 +250,6 @@ - (void)dealloc
[webFrameView release];
[dataSource release];
[provisionalDataSource release];
[bridge release];
[children release];
[currentItem release];
[provisionalItem release];
......@@ -378,94 +342,42 @@ - (void)setCurrentItem:(WebHistoryItem *)item
@implementation WebFrame (FrameTraversal)
- (WebFrame *)_firstChildFrame
{
if (![_private->children count])
return nil;
return [_private->children objectAtIndex:0];
return [[[self _bridge] firstChild] webFrame];
}
- (WebFrame *)_lastChildFrame
{
return [_private->children lastObject];
return [[[self _bridge] lastChild] webFrame];
}
- (unsigned)_childFrameCount
{
return [_private->children count];
return [[self _bridge] childCount];
}
- (WebFrame *)_previousSiblingFrame;
{
return _private->previousSibling;
return [[[self _bridge] previousSibling] webFrame];
}
- (WebFrame *)_nextSiblingFrame;
{
return _private->nextSibling;
return [[[self _bridge] nextSibling] webFrame];
}
- (WebFrame *)_traverseNextFrameStayWithin:(WebFrame *)stayWithin
{
WebFrame *firstChild = [self _firstChildFrame];
if (firstChild) {
ASSERT(!stayWithin || [firstChild _isDescendantOfFrame:stayWithin]);
return firstChild;
}
if (self == stayWithin)
return 0;
WebFrame *nextSibling = [self _nextSiblingFrame];
if (nextSibling) {
assert(!stayWithin || [nextSibling _isDescendantOfFrame:stayWithin]);
return nextSibling;
}
WebFrame *frame = self;
while (frame && !nextSibling && (!stayWithin || [frame parentFrame] != stayWithin)) {
frame = [frame parentFrame];
nextSibling = [frame _nextSiblingFrame];
}
if (frame) {
ASSERT(!stayWithin || !nextSibling || [nextSibling _isDescendantOfFrame:stayWithin]);
return nextSibling;
}
return nil;
return [[[self _bridge] traverseNextFrameStayWithin:[stayWithin _bridge]] webFrame];
}
- (void)_appendChild:(WebFrame *)child
{
[[child _bridge] setParent:_private->bridge];
if (_private->children == nil)
_private->children = [[NSMutableArray alloc] init];
WebFrame *previousFrame = [self _lastChildFrame];
if (previousFrame) {
previousFrame->_private->nextSibling = child;
child->_private->previousSibling = previousFrame;
}
ASSERT(child->_private->nextSibling == nil);
[_private->children addObject:child];
[[self _bridge] appendChild:[child _bridge]];
}
- (void)_removeChild:(WebFrame *)child
{
// move corresponding previous and next WebFrame sibling pointers to their new positions
// when we remove a child we may have to reattach the previous frame's next frame and visa versa
if (child->_private->previousSibling)
child->_private->previousSibling->_private->nextSibling = child->_private->nextSibling;
if (child->_private->nextSibling)
child->_private->nextSibling->_private->previousSibling = child->_private->previousSibling;
child->_private->previousSibling = nil;
child->_private->nextSibling = nil;
[_private->children removeObject:child];
[[self _bridge] removeChild:[child _bridge]];
}
@end
......@@ -655,11 +567,7 @@ - (void)_setName:(NSString *)name
// FIXME: this exists only as a convenience for Safari, consider moving there
- (BOOL)_isDescendantOfFrame:(WebFrame *)ancestor
{
for (WebFrame *frame = self; frame; frame = [frame parentFrame])
if (frame == ancestor)
return YES;
return NO;
return [[self _bridge] isDescendantOfFrame:[ancestor _bridge]];
}
- (BOOL)_isFrameSet
......@@ -708,9 +616,9 @@ - (void)_detachFromParent
[self retain]; // retain self temporarily because dealloc can re-enter this method
[[self parentFrame] _removeChild:self];
[bridge close];
[bridge release];
[[self parentFrame] _removeChild:self];
_private->bridge = nil;
[self release];
......@@ -2657,6 +2565,29 @@ - (void)_recursive_resumeNullEventsForAllNetscapePlugins
@implementation WebFrame (WebInternal)
- (id)_initWithName:(NSString *)n webFrameView:(WebFrameView *)fv webView:(WebView *)v bridge:(WebBridge *)bridge
{
self = [super init];
if (!self)
return nil;
_private = [[WebFramePrivate alloc] init];
[self _setWebView:v];
[self _setName:n];
_private->bridge = bridge;
if (fv) {
[_private setWebFrameView:fv];
[fv _setWebView:v];
[fv _setWebFrame:self];
}
++WebFrameCount;
return self;
}
- (NSArray *)_documentViews
{
NSMutableArray *result = [NSMutableArray array];
......@@ -2976,33 +2907,15 @@ - (WebFrame *)sourceFrame
@implementation WebFrame
- init
- (id)init
{
return [self initWithName:nil webFrameView:nil webView:nil];
}
- initWithName:(NSString *)n webFrameView:(WebFrameView *)fv webView:(WebView *)v
// FIXME: this method can't work any more and should be marked deprecated
- (id)initWithName:(NSString *)n webFrameView:(WebFrameView *)fv webView:(WebView *)v
{
self = [super init];
if (!self)
return nil;
_private = [[WebFramePrivate alloc] init];
[self _setWebView:v];
[self _setName:n];
_private->bridge = [[WebBridge alloc] initWithWebFrame:self];
if (fv) {
[_private setWebFrameView:fv];
[fv _setWebView:v];
[fv _setWebFrame:self];
}
++WebFrameCount;
return self;
return [self _initWithName:n webFrameView:fv webView:v bridge:nil];
}
- (void)dealloc
......
......@@ -58,6 +58,7 @@
- (WebFrame *)_findFrameWithSelection;
- (void)_clearSelectionInOtherFrames;
- (BOOL)_subframeIsLoading;
- (id)_initWithName:(NSString *)n webFrameView:(WebFrameView *)fv webView:(WebView *)v bridge:(WebBridge *)bridge;
@end
......
......@@ -207,7 +207,7 @@ - (BOOL)_shouldAutoscrollForDraggingInfo:(id)dragInfo;
@interface WebViewPrivate : NSObject
{
@public
WebFrame *mainFrame;
WebBridge *mainFrameBridge;
id UIDelegate;
id UIDelegateForwarder;
......@@ -369,7 +369,7 @@ @implementation WebViewPrivate
- (void)dealloc
{
ASSERT(mainFrame == nil);
ASSERT(mainFrameBridge == nil);
ASSERT(draggingDocumentView == nil);
ASSERT(dragCaretBridge == nil);
......@@ -540,9 +540,9 @@ - (void)_close
// To avoid leaks, call removeDragCaret in case it wasn't called after moveDragCaretToPoint.
[self removeDragCaret];
[_private->mainFrame _detachFromParent];
[_private->mainFrame release];
_private->mainFrame = nil;
[[self mainFrame] _detachFromParent];
[_private->mainFrameBridge release];
_private->mainFrameBridge = nil;
// Clear the page cache so we call destroy on all the plug-ins in the page cache to break any retain cycles.
// See comment in [WebHistoryItem _releaseAllPendingPageCaches] for more information.
......@@ -561,15 +561,14 @@ - (WebFrame *)_createFrameNamed:(NSString *)fname inParent:(WebFrame *)parent al
[childView _setWebView:self];
[childView setAllowsScrolling:allowsScrolling];
WebFrame *newFrame = [[WebFrame alloc] initWithName:fname webFrameView:childView webView:self];
WebBridge *newBridge = [[WebBridge alloc] initWithFrameName:fname view:childView];
[childView release];
[parent _addChild:newFrame];
[parent _addChild:[newBridge webFrame]];
[newFrame release];
[childView release];
[newBridge release];
return newFrame;
return [newBridge webFrame];
}
- (void)_finishedLoadingResourceFromDataSource:(WebDataSource *)dataSource
......@@ -691,7 +690,7 @@ - (void)setDefersCallbacks:(BOOL)defers
}
_private->defersCallbacks = defers;
[_private->mainFrame _defersCallbacksChanged];
[[self mainFrame] _defersCallbacksChanged];
}
- (void)_setTopLevelFrameName:(NSString *)name
......@@ -1554,11 +1553,13 @@ - (void)_commonInitializationWithFrameName:(NSString *)frameName groupName:(NSSt
NSRect f = [self frame];
WebFrameView *wv = [[WebFrameView alloc] initWithFrame: NSMakeRect(0,0,f.size.width,f.size.height)];
[wv _setWebView:self];
[wv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[self addSubview: wv];
[wv release];
_private->mainFrame = [[WebFrame alloc] initWithName: frameName webFrameView: wv webView: self];
_private->mainFrameBridge = [[WebBridge alloc] initWithFrameName:frameName view:wv];
[self _addToAllWebViewsSet];
[self setGroupName:groupName];
......@@ -1817,9 +1818,9 @@ - (void)setFrameLoadDelegate:delegate
- (WebFrame *)mainFrame
{
// This can be called in initialization, before _private has been set up (3465613)
if (_private != nil) {
return _private->mainFrame;
}
if (_private != nil)
return [_private->mainFrameBridge webFrame];
return nil;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment