From 88ab4507c403a0167777f445b28853e89417ec25 Mon Sep 17 00:00:00 2001 From: dmarkov Date: Fri, 4 Nov 2016 15:35:33 +0300 Subject: [PATCH] 8139189: VK_OEM_102 dead key detected as VK_UNDEFINED 8160623: [PIT] Exception running java/awt/event/KeyEvent/KeyChar/KeyCharTest.java Reviewed-by: alexsch, yan, prr --- .../native/sun/windows/awt_Component.cpp | 29 ++++++++++++++----- .../native/sun/windows/awt_Component.h | 4 ++- .../DiacriticsTest/DiacriticsTest.html | 10 ++++++- .../event/KeyEvent/KeyChar/KeyCharTest.java | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/windows/native/sun/windows/awt_Component.cpp b/src/windows/native/sun/windows/awt_Component.cpp index 0128972cb..405098b7b 100644 --- a/src/windows/native/sun/windows/awt_Component.cpp +++ b/src/windows/native/sun/windows/awt_Component.cpp @@ -256,6 +256,8 @@ AwtComponent::AwtComponent() AwtComponent::BuildPrimaryDynamicTable(); sm_PrimaryDynamicTableBuilt = TRUE; } + + deadKeyActive = FALSE; } AwtComponent::~AwtComponent() @@ -2936,6 +2938,7 @@ static const CharToVKEntry charToDeadVKTable[] = { {0x037A, java_awt_event_KeyEvent_VK_DEAD_IOTA}, // ASCII ??? {0x309B, java_awt_event_KeyEvent_VK_DEAD_VOICED_SOUND}, {0x309C, java_awt_event_KeyEvent_VK_DEAD_SEMIVOICED_SOUND}, + {0x0004, java_awt_event_KeyEvent_VK_COMPOSE}, {0,0} }; @@ -3428,8 +3431,9 @@ UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops, AwtToolkit::GetKeyboardState(keyboardState); // apply modifiers to keyboard state if necessary + BOOL shiftIsDown = FALSE; if (modifiers) { - BOOL shiftIsDown = modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK; + shiftIsDown = modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK; BOOL altIsDown = modifiers & java_awt_event_InputEvent_ALT_DOWN_MASK; BOOL ctrlIsDown = modifiers & java_awt_event_InputEvent_CTRL_DOWN_MASK; @@ -3501,18 +3505,27 @@ UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops, } // ctrlIsDown } // modifiers - // instead of creating our own conversion tables, I'll let Win32 - // convert the character for me. WORD wChar[2]; - UINT scancode = ::MapVirtualKey(wkey, 0); - int converted = ::ToUnicodeEx(wkey, scancode, keyboardState, - wChar, 2, 0, GetKeyboardLayout()); + int converted = 1; + UINT ch = ::MapVirtualKey(wkey, 2); + if (ch & 0x80000000) { + // Dead key which is handled as a normal key + isDeadKey = deadKeyActive = TRUE; + } else if (deadKeyActive) { + // We cannot use ::ToUnicodeEx if dead key is active because this will + // break dead key function + wChar[0] = shiftIsDown ? ch : tolower(ch); + } else { + UINT scancode = ::MapVirtualKey(wkey, 0); + converted = ::ToUnicodeEx(wkey, scancode, keyboardState, + wChar, 2, 0, GetKeyboardLayout()); + } UINT translation; BOOL deadKeyFlag = (converted == 2); // Dead Key - if (converted < 0) { + if (converted < 0 || isDeadKey) { translation = java_awt_event_KeyEvent_CHAR_UNDEFINED; } else // No translation available -- try known conversions or else punt. @@ -3666,6 +3679,8 @@ MsgRouting AwtComponent::WmIMEChar(UINT character, UINT repCnt, UINT flags, BOOL MsgRouting AwtComponent::WmChar(UINT character, UINT repCnt, UINT flags, BOOL system) { + deadKeyActive = FALSE; + // Will only get WmChar messages with DBCS if we create them for // an Edit class in the WmForwardChar method. These synthesized // DBCS chars are ok to pass on directly to the default window diff --git a/src/windows/native/sun/windows/awt_Component.h b/src/windows/native/sun/windows/awt_Component.h index b914ef1a2..780d810d4 100644 --- a/src/windows/native/sun/windows/awt_Component.h +++ b/src/windows/native/sun/windows/awt_Component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -820,6 +820,8 @@ private: // 6524352: support finer-resolution int m_wheelRotationAmount; + BOOL deadKeyActive; + /* * The association list of children's IDs and corresponding components. * Some components like Choice or List are required their sizes while diff --git a/test/java/awt/InputMethods/DiacriticsTest/DiacriticsTest.html b/test/java/awt/InputMethods/DiacriticsTest/DiacriticsTest.html index 89dab3d87..5cf5c91ea 100644 --- a/test/java/awt/InputMethods/DiacriticsTest/DiacriticsTest.html +++ b/test/java/awt/InputMethods/DiacriticsTest/DiacriticsTest.html @@ -1,5 +1,5 @@