Skip to content

Commit

Permalink
[Win][MiniBrowser] MiniBrowser::updateDeviceScaleFactor should be a M…
Browse files Browse the repository at this point in the history
…ainWindow's method

https://bugs.webkit.org/show_bug.cgi?id=186387

Reviewed by Ryosuke Niwa.

MiniBrowser::updateDeviceScaleFactor does nothing for MiniBrowser.
It should be a MainWindow's method.

* MiniBrowser/win/MainWindow.cpp:
(MainWindow::init): Call MainWindow::updateDeviceScaleFactor.
(MainWindow::resizeSubViews): Do not set a font every time window size is changed.
(MainWindow::WndProc): Call MainWindow::updateDeviceScaleFactor on WM_DPICHANGED.
(MainWindow::updateDeviceScaleFactor): Converted from
MiniBrowser::updateDeviceScaleFactor and
MiniBrowser::generateFontForScaleFactor. Set a URL bar's font if DPI is changed.
* MiniBrowser/win/MainWindow.h:
* MiniBrowser/win/MiniBrowser.cpp:
(MiniBrowser::init):
(MiniBrowser::generateFontForScaleFactor): Deleted.
(MiniBrowser::updateDeviceScaleFactor): Deleted.
* MiniBrowser/win/MiniBrowser.h:
(MiniBrowser::deviceScaleFactor): Deleted.
(MiniBrowser::urlBarFont): Deleted.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@232609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] authored and [email protected] committed Jun 8, 2018
1 parent 13c43e1 commit 62cffd9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
26 changes: 26 additions & 0 deletions Tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
2018-06-07 Fujii Hironori <[email protected]>

[Win][MiniBrowser] MiniBrowser::updateDeviceScaleFactor should be a MainWindow's method
https://bugs.webkit.org/show_bug.cgi?id=186387

Reviewed by Ryosuke Niwa.

MiniBrowser::updateDeviceScaleFactor does nothing for MiniBrowser.
It should be a MainWindow's method.

* MiniBrowser/win/MainWindow.cpp:
(MainWindow::init): Call MainWindow::updateDeviceScaleFactor.
(MainWindow::resizeSubViews): Do not set a font every time window size is changed.
(MainWindow::WndProc): Call MainWindow::updateDeviceScaleFactor on WM_DPICHANGED.
(MainWindow::updateDeviceScaleFactor): Converted from
MiniBrowser::updateDeviceScaleFactor and
MiniBrowser::generateFontForScaleFactor. Set a URL bar's font if DPI is changed.
* MiniBrowser/win/MainWindow.h:
* MiniBrowser/win/MiniBrowser.cpp:
(MiniBrowser::init):
(MiniBrowser::generateFontForScaleFactor): Deleted.
(MiniBrowser::updateDeviceScaleFactor): Deleted.
* MiniBrowser/win/MiniBrowser.h:
(MiniBrowser::deviceScaleFactor): Deleted.
(MiniBrowser::urlBarFont): Deleted.

2018-06-07 Jonathan Bedard <[email protected]>

[webkitpy] Treat svn versions as Version objects
Expand Down
18 changes: 14 additions & 4 deletions Tools/MiniBrowser/win/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ float deviceScaleFactorForWindow(HWND);
}

static constexpr int controlButtonWidth = 24;
static constexpr int urlBarHeight = 24;

static WNDPROC DefEditProc = nullptr;

Expand Down Expand Up @@ -119,6 +120,7 @@ bool MainWindow::init(HINSTANCE hInstance, bool usesLayeredWebView, bool pageLoa
if (FAILED(hr))
return false;

updateDeviceScaleFactor();
resizeSubViews();
SetFocus(m_hURLBarWnd);
return true;
Expand All @@ -131,16 +133,13 @@ void MainWindow::resizeSubViews()
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);
Expand Down Expand Up @@ -229,7 +228,7 @@ LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPA
thisWindow->resizeSubViews();
break;
case WM_DPICHANGED:
thisWindow->browserWindow()->updateDeviceScaleFactor();
thisWindow->updateDeviceScaleFactor();
return DefWindowProc(hWnd, message, wParam, lParam);
default:
return DefWindowProc(hWnd, message, wParam, lParam);
Expand Down Expand Up @@ -418,3 +417,14 @@ void MainWindow::onURLBarEnter()
_bstr_t bstr(strPtr);
loadURL(bstr.GetBSTR());
}

void MainWindow::updateDeviceScaleFactor()
{
if (m_hURLBarFont)
::DeleteObject(m_hURLBarFont);
auto scaleFactor = WebCore::deviceScaleFactorForWindow(m_hMainWnd);
int fontHeight = scaleFactor * urlBarHeight * 3 / 4;
m_hURLBarFont = ::CreateFont(fontHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE, L"Times New Roman");
::SendMessage(m_hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(m_hURLBarFont), TRUE);
}
2 changes: 2 additions & 0 deletions Tools/MiniBrowser/win/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ class MainWindow : public RefCounted<MainWindow> {
MainWindow();
bool toggleMenuItem(UINT menuID);
void onURLBarEnter();
void updateDeviceScaleFactor();

HWND m_hMainWnd { nullptr };
HWND m_hURLBarWnd { nullptr };
HWND m_hBackButtonWnd { nullptr };
HWND m_hForwardButtonWnd { nullptr };
HWND m_hCacheWnd { nullptr };
HGDIOBJ m_hURLBarFont { nullptr };
RefPtr<MiniBrowser> m_browserWindow;
};
18 changes: 0 additions & 18 deletions Tools/MiniBrowser/win/MiniBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ ULONG MiniBrowser::Release()

HRESULT MiniBrowser::init()
{
updateDeviceScaleFactor();

HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&m_webView.GetInterfacePtr()));
if (FAILED(hr))
return hr;
Expand Down Expand Up @@ -627,22 +625,6 @@ void MiniBrowser::showLayerTree()
OutputDebugString(L"\n\n");
}

void MiniBrowser::generateFontForScaleFactor(float scaleFactor)
{
if (m_hURLBarFont)
::DeleteObject(m_hURLBarFont);

m_hURLBarFont = ::CreateFont(scaleFactor * 18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE, L"Times New Roman");
}


void MiniBrowser::updateDeviceScaleFactor()
{
m_deviceScaleFactor = WebCore::deviceScaleFactorForWindow(m_hMainWnd);
generateFontForScaleFactor(m_deviceScaleFactor);
}

static BOOL CALLBACK AbortProc(HDC hDC, int Error)
{
MSG msg;
Expand Down
7 changes: 0 additions & 7 deletions Tools/MiniBrowser/win/MiniBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ class MiniBrowser : public RefCounted<MiniBrowser> {

void showLayerTree();

float deviceScaleFactor() { return m_deviceScaleFactor; }
void updateDeviceScaleFactor();

HGDIOBJ urlBarFont() { return m_hURLBarFont; }
HWND hwnd() { return m_viewWnd; }

void print();
Expand All @@ -113,7 +109,6 @@ class MiniBrowser : public RefCounted<MiniBrowser> {
private:
MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting);
void subclassForLayeredWindow();
void generateFontForScaleFactor(float);
bool setCacheFolder();

std::vector<IWebHistoryItemPtr> m_historyItems;
Expand All @@ -139,9 +134,7 @@ class MiniBrowser : public RefCounted<MiniBrowser> {

HWND m_hMainWnd { nullptr };
HWND m_hURLBarWnd { nullptr };
HGDIOBJ m_hURLBarFont { nullptr };
HWND m_viewWnd { nullptr };

float m_deviceScaleFactor { 1.0f };
bool m_useLayeredWebView;
};

0 comments on commit 62cffd9

Please sign in to comment.