Changeset 232234 in webkit
- Timestamp:
- May 27, 2018 8:49:08 PM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r232230 r232234 1 2018-05-27 Fujii Hironori <Hironori.Fujii@sony.com> 2 3 [Win][MiniBrowser] Add MainWindow class 4 https://bugs.webkit.org/show_bug.cgi?id=185814 5 6 Reviewed by Per Arne Vollan. 7 8 This is a sub task of Bug 184770. Added a new class MainWindow to 9 represent the main window which will be shared among WK1 and WK2. 10 11 This change is partial so that it's easy to review this patch. 12 I'll move more functions into MainWindow.cpp, and remove more 13 global variables in forthcoming patches. 14 15 * MiniBrowser/win/CMakeLists.txt: Added MainWindow.cpp. 16 * MiniBrowser/win/Common.cpp: Removed MainWindow related global 17 variables hMainWnd, hURLBarWnd, hBackButtonWnd and 18 hForwardButtonWnd. Added a new global variable gMainWindow. 19 (WndProc): Moved to MainWindow.cpp. 20 (resizeSubViews): Ditto. 21 (ToggleMenuFlag): Removed static to be called from MainWindow.cpp. 22 (ToggleMenuItem): Ditto. 23 (CustomUserAgent): Follow the global variables removal. 24 (DisplayAuthDialog): Ditto. 25 (loadURL): Ditto. 26 (WndProc): Renamed to MainWindow::WndProc. 27 * MiniBrowser/win/MainWindow.cpp: Added. 28 (MainWindow::registerClass): Renamed from MyRegisterClass of WinMain.cpp. 29 (MainWindow::init): Extracted MainWindow initialization code from wWinMain. 30 (MainWindow::resizeSubViews): Moved from Common.cpp. 31 (MainWindow::WndProc): Ditto. 32 * MiniBrowser/win/MainWindow.h: Added. 33 (MainWindow::hwnd): 34 (MainWindow::browserWindow): 35 * MiniBrowser/win/MiniBrowser.cpp: 36 (MiniBrowser::init): 37 (MiniBrowser::prepareViews): Extract some code into MiniBrowser::loadDefaultHTML. 38 (MiniBrowser::loadDefaultHTML): Extracted from MiniBrowser::prepareViews. 39 * MiniBrowser/win/MiniBrowser.h: 40 * MiniBrowser/win/WinMain.cpp: 41 (wWinMain): Extracted MainWindow initialization code into MainWindow::init. 42 (MyRegisterClass): Moved to MainWindow.cpp. 43 1 44 2018-05-27 Fujii Hironori <Hironori.Fujii@sony.com> 2 45 -
trunk/Tools/MiniBrowser/win/CMakeLists.txt
r225191 r232234 9 9 AccessibilityDelegate.cpp 10 10 DOMDefaultImpl.cpp 11 MainWindow.cpp 11 12 PageLoadTestClient.cpp 12 13 PrintWebUIDelegate.cpp -
trunk/Tools/MiniBrowser/win/Common.cpp
r231964 r232234 28 28 29 29 #include "DOMDefaultImpl.h" 30 #include "MainWindow.h" 30 31 #include "MiniBrowser.h" 31 32 #include "MiniBrowserReplace.h" … … 56 57 #include <wininet.h> 57 58 58 #define MAX_LOADSTRING 10059 #define URLBAR_HEIGHT 2460 #define CONTROLBUTTON_WIDTH 2461 62 static const int maxHistorySize = 10;63 64 59 #ifndef WM_DPICHANGED 65 60 #define WM_DPICHANGED 0x02E0 … … 71 66 // Global Variables: 72 67 HINSTANCE hInst; 73 HWND hMainWnd;74 HWND hURLBarWnd;75 HGDIOBJ hURLFont;76 HWND hBackButtonWnd;77 HWND hForwardButtonWnd;78 68 HWND hCacheWnd; 79 69 WNDPROC DefEditProc = nullptr; 80 70 WNDPROC DefButtonProc = nullptr; 81 WNDPROC DefWebKitProc = nullptr; 82 HWND gViewWindow = 0;71 72 MainWindow* gMainWindow = nullptr; 83 73 MiniBrowser* gMiniBrowser = nullptr; 84 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text85 TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name86 74 87 75 // Support moving the transparent window … … 90 78 91 79 // Forward declarations of functions included in this code module: 92 ATOM MyRegisterClass(HINSTANCE hInstance);93 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);94 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);95 INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM);96 LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);97 LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);98 LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);99 LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);100 INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);101 80 INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM); 102 81 … … 106 85 namespace WebCore { 107 86 float deviceScaleFactorForWindow(HWND); 108 }109 110 static void resizeSubViews()111 {112 float scaleFactor = WebCore::deviceScaleFactorForWindow(hMainWnd);113 114 RECT rcClient;115 GetClientRect(hMainWnd, &rcClient);116 117 int height = scaleFactor * URLBAR_HEIGHT;118 int width = scaleFactor * CONTROLBUTTON_WIDTH;119 120 MoveWindow(hBackButtonWnd, 0, 0, width, height, TRUE);121 MoveWindow(hForwardButtonWnd, width, 0, width, height, TRUE);122 MoveWindow(hURLBarWnd, width * 2, 0, rcClient.right, height, TRUE);123 124 ::SendMessage(hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(gMiniBrowser->urlBarFont()), TRUE);125 126 if (gMiniBrowser->usesLayeredWebView() || !gViewWindow)127 return;128 MoveWindow(gViewWindow, 0, height, rcClient.right, rcClient.bottom - height, TRUE);129 87 } 130 88 … … 278 236 } 279 237 280 staticvoid ToggleMenuFlag(HWND hWnd, UINT menuID)238 void ToggleMenuFlag(HWND hWnd, UINT menuID) 281 239 { 282 240 HMENU menu = ::GetMenu(hWnd); … … 320 278 } 321 279 322 staticbool ToggleMenuItem(HWND hWnd, UINT menuID)280 bool ToggleMenuItem(HWND hWnd, UINT menuID) 323 281 { 324 282 if (!gMiniBrowser) … … 400 358 } 401 359 402 static const int dragBarHeight = 30;403 404 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)405 {406 switch (message) {407 case WM_COMMAND: {408 int wmId = LOWORD(wParam);409 int wmEvent = HIWORD(wParam);410 if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {411 if (gMiniBrowser)412 gMiniBrowser->navigateToHistory(hWnd, wmId);413 break;414 }415 // Parse the menu selections:416 switch (wmId) {417 case IDM_ABOUT:418 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);419 break;420 case IDM_EXIT:421 DestroyWindow(hWnd);422 break;423 case IDM_PRINT:424 PrintView(hWnd, message, wParam, lParam);425 break;426 case IDM_WEB_INSPECTOR:427 if (gMiniBrowser)428 gMiniBrowser->launchInspector();429 break;430 case IDM_CACHES:431 if (!::IsWindow(hCacheWnd)) {432 hCacheWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, Caches);433 ::ShowWindow(hCacheWnd, SW_SHOW);434 }435 break;436 case IDM_HISTORY_BACKWARD:437 case IDM_HISTORY_FORWARD:438 if (gMiniBrowser)439 gMiniBrowser->navigateForwardOrBackward(hWnd, wmId);440 break;441 case IDM_UA_OTHER:442 if (wmEvent)443 ToggleMenuItem(hWnd, wmId);444 else445 DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent);446 break;447 case IDM_ACTUAL_SIZE:448 if (gMiniBrowser)449 gMiniBrowser->resetZoom();450 break;451 case IDM_ZOOM_IN:452 if (gMiniBrowser)453 gMiniBrowser->zoomIn();454 break;455 case IDM_ZOOM_OUT:456 if (gMiniBrowser)457 gMiniBrowser->zoomOut();458 break;459 case IDM_SHOW_LAYER_TREE:460 if (gMiniBrowser)461 gMiniBrowser->showLayerTree();462 break;463 default:464 if (!ToggleMenuItem(hWnd, wmId))465 return DefWindowProc(hWnd, message, wParam, lParam);466 }467 }468 break;469 case WM_DESTROY:470 #if USE(CF)471 CFRunLoopStop(CFRunLoopGetMain());472 #endif473 PostQuitMessage(0);474 break;475 case WM_SIZE:476 if (!gMiniBrowser || !gMiniBrowser->hasWebView())477 return DefWindowProc(hWnd, message, wParam, lParam);478 479 resizeSubViews();480 break;481 case WM_DPICHANGED:482 if (gMiniBrowser)483 gMiniBrowser->updateDeviceScaleFactor();484 return DefWindowProc(hWnd, message, wParam, lParam);485 default:486 return DefWindowProc(hWnd, message, wParam, lParam);487 }488 489 return 0;490 }491 492 360 LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 493 361 { … … 602 470 if (bstr.length()) { 603 471 gMiniBrowser->setUserAgent(bstr); 604 ::PostMessage( hMainWnd, static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0);472 ::PostMessage(gMainWindow->hwnd(), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0); 605 473 } 606 474 } … … 617 485 HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password) 618 486 { 619 auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), hMainWnd, AuthDialogProc);487 auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), gMainWindow->hwnd(), AuthDialogProc); 620 488 if (!result) 621 489 return E_FAIL; … … 670 538 return; 671 539 672 SetFocus(g ViewWindow);540 SetFocus(gMiniBrowser->hwnd()); 673 541 } 674 542 -
trunk/Tools/MiniBrowser/win/WinMain.cpp
r232230 r232234 33 33 #include "Common.cpp" 34 34 35 namespace WebCore {36 float deviceScaleFactorForWindow(HWND);37 }38 39 35 int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow) 40 36 { … … 60 56 parseCommandLine(usesLayeredWebView, useFullDesktop, pageLoadTesting, requestedURL); 61 57 62 // Initialize global strings63 LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);64 LoadString(hInst, IDC_MINIBROWSER, szWindowClass, MAX_LOADSTRING);65 MyRegisterClass(hInst);66 67 58 if (useFullDesktop) 68 59 computeFullDesktopFrame(); … … 73 64 ::SetProcessDPIAware(); 74 65 75 float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr); 76 77 hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 78 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInst, 0); 79 80 if (!hMainWnd) 81 return FALSE; 82 83 hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, hMainWnd, 0, hInst, 0); 84 hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, scaleFactor * CONTROLBUTTON_WIDTH, 0, 0, 0, hMainWnd, 0, hInst, 0); 85 hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, scaleFactor * CONTROLBUTTON_WIDTH * 2, 0, 0, 0, hMainWnd, 0, hInst, 0); 86 87 ShowWindow(hMainWnd, nCmdShow); 88 UpdateWindow(hMainWnd); 89 90 DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC)); 91 DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC)); 92 SetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc)); 93 SetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BackButtonProc)); 94 SetWindowLongPtr(hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc)); 95 96 SetFocus(hURLBarWnd); 97 98 gMiniBrowser = new MiniBrowser(hMainWnd, hURLBarWnd, usesLayeredWebView, pageLoadTesting); 99 if (!gMiniBrowser) 100 goto exit; 101 HRESULT hr = gMiniBrowser->init(); 66 gMainWindow = new MainWindow(); 67 HRESULT hr = gMainWindow->init(hInst, usesLayeredWebView, pageLoadTesting); 102 68 if (FAILED(hr)) 103 69 goto exit; 104 70 105 gViewWindow = gMiniBrowser->hwnd(); 106 107 resizeSubViews(); 108 109 ShowWindow(gViewWindow, nCmdShow); 110 UpdateWindow(gViewWindow); 71 gMiniBrowser = gMainWindow->browserWindow(); 72 ShowWindow(gMainWindow->hwnd(), nCmdShow); 111 73 112 74 hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER)); … … 140 102 OleUninitialize(); 141 103 142 delete gMiniBrowser;143 144 104 return static_cast<int>(msg.wParam); 145 105 } 146 147 ATOM MyRegisterClass(HINSTANCE hInstance)148 {149 WNDCLASSEX wcex;150 151 wcex.cbSize = sizeof(WNDCLASSEX);152 153 wcex.style = CS_HREDRAW | CS_VREDRAW;154 wcex.lpfnWndProc = WndProc;155 wcex.cbClsExtra = 0;156 wcex.cbWndExtra = 0;157 wcex.hInstance = hInstance;158 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MINIBROWSER));159 wcex.hCursor = LoadCursor(0, IDC_ARROW);160 wcex.hbrBackground = 0;161 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MINIBROWSER);162 wcex.lpszClassName = szWindowClass;163 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));164 165 return RegisterClassEx(&wcex);166 }
Note: See TracChangeset
for help on using the changeset viewer.