Making sure history popup stays on screen.

svn path=/trunk/netsurf/; revision=11708
This commit is contained in:
Sven Weidauer 2011-02-17 17:23:58 +00:00
parent 2beda0fc07
commit d092b9ca35
4 changed files with 68 additions and 13 deletions

View File

@ -27,5 +27,6 @@
@property (readwrite, assign, nonatomic) struct browser_window *browser;
- (void) updateHistory;
- (NSSize) size;
@end

View File

@ -25,13 +25,6 @@
#import "desktop/history_core.h"
#import "desktop/plotters.h"
static NSRect cocoa_history_rect( struct browser_window *bw )
{
int width, height;
history_size( bw->history, &width, &height );
return cocoa_rect( 0, 0, width, height );
}
@implementation HistoryView
@synthesize browser;
@ -42,9 +35,19 @@ static NSRect cocoa_history_rect( struct browser_window *bw )
[self updateHistory];
}
- (NSSize) size;
{
const CGFloat padding = 10;
int width, height;
history_size( browser->history, &width, &height );
return NSMakeSize( cocoa_px_to_pt( width ) + padding, cocoa_px_to_pt( height ) + padding );
}
- (void) updateHistory;
{
[self setFrameSize: cocoa_history_rect( browser ).size];
[self setFrameSize: [self size]];
[self setNeedsDisplay: YES];
}

View File

@ -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;

View File

@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="1"/>
<integer value="2"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -64,7 +64,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomView" id="820702167">
<reference key="NSNextResponder" ref="753770525"/>
<int key="NSvFlags">274</int>
<int key="NSvFlags">256</int>
<string key="NSFrameSize">{480, 270}</string>
<reference key="NSSuperview" ref="753770525"/>
<string key="NSClassName">HistoryView</string>
@ -239,9 +239,9 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{{489, 207}, {480, 270}}</string>
<string>{{364, 310}, {480, 270}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{489, 207}, {480, 270}}</string>
<string>{{364, 310}, {480, 270}}</string>
<boolean value="NO"/>
<string>{196, 240}</string>
<string>{{202, 428}, {480, 270}}</string>