Changeset 13877 in webkit
- Timestamp:
- Apr 14, 2006 10:38:19 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r13865 r13877 1 2006-04-14 James G. Speth <speth@end.com> 2 3 Reviewed by Timothy. 4 5 Bug 8389: support for Cocoa bindings - binding an NSTreeController to the WebView's DOM 6 http://bugzilla.opendarwin.org/show_bug.cgi?id=8389 7 8 Adds a category to WebScriptObject with array accessors for KVC/KVO. 9 10 If super valueForKey: fails it will call valueForUndefinedKey:, which is 11 important because it causes the right behavior to happen with bindings using 12 the "Raises for Not Applicable Keys" flag and the "Not Applicable Placeholder" 13 14 * bindings/objc/WebScriptObject.mm: 15 (-[WebScriptObject valueForKey:]): 16 (-[WebScriptObject count]): 17 (-[WebScriptObject objectAtIndex:]): 18 (-[WebUndefined description]): return "undefined" 19 1 20 2006-04-13 Geoffrey Garen <ggaren@apple.com> 2 21 -
trunk/JavaScriptCore/bindings/objc/WebScriptObject.mm
r13821 r13877 284 284 285 285 id resultObj = [WebScriptObject _convertValueToObjcValue:result originExecutionContext:[self _originExecutionContext] executionContext:[self _executionContext]]; 286 if ([resultObj isKindOfClass:[WebUndefined class]]) 287 resultObj = [super valueForKey:key]; // ensure correct not-applicable key behavior 286 288 287 289 _didExecute(self); … … 423 425 @end 424 426 427 @interface WebScriptObject (WebKitCocoaBindings) 428 429 - (unsigned int)count; 430 - (id)objectAtIndex:(unsigned int)index; 431 432 @end 433 434 @implementation WebScriptObject (WebKitCocoaBindings) 435 436 - (unsigned int)count 437 { 438 id length = [self valueForKey:@"length"]; 439 if ([length respondsToSelector:@selector(intValue)]) 440 return [length intValue]; 441 else 442 return 0; 443 } 444 445 - (id)objectAtIndex:(unsigned int)index 446 { 447 return [self webScriptValueAtIndex:index]; 448 } 449 450 @end 451 425 452 @implementation WebUndefined 426 453 … … 434 461 } 435 462 463 - (NSString *)description 464 { 465 return @"undefined"; 466 } 467 436 468 - (id)initWithCoder:(NSCoder *)coder 437 469 { -
trunk/WebKit/ChangeLog
r13850 r13877 1 2006-04-14 James G. Speth <speth@end.com> 2 3 Reviewed by Timothy. 4 5 Bug 8389: support for Cocoa bindings - binding an NSTreeController to the WebView's DOM 6 http://bugzilla.opendarwin.org/show_bug.cgi?id=8389 7 8 Added a controller class, WebController, that is a subclass of 9 NSTreeController that has a new outlet/binding for the WebView. 10 11 * WebCoreSupport/WebFrameBridge.m: 12 (-[WebFrameBridge windowObjectCleared]): notify bindings about the document change 13 * WebView/WebView.m: 14 (-[WebView _progressStarted:]): notify bindings about the document change 15 (-[WebView _finalProgressComplete]): notify bindings about the document change 16 (-[WebView _declaredKeys]): added a key for the main frame document 17 (-[WebController init]): 18 (-[WebController exposedBindings]): 19 (-[WebController valueClassForBinding:]): 20 (-[WebController setContent:]): 21 (-[WebController webView]): 22 (-[WebController setWebView:]): 23 (-[WebView mainFrameDocument]): get the main frame's DOMDocument 24 * WebView/WebViewPrivate.h: Adds mainFrameDocument to pending public. 25 1 26 2006-04-12 David Harrison <harrison@apple.com> 2 27 -
trunk/WebKit/WebCoreSupport/WebFrameBridge.m
r13648 r13877 1497 1497 WebView *wv = [self webView]; 1498 1498 [[wv _frameLoadDelegateForwarder] webView:wv windowScriptObjectAvailable:[self windowScriptObject]]; 1499 // this KVO notification first started in WebView's _progressStarted:, and gets finished here 1500 [wv _didChangeValueForKey:_WebMainFrameDocumentKey]; 1501 // start another change notification that will be completed in WebView's _finalProgressComplete: 1502 [wv _willChangeValueForKey:_WebMainFrameDocumentKey]; 1499 1503 if ([wv scriptDebugDelegate]) { 1500 1504 [_frame _attachScriptDebugger]; -
trunk/WebKit/WebView/WebView.m
r13850 r13877 346 346 NSString *_WebMainFrameTitleKey = @"mainFrameTitle"; 347 347 NSString *_WebMainFrameURLKey = @"mainFrameURL"; 348 NSString *_WebMainFrameDocumentKey = @"mainFrameDocument"; 348 349 349 350 @interface WebProgressItem : NSObject … … 1039 1040 _private->originatingProgressFrame = [frame retain]; 1040 1041 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressStartedNotification object:self]; 1042 [self _willChangeValueForKey:_WebMainFrameDocumentKey]; // paired with didChange.. in windowObjectCleared 1041 1043 } 1042 1044 _private->numProgressTrackedFrames++; … … 1053 1055 _private->progressValue = 1; 1054 1056 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressEstimateChangedNotification object:self]; 1057 // send the final KVO message, ending the willChange.. from WebFrameBridge windowObjectCleared 1058 [self _didChangeValueForKey:_WebMainFrameDocumentKey]; 1055 1059 } 1056 1060 … … 1187 1191 1188 1192 if (!declaredKeys) { 1189 declaredKeys = [[NSArray alloc] initWithObjects:_WebMainFrameURLKey, _WebIsLoadingKey, _WebEstimatedProgressKey, _WebCanGoBackKey, _WebCanGoForwardKey, _WebMainFrameTitleKey, _WebMainFrameIconKey, nil];1193 declaredKeys = [[NSArray alloc] initWithObjects:_WebMainFrameURLKey, _WebIsLoadingKey, _WebEstimatedProgressKey, _WebCanGoBackKey, _WebCanGoForwardKey, _WebMainFrameTitleKey, _WebMainFrameIconKey, _WebMainFrameDocumentKey, nil]; 1190 1194 } 1191 1195 … … 2521 2525 @end 2522 2526 2527 @implementation WebController 2528 2529 - (id)init 2530 { 2531 self = [super init]; 2532 if (self == nil) 2533 return nil; 2534 [self setChildrenKeyPath:@"childNodes"]; 2535 [self setObjectClass:[DOMNode class]]; 2536 return self; 2537 } 2538 2539 - (NSArray *)exposedBindings 2540 { 2541 NSArray *bindings = [super exposedBindings]; 2542 return [bindings arrayByAddingObject:@"webView"]; 2543 } 2544 2545 - (Class)valueClassForBinding:(NSString *)binding 2546 { 2547 if ([binding isEqualToString:@"webView"]) 2548 return [WebView class]; 2549 return [super valueClassForBinding:binding]; 2550 } 2551 2552 - (void)setContent:(id)newContent 2553 { 2554 // override NSTreeController's setContent: to prevent crash when changing the tree 2555 // see http://www.cocoadev.com/index.pl?NSTreeControllerBugOrDeveloperError 2556 2557 // in our case, it prevents a crash in NSTreeController that occurs when: 2558 // 1. an outline view has a column bound to arrangedObjects.nodeName 2559 // 2. a text field has its value bound to selection.innerHTML 2560 // 3. a node is selected in the outline view 2561 // 4. a new page is loaded in the WebView 2562 // -> crash 2563 // step 3 is necessary for the crash, it does not happen when there's no selection 2564 2565 // retain original values while the content changes 2566 id content = [[self content] retain]; 2567 NSArray *paths = [[self selectionIndexPaths] retain]; 2568 NSString *childrenKeyPath = [[self childrenKeyPath] retain]; 2569 2570 // clear the tree controller state as much as possible 2571 [self setSelectionIndexPaths:nil]; 2572 [super setContent:nil]; 2573 2574 // set the new content and restore the configuration 2575 [super setContent:newContent]; 2576 [self setChildrenKeyPath:childrenKeyPath]; 2577 [self setSelectionIndexPaths:paths]; 2578 2579 // release the original content and the temporary storage 2580 [content release]; 2581 [paths release]; 2582 [childrenKeyPath release]; 2583 } 2584 2585 - (WebView *)webView 2586 { 2587 return [[webView retain] autorelease]; 2588 } 2589 2590 - (void)setWebView:(WebView *)newWebView 2591 { 2592 if (newWebView == webView) 2593 return; 2594 [self unbind:@"contentObject"]; 2595 id old = webView; 2596 webView = [newWebView retain]; 2597 [old release]; 2598 [self bind:@"contentObject" toObject:webView withKeyPath:_WebMainFrameDocumentKey options:nil]; 2599 } 2600 2601 @end 2602 2523 2603 @implementation WebView (WebPendingPublic) 2524 2604 … … 2552 2632 { 2553 2633 return [[WebIconDatabase sharedIconDatabase] iconForURL:[[[[self mainFrame] dataSource] _URL] _web_originalDataAsString] withSize:WebIconSmallSize]; 2634 } 2635 2636 - (DOMDocument *)mainFrameDocument 2637 { 2638 return [[self mainFrame] DOMDocument]; 2554 2639 } 2555 2640 -
trunk/WebKit/WebView/WebViewPrivate.h
r13850 r13877 65 65 extern NSString *_WebMainFrameTitleKey; 66 66 extern NSString *_WebMainFrameURLKey; 67 extern NSString *_WebMainFrameDocumentKey; 67 68 68 69 extern NSString *WebElementTitleKey; // NSString of the title of the element (pending public, used by Safari) … … 75 76 } WebDashboardBehavior; 76 77 78 @interface WebController : NSTreeController { 79 IBOutlet WebView *webView; 80 } 81 - (WebView *)webView; 82 - (void)setWebView:(WebView *)newWebView; 83 @end 77 84 78 85 @interface WebView (WebPendingPublic) … … 83 90 - (NSString *)mainFrameTitle; 84 91 - (NSImage *)mainFrameIcon; 92 - (DOMDocument *)mainFrameDocument; 85 93 86 94 - (void)setDrawsBackground:(BOOL)drawsBackround;
Note: See TracChangeset
for help on using the changeset viewer.