summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-06-22 22:08:42 +0200
committerSven Weidauer <sven@5sw.de>2017-06-22 22:08:42 +0200
commitef7b8258405761d44731cb4967c923a99bf72e37 (patch)
tree42dcf3382ab232824ab97cc0d885f4140407cee7
parent2e5519f22742e7f5751d8a6098e8479bfbc9919b (diff)
downloadnetsurf-ef7b8258405761d44731cb4967c923a99bf72e37.tar.gz
netsurf-ef7b8258405761d44731cb4967c923a99bf72e37.tar.bz2
Update history view.
-rw-r--r--frontends/cocoa/HistoryView.h10
-rw-r--r--frontends/cocoa/HistoryView.m146
-rw-r--r--frontends/cocoa/LocalHistoryController.m2
3 files changed, 70 insertions, 88 deletions
diff --git a/frontends/cocoa/HistoryView.h b/frontends/cocoa/HistoryView.h
index 42e73dd76..0fa2af36a 100644
--- a/frontends/cocoa/HistoryView.h
+++ b/frontends/cocoa/HistoryView.h
@@ -18,17 +18,13 @@
#import <Cocoa/Cocoa.h>
-@class HistoryView;
@class BrowserView;
-@interface HistoryView : NSView {
- struct browser_window *browser;
- NSMutableArray *toolTips;
-}
+@interface HistoryView : NSView
-@property (readwrite, retain, nonatomic) BrowserView *browser;
+@property (readwrite, nonatomic) BrowserView *browser;
+@property (readonly, nonatomic) NSSize size;
- (void)updateHistory;
-- (NSSize)size;
@end
diff --git a/frontends/cocoa/HistoryView.m b/frontends/cocoa/HistoryView.m
index 94d526123..798a3081e 100644
--- a/frontends/cocoa/HistoryView.m
+++ b/frontends/cocoa/HistoryView.m
@@ -22,125 +22,111 @@
#import "cocoa/plotter.h"
#import "cocoa/LocalHistoryController.h"
#import "cocoa/BrowserView.h"
-
+#import "utils/errors.h"
+#import "netsurf/core_window.h"
#import "desktop/browser_history.h"
+#import "desktop/local_history.h"
#import "netsurf/plotters.h"
-@implementation HistoryView
-
-@synthesize browser = browserView;
-
-- (void)setBrowser:(BrowserView *)bw
-{
- browserView = bw;
- browser = [bw browser];
- [self updateHistory];
+@interface HistoryView () {
+ struct local_history_session *_session;
}
-- (NSSize)size
-{
- int width, height;
- browser_window_history_size(browser, &width, &height);
+@property (nonatomic) NSMutableArray *toolTips;
+@property (readwrite, nonatomic) NSSize size;
- return cocoa_size(width, height);
-}
+@end
-- (void)updateHistory
+static nserror invalidate(struct core_window *cw, const struct rect *rect)
{
- [self setFrameSize:[self size]];
- [self setNeedsDisplay:YES];
+ return NSERROR_NOT_IMPLEMENTED;
}
-- (void)drawRect:(NSRect)rect
+static void update_size(struct core_window *cw, int width, int height)
{
- [[NSColor clearColor] set];
- [NSBezierPath fillRect:rect];
-
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &cocoa_plotters
- };
-
- cocoa_set_clip(rect);
-
- browser_window_history_redraw(browser, &ctx);
+ HistoryView *view = (__bridge HistoryView *)cw;
+ NSSize size = cocoa_size(width, height);
+ view.size = size;
}
-- (void)mouseUp:(NSEvent *)theEvent
+static void scroll_visible(struct core_window *cw, const struct rect *r)
{
- const NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
- const bool newWindow = [theEvent modifierFlags] & NSEventModifierFlagCommand;
- if (browser_window_history_click(browser,
- cocoa_pt_to_px(location.x), cocoa_pt_to_px(location.y),
- newWindow)) {
- [browserView setHistoryVisible:NO];
- }
}
-- (BOOL)isFlipped
+static void get_window_dimensions(struct core_window *cw, int *width, int *height)
{
- return YES;
}
-- (void)mouseEntered:(NSEvent *)event
+static void drag_status(struct core_window *cw, core_window_drag_status ds)
{
- [[NSCursor pointingHandCursor] set];
}
-- (void)mouseExited:(NSEvent *)event
+static struct core_window_callback_table history_view_table = {
+ .invalidate = invalidate,
+ .update_size = update_size,
+ .scroll_visible = scroll_visible,
+ .get_window_dimensions = get_window_dimensions,
+ .drag_status = drag_status
+};
+
+@implementation HistoryView
+
+- (void)updateHistory
{
- [[NSCursor arrowCursor] set];
+ if (_session) {
+ local_history_set(_session, self.browser.browser);
+ } else {
+ local_history_init(&history_view_table, (__bridge void *)self, self.browser.browser, &_session);
+ }
+
+ self.frameSize = self.size;
}
-static bool cursor_rects_cb(const struct browser_window *bw, int x0, int y0, int x1, int y1,
- const struct history_entry *page, void *user_data)
+- (void)dealloc
{
- HistoryView *view = (__bridge HistoryView *)user_data;
-
- NSRect rect = NSIntersectionRect([view visibleRect], cocoa_rect(x0, y0, x1, y1));
- if (!NSIsEmptyRect(rect)) {
-
- NSString *toolTip = [NSString stringWithFormat:@"%s\n%s", browser_window_history_entry_get_title(page),
- browser_window_history_entry_get_url(page)];
-
- [view addToolTipRect:rect owner:toolTip userData:nil];
- NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:rect
- options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp
- owner:view
- userInfo:nil];
- [view addTrackingArea:area];
+ if (_session) {
+ local_history_fini(_session);
}
-
- return true;
}
-- (NSToolTipTag)addToolTipRect:(NSRect)rect owner:(id)owner userData:(void *)userData
+- (void)drawRect:(NSRect)rect
{
- if (toolTips == nil)
- toolTips = [[NSMutableArray alloc] init];
- [toolTips addObject:owner];
+ if (!_session) return;
- return [super addToolTipRect:rect owner:owner userData:userData];
-}
+ struct redraw_context context = {
+ .interactive = true,
+ .background_images = false,
+ .plot = &cocoa_plotters,
+ };
-- (void)removeAllToolTips
-{
- [super removeAllToolTips];
- [toolTips removeAllObjects];
+ cocoa_set_clip(rect);
+
+ struct rect clipRect = {
+ .x0 = cocoa_pt_to_px(CGRectGetMinX(rect)),
+ .y0 = cocoa_pt_to_px(CGRectGetMinY(rect)),
+ .x1 = cocoa_pt_to_px(CGRectGetMaxX(rect)),
+ .y1 = cocoa_pt_to_px(CGRectGetMaxY(rect))
+ };
+ local_history_redraw(_session, 0, 0, &clipRect, &context);
}
-- (void)updateTrackingAreas
+- (void)mouseUp:(NSEvent *)theEvent
{
- [self removeAllToolTips];
+ if (!_session) return;
- for (NSTrackingArea *area in [self trackingAreas]) {
- [self removeTrackingArea:area];
+ CGPoint location = [self convertPoint: theEvent.locationInWindow fromView: nil];
+
+ browser_mouse_state state = BROWSER_MOUSE_PRESS_1;
+ if (theEvent.modifierFlags & NSEventModifierFlagCommand) {
+ state = BROWSER_MOUSE_PRESS_2;
}
- browser_window_history_enumerate(browser, cursor_rects_cb, (__bridge void *)self);
+ local_history_mouse_action(_session, state, cocoa_pt_to_px(location.x), cocoa_pt_to_px(location.y));
+}
- [super updateTrackingAreas];
+- (BOOL)isFlipped
+{
+ return YES;
}
@end
diff --git a/frontends/cocoa/LocalHistoryController.m b/frontends/cocoa/LocalHistoryController.m
index b54359ffc..1a60783cb 100644
--- a/frontends/cocoa/LocalHistoryController.m
+++ b/frontends/cocoa/LocalHistoryController.m
@@ -40,9 +40,9 @@
ArrowWindow *box = (ArrowWindow *)[self window];
+ [self.history updateHistory];
box.contentSize = self.history.size;
[box setArrowPosition:50];
- [self.history updateHistory];
[box attachToView:view];
NSRect frame = [box frame];