@@ -438,6 +438,10 @@ CteBase::CteBase()
438438 m_pDocument = NULL ;
439439 m_webviewController = NULL ;
440440 m_webviewWindow = NULL ;
441+ #ifdef USE_DRAGDROP
442+ m_webviewEnvironment3 = NULL ;
443+ m_webviewCompositionController3 = NULL ;
444+ #endif
441445}
442446
443447CteBase::~CteBase ()
@@ -451,7 +455,20 @@ CteBase::~CteBase()
451455 SafeRelease (&m_pDocument);
452456 SafeRelease (&m_webviewController);
453457 SafeRelease (&m_webviewWindow);
458+ #ifdef USE_DRAGDROP
459+ SafeRelease (&m_webviewCompositionController3);
460+ SafeRelease (&m_webviewEnvironment3);
461+ #endif
462+ }
463+
464+ #ifdef USE_DRAGDROP
465+ VOID CteBase::OffsetPointToWebView (LPPOINT ppt)
466+ {
467+ HWND hwnd;
468+ GetWindow (&hwnd);
469+ ::ScreenToClient (hwnd, ppt);
454470}
471+ #endif
455472
456473STDMETHODIMP CteBase::QueryInterface (REFIID riid, void **ppvObject)
457474{
@@ -473,6 +490,9 @@ STDMETHODIMP CteBase::QueryInterface(REFIID riid, void **ppvObject)
473490 QITABENT (CteBase, IServiceProvider),
474491 QITABENT (CteBase, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler),
475492 QITABENT (CteBase, ICoreWebView2CreateCoreWebView2ControllerCompletedHandler),
493+ #ifdef USE_DRAGDROP
494+ QITABENT (CteBase, ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler),
495+ #endif
476496 QITABENT (CteBase, ICoreWebView2DocumentTitleChangedEventHandler),
477497 QITABENT (CteBase, ICoreWebView2NavigationCompletedEventHandler),
478498 { 0 }
@@ -797,7 +817,7 @@ STDMETHODIMP CteBase::get_HWND(SHANDLE_PTR *pHWND)
797817 HWND hwnd;
798818 HRESULT hr = GetWindow (&hwnd);
799819 *pHWND = (HANDLE_PTR )hwnd;
800- return S_OK ;
820+ return hr ;
801821}
802822
803823STDMETHODIMP CteBase::get_FullName (BSTR *FullName)
@@ -964,6 +984,11 @@ STDMETHODIMP CteBase::put_RegisterAsDropTarget(VARIANT_BOOL bRegister)
964984 pDocHostUIHandler->GetDropTarget (this , &pDropTarget);
965985 RegisterDragDrop (hwnd, pDropTarget);
966986 pDropTarget->Release ();
987+ #ifdef USE_DRAGDROP
988+ if (m_webviewEnvironment3) {
989+ m_webviewEnvironment3->CreateCoreWebView2CompositionController (m_hwndParent, this );
990+ }
991+ #endif
967992 }
968993 }
969994 return S_OK ;
@@ -1067,8 +1092,9 @@ STDMETHODIMP CteBase::DoVerb(LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSit
10671092 }
10681093 auto options = Microsoft::WRL ::Make<CoreWebView2EnvironmentOptions>();
10691094 if (pszProxyServer[0 ]) {
1070- lstrcat (pszSetting, L" --proxy-server=" );
1095+ lstrcat (pszSetting, L" --proxy-server=\" " );
10711096 lstrcat (pszSetting, pszProxyServer);
1097+ lstrcat (pszSetting, L" \" " );
10721098 }
10731099 options->put_AdditionalBrowserArguments (pszSetting);
10741100#ifdef _DEBUG
@@ -1144,28 +1170,17 @@ STDMETHODIMP CteBase::SetColorScheme(LOGPALETTE *pLogpal)
11441170// IOleWindow
11451171STDMETHODIMP CteBase::GetWindow (HWND *phwnd)
11461172{
1147- HRESULT hr = E_FAIL ;
1148- if (m_webviewController) {
1149- HWND hwnd1, hwnd = NULL ;
1150- hr = m_webviewController->get_ParentWindow (&hwnd1);
1151- if (hr == S_OK ) {
1152- hwnd = hwnd1;
1153- hwnd1 = FindWindowEx (hwnd1, NULL , L" Chrome_WidgetWin_0" , NULL );
1154- if (hwnd1) {
1155- hwnd = hwnd1;
1156- hwnd1 = FindWindowEx (hwnd1, NULL , L" Chrome_WidgetWin_1" , NULL );
1157- if (hwnd1) {
1158- hwnd = hwnd1;
1159- hwnd1 = FindWindowEx (hwnd1, NULL , L" Chrome_RenderWidgetHostHWND" , NULL );
1160- if (hwnd1) {
1161- hwnd = hwnd1;
1162- }
1163- }
1173+ if (m_hwndParent) {
1174+ *phwnd = FindWindowEx (m_hwndParent, NULL , L" Chrome_WidgetWin_0" , NULL );
1175+ if (*phwnd) {
1176+ *phwnd = FindWindowEx (*phwnd, NULL , L" Chrome_WidgetWin_1" , NULL );
1177+ if (*phwnd) {
1178+ *phwnd = FindWindowEx (*phwnd, NULL , L" Chrome_RenderWidgetHostHWND" , NULL );
1179+ return S_OK ;
11641180 }
11651181 }
1166- *phwnd = hwnd;
11671182 }
1168- return hr ;
1183+ return E_FAIL ;
11691184}
11701185
11711186STDMETHODIMP CteBase::ContextSensitiveHelp (BOOL fEnterMode )
@@ -1195,6 +1210,7 @@ STDMETHODIMP CteBase::SetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
11951210 int deviceYDPI = GetDeviceCaps (hdc, LOGPIXELSY );
11961211 ReleaseDC (m_hwndParent, hdc);
11971212 m_webviewController->SetBoundsAndZoomFactor (*lprcClipRect, 96.0 / deviceYDPI);
1213+ CopyRect (&m_webviewBounds, lprcClipRect);
11981214 return S_OK ;
11991215}
12001216
@@ -1209,21 +1225,47 @@ STDMETHODIMP CteBase::ReactivateAndUndo(void)
12091225// IDropTarget
12101226STDMETHODIMP CteBase::DragEnter (IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
12111227{
1228+ #ifdef USE_DRAGDROP
1229+ if (m_webviewCompositionController3) {
1230+ POINT ptc = { pt.x , pt.y };
1231+ OffsetPointToWebView (&ptc);
1232+ return m_webviewCompositionController3->DragEnter (pDataObj, grfKeyState, ptc, pdwEffect);
1233+ }
1234+ #endif
12121235 return E_NOTIMPL ;
12131236}
12141237
12151238STDMETHODIMP CteBase::DragOver (DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
12161239{
1240+ #ifdef USE_DRAGDROP
1241+ if (m_webviewCompositionController3) {
1242+ POINT ptc = { pt.x , pt.y };
1243+ OffsetPointToWebView (&ptc);
1244+ return m_webviewCompositionController3->DragOver (grfKeyState, ptc, pdwEffect);
1245+ }
1246+ #endif
12171247 return E_NOTIMPL ;
12181248}
12191249
12201250STDMETHODIMP CteBase::DragLeave ()
12211251{
1252+ #ifdef USE_DRAGDROP
1253+ if (m_webviewCompositionController3) {
1254+ return m_webviewCompositionController3->DragLeave ();
1255+ }
1256+ #endif
12221257 return E_NOTIMPL ;
12231258}
12241259
12251260STDMETHODIMP CteBase::Drop (IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
12261261{
1262+ #ifdef USE_DRAGDROP
1263+ if (m_webviewCompositionController3) {
1264+ POINT ptc = { pt.x , pt.y };
1265+ OffsetPointToWebView (&ptc);
1266+ return m_webviewCompositionController3->Drop (pDataObj, grfKeyState, ptc, pdwEffect);
1267+ }
1268+ #endif
12271269 return E_NOTIMPL ;
12281270}
12291271
@@ -1325,6 +1367,9 @@ STDMETHODIMP CteBase::QueryService(REFGUID guidService, REFIID riid, void **ppv)
13251367STDMETHODIMP CteBase::Invoke (HRESULT result, ICoreWebView2Environment *created_environment)
13261368{
13271369 created_environment->CreateCoreWebView2Controller (m_hwndParent, this );
1370+ #ifdef USE_DRAGDROP
1371+ created_environment->QueryInterface (IID_PPV_ARGS (&m_webviewEnvironment3));
1372+ #endif
13281373 return S_OK ;
13291374}
13301375
@@ -1362,6 +1407,15 @@ STDMETHODIMP CteBase::Invoke(HRESULT result, ICoreWebView2Controller *createdCon
13621407 return S_OK ;
13631408}
13641409
1410+ #ifdef USE_DRAGDROP
1411+ // ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler
1412+ STDMETHODIMP CteBase::Invoke (HRESULT result, ICoreWebView2CompositionController *createdController)
1413+ {
1414+ SafeRelease (&m_webviewCompositionController3);
1415+ return createdController->QueryInterface (IID_PPV_ARGS (&m_webviewCompositionController3));
1416+ }
1417+ #endif
1418+
13651419// ICoreWebView2ExecuteScriptCompletedHandler
13661420STDMETHODIMP CteBase::Invoke (HRESULT result, LPCWSTR resultObjectAsJson)
13671421{
0 commit comments