Refactors ui::internal::InputMethodDelegate.

Simplify and combine Dispatch{,Fabricated}KeyEventPostIME methods into one method.

TEST=Run unit_tests, ui_unittests, views_unittests.
TBR=pfeldman@chromium.org

Review URL: https://codereview.chromium.org/142043006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247947 0039d316-1c4b-4281-b951-d872f2087c98
parent c419d483
...@@ -94,21 +94,10 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, ...@@ -94,21 +94,10 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate,
} }
} }
// ui::InputMethodDelegate: // ui::internal::InputMethodDelegate:
virtual bool DispatchKeyEventPostIME( virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE {
const base::NativeEvent& event) OVERRIDE { ui::TranslatedKeyEvent aura_event(event);
ui::TranslatedKeyEvent aura_event(event, false /* is_char */); return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent(&aura_event);
return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent(
&aura_event);
}
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) OVERRIDE {
ui::TranslatedKeyEvent aura_event(type == ui::ET_KEY_PRESSED, key_code,
flags);
return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent(
&aura_event);
} }
aura::RootWindow* root_; aura::RootWindow* root_;
......
...@@ -95,19 +95,9 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, ...@@ -95,19 +95,9 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate,
} }
} }
// ui::InputMethodDelegate: // ui::internal::InputMethodDelegate:
virtual bool DispatchKeyEventPostIME( virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE {
const base::NativeEvent& event) OVERRIDE { ui::TranslatedKeyEvent aura_event(event);
ui::TranslatedKeyEvent aura_event(event, false /* is_char */);
return root_->GetDispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent(
&aura_event);
}
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) OVERRIDE {
ui::TranslatedKeyEvent aura_event(type == ui::ET_KEY_PRESSED, key_code,
flags);
return root_->GetDispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( return root_->GetDispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent(
&aura_event); &aura_event);
} }
......
...@@ -11,14 +11,7 @@ DummyInputMethodDelegate::DummyInputMethodDelegate() {} ...@@ -11,14 +11,7 @@ DummyInputMethodDelegate::DummyInputMethodDelegate() {}
DummyInputMethodDelegate::~DummyInputMethodDelegate() {} DummyInputMethodDelegate::~DummyInputMethodDelegate() {}
bool DummyInputMethodDelegate::DispatchKeyEventPostIME( bool DummyInputMethodDelegate::DispatchKeyEventPostIME(
const base::NativeEvent& native_key_event) { const ui::KeyEvent& key_event) {
return true;
}
bool DummyInputMethodDelegate::DispatchFabricatedKeyEventPostIME(
ui::EventType type,
ui::KeyboardCode key_code,
int flags) {
return true; return true;
} }
......
...@@ -5,26 +5,20 @@ ...@@ -5,26 +5,20 @@
#ifndef UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_ #ifndef UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_
#define UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_ #define UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h"
#include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/input_method_delegate.h"
#include "ui/base/ui_base_export.h"
namespace ui { namespace ui {
namespace internal { namespace internal {
class UI_BASE_EXPORT DummyInputMethodDelegate class UI_BASE_EXPORT DummyInputMethodDelegate : public InputMethodDelegate {
: NON_EXPORTED_BASE(public InputMethodDelegate) {
public: public:
DummyInputMethodDelegate(); DummyInputMethodDelegate();
virtual ~DummyInputMethodDelegate(); virtual ~DummyInputMethodDelegate();
// InputMethodDelegate overrides: // Overridden from InputMethodDelegate:
virtual bool DispatchKeyEventPostIME( virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) OVERRIDE;
const base::NativeEvent& native_key_event) OVERRIDE;
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) OVERRIDE;
private: private:
DISALLOW_COPY_AND_ASSIGN(DummyInputMethodDelegate); DISALLOW_COPY_AND_ASSIGN(DummyInputMethodDelegate);
......
...@@ -111,11 +111,7 @@ bool InputMethodBase::DispatchKeyEventPostIME( ...@@ -111,11 +111,7 @@ bool InputMethodBase::DispatchKeyEventPostIME(
if (!delegate_) if (!delegate_)
return false; return false;
if (!event.HasNativeEvent()) return delegate_->DispatchKeyEventPostIME(event);
return delegate_->DispatchFabricatedKeyEventPostIME(
event.type(), event.key_code(), event.flags());
return delegate_->DispatchKeyEventPostIME(event.native_event());
} }
void InputMethodBase::NotifyTextInputStateChanged( void InputMethodBase::NotifyTextInputStateChanged(
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/base/ime/input_method_chromeos.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#undef Bool #undef Bool
#undef FocusIn #undef FocusIn
...@@ -19,12 +21,11 @@ ...@@ -19,12 +21,11 @@
#include "ui/base/ime/chromeos/ime_bridge.h" #include "ui/base/ime/chromeos/ime_bridge.h"
#include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h" #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h"
#include "ui/base/ime/chromeos/mock_ime_engine_handler.h" #include "ui/base/ime/chromeos/mock_ime_engine_handler.h"
#include "ui/base/ime/input_method_chromeos.h"
#include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/input_method_delegate.h"
#include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_client.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/test/events_test_utils_x11.h" #include "ui/events/test/events_test_utils_x11.h"
#include "ui/gfx/rect.h" #include "ui/gfx/geometry/rect.h"
using base::UTF8ToUTF16; using base::UTF8ToUTF16;
using base::UTF16ToUTF8; using base::UTF16ToUTF8;
...@@ -72,7 +73,7 @@ class TestableInputMethodChromeOS : public InputMethodChromeOS { ...@@ -72,7 +73,7 @@ class TestableInputMethodChromeOS : public InputMethodChromeOS {
bool handled; bool handled;
}; };
// InputMethodChromeOS override. // Overridden from InputMethodChromeOS:
virtual void ProcessKeyEventPostIME(const ui::KeyEvent& key_event, virtual void ProcessKeyEventPostIME(const ui::KeyEvent& key_event,
bool handled) OVERRIDE { bool handled) OVERRIDE {
process_key_event_post_ime_args_.event = &key_event; process_key_event_post_ime_args_.event = &key_event;
...@@ -193,17 +194,17 @@ class SetSurroundingTextVerifier { ...@@ -193,17 +194,17 @@ class SetSurroundingTextVerifier {
}; };
class InputMethodChromeOSTest : public internal::InputMethodDelegate, class InputMethodChromeOSTest : public internal::InputMethodDelegate,
public testing::Test, public testing::Test,
public TextInputClient { public TextInputClient {
public: public:
InputMethodChromeOSTest() { InputMethodChromeOSTest()
: dispatched_key_event_(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, 0, false) {
ResetFlags(); ResetFlags();
} }
virtual ~InputMethodChromeOSTest() { virtual ~InputMethodChromeOSTest() {
} }
// testing::Test overrides:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
chromeos::IMEBridge::Initialize(); chromeos::IMEBridge::Initialize();
...@@ -232,22 +233,13 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, ...@@ -232,22 +233,13 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate,
chromeos::IMEBridge::Shutdown(); chromeos::IMEBridge::Shutdown();
} }
// ui::internal::InputMethodDelegate overrides: // Overridden from ui::internal::InputMethodDelegate:
virtual bool DispatchKeyEventPostIME( virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE {
const base::NativeEvent& native_key_event) OVERRIDE { dispatched_key_event_ = event;
dispatched_native_event_ = native_key_event;
return false;
}
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) OVERRIDE {
dispatched_fabricated_event_type_ = type;
dispatched_fabricated_event_key_code_ = key_code;
dispatched_fabricated_event_flags_ = flags;
return false; return false;
} }
// ui::TextInputClient overrides: // Overridden from ui::TextInputClient:
virtual void SetCompositionText( virtual void SetCompositionText(
const CompositionText& composition) OVERRIDE { const CompositionText& composition) OVERRIDE {
composition_text_ = composition; composition_text_ = composition;
...@@ -316,26 +308,19 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, ...@@ -316,26 +308,19 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate,
virtual bool ChangeTextDirectionAndLayoutAlignment( virtual bool ChangeTextDirectionAndLayoutAlignment(
base::i18n::TextDirection direction) OVERRIDE { return false; } base::i18n::TextDirection direction) OVERRIDE { return false; }
virtual void ExtendSelectionAndDelete(size_t before, virtual void ExtendSelectionAndDelete(size_t before,
size_t after) OVERRIDE { } size_t after) OVERRIDE {}
virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE { } virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE {}
virtual void OnCandidateWindowShown() OVERRIDE { } virtual void OnCandidateWindowShown() OVERRIDE {}
virtual void OnCandidateWindowUpdated() OVERRIDE { } virtual void OnCandidateWindowUpdated() OVERRIDE {}
virtual void OnCandidateWindowHidden() OVERRIDE { } virtual void OnCandidateWindowHidden() OVERRIDE {}
bool HasNativeEvent() const { bool HasNativeEvent() const {
base::NativeEvent empty; return dispatched_key_event_.HasNativeEvent();
std::memset(&empty, 0, sizeof(empty));
return !!std::memcmp(&dispatched_native_event_,
&empty,
sizeof(dispatched_native_event_));
} }
void ResetFlags() { void ResetFlags() {
std::memset(&dispatched_native_event_, 0, sizeof(dispatched_native_event_)); dispatched_key_event_ = ui::KeyEvent(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, 0,
DCHECK(!HasNativeEvent()); false);
dispatched_fabricated_event_type_ = ET_UNKNOWN;
dispatched_fabricated_event_key_code_ = VKEY_UNKNOWN;
dispatched_fabricated_event_flags_ = 0;
composition_text_.Clear(); composition_text_.Clear();
confirmed_text_.Clear(); confirmed_text_.Clear();
...@@ -352,12 +337,8 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, ...@@ -352,12 +337,8 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate,
scoped_ptr<TestableInputMethodChromeOS> ime_; scoped_ptr<TestableInputMethodChromeOS> ime_;
// Variables for remembering the parameters that are passed to // Copy of the dispatched key event.
// ui::internal::InputMethodDelegate functions. ui::KeyEvent dispatched_key_event_;
base::NativeEvent dispatched_native_event_;
ui::EventType dispatched_fabricated_event_type_;
ui::KeyboardCode dispatched_fabricated_event_key_code_;
int dispatched_fabricated_event_flags_;
// Variables for remembering the parameters that are passed to // Variables for remembering the parameters that are passed to
// ui::TextInputClient functions. // ui::TextInputClient functions.
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#ifndef UI_BASE_IME_INPUT_METHOD_DELEGATE_H_ #ifndef UI_BASE_IME_INPUT_METHOD_DELEGATE_H_
#define UI_BASE_IME_INPUT_METHOD_DELEGATE_H_ #define UI_BASE_IME_INPUT_METHOD_DELEGATE_H_
#include "base/event_types.h"
#include "ui/base/ui_base_export.h" #include "ui/base/ui_base_export.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace ui { namespace ui {
class KeyEvent;
namespace internal { namespace internal {
// An interface implemented by the object that handles events sent back from an // An interface implemented by the object that handles events sent back from an
...@@ -21,13 +21,7 @@ class UI_BASE_EXPORT InputMethodDelegate { ...@@ -21,13 +21,7 @@ class UI_BASE_EXPORT InputMethodDelegate {
// Dispatch a key event already processed by the input method. // Dispatch a key event already processed by the input method.
// Returns true if the event was processed. // Returns true if the event was processed.
virtual bool DispatchKeyEventPostIME( virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) = 0;
const base::NativeEvent& native_key_event) = 0;
// TODO(komatsu): Unify this function to DispatchKeyEventPostIME.
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) = 0;
}; };
} // namespace internal } // namespace internal
......
...@@ -204,9 +204,7 @@ class RemoteInputMethodWin : public InputMethod, ...@@ -204,9 +204,7 @@ class RemoteInputMethodWin : public InputMethod,
} }
if (!delegate_) if (!delegate_)
return false; return false;
return delegate_->DispatchFabricatedKeyEventPostIME(event.type(), return delegate_->DispatchKeyEventPostIME(event);
event.key_code(),
event.flags());
} }
virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE {
......
...@@ -159,15 +159,9 @@ class MockInputMethodDelegate : public internal::InputMethodDelegate { ...@@ -159,15 +159,9 @@ class MockInputMethodDelegate : public internal::InputMethodDelegate {
} }
private: private:
virtual bool DispatchKeyEventPostIME( virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE {
const base::NativeEvent& native_key_event) OVERRIDE { EXPECT_FALSE(event.HasNativeEvent());
EXPECT_TRUE(false) << "Not reach here"; fabricated_key_events_.push_back(event.key_code());
return true;
}
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) OVERRIDE {
fabricated_key_events_.push_back(key_code);
return true; return true;
} }
......
...@@ -639,6 +639,13 @@ TranslatedKeyEvent::TranslatedKeyEvent(bool is_press, ...@@ -639,6 +639,13 @@ TranslatedKeyEvent::TranslatedKeyEvent(bool is_press,
false) { false) {
} }
TranslatedKeyEvent::TranslatedKeyEvent(const KeyEvent& key_event)
: KeyEvent(key_event) {
SetType(type() == ET_KEY_PRESSED ?
ET_TRANSLATED_KEY_PRESS : ET_TRANSLATED_KEY_RELEASE);
set_is_char(false);
}
void TranslatedKeyEvent::ConvertToKeyEvent() { void TranslatedKeyEvent::ConvertToKeyEvent() {
SetType(type() == ET_TRANSLATED_KEY_PRESS ? SetType(type() == ET_TRANSLATED_KEY_PRESS ?
ET_KEY_PRESSED : ET_KEY_RELEASED); ET_KEY_PRESSED : ET_KEY_RELEASED);
......
...@@ -566,6 +566,10 @@ class EVENTS_EXPORT KeyEvent : public Event { ...@@ -566,6 +566,10 @@ class EVENTS_EXPORT KeyEvent : public Event {
// in http://crbug.com/127142#c8, the normalization is necessary. // in http://crbug.com/127142#c8, the normalization is necessary.
void NormalizeFlags(); void NormalizeFlags();
protected:
// This allows a subclass TranslatedKeyEvent to be a non character event.
void set_is_char(bool is_char) { is_char_ = is_char; }
private: private:
KeyboardCode key_code_; KeyboardCode key_code_;
...@@ -596,6 +600,8 @@ class EVENTS_EXPORT TranslatedKeyEvent : public KeyEvent { ...@@ -596,6 +600,8 @@ class EVENTS_EXPORT TranslatedKeyEvent : public KeyEvent {
// Used for synthetic events such as a VKEY_PROCESSKEY key event. // Used for synthetic events such as a VKEY_PROCESSKEY key event.
TranslatedKeyEvent(bool is_press, KeyboardCode key_code, int flags); TranslatedKeyEvent(bool is_press, KeyboardCode key_code, int flags);
explicit TranslatedKeyEvent(const KeyEvent& key_event);
// Changes the type() of the object from ET_TRANSLATED_KEY_* to ET_KEY_* so // Changes the type() of the object from ET_TRANSLATED_KEY_* to ET_KEY_* so
// that RenderWidgetHostViewAura and NativeWidgetAura could handle the event. // that RenderWidgetHostViewAura and NativeWidgetAura could handle the event.
void ConvertToKeyEvent(); void ConvertToKeyEvent();
......
...@@ -58,21 +58,12 @@ void InputMethodEventFilter::OnKeyEvent(ui::KeyEvent* event) { ...@@ -58,21 +58,12 @@ void InputMethodEventFilter::OnKeyEvent(ui::KeyEvent* event) {
// InputMethodEventFilter, ui::InputMethodDelegate implementation: // InputMethodEventFilter, ui::InputMethodDelegate implementation:
bool InputMethodEventFilter::DispatchKeyEventPostIME( bool InputMethodEventFilter::DispatchKeyEventPostIME(
const base::NativeEvent& event) { const ui::KeyEvent& event) {
#if defined(OS_WIN) #if defined(OS_WIN)
DCHECK(event.message != WM_CHAR); if (DCHECK_IS_ON() && event.HasNativeEvent())
DCHECK_NE(event.native_event().message, static_cast<UINT>(WM_CHAR));
#endif #endif
ui::TranslatedKeyEvent aura_event(event, false /* is_char */); ui::TranslatedKeyEvent aura_event(event);
return target_dispatcher_->AsWindowTreeHostDelegate()->OnHostKeyEvent(
&aura_event);
}
bool InputMethodEventFilter::DispatchFabricatedKeyEventPostIME(
ui::EventType type,
ui::KeyboardCode key_code,
int flags) {
ui::TranslatedKeyEvent aura_event(type == ui::ET_KEY_PRESSED, key_code,
flags);
return target_dispatcher_->AsWindowTreeHostDelegate()->OnHostKeyEvent( return target_dispatcher_->AsWindowTreeHostDelegate()->OnHostKeyEvent(
&aura_event); &aura_event);
} }
......
...@@ -5,13 +5,12 @@ ...@@ -5,13 +5,12 @@
#ifndef UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_ #ifndef UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_
#define UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_ #define UI_VIEWS_COREWM_INPUT_METHOD_EVENT_FILTER_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/input_method_delegate.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace ui { namespace ui {
...@@ -38,11 +37,8 @@ class VIEWS_EXPORT InputMethodEventFilter ...@@ -38,11 +37,8 @@ class VIEWS_EXPORT InputMethodEventFilter
// Overridden from ui::EventHandler: // Overridden from ui::EventHandler:
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
// Overridden from ui::internal::InputMethodDelegate. // Overridden from ui::internal::InputMethodDelegate:
virtual bool DispatchKeyEventPostIME(const base::NativeEvent& event) OVERRIDE; virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE;
virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
ui::KeyboardCode key_code,
int flags) OVERRIDE;
scoped_ptr<ui::InputMethod> input_method_; scoped_ptr<ui::InputMethod> input_method_;
......
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