From 9bf0edb5dfe636909339aa582d2e3011fe92ee3e Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Tue, 14 Dec 2010 12:12:25 -0800 Subject: [PATCH] Implement CPScrollView scrollToBeginningOfDocument: and scrollToEndOfDocument:. Also ensures that the home/end DOM keys were properly mapped to their Cocoa equivalents, so that home/end will trigger scrollToBeginningOfDocument:/scrollToEndOfDocument:. --- AppKit/CPScrollView.j | 23 ++++++++++++++++++++-- AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/AppKit/CPScrollView.j b/AppKit/CPScrollView.j index 69d128edb..0bc213570 100644 --- a/AppKit/CPScrollView.j +++ b/AppKit/CPScrollView.j @@ -974,6 +974,20 @@ [self moveByOffset:CGSizeMake(0.0, _CGRectGetHeight(contentBounds) - _verticalPageScroll)]; } +- (void)scrollToBeginningOfDocument:(id)sender +{ + var contentBounds = [_contentView bounds]; + [self _moveToPoint:_CGPointMakeZero()]; +} + +- (void)scrollToEndOfDocument:(id)sender +{ + var contentBounds = [_contentView bounds], + documentFrame = [[self documentView] frame]; + + [self _moveToPoint:_CGPointMake(0.0, _CGRectGetHeight(documentFrame) - _CGRectGetHeight(contentBounds))] +} + - (void)moveLeft:(id)sender { [self moveByOffset:CGSizeMake(-_horizontalLineScroll, 0.0)]; @@ -1002,8 +1016,13 @@ contentBounds.origin.x += aSize.width; contentBounds.origin.y += aSize.height; - [_contentView scrollToPoint:contentBounds.origin]; - [_headerClipView scrollToPoint:CGPointMake(contentBounds.origin, 0)]; + [self _moveToPoint:contentBounds.origin]; +} + +- (void)_moveToPoint:(CGPoint)aPoint +{ + [_contentView scrollToPoint:aPoint]; + [_headerClipView scrollToPoint:CGPointMake(aPoint, 0)]; } @end diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 21e6fa589..f942e3978 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -168,6 +168,8 @@ KeyCodesToUnicodeMap[CPKeyCodes.LEFT] = CPLeftArrowFunctionKey KeyCodesToUnicodeMap[CPKeyCodes.UP] = CPUpArrowFunctionKey; KeyCodesToUnicodeMap[CPKeyCodes.RIGHT] = CPRightArrowFunctionKey; KeyCodesToUnicodeMap[CPKeyCodes.DOWN] = CPDownArrowFunctionKey; +KeyCodesToUnicodeMap[CPKeyCodes.HOME] = CPHomeFunctionKey; +KeyCodesToUnicodeMap[CPKeyCodes.END] = CPEndFunctionKey; KeyCodesToUnicodeMap[CPKeyCodes.SEMICOLON] = ";"; KeyCodesToUnicodeMap[CPKeyCodes.DASH] = "-"; KeyCodesToUnicodeMap[CPKeyCodes.EQUALS] = "=";