From 41e109ecc963d4730f7679eaac795c3c3eb3a1ad Mon Sep 17 00:00:00 2001 From: Gaku Date: Sat, 9 Mar 2024 21:54:18 +0900 Subject: [PATCH] 24.3.9 WebView2.1.0.2365.46 --- tewv/Resource.h | 2 +- tewv/packages.config | 2 +- tewv/tewv.cpp | 96 ++++++++++++++++++++++++++++++++++---------- tewv/tewv.h | 19 +++++++++ tewv/tewv.vcxproj | 4 +- 5 files changed, 98 insertions(+), 25 deletions(-) diff --git a/tewv/Resource.h b/tewv/Resource.h index 56dada0..8efe208 100644 --- a/tewv/Resource.h +++ b/tewv/Resource.h @@ -4,6 +4,6 @@ #define STRING(str) STRING2(str) #define STRING2(str) #str #define VER_Y 24 -#define VER_M 1 +#define VER_M 3 #define VER_D 9 #define VER_Z 0 diff --git a/tewv/packages.config b/tewv/packages.config index e84f784..21a8a2b 100644 --- a/tewv/packages.config +++ b/tewv/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/tewv/tewv.cpp b/tewv/tewv.cpp index 5eba87e..37de9ad 100644 --- a/tewv/tewv.cpp +++ b/tewv/tewv.cpp @@ -438,6 +438,10 @@ CteBase::CteBase() m_pDocument = NULL; m_webviewController = NULL; m_webviewWindow = NULL; +#ifdef USE_DRAGDROP + m_webviewEnvironment3 = NULL; + m_webviewCompositionController3 = NULL; +#endif } CteBase::~CteBase() @@ -451,7 +455,20 @@ CteBase::~CteBase() SafeRelease(&m_pDocument); SafeRelease(&m_webviewController); SafeRelease(&m_webviewWindow); +#ifdef USE_DRAGDROP + SafeRelease(&m_webviewCompositionController3); + SafeRelease(&m_webviewEnvironment3); +#endif +} + +#ifdef USE_DRAGDROP +VOID CteBase::OffsetPointToWebView(LPPOINT ppt) +{ + HWND hwnd; + GetWindow(&hwnd); + ::ScreenToClient(hwnd, ppt); } +#endif STDMETHODIMP CteBase::QueryInterface(REFIID riid, void **ppvObject) { @@ -473,6 +490,9 @@ STDMETHODIMP CteBase::QueryInterface(REFIID riid, void **ppvObject) QITABENT(CteBase, IServiceProvider), QITABENT(CteBase, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler), QITABENT(CteBase, ICoreWebView2CreateCoreWebView2ControllerCompletedHandler), +#ifdef USE_DRAGDROP + QITABENT(CteBase, ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler), +#endif QITABENT(CteBase, ICoreWebView2DocumentTitleChangedEventHandler), QITABENT(CteBase, ICoreWebView2NavigationCompletedEventHandler), { 0 } @@ -797,7 +817,7 @@ STDMETHODIMP CteBase::get_HWND(SHANDLE_PTR *pHWND) HWND hwnd; HRESULT hr = GetWindow(&hwnd); *pHWND = (HANDLE_PTR)hwnd; - return S_OK; + return hr; } STDMETHODIMP CteBase::get_FullName(BSTR *FullName) @@ -964,6 +984,11 @@ STDMETHODIMP CteBase::put_RegisterAsDropTarget(VARIANT_BOOL bRegister) pDocHostUIHandler->GetDropTarget(this, &pDropTarget); RegisterDragDrop(hwnd, pDropTarget); pDropTarget->Release(); +#ifdef USE_DRAGDROP + if (m_webviewEnvironment3) { + m_webviewEnvironment3->CreateCoreWebView2CompositionController(m_hwndParent, this); + } +#endif } } return S_OK; @@ -1067,8 +1092,9 @@ STDMETHODIMP CteBase::DoVerb(LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSit } auto options = Microsoft::WRL::Make(); if (pszProxyServer[0]) { - lstrcat(pszSetting, L" --proxy-server="); + lstrcat(pszSetting, L" --proxy-server=\""); lstrcat(pszSetting, pszProxyServer); + lstrcat(pszSetting, L"\""); } options->put_AdditionalBrowserArguments(pszSetting); #ifdef _DEBUG @@ -1144,28 +1170,17 @@ STDMETHODIMP CteBase::SetColorScheme(LOGPALETTE *pLogpal) //IOleWindow STDMETHODIMP CteBase::GetWindow(HWND *phwnd) { - HRESULT hr = E_FAIL; - if (m_webviewController) { - HWND hwnd1, hwnd = NULL; - hr = m_webviewController->get_ParentWindow(&hwnd1); - if (hr == S_OK) { - hwnd = hwnd1; - hwnd1 = FindWindowEx(hwnd1, NULL, L"Chrome_WidgetWin_0", NULL); - if (hwnd1) { - hwnd = hwnd1; - hwnd1 = FindWindowEx(hwnd1, NULL, L"Chrome_WidgetWin_1", NULL); - if (hwnd1) { - hwnd = hwnd1; - hwnd1 = FindWindowEx(hwnd1, NULL, L"Chrome_RenderWidgetHostHWND", NULL); - if (hwnd1) { - hwnd = hwnd1; - } - } + if (m_hwndParent) { + *phwnd = FindWindowEx(m_hwndParent, NULL, L"Chrome_WidgetWin_0", NULL); + if (*phwnd) { + *phwnd = FindWindowEx(*phwnd, NULL, L"Chrome_WidgetWin_1", NULL); + if (*phwnd) { + *phwnd = FindWindowEx(*phwnd, NULL, L"Chrome_RenderWidgetHostHWND", NULL); + return S_OK; } } - *phwnd = hwnd; } - return hr; + return E_FAIL; } STDMETHODIMP CteBase::ContextSensitiveHelp(BOOL fEnterMode) @@ -1195,6 +1210,7 @@ STDMETHODIMP CteBase::SetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect) int deviceYDPI = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(m_hwndParent, hdc); m_webviewController->SetBoundsAndZoomFactor(*lprcClipRect, 96.0 / deviceYDPI); + CopyRect(&m_webviewBounds, lprcClipRect); return S_OK; } @@ -1209,21 +1225,47 @@ STDMETHODIMP CteBase::ReactivateAndUndo(void) //IDropTarget STDMETHODIMP CteBase::DragEnter(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { +#ifdef USE_DRAGDROP + if (m_webviewCompositionController3) { + POINT ptc = { pt.x, pt.y }; + OffsetPointToWebView(&ptc); + return m_webviewCompositionController3->DragEnter(pDataObj, grfKeyState, ptc, pdwEffect); + } +#endif return E_NOTIMPL; } STDMETHODIMP CteBase::DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { +#ifdef USE_DRAGDROP + if (m_webviewCompositionController3) { + POINT ptc = { pt.x, pt.y }; + OffsetPointToWebView(&ptc); + return m_webviewCompositionController3->DragOver(grfKeyState, ptc, pdwEffect); + } +#endif return E_NOTIMPL; } STDMETHODIMP CteBase::DragLeave() { +#ifdef USE_DRAGDROP + if (m_webviewCompositionController3) { + return m_webviewCompositionController3->DragLeave(); + } +#endif return E_NOTIMPL; } STDMETHODIMP CteBase::Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { +#ifdef USE_DRAGDROP + if (m_webviewCompositionController3) { + POINT ptc = { pt.x, pt.y }; + OffsetPointToWebView(&ptc); + return m_webviewCompositionController3->Drop(pDataObj, grfKeyState, ptc, pdwEffect); + } +#endif return E_NOTIMPL; } @@ -1325,6 +1367,9 @@ STDMETHODIMP CteBase::QueryService(REFGUID guidService, REFIID riid, void **ppv) STDMETHODIMP CteBase::Invoke(HRESULT result, ICoreWebView2Environment *created_environment) { created_environment->CreateCoreWebView2Controller(m_hwndParent, this); +#ifdef USE_DRAGDROP + created_environment->QueryInterface(IID_PPV_ARGS(&m_webviewEnvironment3)); +#endif return S_OK; } @@ -1362,6 +1407,15 @@ STDMETHODIMP CteBase::Invoke(HRESULT result, ICoreWebView2Controller *createdCon return S_OK; } +#ifdef USE_DRAGDROP +//ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler +STDMETHODIMP CteBase::Invoke(HRESULT result, ICoreWebView2CompositionController *createdController) +{ + SafeRelease(&m_webviewCompositionController3); + return createdController->QueryInterface(IID_PPV_ARGS(&m_webviewCompositionController3)); +} +#endif + //ICoreWebView2ExecuteScriptCompletedHandler STDMETHODIMP CteBase::Invoke(HRESULT result, LPCWSTR resultObjectAsJson) { diff --git a/tewv/tewv.h b/tewv/tewv.h index 6e04bdf..6b913b8 100644 --- a/tewv/tewv.h +++ b/tewv/tewv.h @@ -30,6 +30,8 @@ #define DISPID_TE_MAX TE_VI #define MAX_PATHEX 32768 +//#define USE_DRAGDROP 1 + //Tablacus Explorer (Edge) const CLSID CLSID_WebBrowserExt = {0x55bbf1b8, 0x0d30, 0x4908, { 0xbe, 0x0c, 0xd5, 0x76, 0x61, 0x2a, 0x0f, 0x48}}; // {BD34E79B-963F-4AFB-B03E-C5BD289B5080} @@ -53,6 +55,9 @@ class CteBase : public IWebBrowser2, public IOleObject, public IOleInPlaceObject public IDropTarget, public IShellBrowser, public ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, public ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, +#ifdef USE_DRAGDROP + public ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler, +#endif public ICoreWebView2ExecuteScriptCompletedHandler, public ICoreWebView2DocumentTitleChangedEventHandler, public ICoreWebView2NavigationStartingEventHandler, @@ -189,6 +194,10 @@ class CteBase : public IWebBrowser2, public IOleObject, public IOleInPlaceObject STDMETHODIMP Invoke(HRESULT result, ICoreWebView2Environment *created_environment); //ICoreWebView2CreateCoreWebView2ControllerCompletedHandler STDMETHODIMP Invoke(HRESULT result, ICoreWebView2Controller *createdController); +#ifdef USE_DRAGDROP + //ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler + STDMETHODIMP Invoke(HRESULT result, ICoreWebView2CompositionController *createdController); +#endif //ICoreWebView2ExecuteScriptCompletedHandler STDMETHODIMP Invoke(HRESULT result, LPCWSTR resultObjectAsJson); //ICoreWebView2DocumentTitleChangedEventHandler @@ -200,18 +209,28 @@ class CteBase : public IWebBrowser2, public IOleObject, public IOleInPlaceObject CteBase(); ~CteBase(); + +#ifdef USE_DRAGDROP + VOID OffsetPointToWebView(LPPOINT point); +#endif private: IOleClientSite *m_pOleClientSite; IDispatch *m_pdisp; HWND m_hwndParent; ICoreWebView2Controller *m_webviewController; ICoreWebView2 *m_webviewWindow; +#ifdef USE_DRAGDROP + ICoreWebView2Environment3 *m_webviewEnvironment3; + ICoreWebView2CompositionController3 *m_webviewCompositionController3; +#endif EventRegistrationToken m_documentTitleChangedToken; EventRegistrationToken m_navigationStartingToken; EventRegistrationToken m_navigationCompletedToken; BSTR m_bstrPath; +// HANDLE m_hOleDropTargetInterface; IDispatch *m_pDocument; + RECT m_webviewBounds; LONG m_cRef; }; diff --git a/tewv/tewv.vcxproj b/tewv/tewv.vcxproj index b7461c1..f4b1472 100644 --- a/tewv/tewv.vcxproj +++ b/tewv/tewv.vcxproj @@ -157,7 +157,7 @@ - + Static @@ -166,6 +166,6 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file