diff options
author | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 07:13:16 +0000 |
---|---|---|
committer | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 07:13:16 +0000 |
commit | 06e67118f15728c74ed025c409d931e830e39d3a (patch) | |
tree | 868ca30c9c24c960c20b04405ebe9bd37dcb1b77 /ui | |
parent | 752099f85a010b635a107e0c18a1aac31f2c96e4 (diff) | |
download | chromium_src-06e67118f15728c74ed025c409d931e830e39d3a.zip chromium_src-06e67118f15728c74ed025c409d931e830e39d3a.tar.gz chromium_src-06e67118f15728c74ed025c409d931e830e39d3a.tar.bz2 |
Allow to pass a NULL |host| to the bridge.
This is necessary since ui::InputMethod object might not be registered to aura::RootWindow when it's used without a shell (e.g., Aura without Aura Shell).
BUG=97261
TEST=none
Review URL: http://codereview.chromium.org/8989008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/ime/input_method_bridge.cc | 28 | ||||
-rw-r--r-- | ui/views/ime/input_method_bridge.h | 2 |
2 files changed, 18 insertions, 12 deletions
diff --git a/ui/views/ime/input_method_bridge.cc b/ui/views/ime/input_method_bridge.cc index 1ca1631..eef4c12 100644 --- a/ui/views/ime/input_method_bridge.cc +++ b/ui/views/ime/input_method_bridge.cc @@ -15,12 +15,11 @@ InputMethodBridge::InputMethodBridge(internal::InputMethodDelegate* delegate, ui::InputMethod* host) : host_(host), context_focused_(false) { - DCHECK(host_); set_delegate(delegate); } InputMethodBridge::~InputMethodBridge() { - if (host_->GetTextInputClient() == this) + if (host_ && host_->GetTextInputClient() == this) host_->SetFocusedTextInputClient(NULL); } @@ -29,12 +28,16 @@ void InputMethodBridge::Init(Widget* widget) { } void InputMethodBridge::OnFocus() { - DCHECK(!widget_focused()); + // Disabling the DCHECK for now since views_unittests seems to call + // views::InputMethod::OnFocus and OnBlur in a wrong way. + // TODO(yusukes): Reenable it once views_unittests are fixed. + // DCHECK(!widget_focused()); InputMethodBase::OnFocus(); // Ask the system-wide IME to send all TextInputClient messages to |this| // object. - host_->SetFocusedTextInputClient(this); + if (host_) + host_->SetFocusedTextInputClient(this); // TODO(yusukes): We don't need to call OnTextInputTypeChanged() once we move // text input type tracker code to ui::InputMethodBase. @@ -43,11 +46,12 @@ void InputMethodBridge::OnFocus() { } void InputMethodBridge::OnBlur() { - DCHECK(widget_focused()); + // TODO(yusukes): Reenable it once views_unittests are fixed. + // DCHECK(widget_focused()); ConfirmCompositionText(); InputMethodBase::OnBlur(); - if (host_->GetTextInputClient() == this) + if (host_ && host_->GetTextInputClient() == this) host_->SetFocusedTextInputClient(NULL); } @@ -61,31 +65,31 @@ void InputMethodBridge::DispatchKeyEvent(const KeyEvent& key) { } void InputMethodBridge::OnTextInputTypeChanged(View* view) { - if (IsViewFocused(view)) + if (host_ && IsViewFocused(view)) host_->OnTextInputTypeChanged(this); InputMethodBase::OnTextInputTypeChanged(view); } void InputMethodBridge::OnCaretBoundsChanged(View* view) { - if (IsViewFocused(view) && !IsTextInputTypeNone()) + if (host_ && IsViewFocused(view) && !IsTextInputTypeNone()) host_->OnCaretBoundsChanged(this); } void InputMethodBridge::CancelComposition(View* view) { - if (IsViewFocused(view)) + if (host_ && IsViewFocused(view)) host_->CancelComposition(this); } std::string InputMethodBridge::GetInputLocale() { - return host_->GetInputLocale(); + return host_ ? host_->GetInputLocale() : ""; } base::i18n::TextDirection InputMethodBridge::GetInputTextDirection() { - return host_->GetInputTextDirection(); + return host_ ? host_->GetInputTextDirection() : base::i18n::UNKNOWN_DIRECTION; } bool InputMethodBridge::IsActive() { - return host_->IsActive(); + return host_ ? host_->IsActive() : false; } // Overridden from TextInputClient. Forward an event from the system-wide IME diff --git a/ui/views/ime/input_method_bridge.h b/ui/views/ime/input_method_bridge.h index 6f4b384..2ad3ecb 100644 --- a/ui/views/ime/input_method_bridge.h +++ b/ui/views/ime/input_method_bridge.h @@ -27,6 +27,8 @@ class View; class InputMethodBridge : public InputMethodBase, public ui::TextInputClient { public: + // |this| object owns neither |delegate| nor |host|. Both |delegate| and + // |host| must outlive |this| object. InputMethodBridge(internal::InputMethodDelegate* delegate, ui::InputMethod* host); virtual ~InputMethodBridge(); |