[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty))
From: |
address@hidden |
Subject: |
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)) |
Date: |
6 Mar 2007 12:05:39 -0800 |
User-agent: |
G2/1.0 |
> As for the xhtml text converter bundle Nicola suggests for use by the
> gui library ... the obvious thing IMO would be to write it to use
> SimpleWebKit, and perhaps provide an alternative bundle using WebKit
> later.
The wrapper can indeed be made 100% interchangeable since both use the
WebKit API. So, users can finally install one or the other.
Here is a code snippet (this time from mySTEP AppKit and not really
tested):
- (id) initWithHTML:(NSData *)data documentAttributes:(NSDictionary
**)dict;
{
return [self initWithHTML:data options:nil documentAttributes:dict];
}
- (id) initWithHTML:(NSData *)data baseURL:(NSURL *)url
documentAttributes:(NSDictionary **)dict;
{
return [self initWithHTML:data options:[NSDictionary
dictionaryWithObject:url forKey:NSBaseURLDocumentOption]
documentAttributes:dict];
}
// reuse (this is not at all thread safe!)
static BOOL didLoadWebKit;
static WebView *webView;
static BOOL done;
- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame*)
frame
{
NSLog(@"did finish loading main frame");
if(frame == [sender mainFrame])
done=YES;
}
- (id) initWithHTML:(NSData *)data options:(NSDictionary *)options
documentAttributes:(NSDictionary **)dict;
{
// check for HTML like header before trying
if(!didLoadWebKit)
[[NSBundle bundleWithPath:@"/System/Library/Frameworks/
WebKit.framework"] load], didLoadWebKit=YES; // dynamically load
if(!webView)
{
webView=[[NSClassFromString(@"WebView") alloc]
initWithFrame:NSMakeRect(0.0, 0.0, 100.0, 100.0)];
if(!webView)
return nil; // can't initialize
}
[[webView mainFrame] loadData:data MIMEType:@"text/html"
textEncodingName:@"utf-8" baseURL:[options
objectForKey:NSBaseURLDocumentOption]];
[self setFrameLoadDelegate:self];
done=NO;
while(!done)
{ // loading is not yet done
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate
dateWithTimeIntervalSinceNow:0.2] inMode:NSDefaultRunLoopMode
dequeue:NO]; // process events
}
if(dict)
*dict=[NSDictionary dictionaryWithKeysAndAttributes:
NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute,
[[[webView mainFrame] dataSource] textEncodingName],
NSCharacterEncodingDocumentAttribute, // may be nil?
[[[webView mainFrame] dataSource] pageTitle],
NSTitleDocumentAttribute, // title may be nil!!!
nil];
return [self initWithAttributedString:[[[[webView mainFrame]
frameView] documentView] attributedString]];
}
-- hns
- Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), (continued)
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), Gregory John Casamento, 2007/03/06
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), Nicola Pero, 2007/03/06
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), Peter Cooper, 2007/03/07
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), Dr. H. Nikolaus Schaller, 2007/03/07
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), Gregory John Casamento, 2007/03/07
Re: SimpleWebKit (was GNUstep Web browser (was Re: WebKit Bounty)), Nicola Pero, 2007/03/07