plusui-native-core 0.1.42 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Core/CMakeLists.txt +1 -0
- package/Core/Features/Window/window.cpp +77 -66
- package/package.json +1 -1
package/Core/CMakeLists.txt
CHANGED
|
@@ -767,6 +767,12 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
|
|
|
767
767
|
Window win;
|
|
768
768
|
win.pImpl->config = config;
|
|
769
769
|
|
|
770
|
+
// Pure native file-drop mode: when native FileDrop is enabled,
|
|
771
|
+
// fully disable browser/WebView drag-drop handling.
|
|
772
|
+
if (win.pImpl->config.enableFileDrop) {
|
|
773
|
+
win.pImpl->config.disableWebviewDragDrop = true;
|
|
774
|
+
}
|
|
775
|
+
|
|
770
776
|
#ifdef _WIN32
|
|
771
777
|
HWND hwnd = static_cast<HWND>(windowHandle);
|
|
772
778
|
|
|
@@ -829,24 +835,31 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
|
|
|
829
835
|
// and allows the native FileDrop API to handle them instead
|
|
830
836
|
if (pImpl->config.disableWebviewDragDrop) {
|
|
831
837
|
std::string disableDragDropScript = R"(
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
838
|
+
(function() {
|
|
839
|
+
if (window.__plusui_nativeFileDropOnly) return;
|
|
840
|
+
window.__plusui_nativeFileDropOnly = true;
|
|
841
|
+
|
|
842
|
+
var block = function(e) {
|
|
843
|
+
if (!e) return false;
|
|
844
|
+
e.preventDefault();
|
|
845
|
+
e.stopPropagation();
|
|
846
|
+
if (typeof e.stopImmediatePropagation === 'function') {
|
|
847
|
+
e.stopImmediatePropagation();
|
|
848
|
+
}
|
|
849
|
+
if (e.dataTransfer) {
|
|
850
|
+
try { e.dataTransfer.dropEffect = 'none'; } catch (_) {}
|
|
851
|
+
}
|
|
852
|
+
return false;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
window.__plusui_dragDropEvents = ['dragenter', 'dragover', 'dragleave', 'drop'];
|
|
856
|
+
window.__plusui_dragDropBlocker = block;
|
|
857
|
+
|
|
858
|
+
window.__plusui_dragDropEvents.forEach(function(eventName) {
|
|
859
|
+
window.addEventListener(eventName, block, true);
|
|
860
|
+
document.addEventListener(eventName, block, true);
|
|
861
|
+
});
|
|
862
|
+
})();
|
|
850
863
|
)";
|
|
851
864
|
pImpl->webview->AddScriptToExecuteOnDocumentCreated(
|
|
852
865
|
std::wstring(disableDragDropScript.begin(),
|
|
@@ -1175,17 +1188,21 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
|
|
|
1175
1188
|
// Disable webview drag & drop behavior to allow native FileDrop API
|
|
1176
1189
|
if (win.pImpl->config.disableWebviewDragDrop) {
|
|
1177
1190
|
NSString *disableDragDropScript = @"(function() {"
|
|
1178
|
-
"
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
"
|
|
1185
|
-
"
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1191
|
+
"if (window.__plusui_nativeFileDropOnly) return;"
|
|
1192
|
+
"window.__plusui_nativeFileDropOnly = true;"
|
|
1193
|
+
"var block = function(e) {"
|
|
1194
|
+
"if (!e) return false;"
|
|
1195
|
+
"e.preventDefault();"
|
|
1196
|
+
"e.stopPropagation();"
|
|
1197
|
+
"if (typeof e.stopImmediatePropagation === 'function') e.stopImmediatePropagation();"
|
|
1198
|
+
"if (e.dataTransfer) { try { e.dataTransfer.dropEffect = 'none'; } catch (_) {} }"
|
|
1199
|
+
"return false;"
|
|
1200
|
+
"};"
|
|
1201
|
+
"window.__plusui_dragDropEvents = ['dragenter','dragover','dragleave','drop'];"
|
|
1202
|
+
"window.__plusui_dragDropBlocker = block;"
|
|
1203
|
+
"window.__plusui_dragDropEvents.forEach(function(eventName) {"
|
|
1204
|
+
"window.addEventListener(eventName, block, true);"
|
|
1205
|
+
"document.addEventListener(eventName, block, true);"
|
|
1189
1206
|
"});"
|
|
1190
1207
|
"})();";
|
|
1191
1208
|
|
|
@@ -1299,29 +1316,6 @@ void Window::navigate(const std::string &url) {
|
|
|
1299
1316
|
webkit_web_view_load_uri(pImpl->gtkWebView, url.c_str());
|
|
1300
1317
|
}
|
|
1301
1318
|
#endif
|
|
1302
|
-
|
|
1303
|
-
// Apply scrollbar hiding CSS if configured
|
|
1304
|
-
if (!pImpl->config.scrollbars) {
|
|
1305
|
-
std::string hideScrollbars = kHideScrollbarsScript;
|
|
1306
|
-
// Schedule this to run after a short delay to ensure DOM is ready
|
|
1307
|
-
#ifdef _WIN32
|
|
1308
|
-
if (pImpl->ready && pImpl->webview) {
|
|
1309
|
-
pImpl->webview->ExecuteScript(
|
|
1310
|
-
std::wstring(hideScrollbars.begin(), hideScrollbars.end()).c_str(),
|
|
1311
|
-
nullptr);
|
|
1312
|
-
}
|
|
1313
|
-
#elif defined(__APPLE__)
|
|
1314
|
-
if (pImpl->wkWebView) {
|
|
1315
|
-
NSString *js = [NSString stringWithUTF8String:hideScrollbars.c_str()];
|
|
1316
|
-
[pImpl->wkWebView evaluateJavaScript:js completionHandler:nil];
|
|
1317
|
-
}
|
|
1318
|
-
#else
|
|
1319
|
-
if (pImpl->gtkWebView) {
|
|
1320
|
-
webkit_web_view_run_javascript(pImpl->gtkWebView, hideScrollbars.c_str(),
|
|
1321
|
-
nullptr, nullptr, nullptr);
|
|
1322
|
-
}
|
|
1323
|
-
#endif
|
|
1324
|
-
}
|
|
1325
1319
|
}
|
|
1326
1320
|
|
|
1327
1321
|
void Window::loadURL(const std::string &url) {
|
|
@@ -1654,30 +1648,47 @@ void Window::setWebviewDragDropEnabled(bool enabled) {
|
|
|
1654
1648
|
// Enable webview drag-drop by removing our prevention handlers
|
|
1655
1649
|
script = R"(
|
|
1656
1650
|
(function() {
|
|
1657
|
-
|
|
1658
|
-
|
|
1651
|
+
var events = window.__plusui_dragDropEvents || ['dragenter', 'dragover', 'dragleave', 'drop'];
|
|
1652
|
+
var blocker = window.__plusui_dragDropBlocker;
|
|
1653
|
+
if (blocker) {
|
|
1654
|
+
events.forEach(function(eventName) {
|
|
1655
|
+
window.removeEventListener(eventName, blocker, true);
|
|
1656
|
+
document.removeEventListener(eventName, blocker, true);
|
|
1657
|
+
});
|
|
1659
1658
|
}
|
|
1659
|
+
delete window.__plusui_dragDropBlocker;
|
|
1660
|
+
delete window.__plusui_dragDropEvents;
|
|
1661
|
+
delete window.__plusui_dragDropDisabled;
|
|
1662
|
+
delete window.__plusui_nativeFileDropOnly;
|
|
1660
1663
|
})();
|
|
1661
1664
|
)";
|
|
1662
1665
|
} else {
|
|
1663
1666
|
// Disable webview drag-drop by preventing default behavior
|
|
1664
1667
|
script = R"(
|
|
1665
1668
|
(function() {
|
|
1666
|
-
if (window.
|
|
1669
|
+
if (window.__plusui_nativeFileDropOnly) return;
|
|
1670
|
+
window.__plusui_nativeFileDropOnly = true;
|
|
1667
1671
|
window.__plusui_dragDropDisabled = true;
|
|
1668
1672
|
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
}
|
|
1673
|
+
var block = function(e) {
|
|
1674
|
+
if (!e) return false;
|
|
1675
|
+
e.preventDefault();
|
|
1676
|
+
e.stopPropagation();
|
|
1677
|
+
if (typeof e.stopImmediatePropagation === 'function') {
|
|
1678
|
+
e.stopImmediatePropagation();
|
|
1679
|
+
}
|
|
1680
|
+
if (e.dataTransfer) {
|
|
1681
|
+
try { e.dataTransfer.dropEffect = 'none'; } catch (_) {}
|
|
1682
|
+
}
|
|
1683
|
+
return false;
|
|
1684
|
+
};
|
|
1685
|
+
|
|
1686
|
+
window.__plusui_dragDropEvents = ['dragenter', 'dragover', 'dragleave', 'drop'];
|
|
1687
|
+
window.__plusui_dragDropBlocker = block;
|
|
1676
1688
|
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
}, true);
|
|
1689
|
+
window.__plusui_dragDropEvents.forEach(function(eventName) {
|
|
1690
|
+
window.addEventListener(eventName, block, true);
|
|
1691
|
+
document.addEventListener(eventName, block, true);
|
|
1681
1692
|
});
|
|
1682
1693
|
})();
|
|
1683
1694
|
)";
|