diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 15:06:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:48:58 +0000 |
commit | daa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch) | |
tree | 96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/base/win/win_util.cc | |
parent | be59a35641616a4cf23c4a13fa0632624b021c1b (diff) |
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/base/win/win_util.cc')
-rw-r--r-- | chromium/base/win/win_util.cc | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/chromium/base/win/win_util.cc b/chromium/base/win/win_util.cc index 30a7a3a1e87..7de52ae7fb2 100644 --- a/chromium/base/win/win_util.cc +++ b/chromium/base/win/win_util.cc @@ -42,10 +42,12 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" +#include "base/win/core_winrt_util.h" #include "base/win/registry.h" #include "base/win/scoped_co_mem.h" #include "base/win/scoped_comptr.h" #include "base/win/scoped_handle.h" +#include "base/win/scoped_hstring.h" #include "base/win/scoped_propvariant.h" #include "base/win/windows_version.h" @@ -89,6 +91,34 @@ POWER_PLATFORM_ROLE GetPlatformRole() { return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); } +// Method used for Windows 8.1 and later. +// Since we support versions earlier than 8.1, we must dynamically load this +// function from user32.dll, so it won't fail to load in runtime. For earlier +// Windows versions GetProcAddress will return null and report failure so that +// callers can fall back on the deprecated SetProcessDPIAware. +bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) { + decltype(&::SetProcessDpiAwareness) set_process_dpi_awareness_func = + reinterpret_cast<decltype(&::SetProcessDpiAwareness)>(GetProcAddress( + GetModuleHandle(L"user32.dll"), "SetProcessDpiAwarenessInternal")); + if (set_process_dpi_awareness_func) { + HRESULT hr = set_process_dpi_awareness_func(value); + if (SUCCEEDED(hr)) + return true; + DLOG_IF(ERROR, hr == E_ACCESSDENIED) + << "Access denied error from SetProcessDpiAwarenessInternal. Function " + "called twice, or manifest was used."; + NOTREACHED() + << "SetProcessDpiAwarenessInternal failed with unexpected error: " + << hr; + return false; + } + + DCHECK_LT(GetVersion(), VERSION_WIN8_1) << "SetProcessDpiAwarenessInternal " + "should be available on all " + "platforms >= Windows 8.1"; + return false; +} + } // namespace // Uses the Windows 10 WRL API's to query the current system state. The API's @@ -100,58 +130,20 @@ bool IsWindows10TabletMode(HWND hwnd) { if (GetVersion() < VERSION_WIN10) return false; - using RoGetActivationFactoryFunction = decltype(&RoGetActivationFactory); - using WindowsCreateStringFunction = decltype(&WindowsCreateString); - - static RoGetActivationFactoryFunction get_factory = nullptr; - static WindowsCreateStringFunction create_string = nullptr; - - if (!get_factory) { - DCHECK_EQ(create_string, static_cast<WindowsCreateStringFunction>( - nullptr)); - - HMODULE combase_dll = ::LoadLibrary(L"combase.dll"); - if (!combase_dll) - return false; - - get_factory = reinterpret_cast<RoGetActivationFactoryFunction>( - ::GetProcAddress(combase_dll, "RoGetActivationFactory")); - if (!get_factory) { - CHECK(false); - return false; - } - - create_string = reinterpret_cast<WindowsCreateStringFunction>( - ::GetProcAddress(combase_dll, "WindowsCreateString")); - if (!create_string) { - CHECK(false); - return false; - } - } - - HRESULT hr = E_FAIL; - // This HSTRING is allocated on the heap and is leaked. - static HSTRING view_settings_guid = NULL; - if (!view_settings_guid) { - hr = create_string( - RuntimeClass_Windows_UI_ViewManagement_UIViewSettings, - static_cast<UINT32>( - wcslen(RuntimeClass_Windows_UI_ViewManagement_UIViewSettings)), - &view_settings_guid); - if (FAILED(hr)) - return false; + if (!ResolveCoreWinRTDelayload() || + !ScopedHString::ResolveCoreWinRTStringDelayload()) { + return false; } - base::win::ScopedComPtr<IUIViewSettingsInterop> view_settings_interop; - hr = get_factory(view_settings_guid, IID_PPV_ARGS(&view_settings_interop)); + ScopedHString view_settings_guid = ScopedHString::Create( + RuntimeClass_Windows_UI_ViewManagement_UIViewSettings); + ScopedComPtr<IUIViewSettingsInterop> view_settings_interop; + HRESULT hr = base::win::RoGetActivationFactory( + view_settings_guid.get(), IID_PPV_ARGS(&view_settings_interop)); if (FAILED(hr)) return false; - base::win::ScopedComPtr<ABI::Windows::UI::ViewManagement::IUIViewSettings> - view_settings; - // TODO(ananta) - // Avoid using GetForegroundWindow here and pass in the HWND of the window - // intiating the request to display the keyboard. + ScopedComPtr<ABI::Windows::UI::ViewManagement::IUIViewSettings> view_settings; hr = view_settings_interop->GetForWindow(hwnd, IID_PPV_ARGS(&view_settings)); if (FAILED(hr)) return false; @@ -167,7 +159,7 @@ bool IsWindows10TabletMode(HWND hwnd) { // if the keyboard count is 1 or more.. While this will work in most cases // it won't work if there are devices which expose keyboard interfaces which // are attached to the machine. -bool IsKeyboardPresentOnSlate(std::string* reason) { +bool IsKeyboardPresentOnSlate(std::string* reason, HWND hwnd) { bool result = false; if (GetVersion() < VERSION_WIN8) { @@ -195,7 +187,7 @@ bool IsKeyboardPresentOnSlate(std::string* reason) { } // If it is a tablet device we assume that there is no keyboard attached. - if (IsTabletDevice(reason)) { + if (IsTabletDevice(reason, hwnd)) { if (reason) *reason += "Tablet device.\n"; return false; @@ -438,14 +430,14 @@ void SetAbortBehaviorForCrashReporting() { signal(SIGABRT, ForceCrashOnSigAbort); } -bool IsTabletDevice(std::string* reason) { +bool IsTabletDevice(std::string* reason, HWND hwnd) { if (GetVersion() < VERSION_WIN8) { if (reason) *reason = "Tablet device detection not supported below Windows 8\n"; return false; } - if (IsWindows10TabletMode(::GetForegroundWindow())) + if (IsWindows10TabletMode(hwnd)) return true; if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) { @@ -570,7 +562,7 @@ bool IsUser32AndGdi32Available() { // If win32k syscalls aren't disabled, then user32 and gdi32 are available. // Can't disable win32k prior to windows 8. - if (base::win::GetVersion() < base::win::VERSION_WIN8) + if (GetVersion() < VERSION_WIN8) return true; typedef decltype( @@ -672,5 +664,20 @@ bool IsProcessPerMonitorDpiAware() { return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; } +void EnableHighDPISupport() { + // Enable per-monitor DPI for Win10 or above instead of Win8.1 since Win8.1 + // does not have EnableChildWindowDpiMessage, necessary for correct non-client + // area scaling across monitors. + PROCESS_DPI_AWARENESS process_dpi_awareness = + GetVersion() >= VERSION_WIN10 ? PROCESS_PER_MONITOR_DPI_AWARE + : PROCESS_SYSTEM_DPI_AWARE; + if (!SetProcessDpiAwarenessWrapper(process_dpi_awareness)) { + // For windows versions where SetProcessDpiAwareness is not available or + // failed, try its predecessor. + BOOL result = ::SetProcessDPIAware(); + DCHECK(result) << "SetProcessDPIAware failed."; + } +} + } // namespace win } // namespace base |