This source file includes following definitions.
- WindowSupportsRerouteMouseWheel
- IsCompatibleWithMouseWheelRedirection
- CanRedirectMouseWheelFrom
- SetWindowSupportsRerouteMouseWheel
- RerouteMouseWheel
#include "ui/base/win/mouse_wheel_util.h"
#include <windowsx.h>
#include "base/auto_reset.h"
#include "ui/base/view_prop.h"
#include "ui/gfx/win/hwnd_util.h"
namespace ui {
static const char* const kHWNDSupportMouseWheelRerouting =
"__HWND_MW_REROUTE_OK";
static bool WindowSupportsRerouteMouseWheel(HWND window) {
while (GetWindowLong(window, GWL_STYLE) & WS_CHILD) {
if (!IsWindow(window))
break;
if (ViewProp::GetValue(window, kHWNDSupportMouseWheelRerouting) != NULL) {
return true;
}
window = GetParent(window);
}
return false;
}
static bool IsCompatibleWithMouseWheelRedirection(HWND window) {
std::wstring class_name = gfx::GetClassName(window);
return !(class_name == L"ComboBox" ||
class_name == L"ComboBoxEx32");
}
static bool CanRedirectMouseWheelFrom(HWND window) {
std::wstring class_name = gfx::GetClassName(window);
if ((class_name == L"Syn Visual Class") ||
(class_name == L"SynTrackCursorWindowClass"))
return false;
return true;
}
ViewProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd) {
return new ViewProp(hwnd, kHWNDSupportMouseWheelRerouting,
reinterpret_cast<HANDLE>(true));
}
bool RerouteMouseWheel(HWND window, WPARAM w_param, LPARAM l_param) {
static bool recursion_break = false;
if (recursion_break)
return false;
if (!IsCompatibleWithMouseWheelRedirection(window))
return false;
DWORD current_process = GetCurrentProcessId();
POINT wheel_location = { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) };
HWND window_under_wheel = WindowFromPoint(wheel_location);
if (!CanRedirectMouseWheelFrom(window_under_wheel))
return false;
while (window != window_under_wheel) {
if (!::IsWindow(window_under_wheel))
return true;
DWORD wheel_window_process = 0;
GetWindowThreadProcessId(window_under_wheel, &wheel_window_process);
if (current_process != wheel_window_process) {
if (IsChild(window, window_under_wheel)) {
return false;
} else {
if (!WindowSupportsRerouteMouseWheel(window_under_wheel))
return true;
}
}
if (IsCompatibleWithMouseWheelRedirection(window_under_wheel)) {
base::AutoReset<bool> auto_reset_recursion_break(&recursion_break, true);
SendMessage(window_under_wheel, WM_MOUSEWHEEL, w_param, l_param);
return true;
}
window_under_wheel = GetAncestor(window_under_wheel, GA_PARENT);
}
return false;
}
}