Commit e45bf8e4 authored by Mustafa Çamurcu's avatar Mustafa Çamurcu Committed by Commit Bot

Remove seperate path for test events on Windows

Currently test events use a seperate path for IME because they don't
have an MSG attached to them. This causes discrepancies
between tests and actual functionality. This cl removes the seperate
path and creates an MSG for all events.

This change also revealed that MenuRunnerTest.NonLatinMnemonic was
passing even though the functionality it tests doesn't actually work
on Windows. It sends a WM_CHAR event without sending WM_KEYDOWN event
and a WM_CHAR event alone is not sufficient to select a menu item.

Change-Id: I2be217fe65e9681a60e4405eb0982d838cf8f37d
Reviewed-on: https://chromium-review.googlesource.com/1048246
Commit-Queue: Mustafa Çamurcu <camurcu@google.com>
Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557940}
parent c8795e72
......@@ -97,10 +97,7 @@ bool InputMethodWin::OnUntranslatedIMEMessage(
}
ui::EventDispatchDetails InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) {
if (!event->HasNativeEvent())
return DispatchFabricatedKeyEvent(event);
const PlatformEvent& native_key_event = event->native_event();
MSG native_key_event = MSGFromKeyEvent(event);
BOOL handled = FALSE;
if (native_key_event.message == WM_CHAR) {
auto ref = weak_ptr_factory_.GetWeakPtr();
......@@ -453,21 +450,6 @@ void InputMethodWin::RefreshInputLanguage() {
}
}
ui::EventDispatchDetails InputMethodWin::DispatchFabricatedKeyEvent(
ui::KeyEvent* event) {
// The key event if from calling input.ime.sendKeyEvent or test.
ui::EventDispatchDetails details = DispatchKeyEventPostIME(event);
if (details.dispatcher_destroyed || details.target_destroyed ||
event->stopped_propagation()) {
return details;
}
if ((event->is_char() || event->GetDomKey().IsCharacter()) &&
event->type() == ui::ET_KEY_PRESSED && GetTextInputClient())
GetTextInputClient()->InsertChar(*event);
return details;
}
void InputMethodWin::ConfirmCompositionText() {
if (composing_window_handle_)
imm32_manager_.CleanupComposition(composing_window_handle_);
......
......@@ -74,8 +74,6 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodWinBase {
void RefreshInputLanguage();
ui::EventDispatchDetails DispatchFabricatedKeyEvent(ui::KeyEvent* event);
// Asks the client to confirm current composition text.
void ConfirmCompositionText();
......
......@@ -161,6 +161,9 @@ EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
EVENTS_EXPORT uint16_t GetScanCodeFromLParam(LPARAM lParam);
EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16_t scan_code);
// Creates an MSG from the given KeyEvent if there is no native_event.
EVENTS_EXPORT MSG MSGFromKeyEvent(KeyEvent* key_event, HWND hwnd = nullptr);
#endif
#if defined(USE_X11)
......
......@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/time/time.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
#include "ui/events/keycodes/platform_key_map_win.h"
#include "ui/events/win/system_event_state_lookup.h"
......@@ -418,4 +419,18 @@ LPARAM GetLParamFromScanCode(uint16_t scan_code) {
return l_param;
}
MSG MSGFromKeyEvent(KeyEvent* event, HWND hwnd) {
if (event->HasNativeEvent())
return event->native_event();
uint16_t scan_code = KeycodeConverter::DomCodeToNativeKeycode(event->code());
LPARAM l_param = GetLParamFromScanCode(scan_code);
WPARAM w_param = event->GetConflatedWindowsKeyCode();
UINT message;
if (event->is_char())
message = WM_CHAR;
else
message = event->type() == ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP;
return {hwnd, message, w_param, l_param};
}
} // namespace ui
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "ui/base/ui_base_types.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/controls/menu/menu_controller.h"
......@@ -179,8 +180,9 @@ TEST_F(MenuRunnerTest, LatinMnemonic) {
EXPECT_NE(nullptr, delegate->on_menu_closed_menu());
}
#if !defined(OS_WIN)
// Tests that a key press on a non-US keyboard layout activates the correct menu
// item.
// item. Disabled on Windows because a WM_CHAR event does not activate an item.
TEST_F(MenuRunnerTest, NonLatinMnemonic) {
// TODO: test uses GetContext(), which is not applicable to aura-mus.
// http://crbug.com/663809.
......@@ -204,6 +206,7 @@ TEST_F(MenuRunnerTest, NonLatinMnemonic) {
EXPECT_EQ(1, delegate->on_menu_closed_called());
EXPECT_NE(nullptr, delegate->on_menu_closed_menu());
}
#endif // !defined(OS_WIN)
// Tests that attempting to nest a menu within a drag-and-drop menu does not
// cause a crash. Instead the drag and drop action should be canceled, and the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment