OSDN Git Service

Flashの位置をDOMから取得するようにした
authormasakih <masakih@users.sourceforge.jp>
Tue, 22 Apr 2014 12:04:11 +0000 (21:04 +0900)
committermasakih <masakih@users.sourceforge.jp>
Tue, 22 Apr 2014 12:04:11 +0000 (21:04 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMBroserWindowController.m
KCD/ja.lproj/HMBroserWindowController.xib

index cb22f96..e01733e 100644 (file)
                                        "COREDATA_STORE_TYPE=0",
                                );
                                INFOPLIST_FILE = "KCD/KCD-Info.plist";
+                               MACOSX_DEPLOYMENT_TARGET = 10.9;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                                WRAPPER_EXTENSION = app;
                        };
                                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;
                        };
index d43c048..9c311f0 100644 (file)
@@ -17,6 +17,7 @@
 
 #import "HMServerDataStore.h"
 
+#import <JavaScriptCore/JavaScriptCore.h>
 
 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
index e8fef28..2ac327b 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
-        <deployment defaultVersion="1080" identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
-        <plugIn identifier="com.apple.WebKitIBPlugin" version="5053"/>
+        <deployment defaultVersion="1090" identifier="macosx"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
+        <plugIn identifier="com.apple.WebKitIBPlugin" version="5056"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="HMBroserWindowController">
             </connections>
         </window>
         <webView id="tgB-GD-Aq9">
-            <rect key="frame" x="0.0" y="0.0" width="900" height="1000"/>
+            <rect key="frame" x="0.0" y="0.0" width="900" height="700"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12">
                 <nil key="identifier"/>
             </webPreferences>
+            <connections>
+                <outlet property="frameLoadDelegate" destination="-2" id="ghK-Nk-WYy"/>
+            </connections>
         </webView>
         <objectController mode="entity" entityName="Material" editable="NO" automaticallyPreparesContent="YES" id="bH9-1e-fxA" userLabel="Material">
             <connections>