From 59c2a2cf79038dd2bcae5c45300a6a50de4ac9fd Mon Sep 17 00:00:00 2001 From: shuchen Date: Tue, 4 Aug 2015 02:47:50 -0700 Subject: [PATCH] Refactoring for the InputMethod & InputMethodDelegate interfaces. 1) DispatchKeyEvent returns void type instead of bool, as it is not used. 2) DispatchKeyEventPostIME returns EventDispatchDetails, so that the caller (InputMethod) can know whether its being destroyed after the call of DispatchKeyEventPostIME. 3) Both DispatchKeyEvent & DispatchKeyEventPostIME takes ui::KeyEvent* as the parameter, so that the stopped_propagation() state can be carried over. Note: this cl doesn't try to change any existing behaviors/logics, except one thing: The cl https://codereview.chromium.org/1236923003 may introduce a potential regression which this cl tries to fix: DesktopWindowTreeHostWin::DispatchKeyEventPostIME() always call event->StopPropagation(). However, HWNDMessageHandler::OnKeyEvent() relies on the event.handled() state to correctly call SetMsgHandled(FALSE). This cl remove the StopPropagation() call in DesktopWindowTreeHostWin::DispatchKeyEventPostIME() and let InputMethodWin/RemoteInputMethodWin call it as appropriate. TBR=sky@chromium.org BUG=513917,474828 TEST=Trybots green. Review URL: https://codereview.chromium.org/1257603006 Cr-Commit-Position: refs/heads/master@{#341704} --- ash/display/window_tree_host_manager.cc | 3 +- ash/display/window_tree_host_manager.h | 3 +- ash/host/ash_remote_window_tree_host_win.cc | 14 +- ash/host/ash_remote_window_tree_host_win.h | 3 +- ash/host/ash_window_tree_host_ozone.cc | 17 +-- ash/host/ash_window_tree_host_unified.cc | 14 +- ash/host/ash_window_tree_host_unified.h | 3 +- ash/host/ash_window_tree_host_win.cc | 13 +- ash/host/ash_window_tree_host_x11.cc | 13 +- ash/host/ash_window_tree_host_x11.h | 3 +- ash/ime/input_method_event_handler.cc | 2 +- .../input_method/input_method_engine.cc | 2 +- mandoline/ui/aura/input_method_mandoline.cc | 22 +-- mandoline/ui/aura/input_method_mandoline.h | 2 +- .../ui/aura/native_widget_view_manager.cc | 3 +- ui/aura/window_tree_host.cc | 8 +- ui/aura/window_tree_host.h | 3 +- ui/base/ime/dummy_input_method.cc | 3 +- ui/base/ime/dummy_input_method.h | 2 +- ui/base/ime/input_method.h | 3 +- ui/base/ime/input_method_auralinux.cc | 106 +++++++------ ui/base/ime/input_method_auralinux.h | 10 +- .../ime/input_method_auralinux_unittest.cc | 142 +++++++++++------- ui/base/ime/input_method_base.cc | 12 +- ui/base/ime/input_method_base.h | 4 +- ui/base/ime/input_method_base_unittest.cc | 2 +- ui/base/ime/input_method_chromeos.cc | 99 ++++++------ ui/base/ime/input_method_chromeos.h | 15 +- ui/base/ime/input_method_chromeos_unittest.cc | 23 +-- ui/base/ime/input_method_delegate.h | 4 +- ui/base/ime/input_method_mac.h | 2 +- ui/base/ime/input_method_mac.mm | 4 +- ui/base/ime/input_method_minimal.cc | 21 +-- ui/base/ime/input_method_minimal.h | 2 +- ui/base/ime/input_method_win.cc | 44 +++--- ui/base/ime/input_method_win.h | 11 +- ui/base/ime/mock_input_method.cc | 4 +- ui/base/ime/mock_input_method.h | 2 +- ui/base/ime/remote_input_method_win.cc | 33 ++-- .../ime/remote_input_method_win_unittest.cc | 81 ++++++---- ui/keyboard/keyboard_util.cc | 2 +- ui/views/cocoa/bridged_content_view.mm | 4 +- ui/views/cocoa/bridged_native_widget.h | 2 +- ui/views/cocoa/bridged_native_widget.mm | 13 +- .../controls/textfield/textfield_unittest.cc | 27 ++-- .../desktop_window_tree_host_win.cc | 3 +- .../desktop_window_tree_host_x11.cc | 3 +- 47 files changed, 430 insertions(+), 381 deletions(-) diff --git a/ash/display/window_tree_host_manager.cc b/ash/display/window_tree_host_manager.cc index 77bec60e929827..af7d17c4b82fe8 100644 --- a/ash/display/window_tree_host_manager.cc +++ b/ash/display/window_tree_host_manager.cc @@ -862,7 +862,8 @@ void WindowTreeHostManager::PostDisplayConfigurationChange() { UpdateMouseLocationAfterDisplayChange(); } -bool WindowTreeHostManager::DispatchKeyEventPostIME(const ui::KeyEvent& event) { +ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( + ui::KeyEvent* event) { // Getting the active root window to dispatch the event. This isn't // significant as the event will be sent to the window resolved by // aura::client::FocusClient which is FocusController in ash. diff --git a/ash/display/window_tree_host_manager.h b/ash/display/window_tree_host_manager.h index 9829b287e24a88..5d276992e05f45 100644 --- a/ash/display/window_tree_host_manager.h +++ b/ash/display/window_tree_host_manager.h @@ -174,7 +174,8 @@ class ASH_EXPORT WindowTreeHostManager void PostDisplayConfigurationChange() override; // ui::internal::InputMethodDelegate overrides: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override; InputMethodEventHandler* input_method_event_handler() { return input_method_event_handler_.get(); diff --git a/ash/host/ash_remote_window_tree_host_win.cc b/ash/host/ash_remote_window_tree_host_win.cc index b51f1a603c987c..f3191b5eda025a 100644 --- a/ash/host/ash_remote_window_tree_host_win.cc +++ b/ash/host/ash_remote_window_tree_host_win.cc @@ -58,16 +58,14 @@ void AshRemoteWindowTreeHostWin::UpdateRootWindowSize( transformer_helper_.UpdateWindowSize(host_size); } -bool AshRemoteWindowTreeHostWin::DispatchKeyEventPostIME( - const ui::KeyEvent& event) { - ui::KeyEvent event_copy(event); +ui::EventDispatchDetails AshRemoteWindowTreeHostWin::DispatchKeyEventPostIME( + ui::KeyEvent* event) { input_method_handler()->SetPostIME(true); ui::EventDispatchDetails details = - event_processor()->OnEventFromSource(&event_copy); - if (details.dispatcher_destroyed) - return true; - input_method_handler()->SetPostIME(false); - return event_copy.stopped_propagation(); + event_processor()->OnEventFromSource(event); + if (!details.dispatcher_destroyed) + input_method_handler()->SetPostIME(false); + return details; } } // namespace ash diff --git a/ash/host/ash_remote_window_tree_host_win.h b/ash/host/ash_remote_window_tree_host_win.h index 97950c477d78ed..77ff3c378baebd 100644 --- a/ash/host/ash_remote_window_tree_host_win.h +++ b/ash/host/ash_remote_window_tree_host_win.h @@ -39,7 +39,8 @@ class ASH_EXPORT AshRemoteWindowTreeHostWin void UpdateRootWindowSize(const gfx::Size& host_size) override; // ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override; TransformerHelper transformer_helper_; diff --git a/ash/host/ash_window_tree_host_ozone.cc b/ash/host/ash_window_tree_host_ozone.cc index e04e75b708d1a0..85b3faef7e50db 100644 --- a/ash/host/ash_window_tree_host_ozone.cc +++ b/ash/host/ash_window_tree_host_ozone.cc @@ -49,7 +49,8 @@ class AshWindowTreeHostOzone : public AshWindowTreeHost, void DispatchEvent(ui::Event* event) override; // ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override; // Temporarily disable the tap-to-click feature. Used on CrOS. void SetTapToClickPaused(bool state); @@ -137,16 +138,14 @@ void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) { SendEventToProcessor(event); } -bool AshWindowTreeHostOzone::DispatchKeyEventPostIME( - const ui::KeyEvent& event) { - ui::KeyEvent event_copy(event); +ui::EventDispatchDetails AshWindowTreeHostOzone::DispatchKeyEventPostIME( + ui::KeyEvent* event) { input_method_handler()->SetPostIME(true); ui::EventDispatchDetails details = - event_processor()->OnEventFromSource(&event_copy); - if (details.dispatcher_destroyed) - return true; - input_method_handler()->SetPostIME(false); - return event_copy.stopped_propagation(); + event_processor()->OnEventFromSource(event); + if (!details.dispatcher_destroyed) + input_method_handler()->SetPostIME(false); + return details; } void AshWindowTreeHostOzone::SetTapToClickPaused(bool state) { diff --git a/ash/host/ash_window_tree_host_unified.cc b/ash/host/ash_window_tree_host_unified.cc index 7e78691629dee2..2759af6d1332e6 100644 --- a/ash/host/ash_window_tree_host_unified.cc +++ b/ash/host/ash_window_tree_host_unified.cc @@ -177,16 +177,14 @@ void AshWindowTreeHostUnified::OnWindowDestroying(aura::Window* window) { mirroring_hosts_.erase(iter); } -bool AshWindowTreeHostUnified::DispatchKeyEventPostIME( - const ui::KeyEvent& event) { - ui::KeyEvent event_copy(event); +ui::EventDispatchDetails AshWindowTreeHostUnified::DispatchKeyEventPostIME( + ui::KeyEvent* event) { input_method_handler()->SetPostIME(true); ui::EventDispatchDetails details = - event_processor()->OnEventFromSource(&event_copy); - if (details.dispatcher_destroyed) - return true; - input_method_handler()->SetPostIME(false); - return event_copy.stopped_propagation(); + event_processor()->OnEventFromSource(event); + if (!details.dispatcher_destroyed) + input_method_handler()->SetPostIME(false); + return details; } } // namespace ash diff --git a/ash/host/ash_window_tree_host_unified.h b/ash/host/ash_window_tree_host_unified.h index e6dac3c837c8ae..32557c9ed482af 100644 --- a/ash/host/ash_window_tree_host_unified.h +++ b/ash/host/ash_window_tree_host_unified.h @@ -65,7 +65,8 @@ class AshWindowTreeHostUnified : public AshWindowTreeHost, void OnWindowDestroying(aura::Window* window) override; // ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override; std::vector mirroring_hosts_; diff --git a/ash/host/ash_window_tree_host_win.cc b/ash/host/ash_window_tree_host_win.cc index 9419fa41863fa4..e69769ca6a55fe 100644 --- a/ash/host/ash_window_tree_host_win.cc +++ b/ash/host/ash_window_tree_host_win.cc @@ -104,15 +104,14 @@ class AshWindowTreeHostWin : public AshWindowTreeHost, } // ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { - ui::KeyEvent event_copy(event); + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override { input_method_handler()->SetPostIME(true); ui::EventDispatchDetails details = - event_processor()->OnEventFromSource(&event_copy); - if (details.dispatcher_destroyed) - return true; - input_method_handler()->SetPostIME(false); - return event_copy.stopped_propagation(); + event_processor()->OnEventFromSource(event); + if (!details.dispatcher_destroyed) + input_method_handler()->SetPostIME(false); + return details; } bool fullscreen_; diff --git a/ash/host/ash_window_tree_host_x11.cc b/ash/host/ash_window_tree_host_x11.cc index 1999052530ebac..a6971b5cae77d1 100644 --- a/ash/host/ash_window_tree_host_x11.cc +++ b/ash/host/ash_window_tree_host_x11.cc @@ -236,15 +236,14 @@ void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( SendEventToProcessor(event); } -bool AshWindowTreeHostX11::DispatchKeyEventPostIME(const ui::KeyEvent& event) { - ui::KeyEvent event_copy(event); +ui::EventDispatchDetails AshWindowTreeHostX11::DispatchKeyEventPostIME( + ui::KeyEvent* event) { input_method_handler()->SetPostIME(true); ui::EventDispatchDetails details = - event_processor()->OnEventFromSource(&event_copy); - if (details.dispatcher_destroyed) - return true; - input_method_handler()->SetPostIME(false); - return event_copy.stopped_propagation(); + event_processor()->OnEventFromSource(event); + if (!details.dispatcher_destroyed) + input_method_handler()->SetPostIME(false); + return details; } #if defined(OS_CHROMEOS) diff --git a/ash/host/ash_window_tree_host_x11.h b/ash/host/ash_window_tree_host_x11.h index bfe8bcc20a8103..f0e30d3731ab90 100644 --- a/ash/host/ash_window_tree_host_x11.h +++ b/ash/host/ash_window_tree_host_x11.h @@ -52,7 +52,8 @@ class ASH_EXPORT AshWindowTreeHostX11 : public AshWindowTreeHost, void OnHostInitialized(aura::WindowTreeHost* host) override; // ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override; #if defined(OS_CHROMEOS) // Set the CrOS touchpad "tap paused" property. It is used to temporarily diff --git a/ash/ime/input_method_event_handler.cc b/ash/ime/input_method_event_handler.cc index 8d3c0a8a6b8f22..da7d2fdc665e29 100644 --- a/ash/ime/input_method_event_handler.cc +++ b/ash/ime/input_method_event_handler.cc @@ -32,7 +32,7 @@ void InputMethodEventHandler::OnKeyEvent(ui::KeyEvent* event) { return; if (post_ime_) return; - input_method_->DispatchKeyEvent(*event); + input_method_->DispatchKeyEvent(event); event->StopPropagation(); } diff --git a/chrome/browser/chromeos/input_method/input_method_engine.cc b/chrome/browser/chromeos/input_method/input_method_engine.cc index 8b73134c79af31..d985f6a565f11c 100644 --- a/chrome/browser/chromeos/input_method/input_method_engine.cc +++ b/chrome/browser/chromeos/input_method/input_method_engine.cc @@ -324,7 +324,7 @@ bool InputMethodEngine::SendKeyEvents( ui::EventTimeForNow()); base::AutoReset reset_sent_key(&sent_key_event_, &ui_event); - input_method->DispatchKeyEvent(ui_event); + input_method->DispatchKeyEvent(&ui_event); } return true; diff --git a/mandoline/ui/aura/input_method_mandoline.cc b/mandoline/ui/aura/input_method_mandoline.cc index f1b510bd9ddbb1..5857466112d1f5 100644 --- a/mandoline/ui/aura/input_method_mandoline.cc +++ b/mandoline/ui/aura/input_method_mandoline.cc @@ -28,25 +28,27 @@ bool InputMethodMandoline::OnUntranslatedIMEMessage( return false; } -bool InputMethodMandoline::DispatchKeyEvent(const ui::KeyEvent& event) { - DCHECK(event.type() == ui::ET_KEY_PRESSED || - event.type() == ui::ET_KEY_RELEASED); +void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent* event) { + DCHECK(event->type() == ui::ET_KEY_PRESSED || + event->type() == ui::ET_KEY_RELEASED); // If no text input client, do nothing. - if (!GetTextInputClient()) - return DispatchKeyEventPostIME(event); + if (!GetTextInputClient()) { + ignore_result(DispatchKeyEventPostIME(event)); + return; + } // Here is where we change the differ from our base class's logic. Instead of // always dispatching a key down event, and then sending a synthesized // character event, we instead check to see if this is a character event and // send out the key if it is. (We fallback to normal dispatch if it isn't.) - if (event.is_char()) { - GetTextInputClient()->InsertChar(event.GetCharacter(), event.flags()); - - return false; + if (event->is_char()) { + GetTextInputClient()->InsertChar(event->GetCharacter(), event->flags()); + event->StopPropagation(); + return; } - return DispatchKeyEventPostIME(event); + ignore_result(DispatchKeyEventPostIME(event)); } void InputMethodMandoline::OnCaretBoundsChanged( diff --git a/mandoline/ui/aura/input_method_mandoline.h b/mandoline/ui/aura/input_method_mandoline.h index a7cfbe24720dd7..9da4653d5de1cf 100644 --- a/mandoline/ui/aura/input_method_mandoline.h +++ b/mandoline/ui/aura/input_method_mandoline.h @@ -18,7 +18,7 @@ class InputMethodMandoline : public ui::InputMethodBase { // Overridden from ui::InputMethod: bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnCaretBoundsChanged(const ui::TextInputClient* client) override; void CancelComposition(const ui::TextInputClient* client) override; void OnInputLocaleChanged() override; diff --git a/mandoline/ui/aura/native_widget_view_manager.cc b/mandoline/ui/aura/native_widget_view_manager.cc index cdc03b3898bb7d..1665d18c977a3b 100644 --- a/mandoline/ui/aura/native_widget_view_manager.cc +++ b/mandoline/ui/aura/native_widget_view_manager.cc @@ -108,8 +108,7 @@ void NativeWidgetViewManager::OnViewInputEvent(mojo::View* view, if (ui_event->IsKeyEvent()) { window_tree_host_->GetInputMethod()->DispatchKeyEvent( - *static_cast(ui_event.get())); - ui_event->StopPropagation(); + static_cast(ui_event.get())); } else { window_tree_host_->SendEventToProcessor(ui_event.get()); } diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc index c65c9271f4bc3b..5fdadb9ebbb210 100644 --- a/ui/aura/window_tree_host.cc +++ b/ui/aura/window_tree_host.cc @@ -193,11 +193,9 @@ void WindowTreeHost::SetSharedInputMethod(ui::InputMethod* input_method) { owned_input_method_ = false; } -bool WindowTreeHost::DispatchKeyEventPostIME(const ui::KeyEvent& event) { - ui::KeyEvent copied_event(event); - ui::EventDispatchDetails details = SendEventToProcessor(&copied_event); - DCHECK(!details.dispatcher_destroyed); - return copied_event.stopped_propagation(); +ui::EventDispatchDetails WindowTreeHost::DispatchKeyEventPostIME( + ui::KeyEvent* event) { + return SendEventToProcessor(event); } void WindowTreeHost::Show() { diff --git a/ui/aura/window_tree_host.h b/ui/aura/window_tree_host.h index fef9f63f650e57..2587c014b4e81e 100644 --- a/ui/aura/window_tree_host.h +++ b/ui/aura/window_tree_host.h @@ -144,7 +144,8 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate, void SetSharedInputMethod(ui::InputMethod* input_method); // Overridden from ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override; // Returns the EventSource responsible for dispatching events to the window // tree. diff --git a/ui/base/ime/dummy_input_method.cc b/ui/base/ime/dummy_input_method.cc index 3e54612422020d..186db86716eb11 100644 --- a/ui/base/ime/dummy_input_method.cc +++ b/ui/base/ime/dummy_input_method.cc @@ -36,8 +36,7 @@ TextInputClient* DummyInputMethod::GetTextInputClient() const { return NULL; } -bool DummyInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) { - return false; +void DummyInputMethod::DispatchKeyEvent(ui::KeyEvent* event) { } void DummyInputMethod::OnTextInputTypeChanged(const TextInputClient* client) { diff --git a/ui/base/ime/dummy_input_method.h b/ui/base/ime/dummy_input_method.h index 470151a9560581..636c8bbf581eec 100644 --- a/ui/base/ime/dummy_input_method.h +++ b/ui/base/ime/dummy_input_method.h @@ -25,7 +25,7 @@ class DummyInputMethod : public InputMethod { void SetFocusedTextInputClient(TextInputClient* client) override; void DetachTextInputClient(TextInputClient* client) override; TextInputClient* GetTextInputClient() const override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnTextInputTypeChanged(const TextInputClient* client) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; diff --git a/ui/base/ime/input_method.h b/ui/base/ime/input_method.h index dc0a43eb171697..21b02354b2c35b 100644 --- a/ui/base/ime/input_method.h +++ b/ui/base/ime/input_method.h @@ -91,8 +91,7 @@ class InputMethod { // dispatched back to the caller via // ui::InputMethodDelegate::DispatchKeyEventPostIME(), once it's processed by // the input method. It should only be called by a message dispatcher. - // Returns true if the event was processed. - virtual bool DispatchKeyEvent(const ui::KeyEvent& event) = 0; + virtual void DispatchKeyEvent(ui::KeyEvent* event) = 0; // Called by the focused client whenever its text input type is changed. // Before calling this method, the focused client must confirm or clear diff --git a/ui/base/ime/input_method_auralinux.cc b/ui/base/ime/input_method_auralinux.cc index a084195de193ed..73b8c306eaca02 100644 --- a/ui/base/ime/input_method_auralinux.cc +++ b/ui/base/ime/input_method_auralinux.cc @@ -17,8 +17,7 @@ InputMethodAuraLinux::InputMethodAuraLinux( : text_input_type_(TEXT_INPUT_TYPE_NONE), is_sync_mode_(false), composition_changed_(false), - suppress_next_result_(false), - destroyed_ptr_(nullptr) { + suppress_next_result_(false) { SetDelegate(delegate); context_ = LinuxInputMethodContextFactory::instance()->CreateInputMethodContext( @@ -29,8 +28,6 @@ InputMethodAuraLinux::InputMethodAuraLinux( } InputMethodAuraLinux::~InputMethodAuraLinux() { - if (destroyed_ptr_) - *destroyed_ptr_ = true; } LinuxInputMethodContext* InputMethodAuraLinux::GetContextForTesting( @@ -46,13 +43,15 @@ bool InputMethodAuraLinux::OnUntranslatedIMEMessage( return false; } -bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { - DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); +void InputMethodAuraLinux::DispatchKeyEvent(ui::KeyEvent* event) { + DCHECK(event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED); DCHECK(system_toplevel_window_focused()); // If no text input client, do nothing. - if (!GetTextInputClient()) - return DispatchKeyEventPostIME(event); + if (!GetTextInputClient()) { + ignore_result(DispatchKeyEventPostIME(event)); + return; + } suppress_next_result_ = false; composition_changed_ = false; @@ -63,29 +62,25 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { base::AutoReset flipper(&is_sync_mode_, true); if (text_input_type_ != TEXT_INPUT_TYPE_NONE && text_input_type_ != TEXT_INPUT_TYPE_PASSWORD) { - filtered = context_->DispatchKeyEvent(event); + filtered = context_->DispatchKeyEvent(*event); } else { - filtered = context_simple_->DispatchKeyEvent(event); + filtered = context_simple_->DispatchKeyEvent(*event); } } - bool destroyed = false; - bool handled = false; - if (event.type() == ui::ET_KEY_PRESSED && filtered) { - { - base::AutoReset auto_reset(&destroyed_ptr_, &destroyed); - if (NeedInsertChar()) - handled = DispatchKeyEventPostIME(event); - else if (HasInputMethodResult()) - handled = SendFakeProcessKeyEvent(event.flags()); - if (destroyed) - return true; - } + ui::EventDispatchDetails details; + if (event->type() == ui::ET_KEY_PRESSED && filtered) { + if (NeedInsertChar()) + details = DispatchKeyEventPostIME(event); + else if (HasInputMethodResult()) + details = SendFakeProcessKeyEvent(event); + if (details.dispatcher_destroyed) + return; // If the KEYDOWN is stopped propagation (e.g. triggered an accelerator), // don't InsertChar/InsertText to the input field. - if (handled) { + if (event->stopped_propagation() || details.target_destroyed) { ResetContext(); - return true; + return; } // Don't send VKEY_PROCESSKEY event if there is no result text or @@ -95,12 +90,13 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { // keydown/keypress/keyup event without an initial 229 keydown event. } + bool should_stop_propagation = false; TextInputClient* client = GetTextInputClient(); // Processes the result text before composition for sync mode. if (!result_text_.empty()) { if (filtered && NeedInsertChar()) { for (const auto ch : result_text_) - client->InsertChar(ch, event.flags()); + client->InsertChar(ch, event->flags()); } else { // If |filtered| is false, that means the IME wants to commit some text // but still release the key to the application. For example, Korean IME @@ -110,6 +106,7 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { // keydown event once. client->InsertText(result_text_); } + should_stop_propagation = true; } if (composition_changed_ && !IsTextInputTypeNone()) { @@ -119,6 +116,7 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { client->SetCompositionText(composition_); else if (result_text_.empty()) client->ClearCompositionText(); + should_stop_propagation = true; } // Makes sure the cached composition is cleared after committing any text or @@ -127,17 +125,15 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { composition_.Clear(); if (!filtered) { - { - base::AutoReset auto_reset(&destroyed_ptr_, &destroyed); - handled = DispatchKeyEventPostIME(event); - if (destroyed) - return true; + details = DispatchKeyEventPostIME(event); + if (details.dispatcher_destroyed) { + if (should_stop_propagation) + event->StopPropagation(); + return; } - if (handled) { + if (event->stopped_propagation() || details.target_destroyed) { ResetContext(); - return true; - } - if (event.type() == ui::ET_KEY_PRESSED) { + } else if (event->type() == ui::ET_KEY_PRESSED) { // If a key event was not filtered by |context_| or |context_simple_|, // then it means the key event didn't generate any result text. For some // cases, the key event may still generate a valid character, eg. a @@ -146,13 +142,15 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { // TextInputClient::InsertChar(). // Note: don't use |client| and use GetTextInputClient() here because // DispatchKeyEventPostIME may cause the current text input client change. - base::char16 ch = event.GetCharacter(); + base::char16 ch = event->GetCharacter(); if (ch && GetTextInputClient()) - GetTextInputClient()->InsertChar(ch, event.flags()); + GetTextInputClient()->InsertChar(ch, event->flags()); + should_stop_propagation = true; } } - return true; + if (should_stop_propagation) + event->StopPropagation(); } void InputMethodAuraLinux::UpdateContextFocusState() { @@ -248,8 +246,12 @@ void InputMethodAuraLinux::OnCommit(const base::string16& text) { } else if (!IsTextInputTypeNone()) { // If we are not handling key event, do not bother sending text result if // the focused text input client does not support text input. - SendFakeProcessKeyEvent(0); - GetTextInputClient()->InsertText(text); + ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, 0); + ui::EventDispatchDetails details = SendFakeProcessKeyEvent(&event); + if (details.dispatcher_destroyed) + return; + if (!event.stopped_propagation() && !details.target_destroyed) + GetTextInputClient()->InsertText(text); composition_.Clear(); } } @@ -263,8 +265,12 @@ void InputMethodAuraLinux::OnPreeditChanged( if (!composition_.text.empty() || !composition_text.text.empty()) composition_changed_ = true; } else { - SendFakeProcessKeyEvent(0); - GetTextInputClient()->SetCompositionText(composition_text); + ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, 0); + ui::EventDispatchDetails details = SendFakeProcessKeyEvent(&event); + if (details.dispatcher_destroyed) + return; + if (!event.stopped_propagation() && !details.target_destroyed) + GetTextInputClient()->SetCompositionText(composition_text); } composition_ = composition_text; @@ -282,8 +288,12 @@ void InputMethodAuraLinux::OnPreeditEnd() { } else { TextInputClient* client = GetTextInputClient(); if (client && client->HasCompositionText()) { - SendFakeProcessKeyEvent(0); - client->ClearCompositionText(); + ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, 0); + ui::EventDispatchDetails details = SendFakeProcessKeyEvent(&event); + if (details.dispatcher_destroyed) + return; + if (!event.stopped_propagation() && !details.target_destroyed) + client->ClearCompositionText(); } composition_.Clear(); } @@ -333,9 +343,13 @@ bool InputMethodAuraLinux::NeedInsertChar() const { result_text_.length() == 1); } -bool InputMethodAuraLinux::SendFakeProcessKeyEvent(int flags) const { - return DispatchKeyEventPostIME( - KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, flags)); +ui::EventDispatchDetails InputMethodAuraLinux::SendFakeProcessKeyEvent( + ui::KeyEvent* event) const { + KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, event->flags()); + ui::EventDispatchDetails details = DispatchKeyEventPostIME(&key_event); + if (key_event.stopped_propagation()) + event->StopPropagation(); + return details; } void InputMethodAuraLinux::ConfirmCompositionText() { diff --git a/ui/base/ime/input_method_auralinux.h b/ui/base/ime/input_method_auralinux.h index fec733b531ff48..05a80d7798bc44 100644 --- a/ui/base/ime/input_method_auralinux.h +++ b/ui/base/ime/input_method_auralinux.h @@ -27,7 +27,7 @@ class UI_BASE_IME_EXPORT InputMethodAuraLinux // Overriden from InputMethod. bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnTextInputTypeChanged(const TextInputClient* client) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; @@ -53,7 +53,7 @@ class UI_BASE_IME_EXPORT InputMethodAuraLinux private: bool HasInputMethodResult(); bool NeedInsertChar() const; - bool SendFakeProcessKeyEvent(int flags) const; + ui::EventDispatchDetails SendFakeProcessKeyEvent(ui::KeyEvent* event) const; void ConfirmCompositionText(); void UpdateContextFocusState(); void ResetContext(); @@ -80,12 +80,6 @@ class UI_BASE_IME_EXPORT InputMethodAuraLinux // event will be discarded. bool suppress_next_result_; - // The pointer to a boolean value which indicates whether this InputMethod - // instance is destroyed. This is used in DispatchKeyEvent to detect whether - // DispatchKeyEventPostIME will cause destruction of this InputMethod - // instance. See crbug.com/513917. - bool* destroyed_ptr_; - DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinux); }; diff --git a/ui/base/ime/input_method_auralinux_unittest.cc b/ui/base/ime/input_method_auralinux_unittest.cc index 456b372bf8643b..5c4afc53535bfc 100644 --- a/ui/base/ime/input_method_auralinux_unittest.cc +++ b/ui/base/ime/input_method_auralinux_unittest.cc @@ -153,9 +153,10 @@ class InputMethodDelegateForTesting : public internal::InputMethodDelegate { InputMethodDelegateForTesting(){}; ~InputMethodDelegateForTesting() override{}; - bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) override { + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* key_event) override { std::string action; - switch (key_event.type()) { + switch (key_event->type()) { case ET_KEY_PRESSED: action = "keydown:"; break; @@ -166,10 +167,10 @@ class InputMethodDelegateForTesting : public internal::InputMethodDelegate { break; } std::stringstream ss; - ss << key_event.key_code(); + ss << key_event->key_code(); action += std::string(ss.str()); TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16(action)); - return false; + return ui::EventDispatchDetails(); } private: @@ -290,9 +291,11 @@ TEST_F(InputMethodAuraLinuxTest, BasicSyncModeTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:65"); test_result_->ExpectAction("keypress:97"); @@ -305,7 +308,8 @@ TEST_F(InputMethodAuraLinuxTest, BasicSyncModeTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:65"); test_result_->ExpectAction("keypress:97"); @@ -320,9 +324,10 @@ TEST_F(InputMethodAuraLinuxTest, BasicAsyncModeTest) { new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); input_method_auralinux_->OnCommit(base::ASCIIToUTF16("a")); test_result_->ExpectAction("keydown:229"); @@ -336,7 +341,8 @@ TEST_F(InputMethodAuraLinuxTest, BasicAsyncModeTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:65"); test_result_->ExpectAction("keypress:97"); @@ -351,9 +357,10 @@ TEST_F(InputMethodAuraLinuxTest, IBusUSTest) { new TextInputClientForTesting(TEXT_INPUT_TYPE_TEXT)); input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); // IBus mutes the key down. test_result_->Verify(); @@ -361,7 +368,8 @@ TEST_F(InputMethodAuraLinuxTest, IBusUSTest) { // IBus simulates a faked key down and handle it in sync mode. context_->SetSyncMode(true); context_->AddCommitAction("a"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:65"); test_result_->ExpectAction("keypress:97"); @@ -369,8 +377,8 @@ TEST_F(InputMethodAuraLinuxTest, IBusUSTest) { // IBus does NOT handle the key up. context_->SetEatKey(false); - input_method_auralinux_->DispatchKeyEvent( - KeyEvent(ET_KEY_RELEASED, VKEY_A, 0)); + KeyEvent key_up(ET_KEY_RELEASED, VKEY_A, 0); + input_method_auralinux_->DispatchKeyEvent(&key_up); test_result_->ExpectAction("keyup:65"); test_result_->Verify(); @@ -386,7 +394,7 @@ TEST_F(InputMethodAuraLinuxTest, IBusPinyinTest) { input_method_auralinux_->OnTextInputTypeChanged(client.get()); KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + input_method_auralinux_->DispatchKeyEvent(&key); // IBus issues a standalone set_composition action. input_method_auralinux_->OnPreeditStart(); @@ -400,8 +408,8 @@ TEST_F(InputMethodAuraLinuxTest, IBusPinyinTest) { test_result_->Verify(); // IBus issues a commit text with composition after muting the space key down. - input_method_auralinux_->DispatchKeyEvent( - KeyEvent(ET_KEY_PRESSED, VKEY_SPACE, 0)); + KeyEvent key_up(ET_KEY_RELEASED, VKEY_SPACE, 0); + input_method_auralinux_->DispatchKeyEvent(&key_up); input_method_auralinux_->OnPreeditEnd(); input_method_auralinux_->OnCommit(base::ASCIIToUTF16("A")); @@ -425,7 +433,7 @@ TEST_F(InputMethodAuraLinuxTest, DeadKeyTest) { KeyEvent dead_key(ET_KEY_PRESSED, VKEY_OEM_7, 0); dead_key.set_character(L'\''); - input_method_auralinux_->DispatchKeyEvent(dead_key); + input_method_auralinux_->DispatchKeyEvent(&dead_key); // The single quote key is muted. test_result_->ExpectAction("keydown:222"); @@ -434,7 +442,7 @@ TEST_F(InputMethodAuraLinuxTest, DeadKeyTest) { context_simple_->AddCommitAction("X"); KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + input_method_auralinux_->DispatchKeyEvent(&key); // The following A key generates the accent key: รก. test_result_->ExpectAction("keydown:65"); @@ -456,7 +464,7 @@ TEST_F(InputMethodAuraLinuxTest, MultiCommitsTest) { KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("textinput:abc"); @@ -477,9 +485,10 @@ TEST_F(InputMethodAuraLinuxTest, MixedCompositionAndCommitTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("textinput:ac"); @@ -488,7 +497,8 @@ TEST_F(InputMethodAuraLinuxTest, MixedCompositionAndCommitTest) { test_result_->Verify(); context_->AddCommitAction("e"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionend"); @@ -507,9 +517,10 @@ TEST_F(InputMethodAuraLinuxTest, CompositionEndWithoutCommitTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionstart"); @@ -517,7 +528,8 @@ TEST_F(InputMethodAuraLinuxTest, CompositionEndWithoutCommitTest) { test_result_->Verify(); context_->AddCompositionEndAction(); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionend"); @@ -535,9 +547,10 @@ TEST_F(InputMethodAuraLinuxTest, CompositionEndWithEmptyCommitTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionstart"); @@ -546,7 +559,8 @@ TEST_F(InputMethodAuraLinuxTest, CompositionEndWithEmptyCommitTest) { context_->AddCompositionEndAction(); context_->AddCommitAction(""); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionend"); @@ -564,9 +578,10 @@ TEST_F(InputMethodAuraLinuxTest, CompositionEndWithCommitTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionstart"); @@ -575,7 +590,8 @@ TEST_F(InputMethodAuraLinuxTest, CompositionEndWithCommitTest) { context_->AddCompositionEndAction(); context_->AddCommitAction("b"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); // Verifies single char commit under composition mode will call InsertText // intead of InsertChar. @@ -597,9 +613,10 @@ TEST_F(InputMethodAuraLinuxTest, CompositionUpdateWithCommitTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("textinput:b"); @@ -612,7 +629,8 @@ TEST_F(InputMethodAuraLinuxTest, CompositionUpdateWithCommitTest) { context_->SetEatKey(true); context_->AddCommitAction("c"); context_->AddCompositionUpdateAction(""); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionend"); @@ -629,9 +647,10 @@ TEST_F(InputMethodAuraLinuxTest, MixedAsyncAndSyncTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); CompositionText comp; comp.text = base::ASCIIToUTF16("a"); input_method_auralinux_->OnPreeditChanged(comp); @@ -645,7 +664,8 @@ TEST_F(InputMethodAuraLinuxTest, MixedAsyncAndSyncTest) { context_->AddCompositionEndAction(); context_->AddCommitAction("b"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionend"); @@ -664,9 +684,10 @@ TEST_F(InputMethodAuraLinuxTest, MixedSyncAndAsyncTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'a'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'a'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionstart"); @@ -675,7 +696,8 @@ TEST_F(InputMethodAuraLinuxTest, MixedSyncAndAsyncTest) { context_->SetSyncMode(false); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); input_method_auralinux_->OnCommit(base::ASCIIToUTF16("b")); test_result_->ExpectAction("keydown:229"); @@ -685,7 +707,8 @@ TEST_F(InputMethodAuraLinuxTest, MixedSyncAndAsyncTest) { context_->SetSyncMode(true); context_->AddCommitAction("c"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:65"); test_result_->ExpectAction("keypress:99"); @@ -702,9 +725,10 @@ TEST_F(InputMethodAuraLinuxTest, ReleaseKeyTest) { input_method_auralinux_->SetFocusedTextInputClient(client.get()); input_method_auralinux_->OnTextInputTypeChanged(client.get()); - KeyEvent key(ET_KEY_PRESSED, VKEY_A, 0); - key.set_character(L'A'); - input_method_auralinux_->DispatchKeyEvent(key); + KeyEvent key_new(ET_KEY_PRESSED, VKEY_A, 0); + key_new.set_character(L'A'); + KeyEvent key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("keydown:229"); test_result_->ExpectAction("compositionstart"); @@ -713,7 +737,8 @@ TEST_F(InputMethodAuraLinuxTest, ReleaseKeyTest) { context_->SetEatKey(false); context_->AddCommitAction("b"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("compositionend"); test_result_->ExpectAction("textinput:b"); @@ -722,7 +747,8 @@ TEST_F(InputMethodAuraLinuxTest, ReleaseKeyTest) { test_result_->Verify(); context_->AddCommitAction("c"); - input_method_auralinux_->DispatchKeyEvent(key); + key = key_new; + input_method_auralinux_->DispatchKeyEvent(&key); test_result_->ExpectAction("textinput:c"); test_result_->ExpectAction("keydown:65"); diff --git a/ui/base/ime/input_method_base.cc b/ui/base/ime/input_method_base.cc index dc856198b0ca3b..3441f928b90ac4 100644 --- a/ui/base/ime/input_method_base.cc +++ b/ui/base/ime/input_method_base.cc @@ -104,12 +104,12 @@ void InputMethodBase::OnInputMethodChanged() const { client->OnInputMethodChanged(); } -bool InputMethodBase::DispatchKeyEventPostIME( - const ui::KeyEvent& event) const { - if (!delegate_) - return false; - - return delegate_->DispatchKeyEventPostIME(event); +ui::EventDispatchDetails InputMethodBase::DispatchKeyEventPostIME( + ui::KeyEvent* event) const { + ui::EventDispatchDetails details; + if (delegate_) + details = delegate_->DispatchKeyEventPostIME(event); + return details; } void InputMethodBase::NotifyTextInputStateChanged( diff --git a/ui/base/ime/input_method_base.h b/ui/base/ime/input_method_base.h index eb817383ba41e2..345683906be6c2 100644 --- a/ui/base/ime/input_method_base.h +++ b/ui/base/ime/input_method_base.h @@ -11,6 +11,7 @@ #include "base/observer_list.h" #include "ui/base/ime/input_method.h" #include "ui/base/ime/ui_base_ime_export.h" +#include "ui/events/event_dispatcher.h" namespace gfx { class Rect; @@ -76,7 +77,8 @@ class UI_BASE_IME_EXPORT InputMethodBase // Convenience method to call delegate_->DispatchKeyEventPostIME(). // Returns true if the event was processed - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) const; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) const; // Convenience method to notify all observers of TextInputClient changes. void NotifyTextInputStateChanged(const TextInputClient* client); diff --git a/ui/base/ime/input_method_base_unittest.cc b/ui/base/ime/input_method_base_unittest.cc index f8c45bc2dc31b0..0b619c2ef55913 100644 --- a/ui/base/ime/input_method_base_unittest.cc +++ b/ui/base/ime/input_method_base_unittest.cc @@ -143,7 +143,7 @@ class MockInputMethodBase : public InputMethodBase { InputMethod::NativeEventResult* result) override { return false; } - bool DispatchKeyEvent(const ui::KeyEvent&) override { return false; } + void DispatchKeyEvent(ui::KeyEvent*) override {} void OnCaretBoundsChanged(const TextInputClient* client) override {} void CancelComposition(const TextInputClient* client) override {} void OnInputLocaleChanged() override {} diff --git a/ui/base/ime/input_method_chromeos.cc b/ui/base/ime/input_method_chromeos.cc index 47c9c1678e6d34..c624a0fc20bd63 100644 --- a/ui/base/ime/input_method_chromeos.cc +++ b/ui/base/ime/input_method_chromeos.cc @@ -71,7 +71,7 @@ bool InputMethodChromeOS::OnUntranslatedIMEMessage( return false; } -void InputMethodChromeOS::ProcessKeyEventDone(const ui::KeyEvent* event, +void InputMethodChromeOS::ProcessKeyEventDone(ui::KeyEvent* event, bool is_handled) { DCHECK(event); if (event->type() == ET_KEY_PRESSED) { @@ -87,14 +87,14 @@ void InputMethodChromeOS::ProcessKeyEventDone(const ui::KeyEvent* event, } if (event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED) - ProcessKeyEventPostIME(*event, is_handled); + ProcessKeyEventPostIME(event, is_handled); handling_key_event_ = false; } -bool InputMethodChromeOS::DispatchKeyEvent(const ui::KeyEvent& event) { - DCHECK(event.IsKeyEvent()); - DCHECK(!(event.flags() & ui::EF_IS_SYNTHESIZED)); +void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { + DCHECK(event->IsKeyEvent()); + DCHECK(!(event->flags() & ui::EF_IS_SYNTHESIZED)); DCHECK(system_toplevel_window_focused()); // For linux_chromeos, the ime keyboard cannot track the caps lock state by @@ -105,10 +105,10 @@ bool InputMethodChromeOS::DispatchKeyEvent(const ui::KeyEvent& event) { chromeos::input_method::InputMethodManager::Get(); if (manager) { chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); - if (keyboard && event.type() == ui::ET_KEY_PRESSED) { - bool caps = (event.key_code() == ui::VKEY_CAPITAL) + if (keyboard && event->type() == ui::ET_KEY_PRESSED) { + bool caps = (event->key_code() == ui::VKEY_CAPITAL) ? !keyboard->CapsLockIsEnabled() - : (event.flags() & EF_CAPS_LOCK_DOWN); + : (event->flags() & EF_CAPS_LOCK_DOWN); keyboard->SetCapsLockEnabled(caps); } } @@ -120,32 +120,31 @@ bool InputMethodChromeOS::DispatchKeyEvent(const ui::KeyEvent& event) { // Note: We need to send the key event to ibus even if the |context_| is not // enabled, so that ibus can have a chance to enable the |context_|. if (!IsNonPasswordInputFieldFocused() || !GetEngine()) { - if (event.type() == ET_KEY_PRESSED) { - if (ExecuteCharacterComposer(event)) { + if (event->type() == ET_KEY_PRESSED) { + if (ExecuteCharacterComposer(*event)) { // Treating as PostIME event if character composer handles key event and // generates some IME event, ProcessKeyEventPostIME(event, true); - return true; + return; } ProcessUnfilteredKeyPressEvent(event); } else { - DispatchKeyEventPostIME(event); + ignore_result(DispatchKeyEventPostIME(event)); } - return true; + return; } handling_key_event_ = true; if (GetEngine()->IsInterestedInKeyEvent()) { GetEngine()->ProcessKeyEvent( - event, + *event, base::Bind(&InputMethodChromeOS::ProcessKeyEventDone, weak_ptr_factory_.GetWeakPtr(), // Pass the ownership of the new copied event. - base::Owned(new ui::KeyEvent(event)))); + base::Owned(new ui::KeyEvent(*event)))); } else { - ProcessKeyEventDone(&event, false); + ProcessKeyEventDone(event, false); } - return true; } void InputMethodChromeOS::OnTextInputTypeChanged( @@ -336,18 +335,19 @@ void InputMethodChromeOS::UpdateContextFocusState() { OnCaretBoundsChanged(GetTextInputClient()); } -void InputMethodChromeOS::ProcessKeyEventPostIME(const ui::KeyEvent& event, +void InputMethodChromeOS::ProcessKeyEventPostIME(ui::KeyEvent* event, bool handled) { TextInputClient* client = GetTextInputClient(); if (!client) { // As ibus works asynchronously, there is a chance that the focused client // loses focus before this method gets called. - DispatchKeyEventPostIME(event); + ignore_result(DispatchKeyEventPostIME(event)); return; } - if (event.type() == ET_KEY_PRESSED && handled) { - if (ProcessFilteredKeyPressEvent(event)) { + if (event->type() == ET_KEY_PRESSED && handled) { + ProcessFilteredKeyPressEvent(event); + if (event->stopped_propagation()) { ResetContext(); return; } @@ -369,26 +369,30 @@ void InputMethodChromeOS::ProcessKeyEventPostIME(const ui::KeyEvent& event, if (handled) return; // IME handled the key event. do not forward. - if (event.type() == ET_KEY_PRESSED) + if (event->type() == ET_KEY_PRESSED) ProcessUnfilteredKeyPressEvent(event); - else if (event.type() == ET_KEY_RELEASED) - DispatchKeyEventPostIME(event); + else if (event->type() == ET_KEY_RELEASED) + ignore_result(DispatchKeyEventPostIME(event)); } -bool InputMethodChromeOS::ProcessFilteredKeyPressEvent( - const ui::KeyEvent& event) { - if (NeedInsertChar()) - return DispatchKeyEventPostIME(event); - const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, - VKEY_PROCESSKEY, - event.flags()); - return DispatchKeyEventPostIME(fabricated_event); +void InputMethodChromeOS::ProcessFilteredKeyPressEvent(ui::KeyEvent* event) { + if (NeedInsertChar()) { + ignore_result(DispatchKeyEventPostIME(event)); + return; + } + ui::KeyEvent fabricated_event(ET_KEY_PRESSED, + VKEY_PROCESSKEY, + event->flags()); + ignore_result(DispatchKeyEventPostIME(&fabricated_event)); + if (fabricated_event.stopped_propagation()) + event->StopPropagation(); } void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( - const ui::KeyEvent& event) { + ui::KeyEvent* event) { const TextInputClient* prev_client = GetTextInputClient(); - if (DispatchKeyEventPostIME(event)) { + ignore_result(DispatchKeyEventPostIME(event)); + if (event->stopped_propagation()) { ResetContext(); return; } @@ -407,12 +411,12 @@ void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( // If a key event was not filtered by |context_| and |character_composer_|, // then it means the key event didn't generate any result text. So we need // to send corresponding character to the focused text input client. - uint16 ch = event.GetCharacter(); + uint16 ch = event->GetCharacter(); if (ch) - client->InsertChar(ch, event.flags()); + client->InsertChar(ch, event->flags()); } -void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, +void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, bool handled) { TextInputClient* client = GetTextInputClient(); DCHECK(client); @@ -421,7 +425,7 @@ void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, if (handled && NeedInsertChar()) { for (base::string16::const_iterator i = result_text_.begin(); i != result_text_.end(); ++i) { - client->InsertChar(*i, event.flags()); + client->InsertChar(*i, event->flags()); } } else { client->InsertText(result_text_); @@ -454,13 +458,12 @@ bool InputMethodChromeOS::HasInputMethodResult() const { return result_text_.length() || composition_changed_; } -void InputMethodChromeOS::SendFakeProcessKeyEvent(bool pressed) const { - if (!GetTextInputClient()) - return; +bool InputMethodChromeOS::SendFakeProcessKeyEvent(bool pressed) const { KeyEvent evt(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, pressed ? VKEY_PROCESSKEY : VKEY_UNKNOWN, EF_IME_FABRICATED_KEY); - DispatchKeyEventPostIME(evt); + ignore_result(DispatchKeyEventPostIME(&evt)); + return evt.stopped_propagation(); } void InputMethodChromeOS::CommitText(const std::string& text) { @@ -484,8 +487,8 @@ void InputMethodChromeOS::CommitText(const std::string& text) { // If we are not handling key event, do not bother sending text result if the // focused text input client does not support text input. if (!handling_key_event_ && !IsTextInputTypeNone()) { - SendFakeProcessKeyEvent(true); - GetTextInputClient()->InsertText(utf16_text); + if (!SendFakeProcessKeyEvent(true)) + GetTextInputClient()->InsertText(utf16_text); SendFakeProcessKeyEvent(false); result_text_.clear(); } @@ -528,8 +531,8 @@ void InputMethodChromeOS::UpdateCompositionText( if (!handling_key_event_) { // If we receive a composition text without pending key event, then we need // to send it to the focused text input client directly. - SendFakeProcessKeyEvent(true); - GetTextInputClient()->SetCompositionText(composition_); + if (!SendFakeProcessKeyEvent(true)) + GetTextInputClient()->SetCompositionText(composition_); SendFakeProcessKeyEvent(false); composition_changed_ = false; composition_.Clear(); @@ -547,8 +550,8 @@ void InputMethodChromeOS::HidePreeditText() { if (!handling_key_event_) { TextInputClient* client = GetTextInputClient(); if (client && client->HasCompositionText()) { - SendFakeProcessKeyEvent(true); - client->ClearCompositionText(); + if (!SendFakeProcessKeyEvent(true)) + client->ClearCompositionText(); SendFakeProcessKeyEvent(false); } composition_changed_ = false; diff --git a/ui/base/ime/input_method_chromeos.h b/ui/base/ime/input_method_chromeos.h index da1b12ba5ef58e..d632bf4405a7cc 100644 --- a/ui/base/ime/input_method_chromeos.h +++ b/ui/base/ime/input_method_chromeos.h @@ -32,7 +32,7 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS void OnBlur() override; bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnTextInputTypeChanged(const TextInputClient* client) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; @@ -47,7 +47,7 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS CompositionText* out_composition) const; // Process a key returned from the input method. - virtual void ProcessKeyEventPostIME(const ui::KeyEvent& event, + virtual void ProcessKeyEventPostIME(ui::KeyEvent* event, bool handled); // Resets context and abandon all pending results and key events. @@ -73,14 +73,14 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS // A VKEY_PROCESSKEY may be dispatched to the EventTargets. // It returns the result of whether the event has been stopped propagation // when dispatching post IME. - bool ProcessFilteredKeyPressEvent(const ui::KeyEvent& event); + void ProcessFilteredKeyPressEvent(ui::KeyEvent* event); // Processes a key event that was not filtered by the input method. - void ProcessUnfilteredKeyPressEvent(const ui::KeyEvent& event); + void ProcessUnfilteredKeyPressEvent(ui::KeyEvent* event); // Sends input method result caused by the given key event to the focused text // input client. - void ProcessInputMethodResult(const ui::KeyEvent& event, bool filtered); + void ProcessInputMethodResult(ui::KeyEvent* event, bool filtered); // Checks if the pending input method result needs inserting into the focused // text input client as a single character. @@ -90,7 +90,8 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS bool HasInputMethodResult() const; // Sends a fake key event for IME composing without physical key events. - void SendFakeProcessKeyEvent(bool pressed) const; + // Returns true if the faked key event is stopped propagation. + bool SendFakeProcessKeyEvent(bool pressed) const; // Passes keyevent and executes character composition if necessary. Returns // true if character composer comsumes key event. @@ -107,7 +108,7 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS void HidePreeditText(); // Callback function for IMEEngineHandlerInterface::ProcessKeyEvent. - void ProcessKeyEventDone(const ui::KeyEvent* event, bool is_handled); + void ProcessKeyEventDone(ui::KeyEvent* event, bool is_handled); // Returns whether an non-password input field is focused. bool IsNonPasswordInputFieldFocused(); diff --git a/ui/base/ime/input_method_chromeos_unittest.cc b/ui/base/ime/input_method_chromeos_unittest.cc index 26607f813e3b6a..c1dcdf21c2bc43 100644 --- a/ui/base/ime/input_method_chromeos_unittest.cc +++ b/ui/base/ime/input_method_chromeos_unittest.cc @@ -73,10 +73,10 @@ class TestableInputMethodChromeOS : public InputMethodChromeOS { }; // Overridden from InputMethodChromeOS: - void ProcessKeyEventPostIME(const ui::KeyEvent& key_event, + void ProcessKeyEventPostIME(ui::KeyEvent* key_event, bool handled) override { InputMethodChromeOS::ProcessKeyEventPostIME(key_event, handled); - process_key_event_post_ime_args_.event = &key_event; + process_key_event_post_ime_args_.event = key_event; process_key_event_post_ime_args_.handled = handled; ++process_key_event_post_ime_call_count_; } @@ -236,9 +236,12 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, } // Overridden from ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { - dispatched_key_event_ = event; - return stop_propagation_post_ime_; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override { + dispatched_key_event_ = *event; + if (stop_propagation_post_ime_) + event->StopPropagation(); + return ui::EventDispatchDetails(); } // Overridden from ui::TextInputClient: @@ -883,7 +886,7 @@ TEST_F(InputMethodChromeOSKeyEventTest, KeyEventDelayResponseTest) { // Do key event. input_type_ = TEXT_INPUT_TYPE_TEXT; ime_->OnTextInputTypeChanged(this); - ime_->DispatchKeyEvent(event); + ime_->DispatchKeyEvent(&event); // Check before state. const ui::KeyEvent* key_event = @@ -921,7 +924,7 @@ TEST_F(InputMethodChromeOSKeyEventTest, MultiKeyEventDelayResponseTest) { ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_B, kFlags); // Do key event. - ime_->DispatchKeyEvent(event); + ime_->DispatchKeyEvent(&event); const ui::KeyEvent* key_event = mock_ime_engine_handler_->last_processed_key_event(); EXPECT_EQ(ui::VKEY_B, key_event->key_code()); @@ -933,7 +936,7 @@ TEST_F(InputMethodChromeOSKeyEventTest, MultiKeyEventDelayResponseTest) { // Do key event again. ui::KeyEvent event2(ui::ET_KEY_PRESSED, ui::VKEY_C, kFlags); - ime_->DispatchKeyEvent(event2); + ime_->DispatchKeyEvent(&event2); const ui::KeyEvent* key_event2 = mock_ime_engine_handler_->last_processed_key_event(); EXPECT_EQ(ui::VKEY_C, key_event2->key_code()); @@ -987,7 +990,7 @@ TEST_F(InputMethodChromeOSKeyEventTest, StopPropagationTest) { stop_propagation_post_ime_ = true; ui::KeyEvent eventA(ui::ET_KEY_PRESSED, ui::VKEY_A, EF_NONE); eventA.set_character(L'A'); - ime_->DispatchKeyEvent(eventA); + ime_->DispatchKeyEvent(&eventA); mock_ime_engine_handler_->last_passed_callback().Run(false); const ui::KeyEvent* key_event = @@ -997,7 +1000,7 @@ TEST_F(InputMethodChromeOSKeyEventTest, StopPropagationTest) { // Do key event with event not being stopped propagation. stop_propagation_post_ime_ = false; - ime_->DispatchKeyEvent(eventA); + ime_->DispatchKeyEvent(&eventA); mock_ime_engine_handler_->last_passed_callback().Run(false); key_event = mock_ime_engine_handler_->last_processed_key_event(); diff --git a/ui/base/ime/input_method_delegate.h b/ui/base/ime/input_method_delegate.h index eed2724d2f557d..7bfa01a242adcc 100644 --- a/ui/base/ime/input_method_delegate.h +++ b/ui/base/ime/input_method_delegate.h @@ -6,6 +6,7 @@ #define UI_BASE_IME_INPUT_METHOD_DELEGATE_H_ #include "ui/base/ime/ui_base_ime_export.h" +#include "ui/events/event_dispatcher.h" namespace ui { @@ -21,7 +22,8 @@ class UI_BASE_IME_EXPORT InputMethodDelegate { // Dispatch a key event already processed by the input method. // Returns true if the event was processed. - virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) = 0; + virtual ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* key_event) = 0; }; } // namespace internal diff --git a/ui/base/ime/input_method_mac.h b/ui/base/ime/input_method_mac.h index 3a259b1a927e54..e14925c3e8c128 100644 --- a/ui/base/ime/input_method_mac.h +++ b/ui/base/ime/input_method_mac.h @@ -21,7 +21,7 @@ class UI_BASE_IME_EXPORT InputMethodMac : public InputMethodBase { // Overriden from InputMethod. bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; void OnInputLocaleChanged() override; diff --git a/ui/base/ime/input_method_mac.mm b/ui/base/ime/input_method_mac.mm index 0e9cac557e9f73..ff6118fa165dea 100644 --- a/ui/base/ime/input_method_mac.mm +++ b/ui/base/ime/input_method_mac.mm @@ -18,9 +18,9 @@ return false; } -bool InputMethodMac::DispatchKeyEvent(const ui::KeyEvent& event) { +void InputMethodMac::DispatchKeyEvent(ui::KeyEvent* event) { // This is used on Mac only to dispatch events post-IME. - return DispatchKeyEventPostIME(event); + ignore_result(DispatchKeyEventPostIME(event)); } void InputMethodMac::OnCaretBoundsChanged(const TextInputClient* client) { diff --git a/ui/base/ime/input_method_minimal.cc b/ui/base/ime/input_method_minimal.cc index 47d8cec0fb0be2..cd00702111f7b1 100644 --- a/ui/base/ime/input_method_minimal.cc +++ b/ui/base/ime/input_method_minimal.cc @@ -23,23 +23,24 @@ bool InputMethodMinimal::OnUntranslatedIMEMessage( return false; } -bool InputMethodMinimal::DispatchKeyEvent(const ui::KeyEvent& event) { - DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); +void InputMethodMinimal::DispatchKeyEvent(ui::KeyEvent* event) { + DCHECK(event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED); // If no text input client, do nothing. - if (!GetTextInputClient()) - return DispatchKeyEventPostIME(event); + if (!GetTextInputClient()) { + ignore_result(DispatchKeyEventPostIME(event)); + return; + } // Insert the character. - const bool handled = DispatchKeyEventPostIME(event); - if (event.type() == ET_KEY_PRESSED && GetTextInputClient()) { - const uint16 ch = event.GetCharacter(); + ignore_result(DispatchKeyEventPostIME(event)); + if (event->type() == ET_KEY_PRESSED && GetTextInputClient()) { + const uint16 ch = event->GetCharacter(); if (ch) { - GetTextInputClient()->InsertChar(ch, event.flags()); - return true; + GetTextInputClient()->InsertChar(ch, event->flags()); + event->StopPropagation(); } } - return handled; } void InputMethodMinimal::OnCaretBoundsChanged(const TextInputClient* client) {} diff --git a/ui/base/ime/input_method_minimal.h b/ui/base/ime/input_method_minimal.h index bb9b4abb628c7c..60d1a8e23f95cb 100644 --- a/ui/base/ime/input_method_minimal.h +++ b/ui/base/ime/input_method_minimal.h @@ -19,7 +19,7 @@ class UI_BASE_IME_EXPORT InputMethodMinimal : public InputMethodBase { // Overriden from InputMethod. bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; void OnInputLocaleChanged() override; diff --git a/ui/base/ime/input_method_win.cc b/ui/base/ime/input_method_win.cc index 45a0e6118ca4e2..7db88b6298a3ab 100644 --- a/ui/base/ime/input_method_win.cc +++ b/ui/base/ime/input_method_win.cc @@ -33,16 +33,10 @@ InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, enabled_(false), is_candidate_popup_open_(false), composing_window_handle_(NULL), - suppress_next_char_(false), - destroyed_ptr_(nullptr) { + suppress_next_char_(false) { SetDelegate(delegate); } -InputMethodWin::~InputMethodWin() { - if (destroyed_ptr_) - *destroyed_ptr_ = true; -} - void InputMethodWin::OnFocus() { InputMethodBase::OnFocus(); if (GetTextInputClient()) @@ -104,16 +98,20 @@ bool InputMethodWin::OnUntranslatedIMEMessage( return !!handled; } -bool InputMethodWin::DispatchKeyEvent(const ui::KeyEvent& event) { - if (!event.HasNativeEvent()) - return DispatchFabricatedKeyEvent(event); +void InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) { + if (!event->HasNativeEvent()) { + DispatchFabricatedKeyEvent(event); + return; + } - const base::NativeEvent& native_key_event = event.native_event(); + const base::NativeEvent& native_key_event = event->native_event(); if (native_key_event.message == WM_CHAR) { BOOL handled; OnChar(native_key_event.hwnd, native_key_event.message, native_key_event.wParam, native_key_event.lParam, &handled); - return !!handled; // Don't send WM_CHAR for post event processing. + if (handled) + event->StopPropagation(); + return; } // Handles ctrl-shift key to change text direction and layout alignment. if (ui::IMM32Manager::IsRTLKeyboardLayoutInstalled() && @@ -138,13 +136,9 @@ bool InputMethodWin::DispatchKeyEvent(const ui::KeyEvent& event) { } } - bool destroyed = false; - base::AutoReset auto_reset(&destroyed_ptr_, &destroyed); - bool handled = DispatchKeyEventPostIME(event); - if (destroyed) - return true; - suppress_next_char_ = handled; - return handled; + ui::EventDispatchDetails details = DispatchKeyEventPostIME(event); + if (!details.dispatcher_destroyed) + suppress_next_char_ = event->stopped_propagation(); } void InputMethodWin::OnTextInputTypeChanged(const TextInputClient* client) { @@ -591,20 +585,20 @@ bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { GetActiveWindow() == toplevel_window_handle_; } -bool InputMethodWin::DispatchFabricatedKeyEvent(const ui::KeyEvent& event) { - if (event.is_char()) { +void InputMethodWin::DispatchFabricatedKeyEvent(ui::KeyEvent* event) { + if (event->is_char()) { if (suppress_next_char_) { suppress_next_char_ = false; - return true; + return; } if (GetTextInputClient()) { GetTextInputClient()->InsertChar( - static_cast(event.key_code()), + static_cast(event->key_code()), ui::GetModifiersFromKeyState()); - return true; + return; } } - return DispatchKeyEventPostIME(event); + ignore_result(DispatchKeyEventPostIME(event)); } void InputMethodWin::ConfirmCompositionText() { diff --git a/ui/base/ime/input_method_win.h b/ui/base/ime/input_method_win.h index 66df7b350f0841..4814f269c2fe96 100644 --- a/ui/base/ime/input_method_win.h +++ b/ui/base/ime/input_method_win.h @@ -21,14 +21,13 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { public: InputMethodWin(internal::InputMethodDelegate* delegate, HWND toplevel_window_handle); - ~InputMethodWin() override; // Overridden from InputMethod: void OnFocus() override; void OnBlur() override; bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnTextInputTypeChanged(const TextInputClient* client) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; @@ -93,7 +92,7 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { // to be ready for receiving keyboard input. bool IsWindowFocused(const TextInputClient* client) const; - bool DispatchFabricatedKeyEvent(const ui::KeyEvent& event); + void DispatchFabricatedKeyEvent(ui::KeyEvent* event); // Asks the client to confirm current composition text. void ConfirmCompositionText(); @@ -134,12 +133,6 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { // propagation (e.g. triggered an accelerator). bool suppress_next_char_; - // The pointer to a boolean value which indicates whether this InputMethod - // instance is destroyed. This is used in DispatchKeyEvent to detect whether - // DispatchKeyEventPostIME will cause destruction of this InputMethod - // instance. See crbug.com/513917. - bool* destroyed_ptr_; - DISALLOW_COPY_AND_ASSIGN(InputMethodWin); }; diff --git a/ui/base/ime/mock_input_method.cc b/ui/base/ime/mock_input_method.cc index 8ff36190fbe6a2..f2cf8ebc67f5c4 100644 --- a/ui/base/ime/mock_input_method.cc +++ b/ui/base/ime/mock_input_method.cc @@ -40,8 +40,8 @@ TextInputClient* MockInputMethod::GetTextInputClient() const { return text_input_client_; } -bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) { - return delegate_->DispatchKeyEventPostIME(event); +void MockInputMethod::DispatchKeyEvent(ui::KeyEvent* event) { + ignore_result(delegate_->DispatchKeyEventPostIME(event)); } void MockInputMethod::OnFocus() { diff --git a/ui/base/ime/mock_input_method.h b/ui/base/ime/mock_input_method.h index f039eb5325ca7b..0925e4632ff51d 100644 --- a/ui/base/ime/mock_input_method.h +++ b/ui/base/ime/mock_input_method.h @@ -38,7 +38,7 @@ class UI_BASE_IME_EXPORT MockInputMethod void SetFocusedTextInputClient(TextInputClient* client) override; void DetachTextInputClient(TextInputClient* client) override; TextInputClient* GetTextInputClient() const override; - bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; void OnTextInputTypeChanged(const TextInputClient* client) override; void OnCaretBoundsChanged(const TextInputClient* client) override; void CancelComposition(const TextInputClient* client) override; diff --git a/ui/base/ime/remote_input_method_win.cc b/ui/base/ime/remote_input_method_win.cc index 5f8c0e71bc57cd..1a589bb0668f6b 100644 --- a/ui/base/ime/remote_input_method_win.cc +++ b/ui/base/ime/remote_input_method_win.cc @@ -179,30 +179,29 @@ class RemoteInputMethodWin : public InputMethod, return text_input_client_; } - bool DispatchKeyEvent(const ui::KeyEvent& event) override { - if (event.HasNativeEvent()) { - const base::NativeEvent& native_key_event = event.native_event(); - if (native_key_event.message != WM_CHAR) - return false; - if (!text_input_client_) - return false; - text_input_client_->InsertChar( - static_cast(native_key_event.wParam), - ui::GetModifiersFromKeyState()); - return true; + void DispatchKeyEvent(ui::KeyEvent* event) override { + if (event->HasNativeEvent()) { + const base::NativeEvent& native_key_event = event->native_event(); + if (native_key_event.message == WM_CHAR && text_input_client_) { + text_input_client_->InsertChar( + static_cast(native_key_event.wParam), + ui::GetModifiersFromKeyState()); + event->StopPropagation(); + } + return; } - if (event.is_char()) { + if (event->is_char()) { if (text_input_client_) { text_input_client_->InsertChar( - event.GetCharacter(), + event->GetCharacter(), ui::GetModifiersFromKeyState()); } - return true; + event->StopPropagation(); + return; } - if (!delegate_) - return false; - return delegate_->DispatchKeyEventPostIME(event); + if (delegate_) + ignore_result(delegate_->DispatchKeyEventPostIME(event)); } void OnTextInputTypeChanged(const TextInputClient* client) override { diff --git a/ui/base/ime/remote_input_method_win_unittest.cc b/ui/base/ime/remote_input_method_win_unittest.cc index a49662bfd84493..686937b2ecac28 100644 --- a/ui/base/ime/remote_input_method_win_unittest.cc +++ b/ui/base/ime/remote_input_method_win_unittest.cc @@ -138,10 +138,12 @@ class MockInputMethodDelegate : public internal::InputMethodDelegate { } private: - bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { - EXPECT_FALSE(event.HasNativeEvent()); - fabricated_key_events_.push_back(event.key_code()); - return true; + ui::EventDispatchDetails DispatchKeyEventPostIME( + ui::KeyEvent* event) override { + EXPECT_FALSE(event->HasNativeEvent()); + fabricated_key_events_.push_back(event->key_code()); + event->SetHandled(); + return ui::EventDispatchDetails(); } std::vector fabricated_key_events_; @@ -513,10 +515,12 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeKeyEvent) { scoped_ptr input_method(CreateRemoteInputMethodWin(&delegate_)); const MSG wm_keydown = { NULL, WM_KEYDOWN, ui::VKEY_A }; - ui::KeyEvent native_keydown(wm_keydown); + ui::KeyEvent new_keydown(wm_keydown); + ui::KeyEvent native_keydown(new_keydown); // This must not cause a crash. - EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); + input_method->DispatchKeyEvent(&native_keydown); + EXPECT_FALSE(native_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -529,8 +533,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeKeyEvent) { private_ptr->SetRemoteDelegate(&mock_remote_delegate); // TextInputClient is not focused yet here. - - EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); + native_keydown = new_keydown; + input_method->DispatchKeyEvent(&native_keydown); + EXPECT_FALSE(native_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -539,8 +544,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeKeyEvent) { input_method->SetFocusedTextInputClient(&mock_text_input_client); // TextInputClient is now focused here. - - EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); + native_keydown = new_keydown; + input_method->DispatchKeyEvent(&native_keydown); + EXPECT_FALSE(native_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -555,10 +561,12 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { scoped_ptr input_method(CreateRemoteInputMethodWin(&delegate_)); const MSG wm_char = { NULL, WM_CHAR, 'A', 0 }; - ui::KeyEvent native_char(wm_char); + ui::KeyEvent new_char(wm_char); + ui::KeyEvent native_char(new_char); // This must not cause a crash. - EXPECT_FALSE(input_method->DispatchKeyEvent(native_char)); + input_method->DispatchKeyEvent(&native_char); + EXPECT_FALSE(native_char.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -571,8 +579,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { private_ptr->SetRemoteDelegate(&mock_remote_delegate); // TextInputClient is not focused yet here. - - EXPECT_FALSE(input_method->DispatchKeyEvent(native_char)); + native_char = new_char; + input_method->DispatchKeyEvent(&native_char); + EXPECT_FALSE(native_char.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -581,8 +590,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { input_method->SetFocusedTextInputClient(&mock_text_input_client); // TextInputClient is now focused here. - - EXPECT_TRUE(input_method->DispatchKeyEvent(native_char)); + native_char = new_char; + input_method->DispatchKeyEvent(&native_char); + EXPECT_TRUE(native_char.handled()); EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -598,11 +608,13 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { MockTextInputClient mock_text_input_client; scoped_ptr input_method(CreateRemoteInputMethodWin(&delegate_)); - ui::KeyEvent fabricated_keydown(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); - fabricated_keydown.set_character(L'A'); + ui::KeyEvent new_keydown(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); + new_keydown.set_character(L'A'); + ui::KeyEvent fabricated_keydown(new_keydown); // This must not cause a crash. - EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); + input_method->DispatchKeyEvent(&fabricated_keydown); + EXPECT_TRUE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); ASSERT_EQ(1, delegate_.fabricated_key_events().size()); EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); @@ -616,8 +628,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { private_ptr->SetRemoteDelegate(&mock_remote_delegate); // TextInputClient is not focused yet here. - - EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); + fabricated_keydown = new_keydown; + input_method->DispatchKeyEvent(&fabricated_keydown); + EXPECT_TRUE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); ASSERT_EQ(1, delegate_.fabricated_key_events().size()); EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); @@ -626,8 +639,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { input_method->SetFocusedTextInputClient(&mock_text_input_client); // TextInputClient is now focused here. - - EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); + fabricated_keydown = new_keydown; + input_method->DispatchKeyEvent(&fabricated_keydown); + EXPECT_TRUE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); ASSERT_EQ(1, delegate_.fabricated_key_events().size()); EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); @@ -636,8 +650,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { input_method->SetDelegate(NULL); // RemoteInputMethodDelegateWin is no longer set here. - - EXPECT_FALSE(input_method->DispatchKeyEvent(fabricated_keydown)); + fabricated_keydown = new_keydown; + input_method->DispatchKeyEvent(&fabricated_keydown); + EXPECT_FALSE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); } @@ -649,10 +664,12 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { MockTextInputClient mock_text_input_client; scoped_ptr input_method(CreateRemoteInputMethodWin(&delegate_)); - ui::KeyEvent fabricated_char(L'A', ui::VKEY_A, ui::EF_NONE); + ui::KeyEvent new_char(L'A', ui::VKEY_A, ui::EF_NONE); + ui::KeyEvent fabricated_char(new_char); // This must not cause a crash. - EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); + input_method->DispatchKeyEvent(&fabricated_char); + EXPECT_TRUE(fabricated_char.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -665,8 +682,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { private_ptr->SetRemoteDelegate(&mock_remote_delegate); // TextInputClient is not focused yet here. - - EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); + fabricated_char = new_char; + input_method->DispatchKeyEvent(&fabricated_char); + EXPECT_TRUE(fabricated_char.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); @@ -675,8 +693,9 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { input_method->SetFocusedTextInputClient(&mock_text_input_client); // TextInputClient is now focused here. - - EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); + fabricated_char = new_char; + input_method->DispatchKeyEvent(&fabricated_char); + EXPECT_TRUE(fabricated_char.handled()); EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); EXPECT_TRUE(delegate_.fabricated_key_events().empty()); delegate_.Reset(); diff --git a/ui/keyboard/keyboard_util.cc b/ui/keyboard/keyboard_util.cc index f1753beb42f477..012c0d99e87738 100644 --- a/ui/keyboard/keyboard_util.cc +++ b/ui/keyboard/keyboard_util.cc @@ -327,7 +327,7 @@ bool SendKeyEvent(const std::string type, dom_code, modifiers); if (input_method) { - input_method->DispatchKeyEvent(event); + input_method->DispatchKeyEvent(&event); } else { ui::EventDispatchDetails details = host->event_processor()->OnEventFromSource(&event); diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm index 3a3e83962f1774..0a4b25796790c6 100644 --- a/ui/views/cocoa/bridged_content_view.mm +++ b/ui/views/cocoa/bridged_content_view.mm @@ -172,7 +172,7 @@ - (void)handleKeyEvent:(NSEvent*)theEvent { if (DispatchEventToMenu(hostedView_->GetWidget(), event.key_code())) return; - hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(event); + hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); } - (void)handleAction:(int)commandId @@ -193,7 +193,7 @@ - (void)handleAction:(int)commandId // Generate a synthetic event with the keycode toolkit-views expects. ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); - hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(event); + hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); } - (void)undo:(id)sender { diff --git a/ui/views/cocoa/bridged_native_widget.h b/ui/views/cocoa/bridged_native_widget.h index 288b0c7ee8872b..2f7d30a7fcab32 100644 --- a/ui/views/cocoa/bridged_native_widget.h +++ b/ui/views/cocoa/bridged_native_widget.h @@ -172,7 +172,7 @@ class VIEWS_EXPORT BridgedNativeWidget bool window_visible() { return window_visible_; } // Overridden from ui::internal::InputMethodDelegate: - bool DispatchKeyEventPostIME(const ui::KeyEvent& key) override; + ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override; private: friend class test::BridgedNativeWidgetTestApi; diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm index 1759a9591417fd..1bd03ff243ee6d 100644 --- a/ui/views/cocoa/bridged_native_widget.mm +++ b/ui/views/cocoa/bridged_native_widget.mm @@ -789,12 +789,15 @@ void SetupDragEventMonitor() { //////////////////////////////////////////////////////////////////////////////// // BridgedNativeWidget, internal::InputMethodDelegate: -bool BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { +ui::EventDispatchDetails BridgedNativeWidget::DispatchKeyEventPostIME( + ui::KeyEvent* key) { DCHECK(focus_manager_); - native_widget_mac_->GetWidget()->OnKeyEvent(const_cast(&key)); - if (!key.handled()) - return !focus_manager_->OnKeyEvent(key); - return key.handled(); + native_widget_mac_->GetWidget()->OnKeyEvent(key); + if (!key->handled()) { + if (!focus_manager_->OnKeyEvent(*key)) + key->StopPropagation(); + } + return ui::EventDispatchDetails(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc index cc17d01c1b644a..056a4c569b441b 100644 --- a/ui/views/controls/textfield/textfield_unittest.cc +++ b/ui/views/controls/textfield/textfield_unittest.cc @@ -73,7 +73,7 @@ class MockInputMethod : public ui::InputMethodBase { // Overridden from InputMethod: bool OnUntranslatedIMEMessage(const base::NativeEvent& event, NativeEventResult* result) override; - bool DispatchKeyEvent(const ui::KeyEvent& key) override; + void DispatchKeyEvent(ui::KeyEvent* key) override; void OnTextInputTypeChanged(const ui::TextInputClient* client) override; void OnCaretBoundsChanged(const ui::TextInputClient* client) override {} void CancelComposition(const ui::TextInputClient* client) override; @@ -141,19 +141,21 @@ bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event, return false; } -bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) { +void MockInputMethod::DispatchKeyEvent(ui::KeyEvent* key) { // Checks whether the key event is from EventGenerator on Windows which will // generate key event for WM_CHAR. // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here. - if (key.is_char() && key.HasNativeEvent()) - return true; + if (key->is_char() && key->HasNativeEvent()) + return; bool handled = !IsTextInputTypeNone() && HasComposition(); ClearStates(); if (handled) { - DCHECK(!key.is_char()); - ui::KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags()); - DispatchKeyEventPostIME(mock_key); + DCHECK(!key->is_char()); + ui::KeyEvent mock_key(ui::ET_KEY_PRESSED, + ui::VKEY_PROCESSKEY, + key->flags()); + DispatchKeyEventPostIME(&mock_key); } else { DispatchKeyEventPostIME(key); } @@ -167,15 +169,14 @@ bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) { client->SetCompositionText(composition_); else client->ClearCompositionText(); - } else if (key.type() == ui::ET_KEY_PRESSED) { - base::char16 ch = key.GetCharacter(); + } else if (key->type() == ui::ET_KEY_PRESSED) { + base::char16 ch = key->GetCharacter(); if (ch) - client->InsertChar(ch, key.flags()); + client->InsertChar(ch, key->flags()); } } ClearComposition(); - return true; } void MockInputMethod::OnTextInputTypeChanged( @@ -484,7 +485,7 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { // TODO(shuchen): making EventGenerator support input method and using // EventGenerator here. crbug.com/512315. ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); - input_method_->DispatchKeyEvent(event); + input_method_->DispatchKeyEvent(&event); #endif } @@ -508,7 +509,7 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { // For unicode characters, assume they come from IME rather than the // keyboard. So they are dispatched directly to the input method. ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); - input_method_->DispatchKeyEvent(event); + input_method_->DispatchKeyEvent(&event); } } diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc index 17888bc6231a09..5bee7fd959f9bf 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc @@ -805,8 +805,7 @@ bool DesktopWindowTreeHostWin::HandleMouseEvent(const ui::MouseEvent& event) { } void DesktopWindowTreeHostWin::HandleKeyEvent(ui::KeyEvent* event) { - GetInputMethod()->DispatchKeyEvent(*event); - event->StopPropagation(); + GetInputMethod()->DispatchKeyEvent(event); } void DesktopWindowTreeHostWin::HandleTouchEvent( diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc index 51c324110a74dd..4a6931050b59b4 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc @@ -1519,8 +1519,7 @@ void DesktopWindowTreeHostX11::DispatchTouchEvent(ui::TouchEvent* event) { } void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) { - GetInputMethod()->DispatchKeyEvent(*event); - event->StopPropagation(); + GetInputMethod()->DispatchKeyEvent(event); } void DesktopWindowTreeHostX11::ConvertEventToDifferentHost(