From f56b20994ea693d36b2bcc8c99942f50e1fd6814 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Fri, 28 Jan 2011 13:22:40 +0000 Subject: [PATCH] Keyboard scrolling. svn path=/trunk/netsurf/; revision=11517 --- cocoa/BrowserView.m | 59 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index b1511216a..d5e8d0aff 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -29,6 +29,14 @@ #import "cocoa/font.h" #import "cocoa/plotter.h" +@interface BrowserView () + +- (void) scrollHorizontal: (CGFloat) amount; +- (void) scrollVertical: (CGFloat) amount; +- (CGFloat) pageScroll; + +@end + @implementation BrowserView @synthesize browser; @@ -244,22 +252,26 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) moveLeft: (id)sender; { - browser_window_key_press( browser, KEY_LEFT ); + if (browser_window_key_press( browser, KEY_LEFT )) return; + [self scrollHorizontal: -[[self enclosingScrollView] horizontalLineScroll]]; } - (void) moveRight: (id)sender; { - browser_window_key_press( browser, KEY_RIGHT ); + if (browser_window_key_press( browser, KEY_RIGHT )) return; + [self scrollHorizontal: [[self enclosingScrollView] horizontalLineScroll]]; } - (void) moveUp: (id)sender; { - browser_window_key_press( browser, KEY_UP ); + if (browser_window_key_press( browser, KEY_UP )) return; + [self scrollVertical: -[[self enclosingScrollView] lineScroll]]; } - (void) moveDown: (id)sender; { if (browser_window_key_press( browser, KEY_DOWN )) return; + [self scrollVertical: [[self enclosingScrollView] lineScroll]]; } - (void) deleteBackward: (id)sender; @@ -279,12 +291,14 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) scrollPageUp: (id)sender; { - browser_window_key_press( browser, KEY_PAGE_UP ); + if (browser_window_key_press( browser, KEY_PAGE_UP )) return; + [self scrollVertical: -[self pageScroll]]; } - (void) scrollPageDown: (id)sender; { - browser_window_key_press( browser, KEY_PAGE_DOWN ); + if (browser_window_key_press( browser, KEY_PAGE_DOWN )) return; + [self scrollVertical: [self pageScroll]]; } - (void) insertTab: (id)sender; @@ -309,7 +323,14 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) moveToBeginningOfDocument: (id)sender; { - browser_window_key_press( browser, KEY_TEXT_START ); + if (browser_window_key_press( browser, KEY_TEXT_START )) return; +} + +- (void) scrollToBeginningOfDocument: (id) sender; +{ + NSPoint origin = [self visibleRect].origin; + origin.y = 0; + [self scrollPoint: origin]; } - (void) moveToEndOfDocument: (id)sender; @@ -317,6 +338,13 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) browser_window_key_press( browser, KEY_TEXT_END ); } +- (void) scrollToEndOfDocument: (id) sender; +{ + NSPoint origin = [self visibleRect].origin; + origin.y = NSHeight( [self frame] ); + [self scrollPoint: origin]; +} + - (void) insertNewline: (id)sender; { browser_window_key_press( browser, KEY_NL ); @@ -375,4 +403,23 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) } } +- (void) scrollHorizontal: (CGFloat) amount; +{ + NSPoint currentPoint = [self visibleRect].origin; + currentPoint.x += amount; + [self scrollPoint: currentPoint]; +} + +- (void) scrollVertical: (CGFloat) amount; +{ + NSPoint currentPoint = [self visibleRect].origin; + currentPoint.y += amount; + [self scrollPoint: currentPoint]; +} + +- (CGFloat) pageScroll; +{ + return NSHeight( [[self superview] frame] ) - [[self enclosingScrollView] pageScroll]; +} + @end