From e21cab6a7fc68b311a79a067b408da23173fb255 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 24 Jan 2011 15:01:34 +0000 Subject: [PATCH] Added local history overlay svn path=/trunk/netsurf/; revision=11479 --- cocoa/BrowserView.h | 6 + cocoa/BrowserView.m | 35 ++++++ cocoa/BrowserViewController.h | 2 + cocoa/BrowserViewController.m | 5 + cocoa/HistoryView.h | 41 +++++++ cocoa/HistoryView.m | 109 +++++++++++++++++ cocoa/Makefile.target | 1 + cocoa/NetSurf.xcodeproj/project.pbxproj | 6 + cocoa/Prefix.pch | 5 +- cocoa/res/BrowserWindow.xib | 153 +++++++++++++++++++----- 10 files changed, 335 insertions(+), 28 deletions(-) create mode 100644 cocoa/HistoryView.h create mode 100644 cocoa/HistoryView.m diff --git a/cocoa/BrowserView.h b/cocoa/BrowserView.h index 3a6be0604..947825b24 100644 --- a/cocoa/BrowserView.h +++ b/cocoa/BrowserView.h @@ -19,6 +19,7 @@ #import #import "ScrollableView.h" +@class HistoryView; @interface BrowserView : ScrollableView { struct browser_window *browser; @@ -33,6 +34,9 @@ NSPoint dragStart; BOOL isResizing; + + HistoryView *history; + BOOL historyVisible; } @property (readwrite, assign, nonatomic) struct browser_window *browser; @@ -42,4 +46,6 @@ - (void) removeCaret; - (void) addCaretAt: (NSPoint) point height: (CGFloat) height; +- (void) toggleHistory; + @end diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index e20c053a6..ba0874c3a 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -17,6 +17,7 @@ */ #import "BrowserView.h" +#import "HistoryView.h" #import "desktop/browser.h" #import "desktop/history_core.h" @@ -27,6 +28,11 @@ #import "cocoa/font.h" +@interface BrowserView () + +@end + + @implementation BrowserView @synthesize browser; @@ -39,6 +45,8 @@ static const NSTimeInterval CaretBlinkTime = 0.8; - (void) dealloc; { [self setCaretTimer: nil]; + [history release]; + [super dealloc]; } @@ -173,6 +181,11 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) mouseUp: (NSEvent *)theEvent; { + if (historyVisible) { + [self toggleHistory]; + return; + } + NSPoint location = [self convertMousePoint: theEvent]; browser_mouse_state modifierFlags = cocoa_mouse_flags_for_event( theEvent ); @@ -326,6 +339,28 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) browser_window_key_press( browser, KEY_PASTE ); } +- (void) toggleHistory; +{ + if (!historyVisible) { + if (nil == history) { + history = [[HistoryView alloc] initWithBrowser: browser]; + [history setDelegate: self]; + } + [self addSubview: history]; + + historyVisible = YES; + } else { + [history removeFromSuperview]; + historyVisible = NO; + } +} + + +- (void) historyViewDidSelectItem: (HistoryView *) history; +{ + [history removeFromSuperview]; + historyVisible = NO; +} - (BOOL) acceptsFirstResponder; { diff --git a/cocoa/BrowserViewController.h b/cocoa/BrowserViewController.h index 55bf3d37f..fc83054a4 100644 --- a/cocoa/BrowserViewController.h +++ b/cocoa/BrowserViewController.h @@ -47,6 +47,8 @@ struct browser_window; - (IBAction) backForwardSelected: (id) sender; +- (IBAction) showHistory: (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 0d08676be..f4bc5abce 100644 --- a/cocoa/BrowserViewController.m +++ b/cocoa/BrowserViewController.m @@ -151,4 +151,9 @@ static inline bool compare_float( float a, float b ) } +- (IBAction) showHistory: (id) sender; +{ + [browserView toggleHistory]; +} + @end diff --git a/cocoa/HistoryView.h b/cocoa/HistoryView.h new file mode 100644 index 000000000..974b649d5 --- /dev/null +++ b/cocoa/HistoryView.h @@ -0,0 +1,41 @@ +/* + * 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 + +@class HistoryView; + +@protocol HistoryViewDelegate + +- (void) historyViewDidSelectItem: (HistoryView *) history; + +@end + + +@interface HistoryView : NSView { + struct browser_window *browser; + id delegate; +} + +@property (readwrite, assign, nonatomic) struct browser_window *browser; +@property (readwrite, assign, nonatomic) id delegate; + +- (id) initWithBrowser: (struct browser_window *)bw; +- (void) updateHistory; + +@end diff --git a/cocoa/HistoryView.m b/cocoa/HistoryView.m new file mode 100644 index 000000000..390256efe --- /dev/null +++ b/cocoa/HistoryView.m @@ -0,0 +1,109 @@ +/* + * 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 "HistoryView.h" + +#import "desktop/browser.h" +#import "desktop/history_core.h" +#import "desktop/plotters.h" +#import "cocoa/font.h" + +static NSRect cocoa_history_rect( struct browser_window *bw ) +{ + int width, height; + history_size( bw->history, &width, &height ); + return NSMakeRect( 0, 0, width + 10, height + 10 ); +} + +@implementation HistoryView + +@synthesize browser; +@synthesize delegate; + +- (id)initWithBrowser: (struct browser_window *)bw; +{ + NSParameterAssert( NULL != bw ); + if ((self = [super initWithFrame: cocoa_history_rect( bw )]) == nil) return nil; + + browser = bw; + + return self; +} + +- (void) updateHistory; +{ + [self setFrameSize: cocoa_history_rect( browser ).size]; + + [self setNeedsDisplay: YES]; +} + +- (void) recenter; +{ + NSView *superView = [self superview]; + NSRect visibleRect = [superView visibleRect]; + NSRect rect = [self frame]; + NSRect frame = [superView frame]; + + rect.origin.x = visibleRect.origin.x + (NSWidth( visibleRect ) - NSWidth( rect )) / 2.0; + rect.origin.x = MAX( rect.origin.x, frame.origin.x ); + + rect.origin.y = visibleRect.origin.y + (NSHeight( visibleRect ) - NSHeight( rect )) / 2.0; + rect.origin.y = MAX( rect.origin.y, frame.origin.y ); + + [self setFrameOrigin: rect.origin]; +} + +- (void) viewDidMoveToSuperview; +{ + [self updateHistory]; + [self recenter]; +} + +- (void) drawRect: (NSRect)rect; +{ + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: NSInsetRect( [self bounds], 5, 5 ) + xRadius: 10 yRadius: 10]; + + [[NSColor colorWithDeviceWhite: 0 alpha: 0.8] setFill]; + [path fill]; + + [path setLineWidth: 2.0]; + [[NSColor whiteColor] set]; + [path stroke]; + + cocoa_set_font_scale_factor( 1.0 ); + plot.clip( NSMinX( rect ), NSMinY( rect ), NSMaxX( rect ), NSMaxY( rect ) ); + history_redraw( browser->history ); +} + +- (void) mouseUp: (NSEvent *)theEvent; +{ + const NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + const bool newWindow = [theEvent modifierFlags] & NSCommandKeyMask; + if (history_click( browser, browser->history, location.x, location.y, newWindow )) { + [delegate historyViewDidSelectItem: self]; + } +} + +- (BOOL) isFlipped; +{ + return YES; +} + + +@end diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target index 95f8e5c83..8c14340fd 100644 --- a/cocoa/Makefile.target +++ b/cocoa/Makefile.target @@ -73,6 +73,7 @@ S_COCOA := \ ScrollableView.m \ URLFieldCell.m \ TreeView.m \ + HistoryView.m \ bitmap.m \ fetch.m \ font.m \ diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index dd48ae3c0..8d059bbf7 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -141,6 +141,7 @@ 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 */; }; + 26EC3C4412ED8202000A960C /* HistoryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 26EC3C4312ED8202000A960C /* HistoryView.m */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -404,6 +405,8 @@ 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 = ""; }; + 26EC3C4212ED8202000A960C /* HistoryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryView.h; sourceTree = ""; }; + 26EC3C4312ED8202000A960C /* HistoryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryView.m; sourceTree = ""; }; 8D1107320486CEB800E47090 /* NetSurf.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetSurf.app; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -800,6 +803,8 @@ 2622F1D612DCD84600CD5A62 /* TreeView.m */, 26EC3B6812ED62C0000A960C /* URLFieldCell.h */, 26EC3B6912ED62C0000A960C /* URLFieldCell.m */, + 26EC3C4212ED8202000A960C /* HistoryView.h */, + 26EC3C4312ED8202000A960C /* HistoryView.m */, ); name = Views; sourceTree = ""; @@ -1068,6 +1073,7 @@ 26CDD00312E70F56004FC66B /* BrowserWindowController.m in Sources */, 26CDD0F612E726E0004FC66B /* BrowserViewController.m in Sources */, 26EC3B6A12ED62C0000A960C /* URLFieldCell.m in Sources */, + 26EC3C4412ED8202000A960C /* HistoryView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cocoa/Prefix.pch b/cocoa/Prefix.pch index 0516a0bf7..0b11cf1e3 100644 --- a/cocoa/Prefix.pch +++ b/cocoa/Prefix.pch @@ -4,4 +4,7 @@ #import #endif -#undef offsetof \ No newline at end of file +#undef offsetof + +#define HISTORY_COLOUR_BACKGROUND 0x000000 +#define HISTORY_COLOUR_FOREGROUND 0xFFFFFF \ No newline at end of file diff --git a/cocoa/res/BrowserWindow.xib b/cocoa/res/BrowserWindow.xib index d9e3e3de9..50d94f165 100644 --- a/cocoa/res/BrowserWindow.xib +++ b/cocoa/res/BrowserWindow.xib @@ -60,6 +60,7 @@ YES YES + 6D497003-6D4B-4335-ADCE-368C7CD87371 BC5CEBFC-2E3B-420C-A75F-BE0760149C45 E2E89C48-DD3F-47A5-9E6C-25985A970F69 NSToolbarCustomizeToolbarItem @@ -69,19 +70,68 @@ YES - + + + 6D497003-6D4B-4335-ADCE-368C7CD87371 + + History + History + + + + 268 + {{8, 14}, {30, 25}} + + + YES + + -2080244224 + 134217728 + + + LucidaGrande + 13 + 1044 + + + -2033958657 + 163 + + NSImage + NSIconViewTemplate + + + + 400 + 75 + + + + + + {22, 25} + {32, 25} + YES + YES + 0 + YES + 0 + + BC5CEBFC-2E3B-420C-A75F-BE0760149C45 Back/Forward - - + + 268 {{5, 14}, {71, 25}} + + YES - + 67239424 0 @@ -89,7 +139,7 @@ 13 16 - + YES @@ -123,7 +173,7 @@ {71, 25} - {104, 25} + {71, 25} YES YES 0 @@ -138,19 +188,17 @@ URL - + 268 {{0, 14}, {96, 22}} + + YES -1804468671 268436480 - - LucidaGrande - 13 - 1044 - + Open this URL YES @@ -296,7 +344,8 @@ YES - + + @@ -305,7 +354,8 @@ YES - + + @@ -565,10 +615,18 @@ backForwardSelected: - + 74 + + + showHistory: + + + + 78 + @@ -661,7 +719,8 @@ - + + @@ -716,26 +775,49 @@ 73 - + YES - + 71 - + YES - + - + 72 - - + + + + + 77 + + + YES + + + + + + 75 + + + YES + + + + + + 76 + + @@ -774,12 +856,14 @@ 71.IBPluginDependency 72.IBPluginDependency 72.IBSegmentedControlInspectorSelectedSegmentMetadataKey + 75.IBPluginDependency + 76.IBPluginDependency YES - {{155, 115}, {774, 554}} + {{343, 318}, {774, 554}} com.apple.InterfaceBuilder.CocoaPlugin - {{155, 115}, {774, 554}} + {{343, 318}, {774, 554}} {196, 240} {{202, 428}, {480, 270}} @@ -803,7 +887,7 @@ P4AAAL+AAABDiwAAxAVAAA - {{234, 669}, {616, 0}} + {{422, 872}, {616, 0}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -816,6 +900,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -834,7 +920,7 @@ - 74 + 78 @@ -842,6 +928,17 @@ BrowserView ScrollableView + + showHistory: + id + + + showHistory: + + showHistory: + id + + IBProjectSource BrowserView.h @@ -1144,6 +1241,7 @@ YES YES + NSIconViewTemplate NSLeftFacingTriangleTemplate NSMenuCheckmark NSMenuMixedState @@ -1152,6 +1250,7 @@ YES + {11, 10} {9, 9} {9, 8} {7, 2}