Commit d71e32d3 authored by robliao's avatar robliao Committed by Commit bot
Browse files

Add Plumbing for WM_DPICHANGED

Once Per-Monitor DPI is enabled for Chrome, WM_DPICHANGED will be fired by the
Windows manager to let Chrome now the DPI for its HWND has changed and suggest
a new size and location for the Chrome Window based off of the new DPI.

BUG=426656

Review-Url: https://codereview.chromium.org/2093993003
Cr-Commit-Position: refs/heads/master@{#402353}
parent ed717079
......@@ -940,6 +940,15 @@ void DesktopWindowTreeHostWin::HandleWindowSizeChanged() {
}
}
void DesktopWindowTreeHostWin::HandleWindowScaleFactorChanged(
float window_scale_factor) {
if (compositor()) {
compositor()->SetScaleAndSize(
window_scale_factor,
message_handler_->GetClientAreaBounds().size());
}
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostWin, private:
......
......@@ -196,6 +196,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
bool HandleScrollEvent(const ui::ScrollEvent& event) override;
void HandleWindowSizeChanging() override;
void HandleWindowSizeChanged() override;
void HandleWindowScaleFactorChanged(float window_scale_factor) override;
Widget* GetWidget();
const Widget* GetWidget() const;
......
......@@ -28,6 +28,7 @@
#include "ui/base/win/mouse_wheel_util.h"
#include "ui/base/win/shell.h"
#include "ui/base/win/touch_input.h"
#include "ui/display/win/dpi.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
......@@ -1395,6 +1396,18 @@ LRESULT HWNDMessageHandler::OnDwmCompositionChanged(UINT msg,
return 0;
}
LRESULT HWNDMessageHandler::OnDpiChanged(UINT msg,
WPARAM w_param,
LPARAM l_param) {
if (LOWORD(w_param) != HIWORD(w_param))
NOTIMPLEMENTED() << "Received non-square scaling factors";
SetBoundsInternal(gfx::Rect(*reinterpret_cast<RECT*>(l_param)), false);
delegate_->HandleWindowScaleFactorChanged(
display::win::GetScalingFactorFromDPI(LOWORD(w_param)));
return 0;
}
void HWNDMessageHandler::OnEnterMenuLoop(BOOL from_track_popup_menu) {
if (menu_depth_++ == 0)
delegate_->HandleMenuLoop(true);
......
......@@ -330,6 +330,9 @@ class VIEWS_EXPORT HWNDMessageHandler :
// Vista and newer
CR_MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged)
// Win 8.1 and newer
CR_MESSAGE_HANDLER_EX(WM_DPICHANGED, OnDpiChanged)
// Non-atlcrack.h handlers
CR_MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject)
......@@ -422,6 +425,7 @@ class VIEWS_EXPORT HWNDMessageHandler :
LRESULT OnCreate(CREATESTRUCT* create_struct);
void OnDestroy();
void OnDisplayChange(UINT bits_per_pixel, const gfx::Size& screen_size);
LRESULT OnDpiChanged(UINT msg, WPARAM w_param, LPARAM l_param);
LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param);
void OnEnterMenuLoop(BOOL from_track_popup_menu);
void OnEnterSizeMove();
......
......@@ -242,6 +242,9 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
// Called when the window size has finished changing.
virtual void HandleWindowSizeChanged() = 0;
// Called when the window scale factor has changed.
virtual void HandleWindowScaleFactorChanged(float window_scale_factor) = 0;
protected:
virtual ~HWNDMessageHandlerDelegate() {}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment