Changeset 232458 in webkit


Ignore:
Timestamp:
Jun 3, 2018 8:26:15 PM (6 years ago)
Author:
Fujii Hironori
Message:

[Win][MiniBrowser] Remove gMiniBrowser global variable
https://bugs.webkit.org/show_bug.cgi?id=186134

Reviewed by Brent Fulgham.

It should not be assumed there is only one main window and one browser
window to support multiple windows properly. gMainWindow and
gMiniBrowser global variables should be removed. This change
removes gMiniBrowser.

  • MiniBrowser/win/Common.cpp: Removed gMiniBrowser global variable.
  • MiniBrowser/win/Common.h: Ditto.
  • MiniBrowser/win/MainWindow.cpp:

(MainWindow::init):
(MainWindow::WndProc):
(EditProc): Post WM_COMMAND if the enter key is pressed in URL bar.
(MainWindow::cachesDialogProc): Renamed from Caches.
(MainWindow::customUserAgentDialogProc): Renamed from CustomUserAgent.
(MainWindow::onURLBarEnter): Extracted from EditProc.
(BackButtonProc): Deleted.
(ForwardButtonProc): Deleted.
(Caches): Renamed to MainWindow::cachesDialogProc.
(CustomUserAgent): Renamed to MainWindow::customUserAgentDialogProc.

  • MiniBrowser/win/MainWindow.h: Convert hCacheWnd global variable to a member variable of MainWindow.
  • MiniBrowser/win/MiniBrowserLibResource.h:
  • MiniBrowser/win/WinMain.cpp:

(wWinMain):

Location:
trunk/Tools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232452 r232458  
     12018-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
    1312018-06-02  Darin Adler  <darin@apple.com>
    232
  • trunk/Tools/MiniBrowser/win/Common.cpp

    r232333 r232458  
    3737HINSTANCE hInst;
    3838MainWindow* gMainWindow = nullptr;
    39 MiniBrowser* gMiniBrowser = nullptr;
    4039
    4140// Support moving the transparent window
  • trunk/Tools/MiniBrowser/win/Common.h

    r232333 r232458  
    3737extern HINSTANCE hInst;
    3838extern MainWindow* gMainWindow;
    39 extern MiniBrowser* gMiniBrowser;
    4039extern POINT s_windowPosition;
    4140extern SIZE s_windowSize;
  • trunk/Tools/MiniBrowser/win/MainWindow.cpp

    r232333 r232458  
    3737static constexpr int controlButtonWidth = 24;
    3838
    39 static HWND hCacheWnd;
    4039static WNDPROC DefEditProc = nullptr;
    41 static WNDPROC DefButtonProc = nullptr;
    4240
    4341static 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);
    4742static 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);
    5043
    5144std::wstring MainWindow::s_windowClass;
     
    9285
    9386    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);
    9588
    9689    if (!m_hMainWnd)
     
    9891
    9992    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);
    10295    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);
    10396
    10497    DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC));
    105     DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hBackButtonWnd, GWLP_WNDPROC));
    10698    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));
    10999
    110100    m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
     
    144134LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    145135{
    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;
    147141    case WM_COMMAND: {
    148142        int wmId = LOWORD(wParam);
    149143        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        }
    150151        if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
    151             if (gMiniBrowser)
    152                 gMiniBrowser->navigateToHistory(hWnd, wmId);
     152            thiz.browserWindow()->navigateToHistory(hWnd, wmId);
    153153            break;
    154154        }
    155155        // Parse the menu selections:
    156156        switch (wmId) {
     157        case IDC_URL_BAR:
     158            thiz.onURLBarEnter();
     159            break;
    157160        case IDM_ABOUT:
    158161            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
     
    162165            break;
    163166        case IDM_PRINT:
    164             gMiniBrowser->print();
     167            thiz.browserWindow()->print();
    165168            break;
    166169        case IDM_WEB_INSPECTOR:
    167             if (gMiniBrowser)
    168                 gMiniBrowser->launchInspector();
     170            thiz.browserWindow()->launchInspector();
    169171            break;
    170172        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);
    174176            }
    175177            break;
    176178        case IDM_HISTORY_BACKWARD:
    177179        case IDM_HISTORY_FORWARD:
    178             if (gMiniBrowser)
    179                 gMiniBrowser->navigateForwardOrBackward(hWnd, wmId);
     180            thiz.browserWindow()->navigateForwardOrBackward(hWnd, wmId);
    180181            break;
    181182        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));
    186184            break;
    187185        case IDM_ACTUAL_SIZE:
    188             if (gMiniBrowser)
    189                 gMiniBrowser->resetZoom();
     186            thiz.browserWindow()->resetZoom();
    190187            break;
    191188        case IDM_ZOOM_IN:
    192             if (gMiniBrowser)
    193                 gMiniBrowser->zoomIn();
     189            thiz.browserWindow()->zoomIn();
    194190            break;
    195191        case IDM_ZOOM_OUT:
    196             if (gMiniBrowser)
    197                 gMiniBrowser->zoomOut();
     192            thiz.browserWindow()->zoomOut();
    198193            break;
    199194        case IDM_SHOW_LAYER_TREE:
    200             if (gMiniBrowser)
    201                 gMiniBrowser->showLayerTree();
     195            thiz.browserWindow()->showLayerTree();
    202196            break;
    203197        default:
    204             if (!gMainWindow->toggleMenuItem(wmId))
     198            if (!thiz.toggleMenuItem(wmId))
    205199                return DefWindowProc(hWnd, message, wParam, lParam);
    206200        }
     
    214208        break;
    215209    case WM_SIZE:
    216         if (!gMiniBrowser || !gMiniBrowser->hasWebView())
    217             return DefWindowProc(hWnd, message, wParam, lParam);
    218 
    219         gMainWindow->resizeSubViews();
     210        thiz.resizeSubViews();
    220211        break;
    221212    case WM_DPICHANGED:
    222         if (gMiniBrowser)
    223             gMiniBrowser->updateDeviceScaleFactor();
     213        thiz.browserWindow()->updateDeviceScaleFactor();
    224214        return DefWindowProc(hWnd, message, wParam, lParam);
    225215    default:
     
    299289        if (wParam == 13) {
    300290            // 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);
    309292            return 0;
    310293        }
    311294    default:
    312295        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);
    333296    }
    334297}
     
    352315}
    353316
    354 INT_PTR CALLBACK Caches(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    355 {
    356     UNREFERENCED_PARAMETER(lParam);
     317INT_PTR CALLBACK MainWindow::cachesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     318{
     319    MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
    357320    switch (message) {
    358321    case WM_INITDIALOG:
     322        SetWindowLongPtr(hDlg, DWLP_USER, lParam);
    359323        ::SetTimer(hDlg, IDT_UPDATE_STATS, 1000, nullptr);
    360324        return (INT_PTR)TRUE;
     
    364328            ::KillTimer(hDlg, IDT_UPDATE_STATS);
    365329            ::DestroyWindow(hDlg);
    366             hCacheWnd = 0;
     330            thiz.m_hCacheWnd = 0;
    367331            return (INT_PTR)TRUE;
    368332        }
     
    374338
    375339    case WM_PAINT:
    376         gMiniBrowser->updateStatistics(hDlg);
     340        thiz.browserWindow()->updateStatistics(hDlg);
    377341        break;
    378342    }
     
    381345}
    382346
    383 INT_PTR CALLBACK CustomUserAgent(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    384 {
    385     UNREFERENCED_PARAMETER(lParam);
     347INT_PTR CALLBACK MainWindow::customUserAgentDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     348{
     349    MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
    386350    switch (message) {
    387351    case WM_INITDIALOG: {
     352        MainWindow& thiz = *reinterpret_cast<MainWindow*>(lParam);
     353        SetWindowLongPtr(hDlg, DWLP_USER, lParam);
    388354        HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT);
    389355        _bstr_t userAgent;
    390         if (gMiniBrowser)
    391             userAgent = gMiniBrowser->userAgent();
     356        userAgent = thiz.browserWindow()->userAgent();
    392357
    393358        ::SetWindowText(edit, static_cast<LPCTSTR>(userAgent));
     
    405370            _bstr_t bstr(buffer);
    406371            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);
    409374            }
    410375        }
     
    476441    SetFocus(m_browserWindow->hwnd());
    477442}
     443
     444void 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  
    4444private:
    4545    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);
    4648    static void registerClass(HINSTANCE hInstance);
    4749    static std::wstring s_windowClass;
    4850
    4951    bool toggleMenuItem(UINT menuID);
     52    void onURLBarEnter();
    5053
    5154    HWND m_hMainWnd { nullptr };
     
    5356    HWND m_hBackButtonWnd { nullptr };
    5457    HWND m_hForwardButtonWnd { nullptr };
     58    HWND m_hCacheWnd { nullptr };
    5559    std::unique_ptr<MiniBrowser> m_browserWindow;
    5660};
  • trunk/Tools/MiniBrowser/win/MiniBrowserLibResource.h

    r219830 r232458  
    110110#define IDC_AUTH_USER                   1053
    111111#define IDC_AUTH_PASSWORD               1054
     112#define IDC_URL_BAR                     1055
    112113#define IDC_STATIC                      -1
    113114
     
    119120#define _APS_NEXT_RESOURCE_VALUE        175
    120121#define _APS_NEXT_COMMAND_VALUE         32776
    121 #define _APS_NEXT_CONTROL_VALUE         1054
     122#define _APS_NEXT_CONTROL_VALUE         1055
    122123#define _APS_NEXT_SYMED_VALUE           110
    123124#endif
  • trunk/Tools/MiniBrowser/win/WinMain.cpp

    r232333 r232458  
    7171        goto exit;
    7272
    73     gMiniBrowser = gMainWindow->browserWindow();
    7473    ShowWindow(gMainWindow->hwnd(), nCmdShow);
    7574
     
    7978        gMainWindow->loadURL(requestedURL.GetBSTR());
    8079    else
    81         gMiniBrowser->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
     80        gMainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
    8281
    8382#pragma warning(disable:4509)
Note: See TracChangeset for help on using the changeset viewer.