Changeset 232234 in webkit


Ignore:
Timestamp:
May 27, 2018 8:49:08 PM (6 years ago)
Author:
Fujii Hironori
Message:

[Win][MiniBrowser] Add MainWindow class
https://bugs.webkit.org/show_bug.cgi?id=185814

Reviewed by Per Arne Vollan.

This is a sub task of Bug 184770. Added a new class MainWindow to
represent the main window which will be shared among WK1 and WK2.

This change is partial so that it's easy to review this patch.
I'll move more functions into MainWindow.cpp, and remove more
global variables in forthcoming patches.

  • MiniBrowser/win/CMakeLists.txt: Added MainWindow.cpp.
  • MiniBrowser/win/Common.cpp: Removed MainWindow related global

variables hMainWnd, hURLBarWnd, hBackButtonWnd and
hForwardButtonWnd. Added a new global variable gMainWindow.
(WndProc): Moved to MainWindow.cpp.
(resizeSubViews): Ditto.
(ToggleMenuFlag): Removed static to be called from MainWindow.cpp.
(ToggleMenuItem): Ditto.
(CustomUserAgent): Follow the global variables removal.
(DisplayAuthDialog): Ditto.
(loadURL): Ditto.
(WndProc): Renamed to MainWindow::WndProc.

  • MiniBrowser/win/MainWindow.cpp: Added.

(MainWindow::registerClass): Renamed from MyRegisterClass of WinMain.cpp.
(MainWindow::init): Extracted MainWindow initialization code from wWinMain.
(MainWindow::resizeSubViews): Moved from Common.cpp.
(MainWindow::WndProc): Ditto.

  • MiniBrowser/win/MainWindow.h: Added.

(MainWindow::hwnd):
(MainWindow::browserWindow):

  • MiniBrowser/win/MiniBrowser.cpp:

(MiniBrowser::init):
(MiniBrowser::prepareViews): Extract some code into MiniBrowser::loadDefaultHTML.
(MiniBrowser::loadDefaultHTML): Extracted from MiniBrowser::prepareViews.

  • MiniBrowser/win/MiniBrowser.h:
  • MiniBrowser/win/WinMain.cpp:

(wWinMain): Extracted MainWindow initialization code into MainWindow::init.
(MyRegisterClass): Moved to MainWindow.cpp.

Location:
trunk/Tools
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232230 r232234  
     12018-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
    1442018-05-27  Fujii Hironori  <Hironori.Fujii@sony.com>
    245
  • trunk/Tools/MiniBrowser/win/CMakeLists.txt

    r225191 r232234  
    99    AccessibilityDelegate.cpp
    1010    DOMDefaultImpl.cpp
     11    MainWindow.cpp
    1112    PageLoadTestClient.cpp
    1213    PrintWebUIDelegate.cpp
  • trunk/Tools/MiniBrowser/win/Common.cpp

    r231964 r232234  
    2828
    2929#include "DOMDefaultImpl.h"
     30#include "MainWindow.h"
    3031#include "MiniBrowser.h"
    3132#include "MiniBrowserReplace.h"
     
    5657#include <wininet.h>
    5758
    58 #define MAX_LOADSTRING 100
    59 #define URLBAR_HEIGHT  24
    60 #define CONTROLBUTTON_WIDTH 24
    61 
    62 static const int maxHistorySize = 10;
    63 
    6459#ifndef WM_DPICHANGED
    6560#define WM_DPICHANGED 0x02E0
     
    7166// Global Variables:
    7267HINSTANCE hInst;
    73 HWND hMainWnd;
    74 HWND hURLBarWnd;
    75 HGDIOBJ hURLFont;
    76 HWND hBackButtonWnd;
    77 HWND hForwardButtonWnd;
    7868HWND hCacheWnd;
    7969WNDPROC DefEditProc = nullptr;
    8070WNDPROC DefButtonProc = nullptr;
    81 WNDPROC DefWebKitProc = nullptr;
    82 HWND gViewWindow = 0;
     71
     72MainWindow* gMainWindow = nullptr;
    8373MiniBrowser* gMiniBrowser = nullptr;
    84 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
    85 TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
    8674
    8775// Support moving the transparent window
     
    9078
    9179// 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);
    10180INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM);
    10281
     
    10685namespace WebCore {
    10786float 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);
    12987}
    13088
     
    278236}
    279237
    280 static void ToggleMenuFlag(HWND hWnd, UINT menuID)
     238void ToggleMenuFlag(HWND hWnd, UINT menuID)
    281239{
    282240    HMENU menu = ::GetMenu(hWnd);
     
    320278}
    321279
    322 static bool ToggleMenuItem(HWND hWnd, UINT menuID)
     280bool ToggleMenuItem(HWND hWnd, UINT menuID)
    323281{
    324282    if (!gMiniBrowser)
     
    400358}
    401359
    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             else
    445                 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 #endif
    473         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 
    492360LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    493361{
     
    602470            if (bstr.length()) {
    603471                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);
    605473            }
    606474        }
     
    617485HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password)
    618486{
    619     auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), hMainWnd, AuthDialogProc);
     487    auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), gMainWindow->hwnd(), AuthDialogProc);
    620488    if (!result)
    621489        return E_FAIL;
     
    670538        return;
    671539
    672     SetFocus(gViewWindow);
     540    SetFocus(gMiniBrowser->hwnd());
    673541}
    674542
  • trunk/Tools/MiniBrowser/win/WinMain.cpp

    r232230 r232234  
    3333#include "Common.cpp"
    3434
    35 namespace WebCore {
    36 float deviceScaleFactorForWindow(HWND);
    37 }
    38 
    3935int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow)
    4036{
     
    6056    parseCommandLine(usesLayeredWebView, useFullDesktop, pageLoadTesting, requestedURL);
    6157
    62     // Initialize global strings
    63     LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    64     LoadString(hInst, IDC_MINIBROWSER, szWindowClass, MAX_LOADSTRING);
    65     MyRegisterClass(hInst);
    66 
    6758    if (useFullDesktop)
    6859        computeFullDesktopFrame();
     
    7364    ::SetProcessDPIAware();
    7465
    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);
    10268    if (FAILED(hr))
    10369        goto exit;
    10470
    105     gViewWindow = gMiniBrowser->hwnd();
    106 
    107     resizeSubViews();
    108 
    109     ShowWindow(gViewWindow, nCmdShow);
    110     UpdateWindow(gViewWindow);
     71    gMiniBrowser = gMainWindow->browserWindow();
     72    ShowWindow(gMainWindow->hwnd(), nCmdShow);
    11173
    11274    hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER));
     
    140102    OleUninitialize();
    141103
    142     delete gMiniBrowser;
    143    
    144104    return static_cast<int>(msg.wParam);
    145105}
    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.