Révision | af73cc0be12127dd7a283710f470f32c8cdce740 (tree) |
---|---|
l'heure | 2015-07-08 22:20:36 |
Auteur | masakih <masakih@user...> |
Commiter | masakih |
メインブラウザウインドウを追加
@@ -12,6 +12,9 @@ | ||
12 | 12 | F4EF18BA1B4D36E60021BF8D /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4EF18B81B4D36E60021BF8D /* MainMenu.xib */; }; |
13 | 13 | F4EF18C61B4D36E60021BF8D /* KanColleBrowserForOSXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EF18C51B4D36E60021BF8D /* KanColleBrowserForOSXTests.swift */; }; |
14 | 14 | F4EF18D21B4D38BB0021BF8D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F4EF18D41B4D38BB0021BF8D /* InfoPlist.strings */; }; |
15 | + F4EF18D91B4D40160021BF8D /* KCBFOMainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EF18D71B4D40160021BF8D /* KCBFOMainWindowController.swift */; }; | |
16 | + F4EF18DB1B4D40250021BF8D /* KCBFOMainWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4EF18DD1B4D40250021BF8D /* KCBFOMainWindowController.xib */; }; | |
17 | + F4EF18DF1B4D41DE0021BF8D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4EF18DE1B4D41DE0021BF8D /* WebKit.framework */; }; | |
15 | 18 | /* End PBXBuildFile section */ |
16 | 19 | |
17 | 20 | /* Begin PBXContainerItemProxy section */ |
@@ -35,6 +38,9 @@ | ||
35 | 38 | F4EF18C51B4D36E60021BF8D /* KanColleBrowserForOSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KanColleBrowserForOSXTests.swift; sourceTree = "<group>"; }; |
36 | 39 | F4EF18D31B4D38BB0021BF8D /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; }; |
37 | 40 | F4EF18D61B4D3A220021BF8D /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/MainMenu.strings; sourceTree = "<group>"; }; |
41 | + F4EF18D71B4D40160021BF8D /* KCBFOMainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KCBFOMainWindowController.swift; sourceTree = "<group>"; }; | |
42 | + F4EF18DC1B4D40250021BF8D /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/KCBFOMainWindowController.xib; sourceTree = "<group>"; }; | |
43 | + F4EF18DE1B4D41DE0021BF8D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; | |
38 | 44 | /* End PBXFileReference section */ |
39 | 45 | |
40 | 46 | /* Begin PBXFrameworksBuildPhase section */ |
@@ -42,6 +48,7 @@ | ||
42 | 48 | isa = PBXFrameworksBuildPhase; |
43 | 49 | buildActionMask = 2147483647; |
44 | 50 | files = ( |
51 | + F4EF18DF1B4D41DE0021BF8D /* WebKit.framework in Frameworks */, | |
45 | 52 | ); |
46 | 53 | runOnlyForDeploymentPostprocessing = 0; |
47 | 54 | }; |
@@ -58,6 +65,7 @@ | ||
58 | 65 | F4EF18A61B4D36E60021BF8D = { |
59 | 66 | isa = PBXGroup; |
60 | 67 | children = ( |
68 | + F4EF18DE1B4D41DE0021BF8D /* WebKit.framework */, | |
61 | 69 | F4EF18B11B4D36E60021BF8D /* KanColleBrowserForOSX */, |
62 | 70 | F4EF18C21B4D36E60021BF8D /* KanColleBrowserForOSXTests */, |
63 | 71 | F4EF18B01B4D36E60021BF8D /* Products */, |
@@ -77,6 +85,8 @@ | ||
77 | 85 | isa = PBXGroup; |
78 | 86 | children = ( |
79 | 87 | F4EF18B41B4D36E60021BF8D /* AppDelegate.swift */, |
88 | + F4EF18D71B4D40160021BF8D /* KCBFOMainWindowController.swift */, | |
89 | + F4EF18DD1B4D40250021BF8D /* KCBFOMainWindowController.xib */, | |
80 | 90 | F4EF18B61B4D36E60021BF8D /* Images.xcassets */, |
81 | 91 | F4EF18B81B4D36E60021BF8D /* MainMenu.xib */, |
82 | 92 | F4EF18B21B4D36E60021BF8D /* Supporting Files */, |
@@ -191,6 +201,7 @@ | ||
191 | 201 | isa = PBXResourcesBuildPhase; |
192 | 202 | buildActionMask = 2147483647; |
193 | 203 | files = ( |
204 | + F4EF18DB1B4D40250021BF8D /* KCBFOMainWindowController.xib in Resources */, | |
194 | 205 | F4EF18B71B4D36E60021BF8D /* Images.xcassets in Resources */, |
195 | 206 | F4EF18D21B4D38BB0021BF8D /* InfoPlist.strings in Resources */, |
196 | 207 | F4EF18BA1B4D36E60021BF8D /* MainMenu.xib in Resources */, |
@@ -211,6 +222,7 @@ | ||
211 | 222 | isa = PBXSourcesBuildPhase; |
212 | 223 | buildActionMask = 2147483647; |
213 | 224 | files = ( |
225 | + F4EF18D91B4D40160021BF8D /* KCBFOMainWindowController.swift in Sources */, | |
214 | 226 | F4EF18B51B4D36E60021BF8D /* AppDelegate.swift in Sources */, |
215 | 227 | ); |
216 | 228 | runOnlyForDeploymentPostprocessing = 0; |
@@ -251,6 +263,14 @@ | ||
251 | 263 | name = InfoPlist.strings; |
252 | 264 | sourceTree = "<group>"; |
253 | 265 | }; |
266 | + F4EF18DD1B4D40250021BF8D /* KCBFOMainWindowController.xib */ = { | |
267 | + isa = PBXVariantGroup; | |
268 | + children = ( | |
269 | + F4EF18DC1B4D40250021BF8D /* ja */, | |
270 | + ); | |
271 | + name = KCBFOMainWindowController.xib; | |
272 | + sourceTree = "<group>"; | |
273 | + }; | |
254 | 274 | /* End PBXVariantGroup section */ |
255 | 275 | |
256 | 276 | /* Begin XCBuildConfiguration section */ |
@@ -10,9 +10,12 @@ import Cocoa | ||
10 | 10 | |
11 | 11 | @NSApplicationMain |
12 | 12 | class AppDelegate: NSObject, NSApplicationDelegate { |
13 | - | |
13 | + | |
14 | + var mainWindowController : KCBFOMainWindowController! | |
15 | + | |
14 | 16 | func applicationDidFinishLaunching(aNotification: NSNotification) { |
15 | - // Insert code here to initialize your application | |
17 | + mainWindowController = KCBFOMainWindowController.new() | |
18 | + mainWindowController.showWindow(nil) | |
16 | 19 | } |
17 | 20 | |
18 | 21 | func applicationWillTerminate(aNotification: NSNotification) { |
@@ -113,8 +113,16 @@ | ||
113 | 113 | <modifierMask key="keyEquivalentModifierMask"/> |
114 | 114 | <menu key="submenu" title="View" id="HyV-fh-RgO"> |
115 | 115 | <items> |
116 | - <menuItem title="Reload" keyEquivalent="r" id="CZp-hf-DCN"/> | |
117 | - <menuItem title="Reload And Recache" keyEquivalent="R" id="nhW-uJ-3sj"/> | |
116 | + <menuItem title="Reload" keyEquivalent="r" id="CZp-hf-DCN"> | |
117 | + <connections> | |
118 | + <action selector="reloadContent:" target="-1" id="S9I-xb-YsW"/> | |
119 | + </connections> | |
120 | + </menuItem> | |
121 | + <menuItem title="Reload And Recache" keyEquivalent="R" id="nhW-uJ-3sj"> | |
122 | + <connections> | |
123 | + <action selector="reloadAndRecache:" target="-1" id="Mvt-Lm-ARk"/> | |
124 | + </connections> | |
125 | + </menuItem> | |
118 | 126 | </items> |
119 | 127 | </menu> |
120 | 128 | </menuItem> |
@@ -0,0 +1,143 @@ | ||
1 | +// | |
2 | +// KCBFOMainWindowController.swift | |
3 | +// KanColleBrowserForOSX | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2015/07/08. | |
6 | +// Copyright (c) 2015年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +import Cocoa | |
10 | +import WebKit | |
11 | + | |
12 | +class KCBFOMainWindowController: NSWindowController { | |
13 | + | |
14 | + @IBOutlet var clipView : NSClipView! | |
15 | + @IBOutlet var webView : WebView! | |
16 | + | |
17 | + var flashTopLeft : NSPoint = NSMakePoint(2600, 145); | |
18 | + | |
19 | + let gamePageURL = "http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/" | |
20 | + let loginPageURLPrefix = "https://www.dmm.com/my/-/login/=/" | |
21 | + | |
22 | + override init(window: NSWindow?) { | |
23 | + super.init(window: window) | |
24 | + } | |
25 | + required init?(coder: NSCoder) { | |
26 | + super.init(coder: coder) | |
27 | + } | |
28 | + | |
29 | + override class func new() -> KCBFOMainWindowController { | |
30 | + return KCBFOMainWindowController(windowNibName: "KCBFOMainWindowController") | |
31 | + } | |
32 | + | |
33 | + override func windowDidLoad() { | |
34 | + super.windowDidLoad() | |
35 | + | |
36 | + clipView.documentView = webView | |
37 | + | |
38 | + adjustFlash() | |
39 | + | |
40 | + webView.mainFrame.frameView.allowsScrolling = false | |
41 | + webView.applicationNameForUserAgent = "Version/8.0.6 Safari/600.6.3" | |
42 | + webView.mainFrameURL = gamePageURL | |
43 | + } | |
44 | + | |
45 | + @IBAction func reloadContent(sender : AnyObject?) { | |
46 | + let currentURL = webView.mainFrameURL | |
47 | + if currentURL != gamePageURL { | |
48 | + adjustFlash() | |
49 | + webView.mainFrameURL = gamePageURL | |
50 | + return | |
51 | + } | |
52 | + adjustFlash() | |
53 | + webView.reload(nil) | |
54 | + } | |
55 | + @IBAction func reloadAndRecache(sender :AnyObject?) { | |
56 | + let cache = NSURLCache.sharedURLCache() | |
57 | + cache.removeAllCachedResponses() | |
58 | + reloadContent(sender) | |
59 | + } | |
60 | + | |
61 | + func adjustFlash() { | |
62 | + clipView.scrollToPoint(flashTopLeft) | |
63 | + } | |
64 | + | |
65 | + // MARK: - WebFrameLoadDelegate | |
66 | + override func webView(sender: WebView!, didFinishLoadForFrame frame: WebFrame!) { | |
67 | + func handler(c : JSContext! , e : JSValue!) { | |
68 | + println("caught exception in evaluateScript: -> \(e)") | |
69 | + } | |
70 | + | |
71 | + if let path = frame.dataSource?.initialRequest.URL?.path { | |
72 | + if path.hasSuffix("gadgets/ifr") { | |
73 | + let context = frame.javaScriptContext! | |
74 | + context.exceptionHandler = handler | |
75 | + context.evaluateScript( | |
76 | + [ | |
77 | + "var emb = document.getElementById('flashWrap');", | |
78 | + "var rect = emb.getBoundingClientRect();", | |
79 | + "var atop = rect.top;", | |
80 | + "var aleft = rect.left;" | |
81 | + ].reduce(""){ $0 + $1 } | |
82 | + ) | |
83 | + let top = context.objectForKeyedSubscript("atop") | |
84 | + let left = context.objectForKeyedSubscript("aleft") | |
85 | + flashTopLeft = NSMakePoint(0, webView.frame.size.height) | |
86 | + let x = CGFloat(left.toDouble()) as CGFloat | |
87 | + let y = webView.frame.size.height - CGFloat(top.toDouble()) - 480 | |
88 | + flashTopLeft = NSMakePoint(x, y) | |
89 | + } | |
90 | + | |
91 | + if path.hasSuffix("app_id=854854") { | |
92 | + let context = frame.javaScriptContext! | |
93 | + context.exceptionHandler = handler | |
94 | + context.evaluateScript( | |
95 | + [ | |
96 | + "var iframe = document.getElementById('game_frame');", | |
97 | + "var validIframe = 0;", | |
98 | + "if(iframe) {", | |
99 | + " validIframe = 1;", | |
100 | + " var rect = iframe.getBoundingClientRect();", | |
101 | + " var atop = rect.top;", | |
102 | + " var aleft = rect.left;", | |
103 | + "}" | |
104 | + ].reduce(""){ $0 + $1 } | |
105 | + ) | |
106 | + let validIframe = context.objectForKeyedSubscript("validIframe") | |
107 | + println("\(validIframe)") | |
108 | + | |
109 | + if let validIframe = context.objectForKeyedSubscript("validIframe")?.toInt32() { | |
110 | + if validIframe == 0 { return } | |
111 | + | |
112 | + let top = context.objectForKeyedSubscript("atop") | |
113 | + let left = context.objectForKeyedSubscript("aleft") | |
114 | + let x = flashTopLeft.x + CGFloat(left.toDouble()) | |
115 | + let y = flashTopLeft.y - CGFloat(top.toDouble()) | |
116 | + flashTopLeft = NSMakePoint(x, y) | |
117 | + adjustFlash() | |
118 | + } | |
119 | + } | |
120 | + } | |
121 | + } | |
122 | + | |
123 | + // MARK: - WebUIDelegate | |
124 | + override func webView(sender: WebView!, contextMenuItemsForElement element: [NSObject : AnyObject]!, defaultMenuItems: [AnyObject]!) -> [AnyObject]! { | |
125 | + var items:[AnyObject] = defaultMenuItems.flatMap(){ | |
126 | + item in | |
127 | + switch item.tag() { | |
128 | + case WebMenuItemTagOpenLinkInNewWindow, | |
129 | + WebMenuItemTagDownloadLinkToDisk, | |
130 | + WebMenuItemTagOpenImageInNewWindow, | |
131 | + WebMenuItemTagOpenFrameInNewWindow, | |
132 | + WebMenuItemTagGoBack, | |
133 | + WebMenuItemTagGoForward, | |
134 | + WebMenuItemTagStop, | |
135 | + WebMenuItemTagReload: | |
136 | + return [] | |
137 | + default: | |
138 | + return [item] | |
139 | + } | |
140 | + } | |
141 | + return items | |
142 | + } | |
143 | +} |
@@ -0,0 +1,48 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
2 | +<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none"> | |
3 | + <dependencies> | |
4 | + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/> | |
5 | + <plugIn identifier="com.apple.WebKitIBPlugin" version="7706"/> | |
6 | + </dependencies> | |
7 | + <objects> | |
8 | + <customObject id="-2" userLabel="File's Owner" customClass="KCBFOMainWindowController" customModule="KanColleBrowserForOSX" customModuleProvider="target"> | |
9 | + <connections> | |
10 | + <outlet property="clipView" destination="CE2-tS-wOP" id="e59-4N-ABH"/> | |
11 | + <outlet property="webView" destination="9oP-vl-4d9" id="S8P-5p-uZ0"/> | |
12 | + <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/> | |
13 | + </connections> | |
14 | + </customObject> | |
15 | + <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | |
16 | + <customObject id="-3" userLabel="Application" customClass="NSObject"/> | |
17 | + <window title="OSXを起動したらそこには『艦隊これくしょん -艦これ-』の世界が広がっていたのです!?" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5"> | |
18 | + <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/> | |
19 | + <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> | |
20 | + <rect key="contentRect" x="196" y="240" width="800" height="480"/> | |
21 | + <rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/> | |
22 | + <view key="contentView" id="se5-gp-TjO"> | |
23 | + <rect key="frame" x="0.0" y="6" width="800" height="480"/> | |
24 | + <autoresizingMask key="autoresizingMask"/> | |
25 | + <subviews> | |
26 | + <customView id="CE2-tS-wOP" customClass="NSClipView"> | |
27 | + <rect key="frame" x="0.0" y="0.0" width="800" height="480"/> | |
28 | + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | |
29 | + </customView> | |
30 | + </subviews> | |
31 | + </view> | |
32 | + <connections> | |
33 | + <outlet property="delegate" destination="-2" id="0bl-1N-AYu"/> | |
34 | + </connections> | |
35 | + <point key="canvasLocation" x="422" y="234"/> | |
36 | + </window> | |
37 | + <webView id="9oP-vl-4d9"> | |
38 | + <rect key="frame" x="0.0" y="0.0" width="6000" height="700"/> | |
39 | + <autoresizingMask key="autoresizingMask"/> | |
40 | + <webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12"/> | |
41 | + <connections> | |
42 | + <outlet property="UIDelegate" destination="-2" id="vms-hm-oFJ"/> | |
43 | + <outlet property="frameLoadDelegate" destination="-2" id="Qaq-jw-LUu"/> | |
44 | + </connections> | |
45 | + <point key="canvasLocation" x="199" y="1063"/> | |
46 | + </webView> | |
47 | + </objects> | |
48 | +</document> |