From 8cc6b55981e808576d32c37f374716015fafe55b Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 24 Jan 2011 09:12:22 +0000 Subject: Nice back/forward buttons and moved refresh button into URL field (like Safari) svn path=/trunk/netsurf/; revision=11477 --- cocoa/BrowserViewController.h | 2 + cocoa/BrowserViewController.m | 25 +-- cocoa/BrowserWindowController.h | 5 + cocoa/BrowserWindowController.m | 6 + cocoa/Makefile.target | 1 + cocoa/NetSurf.xcodeproj/project.pbxproj | 6 + cocoa/URLFieldCell.h | 29 ++++ cocoa/URLFieldCell.m | 117 ++++++++++++++ cocoa/res/BrowserWindow.xib | 261 +++++++++++++++++--------------- 9 files changed, 308 insertions(+), 144 deletions(-) create mode 100644 cocoa/URLFieldCell.h create mode 100644 cocoa/URLFieldCell.m (limited to 'cocoa') diff --git a/cocoa/BrowserViewController.h b/cocoa/BrowserViewController.h index e01b34089..55bf3d37f 100644 --- a/cocoa/BrowserViewController.h +++ b/cocoa/BrowserViewController.h @@ -45,6 +45,8 @@ struct browser_window; - (IBAction) navigate: (id) sender; +- (IBAction) backForwardSelected: (id) sender; + - (IBAction) goBack: (id) sender; - (IBAction) goForward: (id) sender; - (IBAction) reloadPage: (id) sender; diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m index 026bacf24..0d08676be 100644 --- a/cocoa/BrowserViewController.m +++ b/cocoa/BrowserViewController.m @@ -84,6 +84,12 @@ browser_window_set_scale( browser, (float)option_scale / 100.0, true ); } +- (IBAction) backForwardSelected: (id) sender; +{ + if ([sender selectedSegment] == 0) [self goBack: sender]; + else [self goForward: sender]; +} + - (IBAction) goBack: (id) sender; { if (browser && history_back_available( browser->history )) { @@ -108,25 +114,6 @@ browser_window_stop( browser ); } -- (BOOL) validateToolbarItem: (NSToolbarItem *)theItem; -{ - SEL action = [theItem action]; - - if (action == @selector( goBack: )) { - return browser != NULL && history_back_available( browser->history ); - } - - if (action == @selector( goForward: )) { - return browser != NULL && history_forward_available( browser->history ); - } - - if (action == @selector( reloadPage: )) { - return browser_window_reload_available( browser ); - } - - return YES; -} - static inline bool compare_float( float a, float b ) { const float epsilon = 0.00001; diff --git a/cocoa/BrowserWindowController.h b/cocoa/BrowserWindowController.h index 42a75930a..25482bbfa 100644 --- a/cocoa/BrowserWindowController.h +++ b/cocoa/BrowserWindowController.h @@ -20,15 +20,20 @@ @class PSMTabBarControl; @class BrowserViewController; +@class URLFieldCell; @interface BrowserWindowController : NSWindowController { PSMTabBarControl *tabBar; NSTabView *tabView; + URLFieldCell *urlField; + BrowserViewController *activeBrowser; } @property (readwrite, retain, nonatomic) IBOutlet PSMTabBarControl *tabBar; @property (readwrite, retain, nonatomic) IBOutlet NSTabView *tabView; +@property (readwrite, retain, nonatomic) IBOutlet URLFieldCell *urlField; + @property (readwrite, assign, nonatomic) BrowserViewController *activeBrowser; - (IBAction) newTab: (id) sender; diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m index 7a59fad2f..ceb3f9f28 100644 --- a/cocoa/BrowserWindowController.m +++ b/cocoa/BrowserWindowController.m @@ -21,6 +21,7 @@ #import "BrowserViewController.h" #import "PSMTabBarControl.h" #import "PSMRolloverButton.h" +#import "URLFieldCell.h" #import "desktop/browser.h" @@ -28,6 +29,8 @@ @synthesize tabBar; @synthesize tabView; +@synthesize urlField; + @synthesize activeBrowser; - (id) init; @@ -41,6 +44,7 @@ { [self setTabBar: nil]; [self setTabView: nil]; + [self setUrlField: nil]; [super dealloc]; } @@ -56,6 +60,8 @@ [b setAction: @selector(newTab:)]; [[self window] setAcceptsMouseMovedEvents: YES]; + + [urlField setRefreshAction: @selector(reloadPage:)]; } - (void) addTab: (BrowserViewController *)browser; diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target index fdb063460..95f8e5c83 100644 --- a/cocoa/Makefile.target +++ b/cocoa/Makefile.target @@ -71,6 +71,7 @@ S_COCOA := \ NetSurfAppDelegate.m \ NetsurfApp.m \ ScrollableView.m \ + URLFieldCell.m \ TreeView.m \ bitmap.m \ fetch.m \ diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index 500c316de..dd48ae3c0 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -140,6 +140,7 @@ 26CDCFF312E70AD1004FC66B /* BrowserWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 26CDCFF212E70AD1004FC66B /* BrowserWindow.xib */; }; 26CDD00312E70F56004FC66B /* BrowserWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 26CDD00212E70F56004FC66B /* BrowserWindowController.m */; }; 26CDD0F612E726E0004FC66B /* BrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 26CDD0F512E726E0004FC66B /* BrowserViewController.m */; }; + 26EC3B6A12ED62C0000A960C /* URLFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 26EC3B6912ED62C0000A960C /* URLFieldCell.m */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -401,6 +402,8 @@ 26CDD00212E70F56004FC66B /* BrowserWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BrowserWindowController.m; sourceTree = ""; }; 26CDD0F412E726E0004FC66B /* BrowserViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrowserViewController.h; sourceTree = ""; }; 26CDD0F512E726E0004FC66B /* BrowserViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BrowserViewController.m; sourceTree = ""; }; + 26EC3B6812ED62C0000A960C /* URLFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = URLFieldCell.h; sourceTree = ""; }; + 26EC3B6912ED62C0000A960C /* URLFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = URLFieldCell.m; sourceTree = ""; }; 8D1107320486CEB800E47090 /* NetSurf.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetSurf.app; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -795,6 +798,8 @@ 26AFE8E312DF4200005AD082 /* ScrollableView.m */, 2622F1D512DCD84600CD5A62 /* TreeView.h */, 2622F1D612DCD84600CD5A62 /* TreeView.m */, + 26EC3B6812ED62C0000A960C /* URLFieldCell.h */, + 26EC3B6912ED62C0000A960C /* URLFieldCell.m */, ); name = Views; sourceTree = ""; @@ -1062,6 +1067,7 @@ 26CDCEE312E702D8004FC66B /* PSMUnifiedTabStyle.m in Sources */, 26CDD00312E70F56004FC66B /* BrowserWindowController.m in Sources */, 26CDD0F612E726E0004FC66B /* BrowserViewController.m in Sources */, + 26EC3B6A12ED62C0000A960C /* URLFieldCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cocoa/URLFieldCell.h b/cocoa/URLFieldCell.h new file mode 100644 index 000000000..bb0d6572b --- /dev/null +++ b/cocoa/URLFieldCell.h @@ -0,0 +1,29 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import + + +@interface URLFieldCell : NSTextFieldCell { + NSButtonCell *refreshCell; +} + +@property (readwrite, assign, nonatomic) SEL refreshAction; +@property (readwrite, assign, nonatomic) id refreshTarget; + +@end diff --git a/cocoa/URLFieldCell.m b/cocoa/URLFieldCell.m new file mode 100644 index 000000000..cb9565aa1 --- /dev/null +++ b/cocoa/URLFieldCell.m @@ -0,0 +1,117 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import "URLFieldCell.h" + + +@interface URLFieldCell () + +@property (readonly, retain, nonatomic) NSButtonCell *refreshCell; + +- (NSRect) buttonFrame: (NSRect) cellFrame; + +@end + + +@implementation URLFieldCell + +#define BUTTON_SIZE 32 +#define PADDING 2 + +- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView; +{ + [super drawInteriorWithFrame: cellFrame inView: controlView]; + const NSRect buttonRect = [self buttonFrame: cellFrame]; + [[self refreshCell] drawInteriorWithFrame: buttonRect inView: controlView]; +} + +- (void) selectWithFrame: (NSRect)aRect inView: (NSView *)controlView editor: (NSText *)textObj + delegate: (id)anObject start: (NSInteger)selStart length: (NSInteger)selLength; +{ + aRect.size.width -= BUTTON_SIZE + PADDING; + [super selectWithFrame: aRect inView: controlView editor: textObj + delegate: anObject start: selStart length: selLength]; +} + +- (void) editWithFrame: (NSRect)aRect inView: (NSView *)controlView editor: (NSText *)textObj + delegate: (id)anObject event: (NSEvent *)theEvent; +{ + aRect.size.width -= BUTTON_SIZE + PADDING; + [super editWithFrame: aRect inView: controlView editor: textObj + delegate: anObject event: theEvent]; +} + +- (BOOL) trackMouse: (NSEvent *)theEvent inRect: (NSRect)cellFrame ofView: (NSView *)controlView untilMouseUp: (BOOL)flag; +{ + const NSPoint point = [controlView convertPoint: [theEvent locationInWindow] fromView: nil]; + const NSRect buttonRect = [self buttonFrame: cellFrame]; + if (NSPointInRect( point, buttonRect )) { + return [[self refreshCell] trackMouse: theEvent inRect: buttonRect + ofView: controlView untilMouseUp: flag]; + } else { + cellFrame.size.width -= BUTTON_SIZE + PADDING; + return [super trackMouse: theEvent inRect: cellFrame ofView: controlView untilMouseUp: YES]; + } +} + +- (void) dealloc; +{ + [refreshCell release]; + + [super dealloc]; +} + +- (NSRect) buttonFrame: (NSRect) cellFrame; +{ + NSRect buttonRect = cellFrame; + buttonRect.origin.x = NSMaxX( cellFrame ) - BUTTON_SIZE; + buttonRect.size.width = BUTTON_SIZE; + return buttonRect; +} + +- (NSButtonCell *) refreshCell; +{ + if (nil == refreshCell) { + refreshCell = [[NSButtonCell alloc] initImageCell: [NSImage imageNamed: NSImageNameRefreshTemplate]]; + [refreshCell setButtonType: NSMomentaryPushInButton]; + [refreshCell setBordered: NO]; + } + return refreshCell; +} + +- (void) setRefreshTarget: (id) newTarget; +{ + [[self refreshCell] setTarget: newTarget]; +} + +- (id) refreshTarget; +{ + return [[self refreshCell] target]; +} + +- (void) setRefreshAction: (SEL) newAction; +{ + [[self refreshCell] setAction: newAction]; +} + +- (SEL) refreshAction; +{ + return [[self refreshCell] action]; +} + +@end diff --git a/cocoa/res/BrowserWindow.xib b/cocoa/res/BrowserWindow.xib index d4a653244..d9e3e3de9 100644 --- a/cocoa/res/BrowserWindow.xib +++ b/cocoa/res/BrowserWindow.xib @@ -12,6 +12,7 @@ YES + YES @@ -59,9 +60,7 @@ YES YES - 316FFEF7-FE4B-4054-A233-B48593490A7F - 484FB8D5-6AD6-4E75-B60E-CA03FC98EFCD - 7EEF129A-ED23-47F1-88E8-B60EAF53C80C + BC5CEBFC-2E3B-420C-A75F-BE0760149C45 E2E89C48-DD3F-47A5-9E6C-25985A970F69 NSToolbarCustomizeToolbarItem NSToolbarFlexibleSpaceItem @@ -70,69 +69,64 @@ YES - + - 316FFEF7-FE4B-4054-A233-B48593490A7F + BC5CEBFC-2E3B-420C-A75F-BE0760149C45 - Go back - Go back - - - - NSImage - NSGoLeftTemplate - - - - {0, 0} - {0, 0} - YES - YES - -1 - YES - 0 - - - - 484FB8D5-6AD6-4E75-B60E-CA03FC98EFCD - - Go forward - Go forward - - - - NSImage - NSGoRightTemplate - - - - {0, 0} - {0, 0} - YES - YES - -1 - YES - 0 - - - - 7EEF129A-ED23-47F1-88E8-B60EAF53C80C - - Reload - Reload - - - - NSImage - NSRefreshTemplate + + Back/Forward + + + + 268 + {{5, 14}, {71, 25}} + YES + + 67239424 + 0 + + LucidaGrande + 13 + 16 + + + + YES + + 32 + + NSImage + NSLeftFacingTriangleTemplate + + + Back + 0 + + + 32 + + NSImage + NSRightFacingTriangleTemplate + + + Forward + 1 + 0 + + + 1 + 2 + 2 + + - {0, 0} - {0, 0} + {71, 25} + {104, 25} YES YES - -1 + 0 YES 0 @@ -150,13 +144,14 @@ YES -1804468671 - 272630784 + 268436480 LucidaGrande 13 1044 + Open this URL YES @@ -301,21 +296,16 @@ YES - - - - + + YES - - - - + @@ -325,7 +315,7 @@ {1.79769e+308, 1.79769e+308} {273, 43} - + 256 YES @@ -393,9 +383,10 @@ {774, 554} + {{0, 0}, {1680, 1028}} - {273, 104} + {273, 97} {1.79769e+308, 1.79769e+308} NO 20 @@ -466,30 +457,6 @@ 56 - - - goBack: - - - - 57 - - - - reloadPage: - - - - 58 - - - - goForward: - - - - 59 - navigate: @@ -586,6 +553,22 @@ 69 + + + urlField + + + + 70 + + + + backForwardSelected: + + + + 74 + @@ -673,32 +656,15 @@ YES - - - + - - 45 - - - - - 47 - - - - - 48 - - - 49 @@ -748,6 +714,29 @@ Active Browser + + 73 + + + YES + + + + + + 71 + + + YES + + + + + + 72 + + + @@ -774,22 +763,23 @@ 37.IBViewBoundsToFrameTransform 44.IBEditorWindowLastContentRect 44.IBPluginDependency - 45.IBPluginDependency - 47.IBPluginDependency - 48.IBPluginDependency 50.IBPluginDependency 51.IBPluginDependency 52.IBPluginDependency 53.IBPluginDependency 54.IBPluginDependency + 55.CustomClassName 55.IBPluginDependency 61.IBPluginDependency + 71.IBPluginDependency + 72.IBPluginDependency + 72.IBSegmentedControlInspectorSelectedSegmentMetadataKey YES - {{155, 108}, {774, 554}} + {{155, 115}, {774, 554}} com.apple.InterfaceBuilder.CocoaPlugin - {{155, 108}, {774, 554}} + {{155, 115}, {774, 554}} {196, 240} {{202, 428}, {480, 270}} @@ -813,18 +803,19 @@ P4AAAL+AAABDiwAAxAVAAA - {{234, 662}, {616, 0}} - com.apple.InterfaceBuilder.CocoaPlugin + {{234, 669}, {616, 0}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + URLFieldCell com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + @@ -843,7 +834,7 @@ - 69 + 74 @@ -863,6 +854,7 @@ YES YES + backForwardSelected: goBack: goForward: navigate: @@ -882,12 +874,14 @@ id id id + id YES YES + backForwardSelected: goBack: goForward: navigate: @@ -899,6 +893,10 @@ YES + + backForwardSelected: + id + goBack: id @@ -969,11 +967,13 @@ YES tabBar tabView + urlField YES PSMTabBarControl NSTabView + URLFieldCell @@ -982,6 +982,7 @@ YES tabBar tabView + urlField YES @@ -993,6 +994,10 @@ tabView NSTabView + + urlField + URLFieldCell + @@ -1102,6 +1107,14 @@ ScrollableView.h + + URLFieldCell + NSTextFieldCell + + IBProjectSource + URLFieldCell.h + + YES @@ -1131,20 +1144,18 @@ YES YES - NSGoLeftTemplate - NSGoRightTemplate + NSLeftFacingTriangleTemplate NSMenuCheckmark NSMenuMixedState - NSRefreshTemplate + NSRightFacingTriangleTemplate NSToolbarCustomizeToolbarItemImage YES {9, 9} - {9, 9} {9, 8} {7, 2} - {10, 12} + {9, 9} {32, 32} -- cgit v1.2.3