Diff
Modified: trunk/Tools/ChangeLog (232233 => 232234)
--- trunk/Tools/ChangeLog 2018-05-28 03:21:52 UTC (rev 232233)
+++ trunk/Tools/ChangeLog 2018-05-28 03:49:08 UTC (rev 232234)
@@ -1,5 +1,48 @@
2018-05-27 Fujii Hironori <[email protected]>
+ [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.
+
+2018-05-27 Fujii Hironori <[email protected]>
+
[Win][MiniBrowser] Remove URL argument of MiniBrowser::init
https://bugs.webkit.org/show_bug.cgi?id=185969
Modified: trunk/Tools/MiniBrowser/win/CMakeLists.txt (232233 => 232234)
--- trunk/Tools/MiniBrowser/win/CMakeLists.txt 2018-05-28 03:21:52 UTC (rev 232233)
+++ trunk/Tools/MiniBrowser/win/CMakeLists.txt 2018-05-28 03:49:08 UTC (rev 232234)
@@ -8,6 +8,7 @@
set(MiniBrowser_SOURCES
AccessibilityDelegate.cpp
DOMDefaultImpl.cpp
+ MainWindow.cpp
PageLoadTestClient.cpp
PrintWebUIDelegate.cpp
ResourceLoadDelegate.cpp
Modified: trunk/Tools/MiniBrowser/win/Common.cpp (232233 => 232234)
--- trunk/Tools/MiniBrowser/win/Common.cpp 2018-05-28 03:21:52 UTC (rev 232233)
+++ trunk/Tools/MiniBrowser/win/Common.cpp 2018-05-28 03:49:08 UTC (rev 232234)
@@ -27,6 +27,7 @@
*/
#include "DOMDefaultImpl.h"
+#include "MainWindow.h"
#include "MiniBrowser.h"
#include "MiniBrowserReplace.h"
#include <WebKitLegacy/WebKitCOMAPI.h>
@@ -55,12 +56,6 @@
#include <vector>
#include <wininet.h>
-#define MAX_LOADSTRING 100
-#define URLBAR_HEIGHT 24
-#define CONTROLBUTTON_WIDTH 24
-
-static const int maxHistorySize = 10;
-
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0
#endif
@@ -70,19 +65,12 @@
// Global Variables:
HINSTANCE hInst;
-HWND hMainWnd;
-HWND hURLBarWnd;
-HGDIOBJ hURLFont;
-HWND hBackButtonWnd;
-HWND hForwardButtonWnd;
HWND hCacheWnd;
WNDPROC DefEditProc = nullptr;
WNDPROC DefButtonProc = nullptr;
-WNDPROC DefWebKitProc = nullptr;
-HWND gViewWindow = 0;
+
+MainWindow* gMainWindow = nullptr;
MiniBrowser* gMiniBrowser = nullptr;
-TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
-TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Support moving the transparent window
POINT s_windowPosition = { 100, 100 };
@@ -89,15 +77,6 @@
SIZE s_windowSize = { 500, 200 };
// Forward declarations of functions included in this code module:
-ATOM MyRegisterClass(HINSTANCE hInstance);
-LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
-INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
-INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);
-INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM);
static void loadURL(BSTR urlBStr);
@@ -107,27 +86,6 @@
float deviceScaleFactorForWindow(HWND);
}
-static void resizeSubViews()
-{
- float scaleFactor = WebCore::deviceScaleFactorForWindow(hMainWnd);
-
- RECT rcClient;
- GetClientRect(hMainWnd, &rcClient);
-
- int height = scaleFactor * URLBAR_HEIGHT;
- int width = scaleFactor * CONTROLBUTTON_WIDTH;
-
- MoveWindow(hBackButtonWnd, 0, 0, width, height, TRUE);
- MoveWindow(hForwardButtonWnd, width, 0, width, height, TRUE);
- MoveWindow(hURLBarWnd, width * 2, 0, rcClient.right, height, TRUE);
-
- ::SendMessage(hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(gMiniBrowser->urlBarFont()), TRUE);
-
- if (gMiniBrowser->usesLayeredWebView() || !gViewWindow)
- return;
- MoveWindow(gViewWindow, 0, height, rcClient.right, rcClient.bottom - height, TRUE);
-}
-
static void computeFullDesktopFrame()
{
RECT desktop;
@@ -277,7 +235,7 @@
::DeleteDC(printDC);
}
-static void ToggleMenuFlag(HWND hWnd, UINT menuID)
+void ToggleMenuFlag(HWND hWnd, UINT menuID)
{
HMENU menu = ::GetMenu(hWnd);
@@ -319,7 +277,7 @@
}
}
-static bool ToggleMenuItem(HWND hWnd, UINT menuID)
+bool ToggleMenuItem(HWND hWnd, UINT menuID)
{
if (!gMiniBrowser)
return false;
@@ -399,96 +357,6 @@
return true;
}
-static const int dragBarHeight = 30;
-
-LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch (message) {
- case WM_COMMAND: {
- int wmId = LOWORD(wParam);
- int wmEvent = HIWORD(wParam);
- if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
- if (gMiniBrowser)
- gMiniBrowser->navigateToHistory(hWnd, wmId);
- break;
- }
- // Parse the menu selections:
- switch (wmId) {
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- case IDM_PRINT:
- PrintView(hWnd, message, wParam, lParam);
- break;
- case IDM_WEB_INSPECTOR:
- if (gMiniBrowser)
- gMiniBrowser->launchInspector();
- break;
- case IDM_CACHES:
- if (!::IsWindow(hCacheWnd)) {
- hCacheWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, Caches);
- ::ShowWindow(hCacheWnd, SW_SHOW);
- }
- break;
- case IDM_HISTORY_BACKWARD:
- case IDM_HISTORY_FORWARD:
- if (gMiniBrowser)
- gMiniBrowser->navigateForwardOrBackward(hWnd, wmId);
- break;
- case IDM_UA_OTHER:
- if (wmEvent)
- ToggleMenuItem(hWnd, wmId);
- else
- DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent);
- break;
- case IDM_ACTUAL_SIZE:
- if (gMiniBrowser)
- gMiniBrowser->resetZoom();
- break;
- case IDM_ZOOM_IN:
- if (gMiniBrowser)
- gMiniBrowser->zoomIn();
- break;
- case IDM_ZOOM_OUT:
- if (gMiniBrowser)
- gMiniBrowser->zoomOut();
- break;
- case IDM_SHOW_LAYER_TREE:
- if (gMiniBrowser)
- gMiniBrowser->showLayerTree();
- break;
- default:
- if (!ToggleMenuItem(hWnd, wmId))
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- }
- break;
- case WM_DESTROY:
-#if USE(CF)
- CFRunLoopStop(CFRunLoopGetMain());
-#endif
- PostQuitMessage(0);
- break;
- case WM_SIZE:
- if (!gMiniBrowser || !gMiniBrowser->hasWebView())
- return DefWindowProc(hWnd, message, wParam, lParam);
-
- resizeSubViews();
- break;
- case WM_DPICHANGED:
- if (gMiniBrowser)
- gMiniBrowser->updateDeviceScaleFactor();
- return DefWindowProc(hWnd, message, wParam, lParam);
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
-
- return 0;
-}
-
LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
@@ -601,7 +469,7 @@
_bstr_t bstr(buffer);
if (bstr.length()) {
gMiniBrowser->setUserAgent(bstr);
- ::PostMessage(hMainWnd, static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0);
+ ::PostMessage(gMainWindow->hwnd(), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0);
}
}
@@ -616,7 +484,7 @@
HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password)
{
- auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), hMainWnd, AuthDialogProc);
+ auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), gMainWindow->hwnd(), AuthDialogProc);
if (!result)
return E_FAIL;
@@ -669,7 +537,7 @@
if (FAILED(gMiniBrowser->loadURL(passedURL)))
return;
- SetFocus(gViewWindow);
+ SetFocus(gMiniBrowser->hwnd());
}
static void setWindowText(HWND dialog, UINT field, _bstr_t value)
Added: trunk/Tools/MiniBrowser/win/MainWindow.cpp (0 => 232234)
--- trunk/Tools/MiniBrowser/win/MainWindow.cpp (rev 0)
+++ trunk/Tools/MiniBrowser/win/MainWindow.cpp 2018-05-28 03:49:08 UTC (rev 232234)
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "stdafx.h"
+#include "MainWindow.h"
+#include "MiniBrowser.h"
+#include "MiniBrowserLibResource.h"
+
+namespace WebCore {
+float deviceScaleFactorForWindow(HWND);
+}
+
+static constexpr int controlButtonWidth = 24;
+
+extern MainWindow* gMainWindow;
+extern MiniBrowser* gMiniBrowser;
+extern WNDPROC DefEditProc;
+extern WNDPROC DefButtonProc;
+extern HINSTANCE hInst;
+extern HWND hCacheWnd;
+
+LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM);
+void PrintView(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+bool ToggleMenuItem(HWND hWnd, UINT menuID);
+
+std::wstring MainWindow::s_windowClass;
+
+static std::wstring loadString(int id)
+{
+ constexpr size_t length = 100;
+ wchar_t buff[length];
+ LoadString(hInst, id, buff, length);
+ return buff;
+}
+
+void MainWindow::registerClass(HINSTANCE hInstance)
+{
+ static bool initialized = false;
+ if (initialized)
+ return;
+ initialized = true;
+
+ s_windowClass = loadString(IDC_MINIBROWSER);
+
+ WNDCLASSEX wcex;
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = WndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = hInstance;
+ wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MINIBROWSER));
+ wcex.hCursor = LoadCursor(0, IDC_ARROW);
+ wcex.hbrBackground = 0;
+ wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MINIBROWSER);
+ wcex.lpszClassName = s_windowClass.c_str();
+ wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
+
+ RegisterClassEx(&wcex);
+}
+
+bool MainWindow::init(HINSTANCE hInstance, bool usesLayeredWebView, bool pageLoadTesting)
+{
+ registerClass(hInstance);
+
+ 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);
+
+ 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_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));
+
+ SetFocus(m_hURLBarWnd);
+
+ m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
+ if (!m_browserWindow)
+ return false;
+ HRESULT hr = m_browserWindow->init();
+ if (FAILED(hr))
+ return false;
+
+ resizeSubViews();
+ return true;
+}
+
+void MainWindow::resizeSubViews()
+{
+ float scaleFactor = WebCore::deviceScaleFactorForWindow(m_hMainWnd);
+
+ RECT rcClient;
+ GetClientRect(m_hMainWnd, &rcClient);
+
+ constexpr int urlBarHeight = 24;
+ int height = scaleFactor * urlBarHeight;
+ int width = scaleFactor * controlButtonWidth;
+
+ MoveWindow(m_hBackButtonWnd, 0, 0, width, height, TRUE);
+ MoveWindow(m_hForwardButtonWnd, width, 0, width, height, TRUE);
+ MoveWindow(m_hURLBarWnd, width * 2, 0, rcClient.right, height, TRUE);
+
+ ::SendMessage(m_hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(m_browserWindow->urlBarFont()), TRUE);
+
+ if (m_browserWindow->usesLayeredWebView() || !m_browserWindow->hwnd())
+ return;
+ MoveWindow(m_browserWindow->hwnd(), 0, height, rcClient.right, rcClient.bottom - height, TRUE);
+}
+
+LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message) {
+ case WM_COMMAND: {
+ int wmId = LOWORD(wParam);
+ int wmEvent = HIWORD(wParam);
+ if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
+ if (gMiniBrowser)
+ gMiniBrowser->navigateToHistory(hWnd, wmId);
+ break;
+ }
+ // Parse the menu selections:
+ switch (wmId) {
+ case IDM_ABOUT:
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
+ break;
+ case IDM_EXIT:
+ DestroyWindow(hWnd);
+ break;
+ case IDM_PRINT:
+ PrintView(hWnd, message, wParam, lParam);
+ break;
+ case IDM_WEB_INSPECTOR:
+ if (gMiniBrowser)
+ gMiniBrowser->launchInspector();
+ break;
+ case IDM_CACHES:
+ if (!::IsWindow(hCacheWnd)) {
+ hCacheWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, Caches);
+ ::ShowWindow(hCacheWnd, SW_SHOW);
+ }
+ break;
+ case IDM_HISTORY_BACKWARD:
+ case IDM_HISTORY_FORWARD:
+ if (gMiniBrowser)
+ gMiniBrowser->navigateForwardOrBackward(hWnd, wmId);
+ break;
+ case IDM_UA_OTHER:
+ if (wmEvent)
+ ToggleMenuItem(hWnd, wmId);
+ else
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent);
+ break;
+ case IDM_ACTUAL_SIZE:
+ if (gMiniBrowser)
+ gMiniBrowser->resetZoom();
+ break;
+ case IDM_ZOOM_IN:
+ if (gMiniBrowser)
+ gMiniBrowser->zoomIn();
+ break;
+ case IDM_ZOOM_OUT:
+ if (gMiniBrowser)
+ gMiniBrowser->zoomOut();
+ break;
+ case IDM_SHOW_LAYER_TREE:
+ if (gMiniBrowser)
+ gMiniBrowser->showLayerTree();
+ break;
+ default:
+ if (!ToggleMenuItem(hWnd, wmId))
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ }
+ break;
+ case WM_DESTROY:
+#if USE(CF)
+ CFRunLoopStop(CFRunLoopGetMain());
+#endif
+ PostQuitMessage(0);
+ break;
+ case WM_SIZE:
+ if (!gMiniBrowser || !gMiniBrowser->hasWebView())
+ return DefWindowProc(hWnd, message, wParam, lParam);
+
+ gMainWindow->resizeSubViews();
+ break;
+ case WM_DPICHANGED:
+ if (gMiniBrowser)
+ gMiniBrowser->updateDeviceScaleFactor();
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+
+ return 0;
+}
Added: trunk/Tools/MiniBrowser/win/MainWindow.h (0 => 232234)
--- trunk/Tools/MiniBrowser/win/MainWindow.h (rev 0)
+++ trunk/Tools/MiniBrowser/win/MainWindow.h 2018-05-28 03:49:08 UTC (rev 232234)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+class MiniBrowser;
+
+class MainWindow {
+public:
+ bool init(HINSTANCE hInstance, bool usesLayeredWebView = false, bool pageLoadTesting = false);
+
+ void resizeSubViews();
+ HWND hwnd() const { return m_hMainWnd; }
+ MiniBrowser* browserWindow() const { return m_browserWindow.get(); }
+
+private:
+ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+ static void registerClass(HINSTANCE hInstance);
+ static std::wstring s_windowClass;
+
+ HWND m_hMainWnd { nullptr };
+ HWND m_hURLBarWnd { nullptr };
+ HWND m_hBackButtonWnd { nullptr };
+ HWND m_hForwardButtonWnd { nullptr };
+ std::unique_ptr<MiniBrowser> m_browserWindow;
+};
Modified: trunk/Tools/MiniBrowser/win/WinMain.cpp (232233 => 232234)
--- trunk/Tools/MiniBrowser/win/WinMain.cpp 2018-05-28 03:21:52 UTC (rev 232233)
+++ trunk/Tools/MiniBrowser/win/WinMain.cpp 2018-05-28 03:49:08 UTC (rev 232234)
@@ -32,10 +32,6 @@
#include "MiniBrowserLibResource.h"
#include "Common.cpp"
-namespace WebCore {
-float deviceScaleFactorForWindow(HWND);
-}
-
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow)
{
#ifdef _CRTDBG_MAP_ALLOC
@@ -59,11 +55,6 @@
parseCommandLine(usesLayeredWebView, useFullDesktop, pageLoadTesting, requestedURL);
- // Initialize global strings
- LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInst, IDC_MINIBROWSER, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInst);
-
if (useFullDesktop)
computeFullDesktopFrame();
@@ -72,43 +63,14 @@
::SetProcessDPIAware();
- float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
-
- hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInst, 0);
-
- if (!hMainWnd)
- return FALSE;
-
- hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, hMainWnd, 0, hInst, 0);
- hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, scaleFactor * CONTROLBUTTON_WIDTH, 0, 0, 0, hMainWnd, 0, hInst, 0);
- 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);
-
- ShowWindow(hMainWnd, nCmdShow);
- UpdateWindow(hMainWnd);
-
- DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC));
- DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC));
- SetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
- SetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BackButtonProc));
- SetWindowLongPtr(hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc));
-
- SetFocus(hURLBarWnd);
-
- gMiniBrowser = new MiniBrowser(hMainWnd, hURLBarWnd, usesLayeredWebView, pageLoadTesting);
- if (!gMiniBrowser)
- goto exit;
- HRESULT hr = gMiniBrowser->init();
+ gMainWindow = new MainWindow();
+ HRESULT hr = gMainWindow->init(hInst, usesLayeredWebView, pageLoadTesting);
if (FAILED(hr))
goto exit;
- gViewWindow = gMiniBrowser->hwnd();
+ gMiniBrowser = gMainWindow->browserWindow();
+ ShowWindow(gMainWindow->hwnd(), nCmdShow);
- resizeSubViews();
-
- ShowWindow(gViewWindow, nCmdShow);
- UpdateWindow(gViewWindow);
-
hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER));
if (requestedURL.length())
@@ -139,28 +101,5 @@
// Shut down COM.
OleUninitialize();
- delete gMiniBrowser;
-
return static_cast<int>(msg.wParam);
}
-
-ATOM MyRegisterClass(HINSTANCE hInstance)
-{
- WNDCLASSEX wcex;
-
- wcex.cbSize = sizeof(WNDCLASSEX);
-
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MINIBROWSER));
- wcex.hCursor = LoadCursor(0, IDC_ARROW);
- wcex.hbrBackground = 0;
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MINIBROWSER);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
-
- return RegisterClassEx(&wcex);
-}