#include "config.h"
#include "PlatformWheelEvent.h"
#include "FloatPoint.h"
#include "FloatSize.h"
#include <windows.h>
#include <windowsx.h>
namespace WebCore {
#define HIGH_BIT_MASK_SHORT 0x8000
#define SPI_GETWHEELSCROLLCHARS 0x006C
static IntPoint positionForEvent(HWND hWnd, LPARAM lParam)
{
POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
ScreenToClient(hWnd, &point);
return point;
}
static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam)
{
POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
return point;
}
static int horizontalScrollChars()
{
static ULONG scrollChars;
if (!scrollChars && !SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0))
scrollChars = 1;
return scrollChars;
}
static int verticalScrollLines()
{
static ULONG scrollLines;
if (!scrollLines && !SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0))
scrollLines = 3;
return scrollLines;
}
PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, const FloatSize& delta, const FloatPoint& location)
: PlatformEvent(PlatformEvent::Wheel, false, false, false, false, ::GetTickCount() * 0.001)
, m_directionInvertedFromDevice(false)
{
m_deltaX = delta.width();
m_deltaY = delta.height();
m_wheelTicksX = m_deltaX;
m_wheelTicksY = m_deltaY;
POINT point = {location.x(), location.y()};
m_globalPosition = point;
ScreenToClient(hWnd, &point);
m_position = point;
}
PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, WPARAM wParam, LPARAM lParam, bool isMouseHWheel)
: PlatformEvent(PlatformEvent::Wheel, wParam & MK_SHIFT, wParam & MK_CONTROL, GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT, GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT, ::GetTickCount() * 0.001)
, m_position(positionForEvent(hWnd, lParam))
, m_globalPosition(globalPositionForEvent(hWnd, lParam))
, m_directionInvertedFromDevice(false)
{
static const float cScrollbarPixelsPerLine = 100.0f / 3.0f;
float delta = GET_WHEEL_DELTA_WPARAM(wParam) / static_cast<float>(WHEEL_DELTA);
if (isMouseHWheel) {
m_wheelTicksX = delta;
m_wheelTicksY = 0;
delta = -delta;
} else {
m_wheelTicksX = 0;
m_wheelTicksY = delta;
}
if (isMouseHWheel || shiftKey()) {
m_deltaX = delta * static_cast<float>(horizontalScrollChars()) * cScrollbarPixelsPerLine;
m_deltaY = 0;
m_granularity = ScrollByPixelWheelEvent;
} else {
m_deltaX = 0;
m_deltaY = delta;
int verticalMultiplier = verticalScrollLines();
m_granularity = (verticalMultiplier == WHEEL_PAGESCROLL) ? ScrollByPageWheelEvent : ScrollByPixelWheelEvent;
if (m_granularity == ScrollByPixelWheelEvent)
m_deltaY *= static_cast<float>(verticalMultiplier) * cScrollbarPixelsPerLine;
}
}
}