Adding the controller objects.

This commit is contained in:
hyatt%netscape.com 2002-04-20 07:54:17 +00:00
Родитель 1b10e55b23
Коммит 8494bcd77d
34 изменённых файлов: 9260 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,183 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "CHBrowserWrapper.h"
#import "CHFind.h"
#import "CHBookmarksToolbar.h"
class nsIDOMEvent;
class nsIDOMNode;
@interface BrowserWindowController : NSWindowController<CHFind>
{
IBOutlet id mTabBrowser;
IBOutlet NSDrawer* mSidebarDrawer;
IBOutlet id mSidebarTabView;
IBOutlet id mSidebarSourceTabView;
IBOutlet id mLocationToolbarView;
IBOutlet id mURLBar;
IBOutlet id mStatus;
IBOutlet id mProgress;
IBOutlet id mLocationSheetWindow;
IBOutlet id mLocationSheetURLField;
IBOutlet id mSidebarBrowserView;
IBOutlet id mSidebarBookmarksDataSource;
IBOutlet CHBookmarksToolbar* mPersonalToolbar;
IBOutlet id mAddBookmarkSheetWindow;
IBOutlet id mAddBookmarkTitleField;
IBOutlet id mAddBookmarkFolderField;
IBOutlet id mAddBookmarkCheckbox;
// Context menu outlets.
IBOutlet id mPageMenu;
IBOutlet id mImageMenu;
IBOutlet id mInputMenu;
IBOutlet id mLinkMenu;
IBOutlet id mImageLinkMenu;
NSToolbarItem *mLocationToolbarItem;
NSToolbarItem *mSidebarToolbarItem;
BOOL mInitialized;
NSURL* mURL;
CHBrowserWrapper* mBrowserView;
BOOL mMoveReentrant;
NSModalSession mModalSession;
BOOL mShouldAutosave;
BOOL mDrawerCachedFrame;
NSRect mCachedFrameBeforeDrawerOpen; // This is used by the drawer to figure out if the window should
// be returned to its original position when the drawer closes.
NSRect mCachedFrameAfterDrawerOpen;
int mChromeMask; // Indicates which parts of the window to show (e.g., don't show toolbars)
// Context menu members.
int mContextMenuFlags;
nsIDOMEvent* mContextMenuEvent;
nsIDOMNode* mContextMenuNode;
// Cached bookmark ds used when adding through a sheet
id mCachedBMDS;
}
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSURL*)aURL;
- (void)updateLocationFields:(NSString *)locationString;
- (void)updateToolbarItems;
- (void)focusURLBar;
- (void)performAppropriateLocationAction;
- (IBAction)goToLocationFromToolbarURLField:(id)sender;
- (void)focusURLBar;
- (void)beginLocationSheet;
- (IBAction)endLocationSheet:(id)sender;
- (IBAction)cancelAddBookmarkSheet:(id)sender;
- (IBAction)endAddBookmarkSheet:(id)sender;
- (void)cacheBookmarkDS: (id)aDS;
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
- (void)printDocument;
- (void)printPreview;
//- (BOOL)findInPage:(NSString*)text;
-(void) biggerTextSize;
-(void) smallerTextSize;
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder;
- (IBAction)manageBookmarks: (id)aSender;
- (IBAction)toggleSidebar:(id)aSender;
- (void)newTab;
- (void)closeTab;
- (void)previousTab;
- (void)nextTab;
- (IBAction)back:(id)aSender;
- (IBAction)forward:(id)aSender;
- (IBAction)reload:(id)aSender;
- (IBAction)stop:(id)aSender;
- (IBAction)home:(id)aSender;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;
-(void)disableAutosave;
-(void)setChromeMask:(int)aMask;
-(id)getAddBookmarkSheetWindow;
-(id)getAddBookmarkTitle;
-(id)getAddBookmarkFolder;
-(id)getAddBookmarkCheckbox;
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
- (NSMenu*)getContextMenu;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;
- (IBAction)saveImageAs:(id)aSender;
- (IBAction)viewOnlyThisImage:(id)aSender;
- (NSView*) bookmarksToolbar;
@end

Просмотреть файл

@ -0,0 +1,952 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIPrefBranch.h"
#include "nsIContextMenuListener.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsCocoaBrowserService.h"
#include "nsString.h"
#include "CHGeckoUtils.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item";
static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
@interface BrowserWindowController(Private)
- (void)setupToolbar;
- (void)setupSidebarTabs;
@end
@implementation BrowserWindowController
-(void)enterModalSession
{
mModalSession = [NSApp beginModalSessionForWindow: [self window]];
[NSApp runModalSession: mModalSession];
[NSApp endModalSession: mModalSession];
mModalSession = nil;
}
-(void)windowDidBecomeKey: (NSNotification*)aNotification
{
// May become necessary later.
}
-(void)windowDidResignKey: (NSNotification*)aNotification
{
// May be needed later.
}
-(void)mouseMoved:(NSEvent*)aEvent
{
if (mMoveReentrant)
return;
mMoveReentrant = YES;
NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
[view mouseMoved: aEvent];
[super mouseMoved: aEvent];
mMoveReentrant = NO;
}
- (id)initWithWindowNibName:(NSString *)windowNibName
{
if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
[self setShouldCascadeWindows:NO];
} else {
[self setShouldCascadeWindows:YES];
}
mInitialized = NO;
mMoveReentrant = NO;
mShouldAutosave = YES;
mChromeMask = 0;
mContextMenuFlags = 0;
mContextMenuEvent = nsnull;
mContextMenuNode = nsnull;
}
return self;
}
-(void)autosaveWindowFrame
{
if (mShouldAutosave)
[[self window] saveFrameUsingName: @"NavigatorWindow"];
}
-(void)disableAutosave
{
mShouldAutosave = NO;
}
- (void)windowWillClose:(NSNotification *)notification
{
printf("Window will close notification.\n");
[mSidebarBookmarksDataSource windowClosing];
[self autosaveWindowFrame];
[self autorelease];
}
- (void)dealloc
{
printf("Browser controller died.\n");
// Loop over all tabs, and tell them that the window is closed.
int numTabs = [mTabBrowser numberOfTabViewItems];
for (int i = 0; i < numTabs; i++) {
NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
[[item view] windowClosed];
}
[mSidebarBrowserView windowClosed];
[mProgress release];
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[[mURLBar cell] setImage: [NSImage imageNamed:@"smallbookmark"]];
// Get our saved dimensions.
[[self window] setFrameUsingName: @"NavigatorWindow"];
if (mModalSession)
[NSApp stopModal];
mInitialized = YES;
mDrawerCachedFrame = NO;
// Retain with a single extra refcount. This allows the CHBrowserWrappers
// to remove the progress meter from its superview without having to
// worry about retaining and releasing it.
[mProgress retain];
[[self window] setAcceptsMouseMovedEvents: YES];
[self setupToolbar];
// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was
// duplicating a lot of the code found here. I have moved it to that method.
// We now remove the IB tab, then add one of our own.
[mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
[self newTab];
if (mURL) {
[self loadURL: mURL];
[mURL release];
}
[mSidebarDrawer setDelegate: self];
[self setupSidebarTabs];
[mPersonalToolbar initializeToolbar];
}
- (void)drawerWillOpen: (NSNotification*)aNotification
{
[mSidebarBookmarksDataSource ensureBookmarks];
// Force the window to shrink and move if necessary in order to accommodate the sidebar.
NSRect screenFrame = [[[self window] screen] visibleFrame];
NSRect windowFrame = [[self window] frame];
NSSize drawerSize = [mSidebarDrawer contentSize];
int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
drawerSize.width += fudgeFactor;
if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
screenFrame.size.width) {
// We need to adjust the window so that it can fit.
float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
if (shrinkDelta < 0) shrinkDelta = 0;
float newWidth = (windowFrame.size.width - shrinkDelta);
float newPosition = screenFrame.size.width - newWidth - drawerSize.width;
if (newPosition < 0) newPosition = 0;
mCachedFrameBeforeDrawerOpen = windowFrame;
windowFrame.origin.x = newPosition;
windowFrame.size.width = newWidth;
mCachedFrameAfterDrawerOpen = windowFrame;
[[self window] setFrame: windowFrame display: YES];
mDrawerCachedFrame = YES;
}
}
- (void)drawerDidOpen:(NSNotification *)aNotification
{
// XXXdwh This is temporary.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
// Toggle the sidebar icon.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
}
- (void)drawerDidClose:(NSNotification *)aNotification
{
// Unload the Gecko web page in "My Panels" to save memory.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
// XXXdwh ignore for now.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
if (mDrawerCachedFrame) {
printf("Got here.\n");
mDrawerCachedFrame = NO;
NSRect frame = [[self window] frame];
if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
printf("Got here too.\n");
printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
// Restore the original frame.
[[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
}
}
}
- (void)setupToolbar
{
if (mChromeMask) {
printf("Uh-oh. %d\n", mChromeMask);
}
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
PrintToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Back"];
[toolbarItem setPaletteLabel:@"Go Back"];
[toolbarItem setToolTip:@"Go back one page"];
[toolbarItem setImage:[NSImage imageNamed:@"back"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(back:)];
} else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Forward"];
[toolbarItem setPaletteLabel:@"Go Forward"];
[toolbarItem setToolTip:@"Go forward one page"];
[toolbarItem setImage:[NSImage imageNamed:@"forward"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(forward:)];
} else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Reload"];
[toolbarItem setPaletteLabel:@"Reload Page"];
[toolbarItem setToolTip:@"Reload current page"];
[toolbarItem setImage:[NSImage imageNamed:@"reload"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(reload:)];
} else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Stop"];
[toolbarItem setPaletteLabel:@"Stop Loading"];
[toolbarItem setToolTip:@"Stop loading this page"];
[toolbarItem setImage:[NSImage imageNamed:@"stop"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(stop:)];
} else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Home"];
[toolbarItem setPaletteLabel:@"Go Home"];
[toolbarItem setToolTip:@"Go to home page"];
[toolbarItem setImage:[NSImage imageNamed:@"home"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(home:)];
} else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Sidebar"];
[toolbarItem setPaletteLabel:@"Toggle Sidebar"];
[toolbarItem setToolTip:@"Show or hide the Sidebar"];
[toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleSidebar:)];
mSidebarToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:@"Location"];
[toolbarItem setPaletteLabel:@"Location"];
[toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
[toolbarItem setView:mLocationToolbarView];
[toolbarItem setMinSize:NSMakeSize(128,32)];
[toolbarItem setMaxSize:NSMakeSize(2560,32)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(performAppropriateLocationAction)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
mLocationToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Print"];
[toolbarItem setPaletteLabel:@"Print"];
[toolbarItem setToolTip:@"Print this page"];
[toolbarItem setImage:[NSImage imageNamed:@"print"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(printDocument)];
} else {
toolbarItem = nil;
}
return toolbarItem;
}
// This method handles the enabling/disabling of the toolbar buttons.
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
// Check the action and see if it matches.
SEL action = [theItem action];
if (action == @selector(back:))
return [[mBrowserView getBrowserView] canGoBack];
else if (action == @selector(forward:))
return [[mBrowserView getBrowserView] canGoForward];
else if (action == @selector(reload:))
return [mBrowserView isBusy] == NO;
else if (action == @selector(stop:))
return [mBrowserView isBusy];
else
return YES;
}
- (void)updateToolbarItems
{
[[[self window] toolbar] validateVisibleItems];
}
- (void)performAppropriateLocationAction
{
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
[self focusURLBar];
} else {
[self beginLocationSheet];
}
} else {
[self beginLocationSheet];
}
}
- (void)focusURLBar
{
[mURLBar selectText: self];
}
- (void)beginLocationSheet
{
[NSApp beginSheet: mLocationSheetWindow
modalForWindow: [self window]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
- (IBAction)endLocationSheet:(id)sender
{
[mLocationSheetWindow orderOut:self];
[NSApp endSheet:mLocationSheetWindow returnCode:1];
[self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
-(IBAction)cancelAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 0];
}
-(IBAction)endAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 1];
}
- (void)cacheBookmarkDS: (id)aDS
{
mCachedBMDS = aDS;
}
-(IBAction)manageBookmarks: (id)aSender
{
if ([mSidebarDrawer state] == NSDrawerClosedState)
[self toggleSidebar: self];
[mSidebarTabView selectFirstTabViewItem:self];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender
{
[self loadURL:[NSURL URLWithString:[sender stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
{
[[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
}
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename
{
[[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList
url: aURL suggestedFilename: aFilename];
}
- (void)printDocument
{
[[mBrowserView getBrowserView] printDocument];
}
- (void)printPreview
{
[[mBrowserView getBrowserView] printPreview];
}
- (BOOL)findInPage:(NSString*)text
{
return [[mBrowserView getBrowserView] findInPage:text];
}
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder
{
[mSidebarBookmarksDataSource ensureBookmarks];
BOOL useSel = aIsFromMenu;
if (aIsFromMenu) {
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
if ([mSidebarDrawer state] == NSDrawerClosedState)
useSel = NO;
else
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
useSel = NO;
}
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder];
}
- (IBAction)back:(id)aSender
{
[[mBrowserView getBrowserView] goBack];
}
- (IBAction)forward:(id)aSender
{
[[mBrowserView getBrowserView] goForward];
}
- (IBAction)reload:(id)aSender
{
[[mBrowserView getBrowserView] reload: 0];
}
- (IBAction)stop:(id)aSender
{
[[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
}
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender
{
NSResponder* resp = [[self window] firstResponder];
[[self window] makeFirstResponder: nil];
if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
// XXXHack to bypass sidebar crashes.
[mSidebarDrawer openOnEdge: NSMaxXEdge];
} else {
[mSidebarDrawer close];
}
[[self window] makeFirstResponder: resp];
}
-(void)loadURL:(NSURL*)aURL
{
if (mInitialized) {
[[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
}
else {
mURL = aURL;
[mURL retain];
}
}
- (void)updateLocationFields:(NSString *)locationString
{
/* //commenting this out because it doesn't work right yet.
if ( [locationString length] > 30 ) {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
} else {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@", locationString]];
}
*/
[mURLBar setStringValue:locationString];
[mLocationSheetURLField setStringValue:locationString];
[[self window] update];
[[self window] display];
}
-(void)newTab
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newTab setLabel: @"Untitled"];
[newTab setView: newView];
[mTabBrowser addTabViewItem: newTab];
[[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[mTabBrowser selectLastTabViewItem: self];
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
if ([mTabBrowser numberOfTabViewItems] > 1) {
[self focusURLBar];
[[mBrowserView getBrowserView] setActive: NO];
}
else if ([[self window] isKeyWindow])
[[mBrowserView getBrowserView] setActive: YES];
else
[[mBrowserView getBrowserView] setActive: NO];
}
}
}
-(void)closeTab
{
if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
[[[mTabBrowser selectedTabViewItem] view] windowClosed];
[mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
}
}
- (void)previousTab
{
[mTabBrowser selectPreviousTabViewItem:self];
}
- (void)nextTab
{
[mTabBrowser selectNextTabViewItem:self];
}
- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
{
// Disconnect the old view, if one has been designated.
// If the window has just been opened, none has been.
if ( mBrowserView ) {
[mBrowserView disconnectView];
}
// Connect up the new view
mBrowserView = [aTabViewItem view];
// Make the new view the primary content area.
[mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
progress: mProgress windowController: self];
}
-(id)getTabBrowser
{
return mTabBrowser;
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
}
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
[mTabBrowser insertTabViewItem: newTab atIndex: index+1];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newView setTab: newTab];
[newTab setLabel: @"Loading..."];
[newTab setView: newView];
[[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
if (!aLoadInBG) {
[mTabBrowser selectTabViewItem: newTab];
// Focus the content area.
[[newView getBrowserView] setActive: YES];
}
}
-(void)setupSidebarTabs
{
CHIconTabViewItem *bookItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"bookicon"]];
CHIconTabViewItem *histItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"historySidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"historyicon"]];
CHIconTabViewItem *searchItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"searchSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"searchicon"]];
CHIconTabViewItem *panelsItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"myPanelsCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"panel_icon"]];
[bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
[histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
[searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
[mSidebarTabView insertTabViewItem:searchItem atIndex:2];
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
[mSidebarTabView selectFirstTabViewItem:self];
}
-(void)setChromeMask:(int)aMask
{
mChromeMask = aMask;
}
-(void) biggerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom >= 20)
return;
zoom += 0.25;
if (zoom > 20)
zoom = 20;
markupViewer->SetTextZoom(zoom);
}
-(void) smallerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom <= 0.01)
return;
zoom -= 0.25;
if (zoom < 0.01)
zoom = 0.01;
markupViewer->SetTextZoom(zoom);
}
-(id)getAddBookmarkSheetWindow
{
return mAddBookmarkSheetWindow;
}
-(id)getAddBookmarkTitle
{
return mAddBookmarkTitleField;
}
-(id)getAddBookmarkFolder
{
return mAddBookmarkFolderField;
}
-(id)getAddBookmarkCheckbox
{
return mAddBookmarkCheckbox;
}
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
{
mContextMenuFlags = flags;
mContextMenuNode = aNode;
mContextMenuEvent = aEvent;
}
- (NSMenu*)getContextMenu
{
NSMenu* result = nil;
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageLinkMenu;
}
else
result = mLinkMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
(mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
result = mInputMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
result = mPageMenu;
}
return result;
}
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender
{
[self openLinkInNewWindowOrTab: YES];
}
- (IBAction)openLinkInNewTab:(id)aSender
{
[self openLinkInNewWindowOrTab: NO];
}
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
if (aUseWindow)
[self openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
else
[self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
- (IBAction)savePageAs:(id)aSender
{
[self saveDocument: nil filterList: nil];
}
- (IBAction)saveLinkAs:(id)aSender
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
// The user wants to save this link.
nsAutoString text;
CHGeckoUtils::GatherTextUnder(mContextMenuNode, text);
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
- (IBAction)saveImageAs:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString text;
imgElement->GetAttribute(NS_LITERAL_STRING("src"), text);
nsAutoString url;
imgElement->GetSrc(url);
NSString* hrefStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
}
- (IBAction)viewOnlyThisImage:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString url;
imgElement->GetSrc(url);
NSString* urlStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToView = [NSURL URLWithString: urlStr];
[self loadURL: urlToView];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
}
- (NSView*) bookmarksToolbar
{
return mPersonalToolbar;
}
@end

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
#include "nsIWebBrowserFind.h"
@interface FindDlgController : NSWindowController {
IBOutlet id mSearchField;
IBOutlet id mIgnoreCaseBox;
IBOutlet id mWrapAroundBox;
IBOutlet id mSearchBackwardsBox;
IBOutlet id mFindButton;
NSString* mSearchText;
}
-(IBAction) find: (id)aSender;
-(IBAction) findAgain: (id)aSender;
// delegates for NSTextView
- (void)controlTextDidChange:(NSNotification *)aNotification;
@end

107
camino/FindDlgController.mm Normal file
Просмотреть файл

@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "FindDlgController.h"
#import "BrowserWindowController.h"
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (void)windowDidLoad
{
}
//
// -find
//
// User clicked the find button, send the action to the window controller of the
// frontmost browser window. If we found something, hide the window. If not, beep.
//
-(IBAction) find: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
mSearchText = [mSearchField stringValue];
BOOL found = [browserController findInPage:mSearchText];
if ( found )
[self close];
else
NSBeep();
}
else
NSBeep();
}
//
// -findAgain
//
// Someone hit "find again" in the edit menu, send the action to the window controller of the
// frontmost browser window. Beep if we didn't find something.
//
-(IBAction) findAgain: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
BOOL found = [browserController findInPage:mSearchText];
if ( !found )
NSBeep();
}
else
NSBeep();
}
//
// controlTextDidChange
//
// Check if there is anything in the text field, and if not, disable the find button
//
- (void)controlTextDidChange:(NSNotification *)aNotification
{
if ( [[mSearchField stringValue] length] )
[mFindButton setEnabled:PR_TRUE];
else
[mFindButton setEnabled:PR_FALSE];
}
@end

118
camino/MainController.h Normal file
Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "BrowserWindowController.h"
#import "MVPreferencesController.h"
#import "CHSplashScreenWindow.h"
#import "FindDlgController.h"
class BookmarksService;
@interface MainController : NSObject
{
IBOutlet id mApplication;
// The following two items are used by the filter list when saving files.
IBOutlet id mFilterView;
IBOutlet id mFilterList;
IBOutlet id mOfflineMenuItem;
// The bookmarks menu.
IBOutlet id mBookmarksMenu;
BOOL mOffline;
CHSplashScreenWindow *mSplashScreen;
BookmarksService *mMenuBookmarks;
FindDlgController* mFindDialog;
MVPreferencesController *preferencesController;
}
-(void)dealloc;
// File menu actions.
-(IBAction) newWindow:(id)aSender;
-(IBAction) openFile:(id)aSender;
-(IBAction) openLocation:(id)aSender;
-(IBAction) savePage:(id)aSender;
-(IBAction) printPreview:(id)aSender;
-(IBAction) printPage:(id)aSender;
-(IBAction) toggleOfflineMode:(id)aSender;
// Edit menu actions.
-(IBAction) findInPage:(id)aSender;
-(IBAction) findAgain:(id)aSender;
// Go menu actions.
-(IBAction) goBack:(id)aSender;
-(IBAction) goForward:(id)aSender;
-(IBAction) goHome:(id)aSender;
-(IBAction) previousTab:(id)aSender;
-(IBAction) nextTab:(id)aSender;
// View menu actions.
-(IBAction) doReload:(id)aSender;
-(IBAction) doStop:(id)aSender;
-(IBAction) biggerTextSize:(id)aSender;
-(IBAction) smallerTextSize:(id)aSender;
-(IBAction) toggleSmoothText:(id)aSender;
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender;
-(IBAction) openMenuBookmark:(id)aSender;
-(IBAction) manageBookmarks: (id)aSender;
-(IBAction) addFolder:(id)aSender;
-(IBAction) addSeparator:(id)aSender;
//Window menu actions
-(IBAction) newTab:(id)aSender;
-(IBAction) closeTab:(id)aSender;
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL;
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL;
- (MVPreferencesController *)preferencesController;
- (void)displayPreferencesWindow:sender;
- (IBAction)showAboutBox:(id)sender;
@end

375
camino/MainController.mm Normal file
Просмотреть файл

@ -0,0 +1,375 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "MainController.h"
#import "BrowserWindowController.h"
#include "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsCocoaBrowserService.h"
#import "CHAboutBox.h"
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
@implementation MainController
-(id)init
{
if ( (self = [super init]) ) {
mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:YES withStatusRect:NSMakeRect(0,0,0,0)];
mFindDialog = nil;
mMenuBookmarks = nil;
}
return self;
}
-(void)dealloc
{
[super dealloc];
[mFindDialog release];
printf("Main controller died.\n");
}
-(void)awakeFromNib
{
[self newWindow: self];
[mSplashScreen close];
[mBookmarksMenu setAutoenablesItems: NO];
mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
mMenuBookmarks->AddObserver();
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
BookmarksService::gMainController = self;
// Initialize offline mode.
mOffline = NO;
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
mOffline = offline;
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
}
-(IBAction)newWindow:(id)aSender
{
// If we have a key window, have it autosave its dimensions before
// we open a new window. That ensures the size ends up matching.
NSWindow* mainWindow = [mApplication mainWindow];
if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
[controller focusURLBar];
}
-(IBAction)newTab:(id)aSender
{
[[[mApplication mainWindow] windowController] newTab];
}
-(IBAction)closeTab:(id)aSender
{
[[[mApplication mainWindow] windowController] closeTab];
}
-(IBAction) previousTab:(id)aSender
{
[[[mApplication mainWindow] windowController] previousTab];
}
-(IBAction) nextTab:(id)aSender;
{
[[[mApplication mainWindow] windowController] nextTab];
}
-(IBAction) openFile:(id)aSender
{
NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
[openPanel setCanChooseFiles: YES];
[openPanel setCanChooseDirectories: NO];
[openPanel setAllowsMultipleSelection: NO];
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
@"txt",@"text",
@"gif",@"jpg",@"jpeg",@"png",@"bmp",
nil];
int result = [openPanel runModalForTypes: array];
if (result == NSOKButton) {
NSArray* urlArray = [openPanel URLs];
if ([urlArray count] == 0)
return;
NSURL* url = [urlArray objectAtIndex: 0];
// ----------------------
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
// ----------------------
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL: url];
[[[[mainWindow windowController] getBrowserWrapper] getBrowserView] setActive: YES];
}
else
[self openBrowserWindowWithURL: url];
}
}
-(IBAction) openLocation:(id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] performAppropriateLocationAction];
}
-(IBAction) savePage:(id)aSender
{
[[[mApplication mainWindow] windowController] saveDocument: mFilterView filterList: mFilterList];
}
-(IBAction) printPage:(id)aSender
{
[[[mApplication mainWindow] windowController] printDocument];
}
-(IBAction) printPreview:(id)aSender
{
[[[mApplication mainWindow] windowController] printPreview];
}
-(IBAction) toggleOfflineMode:(id)aSender
{
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
ioService->SetOffline(!offline);
mOffline = !offline;
// Update the menu item text.
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
else
[mOfflineMenuItem setTitle: @"Work Offline"];
// Indicate that we are working offline.
[[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
}
// Edit menu actions.
//
// -findInPage
//
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep
// one around for the whole app to use, showing/hiding as we see fit.
//
-(IBAction) findInPage:(id)aSender
{
if ( !mFindDialog )
mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
[mFindDialog showWindow:self];
}
//
// -findAgain
//
// Called in response to "Find Again" in edit menu. Tells the find controller
// to find the next occurrance of what's already been found.
//
-(IBAction) findAgain:(id)aSender
{
if ( mFindDialog )
[mFindDialog findAgain:aSender];
else
NSBeep();
}
-(IBAction) goBack:(id)aSender
{
[[[mApplication mainWindow] windowController] back: aSender];
}
-(IBAction) goForward:(id)aSender
{
[[[mApplication mainWindow] windowController] forward: aSender];
}
-(IBAction) doReload:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) reload: aSender];
}
-(IBAction) doStop:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) stop: aSender];
}
-(IBAction) goHome:(id)aSender
{
[[[mApplication mainWindow] windowController] home: aSender];
}
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
{
return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
}
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
{
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
[browser showWindow: self];
return browser;
}
-(void)applicationWillTerminate: (NSNotification*)aNotification
{
printf("Termination notification.\n");
// Autosave one of the windows.
[[[mApplication mainWindow] windowController] autosaveWindowFrame];
mMenuBookmarks->RemoveObserver();
delete mMenuBookmarks;
mMenuBookmarks = nsnull;
nsCocoaBrowserService::TermEmbedding();
}
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO];
}
-(IBAction) addFolder:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES];
}
-(IBAction) addSeparator:(id)aSender
{
}
-(IBAction) openMenuBookmark:(id)aSender
{
NSWindow* mainWind = [mApplication mainWindow];
if (!mainWind) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWind = [mApplication mainWindow];
}
BookmarksService::OpenMenuBookmark([mainWind windowController], aSender);
}
-(IBAction)manageBookmarks: (id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] manageBookmarks: aSender];
}
- (MVPreferencesController *)preferencesController
{
if (!preferencesController) {
preferencesController = [[MVPreferencesController sharedInstance] retain];
}
return preferencesController;
}
- (void)displayPreferencesWindow:sender
{
[[self preferencesController] showPreferences:nil] ;
}
- (IBAction)showAboutBox:(id)sender
{
[[CHAboutBox sharedInstance] showPanel:sender];
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL:[NSURL fileURLWithPath:filename]];
} else {
[self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]];
}
return YES;
}
- (IBAction)biggerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] biggerTextSize];
}
- (IBAction)smallerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] smallerTextSize];
}
- (IBAction)toggleSmoothText:(id)aSender
{
// XXXdwh Grab the prefs service and just set the pref directly.
}
@end

Просмотреть файл

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
class nsIWebBrowserPersist;
class nsISupports;
class nsIInputStream;
class nsDownloadListener;
@interface ProgressDlgController : NSWindowController {
IBOutlet id mFromField;
IBOutlet id mToField;
IBOutlet id mStatusLabel;
IBOutlet id mTimeLeftLabel;
IBOutlet id mElapsedTimeLabel;
IBOutlet id mProgressBar;
IBOutlet id mKeepOpenCheckbox;
IBOutlet id mCancelButton;
IBOutlet id mPauseResumeButton;
IBOutlet id mLaunchButton;
IBOutlet id mRevealFolderButton;
BOOL mDownloadIsPaused;
BOOL mSaveFileDialogShouldStayOpen;
NSToolbarItem *pauseResumeToggleToolbarItem;
NSToolbarItem *leaveOpenToggleToolbarItem;
nsDownloadListener* mDownloadListener;
}
-(void) setWebPersist: (nsIWebBrowserPersist*)aPersist
source: (nsISupports*)aSource
destination: (NSString*)aDestination
contentType: (const char*)aContentType
postData: (nsIInputStream*)aInputStream
bypassCache: (BOOL)aBypassCache;
-(void) setSourceURL: (const char*)aSource;
-(void) setDestination: (const char*)aDestination;
@end

Просмотреть файл

@ -0,0 +1,446 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "ProgressDlgController.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIWebBrowserPersist.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsILocalFile.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIWebProgressListener.h"
#include "nsIComponentManager.h"
#include "nsIPrefBranch.h"
const char* prefContractID = "@mozilla.org/preferences-service;1";
class nsDownloadListener : public nsIWebProgressListener
{
public:
nsDownloadListener(ProgressDlgController* aController,
nsIWebBrowserPersist* aPersist,
nsISupports* aSource,
NSString* aDestination,
const char* aContentType,
nsIInputStream* aPostData,
BOOL aBypassCache)
{
NS_INIT_REFCNT();
mController = aController;
mWebPersist = aPersist;
// The source is either a simple URL or a complete document.
mURL = do_QueryInterface(aSource);
if (!mURL)
mDocument = do_QueryInterface(aSource);
nsCAutoString dstStr = [aDestination cString];
NS_NewLocalFile(dstStr.get(), PR_FALSE, getter_AddRefs(mDestination));
mContentType = aContentType;
mPostData = aPostData;
mBypassCache = aBypassCache;
};
virtual ~nsDownloadListener() {};
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
public:
void BeginDownload();
void InitDialog();
private: // Member variables
ProgressDlgController* mController; // Controller for our UI.
nsCOMPtr<nsIWebBrowserPersist> mWebPersist; // Our web persist object.
nsCOMPtr<nsIURL> mURL; // The URL of our source file. Null if we're saving a complete document.
nsCOMPtr<nsILocalFile> mDestination; // Our destination URL.
nsCString mContentType; // Our content type string.
nsCOMPtr<nsIDOMHTMLDocument> mDocument; // A DOM document. Null if we're only saving a simple URL.
nsCOMPtr<nsIInputStream> mPostData; // For complete documents, this is our post data from session history.
PRBool mBypassCache; // Whether we should bypass the cache or not.
};
NS_IMPL_ISUPPORTS1(nsDownloadListener, nsIWebProgressListener)
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP
nsDownloadListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsDownloadListener::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsDownloadListener::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsDownloadListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 state)
{
return NS_OK;
}
// Implementation of nsIWebProgressListener
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsDownloadListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
PRUint32 aStatus)
{
return NS_OK;
}
void
nsDownloadListener::BeginDownload()
{
if (mWebPersist) {
mWebPersist->SetProgressListener(this);
PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES;
if (mBypassCache)
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE;
else
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
if (mURL)
mWebPersist->SaveURI(mURL, mPostData, mDestination);
else {
PRInt32 encodingFlags = 0;
nsCOMPtr<nsILocalFile> filesFolder;
if (!mContentType.Equals("text/plain")) {
// Create a local directory in the same dir as our file. It
// will hold our associated files.
filesFolder = do_CreateInstance("@mozilla.org/file/local;1");
nsXPIDLString unicodePath;
mDestination->GetUnicodePath(getter_Copies(unicodePath));
filesFolder->InitWithUnicodePath(unicodePath.get());
nsXPIDLCString leafName;
filesFolder->GetLeafName(getter_Copies(leafName));
nsCAutoString nameMinusExt(leafName.get());
PRInt32 index = nameMinusExt.RFind(".");
if (index >= 0)
nameMinusExt.Left(nameMinusExt, index);
nameMinusExt += " Files"; // XXXdwh needs to be localizable!
filesFolder->SetLeafName(nameMinusExt.get());
PRBool exists = PR_FALSE;
filesFolder->Exists(&exists);
if (!exists)
filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
}
else
encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED |
nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS |
nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT;
mWebPersist->SaveDocument(mDocument, mDestination, filesFolder, mContentType.get(),
encodingFlags, 80);
}
}
InitDialog();
}
void
nsDownloadListener::InitDialog()
{
if (!mURL && !mDocument)
return;
if (mWebPersist) {
if (mURL) {
nsCAutoString spec;
mURL->GetSpec(spec);
[mController setSourceURL: spec.get()];
}
else {
nsAutoString spec;
mDocument->GetURL(spec);
nsCAutoString spec2; spec2.AssignWithConversion(spec);
[mController setSourceURL: spec2.get()];
}
}
nsXPIDLString path;
mDestination->GetUnicodePath(getter_Copies(path));
nsCAutoString pathStr; pathStr.AssignWithConversion(path.get());
[mController setDestination: pathStr.get()];
}
static NSString *SaveFileToolbarIdentifier = @"Save File Dialog Toolbar";
static NSString *CancelToolbarItemIdentifier = @"Cancel Toolbar Item";
static NSString *PauseResumeToolbarItemIdentifier = @"Pause and Resume Toggle Toolbar Item";
static NSString *ShowFileToolbarItemIdentifier = @"Show File Toolbar Item";
static NSString *OpenFileToolbarItemIdentifier = @"Open File Toolbar Item";
static NSString *LeaveOpenToolbarItemIdentifier = @"Leave Open Toggle Toolbar Item";
@interface ProgressDlgController(Private)
-(void)setupToolbar;
@end
@implementation ProgressDlgController
-(void)setWebPersist:(nsIWebBrowserPersist*)aPersist
source:(nsISupports*)aSource
destination:(NSString*)aDestination
contentType:(const char*)aContentType
postData:(nsIInputStream*)aInputStream
bypassCache:(BOOL)aBypassCache
{
mDownloadListener = new nsDownloadListener(self, aPersist, aSource,
aDestination, aContentType,
aInputStream, aBypassCache);
NS_ADDREF(mDownloadListener);
}
-(void) setSourceURL: (const char*)aSource
{
[mFromField setStringValue: [NSString stringWithCString: aSource]];
}
-(void) setDestination: (const char*)aDestination
{
[mToField setStringValue: [NSString stringWithCString: aDestination]];
}
- (void)windowDidLoad
{
mDownloadIsPaused = NO;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
PRBool save = PR_FALSE;
prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive",
&save);
mSaveFileDialogShouldStayOpen = save;
[self setupToolbar];
if (mDownloadListener)
mDownloadListener->BeginDownload();
}
- (void)setupToolbar
{
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Cancel"];
[toolbarItem setPaletteLabel:@"Cancel Download"];
[toolbarItem setToolTip:@"Cancel this file download"];
[toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(cancel)];
} else if ( [itemIdent isEqual:PauseResumeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Pause"];
[toolbarItem setPaletteLabel:@"Pause Download"];
[toolbarItem setToolTip:@"Pause this FTP file download"];
[toolbarItem setImage:[NSImage imageNamed:@"savePause"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(pauseAndResumeDownload)];
if ( willBeInserted ) {
pauseResumeToggleToolbarItem = toolbarItem; //establish reference
}
} else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Show File"];
[toolbarItem setPaletteLabel:@"Show File"];
[toolbarItem setToolTip:@"Show the saved file in the Finder"];
[toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(showFile)];
} else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Open File"];
[toolbarItem setPaletteLabel:@"Open File"];
[toolbarItem setToolTip:@"Open the saved file in its default application."];
[toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(openFile)];
} else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) {
if ( mSaveFileDialogShouldStayOpen ) {
[toolbarItem setLabel:@"Leave Open"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will stay open when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
} else {
[toolbarItem setLabel:@"Close When Done"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will close automatically when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
}
if ( willBeInserted ) {
leaveOpenToggleToolbarItem = toolbarItem; //establish reference
}
} else {
toolbarItem = nil;
}
return toolbarItem;
}
-(void)cancel
{
NSLog(@"Request to cancel download.");
}
-(void)pauseAndResumeDownload
{
if ( ! mDownloadIsPaused ) {
//Do logic to pause download
mDownloadIsPaused = YES;
[pauseResumeToggleToolbarItem setLabel:@"Resume"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Resume Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Resume the paused FTP download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"saveResume"]];
} else {
//Do logic to resume download
mDownloadIsPaused = NO;
[pauseResumeToggleToolbarItem setLabel:@"Pause"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Pause Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Pause this FTP file download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"savePause"]];
}
}
-(void)showFile
{
NSLog(@"Request to show file.");
}
-(void)openFile
{
NSLog(@"Request to open file.");
}
-(void)toggleLeaveOpen
{
if ( ! mSaveFileDialogShouldStayOpen ) {
mSaveFileDialogShouldStayOpen = YES;
[leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
} else {
mSaveFileDialogShouldStayOpen = NO;
[leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen);
}
- (void)windowWillClose:(NSNotification *)notification
{
[self autorelease];
}
- (void)dealloc
{
NS_IF_RELEASE(mDownloadListener);
[super dealloc];
}
@end

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "BrowserWindowController.h"
#import "MVPreferencesController.h"
#import "CHSplashScreenWindow.h"
#import "FindDlgController.h"
class BookmarksService;
@interface MainController : NSObject
{
IBOutlet id mApplication;
// The following two items are used by the filter list when saving files.
IBOutlet id mFilterView;
IBOutlet id mFilterList;
IBOutlet id mOfflineMenuItem;
// The bookmarks menu.
IBOutlet id mBookmarksMenu;
BOOL mOffline;
CHSplashScreenWindow *mSplashScreen;
BookmarksService *mMenuBookmarks;
FindDlgController* mFindDialog;
MVPreferencesController *preferencesController;
}
-(void)dealloc;
// File menu actions.
-(IBAction) newWindow:(id)aSender;
-(IBAction) openFile:(id)aSender;
-(IBAction) openLocation:(id)aSender;
-(IBAction) savePage:(id)aSender;
-(IBAction) printPreview:(id)aSender;
-(IBAction) printPage:(id)aSender;
-(IBAction) toggleOfflineMode:(id)aSender;
// Edit menu actions.
-(IBAction) findInPage:(id)aSender;
-(IBAction) findAgain:(id)aSender;
// Go menu actions.
-(IBAction) goBack:(id)aSender;
-(IBAction) goForward:(id)aSender;
-(IBAction) goHome:(id)aSender;
-(IBAction) previousTab:(id)aSender;
-(IBAction) nextTab:(id)aSender;
// View menu actions.
-(IBAction) doReload:(id)aSender;
-(IBAction) doStop:(id)aSender;
-(IBAction) biggerTextSize:(id)aSender;
-(IBAction) smallerTextSize:(id)aSender;
-(IBAction) toggleSmoothText:(id)aSender;
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender;
-(IBAction) openMenuBookmark:(id)aSender;
-(IBAction) manageBookmarks: (id)aSender;
-(IBAction) addFolder:(id)aSender;
-(IBAction) addSeparator:(id)aSender;
//Window menu actions
-(IBAction) newTab:(id)aSender;
-(IBAction) closeTab:(id)aSender;
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL;
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL;
- (MVPreferencesController *)preferencesController;
- (void)displayPreferencesWindow:sender;
- (IBAction)showAboutBox:(id)sender;
@end

Просмотреть файл

@ -0,0 +1,375 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "MainController.h"
#import "BrowserWindowController.h"
#include "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsCocoaBrowserService.h"
#import "CHAboutBox.h"
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
@implementation MainController
-(id)init
{
if ( (self = [super init]) ) {
mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:YES withStatusRect:NSMakeRect(0,0,0,0)];
mFindDialog = nil;
mMenuBookmarks = nil;
}
return self;
}
-(void)dealloc
{
[super dealloc];
[mFindDialog release];
printf("Main controller died.\n");
}
-(void)awakeFromNib
{
[self newWindow: self];
[mSplashScreen close];
[mBookmarksMenu setAutoenablesItems: NO];
mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
mMenuBookmarks->AddObserver();
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
BookmarksService::gMainController = self;
// Initialize offline mode.
mOffline = NO;
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
mOffline = offline;
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
}
-(IBAction)newWindow:(id)aSender
{
// If we have a key window, have it autosave its dimensions before
// we open a new window. That ensures the size ends up matching.
NSWindow* mainWindow = [mApplication mainWindow];
if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
[controller focusURLBar];
}
-(IBAction)newTab:(id)aSender
{
[[[mApplication mainWindow] windowController] newTab];
}
-(IBAction)closeTab:(id)aSender
{
[[[mApplication mainWindow] windowController] closeTab];
}
-(IBAction) previousTab:(id)aSender
{
[[[mApplication mainWindow] windowController] previousTab];
}
-(IBAction) nextTab:(id)aSender;
{
[[[mApplication mainWindow] windowController] nextTab];
}
-(IBAction) openFile:(id)aSender
{
NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
[openPanel setCanChooseFiles: YES];
[openPanel setCanChooseDirectories: NO];
[openPanel setAllowsMultipleSelection: NO];
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
@"txt",@"text",
@"gif",@"jpg",@"jpeg",@"png",@"bmp",
nil];
int result = [openPanel runModalForTypes: array];
if (result == NSOKButton) {
NSArray* urlArray = [openPanel URLs];
if ([urlArray count] == 0)
return;
NSURL* url = [urlArray objectAtIndex: 0];
// ----------------------
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
// ----------------------
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL: url];
[[[[mainWindow windowController] getBrowserWrapper] getBrowserView] setActive: YES];
}
else
[self openBrowserWindowWithURL: url];
}
}
-(IBAction) openLocation:(id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] performAppropriateLocationAction];
}
-(IBAction) savePage:(id)aSender
{
[[[mApplication mainWindow] windowController] saveDocument: mFilterView filterList: mFilterList];
}
-(IBAction) printPage:(id)aSender
{
[[[mApplication mainWindow] windowController] printDocument];
}
-(IBAction) printPreview:(id)aSender
{
[[[mApplication mainWindow] windowController] printPreview];
}
-(IBAction) toggleOfflineMode:(id)aSender
{
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
ioService->SetOffline(!offline);
mOffline = !offline;
// Update the menu item text.
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
else
[mOfflineMenuItem setTitle: @"Work Offline"];
// Indicate that we are working offline.
[[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
}
// Edit menu actions.
//
// -findInPage
//
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep
// one around for the whole app to use, showing/hiding as we see fit.
//
-(IBAction) findInPage:(id)aSender
{
if ( !mFindDialog )
mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
[mFindDialog showWindow:self];
}
//
// -findAgain
//
// Called in response to "Find Again" in edit menu. Tells the find controller
// to find the next occurrance of what's already been found.
//
-(IBAction) findAgain:(id)aSender
{
if ( mFindDialog )
[mFindDialog findAgain:aSender];
else
NSBeep();
}
-(IBAction) goBack:(id)aSender
{
[[[mApplication mainWindow] windowController] back: aSender];
}
-(IBAction) goForward:(id)aSender
{
[[[mApplication mainWindow] windowController] forward: aSender];
}
-(IBAction) doReload:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) reload: aSender];
}
-(IBAction) doStop:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) stop: aSender];
}
-(IBAction) goHome:(id)aSender
{
[[[mApplication mainWindow] windowController] home: aSender];
}
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
{
return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
}
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
{
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
[browser showWindow: self];
return browser;
}
-(void)applicationWillTerminate: (NSNotification*)aNotification
{
printf("Termination notification.\n");
// Autosave one of the windows.
[[[mApplication mainWindow] windowController] autosaveWindowFrame];
mMenuBookmarks->RemoveObserver();
delete mMenuBookmarks;
mMenuBookmarks = nsnull;
nsCocoaBrowserService::TermEmbedding();
}
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO];
}
-(IBAction) addFolder:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES];
}
-(IBAction) addSeparator:(id)aSender
{
}
-(IBAction) openMenuBookmark:(id)aSender
{
NSWindow* mainWind = [mApplication mainWindow];
if (!mainWind) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWind = [mApplication mainWindow];
}
BookmarksService::OpenMenuBookmark([mainWind windowController], aSender);
}
-(IBAction)manageBookmarks: (id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] manageBookmarks: aSender];
}
- (MVPreferencesController *)preferencesController
{
if (!preferencesController) {
preferencesController = [[MVPreferencesController sharedInstance] retain];
}
return preferencesController;
}
- (void)displayPreferencesWindow:sender
{
[[self preferencesController] showPreferences:nil] ;
}
- (IBAction)showAboutBox:(id)sender
{
[[CHAboutBox sharedInstance] showPanel:sender];
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL:[NSURL fileURLWithPath:filename]];
} else {
[self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]];
}
return YES;
}
- (IBAction)biggerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] biggerTextSize];
}
- (IBAction)smallerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] smallerTextSize];
}
- (IBAction)toggleSmoothText:(id)aSender
{
// XXXdwh Grab the prefs service and just set the pref directly.
}
@end

Просмотреть файл

@ -0,0 +1,183 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "CHBrowserWrapper.h"
#import "CHFind.h"
#import "CHBookmarksToolbar.h"
class nsIDOMEvent;
class nsIDOMNode;
@interface BrowserWindowController : NSWindowController<CHFind>
{
IBOutlet id mTabBrowser;
IBOutlet NSDrawer* mSidebarDrawer;
IBOutlet id mSidebarTabView;
IBOutlet id mSidebarSourceTabView;
IBOutlet id mLocationToolbarView;
IBOutlet id mURLBar;
IBOutlet id mStatus;
IBOutlet id mProgress;
IBOutlet id mLocationSheetWindow;
IBOutlet id mLocationSheetURLField;
IBOutlet id mSidebarBrowserView;
IBOutlet id mSidebarBookmarksDataSource;
IBOutlet CHBookmarksToolbar* mPersonalToolbar;
IBOutlet id mAddBookmarkSheetWindow;
IBOutlet id mAddBookmarkTitleField;
IBOutlet id mAddBookmarkFolderField;
IBOutlet id mAddBookmarkCheckbox;
// Context menu outlets.
IBOutlet id mPageMenu;
IBOutlet id mImageMenu;
IBOutlet id mInputMenu;
IBOutlet id mLinkMenu;
IBOutlet id mImageLinkMenu;
NSToolbarItem *mLocationToolbarItem;
NSToolbarItem *mSidebarToolbarItem;
BOOL mInitialized;
NSURL* mURL;
CHBrowserWrapper* mBrowserView;
BOOL mMoveReentrant;
NSModalSession mModalSession;
BOOL mShouldAutosave;
BOOL mDrawerCachedFrame;
NSRect mCachedFrameBeforeDrawerOpen; // This is used by the drawer to figure out if the window should
// be returned to its original position when the drawer closes.
NSRect mCachedFrameAfterDrawerOpen;
int mChromeMask; // Indicates which parts of the window to show (e.g., don't show toolbars)
// Context menu members.
int mContextMenuFlags;
nsIDOMEvent* mContextMenuEvent;
nsIDOMNode* mContextMenuNode;
// Cached bookmark ds used when adding through a sheet
id mCachedBMDS;
}
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSURL*)aURL;
- (void)updateLocationFields:(NSString *)locationString;
- (void)updateToolbarItems;
- (void)focusURLBar;
- (void)performAppropriateLocationAction;
- (IBAction)goToLocationFromToolbarURLField:(id)sender;
- (void)focusURLBar;
- (void)beginLocationSheet;
- (IBAction)endLocationSheet:(id)sender;
- (IBAction)cancelAddBookmarkSheet:(id)sender;
- (IBAction)endAddBookmarkSheet:(id)sender;
- (void)cacheBookmarkDS: (id)aDS;
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
- (void)printDocument;
- (void)printPreview;
//- (BOOL)findInPage:(NSString*)text;
-(void) biggerTextSize;
-(void) smallerTextSize;
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder;
- (IBAction)manageBookmarks: (id)aSender;
- (IBAction)toggleSidebar:(id)aSender;
- (void)newTab;
- (void)closeTab;
- (void)previousTab;
- (void)nextTab;
- (IBAction)back:(id)aSender;
- (IBAction)forward:(id)aSender;
- (IBAction)reload:(id)aSender;
- (IBAction)stop:(id)aSender;
- (IBAction)home:(id)aSender;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;
-(void)disableAutosave;
-(void)setChromeMask:(int)aMask;
-(id)getAddBookmarkSheetWindow;
-(id)getAddBookmarkTitle;
-(id)getAddBookmarkFolder;
-(id)getAddBookmarkCheckbox;
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
- (NSMenu*)getContextMenu;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;
- (IBAction)saveImageAs:(id)aSender;
- (IBAction)viewOnlyThisImage:(id)aSender;
- (NSView*) bookmarksToolbar;
@end

Просмотреть файл

@ -0,0 +1,952 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIPrefBranch.h"
#include "nsIContextMenuListener.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsCocoaBrowserService.h"
#include "nsString.h"
#include "CHGeckoUtils.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item";
static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
@interface BrowserWindowController(Private)
- (void)setupToolbar;
- (void)setupSidebarTabs;
@end
@implementation BrowserWindowController
-(void)enterModalSession
{
mModalSession = [NSApp beginModalSessionForWindow: [self window]];
[NSApp runModalSession: mModalSession];
[NSApp endModalSession: mModalSession];
mModalSession = nil;
}
-(void)windowDidBecomeKey: (NSNotification*)aNotification
{
// May become necessary later.
}
-(void)windowDidResignKey: (NSNotification*)aNotification
{
// May be needed later.
}
-(void)mouseMoved:(NSEvent*)aEvent
{
if (mMoveReentrant)
return;
mMoveReentrant = YES;
NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
[view mouseMoved: aEvent];
[super mouseMoved: aEvent];
mMoveReentrant = NO;
}
- (id)initWithWindowNibName:(NSString *)windowNibName
{
if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
[self setShouldCascadeWindows:NO];
} else {
[self setShouldCascadeWindows:YES];
}
mInitialized = NO;
mMoveReentrant = NO;
mShouldAutosave = YES;
mChromeMask = 0;
mContextMenuFlags = 0;
mContextMenuEvent = nsnull;
mContextMenuNode = nsnull;
}
return self;
}
-(void)autosaveWindowFrame
{
if (mShouldAutosave)
[[self window] saveFrameUsingName: @"NavigatorWindow"];
}
-(void)disableAutosave
{
mShouldAutosave = NO;
}
- (void)windowWillClose:(NSNotification *)notification
{
printf("Window will close notification.\n");
[mSidebarBookmarksDataSource windowClosing];
[self autosaveWindowFrame];
[self autorelease];
}
- (void)dealloc
{
printf("Browser controller died.\n");
// Loop over all tabs, and tell them that the window is closed.
int numTabs = [mTabBrowser numberOfTabViewItems];
for (int i = 0; i < numTabs; i++) {
NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
[[item view] windowClosed];
}
[mSidebarBrowserView windowClosed];
[mProgress release];
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[[mURLBar cell] setImage: [NSImage imageNamed:@"smallbookmark"]];
// Get our saved dimensions.
[[self window] setFrameUsingName: @"NavigatorWindow"];
if (mModalSession)
[NSApp stopModal];
mInitialized = YES;
mDrawerCachedFrame = NO;
// Retain with a single extra refcount. This allows the CHBrowserWrappers
// to remove the progress meter from its superview without having to
// worry about retaining and releasing it.
[mProgress retain];
[[self window] setAcceptsMouseMovedEvents: YES];
[self setupToolbar];
// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was
// duplicating a lot of the code found here. I have moved it to that method.
// We now remove the IB tab, then add one of our own.
[mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
[self newTab];
if (mURL) {
[self loadURL: mURL];
[mURL release];
}
[mSidebarDrawer setDelegate: self];
[self setupSidebarTabs];
[mPersonalToolbar initializeToolbar];
}
- (void)drawerWillOpen: (NSNotification*)aNotification
{
[mSidebarBookmarksDataSource ensureBookmarks];
// Force the window to shrink and move if necessary in order to accommodate the sidebar.
NSRect screenFrame = [[[self window] screen] visibleFrame];
NSRect windowFrame = [[self window] frame];
NSSize drawerSize = [mSidebarDrawer contentSize];
int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
drawerSize.width += fudgeFactor;
if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
screenFrame.size.width) {
// We need to adjust the window so that it can fit.
float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
if (shrinkDelta < 0) shrinkDelta = 0;
float newWidth = (windowFrame.size.width - shrinkDelta);
float newPosition = screenFrame.size.width - newWidth - drawerSize.width;
if (newPosition < 0) newPosition = 0;
mCachedFrameBeforeDrawerOpen = windowFrame;
windowFrame.origin.x = newPosition;
windowFrame.size.width = newWidth;
mCachedFrameAfterDrawerOpen = windowFrame;
[[self window] setFrame: windowFrame display: YES];
mDrawerCachedFrame = YES;
}
}
- (void)drawerDidOpen:(NSNotification *)aNotification
{
// XXXdwh This is temporary.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
// Toggle the sidebar icon.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
}
- (void)drawerDidClose:(NSNotification *)aNotification
{
// Unload the Gecko web page in "My Panels" to save memory.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
// XXXdwh ignore for now.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
if (mDrawerCachedFrame) {
printf("Got here.\n");
mDrawerCachedFrame = NO;
NSRect frame = [[self window] frame];
if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
printf("Got here too.\n");
printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
// Restore the original frame.
[[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
}
}
}
- (void)setupToolbar
{
if (mChromeMask) {
printf("Uh-oh. %d\n", mChromeMask);
}
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
PrintToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Back"];
[toolbarItem setPaletteLabel:@"Go Back"];
[toolbarItem setToolTip:@"Go back one page"];
[toolbarItem setImage:[NSImage imageNamed:@"back"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(back:)];
} else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Forward"];
[toolbarItem setPaletteLabel:@"Go Forward"];
[toolbarItem setToolTip:@"Go forward one page"];
[toolbarItem setImage:[NSImage imageNamed:@"forward"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(forward:)];
} else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Reload"];
[toolbarItem setPaletteLabel:@"Reload Page"];
[toolbarItem setToolTip:@"Reload current page"];
[toolbarItem setImage:[NSImage imageNamed:@"reload"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(reload:)];
} else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Stop"];
[toolbarItem setPaletteLabel:@"Stop Loading"];
[toolbarItem setToolTip:@"Stop loading this page"];
[toolbarItem setImage:[NSImage imageNamed:@"stop"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(stop:)];
} else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Home"];
[toolbarItem setPaletteLabel:@"Go Home"];
[toolbarItem setToolTip:@"Go to home page"];
[toolbarItem setImage:[NSImage imageNamed:@"home"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(home:)];
} else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Sidebar"];
[toolbarItem setPaletteLabel:@"Toggle Sidebar"];
[toolbarItem setToolTip:@"Show or hide the Sidebar"];
[toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleSidebar:)];
mSidebarToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:@"Location"];
[toolbarItem setPaletteLabel:@"Location"];
[toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
[toolbarItem setView:mLocationToolbarView];
[toolbarItem setMinSize:NSMakeSize(128,32)];
[toolbarItem setMaxSize:NSMakeSize(2560,32)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(performAppropriateLocationAction)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
mLocationToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Print"];
[toolbarItem setPaletteLabel:@"Print"];
[toolbarItem setToolTip:@"Print this page"];
[toolbarItem setImage:[NSImage imageNamed:@"print"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(printDocument)];
} else {
toolbarItem = nil;
}
return toolbarItem;
}
// This method handles the enabling/disabling of the toolbar buttons.
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
// Check the action and see if it matches.
SEL action = [theItem action];
if (action == @selector(back:))
return [[mBrowserView getBrowserView] canGoBack];
else if (action == @selector(forward:))
return [[mBrowserView getBrowserView] canGoForward];
else if (action == @selector(reload:))
return [mBrowserView isBusy] == NO;
else if (action == @selector(stop:))
return [mBrowserView isBusy];
else
return YES;
}
- (void)updateToolbarItems
{
[[[self window] toolbar] validateVisibleItems];
}
- (void)performAppropriateLocationAction
{
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
[self focusURLBar];
} else {
[self beginLocationSheet];
}
} else {
[self beginLocationSheet];
}
}
- (void)focusURLBar
{
[mURLBar selectText: self];
}
- (void)beginLocationSheet
{
[NSApp beginSheet: mLocationSheetWindow
modalForWindow: [self window]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
- (IBAction)endLocationSheet:(id)sender
{
[mLocationSheetWindow orderOut:self];
[NSApp endSheet:mLocationSheetWindow returnCode:1];
[self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
-(IBAction)cancelAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 0];
}
-(IBAction)endAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 1];
}
- (void)cacheBookmarkDS: (id)aDS
{
mCachedBMDS = aDS;
}
-(IBAction)manageBookmarks: (id)aSender
{
if ([mSidebarDrawer state] == NSDrawerClosedState)
[self toggleSidebar: self];
[mSidebarTabView selectFirstTabViewItem:self];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender
{
[self loadURL:[NSURL URLWithString:[sender stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
{
[[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
}
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename
{
[[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList
url: aURL suggestedFilename: aFilename];
}
- (void)printDocument
{
[[mBrowserView getBrowserView] printDocument];
}
- (void)printPreview
{
[[mBrowserView getBrowserView] printPreview];
}
- (BOOL)findInPage:(NSString*)text
{
return [[mBrowserView getBrowserView] findInPage:text];
}
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder
{
[mSidebarBookmarksDataSource ensureBookmarks];
BOOL useSel = aIsFromMenu;
if (aIsFromMenu) {
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
if ([mSidebarDrawer state] == NSDrawerClosedState)
useSel = NO;
else
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
useSel = NO;
}
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder];
}
- (IBAction)back:(id)aSender
{
[[mBrowserView getBrowserView] goBack];
}
- (IBAction)forward:(id)aSender
{
[[mBrowserView getBrowserView] goForward];
}
- (IBAction)reload:(id)aSender
{
[[mBrowserView getBrowserView] reload: 0];
}
- (IBAction)stop:(id)aSender
{
[[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
}
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender
{
NSResponder* resp = [[self window] firstResponder];
[[self window] makeFirstResponder: nil];
if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
// XXXHack to bypass sidebar crashes.
[mSidebarDrawer openOnEdge: NSMaxXEdge];
} else {
[mSidebarDrawer close];
}
[[self window] makeFirstResponder: resp];
}
-(void)loadURL:(NSURL*)aURL
{
if (mInitialized) {
[[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
}
else {
mURL = aURL;
[mURL retain];
}
}
- (void)updateLocationFields:(NSString *)locationString
{
/* //commenting this out because it doesn't work right yet.
if ( [locationString length] > 30 ) {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
} else {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@", locationString]];
}
*/
[mURLBar setStringValue:locationString];
[mLocationSheetURLField setStringValue:locationString];
[[self window] update];
[[self window] display];
}
-(void)newTab
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newTab setLabel: @"Untitled"];
[newTab setView: newView];
[mTabBrowser addTabViewItem: newTab];
[[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[mTabBrowser selectLastTabViewItem: self];
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
if ([mTabBrowser numberOfTabViewItems] > 1) {
[self focusURLBar];
[[mBrowserView getBrowserView] setActive: NO];
}
else if ([[self window] isKeyWindow])
[[mBrowserView getBrowserView] setActive: YES];
else
[[mBrowserView getBrowserView] setActive: NO];
}
}
}
-(void)closeTab
{
if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
[[[mTabBrowser selectedTabViewItem] view] windowClosed];
[mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
}
}
- (void)previousTab
{
[mTabBrowser selectPreviousTabViewItem:self];
}
- (void)nextTab
{
[mTabBrowser selectNextTabViewItem:self];
}
- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
{
// Disconnect the old view, if one has been designated.
// If the window has just been opened, none has been.
if ( mBrowserView ) {
[mBrowserView disconnectView];
}
// Connect up the new view
mBrowserView = [aTabViewItem view];
// Make the new view the primary content area.
[mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
progress: mProgress windowController: self];
}
-(id)getTabBrowser
{
return mTabBrowser;
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
}
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
[mTabBrowser insertTabViewItem: newTab atIndex: index+1];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newView setTab: newTab];
[newTab setLabel: @"Loading..."];
[newTab setView: newView];
[[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
if (!aLoadInBG) {
[mTabBrowser selectTabViewItem: newTab];
// Focus the content area.
[[newView getBrowserView] setActive: YES];
}
}
-(void)setupSidebarTabs
{
CHIconTabViewItem *bookItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"bookicon"]];
CHIconTabViewItem *histItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"historySidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"historyicon"]];
CHIconTabViewItem *searchItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"searchSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"searchicon"]];
CHIconTabViewItem *panelsItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"myPanelsCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"panel_icon"]];
[bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
[histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
[searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
[mSidebarTabView insertTabViewItem:searchItem atIndex:2];
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
[mSidebarTabView selectFirstTabViewItem:self];
}
-(void)setChromeMask:(int)aMask
{
mChromeMask = aMask;
}
-(void) biggerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom >= 20)
return;
zoom += 0.25;
if (zoom > 20)
zoom = 20;
markupViewer->SetTextZoom(zoom);
}
-(void) smallerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom <= 0.01)
return;
zoom -= 0.25;
if (zoom < 0.01)
zoom = 0.01;
markupViewer->SetTextZoom(zoom);
}
-(id)getAddBookmarkSheetWindow
{
return mAddBookmarkSheetWindow;
}
-(id)getAddBookmarkTitle
{
return mAddBookmarkTitleField;
}
-(id)getAddBookmarkFolder
{
return mAddBookmarkFolderField;
}
-(id)getAddBookmarkCheckbox
{
return mAddBookmarkCheckbox;
}
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
{
mContextMenuFlags = flags;
mContextMenuNode = aNode;
mContextMenuEvent = aEvent;
}
- (NSMenu*)getContextMenu
{
NSMenu* result = nil;
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageLinkMenu;
}
else
result = mLinkMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
(mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
result = mInputMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
result = mPageMenu;
}
return result;
}
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender
{
[self openLinkInNewWindowOrTab: YES];
}
- (IBAction)openLinkInNewTab:(id)aSender
{
[self openLinkInNewWindowOrTab: NO];
}
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
if (aUseWindow)
[self openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
else
[self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
- (IBAction)savePageAs:(id)aSender
{
[self saveDocument: nil filterList: nil];
}
- (IBAction)saveLinkAs:(id)aSender
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
// The user wants to save this link.
nsAutoString text;
CHGeckoUtils::GatherTextUnder(mContextMenuNode, text);
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
- (IBAction)saveImageAs:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString text;
imgElement->GetAttribute(NS_LITERAL_STRING("src"), text);
nsAutoString url;
imgElement->GetSrc(url);
NSString* hrefStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
}
- (IBAction)viewOnlyThisImage:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString url;
imgElement->GetSrc(url);
NSString* urlStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToView = [NSURL URLWithString: urlStr];
[self loadURL: urlToView];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
}
- (NSView*) bookmarksToolbar
{
return mPersonalToolbar;
}
@end

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
class nsIWebBrowserPersist;
class nsISupports;
class nsIInputStream;
class nsDownloadListener;
@interface ProgressDlgController : NSWindowController {
IBOutlet id mFromField;
IBOutlet id mToField;
IBOutlet id mStatusLabel;
IBOutlet id mTimeLeftLabel;
IBOutlet id mElapsedTimeLabel;
IBOutlet id mProgressBar;
IBOutlet id mKeepOpenCheckbox;
IBOutlet id mCancelButton;
IBOutlet id mPauseResumeButton;
IBOutlet id mLaunchButton;
IBOutlet id mRevealFolderButton;
BOOL mDownloadIsPaused;
BOOL mSaveFileDialogShouldStayOpen;
NSToolbarItem *pauseResumeToggleToolbarItem;
NSToolbarItem *leaveOpenToggleToolbarItem;
nsDownloadListener* mDownloadListener;
}
-(void) setWebPersist: (nsIWebBrowserPersist*)aPersist
source: (nsISupports*)aSource
destination: (NSString*)aDestination
contentType: (const char*)aContentType
postData: (nsIInputStream*)aInputStream
bypassCache: (BOOL)aBypassCache;
-(void) setSourceURL: (const char*)aSource;
-(void) setDestination: (const char*)aDestination;
@end

Просмотреть файл

@ -0,0 +1,446 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "ProgressDlgController.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIWebBrowserPersist.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsILocalFile.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIWebProgressListener.h"
#include "nsIComponentManager.h"
#include "nsIPrefBranch.h"
const char* prefContractID = "@mozilla.org/preferences-service;1";
class nsDownloadListener : public nsIWebProgressListener
{
public:
nsDownloadListener(ProgressDlgController* aController,
nsIWebBrowserPersist* aPersist,
nsISupports* aSource,
NSString* aDestination,
const char* aContentType,
nsIInputStream* aPostData,
BOOL aBypassCache)
{
NS_INIT_REFCNT();
mController = aController;
mWebPersist = aPersist;
// The source is either a simple URL or a complete document.
mURL = do_QueryInterface(aSource);
if (!mURL)
mDocument = do_QueryInterface(aSource);
nsCAutoString dstStr = [aDestination cString];
NS_NewLocalFile(dstStr.get(), PR_FALSE, getter_AddRefs(mDestination));
mContentType = aContentType;
mPostData = aPostData;
mBypassCache = aBypassCache;
};
virtual ~nsDownloadListener() {};
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
public:
void BeginDownload();
void InitDialog();
private: // Member variables
ProgressDlgController* mController; // Controller for our UI.
nsCOMPtr<nsIWebBrowserPersist> mWebPersist; // Our web persist object.
nsCOMPtr<nsIURL> mURL; // The URL of our source file. Null if we're saving a complete document.
nsCOMPtr<nsILocalFile> mDestination; // Our destination URL.
nsCString mContentType; // Our content type string.
nsCOMPtr<nsIDOMHTMLDocument> mDocument; // A DOM document. Null if we're only saving a simple URL.
nsCOMPtr<nsIInputStream> mPostData; // For complete documents, this is our post data from session history.
PRBool mBypassCache; // Whether we should bypass the cache or not.
};
NS_IMPL_ISUPPORTS1(nsDownloadListener, nsIWebProgressListener)
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP
nsDownloadListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsDownloadListener::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsDownloadListener::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsDownloadListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 state)
{
return NS_OK;
}
// Implementation of nsIWebProgressListener
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsDownloadListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
PRUint32 aStatus)
{
return NS_OK;
}
void
nsDownloadListener::BeginDownload()
{
if (mWebPersist) {
mWebPersist->SetProgressListener(this);
PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES;
if (mBypassCache)
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE;
else
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
if (mURL)
mWebPersist->SaveURI(mURL, mPostData, mDestination);
else {
PRInt32 encodingFlags = 0;
nsCOMPtr<nsILocalFile> filesFolder;
if (!mContentType.Equals("text/plain")) {
// Create a local directory in the same dir as our file. It
// will hold our associated files.
filesFolder = do_CreateInstance("@mozilla.org/file/local;1");
nsXPIDLString unicodePath;
mDestination->GetUnicodePath(getter_Copies(unicodePath));
filesFolder->InitWithUnicodePath(unicodePath.get());
nsXPIDLCString leafName;
filesFolder->GetLeafName(getter_Copies(leafName));
nsCAutoString nameMinusExt(leafName.get());
PRInt32 index = nameMinusExt.RFind(".");
if (index >= 0)
nameMinusExt.Left(nameMinusExt, index);
nameMinusExt += " Files"; // XXXdwh needs to be localizable!
filesFolder->SetLeafName(nameMinusExt.get());
PRBool exists = PR_FALSE;
filesFolder->Exists(&exists);
if (!exists)
filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
}
else
encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED |
nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS |
nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT;
mWebPersist->SaveDocument(mDocument, mDestination, filesFolder, mContentType.get(),
encodingFlags, 80);
}
}
InitDialog();
}
void
nsDownloadListener::InitDialog()
{
if (!mURL && !mDocument)
return;
if (mWebPersist) {
if (mURL) {
nsCAutoString spec;
mURL->GetSpec(spec);
[mController setSourceURL: spec.get()];
}
else {
nsAutoString spec;
mDocument->GetURL(spec);
nsCAutoString spec2; spec2.AssignWithConversion(spec);
[mController setSourceURL: spec2.get()];
}
}
nsXPIDLString path;
mDestination->GetUnicodePath(getter_Copies(path));
nsCAutoString pathStr; pathStr.AssignWithConversion(path.get());
[mController setDestination: pathStr.get()];
}
static NSString *SaveFileToolbarIdentifier = @"Save File Dialog Toolbar";
static NSString *CancelToolbarItemIdentifier = @"Cancel Toolbar Item";
static NSString *PauseResumeToolbarItemIdentifier = @"Pause and Resume Toggle Toolbar Item";
static NSString *ShowFileToolbarItemIdentifier = @"Show File Toolbar Item";
static NSString *OpenFileToolbarItemIdentifier = @"Open File Toolbar Item";
static NSString *LeaveOpenToolbarItemIdentifier = @"Leave Open Toggle Toolbar Item";
@interface ProgressDlgController(Private)
-(void)setupToolbar;
@end
@implementation ProgressDlgController
-(void)setWebPersist:(nsIWebBrowserPersist*)aPersist
source:(nsISupports*)aSource
destination:(NSString*)aDestination
contentType:(const char*)aContentType
postData:(nsIInputStream*)aInputStream
bypassCache:(BOOL)aBypassCache
{
mDownloadListener = new nsDownloadListener(self, aPersist, aSource,
aDestination, aContentType,
aInputStream, aBypassCache);
NS_ADDREF(mDownloadListener);
}
-(void) setSourceURL: (const char*)aSource
{
[mFromField setStringValue: [NSString stringWithCString: aSource]];
}
-(void) setDestination: (const char*)aDestination
{
[mToField setStringValue: [NSString stringWithCString: aDestination]];
}
- (void)windowDidLoad
{
mDownloadIsPaused = NO;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
PRBool save = PR_FALSE;
prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive",
&save);
mSaveFileDialogShouldStayOpen = save;
[self setupToolbar];
if (mDownloadListener)
mDownloadListener->BeginDownload();
}
- (void)setupToolbar
{
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Cancel"];
[toolbarItem setPaletteLabel:@"Cancel Download"];
[toolbarItem setToolTip:@"Cancel this file download"];
[toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(cancel)];
} else if ( [itemIdent isEqual:PauseResumeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Pause"];
[toolbarItem setPaletteLabel:@"Pause Download"];
[toolbarItem setToolTip:@"Pause this FTP file download"];
[toolbarItem setImage:[NSImage imageNamed:@"savePause"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(pauseAndResumeDownload)];
if ( willBeInserted ) {
pauseResumeToggleToolbarItem = toolbarItem; //establish reference
}
} else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Show File"];
[toolbarItem setPaletteLabel:@"Show File"];
[toolbarItem setToolTip:@"Show the saved file in the Finder"];
[toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(showFile)];
} else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Open File"];
[toolbarItem setPaletteLabel:@"Open File"];
[toolbarItem setToolTip:@"Open the saved file in its default application."];
[toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(openFile)];
} else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) {
if ( mSaveFileDialogShouldStayOpen ) {
[toolbarItem setLabel:@"Leave Open"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will stay open when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
} else {
[toolbarItem setLabel:@"Close When Done"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will close automatically when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
}
if ( willBeInserted ) {
leaveOpenToggleToolbarItem = toolbarItem; //establish reference
}
} else {
toolbarItem = nil;
}
return toolbarItem;
}
-(void)cancel
{
NSLog(@"Request to cancel download.");
}
-(void)pauseAndResumeDownload
{
if ( ! mDownloadIsPaused ) {
//Do logic to pause download
mDownloadIsPaused = YES;
[pauseResumeToggleToolbarItem setLabel:@"Resume"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Resume Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Resume the paused FTP download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"saveResume"]];
} else {
//Do logic to resume download
mDownloadIsPaused = NO;
[pauseResumeToggleToolbarItem setLabel:@"Pause"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Pause Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Pause this FTP file download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"savePause"]];
}
}
-(void)showFile
{
NSLog(@"Request to show file.");
}
-(void)openFile
{
NSLog(@"Request to open file.");
}
-(void)toggleLeaveOpen
{
if ( ! mSaveFileDialogShouldStayOpen ) {
mSaveFileDialogShouldStayOpen = YES;
[leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
} else {
mSaveFileDialogShouldStayOpen = NO;
[leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen);
}
- (void)windowWillClose:(NSNotification *)notification
{
[self autorelease];
}
- (void)dealloc
{
NS_IF_RELEASE(mDownloadListener);
[super dealloc];
}
@end

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
#include "nsIWebBrowserFind.h"
@interface FindDlgController : NSWindowController {
IBOutlet id mSearchField;
IBOutlet id mIgnoreCaseBox;
IBOutlet id mWrapAroundBox;
IBOutlet id mSearchBackwardsBox;
IBOutlet id mFindButton;
NSString* mSearchText;
}
-(IBAction) find: (id)aSender;
-(IBAction) findAgain: (id)aSender;
// delegates for NSTextView
- (void)controlTextDidChange:(NSNotification *)aNotification;
@end

Просмотреть файл

@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "FindDlgController.h"
#import "BrowserWindowController.h"
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (void)windowDidLoad
{
}
//
// -find
//
// User clicked the find button, send the action to the window controller of the
// frontmost browser window. If we found something, hide the window. If not, beep.
//
-(IBAction) find: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
mSearchText = [mSearchField stringValue];
BOOL found = [browserController findInPage:mSearchText];
if ( found )
[self close];
else
NSBeep();
}
else
NSBeep();
}
//
// -findAgain
//
// Someone hit "find again" in the edit menu, send the action to the window controller of the
// frontmost browser window. Beep if we didn't find something.
//
-(IBAction) findAgain: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
BOOL found = [browserController findInPage:mSearchText];
if ( !found )
NSBeep();
}
else
NSBeep();
}
//
// controlTextDidChange
//
// Check if there is anything in the text field, and if not, disable the find button
//
- (void)controlTextDidChange:(NSNotification *)aNotification
{
if ( [[mSearchField stringValue] length] )
[mFindButton setEnabled:PR_TRUE];
else
[mFindButton setEnabled:PR_FALSE];
}
@end

Просмотреть файл

@ -0,0 +1,183 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "CHBrowserWrapper.h"
#import "CHFind.h"
#import "CHBookmarksToolbar.h"
class nsIDOMEvent;
class nsIDOMNode;
@interface BrowserWindowController : NSWindowController<CHFind>
{
IBOutlet id mTabBrowser;
IBOutlet NSDrawer* mSidebarDrawer;
IBOutlet id mSidebarTabView;
IBOutlet id mSidebarSourceTabView;
IBOutlet id mLocationToolbarView;
IBOutlet id mURLBar;
IBOutlet id mStatus;
IBOutlet id mProgress;
IBOutlet id mLocationSheetWindow;
IBOutlet id mLocationSheetURLField;
IBOutlet id mSidebarBrowserView;
IBOutlet id mSidebarBookmarksDataSource;
IBOutlet CHBookmarksToolbar* mPersonalToolbar;
IBOutlet id mAddBookmarkSheetWindow;
IBOutlet id mAddBookmarkTitleField;
IBOutlet id mAddBookmarkFolderField;
IBOutlet id mAddBookmarkCheckbox;
// Context menu outlets.
IBOutlet id mPageMenu;
IBOutlet id mImageMenu;
IBOutlet id mInputMenu;
IBOutlet id mLinkMenu;
IBOutlet id mImageLinkMenu;
NSToolbarItem *mLocationToolbarItem;
NSToolbarItem *mSidebarToolbarItem;
BOOL mInitialized;
NSURL* mURL;
CHBrowserWrapper* mBrowserView;
BOOL mMoveReentrant;
NSModalSession mModalSession;
BOOL mShouldAutosave;
BOOL mDrawerCachedFrame;
NSRect mCachedFrameBeforeDrawerOpen; // This is used by the drawer to figure out if the window should
// be returned to its original position when the drawer closes.
NSRect mCachedFrameAfterDrawerOpen;
int mChromeMask; // Indicates which parts of the window to show (e.g., don't show toolbars)
// Context menu members.
int mContextMenuFlags;
nsIDOMEvent* mContextMenuEvent;
nsIDOMNode* mContextMenuNode;
// Cached bookmark ds used when adding through a sheet
id mCachedBMDS;
}
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSURL*)aURL;
- (void)updateLocationFields:(NSString *)locationString;
- (void)updateToolbarItems;
- (void)focusURLBar;
- (void)performAppropriateLocationAction;
- (IBAction)goToLocationFromToolbarURLField:(id)sender;
- (void)focusURLBar;
- (void)beginLocationSheet;
- (IBAction)endLocationSheet:(id)sender;
- (IBAction)cancelAddBookmarkSheet:(id)sender;
- (IBAction)endAddBookmarkSheet:(id)sender;
- (void)cacheBookmarkDS: (id)aDS;
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
- (void)printDocument;
- (void)printPreview;
//- (BOOL)findInPage:(NSString*)text;
-(void) biggerTextSize;
-(void) smallerTextSize;
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder;
- (IBAction)manageBookmarks: (id)aSender;
- (IBAction)toggleSidebar:(id)aSender;
- (void)newTab;
- (void)closeTab;
- (void)previousTab;
- (void)nextTab;
- (IBAction)back:(id)aSender;
- (IBAction)forward:(id)aSender;
- (IBAction)reload:(id)aSender;
- (IBAction)stop:(id)aSender;
- (IBAction)home:(id)aSender;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;
-(void)disableAutosave;
-(void)setChromeMask:(int)aMask;
-(id)getAddBookmarkSheetWindow;
-(id)getAddBookmarkTitle;
-(id)getAddBookmarkFolder;
-(id)getAddBookmarkCheckbox;
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
- (NSMenu*)getContextMenu;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;
- (IBAction)saveImageAs:(id)aSender;
- (IBAction)viewOnlyThisImage:(id)aSender;
- (NSView*) bookmarksToolbar;
@end

Просмотреть файл

@ -0,0 +1,952 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIPrefBranch.h"
#include "nsIContextMenuListener.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsCocoaBrowserService.h"
#include "nsString.h"
#include "CHGeckoUtils.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item";
static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
@interface BrowserWindowController(Private)
- (void)setupToolbar;
- (void)setupSidebarTabs;
@end
@implementation BrowserWindowController
-(void)enterModalSession
{
mModalSession = [NSApp beginModalSessionForWindow: [self window]];
[NSApp runModalSession: mModalSession];
[NSApp endModalSession: mModalSession];
mModalSession = nil;
}
-(void)windowDidBecomeKey: (NSNotification*)aNotification
{
// May become necessary later.
}
-(void)windowDidResignKey: (NSNotification*)aNotification
{
// May be needed later.
}
-(void)mouseMoved:(NSEvent*)aEvent
{
if (mMoveReentrant)
return;
mMoveReentrant = YES;
NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
[view mouseMoved: aEvent];
[super mouseMoved: aEvent];
mMoveReentrant = NO;
}
- (id)initWithWindowNibName:(NSString *)windowNibName
{
if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
[self setShouldCascadeWindows:NO];
} else {
[self setShouldCascadeWindows:YES];
}
mInitialized = NO;
mMoveReentrant = NO;
mShouldAutosave = YES;
mChromeMask = 0;
mContextMenuFlags = 0;
mContextMenuEvent = nsnull;
mContextMenuNode = nsnull;
}
return self;
}
-(void)autosaveWindowFrame
{
if (mShouldAutosave)
[[self window] saveFrameUsingName: @"NavigatorWindow"];
}
-(void)disableAutosave
{
mShouldAutosave = NO;
}
- (void)windowWillClose:(NSNotification *)notification
{
printf("Window will close notification.\n");
[mSidebarBookmarksDataSource windowClosing];
[self autosaveWindowFrame];
[self autorelease];
}
- (void)dealloc
{
printf("Browser controller died.\n");
// Loop over all tabs, and tell them that the window is closed.
int numTabs = [mTabBrowser numberOfTabViewItems];
for (int i = 0; i < numTabs; i++) {
NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
[[item view] windowClosed];
}
[mSidebarBrowserView windowClosed];
[mProgress release];
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[[mURLBar cell] setImage: [NSImage imageNamed:@"smallbookmark"]];
// Get our saved dimensions.
[[self window] setFrameUsingName: @"NavigatorWindow"];
if (mModalSession)
[NSApp stopModal];
mInitialized = YES;
mDrawerCachedFrame = NO;
// Retain with a single extra refcount. This allows the CHBrowserWrappers
// to remove the progress meter from its superview without having to
// worry about retaining and releasing it.
[mProgress retain];
[[self window] setAcceptsMouseMovedEvents: YES];
[self setupToolbar];
// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was
// duplicating a lot of the code found here. I have moved it to that method.
// We now remove the IB tab, then add one of our own.
[mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
[self newTab];
if (mURL) {
[self loadURL: mURL];
[mURL release];
}
[mSidebarDrawer setDelegate: self];
[self setupSidebarTabs];
[mPersonalToolbar initializeToolbar];
}
- (void)drawerWillOpen: (NSNotification*)aNotification
{
[mSidebarBookmarksDataSource ensureBookmarks];
// Force the window to shrink and move if necessary in order to accommodate the sidebar.
NSRect screenFrame = [[[self window] screen] visibleFrame];
NSRect windowFrame = [[self window] frame];
NSSize drawerSize = [mSidebarDrawer contentSize];
int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
drawerSize.width += fudgeFactor;
if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
screenFrame.size.width) {
// We need to adjust the window so that it can fit.
float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
if (shrinkDelta < 0) shrinkDelta = 0;
float newWidth = (windowFrame.size.width - shrinkDelta);
float newPosition = screenFrame.size.width - newWidth - drawerSize.width;
if (newPosition < 0) newPosition = 0;
mCachedFrameBeforeDrawerOpen = windowFrame;
windowFrame.origin.x = newPosition;
windowFrame.size.width = newWidth;
mCachedFrameAfterDrawerOpen = windowFrame;
[[self window] setFrame: windowFrame display: YES];
mDrawerCachedFrame = YES;
}
}
- (void)drawerDidOpen:(NSNotification *)aNotification
{
// XXXdwh This is temporary.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
// Toggle the sidebar icon.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
}
- (void)drawerDidClose:(NSNotification *)aNotification
{
// Unload the Gecko web page in "My Panels" to save memory.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
// XXXdwh ignore for now.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
if (mDrawerCachedFrame) {
printf("Got here.\n");
mDrawerCachedFrame = NO;
NSRect frame = [[self window] frame];
if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
printf("Got here too.\n");
printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
// Restore the original frame.
[[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
}
}
}
- (void)setupToolbar
{
if (mChromeMask) {
printf("Uh-oh. %d\n", mChromeMask);
}
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
PrintToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Back"];
[toolbarItem setPaletteLabel:@"Go Back"];
[toolbarItem setToolTip:@"Go back one page"];
[toolbarItem setImage:[NSImage imageNamed:@"back"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(back:)];
} else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Forward"];
[toolbarItem setPaletteLabel:@"Go Forward"];
[toolbarItem setToolTip:@"Go forward one page"];
[toolbarItem setImage:[NSImage imageNamed:@"forward"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(forward:)];
} else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Reload"];
[toolbarItem setPaletteLabel:@"Reload Page"];
[toolbarItem setToolTip:@"Reload current page"];
[toolbarItem setImage:[NSImage imageNamed:@"reload"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(reload:)];
} else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Stop"];
[toolbarItem setPaletteLabel:@"Stop Loading"];
[toolbarItem setToolTip:@"Stop loading this page"];
[toolbarItem setImage:[NSImage imageNamed:@"stop"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(stop:)];
} else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Home"];
[toolbarItem setPaletteLabel:@"Go Home"];
[toolbarItem setToolTip:@"Go to home page"];
[toolbarItem setImage:[NSImage imageNamed:@"home"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(home:)];
} else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Sidebar"];
[toolbarItem setPaletteLabel:@"Toggle Sidebar"];
[toolbarItem setToolTip:@"Show or hide the Sidebar"];
[toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleSidebar:)];
mSidebarToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:@"Location"];
[toolbarItem setPaletteLabel:@"Location"];
[toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
[toolbarItem setView:mLocationToolbarView];
[toolbarItem setMinSize:NSMakeSize(128,32)];
[toolbarItem setMaxSize:NSMakeSize(2560,32)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(performAppropriateLocationAction)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
mLocationToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Print"];
[toolbarItem setPaletteLabel:@"Print"];
[toolbarItem setToolTip:@"Print this page"];
[toolbarItem setImage:[NSImage imageNamed:@"print"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(printDocument)];
} else {
toolbarItem = nil;
}
return toolbarItem;
}
// This method handles the enabling/disabling of the toolbar buttons.
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
// Check the action and see if it matches.
SEL action = [theItem action];
if (action == @selector(back:))
return [[mBrowserView getBrowserView] canGoBack];
else if (action == @selector(forward:))
return [[mBrowserView getBrowserView] canGoForward];
else if (action == @selector(reload:))
return [mBrowserView isBusy] == NO;
else if (action == @selector(stop:))
return [mBrowserView isBusy];
else
return YES;
}
- (void)updateToolbarItems
{
[[[self window] toolbar] validateVisibleItems];
}
- (void)performAppropriateLocationAction
{
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
[self focusURLBar];
} else {
[self beginLocationSheet];
}
} else {
[self beginLocationSheet];
}
}
- (void)focusURLBar
{
[mURLBar selectText: self];
}
- (void)beginLocationSheet
{
[NSApp beginSheet: mLocationSheetWindow
modalForWindow: [self window]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
- (IBAction)endLocationSheet:(id)sender
{
[mLocationSheetWindow orderOut:self];
[NSApp endSheet:mLocationSheetWindow returnCode:1];
[self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
-(IBAction)cancelAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 0];
}
-(IBAction)endAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 1];
}
- (void)cacheBookmarkDS: (id)aDS
{
mCachedBMDS = aDS;
}
-(IBAction)manageBookmarks: (id)aSender
{
if ([mSidebarDrawer state] == NSDrawerClosedState)
[self toggleSidebar: self];
[mSidebarTabView selectFirstTabViewItem:self];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender
{
[self loadURL:[NSURL URLWithString:[sender stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
{
[[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
}
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename
{
[[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList
url: aURL suggestedFilename: aFilename];
}
- (void)printDocument
{
[[mBrowserView getBrowserView] printDocument];
}
- (void)printPreview
{
[[mBrowserView getBrowserView] printPreview];
}
- (BOOL)findInPage:(NSString*)text
{
return [[mBrowserView getBrowserView] findInPage:text];
}
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder
{
[mSidebarBookmarksDataSource ensureBookmarks];
BOOL useSel = aIsFromMenu;
if (aIsFromMenu) {
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
if ([mSidebarDrawer state] == NSDrawerClosedState)
useSel = NO;
else
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
useSel = NO;
}
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder];
}
- (IBAction)back:(id)aSender
{
[[mBrowserView getBrowserView] goBack];
}
- (IBAction)forward:(id)aSender
{
[[mBrowserView getBrowserView] goForward];
}
- (IBAction)reload:(id)aSender
{
[[mBrowserView getBrowserView] reload: 0];
}
- (IBAction)stop:(id)aSender
{
[[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
}
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender
{
NSResponder* resp = [[self window] firstResponder];
[[self window] makeFirstResponder: nil];
if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
// XXXHack to bypass sidebar crashes.
[mSidebarDrawer openOnEdge: NSMaxXEdge];
} else {
[mSidebarDrawer close];
}
[[self window] makeFirstResponder: resp];
}
-(void)loadURL:(NSURL*)aURL
{
if (mInitialized) {
[[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
}
else {
mURL = aURL;
[mURL retain];
}
}
- (void)updateLocationFields:(NSString *)locationString
{
/* //commenting this out because it doesn't work right yet.
if ( [locationString length] > 30 ) {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
} else {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@", locationString]];
}
*/
[mURLBar setStringValue:locationString];
[mLocationSheetURLField setStringValue:locationString];
[[self window] update];
[[self window] display];
}
-(void)newTab
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newTab setLabel: @"Untitled"];
[newTab setView: newView];
[mTabBrowser addTabViewItem: newTab];
[[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[mTabBrowser selectLastTabViewItem: self];
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
if ([mTabBrowser numberOfTabViewItems] > 1) {
[self focusURLBar];
[[mBrowserView getBrowserView] setActive: NO];
}
else if ([[self window] isKeyWindow])
[[mBrowserView getBrowserView] setActive: YES];
else
[[mBrowserView getBrowserView] setActive: NO];
}
}
}
-(void)closeTab
{
if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
[[[mTabBrowser selectedTabViewItem] view] windowClosed];
[mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
}
}
- (void)previousTab
{
[mTabBrowser selectPreviousTabViewItem:self];
}
- (void)nextTab
{
[mTabBrowser selectNextTabViewItem:self];
}
- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
{
// Disconnect the old view, if one has been designated.
// If the window has just been opened, none has been.
if ( mBrowserView ) {
[mBrowserView disconnectView];
}
// Connect up the new view
mBrowserView = [aTabViewItem view];
// Make the new view the primary content area.
[mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
progress: mProgress windowController: self];
}
-(id)getTabBrowser
{
return mTabBrowser;
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
}
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
[mTabBrowser insertTabViewItem: newTab atIndex: index+1];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newView setTab: newTab];
[newTab setLabel: @"Loading..."];
[newTab setView: newView];
[[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
if (!aLoadInBG) {
[mTabBrowser selectTabViewItem: newTab];
// Focus the content area.
[[newView getBrowserView] setActive: YES];
}
}
-(void)setupSidebarTabs
{
CHIconTabViewItem *bookItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"bookicon"]];
CHIconTabViewItem *histItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"historySidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"historyicon"]];
CHIconTabViewItem *searchItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"searchSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"searchicon"]];
CHIconTabViewItem *panelsItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"myPanelsCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"panel_icon"]];
[bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
[histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
[searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
[mSidebarTabView insertTabViewItem:searchItem atIndex:2];
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
[mSidebarTabView selectFirstTabViewItem:self];
}
-(void)setChromeMask:(int)aMask
{
mChromeMask = aMask;
}
-(void) biggerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom >= 20)
return;
zoom += 0.25;
if (zoom > 20)
zoom = 20;
markupViewer->SetTextZoom(zoom);
}
-(void) smallerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom <= 0.01)
return;
zoom -= 0.25;
if (zoom < 0.01)
zoom = 0.01;
markupViewer->SetTextZoom(zoom);
}
-(id)getAddBookmarkSheetWindow
{
return mAddBookmarkSheetWindow;
}
-(id)getAddBookmarkTitle
{
return mAddBookmarkTitleField;
}
-(id)getAddBookmarkFolder
{
return mAddBookmarkFolderField;
}
-(id)getAddBookmarkCheckbox
{
return mAddBookmarkCheckbox;
}
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
{
mContextMenuFlags = flags;
mContextMenuNode = aNode;
mContextMenuEvent = aEvent;
}
- (NSMenu*)getContextMenu
{
NSMenu* result = nil;
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageLinkMenu;
}
else
result = mLinkMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
(mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
result = mInputMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
result = mPageMenu;
}
return result;
}
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender
{
[self openLinkInNewWindowOrTab: YES];
}
- (IBAction)openLinkInNewTab:(id)aSender
{
[self openLinkInNewWindowOrTab: NO];
}
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
if (aUseWindow)
[self openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
else
[self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
- (IBAction)savePageAs:(id)aSender
{
[self saveDocument: nil filterList: nil];
}
- (IBAction)saveLinkAs:(id)aSender
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
// The user wants to save this link.
nsAutoString text;
CHGeckoUtils::GatherTextUnder(mContextMenuNode, text);
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
- (IBAction)saveImageAs:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString text;
imgElement->GetAttribute(NS_LITERAL_STRING("src"), text);
nsAutoString url;
imgElement->GetSrc(url);
NSString* hrefStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
}
- (IBAction)viewOnlyThisImage:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString url;
imgElement->GetSrc(url);
NSString* urlStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToView = [NSURL URLWithString: urlStr];
[self loadURL: urlToView];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
}
- (NSView*) bookmarksToolbar
{
return mPersonalToolbar;
}
@end

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
#include "nsIWebBrowserFind.h"
@interface FindDlgController : NSWindowController {
IBOutlet id mSearchField;
IBOutlet id mIgnoreCaseBox;
IBOutlet id mWrapAroundBox;
IBOutlet id mSearchBackwardsBox;
IBOutlet id mFindButton;
NSString* mSearchText;
}
-(IBAction) find: (id)aSender;
-(IBAction) findAgain: (id)aSender;
// delegates for NSTextView
- (void)controlTextDidChange:(NSNotification *)aNotification;
@end

Просмотреть файл

@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "FindDlgController.h"
#import "BrowserWindowController.h"
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (void)windowDidLoad
{
}
//
// -find
//
// User clicked the find button, send the action to the window controller of the
// frontmost browser window. If we found something, hide the window. If not, beep.
//
-(IBAction) find: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
mSearchText = [mSearchField stringValue];
BOOL found = [browserController findInPage:mSearchText];
if ( found )
[self close];
else
NSBeep();
}
else
NSBeep();
}
//
// -findAgain
//
// Someone hit "find again" in the edit menu, send the action to the window controller of the
// frontmost browser window. Beep if we didn't find something.
//
-(IBAction) findAgain: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
BOOL found = [browserController findInPage:mSearchText];
if ( !found )
NSBeep();
}
else
NSBeep();
}
//
// controlTextDidChange
//
// Check if there is anything in the text field, and if not, disable the find button
//
- (void)controlTextDidChange:(NSNotification *)aNotification
{
if ( [[mSearchField stringValue] length] )
[mFindButton setEnabled:PR_TRUE];
else
[mFindButton setEnabled:PR_FALSE];
}
@end

118
chimera/MainController.h Normal file
Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "BrowserWindowController.h"
#import "MVPreferencesController.h"
#import "CHSplashScreenWindow.h"
#import "FindDlgController.h"
class BookmarksService;
@interface MainController : NSObject
{
IBOutlet id mApplication;
// The following two items are used by the filter list when saving files.
IBOutlet id mFilterView;
IBOutlet id mFilterList;
IBOutlet id mOfflineMenuItem;
// The bookmarks menu.
IBOutlet id mBookmarksMenu;
BOOL mOffline;
CHSplashScreenWindow *mSplashScreen;
BookmarksService *mMenuBookmarks;
FindDlgController* mFindDialog;
MVPreferencesController *preferencesController;
}
-(void)dealloc;
// File menu actions.
-(IBAction) newWindow:(id)aSender;
-(IBAction) openFile:(id)aSender;
-(IBAction) openLocation:(id)aSender;
-(IBAction) savePage:(id)aSender;
-(IBAction) printPreview:(id)aSender;
-(IBAction) printPage:(id)aSender;
-(IBAction) toggleOfflineMode:(id)aSender;
// Edit menu actions.
-(IBAction) findInPage:(id)aSender;
-(IBAction) findAgain:(id)aSender;
// Go menu actions.
-(IBAction) goBack:(id)aSender;
-(IBAction) goForward:(id)aSender;
-(IBAction) goHome:(id)aSender;
-(IBAction) previousTab:(id)aSender;
-(IBAction) nextTab:(id)aSender;
// View menu actions.
-(IBAction) doReload:(id)aSender;
-(IBAction) doStop:(id)aSender;
-(IBAction) biggerTextSize:(id)aSender;
-(IBAction) smallerTextSize:(id)aSender;
-(IBAction) toggleSmoothText:(id)aSender;
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender;
-(IBAction) openMenuBookmark:(id)aSender;
-(IBAction) manageBookmarks: (id)aSender;
-(IBAction) addFolder:(id)aSender;
-(IBAction) addSeparator:(id)aSender;
//Window menu actions
-(IBAction) newTab:(id)aSender;
-(IBAction) closeTab:(id)aSender;
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL;
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL;
- (MVPreferencesController *)preferencesController;
- (void)displayPreferencesWindow:sender;
- (IBAction)showAboutBox:(id)sender;
@end

375
chimera/MainController.mm Normal file
Просмотреть файл

@ -0,0 +1,375 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "MainController.h"
#import "BrowserWindowController.h"
#include "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsCocoaBrowserService.h"
#import "CHAboutBox.h"
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
@implementation MainController
-(id)init
{
if ( (self = [super init]) ) {
mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:YES withStatusRect:NSMakeRect(0,0,0,0)];
mFindDialog = nil;
mMenuBookmarks = nil;
}
return self;
}
-(void)dealloc
{
[super dealloc];
[mFindDialog release];
printf("Main controller died.\n");
}
-(void)awakeFromNib
{
[self newWindow: self];
[mSplashScreen close];
[mBookmarksMenu setAutoenablesItems: NO];
mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
mMenuBookmarks->AddObserver();
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
BookmarksService::gMainController = self;
// Initialize offline mode.
mOffline = NO;
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
mOffline = offline;
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
}
-(IBAction)newWindow:(id)aSender
{
// If we have a key window, have it autosave its dimensions before
// we open a new window. That ensures the size ends up matching.
NSWindow* mainWindow = [mApplication mainWindow];
if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
[controller focusURLBar];
}
-(IBAction)newTab:(id)aSender
{
[[[mApplication mainWindow] windowController] newTab];
}
-(IBAction)closeTab:(id)aSender
{
[[[mApplication mainWindow] windowController] closeTab];
}
-(IBAction) previousTab:(id)aSender
{
[[[mApplication mainWindow] windowController] previousTab];
}
-(IBAction) nextTab:(id)aSender;
{
[[[mApplication mainWindow] windowController] nextTab];
}
-(IBAction) openFile:(id)aSender
{
NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
[openPanel setCanChooseFiles: YES];
[openPanel setCanChooseDirectories: NO];
[openPanel setAllowsMultipleSelection: NO];
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
@"txt",@"text",
@"gif",@"jpg",@"jpeg",@"png",@"bmp",
nil];
int result = [openPanel runModalForTypes: array];
if (result == NSOKButton) {
NSArray* urlArray = [openPanel URLs];
if ([urlArray count] == 0)
return;
NSURL* url = [urlArray objectAtIndex: 0];
// ----------------------
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
// ----------------------
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL: url];
[[[[mainWindow windowController] getBrowserWrapper] getBrowserView] setActive: YES];
}
else
[self openBrowserWindowWithURL: url];
}
}
-(IBAction) openLocation:(id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] performAppropriateLocationAction];
}
-(IBAction) savePage:(id)aSender
{
[[[mApplication mainWindow] windowController] saveDocument: mFilterView filterList: mFilterList];
}
-(IBAction) printPage:(id)aSender
{
[[[mApplication mainWindow] windowController] printDocument];
}
-(IBAction) printPreview:(id)aSender
{
[[[mApplication mainWindow] windowController] printPreview];
}
-(IBAction) toggleOfflineMode:(id)aSender
{
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
ioService->SetOffline(!offline);
mOffline = !offline;
// Update the menu item text.
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
else
[mOfflineMenuItem setTitle: @"Work Offline"];
// Indicate that we are working offline.
[[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
}
// Edit menu actions.
//
// -findInPage
//
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep
// one around for the whole app to use, showing/hiding as we see fit.
//
-(IBAction) findInPage:(id)aSender
{
if ( !mFindDialog )
mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
[mFindDialog showWindow:self];
}
//
// -findAgain
//
// Called in response to "Find Again" in edit menu. Tells the find controller
// to find the next occurrance of what's already been found.
//
-(IBAction) findAgain:(id)aSender
{
if ( mFindDialog )
[mFindDialog findAgain:aSender];
else
NSBeep();
}
-(IBAction) goBack:(id)aSender
{
[[[mApplication mainWindow] windowController] back: aSender];
}
-(IBAction) goForward:(id)aSender
{
[[[mApplication mainWindow] windowController] forward: aSender];
}
-(IBAction) doReload:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) reload: aSender];
}
-(IBAction) doStop:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) stop: aSender];
}
-(IBAction) goHome:(id)aSender
{
[[[mApplication mainWindow] windowController] home: aSender];
}
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
{
return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
}
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
{
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
[browser showWindow: self];
return browser;
}
-(void)applicationWillTerminate: (NSNotification*)aNotification
{
printf("Termination notification.\n");
// Autosave one of the windows.
[[[mApplication mainWindow] windowController] autosaveWindowFrame];
mMenuBookmarks->RemoveObserver();
delete mMenuBookmarks;
mMenuBookmarks = nsnull;
nsCocoaBrowserService::TermEmbedding();
}
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO];
}
-(IBAction) addFolder:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES];
}
-(IBAction) addSeparator:(id)aSender
{
}
-(IBAction) openMenuBookmark:(id)aSender
{
NSWindow* mainWind = [mApplication mainWindow];
if (!mainWind) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWind = [mApplication mainWindow];
}
BookmarksService::OpenMenuBookmark([mainWind windowController], aSender);
}
-(IBAction)manageBookmarks: (id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] manageBookmarks: aSender];
}
- (MVPreferencesController *)preferencesController
{
if (!preferencesController) {
preferencesController = [[MVPreferencesController sharedInstance] retain];
}
return preferencesController;
}
- (void)displayPreferencesWindow:sender
{
[[self preferencesController] showPreferences:nil] ;
}
- (IBAction)showAboutBox:(id)sender
{
[[CHAboutBox sharedInstance] showPanel:sender];
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL:[NSURL fileURLWithPath:filename]];
} else {
[self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]];
}
return YES;
}
- (IBAction)biggerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] biggerTextSize];
}
- (IBAction)smallerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] smallerTextSize];
}
- (IBAction)toggleSmoothText:(id)aSender
{
// XXXdwh Grab the prefs service and just set the pref directly.
}
@end

Просмотреть файл

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
class nsIWebBrowserPersist;
class nsISupports;
class nsIInputStream;
class nsDownloadListener;
@interface ProgressDlgController : NSWindowController {
IBOutlet id mFromField;
IBOutlet id mToField;
IBOutlet id mStatusLabel;
IBOutlet id mTimeLeftLabel;
IBOutlet id mElapsedTimeLabel;
IBOutlet id mProgressBar;
IBOutlet id mKeepOpenCheckbox;
IBOutlet id mCancelButton;
IBOutlet id mPauseResumeButton;
IBOutlet id mLaunchButton;
IBOutlet id mRevealFolderButton;
BOOL mDownloadIsPaused;
BOOL mSaveFileDialogShouldStayOpen;
NSToolbarItem *pauseResumeToggleToolbarItem;
NSToolbarItem *leaveOpenToggleToolbarItem;
nsDownloadListener* mDownloadListener;
}
-(void) setWebPersist: (nsIWebBrowserPersist*)aPersist
source: (nsISupports*)aSource
destination: (NSString*)aDestination
contentType: (const char*)aContentType
postData: (nsIInputStream*)aInputStream
bypassCache: (BOOL)aBypassCache;
-(void) setSourceURL: (const char*)aSource;
-(void) setDestination: (const char*)aDestination;
@end

Просмотреть файл

@ -0,0 +1,446 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "ProgressDlgController.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIWebBrowserPersist.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsILocalFile.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIWebProgressListener.h"
#include "nsIComponentManager.h"
#include "nsIPrefBranch.h"
const char* prefContractID = "@mozilla.org/preferences-service;1";
class nsDownloadListener : public nsIWebProgressListener
{
public:
nsDownloadListener(ProgressDlgController* aController,
nsIWebBrowserPersist* aPersist,
nsISupports* aSource,
NSString* aDestination,
const char* aContentType,
nsIInputStream* aPostData,
BOOL aBypassCache)
{
NS_INIT_REFCNT();
mController = aController;
mWebPersist = aPersist;
// The source is either a simple URL or a complete document.
mURL = do_QueryInterface(aSource);
if (!mURL)
mDocument = do_QueryInterface(aSource);
nsCAutoString dstStr = [aDestination cString];
NS_NewLocalFile(dstStr.get(), PR_FALSE, getter_AddRefs(mDestination));
mContentType = aContentType;
mPostData = aPostData;
mBypassCache = aBypassCache;
};
virtual ~nsDownloadListener() {};
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
public:
void BeginDownload();
void InitDialog();
private: // Member variables
ProgressDlgController* mController; // Controller for our UI.
nsCOMPtr<nsIWebBrowserPersist> mWebPersist; // Our web persist object.
nsCOMPtr<nsIURL> mURL; // The URL of our source file. Null if we're saving a complete document.
nsCOMPtr<nsILocalFile> mDestination; // Our destination URL.
nsCString mContentType; // Our content type string.
nsCOMPtr<nsIDOMHTMLDocument> mDocument; // A DOM document. Null if we're only saving a simple URL.
nsCOMPtr<nsIInputStream> mPostData; // For complete documents, this is our post data from session history.
PRBool mBypassCache; // Whether we should bypass the cache or not.
};
NS_IMPL_ISUPPORTS1(nsDownloadListener, nsIWebProgressListener)
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP
nsDownloadListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsDownloadListener::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsDownloadListener::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsDownloadListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 state)
{
return NS_OK;
}
// Implementation of nsIWebProgressListener
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsDownloadListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
PRUint32 aStatus)
{
return NS_OK;
}
void
nsDownloadListener::BeginDownload()
{
if (mWebPersist) {
mWebPersist->SetProgressListener(this);
PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES;
if (mBypassCache)
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE;
else
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
if (mURL)
mWebPersist->SaveURI(mURL, mPostData, mDestination);
else {
PRInt32 encodingFlags = 0;
nsCOMPtr<nsILocalFile> filesFolder;
if (!mContentType.Equals("text/plain")) {
// Create a local directory in the same dir as our file. It
// will hold our associated files.
filesFolder = do_CreateInstance("@mozilla.org/file/local;1");
nsXPIDLString unicodePath;
mDestination->GetUnicodePath(getter_Copies(unicodePath));
filesFolder->InitWithUnicodePath(unicodePath.get());
nsXPIDLCString leafName;
filesFolder->GetLeafName(getter_Copies(leafName));
nsCAutoString nameMinusExt(leafName.get());
PRInt32 index = nameMinusExt.RFind(".");
if (index >= 0)
nameMinusExt.Left(nameMinusExt, index);
nameMinusExt += " Files"; // XXXdwh needs to be localizable!
filesFolder->SetLeafName(nameMinusExt.get());
PRBool exists = PR_FALSE;
filesFolder->Exists(&exists);
if (!exists)
filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
}
else
encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED |
nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS |
nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT;
mWebPersist->SaveDocument(mDocument, mDestination, filesFolder, mContentType.get(),
encodingFlags, 80);
}
}
InitDialog();
}
void
nsDownloadListener::InitDialog()
{
if (!mURL && !mDocument)
return;
if (mWebPersist) {
if (mURL) {
nsCAutoString spec;
mURL->GetSpec(spec);
[mController setSourceURL: spec.get()];
}
else {
nsAutoString spec;
mDocument->GetURL(spec);
nsCAutoString spec2; spec2.AssignWithConversion(spec);
[mController setSourceURL: spec2.get()];
}
}
nsXPIDLString path;
mDestination->GetUnicodePath(getter_Copies(path));
nsCAutoString pathStr; pathStr.AssignWithConversion(path.get());
[mController setDestination: pathStr.get()];
}
static NSString *SaveFileToolbarIdentifier = @"Save File Dialog Toolbar";
static NSString *CancelToolbarItemIdentifier = @"Cancel Toolbar Item";
static NSString *PauseResumeToolbarItemIdentifier = @"Pause and Resume Toggle Toolbar Item";
static NSString *ShowFileToolbarItemIdentifier = @"Show File Toolbar Item";
static NSString *OpenFileToolbarItemIdentifier = @"Open File Toolbar Item";
static NSString *LeaveOpenToolbarItemIdentifier = @"Leave Open Toggle Toolbar Item";
@interface ProgressDlgController(Private)
-(void)setupToolbar;
@end
@implementation ProgressDlgController
-(void)setWebPersist:(nsIWebBrowserPersist*)aPersist
source:(nsISupports*)aSource
destination:(NSString*)aDestination
contentType:(const char*)aContentType
postData:(nsIInputStream*)aInputStream
bypassCache:(BOOL)aBypassCache
{
mDownloadListener = new nsDownloadListener(self, aPersist, aSource,
aDestination, aContentType,
aInputStream, aBypassCache);
NS_ADDREF(mDownloadListener);
}
-(void) setSourceURL: (const char*)aSource
{
[mFromField setStringValue: [NSString stringWithCString: aSource]];
}
-(void) setDestination: (const char*)aDestination
{
[mToField setStringValue: [NSString stringWithCString: aDestination]];
}
- (void)windowDidLoad
{
mDownloadIsPaused = NO;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
PRBool save = PR_FALSE;
prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive",
&save);
mSaveFileDialogShouldStayOpen = save;
[self setupToolbar];
if (mDownloadListener)
mDownloadListener->BeginDownload();
}
- (void)setupToolbar
{
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Cancel"];
[toolbarItem setPaletteLabel:@"Cancel Download"];
[toolbarItem setToolTip:@"Cancel this file download"];
[toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(cancel)];
} else if ( [itemIdent isEqual:PauseResumeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Pause"];
[toolbarItem setPaletteLabel:@"Pause Download"];
[toolbarItem setToolTip:@"Pause this FTP file download"];
[toolbarItem setImage:[NSImage imageNamed:@"savePause"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(pauseAndResumeDownload)];
if ( willBeInserted ) {
pauseResumeToggleToolbarItem = toolbarItem; //establish reference
}
} else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Show File"];
[toolbarItem setPaletteLabel:@"Show File"];
[toolbarItem setToolTip:@"Show the saved file in the Finder"];
[toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(showFile)];
} else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Open File"];
[toolbarItem setPaletteLabel:@"Open File"];
[toolbarItem setToolTip:@"Open the saved file in its default application."];
[toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(openFile)];
} else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) {
if ( mSaveFileDialogShouldStayOpen ) {
[toolbarItem setLabel:@"Leave Open"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will stay open when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
} else {
[toolbarItem setLabel:@"Close When Done"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will close automatically when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
}
if ( willBeInserted ) {
leaveOpenToggleToolbarItem = toolbarItem; //establish reference
}
} else {
toolbarItem = nil;
}
return toolbarItem;
}
-(void)cancel
{
NSLog(@"Request to cancel download.");
}
-(void)pauseAndResumeDownload
{
if ( ! mDownloadIsPaused ) {
//Do logic to pause download
mDownloadIsPaused = YES;
[pauseResumeToggleToolbarItem setLabel:@"Resume"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Resume Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Resume the paused FTP download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"saveResume"]];
} else {
//Do logic to resume download
mDownloadIsPaused = NO;
[pauseResumeToggleToolbarItem setLabel:@"Pause"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Pause Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Pause this FTP file download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"savePause"]];
}
}
-(void)showFile
{
NSLog(@"Request to show file.");
}
-(void)openFile
{
NSLog(@"Request to open file.");
}
-(void)toggleLeaveOpen
{
if ( ! mSaveFileDialogShouldStayOpen ) {
mSaveFileDialogShouldStayOpen = YES;
[leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
} else {
mSaveFileDialogShouldStayOpen = NO;
[leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen);
}
- (void)windowWillClose:(NSNotification *)notification
{
[self autorelease];
}
- (void)dealloc
{
NS_IF_RELEASE(mDownloadListener);
[super dealloc];
}
@end

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "BrowserWindowController.h"
#import "MVPreferencesController.h"
#import "CHSplashScreenWindow.h"
#import "FindDlgController.h"
class BookmarksService;
@interface MainController : NSObject
{
IBOutlet id mApplication;
// The following two items are used by the filter list when saving files.
IBOutlet id mFilterView;
IBOutlet id mFilterList;
IBOutlet id mOfflineMenuItem;
// The bookmarks menu.
IBOutlet id mBookmarksMenu;
BOOL mOffline;
CHSplashScreenWindow *mSplashScreen;
BookmarksService *mMenuBookmarks;
FindDlgController* mFindDialog;
MVPreferencesController *preferencesController;
}
-(void)dealloc;
// File menu actions.
-(IBAction) newWindow:(id)aSender;
-(IBAction) openFile:(id)aSender;
-(IBAction) openLocation:(id)aSender;
-(IBAction) savePage:(id)aSender;
-(IBAction) printPreview:(id)aSender;
-(IBAction) printPage:(id)aSender;
-(IBAction) toggleOfflineMode:(id)aSender;
// Edit menu actions.
-(IBAction) findInPage:(id)aSender;
-(IBAction) findAgain:(id)aSender;
// Go menu actions.
-(IBAction) goBack:(id)aSender;
-(IBAction) goForward:(id)aSender;
-(IBAction) goHome:(id)aSender;
-(IBAction) previousTab:(id)aSender;
-(IBAction) nextTab:(id)aSender;
// View menu actions.
-(IBAction) doReload:(id)aSender;
-(IBAction) doStop:(id)aSender;
-(IBAction) biggerTextSize:(id)aSender;
-(IBAction) smallerTextSize:(id)aSender;
-(IBAction) toggleSmoothText:(id)aSender;
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender;
-(IBAction) openMenuBookmark:(id)aSender;
-(IBAction) manageBookmarks: (id)aSender;
-(IBAction) addFolder:(id)aSender;
-(IBAction) addSeparator:(id)aSender;
//Window menu actions
-(IBAction) newTab:(id)aSender;
-(IBAction) closeTab:(id)aSender;
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL;
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL;
- (MVPreferencesController *)preferencesController;
- (void)displayPreferencesWindow:sender;
- (IBAction)showAboutBox:(id)sender;
@end

Просмотреть файл

@ -0,0 +1,375 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "MainController.h"
#import "BrowserWindowController.h"
#include "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsCocoaBrowserService.h"
#import "CHAboutBox.h"
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
@implementation MainController
-(id)init
{
if ( (self = [super init]) ) {
mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:YES withStatusRect:NSMakeRect(0,0,0,0)];
mFindDialog = nil;
mMenuBookmarks = nil;
}
return self;
}
-(void)dealloc
{
[super dealloc];
[mFindDialog release];
printf("Main controller died.\n");
}
-(void)awakeFromNib
{
[self newWindow: self];
[mSplashScreen close];
[mBookmarksMenu setAutoenablesItems: NO];
mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
mMenuBookmarks->AddObserver();
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
BookmarksService::gMainController = self;
// Initialize offline mode.
mOffline = NO;
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
mOffline = offline;
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
}
-(IBAction)newWindow:(id)aSender
{
// If we have a key window, have it autosave its dimensions before
// we open a new window. That ensures the size ends up matching.
NSWindow* mainWindow = [mApplication mainWindow];
if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
[controller focusURLBar];
}
-(IBAction)newTab:(id)aSender
{
[[[mApplication mainWindow] windowController] newTab];
}
-(IBAction)closeTab:(id)aSender
{
[[[mApplication mainWindow] windowController] closeTab];
}
-(IBAction) previousTab:(id)aSender
{
[[[mApplication mainWindow] windowController] previousTab];
}
-(IBAction) nextTab:(id)aSender;
{
[[[mApplication mainWindow] windowController] nextTab];
}
-(IBAction) openFile:(id)aSender
{
NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
[openPanel setCanChooseFiles: YES];
[openPanel setCanChooseDirectories: NO];
[openPanel setAllowsMultipleSelection: NO];
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
@"txt",@"text",
@"gif",@"jpg",@"jpeg",@"png",@"bmp",
nil];
int result = [openPanel runModalForTypes: array];
if (result == NSOKButton) {
NSArray* urlArray = [openPanel URLs];
if ([urlArray count] == 0)
return;
NSURL* url = [urlArray objectAtIndex: 0];
// ----------------------
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
// ----------------------
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL: url];
[[[[mainWindow windowController] getBrowserWrapper] getBrowserView] setActive: YES];
}
else
[self openBrowserWindowWithURL: url];
}
}
-(IBAction) openLocation:(id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] performAppropriateLocationAction];
}
-(IBAction) savePage:(id)aSender
{
[[[mApplication mainWindow] windowController] saveDocument: mFilterView filterList: mFilterList];
}
-(IBAction) printPage:(id)aSender
{
[[[mApplication mainWindow] windowController] printDocument];
}
-(IBAction) printPreview:(id)aSender
{
[[[mApplication mainWindow] windowController] printPreview];
}
-(IBAction) toggleOfflineMode:(id)aSender
{
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
if (!ioService)
return;
PRBool offline = PR_FALSE;
ioService->GetOffline(&offline);
ioService->SetOffline(!offline);
mOffline = !offline;
// Update the menu item text.
// Set the menu item's text to "Go Online" if we're currently
// offline.
if (mOffline)
[mOfflineMenuItem setTitle: @"Go Online"];
else
[mOfflineMenuItem setTitle: @"Work Offline"];
// Indicate that we are working offline.
[[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
}
// Edit menu actions.
//
// -findInPage
//
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep
// one around for the whole app to use, showing/hiding as we see fit.
//
-(IBAction) findInPage:(id)aSender
{
if ( !mFindDialog )
mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
[mFindDialog showWindow:self];
}
//
// -findAgain
//
// Called in response to "Find Again" in edit menu. Tells the find controller
// to find the next occurrance of what's already been found.
//
-(IBAction) findAgain:(id)aSender
{
if ( mFindDialog )
[mFindDialog findAgain:aSender];
else
NSBeep();
}
-(IBAction) goBack:(id)aSender
{
[[[mApplication mainWindow] windowController] back: aSender];
}
-(IBAction) goForward:(id)aSender
{
[[[mApplication mainWindow] windowController] forward: aSender];
}
-(IBAction) doReload:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) reload: aSender];
}
-(IBAction) doStop:(id)aSender
{
[(BrowserWindowController*)([[mApplication mainWindow] windowController]) stop: aSender];
}
-(IBAction) goHome:(id)aSender
{
[[[mApplication mainWindow] windowController] home: aSender];
}
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
{
return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
}
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
{
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
[browser showWindow: self];
return browser;
}
-(void)applicationWillTerminate: (NSNotification*)aNotification
{
printf("Termination notification.\n");
// Autosave one of the windows.
[[[mApplication mainWindow] windowController] autosaveWindowFrame];
mMenuBookmarks->RemoveObserver();
delete mMenuBookmarks;
mMenuBookmarks = nsnull;
nsCocoaBrowserService::TermEmbedding();
}
// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO];
}
-(IBAction) addFolder:(id)aSender
{
[[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES];
}
-(IBAction) addSeparator:(id)aSender
{
}
-(IBAction) openMenuBookmark:(id)aSender
{
NSWindow* mainWind = [mApplication mainWindow];
if (!mainWind) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWind = [mApplication mainWindow];
}
BookmarksService::OpenMenuBookmark([mainWind windowController], aSender);
}
-(IBAction)manageBookmarks: (id)aSender
{
NSWindow* mainWindow = [mApplication mainWindow];
if (!mainWindow) {
[self openBrowserWindowWithURLString: @"about:blank"];
mainWindow = [mApplication mainWindow];
}
[[mainWindow windowController] manageBookmarks: aSender];
}
- (MVPreferencesController *)preferencesController
{
if (!preferencesController) {
preferencesController = [[MVPreferencesController sharedInstance] retain];
}
return preferencesController;
}
- (void)displayPreferencesWindow:sender
{
[[self preferencesController] showPreferences:nil] ;
}
- (IBAction)showAboutBox:(id)sender
{
[[CHAboutBox sharedInstance] showPanel:sender];
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
NSWindow* mainWindow = [mApplication mainWindow];
if (mainWindow) {
[[mainWindow windowController] loadURL:[NSURL fileURLWithPath:filename]];
} else {
[self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]];
}
return YES;
}
- (IBAction)biggerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] biggerTextSize];
}
- (IBAction)smallerTextSize:(id)aSender
{
[[[mApplication mainWindow] windowController] smallerTextSize];
}
- (IBAction)toggleSmoothText:(id)aSender
{
// XXXdwh Grab the prefs service and just set the pref directly.
}
@end

Просмотреть файл

@ -0,0 +1,183 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <Cocoa/Cocoa.h>
#import "CHBrowserWrapper.h"
#import "CHFind.h"
#import "CHBookmarksToolbar.h"
class nsIDOMEvent;
class nsIDOMNode;
@interface BrowserWindowController : NSWindowController<CHFind>
{
IBOutlet id mTabBrowser;
IBOutlet NSDrawer* mSidebarDrawer;
IBOutlet id mSidebarTabView;
IBOutlet id mSidebarSourceTabView;
IBOutlet id mLocationToolbarView;
IBOutlet id mURLBar;
IBOutlet id mStatus;
IBOutlet id mProgress;
IBOutlet id mLocationSheetWindow;
IBOutlet id mLocationSheetURLField;
IBOutlet id mSidebarBrowserView;
IBOutlet id mSidebarBookmarksDataSource;
IBOutlet CHBookmarksToolbar* mPersonalToolbar;
IBOutlet id mAddBookmarkSheetWindow;
IBOutlet id mAddBookmarkTitleField;
IBOutlet id mAddBookmarkFolderField;
IBOutlet id mAddBookmarkCheckbox;
// Context menu outlets.
IBOutlet id mPageMenu;
IBOutlet id mImageMenu;
IBOutlet id mInputMenu;
IBOutlet id mLinkMenu;
IBOutlet id mImageLinkMenu;
NSToolbarItem *mLocationToolbarItem;
NSToolbarItem *mSidebarToolbarItem;
BOOL mInitialized;
NSURL* mURL;
CHBrowserWrapper* mBrowserView;
BOOL mMoveReentrant;
NSModalSession mModalSession;
BOOL mShouldAutosave;
BOOL mDrawerCachedFrame;
NSRect mCachedFrameBeforeDrawerOpen; // This is used by the drawer to figure out if the window should
// be returned to its original position when the drawer closes.
NSRect mCachedFrameAfterDrawerOpen;
int mChromeMask; // Indicates which parts of the window to show (e.g., don't show toolbars)
// Context menu members.
int mContextMenuFlags;
nsIDOMEvent* mContextMenuEvent;
nsIDOMNode* mContextMenuNode;
// Cached bookmark ds used when adding through a sheet
id mCachedBMDS;
}
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSURL*)aURL;
- (void)updateLocationFields:(NSString *)locationString;
- (void)updateToolbarItems;
- (void)focusURLBar;
- (void)performAppropriateLocationAction;
- (IBAction)goToLocationFromToolbarURLField:(id)sender;
- (void)focusURLBar;
- (void)beginLocationSheet;
- (IBAction)endLocationSheet:(id)sender;
- (IBAction)cancelAddBookmarkSheet:(id)sender;
- (IBAction)endAddBookmarkSheet:(id)sender;
- (void)cacheBookmarkDS: (id)aDS;
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
- (void)printDocument;
- (void)printPreview;
//- (BOOL)findInPage:(NSString*)text;
-(void) biggerTextSize;
-(void) smallerTextSize;
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder;
- (IBAction)manageBookmarks: (id)aSender;
- (IBAction)toggleSidebar:(id)aSender;
- (void)newTab;
- (void)closeTab;
- (void)previousTab;
- (void)nextTab;
- (IBAction)back:(id)aSender;
- (IBAction)forward:(id)aSender;
- (IBAction)reload:(id)aSender;
- (IBAction)stop:(id)aSender;
- (IBAction)home:(id)aSender;
-(void)enterModalSession;
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG;
-(void)autosaveWindowFrame;
-(void)disableAutosave;
-(void)setChromeMask:(int)aMask;
-(id)getAddBookmarkSheetWindow;
-(id)getAddBookmarkTitle;
-(id)getAddBookmarkFolder;
-(id)getAddBookmarkCheckbox;
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
- (NSMenu*)getContextMenu;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;
- (IBAction)saveImageAs:(id)aSender;
- (IBAction)viewOnlyThisImage:(id)aSender;
- (NSView*) bookmarksToolbar;
@end

Просмотреть файл

@ -0,0 +1,952 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIPrefBranch.h"
#include "nsIContextMenuListener.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsCocoaBrowserService.h"
#include "nsString.h"
#include "CHGeckoUtils.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item";
static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
@interface BrowserWindowController(Private)
- (void)setupToolbar;
- (void)setupSidebarTabs;
@end
@implementation BrowserWindowController
-(void)enterModalSession
{
mModalSession = [NSApp beginModalSessionForWindow: [self window]];
[NSApp runModalSession: mModalSession];
[NSApp endModalSession: mModalSession];
mModalSession = nil;
}
-(void)windowDidBecomeKey: (NSNotification*)aNotification
{
// May become necessary later.
}
-(void)windowDidResignKey: (NSNotification*)aNotification
{
// May be needed later.
}
-(void)mouseMoved:(NSEvent*)aEvent
{
if (mMoveReentrant)
return;
mMoveReentrant = YES;
NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
[view mouseMoved: aEvent];
[super mouseMoved: aEvent];
mMoveReentrant = NO;
}
- (id)initWithWindowNibName:(NSString *)windowNibName
{
if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
[self setShouldCascadeWindows:NO];
} else {
[self setShouldCascadeWindows:YES];
}
mInitialized = NO;
mMoveReentrant = NO;
mShouldAutosave = YES;
mChromeMask = 0;
mContextMenuFlags = 0;
mContextMenuEvent = nsnull;
mContextMenuNode = nsnull;
}
return self;
}
-(void)autosaveWindowFrame
{
if (mShouldAutosave)
[[self window] saveFrameUsingName: @"NavigatorWindow"];
}
-(void)disableAutosave
{
mShouldAutosave = NO;
}
- (void)windowWillClose:(NSNotification *)notification
{
printf("Window will close notification.\n");
[mSidebarBookmarksDataSource windowClosing];
[self autosaveWindowFrame];
[self autorelease];
}
- (void)dealloc
{
printf("Browser controller died.\n");
// Loop over all tabs, and tell them that the window is closed.
int numTabs = [mTabBrowser numberOfTabViewItems];
for (int i = 0; i < numTabs; i++) {
NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
[[item view] windowClosed];
}
[mSidebarBrowserView windowClosed];
[mProgress release];
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[[mURLBar cell] setImage: [NSImage imageNamed:@"smallbookmark"]];
// Get our saved dimensions.
[[self window] setFrameUsingName: @"NavigatorWindow"];
if (mModalSession)
[NSApp stopModal];
mInitialized = YES;
mDrawerCachedFrame = NO;
// Retain with a single extra refcount. This allows the CHBrowserWrappers
// to remove the progress meter from its superview without having to
// worry about retaining and releasing it.
[mProgress retain];
[[self window] setAcceptsMouseMovedEvents: YES];
[self setupToolbar];
// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was
// duplicating a lot of the code found here. I have moved it to that method.
// We now remove the IB tab, then add one of our own.
[mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
[self newTab];
if (mURL) {
[self loadURL: mURL];
[mURL release];
}
[mSidebarDrawer setDelegate: self];
[self setupSidebarTabs];
[mPersonalToolbar initializeToolbar];
}
- (void)drawerWillOpen: (NSNotification*)aNotification
{
[mSidebarBookmarksDataSource ensureBookmarks];
// Force the window to shrink and move if necessary in order to accommodate the sidebar.
NSRect screenFrame = [[[self window] screen] visibleFrame];
NSRect windowFrame = [[self window] frame];
NSSize drawerSize = [mSidebarDrawer contentSize];
int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
drawerSize.width += fudgeFactor;
if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
screenFrame.size.width) {
// We need to adjust the window so that it can fit.
float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
if (shrinkDelta < 0) shrinkDelta = 0;
float newWidth = (windowFrame.size.width - shrinkDelta);
float newPosition = screenFrame.size.width - newWidth - drawerSize.width;
if (newPosition < 0) newPosition = 0;
mCachedFrameBeforeDrawerOpen = windowFrame;
windowFrame.origin.x = newPosition;
windowFrame.size.width = newWidth;
mCachedFrameAfterDrawerOpen = windowFrame;
[[self window] setFrame: windowFrame display: YES];
mDrawerCachedFrame = YES;
}
}
- (void)drawerDidOpen:(NSNotification *)aNotification
{
// XXXdwh This is temporary.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
// Toggle the sidebar icon.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
}
- (void)drawerDidClose:(NSNotification *)aNotification
{
// Unload the Gecko web page in "My Panels" to save memory.
[mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
// XXXdwh ignore for now.
// [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
if (mDrawerCachedFrame) {
printf("Got here.\n");
mDrawerCachedFrame = NO;
NSRect frame = [[self window] frame];
if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
printf("Got here too.\n");
printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
// Restore the original frame.
[[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
}
}
}
- (void)setupToolbar
{
if (mChromeMask) {
printf("Uh-oh. %d\n", mChromeMask);
}
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
PrintToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
ForwardToolbarItemIdentifier,
ReloadToolbarItemIdentifier,
StopToolbarItemIdentifier,
HomeToolbarItemIdentifier,
LocationToolbarItemIdentifier,
SidebarToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Back"];
[toolbarItem setPaletteLabel:@"Go Back"];
[toolbarItem setToolTip:@"Go back one page"];
[toolbarItem setImage:[NSImage imageNamed:@"back"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(back:)];
} else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Forward"];
[toolbarItem setPaletteLabel:@"Go Forward"];
[toolbarItem setToolTip:@"Go forward one page"];
[toolbarItem setImage:[NSImage imageNamed:@"forward"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(forward:)];
} else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Reload"];
[toolbarItem setPaletteLabel:@"Reload Page"];
[toolbarItem setToolTip:@"Reload current page"];
[toolbarItem setImage:[NSImage imageNamed:@"reload"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(reload:)];
} else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Stop"];
[toolbarItem setPaletteLabel:@"Stop Loading"];
[toolbarItem setToolTip:@"Stop loading this page"];
[toolbarItem setImage:[NSImage imageNamed:@"stop"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(stop:)];
} else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Home"];
[toolbarItem setPaletteLabel:@"Go Home"];
[toolbarItem setToolTip:@"Go to home page"];
[toolbarItem setImage:[NSImage imageNamed:@"home"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(home:)];
} else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Sidebar"];
[toolbarItem setPaletteLabel:@"Toggle Sidebar"];
[toolbarItem setToolTip:@"Show or hide the Sidebar"];
[toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleSidebar:)];
mSidebarToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[toolbarItem setLabel:@"Location"];
[toolbarItem setPaletteLabel:@"Location"];
[toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
[toolbarItem setView:mLocationToolbarView];
[toolbarItem setMinSize:NSMakeSize(128,32)];
[toolbarItem setMaxSize:NSMakeSize(2560,32)];
[menuFormRep setTarget:self];
[menuFormRep setAction:@selector(performAppropriateLocationAction)];
[menuFormRep setTitle:[toolbarItem label]];
[toolbarItem setMenuFormRepresentation:menuFormRep];
mLocationToolbarItem = toolbarItem;
} else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Print"];
[toolbarItem setPaletteLabel:@"Print"];
[toolbarItem setToolTip:@"Print this page"];
[toolbarItem setImage:[NSImage imageNamed:@"print"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(printDocument)];
} else {
toolbarItem = nil;
}
return toolbarItem;
}
// This method handles the enabling/disabling of the toolbar buttons.
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
// Check the action and see if it matches.
SEL action = [theItem action];
if (action == @selector(back:))
return [[mBrowserView getBrowserView] canGoBack];
else if (action == @selector(forward:))
return [[mBrowserView getBrowserView] canGoForward];
else if (action == @selector(reload:))
return [mBrowserView isBusy] == NO;
else if (action == @selector(stop:))
return [mBrowserView isBusy];
else
return YES;
}
- (void)updateToolbarItems
{
[[[self window] toolbar] validateVisibleItems];
}
- (void)performAppropriateLocationAction
{
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
[self focusURLBar];
} else {
[self beginLocationSheet];
}
} else {
[self beginLocationSheet];
}
}
- (void)focusURLBar
{
[mURLBar selectText: self];
}
- (void)beginLocationSheet
{
[NSApp beginSheet: mLocationSheetWindow
modalForWindow: [self window]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
- (IBAction)endLocationSheet:(id)sender
{
[mLocationSheetWindow orderOut:self];
[NSApp endSheet:mLocationSheetWindow returnCode:1];
[self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
-(IBAction)cancelAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 0];
}
-(IBAction)endAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMDS endAddBookmark: 1];
}
- (void)cacheBookmarkDS: (id)aDS
{
mCachedBMDS = aDS;
}
-(IBAction)manageBookmarks: (id)aSender
{
if ([mSidebarDrawer state] == NSDrawerClosedState)
[self toggleSidebar: self];
[mSidebarTabView selectFirstTabViewItem:self];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender
{
[self loadURL:[NSURL URLWithString:[sender stringValue]]];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
{
[[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
}
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename
{
[[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList
url: aURL suggestedFilename: aFilename];
}
- (void)printDocument
{
[[mBrowserView getBrowserView] printDocument];
}
- (void)printPreview
{
[[mBrowserView getBrowserView] printPreview];
}
- (BOOL)findInPage:(NSString*)text
{
return [[mBrowserView getBrowserView] findInPage:text];
}
- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder
{
[mSidebarBookmarksDataSource ensureBookmarks];
BOOL useSel = aIsFromMenu;
if (aIsFromMenu) {
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
if ([mSidebarDrawer state] == NSDrawerClosedState)
useSel = NO;
else
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
useSel = NO;
}
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder];
}
- (IBAction)back:(id)aSender
{
[[mBrowserView getBrowserView] goBack];
}
- (IBAction)forward:(id)aSender
{
[[mBrowserView getBrowserView] goForward];
}
- (IBAction)reload:(id)aSender
{
[[mBrowserView getBrowserView] reload: 0];
}
- (IBAction)stop:(id)aSender
{
[[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
}
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender
{
NSResponder* resp = [[self window] firstResponder];
[[self window] makeFirstResponder: nil];
if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
// XXXHack to bypass sidebar crashes.
[mSidebarDrawer openOnEdge: NSMaxXEdge];
} else {
[mSidebarDrawer close];
}
[[self window] makeFirstResponder: resp];
}
-(void)loadURL:(NSURL*)aURL
{
if (mInitialized) {
[[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
}
else {
mURL = aURL;
[mURL retain];
}
}
- (void)updateLocationFields:(NSString *)locationString
{
/* //commenting this out because it doesn't work right yet.
if ( [locationString length] > 30 ) {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
} else {
[[mLocationToolbarItem menuFormRepresentation] setTitle:
[NSString stringWithFormat:@"Location: %@", locationString]];
}
*/
[mURLBar setStringValue:locationString];
[mLocationSheetURLField setStringValue:locationString];
[[self window] update];
[[self window] display];
}
-(void)newTab
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newTab setLabel: @"Untitled"];
[newTab setView: newView];
[mTabBrowser addTabViewItem: newTab];
[[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[mTabBrowser selectLastTabViewItem: self];
if ( [[[self window] toolbar] isVisible] ) {
if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
if ([mTabBrowser numberOfTabViewItems] > 1) {
[self focusURLBar];
[[mBrowserView getBrowserView] setActive: NO];
}
else if ([[self window] isKeyWindow])
[[mBrowserView getBrowserView] setActive: YES];
else
[[mBrowserView getBrowserView] setActive: NO];
}
}
}
-(void)closeTab
{
if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
[[[mTabBrowser selectedTabViewItem] view] windowClosed];
[mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
}
}
- (void)previousTab
{
[mTabBrowser selectPreviousTabViewItem:self];
}
- (void)nextTab
{
[mTabBrowser selectNextTabViewItem:self];
}
- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
{
// Disconnect the old view, if one has been designated.
// If the window has just been opened, none has been.
if ( mBrowserView ) {
[mBrowserView disconnectView];
}
// Connect up the new view
mBrowserView = [aTabViewItem view];
// Make the new view the primary content area.
[mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
progress: mProgress windowController: self];
}
-(id)getTabBrowser
{
return mTabBrowser;
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
}
-(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
// Autosave our dimensions before we open a new window. That ensures the size ends up matching.
[self autosaveWindowFrame];
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
[browser loadURL: aURL];
if (aLoadInBG)
[[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
else {
// Focus the content area and show the window.
[browser enterModalSession];
[[[browser getBrowserWrapper] getBrowserView] setActive: YES];
}
}
-(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
[mTabBrowser insertTabViewItem: newTab atIndex: index+1];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
[newView setTab: newTab];
[newTab setLabel: @"Loading..."];
[newTab setView: newView];
[[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
if (!aLoadInBG) {
[mTabBrowser selectTabViewItem: newTab];
// Focus the content area.
[[newView getBrowserView] setActive: YES];
}
}
-(void)setupSidebarTabs
{
CHIconTabViewItem *bookItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"bookicon"]];
CHIconTabViewItem *histItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"historySidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"historyicon"]];
CHIconTabViewItem *searchItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"searchSidebarCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"searchicon"]];
CHIconTabViewItem *panelsItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"myPanelsCHIconTabViewItem"
withTabIcon:[NSImage imageNamed:@"panel_icon"]];
[bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
[histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
[searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
[mSidebarTabView insertTabViewItem:searchItem atIndex:2];
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
[mSidebarTabView selectFirstTabViewItem:self];
}
-(void)setChromeMask:(int)aMask
{
mChromeMask = aMask;
}
-(void) biggerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom >= 20)
return;
zoom += 0.25;
if (zoom > 20)
zoom = 20;
markupViewer->SetTextZoom(zoom);
}
-(void) smallerTextSize
{
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
if (!global)
return;
nsCOMPtr<nsIDocShell> docShell;
global->GetDocShell(getter_AddRefs(docShell));
if (!docShell)
return;
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
if (!markupViewer)
return;
float zoom;
markupViewer->GetTextZoom(&zoom);
if (zoom <= 0.01)
return;
zoom -= 0.25;
if (zoom < 0.01)
zoom = 0.01;
markupViewer->SetTextZoom(zoom);
}
-(id)getAddBookmarkSheetWindow
{
return mAddBookmarkSheetWindow;
}
-(id)getAddBookmarkTitle
{
return mAddBookmarkTitleField;
}
-(id)getAddBookmarkFolder
{
return mAddBookmarkFolderField;
}
-(id)getAddBookmarkCheckbox
{
return mAddBookmarkCheckbox;
}
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
{
mContextMenuFlags = flags;
mContextMenuNode = aNode;
mContextMenuEvent = aEvent;
}
- (NSMenu*)getContextMenu
{
NSMenu* result = nil;
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageLinkMenu;
}
else
result = mLinkMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
(mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
result = mInputMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
result = mImageMenu;
}
else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
result = mPageMenu;
}
return result;
}
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender
{
[self openLinkInNewWindowOrTab: YES];
}
- (IBAction)openLinkInNewTab:(id)aSender
{
[self openLinkInNewWindowOrTab: NO];
}
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
if (aUseWindow)
[self openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
else
[self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
- (IBAction)savePageAs:(id)aSender
{
[self saveDocument: nil filterList: nil];
}
- (IBAction)saveLinkAs:(id)aSender
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
// XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
// really uses these anyway? :)
if (!linkContent || href.IsEmpty())
return;
NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
// The user wants to save this link.
nsAutoString text;
CHGeckoUtils::GatherTextUnder(mContextMenuNode, text);
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
- (IBAction)saveImageAs:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString text;
imgElement->GetAttribute(NS_LITERAL_STRING("src"), text);
nsAutoString url;
imgElement->GetSrc(url);
NSString* hrefStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToSave = [NSURL URLWithString: hrefStr];
[self saveURL: nil filterList: nil
url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
length:nsCRT::strlen(text.get())]];
}
}
- (IBAction)viewOnlyThisImage:(id)aSender
{
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
if (imgElement) {
nsAutoString url;
imgElement->GetSrc(url);
NSString* urlStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
NSURL* urlToView = [NSURL URLWithString: urlStr];
[self loadURL: urlToView];
// Focus and activate our content area.
[[mBrowserView getBrowserView] setActive: YES];
}
}
- (NSView*) bookmarksToolbar
{
return mPersonalToolbar;
}
@end

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
class nsIWebBrowserPersist;
class nsISupports;
class nsIInputStream;
class nsDownloadListener;
@interface ProgressDlgController : NSWindowController {
IBOutlet id mFromField;
IBOutlet id mToField;
IBOutlet id mStatusLabel;
IBOutlet id mTimeLeftLabel;
IBOutlet id mElapsedTimeLabel;
IBOutlet id mProgressBar;
IBOutlet id mKeepOpenCheckbox;
IBOutlet id mCancelButton;
IBOutlet id mPauseResumeButton;
IBOutlet id mLaunchButton;
IBOutlet id mRevealFolderButton;
BOOL mDownloadIsPaused;
BOOL mSaveFileDialogShouldStayOpen;
NSToolbarItem *pauseResumeToggleToolbarItem;
NSToolbarItem *leaveOpenToggleToolbarItem;
nsDownloadListener* mDownloadListener;
}
-(void) setWebPersist: (nsIWebBrowserPersist*)aPersist
source: (nsISupports*)aSource
destination: (NSString*)aDestination
contentType: (const char*)aContentType
postData: (nsIInputStream*)aInputStream
bypassCache: (BOOL)aBypassCache;
-(void) setSourceURL: (const char*)aSource;
-(void) setDestination: (const char*)aDestination;
@end

Просмотреть файл

@ -0,0 +1,446 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "ProgressDlgController.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIWebBrowserPersist.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsILocalFile.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIWebProgressListener.h"
#include "nsIComponentManager.h"
#include "nsIPrefBranch.h"
const char* prefContractID = "@mozilla.org/preferences-service;1";
class nsDownloadListener : public nsIWebProgressListener
{
public:
nsDownloadListener(ProgressDlgController* aController,
nsIWebBrowserPersist* aPersist,
nsISupports* aSource,
NSString* aDestination,
const char* aContentType,
nsIInputStream* aPostData,
BOOL aBypassCache)
{
NS_INIT_REFCNT();
mController = aController;
mWebPersist = aPersist;
// The source is either a simple URL or a complete document.
mURL = do_QueryInterface(aSource);
if (!mURL)
mDocument = do_QueryInterface(aSource);
nsCAutoString dstStr = [aDestination cString];
NS_NewLocalFile(dstStr.get(), PR_FALSE, getter_AddRefs(mDestination));
mContentType = aContentType;
mPostData = aPostData;
mBypassCache = aBypassCache;
};
virtual ~nsDownloadListener() {};
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
public:
void BeginDownload();
void InitDialog();
private: // Member variables
ProgressDlgController* mController; // Controller for our UI.
nsCOMPtr<nsIWebBrowserPersist> mWebPersist; // Our web persist object.
nsCOMPtr<nsIURL> mURL; // The URL of our source file. Null if we're saving a complete document.
nsCOMPtr<nsILocalFile> mDestination; // Our destination URL.
nsCString mContentType; // Our content type string.
nsCOMPtr<nsIDOMHTMLDocument> mDocument; // A DOM document. Null if we're only saving a simple URL.
nsCOMPtr<nsIInputStream> mPostData; // For complete documents, this is our post data from session history.
PRBool mBypassCache; // Whether we should bypass the cache or not.
};
NS_IMPL_ISUPPORTS1(nsDownloadListener, nsIWebProgressListener)
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP
nsDownloadListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsDownloadListener::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsDownloadListener::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsDownloadListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 state)
{
return NS_OK;
}
// Implementation of nsIWebProgressListener
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsDownloadListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
PRUint32 aStatus)
{
return NS_OK;
}
void
nsDownloadListener::BeginDownload()
{
if (mWebPersist) {
mWebPersist->SetProgressListener(this);
PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES;
if (mBypassCache)
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE;
else
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
if (mURL)
mWebPersist->SaveURI(mURL, mPostData, mDestination);
else {
PRInt32 encodingFlags = 0;
nsCOMPtr<nsILocalFile> filesFolder;
if (!mContentType.Equals("text/plain")) {
// Create a local directory in the same dir as our file. It
// will hold our associated files.
filesFolder = do_CreateInstance("@mozilla.org/file/local;1");
nsXPIDLString unicodePath;
mDestination->GetUnicodePath(getter_Copies(unicodePath));
filesFolder->InitWithUnicodePath(unicodePath.get());
nsXPIDLCString leafName;
filesFolder->GetLeafName(getter_Copies(leafName));
nsCAutoString nameMinusExt(leafName.get());
PRInt32 index = nameMinusExt.RFind(".");
if (index >= 0)
nameMinusExt.Left(nameMinusExt, index);
nameMinusExt += " Files"; // XXXdwh needs to be localizable!
filesFolder->SetLeafName(nameMinusExt.get());
PRBool exists = PR_FALSE;
filesFolder->Exists(&exists);
if (!exists)
filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
}
else
encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED |
nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS |
nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT;
mWebPersist->SaveDocument(mDocument, mDestination, filesFolder, mContentType.get(),
encodingFlags, 80);
}
}
InitDialog();
}
void
nsDownloadListener::InitDialog()
{
if (!mURL && !mDocument)
return;
if (mWebPersist) {
if (mURL) {
nsCAutoString spec;
mURL->GetSpec(spec);
[mController setSourceURL: spec.get()];
}
else {
nsAutoString spec;
mDocument->GetURL(spec);
nsCAutoString spec2; spec2.AssignWithConversion(spec);
[mController setSourceURL: spec2.get()];
}
}
nsXPIDLString path;
mDestination->GetUnicodePath(getter_Copies(path));
nsCAutoString pathStr; pathStr.AssignWithConversion(path.get());
[mController setDestination: pathStr.get()];
}
static NSString *SaveFileToolbarIdentifier = @"Save File Dialog Toolbar";
static NSString *CancelToolbarItemIdentifier = @"Cancel Toolbar Item";
static NSString *PauseResumeToolbarItemIdentifier = @"Pause and Resume Toggle Toolbar Item";
static NSString *ShowFileToolbarItemIdentifier = @"Show File Toolbar Item";
static NSString *OpenFileToolbarItemIdentifier = @"Open File Toolbar Item";
static NSString *LeaveOpenToolbarItemIdentifier = @"Leave Open Toggle Toolbar Item";
@interface ProgressDlgController(Private)
-(void)setupToolbar;
@end
@implementation ProgressDlgController
-(void)setWebPersist:(nsIWebBrowserPersist*)aPersist
source:(nsISupports*)aSource
destination:(NSString*)aDestination
contentType:(const char*)aContentType
postData:(nsIInputStream*)aInputStream
bypassCache:(BOOL)aBypassCache
{
mDownloadListener = new nsDownloadListener(self, aPersist, aSource,
aDestination, aContentType,
aInputStream, aBypassCache);
NS_ADDREF(mDownloadListener);
}
-(void) setSourceURL: (const char*)aSource
{
[mFromField setStringValue: [NSString stringWithCString: aSource]];
}
-(void) setDestination: (const char*)aDestination
{
[mToField setStringValue: [NSString stringWithCString: aDestination]];
}
- (void)windowDidLoad
{
mDownloadIsPaused = NO;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
PRBool save = PR_FALSE;
prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive",
&save);
mSaveFileDialogShouldStayOpen = save;
[self setupToolbar];
if (mDownloadListener)
mDownloadListener->BeginDownload();
}
- (void)setupToolbar
{
NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease];
[toolbar setDisplayMode:NSToolbarDisplayModeDefault];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects: CancelToolbarItemIdentifier,
PauseResumeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
LeaveOpenToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
ShowFileToolbarItemIdentifier,
OpenFileToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdent
willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Cancel"];
[toolbarItem setPaletteLabel:@"Cancel Download"];
[toolbarItem setToolTip:@"Cancel this file download"];
[toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(cancel)];
} else if ( [itemIdent isEqual:PauseResumeToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Pause"];
[toolbarItem setPaletteLabel:@"Pause Download"];
[toolbarItem setToolTip:@"Pause this FTP file download"];
[toolbarItem setImage:[NSImage imageNamed:@"savePause"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(pauseAndResumeDownload)];
if ( willBeInserted ) {
pauseResumeToggleToolbarItem = toolbarItem; //establish reference
}
} else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Show File"];
[toolbarItem setPaletteLabel:@"Show File"];
[toolbarItem setToolTip:@"Show the saved file in the Finder"];
[toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(showFile)];
} else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) {
[toolbarItem setLabel:@"Open File"];
[toolbarItem setPaletteLabel:@"Open File"];
[toolbarItem setToolTip:@"Open the saved file in its default application."];
[toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(openFile)];
} else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) {
if ( mSaveFileDialogShouldStayOpen ) {
[toolbarItem setLabel:@"Leave Open"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will stay open when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
} else {
[toolbarItem setLabel:@"Close When Done"];
[toolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[toolbarItem setToolTip:@"Window will close automatically when download finishes."];
[toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(toggleLeaveOpen)];
}
if ( willBeInserted ) {
leaveOpenToggleToolbarItem = toolbarItem; //establish reference
}
} else {
toolbarItem = nil;
}
return toolbarItem;
}
-(void)cancel
{
NSLog(@"Request to cancel download.");
}
-(void)pauseAndResumeDownload
{
if ( ! mDownloadIsPaused ) {
//Do logic to pause download
mDownloadIsPaused = YES;
[pauseResumeToggleToolbarItem setLabel:@"Resume"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Resume Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Resume the paused FTP download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"saveResume"]];
} else {
//Do logic to resume download
mDownloadIsPaused = NO;
[pauseResumeToggleToolbarItem setLabel:@"Pause"];
[pauseResumeToggleToolbarItem setPaletteLabel:@"Pause Download"];
[pauseResumeToggleToolbarItem setToolTip:@"Pause this FTP file download"];
[pauseResumeToggleToolbarItem setImage:[NSImage imageNamed:@"savePause"]];
}
}
-(void)showFile
{
NSLog(@"Request to show file.");
}
-(void)openFile
{
NSLog(@"Request to open file.");
}
-(void)toggleLeaveOpen
{
if ( ! mSaveFileDialogShouldStayOpen ) {
mSaveFileDialogShouldStayOpen = YES;
[leaveOpenToggleToolbarItem setLabel:@"Leave Open"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will stay open when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]];
} else {
mSaveFileDialogShouldStayOpen = NO;
[leaveOpenToggleToolbarItem setLabel:@"Close When Done"];
[leaveOpenToggleToolbarItem setPaletteLabel:@"Toggle Close Behavior"];
[leaveOpenToggleToolbarItem setToolTip:@"Window will close automatically when download finishes."];
[leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]];
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen);
}
- (void)windowWillClose:(NSNotification *)notification
{
[self autorelease];
}
- (void)dealloc
{
NS_IF_RELEASE(mDownloadListener);
[super dealloc];
}
@end

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 <AppKit/AppKit.h>
#include "nsIWebBrowserFind.h"
@interface FindDlgController : NSWindowController {
IBOutlet id mSearchField;
IBOutlet id mIgnoreCaseBox;
IBOutlet id mWrapAroundBox;
IBOutlet id mSearchBackwardsBox;
IBOutlet id mFindButton;
NSString* mSearchText;
}
-(IBAction) find: (id)aSender;
-(IBAction) findAgain: (id)aSender;
// delegates for NSTextView
- (void)controlTextDidChange:(NSNotification *)aNotification;
@end

Просмотреть файл

@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 "FindDlgController.h"
#import "BrowserWindowController.h"
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (void)windowDidLoad
{
}
//
// -find
//
// User clicked the find button, send the action to the window controller of the
// frontmost browser window. If we found something, hide the window. If not, beep.
//
-(IBAction) find: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
mSearchText = [mSearchField stringValue];
BOOL found = [browserController findInPage:mSearchText];
if ( found )
[self close];
else
NSBeep();
}
else
NSBeep();
}
//
// -findAgain
//
// Someone hit "find again" in the edit menu, send the action to the window controller of the
// frontmost browser window. Beep if we didn't find something.
//
-(IBAction) findAgain: (id)aSender
{
NSWindowController* controller = [[NSApp mainWindow] windowController];
if ( [controller conformsToProtocol:@protocol(CHFind)] ) {
id<CHFind> browserController = controller;
BOOL found = [browserController findInPage:mSearchText];
if ( !found )
NSBeep();
}
else
NSBeep();
}
//
// controlTextDidChange
//
// Check if there is anything in the text field, and if not, disable the find button
//
- (void)controlTextDidChange:(NSNotification *)aNotification
{
if ( [[mSearchField stringValue] length] )
[mFindButton setEnabled:PR_TRUE];
else
[mFindButton setEnabled:PR_FALSE];
}
@end