summaryrefslogtreecommitdiff
path: root/cocoa
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-25 17:16:17 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-25 17:16:17 +0000
commit67c9970e544f987fc275c7a5eac67a9123e94868 (patch)
treecbd78a08a266fb7b82a4c31d33de04793084a82a /cocoa
parentcca607fbe85ae6b6ad517a08eee80ac6a6e83c50 (diff)
downloadnetsurf-67c9970e544f987fc275c7a5eac67a9123e94868.tar.gz
netsurf-67c9970e544f987fc275c7a5eac67a9123e94868.tar.bz2
Implemented favicons. Doesn't work for .ICO files
svn path=/trunk/netsurf/; revision=11485
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/BrowserViewController.h2
-rw-r--r--cocoa/BrowserViewController.m1
-rw-r--r--cocoa/BrowserWindowController.h2
-rw-r--r--cocoa/BrowserWindowController.m2
-rw-r--r--cocoa/URLFieldCell.h2
-rw-r--r--cocoa/URLFieldCell.m51
-rw-r--r--cocoa/gui.m15
-rw-r--r--cocoa/res/BrowserWindow.xib17
8 files changed, 83 insertions, 9 deletions
diff --git a/cocoa/BrowserViewController.h b/cocoa/BrowserViewController.h
index fc83054a4..020e49e25 100644
--- a/cocoa/BrowserViewController.h
+++ b/cocoa/BrowserViewController.h
@@ -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;
diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m
index 0d08676be..3d35f8f0a 100644
--- a/cocoa/BrowserViewController.m
+++ b/cocoa/BrowserViewController.m
@@ -37,6 +37,7 @@
@synthesize title;
@synthesize status;
@synthesize isProcessing;
+@synthesize favicon;
- (void) dealloc;
{
diff --git a/cocoa/BrowserWindowController.h b/cocoa/BrowserWindowController.h
index 25482bbfa..333a50429 100644
--- a/cocoa/BrowserWindowController.h
+++ b/cocoa/BrowserWindowController.h
@@ -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;
diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m
index ceb3f9f28..019807513 100644
--- a/cocoa/BrowserWindowController.m
+++ b/cocoa/BrowserWindowController.m
@@ -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;
diff --git a/cocoa/URLFieldCell.h b/cocoa/URLFieldCell.h
index bb0d6572b..38a75a139 100644
--- a/cocoa/URLFieldCell.h
+++ b/cocoa/URLFieldCell.h
@@ -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
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) {
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 03a9b1015..83c0cbd65 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -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)
diff --git a/cocoa/res/BrowserWindow.xib b/cocoa/res/BrowserWindow.xib
index f474162ee..2af21b77b 100644
--- a/cocoa/res/BrowserWindow.xib
+++ b/cocoa/res/BrowserWindow.xib
@@ -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,6 +1094,7 @@
<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>
@@ -1091,6 +1102,10 @@
<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>
</object>