Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

james (1129)

  (email not shown publicly)


Journal of james (1129)

Tuesday September 10, 2002
03:40 AM

More Cocoa

[ #7646 ]

So last night I wondered how hard it would be to write a web browser in Cocoa. The answer is, not very hard at all. Cocoa has pretty much all the classes you need to fetch, render, and display HTML, and it all seems to be far too easy.

Its essentially ten-or-so lines of Objective-C with a NSTextView as BrowserWindow and a NSTextField as the urlText:

- (IBAction)fetchURL:(id)sender
    NSAttributedString *rendered;
    NSURL *theURL;
    NSData *rawData;

    theURL = [[NSURL alloc] initWithString: [URLText stringValue]];
    rawData = [[NSData alloc] initWithContentsOfURL: theURL];
    rendered = [[[NSAttributedString alloc] initWithHTML: rawData baseURL: theURL documentAttributes:nil] autorelease];

    [BrowserWindow setRichText: TRUE];
    [BrowserWindow setImportGraphics: TRUE];
    [[BrowserWindow textStorage] setAttributedString: rendered];

And thats it! Thats the core bits of a web browser. Now I need to figure out how to make it repeat the action on the links, and CGI forms etc. I think this may require subclassing however...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.