From 67c9970e544f987fc275c7a5eac67a9123e94868 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Tue, 25 Jan 2011 17:16:17 +0000 Subject: Implemented favicons. Doesn't work for .ICO files svn path=/trunk/netsurf/; revision=11485 --- cocoa/URLFieldCell.m | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'cocoa/URLFieldCell.m') diff --git a/cocoa/URLFieldCell.m b/cocoa/URLFieldCell.m index cb9565aa1..5e5dfdb6b 100644 --- a/cocoa/URLFieldCell.m +++ b/cocoa/URLFieldCell.m @@ -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) { -- cgit v1.2.3