Chromium Code Reviews| Index: ui/views/ime/input_method_base.cc |
| diff --git a/ui/views/ime/input_method_base.cc b/ui/views/ime/input_method_base.cc |
| index c64ea2da8fd7a118c183b06d686a725a381bf7c7..20e535243dc4b79c5b08dc3cc6e6863294fc51ae 100644 |
| --- a/ui/views/ime/input_method_base.cc |
| +++ b/ui/views/ime/input_method_base.cc |
| @@ -4,29 +4,23 @@ |
| #include "ui/views/ime/input_method_base.h" |
| +#include "base/logging.h" |
| #include "ui/base/events/event.h" |
| #include "ui/base/ime/text_input_client.h" |
| #include "ui/views/view.h" |
| #include "ui/views/widget/widget.h" |
| -#include "base/logging.h" |
| - |
| namespace views { |
| -InputMethodBase::InputMethodBase() |
| - : delegate_(NULL), |
| - widget_(NULL), |
| - widget_focused_(false) { |
| -} |
| +InputMethodBase::InputMethodBase() : delegate_(NULL), widget_(NULL) {} |
| InputMethodBase::~InputMethodBase() { |
| - if (widget_) { |
| - widget_->GetFocusManager()->RemoveFocusChangeListener(this); |
| - widget_ = NULL; |
| - } |
| + if (widget()) |
|
sky
2013/03/27 15:10:23
Is this needed? You don't null check widget any wh
msw
2013/03/27 17:36:25
Done; I removed the check, but will restore it if
|
| + widget()->GetFocusManager()->RemoveFocusChangeListener(this); |
| + widget_ = NULL; |
| } |
| -void InputMethodBase::set_delegate(internal::InputMethodDelegate* delegate) { |
| +void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { |
| DCHECK(delegate); |
| delegate_ = delegate; |
| } |
| @@ -34,38 +28,24 @@ void InputMethodBase::set_delegate(internal::InputMethodDelegate* delegate) { |
| void InputMethodBase::Init(Widget* widget) { |
| DCHECK(widget); |
| DCHECK(widget->GetFocusManager()); |
| - |
| - if (widget_) { |
| - NOTREACHED() << "The input method is already initialized."; |
| - return; |
| - } |
| + DCHECK(!widget_) << "The input method is already initialized."; |
| widget_ = widget; |
| - // The InputMethod is lazily created, so we need to tell it the currently |
| - // focused view. |
| + // Alert the InputMethod of the Widget's currently focused view. |
| View* focused = widget->GetFocusManager()->GetFocusedView(); |
| if (focused) |
| OnWillChangeFocus(NULL, focused); |
| widget->GetFocusManager()->AddFocusChangeListener(this); |
| } |
| -void InputMethodBase::OnFocus() { |
| - widget_focused_ = true; |
| -} |
| - |
| -void InputMethodBase::OnBlur() { |
| - widget_focused_ = false; |
| -} |
| - |
| views::View* InputMethodBase::GetFocusedView() const { |
| - return widget_->GetFocusManager()->GetFocusedView(); |
| + return widget()->GetFocusManager()->GetFocusedView(); |
| } |
| -void InputMethodBase::OnTextInputTypeChanged(View* view) { |
| -} |
| +void InputMethodBase::OnTextInputTypeChanged(View* view) {} |
| ui::TextInputClient* InputMethodBase::GetTextInputClient() const { |
| - return (widget_focused_ && GetFocusedView()) ? |
| + return (widget()->IsActive() && GetFocusedView()) ? |
| GetFocusedView()->GetTextInputClient() : NULL; |
| } |
| @@ -78,14 +58,12 @@ bool InputMethodBase::IsMock() const { |
| return false; |
| } |
| -void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) { |
| -} |
| +void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) {} |
| -void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) { |
| -} |
| +void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) {} |
| bool InputMethodBase::IsViewFocused(View* view) const { |
| - return widget_focused_ && view && GetFocusedView() == view; |
| + return widget()->IsActive() && view && GetFocusedView() == view; |
| } |
| bool InputMethodBase::IsTextInputTypeNone() const { |
| @@ -111,10 +89,9 @@ bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { |
| *rect = GetFocusedView()->ConvertRectToWidget(client->GetCaretBounds()); |
| - // We need to do coordinate conversion if the focused view is inside a child |
| - // Widget. |
| - if (GetFocusedView()->GetWidget() != widget_) |
| - return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect); |
| + // Convert coordinates if the focused view is inside a child Widget. |
| + if (GetFocusedView()->GetWidget() != widget()) |
| + return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget(), rect); |
| return true; |
| } |