Mercurial > dwindows
comparison win/edge.cpp @ 2033:d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 16 Nov 2019 09:43:17 +0000 |
parents | 28809bf17957 |
children | 89d62197124b |
comparison
equal
deleted
inserted
replaced
2032:5ca399fb2d6f | 2033:d81d2ea806c6 |
---|---|
255 | 255 |
256 // Resize WebView to fit the bounds of the parent window | 256 // Resize WebView to fit the bounds of the parent window |
257 RECT bounds; | 257 RECT bounds; |
258 GetClientRect(hWnd, &bounds); | 258 GetClientRect(hWnd, &bounds); |
259 webview->put_Bounds(bounds); | 259 webview->put_Bounds(bounds); |
260 | |
261 // Save the token, we might need to dw_window_set_data() this value | |
262 // for later use to remove the handlers | |
263 EventRegistrationToken token; | |
264 | |
265 // Register a handler for the NavigationStarting event. | |
266 // This handler will check the domain being navigated to, and if the domain | |
267 // matches a list of blocked sites, it will cancel the navigation and | |
268 // possibly display a warning page. It will also disable JavaScript on | |
269 // selected websites. | |
270 webview->add_NavigationStarting( | |
271 Callback<IWebView2NavigationStartingEventHandler>( | |
272 [hWnd](IWebView2WebView* sender, | |
273 IWebView2NavigationStartingEventArgs* args) -> HRESULT | |
274 { | |
275 LPWSTR uri; | |
276 sender->get_Source(&uri); | |
277 | |
278 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), | |
279 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); | |
280 | |
281 return S_OK; | |
282 }).Get(), &token); | |
283 | |
284 // Register a handler for the DocumentStateChanged event. | |
285 // This handler will read the webview's source URI and update | |
286 // the app's address bar. | |
287 webview->add_DocumentStateChanged( | |
288 Callback<IWebView2DocumentStateChangedEventHandler>( | |
289 [hWnd](IWebView2WebView* sender, | |
290 IWebView2DocumentStateChangedEventArgs* args) -> HRESULT | |
291 { | |
292 LPWSTR uri; | |
293 sender->get_Source(&uri); | |
294 | |
295 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), | |
296 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); | |
297 | |
298 return S_OK; | |
299 }).Get(), &token); | |
300 | |
301 // Register a handler for the NavigationCompleted event. | |
302 // If the navigation was successful, update the back and forward buttons. | |
303 webview->add_NavigationCompleted( | |
304 Callback<IWebView2NavigationCompletedEventHandler>( | |
305 [hWnd](IWebView2WebView* sender, | |
306 IWebView2NavigationCompletedEventArgs* args) -> HRESULT | |
307 { | |
308 LPWSTR uri; | |
309 sender->get_Source(&uri); | |
310 | |
311 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), | |
312 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); | |
313 | |
314 return S_OK; | |
315 }).Get(), &token); | |
260 | 316 |
261 // Handle cached load requests due to delayed | 317 // Handle cached load requests due to delayed |
262 // loading of the edge webview contexts | 318 // loading of the edge webview contexts |
263 LPCWSTR url = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_LOCATION); | 319 LPCWSTR url = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_LOCATION); |
264 if(url) | 320 if(url) |
292 if (webview) | 348 if (webview) |
293 { | 349 { |
294 dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, NULL); | 350 dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, NULL); |
295 webview->Close(); | 351 webview->Close(); |
296 } | 352 } |
297 _free_window_memory(hwnd, 0); | 353 _free_window_memory(hWnd, 0); |
298 return(TRUE); | 354 return(TRUE); |
299 } | 355 } |
300 } | 356 } |
301 | 357 |
302 return(DefWindowProc(hWnd, uMsg, wParam, lParam)); | 358 return(DefWindowProc(hWnd, uMsg, wParam, lParam)); |