Fix AltGr handling for OSR keyboard events (fixes issue #2892)
This commit is contained in:
parent
f5c79bf50c
commit
30d83cb94a
|
@ -1780,6 +1780,7 @@ typedef enum {
|
|||
EVENTFLAG_IS_KEY_PAD = 1 << 9,
|
||||
EVENTFLAG_IS_LEFT = 1 << 10,
|
||||
EVENTFLAG_IS_RIGHT = 1 << 11,
|
||||
EVENTFLAG_ALTGR_DOWN = 1 << 12,
|
||||
} cef_event_flags_t;
|
||||
|
||||
///
|
||||
|
|
|
@ -210,6 +210,8 @@ int CefBrowserPlatformDelegateNativeAura::TranslateUiEventModifiers(
|
|||
result |= ui::EF_CAPS_LOCK_ON;
|
||||
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
|
||||
result |= ui::EF_NUM_LOCK_ON;
|
||||
if (cef_modifiers & EVENTFLAG_ALTGR_DOWN)
|
||||
result |= ui::EF_ALTGR_DOWN;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -313,6 +313,16 @@ ui::KeyEvent CefBrowserPlatformDelegateNativeLinux::TranslateUiKeyEvent(
|
|||
return ui::KeyEvent(type, key_code, dom_code, flags, dom_key, time_stamp);
|
||||
}
|
||||
|
||||
content::NativeWebKeyboardEvent
|
||||
CefBrowserPlatformDelegateNativeLinux::TranslateWebKeyEvent(
|
||||
const CefKeyEvent& key_event) const {
|
||||
ui::KeyEvent ui_event = TranslateUiKeyEvent(key_event);
|
||||
if (key_event.type == KEYEVENT_CHAR) {
|
||||
return content::NativeWebKeyboardEvent(ui_event, key_event.character);
|
||||
}
|
||||
return content::NativeWebKeyboardEvent(ui_event);
|
||||
}
|
||||
|
||||
base::TimeTicks CefBrowserPlatformDelegateNativeLinux::GetEventTimeStamp()
|
||||
const {
|
||||
return base::TimeTicks() + base::TimeDelta::FromSeconds(GetSystemUptime());
|
||||
|
|
|
@ -40,6 +40,8 @@ class CefBrowserPlatformDelegateNativeLinux
|
|||
|
||||
// CefBrowserPlatformDelegateNativeAura methods:
|
||||
ui::KeyEvent TranslateUiKeyEvent(const CefKeyEvent& key_event) const override;
|
||||
content::NativeWebKeyboardEvent TranslateWebKeyEvent(
|
||||
const CefKeyEvent& key_event) const override;
|
||||
base::TimeTicks GetEventTimeStamp() const override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -791,6 +791,25 @@ void OsrWindowWin::OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam) {
|
|||
event.type = KEYEVENT_CHAR;
|
||||
event.modifiers = GetCefKeyboardModifiers(wParam, lParam);
|
||||
|
||||
// mimic alt-gr check behaviour from
|
||||
// src/ui/events/win/events_win_utils.cc: GetModifiersFromKeyState
|
||||
if ((event.type == KEYEVENT_CHAR) && IsKeyDown(VK_RMENU)) {
|
||||
// reverse AltGr detection taken from PlatformKeyMap::UsesAltGraph
|
||||
// instead of checking all combination for ctrl-alt, just check current char
|
||||
HKL current_layout = ::GetKeyboardLayout(0);
|
||||
|
||||
// https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-vkkeyscanexw
|
||||
// ... high-order byte contains the shift state,
|
||||
// which can be a combination of the following flag bits.
|
||||
// 2 Either CTRL key is pressed.
|
||||
// 4 Either ALT key is pressed.
|
||||
SHORT scan_res = ::VkKeyScanExW(wParam, current_layout);
|
||||
if (((scan_res >> 8) & 0xFF) == (2 | 4)) { // ctrl-alt pressed
|
||||
event.modifiers &= ~(EVENTFLAG_CONTROL_DOWN | EVENTFLAG_ALT_DOWN);
|
||||
event.modifiers |= EVENTFLAG_ALTGR_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
browser_->GetHost()->SendKeyEvent(event);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue