Implemented favicons. Doesn't work for .ICO files

svn path=/trunk/netsurf/; revision=11485
This commit is contained in:
Sven Weidauer 2011-01-25 17:16:17 +00:00
parent cca607fbe8
commit 67c9970e54
8 changed files with 83 additions and 9 deletions

View File

@ -31,6 +31,7 @@ struct browser_window;
NSString *title;
NSString *status;
BOOL isProcessing;
NSImage *favicon;
}
@property (readwrite, assign, nonatomic) struct browser_window *browser;
@ -40,6 +41,7 @@ struct browser_window;
@property (readwrite, copy, nonatomic) NSString *title;
@property (readwrite, copy, nonatomic) NSString *status;
@property (readwrite, assign, nonatomic) BOOL isProcessing;
@property (readwrite, copy, nonatomic) NSImage *favicon;
- initWithBrowser: (struct browser_window *) bw;

View File

@ -37,6 +37,7 @@
@synthesize title;
@synthesize status;
@synthesize isProcessing;
@synthesize favicon;
- (void) dealloc;
{

View File

@ -26,6 +26,7 @@
PSMTabBarControl *tabBar;
NSTabView *tabView;
URLFieldCell *urlField;
NSObjectController *activeBrowserController;
BrowserViewController *activeBrowser;
}
@ -33,6 +34,7 @@
@property (readwrite, retain, nonatomic) IBOutlet PSMTabBarControl *tabBar;
@property (readwrite, retain, nonatomic) IBOutlet NSTabView *tabView;
@property (readwrite, retain, nonatomic) IBOutlet URLFieldCell *urlField;
@property (readwrite, retain, nonatomic) IBOutlet NSObjectController *activeBrowserController;
@property (readwrite, assign, nonatomic) BrowserViewController *activeBrowser;

View File

@ -32,6 +32,7 @@
@synthesize urlField;
@synthesize activeBrowser;
@synthesize activeBrowserController;
- (id) init;
{
@ -62,6 +63,7 @@
[[self window] setAcceptsMouseMovedEvents: YES];
[urlField setRefreshAction: @selector(reloadPage:)];
[urlField bind: @"favicon" toObject: activeBrowserController withKeyPath: @"selection.favicon" options: nil];
}
- (void) addTab: (BrowserViewController *)browser;

View File

@ -21,9 +21,11 @@
@interface URLFieldCell : NSTextFieldCell {
NSButtonCell *refreshCell;
NSImage *favicon;
}
@property (readwrite, assign, nonatomic) SEL refreshAction;
@property (readwrite, assign, nonatomic) id refreshTarget;
@property (readwrite, retain, nonatomic) NSImage *favicon;
@end

View File

@ -24,35 +24,52 @@
@property (readonly, retain, nonatomic) NSButtonCell *refreshCell;
- (NSRect) buttonFrame: (NSRect) cellFrame;
- (NSRect) urlFrame: (NSRect) cellFrame;
- (NSRect) iconFrame: (NSRect) cellFrame;
@end
@implementation URLFieldCell
@synthesize favicon;
- (void) setFavicon: (NSImage *)newIcon;
{
if (favicon != newIcon) {
[favicon release];
favicon = [newIcon retain];
[[self controlView] setNeedsDisplay: YES];
}
}
#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];
[favicon drawInRect: [self iconFrame: cellFrame] fromRect: NSZeroRect
operation: NSCompositeSourceOver fraction: 1.0];
[super drawInteriorWithFrame: [self urlFrame: cellFrame] inView: controlView];
[[self refreshCell] drawInteriorWithFrame: [self buttonFrame: cellFrame]
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
const NSRect textFrame = [self urlFrame: aRect];
[super selectWithFrame: textFrame 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
const NSRect textFrame = [self urlFrame: aRect];
[super editWithFrame: textFrame inView: controlView editor: textObj
delegate: anObject event: theEvent];
}
@ -84,6 +101,26 @@
return buttonRect;
}
- (NSRect) urlFrame: (NSRect) cellFrame;
{
NSRect textFrame = cellFrame;
textFrame.origin.x += cellFrame.size.height;
textFrame.size.width -= cellFrame.size.height + BUTTON_SIZE + PADDING;
return textFrame;
}
- (NSRect) iconFrame: (NSRect)cellFrame;
{
NSRect iconFrame = {
.origin = {
.x = cellFrame.origin.x + PADDING,
.y = cellFrame.origin.y,
},
.size = NSMakeSize( NSHeight( cellFrame ), NSHeight( cellFrame ) )
};
return NSInsetRect( iconFrame, 2 * PADDING, 2 * PADDING );
}
- (NSButtonCell *) refreshCell;
{
if (nil == refreshCell) {

View File

@ -32,6 +32,8 @@
#import "desktop/401login.h"
#import "utils/utils.h"
#import "image/ico.h"
char *default_stylesheet_url;
char *adblock_stylesheet_url;
char *quirks_stylesheet_url;
@ -236,7 +238,18 @@ void gui_window_stop_throbber(struct gui_window *g)
void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
{
// ignore
NSBitmapImageRep *bmp = icon != NULL ? (NSBitmapImageRep *)content_get_bitmap( icon ) : NULL;
NSImage *image = nil;
if (bmp != nil) {
image = [[NSImage alloc] initWithSize: NSMakeSize( 32, 32 )];
[image addRepresentation: bmp];
} else {
image = [[NSApp applicationIconImage] retain];
}
[(BrowserViewController *)g setFavicon: image];
[image release];
}
void gui_window_set_search_ico(hlcache_handle *ico)

View File

@ -638,6 +638,14 @@
</object>
<int key="connectionID">79</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">activeBrowserController</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="177599630"/>
</object>
<int key="connectionID">80</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -931,7 +939,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">79</int>
<int key="maxID">80</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -1069,12 +1077,14 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>activeBrowserController</string>
<string>tabBar</string>
<string>tabView</string>
<string>urlField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSObjectController</string>
<string>PSMTabBarControl</string>
<string>NSTabView</string>
<string>URLFieldCell</string>
@ -1084,12 +1094,17 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>activeBrowserController</string>
<string>tabBar</string>
<string>tabView</string>
<string>urlField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">activeBrowserController</string>
<string key="candidateClassName">NSObjectController</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">tabBar</string>
<string key="candidateClassName">PSMTabBarControl</string>