Annotation of chimera/MyBrowserView.mm, revision 1.11

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.11    ! hyatt      28:     [[NSNotificationCenter defaultCenter] removeObserver: self];
        !            29:     
1.3       macserv    30:        [defaultStatus release];
                     31:     [loadingStatus release];
                     32:     
                     33:        [super dealloc];
1.1       hyatt      34: }
                     35: 
                     36: - (IBAction)load:(id)sender
                     37: {
1.4       macserv    38:   [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
1.1       hyatt      39: }
                     40: 
                     41: - (void)awakeFromNib 
                     42: {
1.7       hyatt      43:   browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease];
1.1       hyatt      44:   [self addSubview:browserView];
                     45:   [browserView setContainer:self];
                     46:   [browserView addListener:self];
                     47: 
                     48:   defaultStatus = NULL;
                     49:   loadingStatus = DOCUMENT_DONE_STRING;
                     50:   [status setStringValue:loadingStatus];
                     51:   mIsBusy = NO;
                     52:   
                     53:   [progress retain];
                     54:   [progress removeFromSuperview];
1.10      hyatt      55:   
                     56:   nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                     57:   if (!ioService)
                     58:     return;
                     59:   PRBool offline = PR_FALSE;
                     60:   ioService->GetOffline(&offline);
                     61:   mOffline = offline;
1.11    ! hyatt      62:   
        !            63:   [[NSNotificationCenter defaultCenter] addObserver:self
        !            64:       selector:@selector(offlineModeChanged:)
        !            65:       name:@"offlineModeChanged"
        !            66:       object:nil];
1.1       hyatt      67: }
                     68: 
                     69: - (void)setFrame:(NSRect)frameRect
                     70: {
                     71:   [super setFrame:frameRect];
                     72:   NSRect bounds = [self bounds];
                     73:   [browserView setFrame:bounds];
                     74: }
                     75: 
                     76: -(BOOL)isBusy
                     77: {
                     78:   return mIsBusy;
                     79: }
                     80: 
                     81: - (void)onLoadingStarted 
                     82: {
                     83:   if (defaultStatus) {
                     84:     [defaultStatus release];
                     85:     defaultStatus = NULL;
                     86:   }
                     87: 
                     88:   [progressSuper addSubview:progress];
                     89:   [progress release];
                     90:   [progress setIndeterminate:YES];
                     91:   [progress startAnimation:self];
                     92: 
                     93:   loadingStatus = LOADING_STRING;
                     94:   [status setStringValue:loadingStatus];
                     95: 
                     96:   mIsBusy = YES;
                     97:   if (mWindowController)
                     98:     [mWindowController updateToolbarItems];
                     99: }
                    100: 
                    101: - (void)onLoadingCompleted:(BOOL)succeeded
                    102: {
                    103:   [progress setIndeterminate:YES];
                    104:   [progress stopAnimation:self];
                    105:   [progress retain];
                    106:   [progress removeFromSuperview];
                    107: 
                    108:   loadingStatus = DOCUMENT_DONE_STRING;
                    109:   if (defaultStatus) {
                    110:     [status setStringValue:defaultStatus];
                    111:   }
                    112:   else {
                    113:     [status setStringValue:loadingStatus];
                    114:   }
                    115: 
                    116:   mIsBusy = NO;
                    117:   
                    118:   if (mWindowController)
                    119:     [mWindowController updateToolbarItems];
                    120: }
                    121: 
                    122: - (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes 
                    123: {
                    124:   if (maxBytes > 0) {
                    125:     BOOL isIndeterminate = [progress isIndeterminate];
                    126:     if (isIndeterminate) {
                    127:       [progress setIndeterminate:NO];
                    128:     }
                    129:     double val = ((double)currentBytes / (double)maxBytes) * 100.0;
                    130:     [progress setDoubleValue:val];
                    131:   }
                    132: }
                    133: 
                    134: - (void)onLocationChange:(NSURL*)url 
                    135: {
                    136:   NSString* spec = [url absoluteString];
1.4       macserv   137:   [mWindowController updateLocationFields:spec];
1.1       hyatt     138: }
                    139: 
                    140: - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
                    141: {
                    142:   if (type == NSStatusTypeScriptDefault) {
                    143:     if (defaultStatus) {
                    144:       [defaultStatus release];
                    145:     }
                    146:     defaultStatus = statusString;
                    147:     if (defaultStatus) {
                    148:       [defaultStatus retain];
                    149:     }
                    150:   }
                    151:   else if (!statusString) {
                    152:     if (defaultStatus) {
                    153:       [status setStringValue:defaultStatus];
                    154:     }
                    155:     else {
                    156:       [status setStringValue:loadingStatus];
                    157:     }      
                    158:   }
                    159:   else {
                    160:     [status setStringValue:statusString];
                    161:   }
                    162: }
                    163: 
                    164: - (NSString *)title 
                    165: {
1.4       macserv   166:   return [[mWindowController window] title];
1.1       hyatt     167: }
                    168: 
                    169: - (void)setTitle:(NSString *)title
                    170: {
1.10      hyatt     171:     if (mOffline) {
                    172:         NSString* newTitle;
                    173:         if (title && ![title isEqualToString:@""])
                    174:             newTitle = [title stringByAppendingString: @" [Working Offline]"];
                    175:         else
                    176:             newTitle = @"Untitled [Working Offline]";
                    177:         [[mWindowController window] setTitle: newTitle];
                    178:     }
                    179:     else {
                    180:         if (title && ![title isEqualToString:@""])
                    181:             [[mWindowController window] setTitle:title];
                    182:         else
                    183:             [[mWindowController window] setTitle:@"Untitled"];
1.11    ! hyatt     184:     }
        !           185: }
        !           186: 
        !           187: - (void)offlineModeChanged: (NSNotification*)aNotification
        !           188: {
        !           189:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
        !           190:     if (!ioService)
        !           191:         return;
        !           192:     PRBool offline = PR_FALSE;
        !           193:     ioService->GetOffline(&offline);
        !           194:     mOffline = offline;
        !           195:     
        !           196:     if (mOffline) {
        !           197:         NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
        !           198:         [[mWindowController window] setTitle: newTitle];
        !           199:     }
        !           200:     else {
        !           201:         NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
        !           202:         [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
1.4       macserv   203:     }
1.1       hyatt     204: }
                    205: 
                    206: - (void)sizeBrowserTo:(NSSize)dimensions
                    207: {
                    208:   NSRect bounds = [self bounds];
                    209:   float dx = dimensions.width - bounds.size.width;
                    210:   float dy = dimensions.height - bounds.size.height;
                    211: 
1.4       macserv   212:   NSRect frame = [[self window] frame];
1.1       hyatt     213:   frame.size.width += dx;
                    214:   frame.size.height += dy;
                    215: 
1.4       macserv   216:   [[self window] setFrame:frame display:YES];
1.1       hyatt     217: }
                    218: 
                    219: - (NSBrowserView*)createBrowserWindow:(unsigned int)mask
                    220: {
                    221:   // XXX not implemented 
                    222:   return NULL;
                    223: }
                    224: 
                    225: - (NSBrowserView*)getBrowserView
                    226: {
                    227:   return browserView;
                    228: }
                    229: 
                    230: @end

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