diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27402f98..6e8d8796 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+### 2.1.1
+- OSX: Fix modifier keys not emitting keyboard events Issue #196
+- WIN: Added Windows 7 touch support Issue #194
+
### 2.1.0
- AND: Updated to FreKotlin 1.6.0
- Upgraded to AIR 32
diff --git a/c_sharp_libs_x64/WebViewANELib.dll b/c_sharp_libs_x64/WebViewANELib.dll
index d60034a7..86994040 100644
Binary files a/c_sharp_libs_x64/WebViewANELib.dll and b/c_sharp_libs_x64/WebViewANELib.dll differ
diff --git a/c_sharp_libs_x86/WebViewANELib.dll b/c_sharp_libs_x86/WebViewANELib.dll
index 0ae03e9e..dc3c543e 100644
Binary files a/c_sharp_libs_x86/WebViewANELib.dll and b/c_sharp_libs_x86/WebViewANELib.dll differ
diff --git a/example-desktop-complete/get_dependencies.ps1 b/example-desktop-complete/get_dependencies.ps1
index 378fc4b9..5b2f2d52 100644
--- a/example-desktop-complete/get_dependencies.ps1
+++ b/example-desktop-complete/get_dependencies.ps1
@@ -1,4 +1,4 @@
-$AneVersion = "2.1.0"
+$AneVersion = "2.1.1"
$currentDir = (Get-Item -Path ".\" -Verbose).FullName
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
diff --git a/example-desktop-complete/get_dependencies.sh b/example-desktop-complete/get_dependencies.sh
index af50d8aa..a95cbcfc 100644
--- a/example-desktop-complete/get_dependencies.sh
+++ b/example-desktop-complete/get_dependencies.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-AneVersion="2.1.0"
+AneVersion="2.1.1"
FreSwiftVersion="3.0.0"
wget -O ../native_extension/ane/FreSwift.ane https://github.com/tuarua/Swift-IOS-ANE/releases/download/$FreSwiftVersion/FreSwift.ane?raw=true
diff --git a/example-mobile/.gitignore b/example-mobile/.gitignore
index 3e9a7049..f63c3754 100644
--- a/example-mobile/.gitignore
+++ b/example-mobile/.gitignore
@@ -7,7 +7,6 @@ bin-debug/
bin-release/
bin-release-temp/
cache/
-AIRSDK_patch/
*.app
diff --git a/example-mobile/AIRSDK_additions/.gitignore b/example-mobile/AIRSDK_patch/.gitignore
similarity index 100%
rename from example-mobile/AIRSDK_additions/.gitignore
rename to example-mobile/AIRSDK_patch/.gitignore
diff --git a/example-mobile/AIRSDK_additions/README.md b/example-mobile/AIRSDK_patch/README.md
similarity index 100%
rename from example-mobile/AIRSDK_additions/README.md
rename to example-mobile/AIRSDK_patch/README.md
diff --git a/example-mobile/get_android_dependencies.ps1 b/example-mobile/get_android_dependencies.ps1
index 22db8087..8d59ce43 100644
--- a/example-mobile/get_android_dependencies.ps1
+++ b/example-mobile/get_android_dependencies.ps1
@@ -1,4 +1,4 @@
-$AneVersion = "2.1.0"
+$AneVersion = "2.1.1"
$currentDir = (Get-Item -Path ".\" -Verbose).FullName
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
diff --git a/example-mobile/get_android_dependencies.sh b/example-mobile/get_android_dependencies.sh
index 2b7c171e..61d12fb2 100755
--- a/example-mobile/get_android_dependencies.sh
+++ b/example-mobile/get_android_dependencies.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-AneVersion="2.1.0"
+AneVersion="2.1.1"
wget -O android_dependencies/com.tuarua.frekotlin.ane https://github.com/tuarua/Android-ANE-Dependencies/blob/master/anes/kotlin/com.tuarua.frekotlin.ane?raw=true
wget -O ../native_extension/ane/WebViewANE.ane https://github.com/tuarua/WebViewANE/releases/download/$AneVersion/WebViewANE.ane?raw=true
diff --git a/example-mobile/get_ios_dependencies.sh b/example-mobile/get_ios_dependencies.sh
index 573a0067..cf7ea21a 100755
--- a/example-mobile/get_ios_dependencies.sh
+++ b/example-mobile/get_ios_dependencies.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-AneVersion="2.1.0"
+AneVersion="2.1.1"
FreSwiftVersion="3.0.0"
rm -r ios_dependencies/device
diff --git a/native_extension/ane/extension_android.xml b/native_extension/ane/extension_android.xml
index 93efa085..167497b3 100644
--- a/native_extension/ane/extension_android.xml
+++ b/native_extension/ane/extension_android.xml
@@ -3,7 +3,7 @@
com.tuarua.WebViewANE
WebView ANE
This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd.
- 2.1.0
+ 2.1.1
diff --git a/native_extension/ane/extension_ios.xml b/native_extension/ane/extension_ios.xml
index 600b5308..39fcf74d 100755
--- a/native_extension/ane/extension_ios.xml
+++ b/native_extension/ane/extension_ios.xml
@@ -3,7 +3,7 @@
com.tuarua.WebViewANE
WebView ANE
This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd.
- 2.1.0
+ 2.1.1
diff --git a/native_extension/ane/extension_multi.xml b/native_extension/ane/extension_multi.xml
index 14de516c..879065b2 100755
--- a/native_extension/ane/extension_multi.xml
+++ b/native_extension/ane/extension_multi.xml
@@ -3,7 +3,7 @@
com.tuarua.WebViewANE
WebView ANE
This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd.
- 2.1.0
+ 2.1.1
diff --git a/native_extension/ane/extension_osx.xml b/native_extension/ane/extension_osx.xml
index 59f3fc45..7aad1c28 100755
--- a/native_extension/ane/extension_osx.xml
+++ b/native_extension/ane/extension_osx.xml
@@ -3,7 +3,7 @@
com.tuarua.WebViewANE
WebView ANE
This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd.
- 2.1.0
+ 2.1.1
diff --git a/native_extension/ane/extension_win.xml b/native_extension/ane/extension_win.xml
index d636bdd3..dabb8222 100755
--- a/native_extension/ane/extension_win.xml
+++ b/native_extension/ane/extension_win.xml
@@ -3,7 +3,7 @@
com.tuarua.WebViewANE
WebView ANE
This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd.
- 2.1.0
+ 2.1.1
diff --git a/native_extension/ane/platforms/win/x64/release/WebViewANE.dll b/native_extension/ane/platforms/win/x64/release/WebViewANE.dll
index 765fb29b..771499cc 100644
Binary files a/native_extension/ane/platforms/win/x64/release/WebViewANE.dll and b/native_extension/ane/platforms/win/x64/release/WebViewANE.dll differ
diff --git a/native_extension/ane/platforms/win/x64/release/library.swf b/native_extension/ane/platforms/win/x64/release/library.swf
index 4891e47e..7e863f8a 100644
Binary files a/native_extension/ane/platforms/win/x64/release/library.swf and b/native_extension/ane/platforms/win/x64/release/library.swf differ
diff --git a/native_extension/ane/platforms/win/x86/release/WebViewANE.dll b/native_extension/ane/platforms/win/x86/release/WebViewANE.dll
index 6fe4b614..645a0c21 100644
Binary files a/native_extension/ane/platforms/win/x86/release/WebViewANE.dll and b/native_extension/ane/platforms/win/x86/release/WebViewANE.dll differ
diff --git a/native_extension/ane/platforms/win/x86/release/library.swf b/native_extension/ane/platforms/win/x86/release/library.swf
index 4891e47e..7e863f8a 100644
Binary files a/native_extension/ane/platforms/win/x86/release/library.swf and b/native_extension/ane/platforms/win/x86/release/library.swf differ
diff --git a/native_extension/bin/WebViewANE.swc b/native_extension/bin/WebViewANE.swc
index abe65b5c..62838209 100644
Binary files a/native_extension/bin/WebViewANE.swc and b/native_extension/bin/WebViewANE.swc differ
diff --git a/native_extension/src/com/tuarua/WebViewANE.as b/native_extension/src/com/tuarua/WebViewANE.as
index c18c0bb7..945757c4 100755
--- a/native_extension/src/com/tuarua/WebViewANE.as
+++ b/native_extension/src/com/tuarua/WebViewANE.as
@@ -236,7 +236,8 @@ public class WebViewANE extends EventDispatcher {
}
//noinspection ReservedWordAsName
- override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void {
+ override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0,
+ useWeakReference:Boolean = false):void {
super.addEventListener(type, listener, useCapture, priority, useWeakReference);
if (_isInited && (KeyboardEvent.KEY_UP == type || KeyboardEvent.KEY_DOWN == type) && (os.isWindows || os.isOSX)) {
if (this.hasEventListener(type)) {
diff --git a/native_library/apple/WebViewANE/WebViewANE/SwiftController.swift b/native_library/apple/WebViewANE/WebViewANE/SwiftController.swift
index e038dce6..a46fb718 100644
--- a/native_library/apple/WebViewANE/WebViewANE/SwiftController.swift
+++ b/native_library/apple/WebViewANE/WebViewANE/SwiftController.swift
@@ -30,33 +30,59 @@ public class SwiftController: NSObject {
public var context: FreContextSwift!
public var functionsToSet: FREFunctionMap = [:]
private var _currentWebView: WebViewVC?
- private var _currentTab: Int = 0
- private var _tabList: NSMutableArray = NSMutableArray()
+ private var _currentTab = 0
+ private var _tabList = NSMutableArray()
private static var escListener: Any?
private static var keyUpListener: Any?
private static var keyDownListener: Any?
private static let zoomIncrement = CGFloat(0.1)
private var _initialUrl = ""
- private var _viewPort: CGRect = CGRect(x: 0.0, y: 0.0, width: 800.0, height: 600.0)
+ private var _viewPort = CGRect(x: 0.0, y: 0.0, width: 800.0, height: 600.0)
private var _capturedCropTo: CGRect?
- internal var _popupBehaviour: PopupBehaviour = PopupBehaviour.newWindow
+ internal var _popupBehaviour = PopupBehaviour.newWindow
#if os(iOS)
private var _bgColor = UIColor.white
#else
internal var _popup: Popup?
internal var downloadTaskSaveTos = [Int: URL]()
#endif
- private var _isAdded: Bool = false
+ private var _isAdded = false
internal var _settings: Settings!
- private var _userController: WKUserContentController = WKUserContentController()
+ private var _userController = WKUserContentController()
private func addKeyListener(type: String) {
#if os(OSX)
- let eventMask: NSEvent.EventTypeMask = type == "keyUp" ? .keyUp : .keyDown
+ var eventMask: NSEvent.EventTypeMask = type == "keyUp" ? .keyUp : .keyDown
+ eventMask.formUnion(.flagsChanged)
var listener: Any? = type == "keyUp" ? SwiftController.keyUpListener : SwiftController.keyDownListener
if listener == nil {
listener = NSEvent.addLocalMonitorForEvents(matching: [eventMask]) { (event: NSEvent) -> NSEvent? in
- var modifiers: String = ""
+ var modifiers = ""
+ var isModifier = false
+ var keyValue: UInt32 = 0
+
+ switch event.keyCode {
+ case 55: //command
+ keyValue = 15
+ isModifier = true
+ case 56: //shift
+ keyValue = 16
+ isModifier = true
+ case 58: //option
+ keyValue = 18
+ isModifier = true
+ case 59: //control
+ keyValue = 17
+ isModifier = true
+ default:
+ break
+ }
+
+ if isModifier {
+ self.sendKeyEvent(keyValue: keyValue, event: event, modifiers: modifiers)
+ return nil
+ }
+
switch event.modifierFlags.intersection(NSEvent.ModifierFlags.deviceIndependentFlagsMask) {
case [.shift]:
modifiers = "shift"
@@ -89,10 +115,8 @@ public class SwiftController: NSObject {
default:
break
}
-
if let characters = event.charactersIgnoringModifiers {
let s = characters.uppercased().unicodeScalars
- var keyValue: UInt32 = 0
switch event.keyCode {
case 51: //BACKSPACE
keyValue = 8
@@ -109,28 +133,47 @@ public class SwiftController: NSObject {
default:
keyValue = s[s.startIndex].value
}
- var props: [String: Any] = Dictionary()
- props["keyCode"] = keyValue
- props["nativeKeyCode"] = event.keyCode
- props["modifiers"] = modifiers
- props["isSystemKey"] = false
- self.dispatchEvent(name: event.type == .keyUp ? WebViewEvent.ON_KEY_UP : WebViewEvent.ON_KEY_DOWN,
- value: JSON(props).description)
-
+ self.sendKeyEvent(keyValue: keyValue, event: event, modifiers: modifiers)
}
-
- return event
+ return nil
}
}
#endif
}
-
+
+#if os(OSX)
+ private func sendKeyEvent(keyValue: UInt32, event: NSEvent, modifiers: String) {
+ var props: [String: Any] = Dictionary()
+ props["keyCode"] = keyValue
+ props["nativeKeyCode"] = event.keyCode
+ props["modifiers"] = modifiers
+ props["isSystemKey"] = false
+ var name = ""
+ switch event.type {
+ case .keyUp:
+ name = WebViewEvent.ON_KEY_UP
+ case .keyDown:
+ name = WebViewEvent.ON_KEY_DOWN
+ case .flagsChanged:
+ if Int(event.modifierFlags.rawValue) == 256 {
+ name = WebViewEvent.ON_KEY_UP
+ } else {
+ name = WebViewEvent.ON_KEY_DOWN
+ }
+ default:
+ break
+ }
+ dispatchEvent(name: name, value: JSON(props).description)
+ }
+#endif
+
func addEventListener(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
#if os(OSX)
guard argc > 0,
- let type = String(argv[0])
- else {
- return FreArgError(message: "addEventListener").getError(#file, #line, #column)
+ let type = String(argv[0])
+ else {
+ return FreArgError(message: "addEventListener").getError(#file, #line, #column)
+
}
if type == "keyUp" || type == "keyDown" {
addKeyListener(type: type)
@@ -142,11 +185,10 @@ public class SwiftController: NSObject {
func removeEventListener(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
#if os(OSX)
guard argc > 0,
- let type = String(argv[0])
- else {
- return FreArgError(message: "removeEventListener").getError(#file, #line, #column)
+ let type = String(argv[0])
+ else {
+ return FreArgError(message: "removeEventListener").getError(#file, #line, #column)
}
-
let listener: Any? = type == "keyUp" ? SwiftController.keyUpListener : SwiftController.keyDownListener
if let lstnr = listener {
NSEvent.removeMonitor(lstnr)
@@ -173,8 +215,8 @@ public class SwiftController: NSObject {
func backForwardList(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard let wv = _currentWebView
- else {
- return FreArgError(message: "backForwardList").getError(#file, #line, #column)
+ else {
+ return FreArgError(message: "backForwardList").getError(#file, #line, #column)
}
let bfList = BackForwardList.init(context: context, webView: wv)
@@ -187,12 +229,11 @@ public class SwiftController: NSObject {
func go(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let wv = _currentWebView,
- let i = Int(argv[0])
- else {
- return FreArgError(message: "go").getError(#file, #line, #column)
+ let wv = _currentWebView,
+ let i = Int(argv[0])
+ else {
+ return FreArgError(message: "go").getError(#file, #line, #column)
}
-
if let item = wv.backForwardList.item(at: i) {
wv.go(to: item)
}
@@ -237,10 +278,10 @@ public class SwiftController: NSObject {
func setVisible(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let wv = _currentWebView,
- let visible = Bool(argv[0])
- else {
- return FreArgError(message: "setVisible").getError(#file, #line, #column)
+ let wv = _currentWebView,
+ let visible = Bool(argv[0])
+ else {
+ return FreArgError(message: "setVisible").getError(#file, #line, #column)
}
if !_isAdded {
@@ -251,9 +292,7 @@ public class SwiftController: NSObject {
}
private func addToStage() {
- guard let wv = _currentWebView else {
- return
- }
+ guard let wv = _currentWebView else { return }
#if os(iOS)
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
rootViewController.view.addSubview(wv)
@@ -278,21 +317,18 @@ public class SwiftController: NSObject {
}
private func removeFromStage() {
- guard let wv = _currentWebView else {
- return
- }
+ guard let wv = _currentWebView else { return }
wv.removeFromSuperview()
_isAdded = false
}
func setViewPort(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let wv = _currentWebView,
- let viewPortFre = CGRect(argv[0])
- else {
- return FreArgError(message: "setViewPort").getError(#file, #line, #column)
+ let wv = _currentWebView,
+ let viewPortFre = CGRect(argv[0])
+ else {
+ return FreArgError(message: "setViewPort").getError(#file, #line, #column)
}
-
_viewPort = viewPortFre
wv.setPositionAndSize(viewPort: _viewPort)
return nil
@@ -300,9 +336,9 @@ public class SwiftController: NSObject {
func load(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let wv = _currentWebView,
- let url = String(argv[0]),
- !url.isEmpty else {
+ let wv = _currentWebView,
+ let url = String(argv[0]),
+ !url.isEmpty else {
return FreArgError(message: "load").getError(#file, #line, #column)
}
wv.load(url: url)
@@ -311,10 +347,10 @@ public class SwiftController: NSObject {
func loadHTMLString(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let wv = _currentWebView,
- let html = String(argv[0])
- else {
- return FreArgError(message: "loadHTMLString").getError(#file, #line, #column)
+ let wv = _currentWebView,
+ let html = String(argv[0])
+ else {
+ return FreArgError(message: "loadHTMLString").getError(#file, #line, #column)
}
wv.load(html: html)
return nil
@@ -335,8 +371,7 @@ public class SwiftController: NSObject {
}
func onFullScreen(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
-#if os(iOS)
-#else
+#if os(OSX)
guard argc > 0,
let fullScreen = Bool(argv[0]) else {
return FreArgError(message: "onFullScreen").getError(#file, #line, #column)
@@ -406,10 +441,10 @@ public class SwiftController: NSObject {
func evaluateJavaScript(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let wv = _currentWebView,
- let js = String(argv[0])
- else {
- return FreArgError(message: "evaluateJavaScript").getError(#file, #line, #column)
+ let wv = _currentWebView,
+ let js = String(argv[0])
+ else {
+ return FreArgError(message: "evaluateJavaScript").getError(#file, #line, #column)
}
if let callback = String(argv[1]) {
@@ -427,9 +462,9 @@ public class SwiftController: NSObject {
func injectScript(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 0,
- let injectCode = String(argv[0])
- else {
- return FreArgError(message: "injectScript").getError(#file, #line, #column)
+ let injectCode = String(argv[0])
+ else {
+ return FreArgError(message: "injectScript").getError(#file, #line, #column)
}
let userScript = WKUserScript(source: injectCode, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
@@ -543,9 +578,9 @@ public class SwiftController: NSObject {
func addTab(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
#if os(OSX)
guard argc > 0,
- let wv = _currentWebView
- else {
- return FreArgError(message: "addTab").getError(#file, #line, #column)
+ let wv = _currentWebView
+ else {
+ return FreArgError(message: "addTab").getError(#file, #line, #column)
}
if let initialUrl = String(argv[0]) {
@@ -571,12 +606,10 @@ public class SwiftController: NSObject {
func closeTab(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
#if os(OSX)
guard argc > 0,
- let cwv = _currentWebView,
- let index = Int(argv[0]),
- index > -1,
- index < (_tabList.count)
- else {
- return FreArgError(message: "closeTab").getError(#file, #line, #column)
+ let cwv = _currentWebView,
+ let index = Int(argv[0]), index > -1, index < (_tabList.count)
+ else {
+ return FreArgError(message: "closeTab").getError(#file, #line, #column)
}
let doRefresh = (_currentTab >= index)
@@ -629,13 +662,10 @@ public class SwiftController: NSObject {
func setCurrentTab(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
#if os(OSX)
guard argc > 0,
- let cwv = _currentWebView,
- let index = Int(argv[0]),
- index > -1,
- index < (_tabList.count),
- index != _currentTab
- else {
- return FreArgError(message: "setCurrentTab").getError(#file, #line, #column)
+ let cwv = _currentWebView,
+ let index = Int(argv[0]), index > -1, index < (_tabList.count), index != _currentTab
+ else {
+ return FreArgError(message: "setCurrentTab").getError(#file, #line, #column)
}
for vc in _tabList {
@@ -718,10 +748,10 @@ public class SwiftController: NSObject {
func initController(ctx: FREContext, argc: FREArgc, argv: FREArgv) -> FREObject? {
guard argc > 4,
- let inFRE4 = argv[4],
- let viewPortFre = CGRect(argv[1])
- else {
- return FreArgError(message: "initWebView").getError(#file, #line, #column)
+ let inFRE4 = argv[4],
+ let viewPortFre = CGRect(argv[1])
+ else {
+ return FreArgError(message: "initWebView").getError(#file, #line, #column)
}
if let initialUrl = String(argv[0]) {
_initialUrl = initialUrl
@@ -805,10 +835,7 @@ public class SwiftController: NSObject {
}
internal func isWhiteListBlocked(url: String) -> Bool {
- guard _settings.urlWhiteList.count > 0
- else {
- return false
- }
+ guard _settings.urlWhiteList.count > 0 else { return false }
let urlClean = url.lowercased()
for item in _settings.urlWhiteList {
if urlClean.range(of: item.lowercased()) != nil {
@@ -819,17 +846,13 @@ public class SwiftController: NSObject {
}
internal func isBlackListBlocked(url: String) -> Bool {
- guard _settings.urlBlackList.count > 0
- else {
- return false
- }
+ guard _settings.urlBlackList.count > 0 else { return false }
let urlClean = url.lowercased()
for item in _settings.urlBlackList {
if urlClean.range(of: item.lowercased()) != nil {
return true
}
}
-
return false
}
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefSharp/CefWindowsFormsHost.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefSharp/CefWindowsFormsHost.cs
new file mode 100644
index 00000000..90ad08ec
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefSharp/CefWindowsFormsHost.cs
@@ -0,0 +1,37 @@
+#region License
+// Copyright 2017 Tua Rua Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// All Rights Reserved. Tua Rua Ltd.
+#endregion
+
+using System;
+using System.Windows;
+using System.Windows.Forms.Integration;
+using WebViewANELib.Touch;
+
+// ReSharper disable IdentifierTypo
+
+namespace WebViewANELib.CefSharp {
+ public class CefWindowsFormsHost : WindowsFormsHost {
+ static CefWindowsFormsHost() {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(CefWindowsFormsHost), new FrameworkPropertyMetadata(typeof(CefWindowsFormsHost)));
+ }
+
+ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
+ MessageTouchDevice.WndProc(Window.GetWindow(this), msg, wParam, lParam, ref handled);
+ return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
+ }
+ }
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefView.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefView.cs
index 13866494..826e3cd3 100644
--- a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefView.cs
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/CefView.cs
@@ -29,7 +29,6 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
-using System.Windows.Forms.Integration;
using CefSharp;
using CefSharp.WinForms;
using Newtonsoft.Json.Linq;
@@ -41,7 +40,7 @@
namespace WebViewANELib {
public partial class CefView : IWebView {
- private WindowsFormsHost _host;
+ private CefWindowsFormsHost _host;
public string InitialUrl { private get; set; }
public int X { get; set; }
public int Y { get; set; }
@@ -83,7 +82,7 @@ public partial class CefView : IWebView {
public void Init() {
InitializeComponent();
IsManipulationEnabled = true;
- _host = new WindowsFormsHost();
+ _host = new CefWindowsFormsHost();
_host.IsManipulationEnabled = true;
Loaded += CefView_Loaded;
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/MainController.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/MainController.cs
index d190d61f..c32c742e 100644
--- a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/MainController.cs
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/MainController.cs
@@ -39,6 +39,8 @@
using Hwnd = System.IntPtr;
using TuaRua.FreSharp.Exceptions;
using TuaRua.FreSharp.Geom;
+using WebViewANELib.Touch;
+using WinApi = TuaRua.FreSharp.Utils.WinApi;
namespace WebViewANELib {
public class MainController : FreSharpMainController {
@@ -287,7 +289,7 @@ public class MainController : FreSharpMainController {
_webViewWindow = source.Handle;
- WinApi.RegisterTouchWindow(_webViewWindow, TouchWindowFlags.TWF_WANTPALM);
+ MessageTouchDevice.RegisterTouchWindow(_webViewWindow);
return FREObject.Zero;
}
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/GraphicsHelper.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/GraphicsHelper.cs
new file mode 100644
index 00000000..517f7d22
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/GraphicsHelper.cs
@@ -0,0 +1,38 @@
+#region License
+// Copyright 2017 Tua Rua Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// All Rights Reserved. Tua Rua Ltd.
+#endregion
+
+using System;
+using System.Windows;
+
+namespace WebViewANELib.Touch {
+ internal class GraphicsHelper {
+ public static double DpiX { get; }
+ public static double DpiY { get; }
+
+ public static Point DivideByDpi(Point point) {
+ return new Point(point.X * 96.0 / DpiX, point.Y * 96.0 / DpiY);
+ }
+
+ static GraphicsHelper() {
+ using (var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero)) {
+ DpiX = graphics.DpiX;
+ DpiY = graphics.DpiY;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/MessageTouchDevice.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/MessageTouchDevice.cs
new file mode 100644
index 00000000..3a67f89b
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/MessageTouchDevice.cs
@@ -0,0 +1,108 @@
+#region License
+// Copyright 2017 Tua Rua Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// All Rights Reserved. Tua Rua Ltd.
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Windows;
+using System.Windows.Input;
+using System.Windows.Media;
+using TuaRua.FreSharp.Utils;
+
+namespace WebViewANELib.Touch {
+ public class MessageTouchDevice : TouchDevice {
+ private static readonly FieldInfo ActualLeft;
+ private static readonly FieldInfo ActualTop;
+ private static readonly Dictionary Devices = new Dictionary();
+
+ static MessageTouchDevice() {
+ ActualLeft = typeof(Window).GetField("_actualLeft", BindingFlags.Instance | BindingFlags.NonPublic);
+ ActualTop = typeof(Window).GetField("_actualTop", BindingFlags.Instance | BindingFlags.NonPublic);
+ }
+
+ public static void RegisterTouchWindow(IntPtr hWnd) {
+ TabletHelper.DisableWpfTabletSupport(hWnd);
+ TuaRua.FreSharp.Utils.WinApi.RegisterTouchWindow(hWnd, TouchWindowFlags.TWF_WANTPALM);
+ }
+
+ public static void WndProc(Window window, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
+ if (msg != WinApi.WM_TOUCH) return;
+ var inputCount = wParam.ToInt32() & 0xffff;
+ var inputs = new TouchInput[inputCount];
+ if (WinApi.GetTouchInputInfo(lParam, inputCount, inputs, WinApi.TouchInputSize)) {
+ for (var i = 0; i < inputCount; i++) {
+ var input = inputs[i];
+ var position = GraphicsHelper.DivideByDpi(new Point(input.x * 0.01, input.y * 0.01));
+ position.Offset(-(double)ActualLeft.GetValue(window), -(double)ActualTop.GetValue(window));
+ if (!Devices.TryGetValue(input.dwID, out var device)) {
+ device = new MessageTouchDevice(input.dwID);
+ Devices.Add(input.dwID, device);
+ }
+ if (!device.IsActive && input.dwFlags.HasFlag(TouchEvent.TOUCHEVENTF_DOWN)) {
+ device.SetActiveSource(PresentationSource.FromVisual(window));
+ device.Position = position;
+ device.Activate();
+ device.ReportDown();
+ }
+ else if (device.IsActive && input.dwFlags.HasFlag(TouchEvent.TOUCHEVENTF_UP)) {
+ device.Position = position;
+ device.ReportUp();
+ device.Deactivate();
+ Devices.Remove(input.dwID);
+ }
+ else if (device.IsActive && input.dwFlags.HasFlag(TouchEvent.TOUCHEVENTF_MOVE) && device.Position != position) {
+ device.Position = position;
+ device.ReportMove();
+ }
+ }
+ }
+
+ WinApi.CloseTouchInputHandle(lParam);
+ handled = true;
+ }
+
+ internal MessageTouchDevice(int id)
+ : base(id) { }
+
+ public Point Position { get; set; }
+
+ public override TouchPointCollection GetIntermediateTouchPoints(IInputElement relativeTo) {
+ return new TouchPointCollection();
+ }
+
+ public override TouchPoint GetTouchPoint(IInputElement relativeTo) {
+ var pt = Position;
+ if (relativeTo != null) {
+ if (ActiveSource != null) {
+ var rootVisual = ActiveSource.RootVisual;
+ var relativeVisual = (Visual)relativeTo;
+ if (rootVisual.IsAncestorOf(relativeVisual)) {
+ pt = rootVisual.TransformToDescendant(relativeVisual).Transform(Position);
+ }
+ }
+ }
+
+ var rect = new Rect(pt, new Size(1.0, 1.0));
+ return new TouchPoint(this, pt, rect, TouchAction.Move);
+ }
+
+ protected override void OnCapture(IInputElement element, CaptureMode captureMode) {
+ Mouse.PrimaryDevice.Capture(element, captureMode);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TabletHelper.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TabletHelper.cs
new file mode 100644
index 00000000..26b2c25d
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TabletHelper.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Reflection;
+using System.Windows.Input;
+namespace WebViewANELib.Touch {
+ public static class TabletHelper {
+ public static bool HasRemovedDevices { get; private set; }
+
+ private static readonly object StylusLogic;
+ private static readonly Type StylusLogicType;
+ private static readonly FieldInfo CountField452;
+
+ static TabletHelper() {
+ var inputManagerType = typeof(InputManager);
+ StylusLogic = inputManagerType.InvokeMember("StylusLogic", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
+ null, InputManager.Current, null);
+
+ if (StylusLogic == null) return;
+ StylusLogicType = StylusLogic.GetType();
+ CountField452 = StylusLogicType.GetField("_lastSeenDeviceCount", BindingFlags.Instance | BindingFlags.NonPublic);
+ }
+
+ public static void DisableWpfTabletSupport(IntPtr hWnd) {
+ while (Tablet.TabletDevices.Count > 0) {
+ // Only in .Net Framework 4.5.2 - see https://connect.microsoft.com/VisualStudio/Feedback/Details/1016534
+ if (CountField452 != null) {
+ CountField452.SetValue(StylusLogic, 1 + (int)CountField452.GetValue(StylusLogic));
+ }
+ var index = Tablet.TabletDevices.Count - 1;
+
+ StylusLogicType.InvokeMember("OnTabletRemoved", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
+ null, StylusLogic, new object[] { (uint)index });
+
+ HasRemovedDevices = true;
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TouchEvent.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TouchEvent.cs
new file mode 100644
index 00000000..b1fe2c93
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TouchEvent.cs
@@ -0,0 +1,11 @@
+using System;
+// ReSharper disable IdentifierTypo
+
+namespace WebViewANELib.Touch {
+ [Flags]
+ internal enum TouchEvent {
+ TOUCHEVENTF_MOVE = 0x0001,
+ TOUCHEVENTF_DOWN = 0x0002,
+ TOUCHEVENTF_UP = 0x0004,
+ }
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TouchInput.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TouchInput.cs
new file mode 100644
index 00000000..002b5d9f
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/TouchInput.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Runtime.InteropServices;
+
+// ReSharper disable IdentifierTypo
+namespace WebViewANELib.Touch {
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct TouchInput {
+ public int x;
+ public int y;
+ public IntPtr hSource;
+ public int dwID;
+ public TouchEvent dwFlags;
+ public int dwMask;
+ public int dwTime;
+ public IntPtr dwExtraInfo;
+ public int cxContact;
+ public int cyContact;
+ }
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/WinApi.cs b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/WinApi.cs
new file mode 100644
index 00000000..4d1c0ff1
--- /dev/null
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/Touch/WinApi.cs
@@ -0,0 +1,36 @@
+#region License
+// Copyright 2017 Tua Rua Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// All Rights Reserved. Tua Rua Ltd.
+#endregion
+using System;
+using System.Runtime.InteropServices;
+
+namespace WebViewANELib.Touch {
+ internal static class WinApi {
+ // ReSharper disable once InconsistentNaming
+ public const int WM_TOUCH = 0x0240;
+
+ public static readonly int TouchInputSize = Marshal.SizeOf(new TouchInput());
+
+ [DllImport("user32")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool GetTouchInputInfo(IntPtr hTouchInput, int cInputs, [In, Out] TouchInput[] pInputs, int cbSize);
+
+ [DllImport("user32")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern void CloseTouchInputHandle(IntPtr lParam);
+ }
+}
\ No newline at end of file
diff --git a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/WebViewANELib.csproj b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/WebViewANELib.csproj
index 596294ae..cca6e946 100644
--- a/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/WebViewANELib.csproj
+++ b/native_library/win/WebViewANE/WebViewANELib/WebViewANELib/WebViewANELib.csproj
@@ -101,9 +101,16 @@
+
+
+
+
+
+
+