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