Annotation of chimera/MyBrowserView.mm, revision 1.9

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

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