Fix for bug 156607 (performance slow with large numbers of tabs open). These changes make all the tabs the same width, and put a cap of 16 on the number of tabs per browser window. When at this limit, commands that would open a new tab (e.g. view source) now open a new window. 'New tab' menu items should disable appropriately.

This commit is contained in:
sfraser%netscape.com 2002-08-06 01:53:37 +00:00
parent a997dfd839
commit 39fd231516
54 changed files with 1326 additions and 282 deletions

View File

@ -836,7 +836,7 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
return isBookmark && [mBrowserWindowController newTabsAllowed];
}
return YES;
}

View File

@ -41,7 +41,7 @@
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#import "CHIconTabViewItem.h"
#import "StringUtils.h"
#include "nsCRT.h"
@ -1021,10 +1021,12 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
elt->GetAttribute(NS_LITERAL_STRING("href"), href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWith_nsAString: href];
NSTabViewItem* tabViewItem = nil;
CHIconTabViewItem* tabViewItem = nil;
if (currentIndex >= total) {
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
// XXX this needs fixing to not max out the number of tabs in a browser window.
// See [BrowserWindowController newTabsAllowed];
tabViewItem = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease];
[tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")];
[tabViewItem setView: newView];

View File

@ -153,8 +153,9 @@ class nsIDOMNode;
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (id)getTabBrowser;
- (BOOL)newTabsAllowed;
- (CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate;
- (void)updateLocationFields:(NSString *)locationString;
@ -235,7 +236,7 @@ class nsIDOMNode;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;

View File

@ -90,6 +90,7 @@ static NSString *NavigatorWindowFrameSaveName = @"NavigatorWindow";
// hardcoded defaults.
static NSArray* sToolbarDefaults = nil;
#define kMaxBrowserWindowTabs 16
@interface BrowserWindowController(Private)
- (void)setupToolbar;
@ -290,6 +291,9 @@ static NSArray* sToolbarDefaults = nil;
[self setupToolbar];
// set an upper limit on the number of tabs per window
[mTabBrowser setMaxNumberOfTabs: kMaxBrowserWindowTabs];
// 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.
@ -758,7 +762,11 @@ static NSArray* sToolbarDefaults = nil;
PRBool loadInBackground;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
if (![self newTabsAllowed])
[self openNewWindowWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
else
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
}
- (IBAction)printDocument:(id)aSender
@ -962,7 +970,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)newTab:(BOOL)allowHomepage
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
PRInt32 newTabPage = 0;
@ -1040,6 +1048,11 @@ static NSArray* sToolbarDefaults = nil;
return mTabBrowser;
}
- (BOOL)newTabsAllowed
{
return [mTabBrowser canMakeNewTabs];
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
@ -1076,7 +1089,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)openNewTabWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
@ -1305,7 +1318,7 @@ static NSArray* sToolbarDefaults = nil;
NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString];
if (aUseWindow)
if (aUseWindow || ![self newTabsAllowed])
[self openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[self openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -70,7 +70,8 @@
NSString* url = [NSString stringWith_nsAString: href];
// Now load the URL in the window.
[[[self window] windowController] loadURL: url referrer:nil activate:YES];
BrowserWindowController* brController = [[self window] windowController];
[brController loadURL: url referrer:nil activate:YES];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
@ -87,7 +88,8 @@
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[[[self window] windowController] openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
BrowserWindowController* brController = [[self window] windowController];
[brController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
@ -106,10 +108,12 @@
nsAutoString group;
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
BrowserWindowController* brController = [[self window] windowController];
if (group.IsEmpty())
[[[self window] windowController] openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
[brController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
else
[[[self window] windowController] openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
[brController openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
}
-(IBAction)showBookmarkInfo:(id)aSender
@ -174,7 +178,8 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
BrowserWindowController* brController = [[self window] windowController];
return isBookmark && [brController newTabsAllowed];
}
return YES;
}

View File

@ -22,6 +22,7 @@
@interface CHExtendedTabView : NSTabView
{
BOOL autoHides;
int maxNumberOfTabs; // 0 means 'no max'
}
// Behavior: Autohiding overrides the default tab visibility state.
@ -30,6 +31,10 @@
- (BOOL)autoHides;
- (void)setAutoHides:(BOOL)newSetting;
-(void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer;
- (int)maxNumberOfTabs;
- (void)setMaxNumberOfTabs:(int)maxTabs;
- (BOOL)canMakeNewTabs;
- (void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer;
@end

View File

@ -1,23 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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 Mozilla 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/MPL/
* 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.
* 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 the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
* 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):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
*
* 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 "NSString+Utils.h"
#import "CHExtendedTabView.h"
#import "CHIconTabViewItem.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
@ -52,6 +75,7 @@
{
if ( (self = [super initWithFrame:frameRect]) ) {
autoHides = YES;
maxNumberOfTabs = 0; // no max
}
return self;
}
@ -108,6 +132,20 @@
autoHides = newSetting;
}
- (int)maxNumberOfTabs
{
return maxNumberOfTabs;
}
- (void)setMaxNumberOfTabs:(int)maxTabs
{
maxNumberOfTabs = maxTabs;
}
- (BOOL)canMakeNewTabs
{
return maxNumberOfTabs == 0 || [self numberOfTabViewItems] < maxNumberOfTabs;
}
/******************************************/
/*** Instance Methods ***/
@ -140,19 +178,37 @@
[[overTabViewItem view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO];
} else if (overContentArea) {
[[[self selectedTabViewItem] view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO];
} else
} else if ([self canMakeNewTabs]) {
[self addTabForURL:url referrer:nil];
} else {
NSLog(@"Can't make new tab for drop");
}
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint];
BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]);
if (!overTabViewItem && !overContentArea && ![self canMakeNewTabs])
return NSDragOperationNone;
return NSDragOperationGeneric;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint];
BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]);
if (!overTabViewItem && !overContentArea && ![self canMakeNewTabs])
return NSDragOperationNone;
return NSDragOperationGeneric;
}
@ -225,12 +281,9 @@
-(void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer
{
NSTabViewItem* tabViewItem;
CHBrowserWrapper* newView;
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease];
CHIconTabViewItem *tabViewItem= [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper *newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease];
[tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")];
[tabViewItem setView: newView];
[self addTabViewItem: tabViewItem];
@ -239,3 +292,7 @@
}
@end

View File

@ -1,25 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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 Mozilla 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/MPL/
* 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.
* 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 the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Matt Judy. Portions
* of code @2002 nibfile.com.
*/
* 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.
* Portions are Copyright (C) 2002 nibfile.com
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
*
* 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>
@interface CHIconTabViewItem : NSTabViewItem {
NSImage *_tabIcon;
NSImage *mTabIcon;
NSDictionary* mLabelAttributes;
}
// The designated initializer

View File

@ -1,40 +0,0 @@
//
// IconTabViewItem.m
// Chimera
//
// Created by Matt L. Judy on Sun Mar 10 2002.
// Copyright (c) 2001 __MyCompanyName__. All rights reserved.
//
#import "CHIconTabViewItem.h"
@implementation CHIconTabViewItem
-(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon
{
if ( (self = [super initWithIdentifier:identifier]) ) {
[self setTabIcon:tabIcon];
}
return self;
}
- (NSSize)sizeOfLabel:(BOOL)computeMin
{
return( NSMakeSize(15,15) );
}
-(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15) );
[[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver];
}
-(NSImage *)tabIcon { return _tabIcon; }
-(void)setTabIcon:(NSImage *)newIcon
{
[_tabIcon autorelease];
_tabIcon = [newIcon copy];
}
@end

192
camino/CHIconTabViewItem.mm Normal file
View File

@ -0,0 +1,192 @@
/* -*- 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.
* Portions are Copyright (C) 2002 nibfile.com.
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
* Simon Fraser <sfraser@netscape.com>
*
* 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 "CHIconTabViewItem.h"
//
// NSParagraphStyle has a line break mode which will automatically
// append ellipses to the end of a string. Unfortunately, as of
// OS X 10.1.5, the header says it doesn't work yet.
//
#define BROKEN_NSLineBreakByTruncatingMiddle
static const int kMinTabsForSpacing = 4; // with 1-4 tabs, each tab is 1/4 the tab view width
static const int kEllipseSpaces = 4; //yes, i know it's 3 ...'s
@interface CHIconTabViewItem(Private)
- (void)setupLabelAttributes;
@end;
@implementation CHIconTabViewItem
-(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon
{
if ( (self = [super initWithIdentifier:identifier]) ) {
[self setTabIcon:tabIcon];
[self setupLabelAttributes];
}
return self;
}
-(id)initWithIdentifier:(id)identifier
{
return [self initWithIdentifier:identifier withTabIcon:nil];
}
-(void)dealloc
{
[mTabIcon release];
[mLabelAttributes release];
[super dealloc];
}
- (void)setupLabelAttributes
{
NSMutableParagraphStyle *labelParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[labelParagraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
[labelParagraphStyle setLineBreakMode:NSLineBreakByClipping];
#else
[labelParagraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle];
#endif
[labelParagraphStyle setAlignment:NSCenterTextAlignment];
NSFont *labelFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
mLabelAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
labelFont, NSFontAttributeName,
labelParagraphStyle, NSParagraphStyleAttributeName,
nil];
[labelParagraphStyle release];
}
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{
int numTabs;
float theWidth = 0;
//if we've got text, size for # of tabs & amount of text.
// Accounts for icon size, if one present.
if ([[self label] length] > 0) {
numTabs = [[self tabView] numberOfTabViewItems];
if (numTabs < kMinTabsForSpacing)
numTabs = kMinTabsForSpacing;
theWidth = NSWidth([[self tabView] frame]) / numTabs - 16.0; // 16 works - don't know why. Maybe 8px on each side of the label?
if (shouldTruncateLabel) {
//I have really no clue what this is for.
//it only gets set YES when the tabs have
//reached the edge of the screen area.
//I don't see any difference in behavior between putting
//in -10 or -600 here. But -1 instead of -10 makes the
//tabs go off screen.
theWidth -= 16.0;
}
}
// If we don't have text, but DO have an icon, we'll have size 15.
else if ([self tabIcon])
theWidth = 15.0;
return NSMakeSize(theWidth, 15.0); // ugh, hard-coded height.
// This doesn't seem to affect, the height, only the rect pass to
// drawLabel.
}
-(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
if ([self tabIcon]) {
NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15.0) );
[[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver];
tabRect = NSMakeRect(NSMinX(tabRect)+15.0,
NSMinY(tabRect),
NSWidth(tabRect)-15.0,
NSHeight(tabRect));
}
NSMutableAttributedString* labelString = [[NSMutableAttributedString alloc] initWithString:[self label] attributes:mLabelAttributes];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
//
// ****************************************************************
// Beginning of LineBreakByTruncatingTail workaround code.
// When it starts working, this can be removed.
// ****************************************************************
//
NSSize stringSize = [labelString size];
if (stringSize.width > NSWidth(tabRect))
{
int labelLength = [[labelString string] length];
float spacePerChar = stringSize.width/labelLength;
int allowableCharacters = floor(NSWidth(tabRect)/spacePerChar) - kEllipseSpaces;
if (allowableCharacters < labelLength)
{
if (allowableCharacters < 0)
allowableCharacters = 0;
[labelString replaceCharactersInRange:NSMakeRange(allowableCharacters, labelLength - allowableCharacters) withString:[NSString ellipsisString]];
}
}
//
// ****************************************************************
// End of LineBreakByTruncatingTail workaround code.
// ****************************************************************
//
#endif
[labelString drawInRect:tabRect];
[labelString release];
}
-(NSImage *)tabIcon
{
return mTabIcon;
}
-(void)setTabIcon:(NSImage *)newIcon
{
[mTabIcon autorelease];
mTabIcon = [newIcon copy];
}
@end

View File

@ -3157,7 +3157,7 @@
};
F564873A023C3857010001CA = {
isa = PBXFileReference;
path = CHIconTabViewItem.m;
path = CHIconTabViewItem.mm;
refType = 4;
};
F564873B023C3857010001CA = {

View File

@ -306,7 +306,7 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
if (shiftKey)
loadInBackground = !loadInBackground;
if (useTab)
if (useTab && [mBrowserController newTabsAllowed])
[mBrowserController openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[mBrowserController openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -438,11 +438,8 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// reuse the main window if there is one. The user may have closed all of
// them or we may get this event at startup before we've had time to load
// our window.
BrowserWindowController* controller = NULL;
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
if (reuseWindow && browserWindow) {
controller = [browserWindow windowController];
BrowserWindowController* controller = [self getMainWindowBrowserController];
if (reuseWindow && controller && [controller canMakeNewTabs]) {
[controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground];
}
else {
@ -669,11 +666,10 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
//NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
if (action == @selector(newTab:) ||
if (action == @selector(printPage:) ||
/* ... many more items go here ... */
/* action == @selector(goHome:) || */ // always enabled
/* action == @selector(doSearch:) || */ // always enabled
action == @selector(printPage:) ||
action == @selector(findInPage:) ||
action == @selector(doReload:) ||
action == @selector(biggerTextSize:) ||
@ -685,6 +681,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
return NO;
}
if (action == @selector(newTab:)) {
if (browserController && [browserController newTabsAllowed])
return YES;
return NO;
}
// check if someone has previously done a find before allowing findAgain to be enabled
if (action == @selector(findAgain:)) {
if (browserController)

View File

@ -51,6 +51,7 @@ typedef enum
// a category to extend NSString
@interface NSString (ChimeraStringUtils)
+ (id)ellipsisString;
+ (id)stringWithPRUnichars:(const PRUnichar*)inString;
+ (id)stringWith_nsAString:(const nsAString&)inString;
- (void)assignTo_nsAString:(nsAString&)ioString;

View File

@ -44,6 +44,18 @@
@implementation NSString (ChimeraStringUtils)
+ (id)ellipsisString
{
static NSString* sEllipsisString = nil;
if (!sEllipsisString)
{
unichar ellipsisChar = 0x2026;
sEllipsisString = [[[NSString alloc] initWithCharacters:&ellipsisChar length:1] retain];
}
return sEllipsisString;
}
+ (id)stringWithPRUnichars:(const PRUnichar*)inString
{
if (inString)
@ -119,8 +131,7 @@
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
{
unichar ellipsisChar = 0x2026;
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
NSString* ellipsisString = [NSString ellipsisString];
if ([self length] > maxCharacters)
{

View File

@ -3157,7 +3157,7 @@
};
F564873A023C3857010001CA = {
isa = PBXFileReference;
path = CHIconTabViewItem.m;
path = CHIconTabViewItem.mm;
refType = 4;
};
F564873B023C3857010001CA = {

View File

@ -438,11 +438,8 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// reuse the main window if there is one. The user may have closed all of
// them or we may get this event at startup before we've had time to load
// our window.
BrowserWindowController* controller = NULL;
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
if (reuseWindow && browserWindow) {
controller = [browserWindow windowController];
BrowserWindowController* controller = [self getMainWindowBrowserController];
if (reuseWindow && controller && [controller canMakeNewTabs]) {
[controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground];
}
else {
@ -669,11 +666,10 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
//NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
if (action == @selector(newTab:) ||
if (action == @selector(printPage:) ||
/* ... many more items go here ... */
/* action == @selector(goHome:) || */ // always enabled
/* action == @selector(doSearch:) || */ // always enabled
action == @selector(printPage:) ||
action == @selector(findInPage:) ||
action == @selector(doReload:) ||
action == @selector(biggerTextSize:) ||
@ -685,6 +681,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
return NO;
}
if (action == @selector(newTab:)) {
if (browserController && [browserController newTabsAllowed])
return YES;
return NO;
}
// check if someone has previously done a find before allowing findAgain to be enabled
if (action == @selector(findAgain:)) {
if (browserController)

View File

@ -70,7 +70,8 @@
NSString* url = [NSString stringWith_nsAString: href];
// Now load the URL in the window.
[[[self window] windowController] loadURL: url referrer:nil activate:YES];
BrowserWindowController* brController = [[self window] windowController];
[brController loadURL: url referrer:nil activate:YES];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
@ -87,7 +88,8 @@
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[[[self window] windowController] openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
BrowserWindowController* brController = [[self window] windowController];
[brController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
@ -106,10 +108,12 @@
nsAutoString group;
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
BrowserWindowController* brController = [[self window] windowController];
if (group.IsEmpty())
[[[self window] windowController] openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
[brController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
else
[[[self window] windowController] openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
[brController openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
}
-(IBAction)showBookmarkInfo:(id)aSender
@ -174,7 +178,8 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
BrowserWindowController* brController = [[self window] windowController];
return isBookmark && [brController newTabsAllowed];
}
return YES;
}

View File

@ -836,7 +836,7 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
return isBookmark && [mBrowserWindowController newTabsAllowed];
}
return YES;
}

View File

@ -41,7 +41,7 @@
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#import "CHIconTabViewItem.h"
#import "StringUtils.h"
#include "nsCRT.h"
@ -1021,10 +1021,12 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
elt->GetAttribute(NS_LITERAL_STRING("href"), href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWith_nsAString: href];
NSTabViewItem* tabViewItem = nil;
CHIconTabViewItem* tabViewItem = nil;
if (currentIndex >= total) {
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
// XXX this needs fixing to not max out the number of tabs in a browser window.
// See [BrowserWindowController newTabsAllowed];
tabViewItem = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease];
[tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")];
[tabViewItem setView: newView];

View File

@ -153,8 +153,9 @@ class nsIDOMNode;
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (id)getTabBrowser;
- (BOOL)newTabsAllowed;
- (CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate;
- (void)updateLocationFields:(NSString *)locationString;
@ -235,7 +236,7 @@ class nsIDOMNode;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;

View File

@ -90,6 +90,7 @@ static NSString *NavigatorWindowFrameSaveName = @"NavigatorWindow";
// hardcoded defaults.
static NSArray* sToolbarDefaults = nil;
#define kMaxBrowserWindowTabs 16
@interface BrowserWindowController(Private)
- (void)setupToolbar;
@ -290,6 +291,9 @@ static NSArray* sToolbarDefaults = nil;
[self setupToolbar];
// set an upper limit on the number of tabs per window
[mTabBrowser setMaxNumberOfTabs: kMaxBrowserWindowTabs];
// 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.
@ -758,7 +762,11 @@ static NSArray* sToolbarDefaults = nil;
PRBool loadInBackground;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
if (![self newTabsAllowed])
[self openNewWindowWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
else
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
}
- (IBAction)printDocument:(id)aSender
@ -962,7 +970,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)newTab:(BOOL)allowHomepage
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
PRInt32 newTabPage = 0;
@ -1040,6 +1048,11 @@ static NSArray* sToolbarDefaults = nil;
return mTabBrowser;
}
- (BOOL)newTabsAllowed
{
return [mTabBrowser canMakeNewTabs];
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
@ -1076,7 +1089,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)openNewTabWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
@ -1305,7 +1318,7 @@ static NSArray* sToolbarDefaults = nil;
NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString];
if (aUseWindow)
if (aUseWindow || ![self newTabsAllowed])
[self openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[self openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -306,7 +306,7 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
if (shiftKey)
loadInBackground = !loadInBackground;
if (useTab)
if (useTab && [mBrowserController newTabsAllowed])
[mBrowserController openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[mBrowserController openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -1,25 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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 Mozilla 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/MPL/
* 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.
* 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 the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Matt Judy. Portions
* of code @2002 nibfile.com.
*/
* 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.
* Portions are Copyright (C) 2002 nibfile.com
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
*
* 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>
@interface CHIconTabViewItem : NSTabViewItem {
NSImage *_tabIcon;
NSImage *mTabIcon;
NSDictionary* mLabelAttributes;
}
// The designated initializer

View File

@ -0,0 +1,192 @@
/* -*- 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.
* Portions are Copyright (C) 2002 nibfile.com.
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
* Simon Fraser <sfraser@netscape.com>
*
* 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 "CHIconTabViewItem.h"
//
// NSParagraphStyle has a line break mode which will automatically
// append ellipses to the end of a string. Unfortunately, as of
// OS X 10.1.5, the header says it doesn't work yet.
//
#define BROKEN_NSLineBreakByTruncatingMiddle
static const int kMinTabsForSpacing = 4; // with 1-4 tabs, each tab is 1/4 the tab view width
static const int kEllipseSpaces = 4; //yes, i know it's 3 ...'s
@interface CHIconTabViewItem(Private)
- (void)setupLabelAttributes;
@end;
@implementation CHIconTabViewItem
-(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon
{
if ( (self = [super initWithIdentifier:identifier]) ) {
[self setTabIcon:tabIcon];
[self setupLabelAttributes];
}
return self;
}
-(id)initWithIdentifier:(id)identifier
{
return [self initWithIdentifier:identifier withTabIcon:nil];
}
-(void)dealloc
{
[mTabIcon release];
[mLabelAttributes release];
[super dealloc];
}
- (void)setupLabelAttributes
{
NSMutableParagraphStyle *labelParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[labelParagraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
[labelParagraphStyle setLineBreakMode:NSLineBreakByClipping];
#else
[labelParagraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle];
#endif
[labelParagraphStyle setAlignment:NSCenterTextAlignment];
NSFont *labelFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
mLabelAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
labelFont, NSFontAttributeName,
labelParagraphStyle, NSParagraphStyleAttributeName,
nil];
[labelParagraphStyle release];
}
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{
int numTabs;
float theWidth = 0;
//if we've got text, size for # of tabs & amount of text.
// Accounts for icon size, if one present.
if ([[self label] length] > 0) {
numTabs = [[self tabView] numberOfTabViewItems];
if (numTabs < kMinTabsForSpacing)
numTabs = kMinTabsForSpacing;
theWidth = NSWidth([[self tabView] frame]) / numTabs - 16.0; // 16 works - don't know why. Maybe 8px on each side of the label?
if (shouldTruncateLabel) {
//I have really no clue what this is for.
//it only gets set YES when the tabs have
//reached the edge of the screen area.
//I don't see any difference in behavior between putting
//in -10 or -600 here. But -1 instead of -10 makes the
//tabs go off screen.
theWidth -= 16.0;
}
}
// If we don't have text, but DO have an icon, we'll have size 15.
else if ([self tabIcon])
theWidth = 15.0;
return NSMakeSize(theWidth, 15.0); // ugh, hard-coded height.
// This doesn't seem to affect, the height, only the rect pass to
// drawLabel.
}
-(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
if ([self tabIcon]) {
NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15.0) );
[[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver];
tabRect = NSMakeRect(NSMinX(tabRect)+15.0,
NSMinY(tabRect),
NSWidth(tabRect)-15.0,
NSHeight(tabRect));
}
NSMutableAttributedString* labelString = [[NSMutableAttributedString alloc] initWithString:[self label] attributes:mLabelAttributes];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
//
// ****************************************************************
// Beginning of LineBreakByTruncatingTail workaround code.
// When it starts working, this can be removed.
// ****************************************************************
//
NSSize stringSize = [labelString size];
if (stringSize.width > NSWidth(tabRect))
{
int labelLength = [[labelString string] length];
float spacePerChar = stringSize.width/labelLength;
int allowableCharacters = floor(NSWidth(tabRect)/spacePerChar) - kEllipseSpaces;
if (allowableCharacters < labelLength)
{
if (allowableCharacters < 0)
allowableCharacters = 0;
[labelString replaceCharactersInRange:NSMakeRange(allowableCharacters, labelLength - allowableCharacters) withString:[NSString ellipsisString]];
}
}
//
// ****************************************************************
// End of LineBreakByTruncatingTail workaround code.
// ****************************************************************
//
#endif
[labelString drawInRect:tabRect];
[labelString release];
}
-(NSImage *)tabIcon
{
return mTabIcon;
}
-(void)setTabIcon:(NSImage *)newIcon
{
[mTabIcon autorelease];
mTabIcon = [newIcon copy];
}
@end

View File

@ -51,6 +51,7 @@ typedef enum
// a category to extend NSString
@interface NSString (ChimeraStringUtils)
+ (id)ellipsisString;
+ (id)stringWithPRUnichars:(const PRUnichar*)inString;
+ (id)stringWith_nsAString:(const nsAString&)inString;
- (void)assignTo_nsAString:(nsAString&)ioString;

View File

@ -44,6 +44,18 @@
@implementation NSString (ChimeraStringUtils)
+ (id)ellipsisString
{
static NSString* sEllipsisString = nil;
if (!sEllipsisString)
{
unichar ellipsisChar = 0x2026;
sEllipsisString = [[[NSString alloc] initWithCharacters:&ellipsisChar length:1] retain];
}
return sEllipsisString;
}
+ (id)stringWithPRUnichars:(const PRUnichar*)inString
{
if (inString)
@ -119,8 +131,7 @@
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
{
unichar ellipsisChar = 0x2026;
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
NSString* ellipsisString = [NSString ellipsisString];
if ([self length] > maxCharacters)
{

View File

@ -836,7 +836,7 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
return isBookmark && [mBrowserWindowController newTabsAllowed];
}
return YES;
}

View File

@ -41,7 +41,7 @@
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#import "CHIconTabViewItem.h"
#import "StringUtils.h"
#include "nsCRT.h"
@ -1021,10 +1021,12 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
elt->GetAttribute(NS_LITERAL_STRING("href"), href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWith_nsAString: href];
NSTabViewItem* tabViewItem = nil;
CHIconTabViewItem* tabViewItem = nil;
if (currentIndex >= total) {
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
// XXX this needs fixing to not max out the number of tabs in a browser window.
// See [BrowserWindowController newTabsAllowed];
tabViewItem = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease];
[tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")];
[tabViewItem setView: newView];

View File

@ -153,8 +153,9 @@ class nsIDOMNode;
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (id)getTabBrowser;
- (BOOL)newTabsAllowed;
- (CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate;
- (void)updateLocationFields:(NSString *)locationString;
@ -235,7 +236,7 @@ class nsIDOMNode;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;

View File

@ -90,6 +90,7 @@ static NSString *NavigatorWindowFrameSaveName = @"NavigatorWindow";
// hardcoded defaults.
static NSArray* sToolbarDefaults = nil;
#define kMaxBrowserWindowTabs 16
@interface BrowserWindowController(Private)
- (void)setupToolbar;
@ -290,6 +291,9 @@ static NSArray* sToolbarDefaults = nil;
[self setupToolbar];
// set an upper limit on the number of tabs per window
[mTabBrowser setMaxNumberOfTabs: kMaxBrowserWindowTabs];
// 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.
@ -758,7 +762,11 @@ static NSArray* sToolbarDefaults = nil;
PRBool loadInBackground;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
if (![self newTabsAllowed])
[self openNewWindowWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
else
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
}
- (IBAction)printDocument:(id)aSender
@ -962,7 +970,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)newTab:(BOOL)allowHomepage
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
PRInt32 newTabPage = 0;
@ -1040,6 +1048,11 @@ static NSArray* sToolbarDefaults = nil;
return mTabBrowser;
}
- (BOOL)newTabsAllowed
{
return [mTabBrowser canMakeNewTabs];
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
@ -1076,7 +1089,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)openNewTabWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
@ -1305,7 +1318,7 @@ static NSArray* sToolbarDefaults = nil;
NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString];
if (aUseWindow)
if (aUseWindow || ![self newTabsAllowed])
[self openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[self openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -70,7 +70,8 @@
NSString* url = [NSString stringWith_nsAString: href];
// Now load the URL in the window.
[[[self window] windowController] loadURL: url referrer:nil activate:YES];
BrowserWindowController* brController = [[self window] windowController];
[brController loadURL: url referrer:nil activate:YES];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
@ -87,7 +88,8 @@
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[[[self window] windowController] openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
BrowserWindowController* brController = [[self window] windowController];
[brController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
@ -106,10 +108,12 @@
nsAutoString group;
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
BrowserWindowController* brController = [[self window] windowController];
if (group.IsEmpty())
[[[self window] windowController] openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
[brController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
else
[[[self window] windowController] openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
[brController openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
}
-(IBAction)showBookmarkInfo:(id)aSender
@ -174,7 +178,8 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
BrowserWindowController* brController = [[self window] windowController];
return isBookmark && [brController newTabsAllowed];
}
return YES;
}

View File

@ -22,6 +22,7 @@
@interface CHExtendedTabView : NSTabView
{
BOOL autoHides;
int maxNumberOfTabs; // 0 means 'no max'
}
// Behavior: Autohiding overrides the default tab visibility state.
@ -30,6 +31,10 @@
- (BOOL)autoHides;
- (void)setAutoHides:(BOOL)newSetting;
-(void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer;
- (int)maxNumberOfTabs;
- (void)setMaxNumberOfTabs:(int)maxTabs;
- (BOOL)canMakeNewTabs;
- (void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer;
@end

View File

@ -1,23 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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 Mozilla 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/MPL/
* 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.
* 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 the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
* 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):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
*
* 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 "NSString+Utils.h"
#import "CHExtendedTabView.h"
#import "CHIconTabViewItem.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
@ -52,6 +75,7 @@
{
if ( (self = [super initWithFrame:frameRect]) ) {
autoHides = YES;
maxNumberOfTabs = 0; // no max
}
return self;
}
@ -108,6 +132,20 @@
autoHides = newSetting;
}
- (int)maxNumberOfTabs
{
return maxNumberOfTabs;
}
- (void)setMaxNumberOfTabs:(int)maxTabs
{
maxNumberOfTabs = maxTabs;
}
- (BOOL)canMakeNewTabs
{
return maxNumberOfTabs == 0 || [self numberOfTabViewItems] < maxNumberOfTabs;
}
/******************************************/
/*** Instance Methods ***/
@ -140,19 +178,37 @@
[[overTabViewItem view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO];
} else if (overContentArea) {
[[[self selectedTabViewItem] view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO];
} else
} else if ([self canMakeNewTabs]) {
[self addTabForURL:url referrer:nil];
} else {
NSLog(@"Can't make new tab for drop");
}
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint];
BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]);
if (!overTabViewItem && !overContentArea && ![self canMakeNewTabs])
return NSDragOperationNone;
return NSDragOperationGeneric;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint];
BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]);
if (!overTabViewItem && !overContentArea && ![self canMakeNewTabs])
return NSDragOperationNone;
return NSDragOperationGeneric;
}
@ -225,12 +281,9 @@
-(void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer
{
NSTabViewItem* tabViewItem;
CHBrowserWrapper* newView;
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease];
CHIconTabViewItem *tabViewItem= [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper *newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease];
[tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")];
[tabViewItem setView: newView];
[self addTabViewItem: tabViewItem];
@ -239,3 +292,7 @@
}
@end

View File

@ -1,25 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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 Mozilla 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/MPL/
* 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.
* 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 the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Matt Judy. Portions
* of code @2002 nibfile.com.
*/
* 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.
* Portions are Copyright (C) 2002 nibfile.com
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
*
* 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>
@interface CHIconTabViewItem : NSTabViewItem {
NSImage *_tabIcon;
NSImage *mTabIcon;
NSDictionary* mLabelAttributes;
}
// The designated initializer

View File

@ -1,40 +0,0 @@
//
// IconTabViewItem.m
// Chimera
//
// Created by Matt L. Judy on Sun Mar 10 2002.
// Copyright (c) 2001 __MyCompanyName__. All rights reserved.
//
#import "CHIconTabViewItem.h"
@implementation CHIconTabViewItem
-(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon
{
if ( (self = [super initWithIdentifier:identifier]) ) {
[self setTabIcon:tabIcon];
}
return self;
}
- (NSSize)sizeOfLabel:(BOOL)computeMin
{
return( NSMakeSize(15,15) );
}
-(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15) );
[[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver];
}
-(NSImage *)tabIcon { return _tabIcon; }
-(void)setTabIcon:(NSImage *)newIcon
{
[_tabIcon autorelease];
_tabIcon = [newIcon copy];
}
@end

View File

@ -0,0 +1,192 @@
/* -*- 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.
* Portions are Copyright (C) 2002 nibfile.com.
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
* Simon Fraser <sfraser@netscape.com>
*
* 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 "CHIconTabViewItem.h"
//
// NSParagraphStyle has a line break mode which will automatically
// append ellipses to the end of a string. Unfortunately, as of
// OS X 10.1.5, the header says it doesn't work yet.
//
#define BROKEN_NSLineBreakByTruncatingMiddle
static const int kMinTabsForSpacing = 4; // with 1-4 tabs, each tab is 1/4 the tab view width
static const int kEllipseSpaces = 4; //yes, i know it's 3 ...'s
@interface CHIconTabViewItem(Private)
- (void)setupLabelAttributes;
@end;
@implementation CHIconTabViewItem
-(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon
{
if ( (self = [super initWithIdentifier:identifier]) ) {
[self setTabIcon:tabIcon];
[self setupLabelAttributes];
}
return self;
}
-(id)initWithIdentifier:(id)identifier
{
return [self initWithIdentifier:identifier withTabIcon:nil];
}
-(void)dealloc
{
[mTabIcon release];
[mLabelAttributes release];
[super dealloc];
}
- (void)setupLabelAttributes
{
NSMutableParagraphStyle *labelParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[labelParagraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
[labelParagraphStyle setLineBreakMode:NSLineBreakByClipping];
#else
[labelParagraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle];
#endif
[labelParagraphStyle setAlignment:NSCenterTextAlignment];
NSFont *labelFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
mLabelAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
labelFont, NSFontAttributeName,
labelParagraphStyle, NSParagraphStyleAttributeName,
nil];
[labelParagraphStyle release];
}
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{
int numTabs;
float theWidth = 0;
//if we've got text, size for # of tabs & amount of text.
// Accounts for icon size, if one present.
if ([[self label] length] > 0) {
numTabs = [[self tabView] numberOfTabViewItems];
if (numTabs < kMinTabsForSpacing)
numTabs = kMinTabsForSpacing;
theWidth = NSWidth([[self tabView] frame]) / numTabs - 16.0; // 16 works - don't know why. Maybe 8px on each side of the label?
if (shouldTruncateLabel) {
//I have really no clue what this is for.
//it only gets set YES when the tabs have
//reached the edge of the screen area.
//I don't see any difference in behavior between putting
//in -10 or -600 here. But -1 instead of -10 makes the
//tabs go off screen.
theWidth -= 16.0;
}
}
// If we don't have text, but DO have an icon, we'll have size 15.
else if ([self tabIcon])
theWidth = 15.0;
return NSMakeSize(theWidth, 15.0); // ugh, hard-coded height.
// This doesn't seem to affect, the height, only the rect pass to
// drawLabel.
}
-(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
if ([self tabIcon]) {
NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15.0) );
[[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver];
tabRect = NSMakeRect(NSMinX(tabRect)+15.0,
NSMinY(tabRect),
NSWidth(tabRect)-15.0,
NSHeight(tabRect));
}
NSMutableAttributedString* labelString = [[NSMutableAttributedString alloc] initWithString:[self label] attributes:mLabelAttributes];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
//
// ****************************************************************
// Beginning of LineBreakByTruncatingTail workaround code.
// When it starts working, this can be removed.
// ****************************************************************
//
NSSize stringSize = [labelString size];
if (stringSize.width > NSWidth(tabRect))
{
int labelLength = [[labelString string] length];
float spacePerChar = stringSize.width/labelLength;
int allowableCharacters = floor(NSWidth(tabRect)/spacePerChar) - kEllipseSpaces;
if (allowableCharacters < labelLength)
{
if (allowableCharacters < 0)
allowableCharacters = 0;
[labelString replaceCharactersInRange:NSMakeRange(allowableCharacters, labelLength - allowableCharacters) withString:[NSString ellipsisString]];
}
}
//
// ****************************************************************
// End of LineBreakByTruncatingTail workaround code.
// ****************************************************************
//
#endif
[labelString drawInRect:tabRect];
[labelString release];
}
-(NSImage *)tabIcon
{
return mTabIcon;
}
-(void)setTabIcon:(NSImage *)newIcon
{
[mTabIcon autorelease];
mTabIcon = [newIcon copy];
}
@end

View File

@ -3157,7 +3157,7 @@
};
F564873A023C3857010001CA = {
isa = PBXFileReference;
path = CHIconTabViewItem.m;
path = CHIconTabViewItem.mm;
refType = 4;
};
F564873B023C3857010001CA = {

View File

@ -306,7 +306,7 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
if (shiftKey)
loadInBackground = !loadInBackground;
if (useTab)
if (useTab && [mBrowserController newTabsAllowed])
[mBrowserController openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[mBrowserController openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -438,11 +438,8 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// reuse the main window if there is one. The user may have closed all of
// them or we may get this event at startup before we've had time to load
// our window.
BrowserWindowController* controller = NULL;
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
if (reuseWindow && browserWindow) {
controller = [browserWindow windowController];
BrowserWindowController* controller = [self getMainWindowBrowserController];
if (reuseWindow && controller && [controller canMakeNewTabs]) {
[controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground];
}
else {
@ -669,11 +666,10 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
//NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
if (action == @selector(newTab:) ||
if (action == @selector(printPage:) ||
/* ... many more items go here ... */
/* action == @selector(goHome:) || */ // always enabled
/* action == @selector(doSearch:) || */ // always enabled
action == @selector(printPage:) ||
action == @selector(findInPage:) ||
action == @selector(doReload:) ||
action == @selector(biggerTextSize:) ||
@ -685,6 +681,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
return NO;
}
if (action == @selector(newTab:)) {
if (browserController && [browserController newTabsAllowed])
return YES;
return NO;
}
// check if someone has previously done a find before allowing findAgain to be enabled
if (action == @selector(findAgain:)) {
if (browserController)

View File

@ -51,6 +51,7 @@ typedef enum
// a category to extend NSString
@interface NSString (ChimeraStringUtils)
+ (id)ellipsisString;
+ (id)stringWithPRUnichars:(const PRUnichar*)inString;
+ (id)stringWith_nsAString:(const nsAString&)inString;
- (void)assignTo_nsAString:(nsAString&)ioString;

View File

@ -44,6 +44,18 @@
@implementation NSString (ChimeraStringUtils)
+ (id)ellipsisString
{
static NSString* sEllipsisString = nil;
if (!sEllipsisString)
{
unichar ellipsisChar = 0x2026;
sEllipsisString = [[[NSString alloc] initWithCharacters:&ellipsisChar length:1] retain];
}
return sEllipsisString;
}
+ (id)stringWithPRUnichars:(const PRUnichar*)inString
{
if (inString)
@ -119,8 +131,7 @@
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
{
unichar ellipsisChar = 0x2026;
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
NSString* ellipsisString = [NSString ellipsisString];
if ([self length] > maxCharacters)
{

View File

@ -3157,7 +3157,7 @@
};
F564873A023C3857010001CA = {
isa = PBXFileReference;
path = CHIconTabViewItem.m;
path = CHIconTabViewItem.mm;
refType = 4;
};
F564873B023C3857010001CA = {

View File

@ -438,11 +438,8 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// reuse the main window if there is one. The user may have closed all of
// them or we may get this event at startup before we've had time to load
// our window.
BrowserWindowController* controller = NULL;
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
if (reuseWindow && browserWindow) {
controller = [browserWindow windowController];
BrowserWindowController* controller = [self getMainWindowBrowserController];
if (reuseWindow && controller && [controller canMakeNewTabs]) {
[controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground];
}
else {
@ -669,11 +666,10 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
//NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
if (action == @selector(newTab:) ||
if (action == @selector(printPage:) ||
/* ... many more items go here ... */
/* action == @selector(goHome:) || */ // always enabled
/* action == @selector(doSearch:) || */ // always enabled
action == @selector(printPage:) ||
action == @selector(findInPage:) ||
action == @selector(doReload:) ||
action == @selector(biggerTextSize:) ||
@ -685,6 +681,12 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
return NO;
}
if (action == @selector(newTab:)) {
if (browserController && [browserController newTabsAllowed])
return YES;
return NO;
}
// check if someone has previously done a find before allowing findAgain to be enabled
if (action == @selector(findAgain:)) {
if (browserController)

View File

@ -70,7 +70,8 @@
NSString* url = [NSString stringWith_nsAString: href];
// Now load the URL in the window.
[[[self window] windowController] loadURL: url referrer:nil activate:YES];
BrowserWindowController* brController = [[self window] windowController];
[brController loadURL: url referrer:nil activate:YES];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
@ -87,7 +88,8 @@
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[[[self window] windowController] openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
BrowserWindowController* brController = [[self window] windowController];
[brController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
@ -106,10 +108,12 @@
nsAutoString group;
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
BrowserWindowController* brController = [[self window] windowController];
if (group.IsEmpty())
[[[self window] windowController] openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
[brController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
else
[[[self window] windowController] openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
[brController openNewWindowWithGroup: mElement loadInBackground: loadInBackground];
}
-(IBAction)showBookmarkInfo:(id)aSender
@ -174,7 +178,8 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
BrowserWindowController* brController = [[self window] windowController];
return isBookmark && [brController newTabsAllowed];
}
return YES;
}

View File

@ -836,7 +836,7 @@
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
return isBookmark && [mBrowserWindowController newTabsAllowed];
}
return YES;
}

View File

@ -41,7 +41,7 @@
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#import "CHIconTabViewItem.h"
#import "StringUtils.h"
#include "nsCRT.h"
@ -1021,10 +1021,12 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
elt->GetAttribute(NS_LITERAL_STRING("href"), href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWith_nsAString: href];
NSTabViewItem* tabViewItem = nil;
CHIconTabViewItem* tabViewItem = nil;
if (currentIndex >= total) {
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
// XXX this needs fixing to not max out the number of tabs in a browser window.
// See [BrowserWindowController newTabsAllowed];
tabViewItem = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease];
[tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")];
[tabViewItem setView: newView];

View File

@ -153,8 +153,9 @@ class nsIDOMNode;
- (void)dealloc;
-(id)getTabBrowser;
-(CHBrowserWrapper*)getBrowserWrapper;
- (id)getTabBrowser;
- (BOOL)newTabsAllowed;
- (CHBrowserWrapper*)getBrowserWrapper;
- (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate;
- (void)updateLocationFields:(NSString *)locationString;
@ -235,7 +236,7 @@ class nsIDOMNode;
// Context menu methods
- (IBAction)openLinkInNewWindow:(id)aSender;
- (IBAction)openLinkInNewTab:(id)aSender;
-(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (void)openLinkInNewWindowOrTab: (BOOL)aUseWindow;
- (IBAction)savePageAs:(id)aSender;
- (IBAction)saveLinkAs:(id)aSender;

View File

@ -90,6 +90,7 @@ static NSString *NavigatorWindowFrameSaveName = @"NavigatorWindow";
// hardcoded defaults.
static NSArray* sToolbarDefaults = nil;
#define kMaxBrowserWindowTabs 16
@interface BrowserWindowController(Private)
- (void)setupToolbar;
@ -290,6 +291,9 @@ static NSArray* sToolbarDefaults = nil;
[self setupToolbar];
// set an upper limit on the number of tabs per window
[mTabBrowser setMaxNumberOfTabs: kMaxBrowserWindowTabs];
// 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.
@ -758,7 +762,11 @@ static NSArray* sToolbarDefaults = nil;
PRBool loadInBackground;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
if (![self newTabsAllowed])
[self openNewWindowWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
else
[self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground];
}
- (IBAction)printDocument:(id)aSender
@ -962,7 +970,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)newTab:(BOOL)allowHomepage
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease];
PRInt32 newTabPage = 0;
@ -1040,6 +1048,11 @@ static NSArray* sToolbarDefaults = nil;
return mTabBrowser;
}
- (BOOL)newTabsAllowed
{
return [mTabBrowser canMakeNewTabs];
}
-(CHBrowserWrapper*)getBrowserWrapper
{
return mBrowserView;
@ -1076,7 +1089,7 @@ static NSArray* sToolbarDefaults = nil;
-(void)openNewTabWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG
{
NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
CHIconTabViewItem* newTab = [[[CHIconTabViewItem alloc] initWithIdentifier: nil] autorelease];
NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
int index = [mTabBrowser indexOfTabViewItem: selectedTab];
@ -1305,7 +1318,7 @@ static NSArray* sToolbarDefaults = nil;
NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString];
if (aUseWindow)
if (aUseWindow || ![self newTabsAllowed])
[self openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[self openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -306,7 +306,7 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
if (shiftKey)
loadInBackground = !loadInBackground;
if (useTab)
if (useTab && [mBrowserController newTabsAllowed])
[mBrowserController openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];
else
[mBrowserController openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground];

View File

@ -1,25 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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 Mozilla 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/MPL/
* 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.
* 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 the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Matt Judy. Portions
* of code @2002 nibfile.com.
*/
* 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.
* Portions are Copyright (C) 2002 nibfile.com
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
*
* 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>
@interface CHIconTabViewItem : NSTabViewItem {
NSImage *_tabIcon;
NSImage *mTabIcon;
NSDictionary* mLabelAttributes;
}
// The designated initializer

View File

@ -0,0 +1,192 @@
/* -*- 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.
* Portions are Copyright (C) 2002 nibfile.com.
*
* Contributor(s):
* Matt Judy <matt@nibfile.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
* Simon Fraser <sfraser@netscape.com>
*
* 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 "CHIconTabViewItem.h"
//
// NSParagraphStyle has a line break mode which will automatically
// append ellipses to the end of a string. Unfortunately, as of
// OS X 10.1.5, the header says it doesn't work yet.
//
#define BROKEN_NSLineBreakByTruncatingMiddle
static const int kMinTabsForSpacing = 4; // with 1-4 tabs, each tab is 1/4 the tab view width
static const int kEllipseSpaces = 4; //yes, i know it's 3 ...'s
@interface CHIconTabViewItem(Private)
- (void)setupLabelAttributes;
@end;
@implementation CHIconTabViewItem
-(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon
{
if ( (self = [super initWithIdentifier:identifier]) ) {
[self setTabIcon:tabIcon];
[self setupLabelAttributes];
}
return self;
}
-(id)initWithIdentifier:(id)identifier
{
return [self initWithIdentifier:identifier withTabIcon:nil];
}
-(void)dealloc
{
[mTabIcon release];
[mLabelAttributes release];
[super dealloc];
}
- (void)setupLabelAttributes
{
NSMutableParagraphStyle *labelParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[labelParagraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
[labelParagraphStyle setLineBreakMode:NSLineBreakByClipping];
#else
[labelParagraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle];
#endif
[labelParagraphStyle setAlignment:NSCenterTextAlignment];
NSFont *labelFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
mLabelAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
labelFont, NSFontAttributeName,
labelParagraphStyle, NSParagraphStyleAttributeName,
nil];
[labelParagraphStyle release];
}
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{
int numTabs;
float theWidth = 0;
//if we've got text, size for # of tabs & amount of text.
// Accounts for icon size, if one present.
if ([[self label] length] > 0) {
numTabs = [[self tabView] numberOfTabViewItems];
if (numTabs < kMinTabsForSpacing)
numTabs = kMinTabsForSpacing;
theWidth = NSWidth([[self tabView] frame]) / numTabs - 16.0; // 16 works - don't know why. Maybe 8px on each side of the label?
if (shouldTruncateLabel) {
//I have really no clue what this is for.
//it only gets set YES when the tabs have
//reached the edge of the screen area.
//I don't see any difference in behavior between putting
//in -10 or -600 here. But -1 instead of -10 makes the
//tabs go off screen.
theWidth -= 16.0;
}
}
// If we don't have text, but DO have an icon, we'll have size 15.
else if ([self tabIcon])
theWidth = 15.0;
return NSMakeSize(theWidth, 15.0); // ugh, hard-coded height.
// This doesn't seem to affect, the height, only the rect pass to
// drawLabel.
}
-(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
if ([self tabIcon]) {
NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15.0) );
[[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver];
tabRect = NSMakeRect(NSMinX(tabRect)+15.0,
NSMinY(tabRect),
NSWidth(tabRect)-15.0,
NSHeight(tabRect));
}
NSMutableAttributedString* labelString = [[NSMutableAttributedString alloc] initWithString:[self label] attributes:mLabelAttributes];
#ifdef BROKEN_NSLineBreakByTruncatingMiddle
//
// ****************************************************************
// Beginning of LineBreakByTruncatingTail workaround code.
// When it starts working, this can be removed.
// ****************************************************************
//
NSSize stringSize = [labelString size];
if (stringSize.width > NSWidth(tabRect))
{
int labelLength = [[labelString string] length];
float spacePerChar = stringSize.width/labelLength;
int allowableCharacters = floor(NSWidth(tabRect)/spacePerChar) - kEllipseSpaces;
if (allowableCharacters < labelLength)
{
if (allowableCharacters < 0)
allowableCharacters = 0;
[labelString replaceCharactersInRange:NSMakeRange(allowableCharacters, labelLength - allowableCharacters) withString:[NSString ellipsisString]];
}
}
//
// ****************************************************************
// End of LineBreakByTruncatingTail workaround code.
// ****************************************************************
//
#endif
[labelString drawInRect:tabRect];
[labelString release];
}
-(NSImage *)tabIcon
{
return mTabIcon;
}
-(void)setTabIcon:(NSImage *)newIcon
{
[mTabIcon autorelease];
mTabIcon = [newIcon copy];
}
@end

View File

@ -51,6 +51,7 @@ typedef enum
// a category to extend NSString
@interface NSString (ChimeraStringUtils)
+ (id)ellipsisString;
+ (id)stringWithPRUnichars:(const PRUnichar*)inString;
+ (id)stringWith_nsAString:(const nsAString&)inString;
- (void)assignTo_nsAString:(nsAString&)ioString;

View File

@ -44,6 +44,18 @@
@implementation NSString (ChimeraStringUtils)
+ (id)ellipsisString
{
static NSString* sEllipsisString = nil;
if (!sEllipsisString)
{
unichar ellipsisChar = 0x2026;
sEllipsisString = [[[NSString alloc] initWithCharacters:&ellipsisChar length:1] retain];
}
return sEllipsisString;
}
+ (id)stringWithPRUnichars:(const PRUnichar*)inString
{
if (inString)
@ -119,8 +131,7 @@
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
{
unichar ellipsisChar = 0x2026;
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
NSString* ellipsisString = [NSString ellipsisString];
if ([self length] > maxCharacters)
{