Annotation of chimera/MyBrowserView.mm, revision 1.10

1.2       macserv     1: /*
                      2:  *  MyBrowserView.mm
                      3:  */
                      4: 
1.1       hyatt       5: #import "MyBrowserView.h"
                      6: 
1.10    ! hyatt       7: #include "nsCOMPtr.h"
        !             8: #include "nsIServiceManager.h"
        !             9: #include "nsIIOService.h"
        !            10: 
1.1       hyatt      11: #define DOCUMENT_DONE_STRING @"Document: Done"
                     12: #define LOADING_STRING @"Loading..."
                     13: 
1.10    ! hyatt      14: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
        !            15: 
1.1       hyatt      16: @implementation MyBrowserView
                     17: 
1.7       hyatt      18: -(void)windowClosed
                     19: {
                     20:     // Break the cycle.
                     21:     [browserView setContainer: nil];
                     22:     [browserView removeListener: self];
1.9       hyatt      23:     [browserView destroyWebBrowser];
1.7       hyatt      24: }
                     25: 
1.1       hyatt      26: -(void)dealloc
                     27: {
1.3       macserv    28:        [defaultStatus release];
                     29:     [loadingStatus release];
                     30:     
                     31:        [super dealloc];
1.1       hyatt      32: }
                     33: 
                     34: - (IBAction)load:(id)sender
                     35: {
1.4       macserv    36:   [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
1.1       hyatt      37: }
                     38: 
                     39: - (void)awakeFromNib 
                     40: {
1.7       hyatt      41:   browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease];
1.1       hyatt      42:   [self addSubview:browserView];
                     43:   [browserView setContainer:self];
                     44:   [browserView addListener:self];
                     45: 
                     46:   defaultStatus = NULL;
                     47:   loadingStatus = DOCUMENT_DONE_STRING;
                     48:   [status setStringValue:loadingStatus];
                     49:   mIsBusy = NO;
                     50:   
                     51:   [progress retain];
                     52:   [progress removeFromSuperview];
1.10    ! hyatt      53:   
        !            54:   nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
        !            55:   if (!ioService)
        !            56:     return;
        !            57:   PRBool offline = PR_FALSE;
        !            58:   ioService->GetOffline(&offline);
        !            59:   mOffline = offline;
1.1       hyatt      60: }
                     61: 
                     62: - (void)setFrame:(NSRect)frameRect
                     63: {
                     64:   [super setFrame:frameRect];
                     65:   NSRect bounds = [self bounds];
                     66:   [browserView setFrame:bounds];
                     67: }
                     68: 
                     69: -(BOOL)isBusy
                     70: {
                     71:   return mIsBusy;
                     72: }
                     73: 
                     74: - (void)onLoadingStarted 
                     75: {
                     76:   if (defaultStatus) {
                     77:     [defaultStatus release];
                     78:     defaultStatus = NULL;
                     79:   }
                     80: 
                     81:   [progressSuper addSubview:progress];
                     82:   [progress release];
                     83:   [progress setIndeterminate:YES];
                     84:   [progress startAnimation:self];
                     85: 
                     86:   loadingStatus = LOADING_STRING;
                     87:   [status setStringValue:loadingStatus];
                     88: 
                     89:   mIsBusy = YES;
                     90:   if (mWindowController)
                     91:     [mWindowController updateToolbarItems];
                     92: }
                     93: 
                     94: - (void)onLoadingCompleted:(BOOL)succeeded
                     95: {
                     96:   [progress setIndeterminate:YES];
                     97:   [progress stopAnimation:self];
                     98:   [progress retain];
                     99:   [progress removeFromSuperview];
                    100: 
                    101:   loadingStatus = DOCUMENT_DONE_STRING;
                    102:   if (defaultStatus) {
                    103:     [status setStringValue:defaultStatus];
                    104:   }
                    105:   else {
                    106:     [status setStringValue:loadingStatus];
                    107:   }
                    108: 
                    109:   mIsBusy = NO;
                    110:   
                    111:   if (mWindowController)
                    112:     [mWindowController updateToolbarItems];
                    113: }
                    114: 
                    115: - (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes 
                    116: {
                    117:   if (maxBytes > 0) {
                    118:     BOOL isIndeterminate = [progress isIndeterminate];
                    119:     if (isIndeterminate) {
                    120:       [progress setIndeterminate:NO];
                    121:     }
                    122:     double val = ((double)currentBytes / (double)maxBytes) * 100.0;
                    123:     [progress setDoubleValue:val];
                    124:   }
                    125: }
                    126: 
                    127: - (void)onLocationChange:(NSURL*)url 
                    128: {
                    129:   NSString* spec = [url absoluteString];
1.4       macserv   130:   [mWindowController updateLocationFields:spec];
1.1       hyatt     131: }
                    132: 
                    133: - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
                    134: {
                    135:   if (type == NSStatusTypeScriptDefault) {
                    136:     if (defaultStatus) {
                    137:       [defaultStatus release];
                    138:     }
                    139:     defaultStatus = statusString;
                    140:     if (defaultStatus) {
                    141:       [defaultStatus retain];
                    142:     }
                    143:   }
                    144:   else if (!statusString) {
                    145:     if (defaultStatus) {
                    146:       [status setStringValue:defaultStatus];
                    147:     }
                    148:     else {
                    149:       [status setStringValue:loadingStatus];
                    150:     }      
                    151:   }
                    152:   else {
                    153:     [status setStringValue:statusString];
                    154:   }
                    155: }
                    156: 
                    157: - (NSString *)title 
                    158: {
1.4       macserv   159:   return [[mWindowController window] title];
1.1       hyatt     160: }
                    161: 
                    162: - (void)setTitle:(NSString *)title
                    163: {
1.10    ! hyatt     164:     if (mOffline) {
        !           165:         NSString* newTitle;
        !           166:         if (title && ![title isEqualToString:@""])
        !           167:             newTitle = [title stringByAppendingString: @" [Working Offline]"];
        !           168:         else
        !           169:             newTitle = @"Untitled [Working Offline]";
        !           170:         [[mWindowController window] setTitle: newTitle];
        !           171:     }
        !           172:     else {
        !           173:         if (title && ![title isEqualToString:@""])
        !           174:             [[mWindowController window] setTitle:title];
        !           175:         else
        !           176:             [[mWindowController window] setTitle:@"Untitled"];
1.4       macserv   177:     }
1.1       hyatt     178: }
                    179: 
                    180: - (void)sizeBrowserTo:(NSSize)dimensions
                    181: {
                    182:   NSRect bounds = [self bounds];
                    183:   float dx = dimensions.width - bounds.size.width;
                    184:   float dy = dimensions.height - bounds.size.height;
                    185: 
1.4       macserv   186:   NSRect frame = [[self window] frame];
1.1       hyatt     187:   frame.size.width += dx;
                    188:   frame.size.height += dy;
                    189: 
1.4       macserv   190:   [[self window] setFrame:frame display:YES];
1.1       hyatt     191: }
                    192: 
                    193: - (NSBrowserView*)createBrowserWindow:(unsigned int)mask
                    194: {
                    195:   // XXX not implemented 
                    196:   return NULL;
                    197: }
                    198: 
                    199: - (NSBrowserView*)getBrowserView
                    200: {
                    201:   return browserView;
                    202: }
                    203: 
                    204: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>