Back to index

lightning-sunbird  0.9+nobinonly
MyBrowserView.mm
Go to the documentation of this file.
00001 #import "MyBrowserView.h"
00002 
00003 #define DOCUMENT_DONE_STRING @"Document: Done"
00004 #define LOADING_STRING @"Loading..."
00005 
00006 @implementation MyBrowserView
00007 
00008 - (IBAction)load:(id)sender
00009 {
00010   NSString* str = [urlbar stringValue];
00011   [browserView loadURI:str referrer:nil flags:NSLoadFlagsNone];
00012 }
00013 
00014 - (void)awakeFromNib 
00015 {
00016   NSRect bounds = [self bounds];
00017   browserView = [[CHBrowserView alloc] initWithFrame:bounds];
00018   [self addSubview:browserView];
00019   [browserView setContainer:self];
00020   [browserView addListener:self];
00021 
00022   defaultStatus = NULL;
00023   loadingStatus = DOCUMENT_DONE_STRING;
00024   [status setStringValue:loadingStatus];
00025 
00026   [progress retain];
00027   [progress removeFromSuperview];
00028 }
00029 
00030 - (void)setFrame:(NSRect)frameRect
00031 {
00032   [super setFrame:frameRect];
00033   NSRect bounds = [self bounds];
00034   [browserView setFrame:bounds];
00035 }
00036 
00037 - (void)onLoadingStarted 
00038 {
00039   if (defaultStatus) {
00040     [defaultStatus release];
00041     defaultStatus = NULL;
00042   }
00043 
00044   [progressSuper addSubview:progress];
00045   [progress release];
00046   [progress setIndeterminate:YES];
00047   [progress startAnimation:self];
00048 
00049   loadingStatus = LOADING_STRING;
00050   [status setStringValue:loadingStatus];
00051 
00052 #ifdef DEBUG_vidur
00053   printf("Starting to load\n");
00054 #endif
00055 }
00056 
00057 - (void)onLoadingCompleted:(BOOL)succeeded
00058 {
00059   [progress setIndeterminate:YES];
00060   [progress stopAnimation:self];
00061   [progress retain];
00062   [progress removeFromSuperview];
00063 
00064   loadingStatus = DOCUMENT_DONE_STRING;
00065   if (defaultStatus) {
00066     [status setStringValue:defaultStatus];
00067   }
00068   else {
00069     [status setStringValue:loadingStatus];
00070   }
00071 
00072   [browserView setActive:YES];
00073 #ifdef DEBUG_vidur
00074   printf("Loading completed\n");
00075 #endif
00076 }
00077 
00078 - (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes 
00079 {
00080   if (maxBytes > 0) {
00081     BOOL isIndeterminate = [progress isIndeterminate];
00082     if (isIndeterminate) {
00083       [progress setIndeterminate:NO];
00084     }
00085     double val = ((double)currentBytes / (double)maxBytes) * 100.0;
00086     [progress setDoubleValue:val];
00087 #ifdef DEBUG_vidur
00088     printf("Progress notification: %f%%\n", val);
00089 #endif
00090   }
00091 }
00092 
00093 - (void)onLocationChange:(NSString*)url 
00094 {
00095   [urlbar setStringValue:url];
00096   
00097 #ifdef DEBUG_vidur
00098   const char* str = [spec cString];
00099   printf("Location changed to: %s\n", str);
00100 #endif
00101 }
00102 
00103 - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
00104 {
00105   if (type == NSStatusTypeScriptDefault) {
00106     if (defaultStatus) {
00107       [defaultStatus release];
00108     }
00109     defaultStatus = statusString;
00110     if (defaultStatus) {
00111       [defaultStatus retain];
00112     }
00113   }
00114   else if (!statusString) {
00115     if (defaultStatus) {
00116       [status setStringValue:defaultStatus];
00117     }
00118     else {
00119       [status setStringValue:loadingStatus];
00120     }      
00121   }
00122   else {
00123     [status setStringValue:statusString];
00124   }
00125 }
00126 
00127 - (void)onStatusChange:(NSString*)aMessage
00128 {
00129   NSLog(@"Status is %@", aMessage);
00130 }
00131 
00132 - (void)onSecurityStateChange:(unsigned long)newState
00133 {
00134 }
00135 
00136 - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
00137 {
00138   NSLog(@"Showing context menu");
00139 }
00140 
00141 - (void)onShowTooltip:(NSPoint)where withText:(NSString*)text
00142 {
00143   NSLog(@"Showing tooltip %@", text);
00144 }
00145 
00146 - (void)onHideTooltip
00147 {
00148 }
00149 
00150 - (NSString *)title 
00151 {
00152   NSWindow* window = [self window];
00153   NSString* str = [window title];
00154   return str;
00155 }
00156 
00157 - (void)setTitle:(NSString *)title
00158 {
00159   NSWindow* window = [self window];
00160   [window setTitle:title];
00161 }
00162 
00163 - (void)sizeBrowserTo:(NSSize)dimensions
00164 {
00165   NSRect bounds = [self bounds];
00166   float dx = dimensions.width - bounds.size.width;
00167   float dy = dimensions.height - bounds.size.height;
00168 
00169   NSWindow* window = [self window];
00170   NSRect frame = [window frame];
00171   frame.size.width += dx;
00172   frame.size.height += dy;
00173 
00174   [window setFrame:frame display:YES];
00175 }
00176 
00177 - (CHBrowserView*)createBrowserWindow:(unsigned int)mask
00178 {
00179   // XXX not implemented 
00180   return NULL;
00181 }
00182 
00183 - (NSMenu*)getContextMenu
00184 {
00185   return nil;
00186 }
00187 
00188 - (NSWindow*)getNativeWindow
00189 {
00190   return [self window];
00191 }
00192 
00193 - (BOOL)shouldAcceptDragFromSource:(id)dragSource
00194 {
00195   return NO;
00196 }
00197 
00198 @end