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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 GetTextInputType(), widget_); | 59 GetTextInputType(), widget_); |
59 } | 60 } |
60 | 61 |
61 void InputMethodBase::OnTextInputTypeChanged(View* view) { | 62 void InputMethodBase::OnTextInputTypeChanged(View* view) { |
62 if (IsViewFocused(view)) { | 63 if (IsViewFocused(view)) { |
63 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | 64 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( |
64 GetTextInputType(), widget_); | 65 GetTextInputType(), widget_); |
65 } | 66 } |
66 } | 67 } |
67 | 68 |
68 TextInputClient* InputMethodBase::GetTextInputClient() const { | 69 ui::TextInputClient* InputMethodBase::GetTextInputClient() const { |
69 return (widget_focused_ && focused_view_) ? | 70 return (widget_focused_ && focused_view_) ? |
70 focused_view_->GetTextInputClient() : NULL; | 71 focused_view_->GetTextInputClient() : NULL; |
71 } | 72 } |
72 | 73 |
73 ui::TextInputType InputMethodBase::GetTextInputType() const { | 74 ui::TextInputType InputMethodBase::GetTextInputType() const { |
74 TextInputClient* client = GetTextInputClient(); | 75 ui::TextInputClient* client = GetTextInputClient(); |
75 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 76 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
76 } | 77 } |
77 | 78 |
78 bool InputMethodBase::IsMock() const { | 79 bool InputMethodBase::IsMock() const { |
79 return false; | 80 return false; |
80 } | 81 } |
81 | 82 |
82 void InputMethodBase::FocusWillChange(View* focused_before, View* focused) { | 83 void InputMethodBase::FocusWillChange(View* focused_before, View* focused) { |
83 DCHECK_EQ(focused_view_, focused_before); | 84 DCHECK_EQ(focused_view_, focused_before); |
84 FocusedViewWillChange(); | 85 FocusedViewWillChange(); |
85 focused_view_ = focused; | 86 focused_view_ = focused; |
86 FocusedViewDidChange(); | 87 FocusedViewDidChange(); |
87 | 88 |
88 if (widget_focused_) { | 89 if (widget_focused_) { |
89 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | 90 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( |
90 GetTextInputType(), widget_); | 91 GetTextInputType(), widget_); |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 bool InputMethodBase::IsViewFocused(View* view) const { | 95 bool InputMethodBase::IsViewFocused(View* view) const { |
95 return widget_focused_ && view && focused_view_ == view; | 96 return widget_focused_ && view && focused_view_ == view; |
96 } | 97 } |
97 | 98 |
98 bool InputMethodBase::IsTextInputTypeNone() const { | 99 bool InputMethodBase::IsTextInputTypeNone() const { |
99 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; | 100 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; |
100 } | 101 } |
101 | 102 |
102 void InputMethodBase::OnInputMethodChanged() const { | 103 void InputMethodBase::OnInputMethodChanged() const { |
103 TextInputClient* client = GetTextInputClient(); | 104 ui::TextInputClient* client = GetTextInputClient(); |
104 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) | 105 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) |
105 client->OnInputMethodChanged(); | 106 client->OnInputMethodChanged(); |
106 } | 107 } |
107 | 108 |
108 void InputMethodBase::DispatchKeyEventPostIME(const KeyEvent& key) const { | 109 void InputMethodBase::DispatchKeyEventPostIME(const KeyEvent& key) const { |
109 if (delegate_) | 110 if (delegate_) |
110 delegate_->DispatchKeyEventPostIME(key); | 111 delegate_->DispatchKeyEventPostIME(key); |
111 } | 112 } |
112 | 113 |
113 bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { | 114 bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { |
114 DCHECK(rect); | 115 DCHECK(rect); |
115 TextInputClient* client = GetTextInputClient(); | 116 ui::TextInputClient* client = GetTextInputClient(); |
116 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 117 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
117 return false; | 118 return false; |
118 | 119 |
119 *rect = focused_view_->ConvertRectToWidget(client->GetCaretBounds()); | 120 *rect = focused_view_->ConvertRectToWidget(client->GetCaretBounds()); |
120 | 121 |
121 // We need to do coordinate conversion if the focused view is inside a child | 122 // We need to do coordinate conversion if the focused view is inside a child |
122 // Widget. | 123 // Widget. |
123 if (focused_view_->GetWidget() != widget_) | 124 if (focused_view_->GetWidget() != widget_) |
124 return Widget::ConvertRect(focused_view_->GetWidget(), widget_, rect); | 125 return Widget::ConvertRect(focused_view_->GetWidget(), widget_, rect); |
125 return true; | 126 return true; |
126 } | 127 } |
127 | 128 |
128 void InputMethodBase::FocusedViewWillChange() { | 129 void InputMethodBase::FocusedViewWillChange() { |
129 } | 130 } |
130 | 131 |
131 void InputMethodBase::FocusedViewDidChange() { | 132 void InputMethodBase::FocusedViewDidChange() { |
132 } | 133 } |
133 | 134 |
134 } // namespace views | 135 } // namespace views |
OLD | NEW |