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 "ui/base/ime/text_input_client.h" |
6 #include "ui/views/ime/input_method_base.h" | 6 #include "ui/views/ime/input_method_base.h" |
7 #include "ui/views/ime/text_input_type_tracker.h" | |
8 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
9 #include "ui/views/widget/widget.h" | 8 #include "ui/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() |
16 : delegate_(NULL), | 15 : delegate_(NULL), |
17 widget_(NULL), | 16 widget_(NULL), |
(...skipping 25 matching lines...) Expand all Loading... |
43 // The InputMethod is lazily created, so we need to tell it the currently | 42 // The InputMethod is lazily created, so we need to tell it the currently |
44 // focused view. | 43 // focused view. |
45 View* focused = widget->GetFocusManager()->GetFocusedView(); | 44 View* focused = widget->GetFocusManager()->GetFocusedView(); |
46 if (focused) | 45 if (focused) |
47 OnWillChangeFocus(NULL, focused); | 46 OnWillChangeFocus(NULL, focused); |
48 widget->GetFocusManager()->AddFocusChangeListener(this); | 47 widget->GetFocusManager()->AddFocusChangeListener(this); |
49 } | 48 } |
50 | 49 |
51 void InputMethodBase::OnFocus() { | 50 void InputMethodBase::OnFocus() { |
52 widget_focused_ = true; | 51 widget_focused_ = true; |
53 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | |
54 GetTextInputType(), widget_); | |
55 } | 52 } |
56 | 53 |
57 void InputMethodBase::OnBlur() { | 54 void InputMethodBase::OnBlur() { |
58 widget_focused_ = false; | 55 widget_focused_ = false; |
59 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | |
60 GetTextInputType(), widget_); | |
61 } | 56 } |
62 | 57 |
63 views::View* InputMethodBase::GetFocusedView() const { | 58 views::View* InputMethodBase::GetFocusedView() const { |
64 return widget_->GetFocusManager()->GetFocusedView(); | 59 return widget_->GetFocusManager()->GetFocusedView(); |
65 } | 60 } |
66 | 61 |
67 void InputMethodBase::OnTextInputTypeChanged(View* view) { | 62 void InputMethodBase::OnTextInputTypeChanged(View* view) { |
68 if (IsViewFocused(view)) { | |
69 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | |
70 GetTextInputType(), widget_); | |
71 } | |
72 } | 63 } |
73 | 64 |
74 ui::TextInputClient* InputMethodBase::GetTextInputClient() const { | 65 ui::TextInputClient* InputMethodBase::GetTextInputClient() const { |
75 return (widget_focused_ && GetFocusedView()) ? | 66 return (widget_focused_ && GetFocusedView()) ? |
76 GetFocusedView()->GetTextInputClient() : NULL; | 67 GetFocusedView()->GetTextInputClient() : NULL; |
77 } | 68 } |
78 | 69 |
79 ui::TextInputType InputMethodBase::GetTextInputType() const { | 70 ui::TextInputType InputMethodBase::GetTextInputType() const { |
80 ui::TextInputClient* client = GetTextInputClient(); | 71 ui::TextInputClient* client = GetTextInputClient(); |
81 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 72 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
82 } | 73 } |
83 | 74 |
84 bool InputMethodBase::IsMock() const { | 75 bool InputMethodBase::IsMock() const { |
85 return false; | 76 return false; |
86 } | 77 } |
87 | 78 |
88 void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) { | 79 void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) { |
89 } | 80 } |
90 | 81 |
91 void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) { | 82 void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) { |
92 if (widget_focused_) { | |
93 TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( | |
94 GetTextInputType(), widget_); | |
95 } | |
96 } | 83 } |
97 | 84 |
98 bool InputMethodBase::IsViewFocused(View* view) const { | 85 bool InputMethodBase::IsViewFocused(View* view) const { |
99 return widget_focused_ && view && GetFocusedView() == view; | 86 return widget_focused_ && view && GetFocusedView() == view; |
100 } | 87 } |
101 | 88 |
102 bool InputMethodBase::IsTextInputTypeNone() const { | 89 bool InputMethodBase::IsTextInputTypeNone() const { |
103 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; | 90 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE; |
104 } | 91 } |
105 | 92 |
(...skipping 17 matching lines...) Expand all Loading... |
123 *rect = GetFocusedView()->ConvertRectToWidget(client->GetCaretBounds()); | 110 *rect = GetFocusedView()->ConvertRectToWidget(client->GetCaretBounds()); |
124 | 111 |
125 // We need to do coordinate conversion if the focused view is inside a child | 112 // We need to do coordinate conversion if the focused view is inside a child |
126 // Widget. | 113 // Widget. |
127 if (GetFocusedView()->GetWidget() != widget_) | 114 if (GetFocusedView()->GetWidget() != widget_) |
128 return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect); | 115 return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect); |
129 return true; | 116 return true; |
130 } | 117 } |
131 | 118 |
132 } // namespace views | 119 } // namespace views |
OLD | NEW |