Title: [232458] trunk/Tools
Revision
232458
Author
[email protected]
Date
2018-06-03 20:26:15 -0700 (Sun, 03 Jun 2018)

Log 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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (232457 => 232458)


--- trunk/Tools/ChangeLog	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/ChangeLog	2018-06-04 03:26:15 UTC (rev 232458)
@@ -1,3 +1,33 @@
+2018-06-03  Fujii Hironori  <[email protected]>
+
+        [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):
+
 2018-06-02  Darin Adler  <[email protected]>
 
         [Cocoa] Update some code to be more ARC-compatible to prepare for future ARC adoption

Modified: trunk/Tools/MiniBrowser/win/Common.cpp (232457 => 232458)


--- trunk/Tools/MiniBrowser/win/Common.cpp	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/MiniBrowser/win/Common.cpp	2018-06-04 03:26:15 UTC (rev 232458)
@@ -36,7 +36,6 @@
 // Global Variables:
 HINSTANCE hInst;
 MainWindow* gMainWindow = nullptr;
-MiniBrowser* gMiniBrowser = nullptr;
 
 // Support moving the transparent window
 POINT s_windowPosition = { 100, 100 };

Modified: trunk/Tools/MiniBrowser/win/Common.h (232457 => 232458)


--- trunk/Tools/MiniBrowser/win/Common.h	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/MiniBrowser/win/Common.h	2018-06-04 03:26:15 UTC (rev 232458)
@@ -36,6 +36,5 @@
 
 extern HINSTANCE hInst;
 extern MainWindow* gMainWindow;
-extern MiniBrowser* gMiniBrowser;
 extern POINT s_windowPosition;
 extern SIZE s_windowSize;

Modified: trunk/Tools/MiniBrowser/win/MainWindow.cpp (232457 => 232458)


--- trunk/Tools/MiniBrowser/win/MainWindow.cpp	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/MiniBrowser/win/MainWindow.cpp	2018-06-04 03:26:15 UTC (rev 232458)
@@ -36,17 +36,10 @@
 
 static constexpr int controlButtonWidth = 24;
 
-static HWND hCacheWnd;
 static WNDPROC DefEditProc = nullptr;
-static WNDPROC DefButtonProc = nullptr;
 
 static LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);
-static LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);
-static LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);
-static LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);
 static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
-static INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM);
-static INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);
 
 std::wstring MainWindow::s_windowClass;
 
@@ -91,21 +84,18 @@
     auto title = loadString(IDS_APP_TITLE);
 
     m_hMainWnd = CreateWindow(s_windowClass.c_str(), title.c_str(), WS_OVERLAPPEDWINDOW,
-        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
+        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, this);
 
     if (!m_hMainWnd)
         return false;
 
     float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
-    m_hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE  | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);
-    m_hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, scaleFactor * controlButtonWidth, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);
+    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);
+    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);
     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);
 
     DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC));
-    DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hBackButtonWnd, GWLP_WNDPROC));
     SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
-    SetWindowLongPtr(m_hBackButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BackButtonProc));
-    SetWindowLongPtr(m_hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc));
 
     m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
     if (!m_browserWindow)
@@ -143,17 +133,30 @@
 
 LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
+    MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
     switch (message) {
+    case WM_CREATE:
+        SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams));
+        break;
     case WM_COMMAND: {
         int wmId = LOWORD(wParam);
         int wmEvent = HIWORD(wParam);
+        switch (wmEvent) {
+        case 0: // Menu or BN_CLICKED
+        case 1: // Accelerator
+            break;
+        default:
+            return DefWindowProc(hWnd, message, wParam, lParam);
+        }
         if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
-            if (gMiniBrowser)
-                gMiniBrowser->navigateToHistory(hWnd, wmId);
+            thiz.browserWindow()->navigateToHistory(hWnd, wmId);
             break;
         }
         // Parse the menu selections:
         switch (wmId) {
+        case IDC_URL_BAR:
+            thiz.onURLBarEnter();
+            break;
         case IDM_ABOUT:
             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
             break;
@@ -161,47 +164,38 @@
             DestroyWindow(hWnd);
             break;
         case IDM_PRINT:
-            gMiniBrowser->print();
+            thiz.browserWindow()->print();
             break;
         case IDM_WEB_INSPECTOR:
-            if (gMiniBrowser)
-                gMiniBrowser->launchInspector();
+            thiz.browserWindow()->launchInspector();
             break;
         case IDM_CACHES:
-            if (!::IsWindow(hCacheWnd)) {
-                hCacheWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, Caches);
-                ::ShowWindow(hCacheWnd, SW_SHOW);
+            if (!::IsWindow(thiz.m_hCacheWnd)) {
+                thiz.m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(&thiz));
+                ::ShowWindow(thiz.m_hCacheWnd, SW_SHOW);
             }
             break;
         case IDM_HISTORY_BACKWARD:
         case IDM_HISTORY_FORWARD:
-            if (gMiniBrowser)
-                gMiniBrowser->navigateForwardOrBackward(hWnd, wmId);
+            thiz.browserWindow()->navigateForwardOrBackward(hWnd, wmId);
             break;
         case IDM_UA_OTHER:
-            if (wmEvent)
-                gMainWindow->toggleMenuItem(wmId);
-            else
-                DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent);
+            DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(&thiz));
             break;
         case IDM_ACTUAL_SIZE:
-            if (gMiniBrowser)
-                gMiniBrowser->resetZoom();
+            thiz.browserWindow()->resetZoom();
             break;
         case IDM_ZOOM_IN:
-            if (gMiniBrowser)
-                gMiniBrowser->zoomIn();
+            thiz.browserWindow()->zoomIn();
             break;
         case IDM_ZOOM_OUT:
-            if (gMiniBrowser)
-                gMiniBrowser->zoomOut();
+            thiz.browserWindow()->zoomOut();
             break;
         case IDM_SHOW_LAYER_TREE:
-            if (gMiniBrowser)
-                gMiniBrowser->showLayerTree();
+            thiz.browserWindow()->showLayerTree();
             break;
         default:
-            if (!gMainWindow->toggleMenuItem(wmId))
+            if (!thiz.toggleMenuItem(wmId))
                 return DefWindowProc(hWnd, message, wParam, lParam);
         }
         }
@@ -213,14 +207,10 @@
         PostQuitMessage(0);
         break;
     case WM_SIZE:
-        if (!gMiniBrowser || !gMiniBrowser->hasWebView())
-            return DefWindowProc(hWnd, message, wParam, lParam);
-
-        gMainWindow->resizeSubViews();
+        thiz.resizeSubViews();
         break;
     case WM_DPICHANGED:
-        if (gMiniBrowser)
-            gMiniBrowser->updateDeviceScaleFactor();
+        thiz.browserWindow()->updateDeviceScaleFactor();
         return DefWindowProc(hWnd, message, wParam, lParam);
     default:
         return DefWindowProc(hWnd, message, wParam, lParam);
@@ -298,14 +288,7 @@
     case WM_CHAR:
         if (wParam == 13) {
             // Enter Key
-            wchar_t strPtr[INTERNET_MAX_URL_LENGTH];
-            *((LPWORD)strPtr) = INTERNET_MAX_URL_LENGTH;
-            int strLen = SendMessage(hDlg, EM_GETLINE, 0, (LPARAM)strPtr);
-
-            strPtr[strLen] = 0;
-            _bstr_t bstr(strPtr);
-            gMainWindow->loadURL(bstr.GetBSTR());
-
+            ::PostMessage(GetParent(hDlg), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDC_URL_BAR, 0), 0);
             return 0;
         }
     default:
@@ -313,26 +296,6 @@
     }
 }
 
-LRESULT CALLBACK BackButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
-    switch (message) {
-    case WM_LBUTTONUP:
-        gMiniBrowser->goBack();
-    default:
-        return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam);
-    }
-}
-
-LRESULT CALLBACK ForwardButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
-    switch (message) {
-    case WM_LBUTTONUP:
-        gMiniBrowser->goForward();
-    default:
-        return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam);
-    }
-}
-
 // Message handler for about box.
 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 {
@@ -351,11 +314,12 @@
     return (INT_PTR)FALSE;
 }
 
-INT_PTR CALLBACK Caches(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK MainWindow::cachesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 {
-    UNREFERENCED_PARAMETER(lParam);
+    MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
     switch (message) {
     case WM_INITDIALOG:
+        SetWindowLongPtr(hDlg, DWLP_USER, lParam);
         ::SetTimer(hDlg, IDT_UPDATE_STATS, 1000, nullptr);
         return (INT_PTR)TRUE;
 
@@ -363,7 +327,7 @@
         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
             ::KillTimer(hDlg, IDT_UPDATE_STATS);
             ::DestroyWindow(hDlg);
-            hCacheWnd = 0;
+            thiz.m_hCacheWnd = 0;
             return (INT_PTR)TRUE;
         }
         break;
@@ -373,7 +337,7 @@
         return (INT_PTR)TRUE;
 
     case WM_PAINT:
-        gMiniBrowser->updateStatistics(hDlg);
+        thiz.browserWindow()->updateStatistics(hDlg);
         break;
     }
 
@@ -380,15 +344,16 @@
     return (INT_PTR)FALSE;
 }
 
-INT_PTR CALLBACK CustomUserAgent(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK MainWindow::customUserAgentDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 {
-    UNREFERENCED_PARAMETER(lParam);
+    MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
     switch (message) {
     case WM_INITDIALOG: {
+        MainWindow& thiz = *reinterpret_cast<MainWindow*>(lParam);
+        SetWindowLongPtr(hDlg, DWLP_USER, lParam);
         HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT);
         _bstr_t userAgent;
-        if (gMiniBrowser)
-            userAgent = gMiniBrowser->userAgent();
+        userAgent = thiz.browserWindow()->userAgent();
 
         ::SetWindowText(edit, static_cast<LPCTSTR>(userAgent));
         return (INT_PTR)TRUE;
@@ -404,8 +369,8 @@
 
             _bstr_t bstr(buffer);
             if (bstr.length()) {
-                gMiniBrowser->setUserAgent(bstr);
-                ::PostMessage(gMainWindow->hwnd(), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0);
+                thiz.browserWindow()->setUserAgent(bstr);
+                thiz.toggleMenuItem(IDM_UA_OTHER);
             }
         }
 
@@ -475,3 +440,12 @@
 
     SetFocus(m_browserWindow->hwnd());
 }
+
+void MainWindow::onURLBarEnter()
+{
+    wchar_t strPtr[INTERNET_MAX_URL_LENGTH];
+    GetWindowText(m_hURLBarWnd, strPtr, INTERNET_MAX_URL_LENGTH);
+    strPtr[INTERNET_MAX_URL_LENGTH - 1] = 0;
+    _bstr_t bstr(strPtr);
+    loadURL(bstr.GetBSTR());
+}

Modified: trunk/Tools/MiniBrowser/win/MainWindow.h (232457 => 232458)


--- trunk/Tools/MiniBrowser/win/MainWindow.h	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/MiniBrowser/win/MainWindow.h	2018-06-04 03:26:15 UTC (rev 232458)
@@ -43,14 +43,18 @@
     
 private:
     static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+    static INT_PTR CALLBACK customUserAgentDialogProc(HWND, UINT, WPARAM, LPARAM);
+    static INT_PTR CALLBACK cachesDialogProc(HWND, UINT, WPARAM, LPARAM);
     static void registerClass(HINSTANCE hInstance);
     static std::wstring s_windowClass;
 
     bool toggleMenuItem(UINT menuID);
+    void onURLBarEnter();
 
     HWND m_hMainWnd { nullptr };
     HWND m_hURLBarWnd { nullptr };
     HWND m_hBackButtonWnd { nullptr };
     HWND m_hForwardButtonWnd { nullptr };
+    HWND m_hCacheWnd { nullptr };
     std::unique_ptr<MiniBrowser> m_browserWindow;
 };

Modified: trunk/Tools/MiniBrowser/win/MiniBrowserLibResource.h (232457 => 232458)


--- trunk/Tools/MiniBrowser/win/MiniBrowserLibResource.h	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/MiniBrowser/win/MiniBrowserLibResource.h	2018-06-04 03:26:15 UTC (rev 232458)
@@ -109,6 +109,7 @@
 #define IDC_USER_AGENT_INPUT            1052
 #define IDC_AUTH_USER                   1053
 #define IDC_AUTH_PASSWORD               1054
+#define IDC_URL_BAR                     1055
 #define IDC_STATIC                      -1
 
 // Next default values for new objects
@@ -118,7 +119,7 @@
 #define _APS_NO_MFC                     1
 #define _APS_NEXT_RESOURCE_VALUE        175
 #define _APS_NEXT_COMMAND_VALUE         32776
-#define _APS_NEXT_CONTROL_VALUE         1054
+#define _APS_NEXT_CONTROL_VALUE         1055
 #define _APS_NEXT_SYMED_VALUE           110
 #endif
 #endif

Modified: trunk/Tools/MiniBrowser/win/WinMain.cpp (232457 => 232458)


--- trunk/Tools/MiniBrowser/win/WinMain.cpp	2018-06-04 02:44:18 UTC (rev 232457)
+++ trunk/Tools/MiniBrowser/win/WinMain.cpp	2018-06-04 03:26:15 UTC (rev 232458)
@@ -70,7 +70,6 @@
     if (FAILED(hr))
         goto exit;
 
-    gMiniBrowser = gMainWindow->browserWindow();
     ShowWindow(gMainWindow->hwnd(), nCmdShow);
 
     hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER));
@@ -78,7 +77,7 @@
     if (requestedURL.length())
         gMainWindow->loadURL(requestedURL.GetBSTR());
     else
-        gMiniBrowser->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
+        gMainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
 
 #pragma warning(disable:4509)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to