File:  [mozdev] / chimera / MyBrowserView.mm
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Jan 29 10:01:11 2002 UTC (17 years, 4 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Initial commit of Chimera, a Gecko-based browser with a native Cocoa front end.

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

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