Commit 29b547e1 authored by flackr@chromium.org's avatar flackr@chromium.org

Revert 186187 - crashing on Win XP browser_tests with "Access is denied".

> Fix touch scaling for high dpi windows.
> 
> Touch events in windows are always expressed in screen coordinates, even if
> the target app is not dpi-aware. This patch determines the dpi scale used
> by the OS, and re-scales touch events accordingly. 
> 
> In some cases the touch events are sent to the wrong window. This is detected
> and corrected.
> 
> BUG=175542
> 
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=185474
> 
> Review URL: https://chromiumcodereview.appspot.com/12317157

TBR=girard@chromium.org
Review URL: https://codereview.chromium.org/12454004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186196 0039d316-1c4b-4281-b951-d872f2087c98
parent bef08a91
......@@ -2072,9 +2072,8 @@ WebKit::WebTouchPoint* WebTouchState::AddTouchPoint(
bool WebTouchState::UpdateTouchPoint(
WebKit::WebTouchPoint* touch_point,
TOUCHINPUT* touch_input) {
CPoint coordinates(
TOUCH_COORD_TO_PIXEL(touch_input->x) / ui::win::GetDPIScaleFromRegistry(),
TOUCH_COORD_TO_PIXEL(touch_input->y) / ui::win::GetDPIScaleFromRegistry());
CPoint coordinates(TOUCH_COORD_TO_PIXEL(touch_input->x),
TOUCH_COORD_TO_PIXEL(touch_input->y));
int radius_x = 1;
int radius_y = 1;
if (touch_input->dwMask & TOUCHINPUTMASKF_CONTACTAREA) {
......@@ -2141,8 +2140,8 @@ LRESULT RenderWidgetHostViewWin::OnTouchEvent(UINT message, WPARAM wparam,
if (total == 1 && (points[0].dwFlags & TOUCHEVENTF_DOWN)) {
pointer_down_context_ = true;
last_touch_location_ = gfx::Point(
TOUCH_COORD_TO_PIXEL(points[0].x) / ui::win::GetDPIScaleFromRegistry(),
TOUCH_COORD_TO_PIXEL(points[0].y) / ui::win::GetDPIScaleFromRegistry());
TOUCH_COORD_TO_PIXEL(points[0].x),
TOUCH_COORD_TO_PIXEL(points[0].y));
}
bool should_forward = render_widget_host_->ShouldForwardTouchEvent() &&
......
......@@ -8,7 +8,6 @@
#include "base/win/scoped_hdc.h"
#include "ui/base/layout.h"
#include "base/win/registry.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point_conversions.h"
#include "ui/gfx/rect_conversions.h"
......@@ -31,24 +30,6 @@ float GetDeviceScaleFactorImpl() {
#endif
}
FARPROC GetProcAddressWrapper(LPCSTR module_name, LPCSTR proc_name) {
HMODULE module = ::GetModuleHandleA(module_name);
if (module) {
return ::GetProcAddress(module, proc_name);
}
return NULL;
}
BOOL IsProcessDPIAwareWrapper() {
typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID);
IsProcessDPIAwarePtr is_process_dpi_aware_func =
reinterpret_cast<IsProcessDPIAwarePtr>(
GetProcAddressWrapper("user32.dll", "IsProcessDPIAware"));
if (is_process_dpi_aware_func)
return is_process_dpi_aware_func();
return FALSE;
}
} // namespace
namespace ui {
......@@ -84,7 +65,7 @@ void EnableHighDPISupport() {
typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID);
SetProcessDPIAwarePtr set_process_dpi_aware_func =
reinterpret_cast<SetProcessDPIAwarePtr>(
GetProcAddressWrapper("user32.dll", "SetProcessDPIAware"));
GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware"));
if (set_process_dpi_aware_func)
set_process_dpi_aware_func();
}
......@@ -122,33 +103,6 @@ gfx::Size DIPToScreenSize(const gfx::Size& dip_size) {
return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor()));
}
double GetDPIScaleFromRegistry() {
static double scale = -1.0;
if (scale == -1.0) {
double result = 1.0;
if (!IsProcessDPIAwareWrapper()) {
//HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
base::win::RegKey key(HKEY_CURRENT_USER,
L"Control Panel\\Desktop\\WindowMetrics",
KEY_QUERY_VALUE);
if (key.Valid()) {
DWORD value = 0;
if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) {
result = ((double)value) / kDefaultDPIX;
}
}
}
scale = result;
}
// Safety test to ignore invalid settings.
if (scale <= 0.0)
scale = 1.0;
return scale;
}
} // namespace win
} // namespace ui
......@@ -38,8 +38,6 @@ UI_EXPORT gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels);
UI_EXPORT gfx::Size DIPToScreenSize(const gfx::Size& dip_size);
UI_EXPORT double GetDPIScaleFromRegistry();
} // namespace win
} // namespace ui
......
......@@ -9,7 +9,6 @@
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h"
#include "ui/base/win/dpi.h"
#include "ui/base/win/hwnd_util.h"
namespace {
......@@ -120,25 +119,6 @@ LRESULT HWNDSubclass::OnWndProc(HWND hwnd,
UINT message,
WPARAM w_param,
LPARAM l_param) {
// Touch messages are always passed in screen coordinates. If the OS is
// scaled, but the app is not DPI aware, then then WM_TOUCH might be
// intended for a different window.
if (message == WM_TOUCH) {
TOUCHINPUT point;
if (GetTouchInputInfo((HTOUCHINPUT)l_param, 1,
&point, sizeof(TOUCHINPUT))) {
POINT touch_location = {
TOUCH_COORD_TO_PIXEL(point.x) / ui::win::GetDPIScaleFromRegistry(),
TOUCH_COORD_TO_PIXEL(point.y) / ui::win::GetDPIScaleFromRegistry()};
HWND actual_target = WindowFromPoint(touch_location);
if (actual_target != hwnd) {
return SendMessage(actual_target, message, w_param, l_param);
}
}
}
for (std::vector<HWNDMessageFilter*>::iterator it = filters_.begin();
it != filters_.end(); ++it) {
LRESULT l_result = 0;
......
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