From d092b9ca354f07a78f0e540ce7da00026f0e534a Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Thu, 17 Feb 2011 17:23:58 +0000 Subject: Making sure history popup stays on screen. svn path=/trunk/netsurf/; revision=11708 --- cocoa/LocalHistoryController.m | 53 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'cocoa/LocalHistoryController.m') diff --git a/cocoa/LocalHistoryController.m b/cocoa/LocalHistoryController.m index 79f842b11..0e90b92c0 100644 --- a/cocoa/LocalHistoryController.m +++ b/cocoa/LocalHistoryController.m @@ -37,8 +37,59 @@ - (void) attachToView: (NSView *) view; { + const CGFloat ScrollerSpace = [NSScroller scrollerWidthForControlSize: NSSmallControlSize];; + + NSDisableScreenUpdates(); + + ArrowWindow *box = (ArrowWindow *)[self window]; + + NSSize newSize = [history size]; + newSize.width += ScrollerSpace; + newSize.height += ScrollerSpace; + + [box setContentSize: newSize]; + [box setArrowPosition: 50]; [history updateHistory]; - [(ArrowWindow *)[self window] attachToView: view]; + [box attachToView: view]; + + NSRect frame = [box frame]; + NSRect screenFrame = [[box screen] visibleFrame]; + + const CGFloat arrowSize = [box arrowSize]; + frame.origin.x += arrowSize; + frame.origin.y += arrowSize; + frame.size.width -= 2 * arrowSize; + frame.size.height -= 2 * arrowSize; + + if (NSMinY( frame ) < NSMinY( screenFrame )) { + const CGFloat delta = NSMinY( screenFrame ) - NSMinY( frame ); + frame.size.height -= delta; + frame.origin.y += delta; + } + + CGFloat arrowPositionChange = 50; + if (NSMaxX( frame ) > NSMaxX( screenFrame )) { + const CGFloat delta = NSMaxX( frame ) - NSMaxX( screenFrame ); + arrowPositionChange += delta; + frame.origin.x -= delta; + } + + if (NSMinX( frame ) < NSMinX( screenFrame )) { + const CGFloat delta = NSMinX( screenFrame ) - NSMinX( frame ); + arrowPositionChange -= delta; + frame.origin.x += delta; + frame.size.width -= delta; + } + + frame.origin.x -= arrowSize; + frame.origin.y -= arrowSize; + frame.size.width += 2 * arrowSize; + frame.size.height += 2 * arrowSize; + + [box setArrowPosition: arrowPositionChange]; + [box setFrame: frame display: YES]; + + NSEnableScreenUpdates(); } - (void) detach; -- cgit v1.2.3