Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions code/framework/src/gui/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,36 @@ namespace Framework::GUI {
}
}

// MK_* button/modifier state from a mouse message's wParam, as CEF event flags.
// Blink sustains drags (scrollbar thumb, text selection) off the button flags
// carried by the move events, so these must reflect the live state.
static uint32_t CefMouseModifiers(WPARAM wParam) {
uint32_t mods = 0;
if (wParam & MK_CONTROL) mods |= EVENTFLAG_CONTROL_DOWN;
if (wParam & MK_SHIFT) mods |= EVENTFLAG_SHIFT_DOWN;
if (wParam & MK_LBUTTON) mods |= EVENTFLAG_LEFT_MOUSE_BUTTON;
if (wParam & MK_MBUTTON) mods |= EVENTFLAG_MIDDLE_MOUSE_BUTTON;
if (wParam & MK_RBUTTON) mods |= EVENTFLAG_RIGHT_MOUSE_BUTTON;
return mods;
}

void View::ProcessMouseEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (!_browser || !_shouldDisplay || !_hasFocus) {
return;
}

auto host = _browser->GetHost();

// Handle mouse wheel separately
// Handle mouse wheel separately. Unlike the client-relative messages below,
// WM_MOUSEWHEEL reports the cursor in screen coordinates, and packs the
// button/modifier state into the low word of wParam.
if (msg == WM_MOUSEWHEEL) {
POINT pt {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
::ScreenToClient(hWnd, &pt);
CefMouseEvent cefEvent;
cefEvent.x = GET_X_LPARAM(lParam) - _x;
cefEvent.y = GET_Y_LPARAM(lParam) - _y;
cefEvent.modifiers = 0;
cefEvent.x = pt.x - _x;
cefEvent.y = pt.y - _y;
cefEvent.modifiers = CefMouseModifiers(GET_KEYSTATE_WPARAM(wParam));
int delta = GET_WHEEL_DELTA_WPARAM(wParam);
host->SendMouseWheelEvent(cefEvent, 0, delta);
return;
Expand All @@ -177,7 +194,7 @@ namespace Framework::GUI {
CefMouseEvent cefEvent;
cefEvent.x = GET_X_LPARAM(lParam) - _x;
cefEvent.y = GET_Y_LPARAM(lParam) - _y;
cefEvent.modifiers = 0;
cefEvent.modifiers = CefMouseModifiers(wParam);

switch (msg) {
case WM_MOUSEMOVE: {
Expand All @@ -188,6 +205,10 @@ namespace Framework::GUI {
_isMouseDown = true;
host->SendMouseClickEvent(cefEvent, MBT_LEFT, false, 1);
} break;
case WM_LBUTTONDBLCLK: {
_isMouseDown = true;
host->SendMouseClickEvent(cefEvent, MBT_LEFT, false, 2);
} break;
case WM_LBUTTONUP: {
_isMouseDown = false;
host->SendMouseClickEvent(cefEvent, MBT_LEFT, true, 1);
Expand Down
Loading