| 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 "ui/base/ime/text_input_client.h" |
| 5 #include "views/ime/input_method_base.h" | 6 #include "views/ime/input_method_base.h" |
| 6 #include "views/ime/text_input_type_tracker.h" | 7 #include "views/ime/text_input_type_tracker.h" |
| 7 #include "views/view.h" | 8 #include "views/view.h" |
| 8 #include "views/widget/widget.h" | 9 #include "views/widget/widget.h" |
| 9 | 10 |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 | 12 |
| 12 namespace views { | 13 namespace views { |
| 13 | 14 |
| 14 InputMethodBase::InputMethodBase() | 15 InputMethodBase::InputMethodBase() |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return widget_->GetFocusManager()->GetFocusedView(); | 64 return widget_->GetFocusManager()->GetFocusedView(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void InputMethodBase::OnTextInputTypeChanged(View* view) { | 67 void InputMethodBase::OnTextInputTypeChanged(View* view) { |
| 67 if (IsViewFocused(view)) { | 68 if (IsViewFocused(view)) { |
| 68 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | 69 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( |
| 69 GetTextInputType(), widget_); | 70 GetTextInputType(), widget_); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 TextInputClient* InputMethodBase::GetTextInputClient() const { | 74 ui::TextInputClient* InputMethodBase::GetTextInputClient() const { |
| 74 return (widget_focused_ && GetFocusedView()) ? | 75 return (widget_focused_ && GetFocusedView()) ? |
| 75 GetFocusedView()->GetTextInputClient() : NULL; | 76 GetFocusedView()->GetTextInputClient() : NULL; |
| 76 } | 77 } |
| 77 | 78 |
| 78 ui::TextInputType InputMethodBase::GetTextInputType() const { | 79 ui::TextInputType InputMethodBase::GetTextInputType() const { |
| 79 TextInputClient* client = GetTextInputClient(); | 80 ui::TextInputClient* client = GetTextInputClient(); |
| 80 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 81 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool InputMethodBase::IsMock() const { | 84 bool InputMethodBase::IsMock() const { |
| 84 return false; | 85 return false; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) { | 88 void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) { |
| 88 } | 89 } |
| 89 | 90 |
| 90 void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) { | 91 void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) { |
| 91 if (widget_focused_) { | 92 if (widget_focused_) { |
| 92 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | 93 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( |
| 93 GetTextInputType(), widget_); | 94 GetTextInputType(), widget_); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool InputMethodBase::IsViewFocused(View* view) const { | 98 bool InputMethodBase::IsViewFocused(View* view) const { |
| 98 return widget_focused_ && view && GetFocusedView() == view; | 99 return widget_focused_ && view && GetFocusedView() == view; |
| 99 } | 100 } |
| 100 | 101 |
| 101 bool InputMethodBase::IsTextInputTypeNone() const { | 102 bool InputMethodBase::IsTextInputTypeNone() const { |
| 102 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; | 103 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; |
| 103 } | 104 } |
| 104 | 105 |
| 105 void InputMethodBase::OnInputMethodChanged() const { | 106 void InputMethodBase::OnInputMethodChanged() const { |
| 106 TextInputClient* client = GetTextInputClient(); | 107 ui::TextInputClient* client = GetTextInputClient(); |
| 107 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) | 108 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) |
| 108 client->OnInputMethodChanged(); | 109 client->OnInputMethodChanged(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void InputMethodBase::DispatchKeyEventPostIME(const KeyEvent& key) const { | 112 void InputMethodBase::DispatchKeyEventPostIME(const KeyEvent& key) const { |
| 112 if (delegate_) | 113 if (delegate_) |
| 113 delegate_->DispatchKeyEventPostIME(key); | 114 delegate_->DispatchKeyEventPostIME(key); |
| 114 } | 115 } |
| 115 | 116 |
| 116 bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { | 117 bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { |
| 117 DCHECK(rect); | 118 DCHECK(rect); |
| 118 TextInputClient* client = GetTextInputClient(); | 119 ui::TextInputClient* client = GetTextInputClient(); |
| 119 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 120 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 120 return false; | 121 return false; |
| 121 | 122 |
| 122 *rect = GetFocusedView()->ConvertRectToWidget(client->GetCaretBounds()); | 123 *rect = GetFocusedView()->ConvertRectToWidget(client->GetCaretBounds()); |
| 123 | 124 |
| 124 // We need to do coordinate conversion if the focused view is inside a child | 125 // We need to do coordinate conversion if the focused view is inside a child |
| 125 // Widget. | 126 // Widget. |
| 126 if (GetFocusedView()->GetWidget() != widget_) | 127 if (GetFocusedView()->GetWidget() != widget_) |
| 127 return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect); | 128 return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect); |
| 128 return true; | 129 return true; |
| 129 } | 130 } |
| 130 } // namespace views | 131 } // namespace views |
| OLD | NEW |