From d58e511d8a97e43239ab5ba0032b3fd537c51195 Mon Sep 17 00:00:00 2001 From: masakih Date: Tue, 22 Apr 2014 21:04:11 +0900 Subject: [PATCH] =?utf8?q?Flash=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=82=92DOM?= =?utf8?q?=E3=81=8B=E3=82=89=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E3=82=88?= =?utf8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 2 + KCD/HMBroserWindowController.m | 70 +++++++++++++++++++++++++++++-- KCD/ja.lproj/HMBroserWindowController.xib | 13 +++--- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index cb22f96d..e01733ef 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -907,6 +907,7 @@ "COREDATA_STORE_TYPE=0", ); INFOPLIST_FILE = "KCD/KCD-Info.plist"; + MACOSX_DEPLOYMENT_TARGET = 10.9; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -921,6 +922,7 @@ GCC_PREFIX_HEADER = "KCD/KCD-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = "COREDATA_STORE_TYPE=0"; INFOPLIST_FILE = "KCD/KCD-Info.plist"; + MACOSX_DEPLOYMENT_TARGET = 10.9; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/KCD/HMBroserWindowController.m b/KCD/HMBroserWindowController.m index d43c0483..9c311f05 100644 --- a/KCD/HMBroserWindowController.m +++ b/KCD/HMBroserWindowController.m @@ -17,6 +17,7 @@ #import "HMServerDataStore.h" +#import static NSString *prevReloadDateStringKey = @"previousReloadDateString"; @@ -27,6 +28,7 @@ typedef NS_ENUM(NSInteger, ViewType) { }; @interface HMBroserWindowController () +@property NSPoint flashTopLeft; @property (strong) NSViewController *selectedViewController; @property (strong) NSMutableDictionary *controllers; @@ -62,7 +64,9 @@ typedef NS_ENUM(NSInteger, ViewType) { [clip setAutoresizingMask:[self.placeholder autoresizingMask]]; [[self.placeholder superview] replaceSubview:self.placeholder with:clip]; [clip setDocumentView:self.webView]; - [clip scrollToPoint:NSMakePoint(70, 445)]; + + self.flashTopLeft = NSMakePoint(70, 145); + [self adjustFlash]; self.selectedViewController = [HMDocksViewController new]; [self.selectedViewController.view setFrame:[self.docksPlaceholder frame]]; @@ -131,10 +135,15 @@ typedef NS_ENUM(NSInteger, ViewType) { self.selectedViewsSegment = type; } -- (IBAction)reloadContent:(id)sender +- (void)adjustFlash { id /*NSClipView * */ clip = [self.webView superview]; - [clip scrollToPoint:NSMakePoint(70, 445)]; + [clip scrollToPoint:self.flashTopLeft]; +} + +- (IBAction)reloadContent:(id)sender +{ + [self adjustFlash]; NSString *prevReloadDateString = [[NSUserDefaults standardUserDefaults] stringForKey:prevReloadDateStringKey]; if(prevReloadDateString) { @@ -218,5 +227,58 @@ typedef NS_ENUM(NSInteger, ViewType) { }]; } - +#pragma mark - WebFrameLoadDelegate +- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame +{ + WebDataSource *datasource = frame.dataSource; + NSURLRequest *request = datasource.initialRequest; + NSURL *url = request.URL; + NSString *path = url.path; + + void (^handler)(JSContext *context, JSValue *exception) = ^(JSContext *context, JSValue *exception) { + NSLog(@"caught exception in evaluateScript: -> %@", exception); + }; + + if([path hasSuffix:@"gadgets/ifr"]) { + JSContext *context = [frame javaScriptContext]; + context.exceptionHandler = handler; + [context evaluateScript: + @"var emb = document.getElementById('flashWrap');" + @"var rect = emb.getBoundingClientRect();" + @"var atop = rect.top;" + @"var aleft = rect.left;" + ]; + JSValue *top = context[@"atop"]; + JSValue *left = context[@"aleft"]; + + self.flashTopLeft = NSMakePoint(0, self.webView.frame.size.height); + self.flashTopLeft = NSMakePoint(self.flashTopLeft.x + left.toDouble, self.flashTopLeft.y - top.toDouble - 480); + } + + if([path hasSuffix:@"app_id=854854"]) { + JSContext *context = [frame javaScriptContext]; + context.exceptionHandler = handler; + [context evaluateScript: + @"var iframe = document.getElementById('game_frame');" + @"var validIframe = 0;" + @"if(iframe) {" + @" validIframe = 1;" + @" var rect = iframe.getBoundingClientRect();" + @" var atop = rect.top;" + @" var aleft = rect.left;" + @"}" + ]; + int32_t validIframe = context[@"validIframe"].toInt32; + if(validIframe == 0) { +// NSLog(@"game_frame is invalid"); + return; + } + + JSValue *top = context[@"atop"]; + JSValue *left = context[@"aleft"]; + + self.flashTopLeft = NSMakePoint(self.flashTopLeft.x + left.toDouble, self.flashTopLeft.y - top.toDouble); + [self adjustFlash]; + } +} @end diff --git a/KCD/ja.lproj/HMBroserWindowController.xib b/KCD/ja.lproj/HMBroserWindowController.xib index e8fef288..2ac327b4 100644 --- a/KCD/ja.lproj/HMBroserWindowController.xib +++ b/KCD/ja.lproj/HMBroserWindowController.xib @@ -1,9 +1,9 @@ - + - - - + + + @@ -341,11 +341,14 @@ - + + + + -- 2.11.0