Added local history overlay

svn path=/trunk/netsurf/; revision=11479
This commit is contained in:
Sven Weidauer 2011-01-24 15:01:34 +00:00
parent 840fb0b9aa
commit e21cab6a7f
10 changed files with 335 additions and 28 deletions

View File

@ -19,6 +19,7 @@
#import <Cocoa/Cocoa.h>
#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

View File

@ -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 () <HistoryViewDelegate>
@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;
{

View File

@ -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;

View File

@ -151,4 +151,9 @@ static inline bool compare_float( float a, float b )
}
- (IBAction) showHistory: (id) sender;
{
[browserView toggleHistory];
}
@end

41
cocoa/HistoryView.h Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#import <Cocoa/Cocoa.h>
@class HistoryView;
@protocol HistoryViewDelegate
- (void) historyViewDidSelectItem: (HistoryView *) history;
@end
@interface HistoryView : NSView {
struct browser_window *browser;
id <HistoryViewDelegate> delegate;
}
@property (readwrite, assign, nonatomic) struct browser_window *browser;
@property (readwrite, assign, nonatomic) id <HistoryViewDelegate> delegate;
- (id) initWithBrowser: (struct browser_window *)bw;
- (void) updateHistory;
@end

109
cocoa/HistoryView.m Normal file
View File

@ -0,0 +1,109 @@
/*
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -73,6 +73,7 @@ S_COCOA := \
ScrollableView.m \
URLFieldCell.m \
TreeView.m \
HistoryView.m \
bitmap.m \
fetch.m \
font.m \

View File

@ -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 = "<group>"; };
26EC3B6812ED62C0000A960C /* URLFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = URLFieldCell.h; sourceTree = "<group>"; };
26EC3B6912ED62C0000A960C /* URLFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = URLFieldCell.m; sourceTree = "<group>"; };
26EC3C4212ED8202000A960C /* HistoryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryView.h; sourceTree = "<group>"; };
26EC3C4312ED8202000A960C /* HistoryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryView.m; sourceTree = "<group>"; };
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 = "<group>";
@ -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;
};

View File

@ -4,4 +4,7 @@
#import <Cocoa/Cocoa.h>
#endif
#undef offsetof
#undef offsetof
#define HISTORY_COLOUR_BACKGROUND 0x000000
#define HISTORY_COLOUR_FOREGROUND 0xFFFFFF

View File

@ -60,6 +60,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>6D497003-6D4B-4335-ADCE-368C7CD87371</string>
<string>BC5CEBFC-2E3B-420C-A75F-BE0760149C45</string>
<string>E2E89C48-DD3F-47A5-9E6C-25985A970F69</string>
<string>NSToolbarCustomizeToolbarItem</string>
@ -69,19 +70,68 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSToolbarItem" id="768608234">
<object class="NSToolbarItem" id="16676378">
<object class="NSMutableString" key="NSToolbarItemIdentifier">
<characters key="NS.bytes">6D497003-6D4B-4335-ADCE-368C7CD87371</characters>
</object>
<string key="NSToolbarItemLabel">History</string>
<string key="NSToolbarItemPaletteLabel">History</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSButton" key="NSToolbarItemView" id="229385913">
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{8, 14}, {30, 25}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="296571644">
<int key="NSCellFlags">-2080244224</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents"/>
<object class="NSFont" key="NSSupport" id="770988704">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">13</double>
<int key="NSfFlags">1044</int>
</object>
<reference key="NSControlView" ref="229385913"/>
<int key="NSButtonFlags">-2033958657</int>
<int key="NSButtonFlags2">163</int>
<object class="NSCustomResource" key="NSNormalImage" id="235904051">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSIconViewTemplate</string>
</object>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
</object>
</object>
<reference key="NSToolbarItemImage" ref="235904051"/>
<nil key="NSToolbarItemTarget"/>
<nil key="NSToolbarItemAction"/>
<string key="NSToolbarItemMinSize">{22, 25}</string>
<string key="NSToolbarItemMaxSize">{32, 25}</string>
<bool key="NSToolbarItemEnabled">YES</bool>
<bool key="NSToolbarItemAutovalidates">YES</bool>
<int key="NSToolbarItemTag">0</int>
<bool key="NSToolbarIsUserRemovable">YES</bool>
<int key="NSToolbarItemVisibilityPriority">0</int>
</object>
<object class="NSToolbarItem" id="685547192">
<object class="NSMutableString" key="NSToolbarItemIdentifier">
<characters key="NS.bytes">BC5CEBFC-2E3B-420C-A75F-BE0760149C45</characters>
</object>
<string key="NSToolbarItemLabel"/>
<string key="NSToolbarItemPaletteLabel">Back/Forward</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSSegmentedControl" key="NSToolbarItemView" id="262335400">
<nil key="NSNextResponder"/>
<object class="NSSegmentedControl" key="NSToolbarItemView" id="692457026">
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{5, 14}, {71, 25}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSSegmentedCell" key="NSCell" id="754779730">
<object class="NSSegmentedCell" key="NSCell" id="845979064">
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">0</int>
<object class="NSFont" key="NSSupport">
@ -89,7 +139,7 @@
<double key="NSSize">13</double>
<int key="NSfFlags">16</int>
</object>
<reference key="NSControlView" ref="262335400"/>
<reference key="NSControlView" ref="692457026"/>
<object class="NSMutableArray" key="NSSegmentImages">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSSegmentItem">
@ -123,7 +173,7 @@
<nil key="NSToolbarItemTarget"/>
<nil key="NSToolbarItemAction"/>
<string key="NSToolbarItemMinSize">{71, 25}</string>
<string key="NSToolbarItemMaxSize">{104, 25}</string>
<string key="NSToolbarItemMaxSize">{71, 25}</string>
<bool key="NSToolbarItemEnabled">YES</bool>
<bool key="NSToolbarItemAutovalidates">YES</bool>
<int key="NSToolbarItemTag">0</int>
@ -138,19 +188,17 @@
<string key="NSToolbarItemPaletteLabel">URL</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSTextField" key="NSToolbarItemView" id="77748234">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {96, 22}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="1053649244">
<int key="NSCellFlags">-1804468671</int>
<int key="NSCellFlags2">268436480</int>
<string key="NSContents"/>
<object class="NSFont" key="NSSupport" id="770988704">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">13</double>
<int key="NSfFlags">1044</int>
</object>
<reference key="NSSupport" ref="770988704"/>
<string key="NSPlaceholderString">Open this URL</string>
<reference key="NSControlView" ref="77748234"/>
<bool key="NSDrawsBackground">YES</bool>
@ -296,7 +344,8 @@
</object>
<object class="NSArray" key="NSToolbarIBAllowedItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="768608234"/>
<reference ref="685547192"/>
<reference ref="16676378"/>
<reference ref="192029103"/>
<reference ref="1012010237"/>
<reference ref="661775936"/>
@ -305,7 +354,8 @@
</object>
<object class="NSMutableArray" key="NSToolbarIBDefaultItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="768608234"/>
<reference ref="685547192"/>
<reference ref="16676378"/>
<reference ref="192029103"/>
</object>
<object class="NSMutableArray" key="NSToolbarIBSelectableItems">
@ -565,10 +615,18 @@
<object class="IBActionConnection" key="connection">
<string key="label">backForwardSelected:</string>
<reference key="source" ref="1003"/>
<reference key="destination" ref="768608234"/>
<reference key="destination" ref="685547192"/>
</object>
<int key="connectionID">74</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">showHistory:</string>
<reference key="source" ref="1003"/>
<reference key="destination" ref="229385913"/>
</object>
<int key="connectionID">78</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -661,7 +719,8 @@
<reference ref="276197344"/>
<reference ref="568640167"/>
<reference ref="661775936"/>
<reference ref="768608234"/>
<reference ref="685547192"/>
<reference ref="16676378"/>
</object>
<reference key="parent" ref="1005"/>
</object>
@ -716,26 +775,49 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">73</int>
<reference key="object" ref="768608234"/>
<reference key="object" ref="685547192"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="262335400"/>
<reference ref="692457026"/>
</object>
<reference key="parent" ref="71746575"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">71</int>
<reference key="object" ref="262335400"/>
<reference key="object" ref="692457026"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="754779730"/>
<reference ref="845979064"/>
</object>
<reference key="parent" ref="768608234"/>
<reference key="parent" ref="685547192"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">72</int>
<reference key="object" ref="754779730"/>
<reference key="parent" ref="262335400"/>
<reference key="object" ref="845979064"/>
<reference key="parent" ref="692457026"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">77</int>
<reference key="object" ref="16676378"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="229385913"/>
</object>
<reference key="parent" ref="71746575"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">75</int>
<reference key="object" ref="229385913"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="296571644"/>
</object>
<reference key="parent" ref="16676378"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">76</int>
<reference key="object" ref="296571644"/>
<reference key="parent" ref="229385913"/>
</object>
</object>
</object>
@ -774,12 +856,14 @@
<string>71.IBPluginDependency</string>
<string>72.IBPluginDependency</string>
<string>72.IBSegmentedControlInspectorSelectedSegmentMetadataKey</string>
<string>75.IBPluginDependency</string>
<string>76.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{{155, 115}, {774, 554}}</string>
<string>{{343, 318}, {774, 554}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{155, 115}, {774, 554}}</string>
<string>{{343, 318}, {774, 554}}</string>
<integer value="1"/>
<string>{196, 240}</string>
<string>{{202, 428}, {480, 270}}</string>
@ -803,7 +887,7 @@
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABDiwAAxAVAAA</bytes>
</object>
<string>{{234, 669}, {616, 0}}</string>
<string>{{422, 872}, {616, 0}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@ -816,6 +900,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@ -834,7 +920,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">74</int>
<int key="maxID">78</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -842,6 +928,17 @@
<object class="IBPartialClassDescription">
<string key="className">BrowserView</string>
<string key="superclassName">ScrollableView</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">showHistory:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">showHistory:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">showHistory:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">BrowserView.h</string>
@ -1144,6 +1241,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSIconViewTemplate</string>
<string>NSLeftFacingTriangleTemplate</string>
<string>NSMenuCheckmark</string>
<string>NSMenuMixedState</string>
@ -1152,6 +1250,7 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{11, 10}</string>
<string>{9, 9}</string>
<string>{9, 8}</string>
<string>{7, 2}</string>