Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webview2-com and windows crates #446

Merged
merged 7 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/windows-0.25.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Update the `windows` crate to 0.25.0, which comes with pre-built libraries. WRY and Tao can both reference the same types directly from the `windows` crate instead of sharing bindings in `webview2-com-sys`.
15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ gtk = "0.14"
gdk = "0.14"

[target."cfg(target_os = \"windows\")".dependencies]
webview2-com = "0.4.0"
windows = "0.19.0"
webview2-com = "0.7.0"

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.25.0"
features = [
"build",
"Win32_Foundation",
"Win32_System_Com",
"Win32_System_Ole",
"Win32_System_SystemServices",
"Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging",
]

[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
cocoa = "0.24"
Expand Down
7 changes: 3 additions & 4 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub(crate) mod webview2;
use self::webview2::*;
use crate::{Error, Result};
#[cfg(target_os = "windows")]
use webview2_com::{
Microsoft::Web::WebView2::Win32::ICoreWebView2Controller, Windows::Win32::Foundation::HWND,
};
use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller;
#[cfg(target_os = "windows")]
use windows::{Win32::Foundation::HWND, Win32::UI::WindowsAndMessaging::DestroyWindow};

use std::{path::PathBuf, rc::Rc};

Expand Down Expand Up @@ -373,7 +373,6 @@ impl Drop for WebView {
}
#[cfg(target_os = "windows")]
unsafe {
use webview2_com::Windows::Win32::UI::WindowsAndMessaging::DestroyWindow;
DestroyWindow(HWND(self.window.hwnd() as _));
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/webview/webview2/file_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ use std::{
rc::Rc,
};

use webview2_com::Windows::{
self,
use windows::{
self as Windows,
runtime::implement,
Win32::{
Foundation::{self as win32f, BOOL, DRAGDROP_E_INVALIDHWND, HWND, LPARAM, POINTL, PWSTR},
System::{
Com::{
IDataObject, IDropTarget, RegisterDragDrop, RevokeDragDrop, DROPEFFECT_COPY,
DROPEFFECT_NONE, DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL,
},
Com::{IDataObject, DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL},
Ole::{IDropTarget, RegisterDragDrop, RevokeDragDrop, DROPEFFECT_COPY, DROPEFFECT_NONE},
SystemServices::CF_HDROP,
},
UI::{
Expand Down Expand Up @@ -102,7 +101,7 @@ unsafe extern "system" fn enumerate_callback(hwnd: HWND, lparam: LPARAM) -> BOOL
closure(hwnd).into()
}

#[windows::implement(Windows::Win32::System::Com::IDropTarget)]
#[implement(Windows::Win32::System::Ole::IDropTarget)]
pub struct FileDropHandler {
window: Rc<Window>,
listener: Rc<dyn Fn(&Window, FileDropEvent) -> bool>,
Expand Down Expand Up @@ -130,7 +129,7 @@ impl FileDropHandler {
_grfKeyState: u32,
_pt: POINTL,
pdwEffect: *mut u32,
) -> windows::Result<()> {
) -> windows::runtime::Result<()> {
let mut paths = Vec::new();
let hdrop = Self::collect_paths(pDataObj, &mut paths);
self.hovered_is_valid = hdrop.is_some();
Expand All @@ -151,12 +150,12 @@ impl FileDropHandler {
_grfKeyState: u32,
_pt: POINTL,
pdwEffect: *mut u32,
) -> windows::Result<()> {
) -> windows::runtime::Result<()> {
*pdwEffect = self.cursor_effect;
Ok(())
}

unsafe fn DragLeave(&self) -> windows::Result<()> {
unsafe fn DragLeave(&self) -> windows::runtime::Result<()> {
if self.hovered_is_valid {
(self.listener)(&self.window, FileDropEvent::Cancelled);
}
Expand All @@ -169,7 +168,7 @@ impl FileDropHandler {
_grfKeyState: u32,
_pt: POINTL,
_pdwEffect: *mut u32,
) -> windows::Result<()> {
) -> windows::runtime::Result<()> {
let mut paths = Vec::new();
let hdrop = Self::collect_paths(pDataObj, &mut paths);
if let Some(hdrop) = hdrop {
Expand All @@ -185,7 +184,7 @@ impl FileDropHandler {
data_obj: &Option<IDataObject>,
paths: &mut Vec<PathBuf>,
) -> Option<HDROP> {
let mut drop_format = FORMATETC {
let drop_format = FORMATETC {
cfFormat: CF_HDROP.0 as u16,
ptd: ptr::null_mut(),
dwAspect: DVASPECT_CONTENT.0 as u32,
Expand All @@ -196,7 +195,7 @@ impl FileDropHandler {
match data_obj
.as_ref()
.expect("Received null IDataObject")
.GetData(&mut drop_format)
.GetData(&drop_format)
{
Ok(medium) => {
let hglobal = medium.Anonymous.hGlobal;
Expand Down
Loading