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