Changeset 13877 in webkit


Ignore:
Timestamp:
Apr 14, 2006 10:38:19 PM (18 years ago)
Author:
thatcher
Message:

JavaScriptCore:

Reviewed by Timothy.

Bug 8389: support for Cocoa bindings - binding an NSTreeController to the WebView's DOM
http://bugzilla.opendarwin.org/show_bug.cgi?id=8389

Adds a category to WebScriptObject with array accessors for KVC/KVO.

If super valueForKey: fails it will call valueForUndefinedKey:, which is
important because it causes the right behavior to happen with bindings using
the "Raises for Not Applicable Keys" flag and the "Not Applicable Placeholder"

  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject valueForKey:]): (-[WebScriptObject count]): (-[WebScriptObject objectAtIndex:]): (-[WebUndefined description]): return "undefined"

WebKit:

Reviewed by Timothy.

Bug 8389: support for Cocoa bindings - binding an NSTreeController to the WebView's DOM
http://bugzilla.opendarwin.org/show_bug.cgi?id=8389

Added a controller class, WebController, that is a subclass of
NSTreeController that has a new outlet/binding for the WebView.

  • WebCoreSupport/WebFrameBridge.m: (-[WebFrameBridge windowObjectCleared]): notify bindings about the document change
  • WebView/WebView.m: (-[WebView _progressStarted:]): notify bindings about the document change (-[WebView _finalProgressComplete]): notify bindings about the document change (-[WebView _declaredKeys]): added a key for the main frame document (-[WebController init]): (-[WebController exposedBindings]): (-[WebController valueClassForBinding:]): (-[WebController setContent:]): (-[WebController webView]): (-[WebController setWebView:]): (-[WebView mainFrameDocument]): get the main frame's DOMDocument
  • WebView/WebViewPrivate.h: Adds mainFrameDocument to pending public.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r13865 r13877  
     12006-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
    1202006-04-13  Geoffrey Garen  <ggaren@apple.com>
    221
  • trunk/JavaScriptCore/bindings/objc/WebScriptObject.mm

    r13821 r13877  
    284284
    285285    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
    286288
    287289    _didExecute(self);
     
    423425@end
    424426
     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
    425452@implementation WebUndefined
    426453
     
    434461}
    435462
     463- (NSString *)description
     464{
     465    return @"undefined";
     466}
     467
    436468- (id)initWithCoder:(NSCoder *)coder
    437469{
  • trunk/WebKit/ChangeLog

    r13850 r13877  
     12006-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
    1262006-04-12  David Harrison  <harrison@apple.com>
    227
  • trunk/WebKit/WebCoreSupport/WebFrameBridge.m

    r13648 r13877  
    14971497    WebView *wv = [self webView];
    14981498    [[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];
    14991503    if ([wv scriptDebugDelegate]) {
    15001504        [_frame _attachScriptDebugger];
  • trunk/WebKit/WebView/WebView.m

    r13850 r13877  
    346346NSString *_WebMainFrameTitleKey =       @"mainFrameTitle";
    347347NSString *_WebMainFrameURLKey =         @"mainFrameURL";
     348NSString *_WebMainFrameDocumentKey =    @"mainFrameDocument";
    348349
    349350@interface WebProgressItem : NSObject
     
    10391040        _private->originatingProgressFrame = [frame retain];
    10401041        [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressStartedNotification object:self];
     1042        [self _willChangeValueForKey:_WebMainFrameDocumentKey];     // paired with didChange.. in windowObjectCleared
    10411043    }
    10421044    _private->numProgressTrackedFrames++;
     
    10531055        _private->progressValue = 1;
    10541056        [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressEstimateChangedNotification object:self];
     1057        // send the final KVO message, ending the willChange.. from WebFrameBridge windowObjectCleared
     1058        [self _didChangeValueForKey:_WebMainFrameDocumentKey];
    10551059    }
    10561060   
     
    11871191   
    11881192    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];
    11901194    }
    11911195
     
    25212525@end
    25222526
     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
    25232603@implementation WebView (WebPendingPublic)
    25242604
     
    25522632{
    25532633    return [[WebIconDatabase sharedIconDatabase] iconForURL:[[[[self mainFrame] dataSource] _URL] _web_originalDataAsString] withSize:WebIconSmallSize];
     2634}
     2635
     2636- (DOMDocument *)mainFrameDocument
     2637{
     2638    return [[self mainFrame] DOMDocument];
    25542639}
    25552640
  • trunk/WebKit/WebView/WebViewPrivate.h

    r13850 r13877  
    6565extern NSString *_WebMainFrameTitleKey;
    6666extern NSString *_WebMainFrameURLKey;
     67extern NSString *_WebMainFrameDocumentKey;
    6768
    6869extern NSString *WebElementTitleKey;   // NSString of the title of the element (pending public, used by Safari)
     
    7576} WebDashboardBehavior;
    7677
     78@interface WebController : NSTreeController {
     79    IBOutlet WebView *webView;
     80}
     81- (WebView *)webView;
     82- (void)setWebView:(WebView *)newWebView;
     83@end
    7784
    7885@interface WebView (WebPendingPublic)
     
    8390- (NSString *)mainFrameTitle;
    8491- (NSImage *)mainFrameIcon;
     92- (DOMDocument *)mainFrameDocument;
    8593
    8694- (void)setDrawsBackground:(BOOL)drawsBackround;
Note: See TracChangeset for help on using the changeset viewer.