Diff for /chimera/MyBrowserView.mm between versions 1.8 and 1.27

version 1.8, 2002/02/04 07:00:31 version 1.27, 2002/04/10 07:46:37
Line 1 Line 1
/*/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 *  MyBrowserView.mm/* ***** BEGIN LICENSE BLOCK *****
 */ * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Netscape Public License
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/NPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  * for the specific language governing rights and limitations under the
  * License.
  *
  * The Original Code is mozilla.org code.
  *
  * The Initial Developer of the Original Code is 
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 2002
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the NPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the NPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
   
 #import "MyBrowserView.h"  #import "MyBrowserView.h"
   #import "BrowserWindowController.h"
   
   #include "nsCOMPtr.h"
   #include "nsIServiceManager.h"
   #include "nsIIOService.h"
   #include "ContentClickListener.h"
   #include "nsIDOMWindow.h"
   #include "nsIChromeEventHandler.h"
   #include "nsPIDOMWindow.h"
   #include "nsIDOMEventReceiver.h"
   
 #define DOCUMENT_DONE_STRING @"Document: Done"  #define DOCUMENT_DONE_STRING @"Document: Done"
 #define LOADING_STRING @"Loading..."  #define LOADING_STRING @"Loading..."
   
   static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
   
 @implementation MyBrowserView  @implementation MyBrowserView
   
 -(void)windowClosed  -(void)windowClosed
 {  {
    // Break the cycle.  // Break the cycle.
    [browserView setContainer: nil];  [browserView destroyWebBrowser];
    [browserView removeListener: self];  [browserView setContainer: nil];
   [browserView removeListener: self];
 }  }
   
 -(void)dealloc  -(void)dealloc
 {  {
        [defaultStatus release];  printf("My browser view died.\n");
    [loadingStatus release];
   [[NSNotificationCenter defaultCenter] removeObserver: self];
           
        [super dealloc];        [defaultStatus release];
   [loadingStatus release];
 
   [super dealloc];
 }  }
   
 - (IBAction)load:(id)sender  - (IBAction)load:(id)sender
Line 29 Line 79
   [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];    [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
 }  }
   
- (void)awakeFromNib -(void)disconnectView
 {
     urlbar = nil;
     status = nil;
     progress = nil;
     progressSuper = nil;
     mIsPrimary = NO;
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     
     [browserView setActive: NO];
 }
 
 - (id)initWithFrame:(NSRect)frameRect
 {
     [super initWithFrame: frameRect];
      browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease];
     [self addSubview:browserView];
     [browserView setContainer:self];
     [browserView addListener:self];
     mIsBusy = NO;
     mListenersAttached = NO;
     return self;
 }
 
 -(void)setTab: (NSTabViewItem*)tab
 {  {
  browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease];  mTab = tab;
  [self addSubview:browserView];}
  [browserView setContainer:self]; 
  [browserView addListener:self]; 
   
   -(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
       progress: (id)aProgress windowController: aWindowController
   {
     urlbar = aUrlbar;
     status = aStatus;
     progress = aProgress;
     progressSuper = [aProgress superview];
     mWindowController = aWindowController;
     
     if (!mIsBusy)
         [progress removeFromSuperview];
     
   defaultStatus = NULL;    defaultStatus = NULL;
   loadingStatus = DOCUMENT_DONE_STRING;    loadingStatus = DOCUMENT_DONE_STRING;
   [status setStringValue:loadingStatus];    [status setStringValue:loadingStatus];
   mIsBusy = NO;  
       
  [progress retain];  mIsPrimary = YES;
  [progress removeFromSuperview]; 
   nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   if (!ioService)
     return;
   PRBool offline = PR_FALSE;
   ioService->GetOffline(&offline);
   mOffline = offline;
   
   if (mWindowController) // Only register if we're the content area.
     [[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(offlineModeChanged:)
         name:@"offlineModeChanged"
         object:nil];
         
   // Update the URL bar.
   [mWindowController updateLocationFields:[self getCurrentURLSpec]];
   
   if (mWindowController && !mListenersAttached) {
     mListenersAttached = YES;
     
     // We need to hook up our click and context menu listeners.
     ContentClickListener* clickListener = new ContentClickListener(mWindowController);
     if (!clickListener)
       return;
     
     nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]);
     nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
     nsCOMPtr<nsIChromeEventHandler> chromeHandler;
     piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler));
     nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
     rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
   }
 }
 
 -(NSString*)getCurrentURLSpec
 {
   return [browserView getCurrentURLSpec];
 }
 
 - (void)awakeFromNib 
 {
 }  }
   
 - (void)setFrame:(NSRect)frameRect  - (void)setFrame:(NSRect)frameRect
Line 65 Line 188
   }    }
   
   [progressSuper addSubview:progress];    [progressSuper addSubview:progress];
   [progress release];  
   [progress setIndeterminate:YES];    [progress setIndeterminate:YES];
   [progress startAnimation:self];    [progress startAnimation:self];
   
Line 73 Line 195
   [status setStringValue:loadingStatus];    [status setStringValue:loadingStatus];
   
   mIsBusy = YES;    mIsBusy = YES;
     [mTab setLabel: LOADING_STRING];
     
   if (mWindowController)    if (mWindowController)
     [mWindowController updateToolbarItems];      [mWindowController updateToolbarItems];
 }  }
Line 81 Line 205
 {  {
   [progress setIndeterminate:YES];    [progress setIndeterminate:YES];
   [progress stopAnimation:self];    [progress stopAnimation:self];
   [progress retain];  
   [progress removeFromSuperview];    [progress removeFromSuperview];
   
   loadingStatus = DOCUMENT_DONE_STRING;    loadingStatus = DOCUMENT_DONE_STRING;
Line 116 Line 239
   [mWindowController updateLocationFields:spec];    [mWindowController updateLocationFields:spec];
 }  }
   
   - (void)onStatusChange:(NSString*)aStatusString
   {
     [status setStringValue: aStatusString];
   }
   
 - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type   - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type 
 {  {
   if (type == NSStatusTypeScriptDefault) {    if (type == NSStatusTypeScriptDefault) {
Line 147 Line 275
   
 - (void)setTitle:(NSString *)title  - (void)setTitle:(NSString *)title
 {  {
    if ( (title) && (! [title isEqualToString:@""]) ) {    // We must be the primary content area.
        [[mWindowController window] setTitle:title];    if (mIsPrimary && mWindowController) {
    } else {        if (mOffline) {
        [[mWindowController window] setTitle:@"Untitled"];            NSString* newTitle;
             if (title && ![title isEqualToString:@""])
                 newTitle = [title stringByAppendingString: @" [Working Offline]"];
             else
                 newTitle = @"Untitled [Working Offline]";
             [[mWindowController window] setTitle: newTitle];
         }
         else {
             if (title && ![title isEqualToString:@""])
                 [[mWindowController window] setTitle:title];
             else
                 [[mWindowController window] setTitle:@"Untitled"];
         }
     }
     
     // Always set the tab.
     if (title && ![title isEqualToString:@""])
         [mTab setLabel:title];
     else
         [mTab setLabel:@"Untitled"];
 }
 
 // Called when a context menu should be shown.
 - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
 {
 
 }
 
 - (void)offlineModeChanged: (NSNotification*)aNotification
 {
     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
     if (!ioService)
         return;
     PRBool offline = PR_FALSE;
     ioService->GetOffline(&offline);
     mOffline = offline;
     
     if (mOffline) {
         NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
         [[mWindowController window] setTitle: newTitle];
     }
     else {
         NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
         [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
     }      }
 }  }
   
Line 169 Line 340
   
 - (NSBrowserView*)createBrowserWindow:(unsigned int)mask  - (NSBrowserView*)createBrowserWindow:(unsigned int)mask
 {  {
  // XXX not implemented   BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  return NULL;  [controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings.
   [controller enterModalSession];
   return [[controller getMyBrowserView] getBrowserView];
 }  }
   
 - (NSBrowserView*)getBrowserView  - (NSBrowserView*)getBrowserView

Removed from v.1.8  
changed lines
  Added in v.1.27


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