Mercurial > dwindows
comparison win/edge.cpp @ 2001:f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
prior to finishing loading save location and raw HTML data requests and
then actually load it when the browser context has finished loading.
Also actually detect Edge (Chromium) instead of just returning TRUE.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 31 Oct 2019 21:28:32 +0000 |
parents | 77e43d71eaa7 |
children | c30f4354966e |
comparison
equal
deleted
inserted
replaced
2000:77e43d71eaa7 | 2001:f7acca46f795 |
---|---|
14 #include <wrl.h> | 14 #include <wrl.h> |
15 | 15 |
16 using namespace Microsoft::WRL; | 16 using namespace Microsoft::WRL; |
17 | 17 |
18 #define _DW_HTML_DATA_NAME (char *)"_dw_edge" | 18 #define _DW_HTML_DATA_NAME (char *)"_dw_edge" |
19 #define _DW_HTML_DATA_LOCATION (char *)"_dw_edge_location" | |
20 #define _DW_HTML_DATA_RAW (char *)"_dw_edge_raw" | |
19 | 21 |
20 extern "C" { | 22 extern "C" { |
21 | 23 |
24 extern HWND DW_HWND_OBJECT; | |
25 BOOL DW_EDGE_DETECTED = FALSE; | |
26 | |
27 /******************************* dw_edge_detect() ************************** | |
28 * Attempts to create a temporary Edge (Chromium) browser context... | |
29 * If we succeed return TRUE and use Edge for HTML windows. | |
30 * If it fails return FALSE and fall back to using embedded IE. | |
31 */ | |
22 BOOL _dw_edge_detect(VOID) | 32 BOOL _dw_edge_detect(VOID) |
23 { | 33 { |
24 return TRUE; | 34 HWND hWnd = DW_HWND_OBJECT; |
25 } | 35 |
26 | 36 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
27 /******************************* dw_html_action() ************************** | 37 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
38 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { | |
39 // Successfully created Edge environment, return TRUE | |
40 DW_EDGE_DETECTED = TRUE; | |
41 return S_OK; | |
42 }).Get()); | |
43 return DW_EDGE_DETECTED; | |
44 } | |
45 | |
46 /******************************* dw_edge_action() ************************** | |
28 * Implements the functionality of a "Back". "Forward", "Home", "Search", | 47 * Implements the functionality of a "Back". "Forward", "Home", "Search", |
29 * "Refresh", or "Stop" button. | 48 * "Refresh", or "Stop" button. |
30 * | 49 * |
31 * hwnd = Handle to the window hosting the browser object. | 50 * hwnd = Handle to the window hosting the browser object. |
32 * action = One of the following: | 51 * action = One of the following: |
94 } | 113 } |
95 } | 114 } |
96 } | 115 } |
97 } | 116 } |
98 | 117 |
99 /******************************* dw_html_raw() **************************** | 118 /******************************* dw_edge_raw() **************************** |
100 * Takes a string containing some HTML BODY, and displays it in the specified | 119 * Takes a string containing some HTML BODY, and displays it in the specified |
101 * window. For example, perhaps you want to display the HTML text of... | 120 * window. For example, perhaps you want to display the HTML text of... |
102 * | 121 * |
103 * <P>This is a picture.<P><IMG src="mypic.jpg"> | 122 * <P>This is a picture.<P><IMG src="mypic.jpg"> |
104 * | 123 * |
116 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when | 135 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
117 // we initially attached the browser object to this window. | 136 // we initially attached the browser object to this window. |
118 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); | 137 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
119 | 138 |
120 if (webview) | 139 if (webview) |
121 { | 140 webview->NavigateToString(string); |
122 return DW_ERROR_NONE; | 141 else |
123 } | 142 dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(string)); |
124 return DW_ERROR_UNKNOWN; | 143 return DW_ERROR_NONE; |
125 } | 144 } |
126 | 145 |
127 /******************************* dw_html_url() **************************** | 146 /******************************* dw_edge_url() **************************** |
128 * Displays a URL, or HTML file on disk. | 147 * Displays a URL, or HTML file on disk. |
129 * | 148 * |
130 * hwnd = Handle to the window hosting the browser object. | 149 * hwnd = Handle to the window hosting the browser object. |
131 * webPageName = Pointer to nul-terminated name of the URL/file. | 150 * webPageName = Pointer to nul-terminated name of the URL/file. |
132 * | 151 * |
140 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when | 159 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
141 // we initially attached the browser object to this window. | 160 // we initially attached the browser object to this window. |
142 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); | 161 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
143 | 162 |
144 if (webview) | 163 if (webview) |
145 { | |
146 webview->Navigate(url); | 164 webview->Navigate(url); |
147 return DW_ERROR_NONE; | 165 else |
148 } | 166 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(url)); |
149 return DW_ERROR_UNKNOWN; | 167 return DW_ERROR_NONE; |
150 } | 168 } |
151 | 169 |
152 /************************** browserWindowProc() ************************* | 170 /************************** edgeWindowProc() ************************* |
153 * Our message handler for our window to host the browser. | 171 * Our message handler for our window to host the browser. |
154 */ | 172 */ |
155 | 173 |
156 LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 174 LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
157 { | 175 { |
158 switch (uMsg) | 176 switch (uMsg) |
159 { | 177 { |
160 case WM_SIZE: | 178 case WM_SIZE: |
161 { | 179 { |
162 // Resize the browser object to fit the window | 180 // Resize the browser object to fit the window |
163 RECT bounds; | |
164 IWebView2WebView* webview; | 181 IWebView2WebView* webview; |
165 | 182 |
166 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when | 183 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
167 // we initially attached the browser object to this window. | 184 // we initially attached the browser object to this window. |
168 webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME); | 185 webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME); |
169 GetClientRect(hWnd, &bounds); | |
170 // Resize WebView to fit the bounds of the parent window | 186 // Resize WebView to fit the bounds of the parent window |
171 if (webview) | 187 if (webview) |
188 { | |
189 RECT bounds; | |
190 | |
191 GetClientRect(hWnd, &bounds); | |
172 webview->put_Bounds(bounds); | 192 webview->put_Bounds(bounds); |
193 } | |
173 return(0); | 194 return(0); |
174 } | 195 } |
175 | 196 |
176 case WM_CREATE: | 197 case WM_CREATE: |
177 { | 198 { |
198 | 219 |
199 // Resize WebView to fit the bounds of the parent window | 220 // Resize WebView to fit the bounds of the parent window |
200 RECT bounds; | 221 RECT bounds; |
201 GetClientRect(hWnd, &bounds); | 222 GetClientRect(hWnd, &bounds); |
202 webview->put_Bounds(bounds); | 223 webview->put_Bounds(bounds); |
224 | |
225 // Handle cached load requests due to delayed | |
226 // loading of the edge webview contexts | |
227 LPCWSTR url = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_LOCATION); | |
228 if(url) | |
229 { | |
230 webview->Navigate(url); | |
231 free((void *)url); | |
232 } | |
233 LPCWSTR raw = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_RAW); | |
234 if (raw) | |
235 { | |
236 webview->NavigateToString(raw); | |
237 free((void *)raw); | |
238 } | |
203 return S_OK; | 239 return S_OK; |
204 }).Get()); | 240 }).Get()); |
205 return S_OK; | 241 return S_OK; |
206 }).Get()); | 242 }).Get()); |
207 | 243 |