Changeset 232458 in webkit
- Timestamp:
- Jun 3, 2018 8:26:15 PM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r232452 r232458 1 2018-06-03 Fujii Hironori <Hironori.Fujii@sony.com> 2 3 [Win][MiniBrowser] Remove gMiniBrowser global variable 4 https://bugs.webkit.org/show_bug.cgi?id=186134 5 6 Reviewed by Brent Fulgham. 7 8 It should not be assumed there is only one main window and one browser 9 window to support multiple windows properly. gMainWindow and 10 gMiniBrowser global variables should be removed. This change 11 removes gMiniBrowser. 12 13 * MiniBrowser/win/Common.cpp: Removed gMiniBrowser global variable. 14 * MiniBrowser/win/Common.h: Ditto. 15 * MiniBrowser/win/MainWindow.cpp: 16 (MainWindow::init): 17 (MainWindow::WndProc): 18 (EditProc): Post WM_COMMAND if the enter key is pressed in URL bar. 19 (MainWindow::cachesDialogProc): Renamed from Caches. 20 (MainWindow::customUserAgentDialogProc): Renamed from CustomUserAgent. 21 (MainWindow::onURLBarEnter): Extracted from EditProc. 22 (BackButtonProc): Deleted. 23 (ForwardButtonProc): Deleted. 24 (Caches): Renamed to MainWindow::cachesDialogProc. 25 (CustomUserAgent): Renamed to MainWindow::customUserAgentDialogProc. 26 * MiniBrowser/win/MainWindow.h: Convert hCacheWnd global variable to a member variable of MainWindow. 27 * MiniBrowser/win/MiniBrowserLibResource.h: 28 * MiniBrowser/win/WinMain.cpp: 29 (wWinMain): 30 1 31 2018-06-02 Darin Adler <darin@apple.com> 2 32 -
trunk/Tools/MiniBrowser/win/Common.cpp
r232333 r232458 37 37 HINSTANCE hInst; 38 38 MainWindow* gMainWindow = nullptr; 39 MiniBrowser* gMiniBrowser = nullptr;40 39 41 40 // Support moving the transparent window -
trunk/Tools/MiniBrowser/win/Common.h
r232333 r232458 37 37 extern HINSTANCE hInst; 38 38 extern MainWindow* gMainWindow; 39 extern MiniBrowser* gMiniBrowser;40 39 extern POINT s_windowPosition; 41 40 extern SIZE s_windowSize; -
trunk/Tools/MiniBrowser/win/MainWindow.cpp
r232333 r232458 37 37 static constexpr int controlButtonWidth = 24; 38 38 39 static HWND hCacheWnd;40 39 static WNDPROC DefEditProc = nullptr; 41 static WNDPROC DefButtonProc = nullptr;42 40 43 41 static LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM); 44 static LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);45 static LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);46 static LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);47 42 static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 48 static INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM);49 static INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);50 43 51 44 std::wstring MainWindow::s_windowClass; … … 92 85 93 86 m_hMainWnd = CreateWindow(s_windowClass.c_str(), title.c_str(), WS_OVERLAPPEDWINDOW, 94 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);87 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, this); 95 88 96 89 if (!m_hMainWnd) … … 98 91 99 92 float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr); 100 m_hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);101 m_hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, scaleFactor * controlButtonWidth, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);93 m_hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_HISTORY_BACKWARD), hInstance, 0); 94 m_hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, scaleFactor * controlButtonWidth, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_HISTORY_FORWARD), hInstance, 0); 102 95 m_hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, scaleFactor * controlButtonWidth * 2, 0, 0, 0, m_hMainWnd, 0, hInstance, 0); 103 96 104 97 DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC)); 105 DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hBackButtonWnd, GWLP_WNDPROC));106 98 SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc)); 107 SetWindowLongPtr(m_hBackButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BackButtonProc));108 SetWindowLongPtr(m_hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc));109 99 110 100 m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting); … … 144 134 LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 145 135 { 146 switch (message) { 136 MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA)); 137 switch (message) { 138 case WM_CREATE: 139 SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams)); 140 break; 147 141 case WM_COMMAND: { 148 142 int wmId = LOWORD(wParam); 149 143 int wmEvent = HIWORD(wParam); 144 switch (wmEvent) { 145 case 0: // Menu or BN_CLICKED 146 case 1: // Accelerator 147 break; 148 default: 149 return DefWindowProc(hWnd, message, wParam, lParam); 150 } 150 151 if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) { 151 if (gMiniBrowser) 152 gMiniBrowser->navigateToHistory(hWnd, wmId); 152 thiz.browserWindow()->navigateToHistory(hWnd, wmId); 153 153 break; 154 154 } 155 155 // Parse the menu selections: 156 156 switch (wmId) { 157 case IDC_URL_BAR: 158 thiz.onURLBarEnter(); 159 break; 157 160 case IDM_ABOUT: 158 161 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); … … 162 165 break; 163 166 case IDM_PRINT: 164 gMiniBrowser->print();167 thiz.browserWindow()->print(); 165 168 break; 166 169 case IDM_WEB_INSPECTOR: 167 if (gMiniBrowser) 168 gMiniBrowser->launchInspector(); 170 thiz.browserWindow()->launchInspector(); 169 171 break; 170 172 case IDM_CACHES: 171 if (!::IsWindow( hCacheWnd)) {172 hCacheWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, Caches);173 ::ShowWindow( hCacheWnd, SW_SHOW);173 if (!::IsWindow(thiz.m_hCacheWnd)) { 174 thiz.m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(&thiz)); 175 ::ShowWindow(thiz.m_hCacheWnd, SW_SHOW); 174 176 } 175 177 break; 176 178 case IDM_HISTORY_BACKWARD: 177 179 case IDM_HISTORY_FORWARD: 178 if (gMiniBrowser) 179 gMiniBrowser->navigateForwardOrBackward(hWnd, wmId); 180 thiz.browserWindow()->navigateForwardOrBackward(hWnd, wmId); 180 181 break; 181 182 case IDM_UA_OTHER: 182 if (wmEvent) 183 gMainWindow->toggleMenuItem(wmId); 184 else 185 DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent); 183 DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(&thiz)); 186 184 break; 187 185 case IDM_ACTUAL_SIZE: 188 if (gMiniBrowser) 189 gMiniBrowser->resetZoom(); 186 thiz.browserWindow()->resetZoom(); 190 187 break; 191 188 case IDM_ZOOM_IN: 192 if (gMiniBrowser) 193 gMiniBrowser->zoomIn(); 189 thiz.browserWindow()->zoomIn(); 194 190 break; 195 191 case IDM_ZOOM_OUT: 196 if (gMiniBrowser) 197 gMiniBrowser->zoomOut(); 192 thiz.browserWindow()->zoomOut(); 198 193 break; 199 194 case IDM_SHOW_LAYER_TREE: 200 if (gMiniBrowser) 201 gMiniBrowser->showLayerTree(); 195 thiz.browserWindow()->showLayerTree(); 202 196 break; 203 197 default: 204 if (! gMainWindow->toggleMenuItem(wmId))198 if (!thiz.toggleMenuItem(wmId)) 205 199 return DefWindowProc(hWnd, message, wParam, lParam); 206 200 } … … 214 208 break; 215 209 case WM_SIZE: 216 if (!gMiniBrowser || !gMiniBrowser->hasWebView()) 217 return DefWindowProc(hWnd, message, wParam, lParam); 218 219 gMainWindow->resizeSubViews(); 210 thiz.resizeSubViews(); 220 211 break; 221 212 case WM_DPICHANGED: 222 if (gMiniBrowser) 223 gMiniBrowser->updateDeviceScaleFactor(); 213 thiz.browserWindow()->updateDeviceScaleFactor(); 224 214 return DefWindowProc(hWnd, message, wParam, lParam); 225 215 default: … … 299 289 if (wParam == 13) { 300 290 // Enter Key 301 wchar_t strPtr[INTERNET_MAX_URL_LENGTH]; 302 *((LPWORD)strPtr) = INTERNET_MAX_URL_LENGTH; 303 int strLen = SendMessage(hDlg, EM_GETLINE, 0, (LPARAM)strPtr); 304 305 strPtr[strLen] = 0; 306 _bstr_t bstr(strPtr); 307 gMainWindow->loadURL(bstr.GetBSTR()); 308 291 ::PostMessage(GetParent(hDlg), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDC_URL_BAR, 0), 0); 309 292 return 0; 310 293 } 311 294 default: 312 295 return CallWindowProc(DefEditProc, hDlg, message, wParam, lParam); 313 }314 }315 316 LRESULT CALLBACK BackButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)317 {318 switch (message) {319 case WM_LBUTTONUP:320 gMiniBrowser->goBack();321 default:322 return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam);323 }324 }325 326 LRESULT CALLBACK ForwardButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)327 {328 switch (message) {329 case WM_LBUTTONUP:330 gMiniBrowser->goForward();331 default:332 return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam);333 296 } 334 297 } … … 352 315 } 353 316 354 INT_PTR CALLBACK Caches(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)355 { 356 UNREFERENCED_PARAMETER(lParam);317 INT_PTR CALLBACK MainWindow::cachesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 318 { 319 MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER)); 357 320 switch (message) { 358 321 case WM_INITDIALOG: 322 SetWindowLongPtr(hDlg, DWLP_USER, lParam); 359 323 ::SetTimer(hDlg, IDT_UPDATE_STATS, 1000, nullptr); 360 324 return (INT_PTR)TRUE; … … 364 328 ::KillTimer(hDlg, IDT_UPDATE_STATS); 365 329 ::DestroyWindow(hDlg); 366 hCacheWnd = 0;330 thiz.m_hCacheWnd = 0; 367 331 return (INT_PTR)TRUE; 368 332 } … … 374 338 375 339 case WM_PAINT: 376 gMiniBrowser->updateStatistics(hDlg);340 thiz.browserWindow()->updateStatistics(hDlg); 377 341 break; 378 342 } … … 381 345 } 382 346 383 INT_PTR CALLBACK CustomUserAgent(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)384 { 385 UNREFERENCED_PARAMETER(lParam);347 INT_PTR CALLBACK MainWindow::customUserAgentDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 348 { 349 MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER)); 386 350 switch (message) { 387 351 case WM_INITDIALOG: { 352 MainWindow& thiz = *reinterpret_cast<MainWindow*>(lParam); 353 SetWindowLongPtr(hDlg, DWLP_USER, lParam); 388 354 HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT); 389 355 _bstr_t userAgent; 390 if (gMiniBrowser) 391 userAgent = gMiniBrowser->userAgent(); 356 userAgent = thiz.browserWindow()->userAgent(); 392 357 393 358 ::SetWindowText(edit, static_cast<LPCTSTR>(userAgent)); … … 405 370 _bstr_t bstr(buffer); 406 371 if (bstr.length()) { 407 gMiniBrowser->setUserAgent(bstr);408 ::PostMessage(gMainWindow->hwnd(), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0);372 thiz.browserWindow()->setUserAgent(bstr); 373 thiz.toggleMenuItem(IDM_UA_OTHER); 409 374 } 410 375 } … … 476 441 SetFocus(m_browserWindow->hwnd()); 477 442 } 443 444 void MainWindow::onURLBarEnter() 445 { 446 wchar_t strPtr[INTERNET_MAX_URL_LENGTH]; 447 GetWindowText(m_hURLBarWnd, strPtr, INTERNET_MAX_URL_LENGTH); 448 strPtr[INTERNET_MAX_URL_LENGTH - 1] = 0; 449 _bstr_t bstr(strPtr); 450 loadURL(bstr.GetBSTR()); 451 } -
trunk/Tools/MiniBrowser/win/MainWindow.h
r232333 r232458 44 44 private: 45 45 static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 46 static INT_PTR CALLBACK customUserAgentDialogProc(HWND, UINT, WPARAM, LPARAM); 47 static INT_PTR CALLBACK cachesDialogProc(HWND, UINT, WPARAM, LPARAM); 46 48 static void registerClass(HINSTANCE hInstance); 47 49 static std::wstring s_windowClass; 48 50 49 51 bool toggleMenuItem(UINT menuID); 52 void onURLBarEnter(); 50 53 51 54 HWND m_hMainWnd { nullptr }; … … 53 56 HWND m_hBackButtonWnd { nullptr }; 54 57 HWND m_hForwardButtonWnd { nullptr }; 58 HWND m_hCacheWnd { nullptr }; 55 59 std::unique_ptr<MiniBrowser> m_browserWindow; 56 60 }; -
trunk/Tools/MiniBrowser/win/MiniBrowserLibResource.h
r219830 r232458 110 110 #define IDC_AUTH_USER 1053 111 111 #define IDC_AUTH_PASSWORD 1054 112 #define IDC_URL_BAR 1055 112 113 #define IDC_STATIC -1 113 114 … … 119 120 #define _APS_NEXT_RESOURCE_VALUE 175 120 121 #define _APS_NEXT_COMMAND_VALUE 32776 121 #define _APS_NEXT_CONTROL_VALUE 105 4122 #define _APS_NEXT_CONTROL_VALUE 1055 122 123 #define _APS_NEXT_SYMED_VALUE 110 123 124 #endif -
trunk/Tools/MiniBrowser/win/WinMain.cpp
r232333 r232458 71 71 goto exit; 72 72 73 gMiniBrowser = gMainWindow->browserWindow();74 73 ShowWindow(gMainWindow->hwnd(), nCmdShow); 75 74 … … 79 78 gMainWindow->loadURL(requestedURL.GetBSTR()); 80 79 else 81 gM iniBrowser->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());80 gMainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR()); 82 81 83 82 #pragma warning(disable:4509)
Note: See TracChangeset
for help on using the changeset viewer.