From: masakih Date: Tue, 26 May 2015 13:57:21 +0000 (+0900) Subject: スクロールロックとリサイズロックが出来るようにした X-Git-Tag: 1.3beta1~16 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=95e0f9025e988017bd8d5f96fc0bd67b2611ade3;p=kcd%2FKCD.git スクロールロックとリサイズロックが出来るようにした 色々な状態を取得設定出来るようにした --- diff --git a/KCD/HMExternalBrowserWindowController.h b/KCD/HMExternalBrowserWindowController.h index 9d19ddd8..1bcd90f1 100644 --- a/KCD/HMExternalBrowserWindowController.h +++ b/KCD/HMExternalBrowserWindowController.h @@ -13,9 +13,15 @@ @interface HMExternalBrowserWindowController : NSWindowController - @property (nonatomic, weak) IBOutlet WebView *webView; -@property (nonatomic, weak) IBOutlet NSSegmentedControl *goSegment; + +@property (nonatomic) NSString *urlString; +@property (nonatomic) NSSize windowContentSize; +@property (readonly) NSRect contentVisibleRect; +@property BOOL canResize; +@property BOOL canScroll; + + - (IBAction)clickGoBackSegment:(id)sender; diff --git a/KCD/HMExternalBrowserWindowController.m b/KCD/HMExternalBrowserWindowController.m index 47cc1067..d8f7f5bc 100644 --- a/KCD/HMExternalBrowserWindowController.m +++ b/KCD/HMExternalBrowserWindowController.m @@ -11,11 +11,14 @@ #import "HMAppDelegate.h" @interface HMExternalBrowserWindowController () - +@property (nonatomic, weak) IBOutlet NSSegmentedControl *goSegment; @end @implementation HMExternalBrowserWindowController +@synthesize canResize = _canResize; +@synthesize canScroll = _canScroll; + - (id)init { self = [super initWithWindowNibName:NSStringFromClass([self class])]; @@ -42,6 +45,9 @@ HMAppDelegate *appDelegate = [[NSApplication sharedApplication] delegate]; [self.webView setApplicationNameForUserAgent:appDelegate.appNameForUserAgent]; + + self.canResize = YES; + self.canScroll = YES; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -62,12 +68,78 @@ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } -/* - - - http://www.dmm.com/netgame/-/basket/ - - */ +static BOOL sameState(BOOL a, BOOL b) { + if(a && b) { + return YES; + } + if(!a && !b) { + return YES; + } + return NO; +} +- (void)setCanResize:(BOOL)canResize +{ + if(sameState(_canResize, canResize)) return; + + _canResize = canResize; + + NSUInteger styleMaks = self.window.styleMask; + if(canResize) { + styleMaks |= NSResizableWindowMask; + } else { + styleMaks &= ~NSResizableWindowMask; + } + self.window.styleMask = styleMaks; +} +- (BOOL)canResize +{ + return _canResize; +} +- (void)setCanScroll:(BOOL)canScroll +{ + if(sameState(_canScroll, canScroll)) return; + + _canScroll = canScroll; + + if(canScroll) { + [[[self.webView mainFrame] frameView] setAllowsScrolling:YES]; + } else { + [[[self.webView mainFrame] frameView] setAllowsScrolling:NO]; + } +} +- (BOOL)canScroll +{ + return _canScroll; +} + +- (NSString *)urlString +{ + return self.webView.mainFrameURL; +} +- (NSRect)contentVisibleRect +{ + return self.webView.visibleRect; +} + +- (void)setWindowContentSize:(NSSize)windowContentSize +{ + NSRect contentRect; + contentRect.origin = NSZeroPoint; + contentRect.size = windowContentSize; + + NSRect newFrame = [self.window frameRectForContentRect:contentRect]; + NSRect frame = self.window.frame; + newFrame.origin.x = NSMinX(frame); + newFrame.origin.y = NSMaxY(frame) - NSHeight(newFrame); + + [self.window setFrame:newFrame display:YES]; +} +- (NSSize)windowContentSize +{ + NSRect frame = self.window.frame; + NSRect contentRect = [self.window contentRectForFrameRect:frame]; + return contentRect.size; +} - (IBAction)reloadContent:(id)sender { diff --git a/KCD/ja.lproj/HMExternalBrowserWindowController.xib b/KCD/ja.lproj/HMExternalBrowserWindowController.xib index fb7d9f75..801d20e4 100644 --- a/KCD/ja.lproj/HMExternalBrowserWindowController.xib +++ b/KCD/ja.lproj/HMExternalBrowserWindowController.xib @@ -1,9 +1,9 @@ - + - - + + @@ -33,7 +33,7 @@ - + @@ -91,9 +91,51 @@ + + + + + + + + + + + + + +