Annotation of chimera/MyBrowserView.mm, revision 1.12

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

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