Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "views/ime/input_method_base.h" | 5 #include "views/ime/input_method_base.h" |
| 6 #include "views/view.h" | 6 #include "views/view.h" |
| 7 #include "views/widget/widget.h" | 7 #include "views/widget/widget.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 void InputMethodBase::Init(Widget* widget) { | 32 void InputMethodBase::Init(Widget* widget) { |
| 33 DCHECK(widget); | 33 DCHECK(widget); |
| 34 DCHECK(widget->GetFocusManager()); | 34 DCHECK(widget->GetFocusManager()); |
| 35 | 35 |
| 36 if (widget_) { | 36 if (widget_) { |
| 37 NOTREACHED() << "The input method is already initialized."; | 37 NOTREACHED() << "The input method is already initialized."; |
| 38 return; | 38 return; |
| 39 } | 39 } |
| 40 | 40 |
| 41 widget_ = widget; | 41 widget_ = widget; |
| 42 View* focused = widget->GetFocusManager()->GetFocusedView(); | |
| 43 if (focused) { | |
| 44 OnFocus(); | |
| 45 FocusWillChange(NULL, focused); | |
| 46 } | |
|
sadrul
2011/06/22 01:47:21
I think this seeped through from 7222007?
| |
| 42 widget->GetFocusManager()->AddFocusChangeListener(this); | 47 widget->GetFocusManager()->AddFocusChangeListener(this); |
| 43 } | 48 } |
| 44 | 49 |
| 45 void InputMethodBase::OnFocus() { | 50 void InputMethodBase::OnFocus() { |
| 46 widget_focused_ = true; | 51 widget_focused_ = true; |
| 47 } | 52 } |
| 48 | 53 |
| 49 void InputMethodBase::OnBlur() { | 54 void InputMethodBase::OnBlur() { |
| 50 widget_focused_ = false; | 55 widget_focused_ = false; |
| 51 } | 56 } |
| 52 | 57 |
| 58 void InputMethodBase::OnTextInputTypeChanged(View* view) { | |
| 59 if (view == focused_view()) | |
|
sadrul
2011/06/22 01:47:21
Is there a difference between checking 'view == fo
| |
| 60 TextInputTypeChanged(focused_view()); | |
| 61 } | |
| 62 | |
| 53 TextInputClient* InputMethodBase::GetTextInputClient() const { | 63 TextInputClient* InputMethodBase::GetTextInputClient() const { |
| 54 return (widget_focused_ && focused_view_) ? | 64 return (widget_focused_ && focused_view_) ? |
| 55 focused_view_->GetTextInputClient() : NULL; | 65 focused_view_->GetTextInputClient() : NULL; |
| 56 } | 66 } |
| 57 | 67 |
| 58 ui::TextInputType InputMethodBase::GetTextInputType() const { | 68 ui::TextInputType InputMethodBase::GetTextInputType() const { |
| 59 TextInputClient* client = GetTextInputClient(); | 69 TextInputClient* client = GetTextInputClient(); |
| 60 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 70 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
| 61 } | 71 } |
| 62 | 72 |
| 63 void InputMethodBase::FocusWillChange(View* focused_before, View* focused) { | 73 void InputMethodBase::FocusWillChange(View* focused_before, View* focused) { |
| 64 DCHECK_EQ(focused_view_, focused_before); | 74 DCHECK_EQ(focused_view_, focused_before); |
| 65 FocusedViewWillChange(); | 75 FocusedViewWillChange(); |
| 66 focused_view_ = focused; | 76 focused_view_ = focused; |
| 67 FocusedViewDidChange(); | 77 FocusedViewDidChange(); |
| 78 TextInputTypeChanged(focused_view()); | |
|
James Su
2011/06/22 03:05:15
Changing focus may not necessarily cause text inpu
Peng
2011/06/22 04:17:39
Probably the name is not good. It not only notify
James Su
2011/06/22 07:33:28
IMHO, the current text input type is the only stat
| |
| 68 } | 79 } |
| 69 | 80 |
| 70 bool InputMethodBase::IsViewFocused(View* view) const { | 81 bool InputMethodBase::IsViewFocused(View* view) const { |
| 71 return widget_focused_ && view && focused_view_ == view; | 82 return widget_focused_ && view && focused_view_ == view; |
| 72 } | 83 } |
| 73 | 84 |
| 74 bool InputMethodBase::IsTextInputTypeNone() const { | 85 bool InputMethodBase::IsTextInputTypeNone() const { |
| 75 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; | 86 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; |
| 76 } | 87 } |
| 77 | 88 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 108 return true; | 119 return true; |
| 109 } | 120 } |
| 110 | 121 |
| 111 void InputMethodBase::FocusedViewWillChange() { | 122 void InputMethodBase::FocusedViewWillChange() { |
| 112 } | 123 } |
| 113 | 124 |
| 114 void InputMethodBase::FocusedViewDidChange() { | 125 void InputMethodBase::FocusedViewDidChange() { |
| 115 } | 126 } |
| 116 | 127 |
| 117 } // namespace views | 128 } // namespace views |
| OLD | NEW |