OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/views/controls/prefix_selector.h" | 5 #include "ui/views/controls/prefix_selector.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "ui/base/ime/input_method.h" |
8 #include "ui/base/ime/text_input_type.h" | 9 #include "ui/base/ime/text_input_type.h" |
9 #include "ui/gfx/range/range.h" | 10 #include "ui/gfx/range/range.h" |
10 #include "ui/views/controls/prefix_delegate.h" | 11 #include "ui/views/controls/prefix_delegate.h" |
11 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 const int64 kTimeBeforeClearingMS = 1000; | 18 const int64 kTimeBeforeClearingMS = 1000; |
18 | 19 |
19 void ConvertRectToScreen(const views::View* src, gfx::Rect* r) { | 20 void ConvertRectToScreen(const views::View* src, gfx::Rect* r) { |
20 DCHECK(src); | 21 DCHECK(src); |
21 | 22 |
22 gfx::Point new_origin = r->origin(); | 23 gfx::Point new_origin = r->origin(); |
23 views::View::ConvertPointToScreen(src, &new_origin); | 24 views::View::ConvertPointToScreen(src, &new_origin); |
24 r->set_origin(new_origin); | 25 r->set_origin(new_origin); |
25 } | 26 } |
26 | 27 |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 PrefixSelector::PrefixSelector(PrefixDelegate* delegate) | 30 PrefixSelector::PrefixSelector(PrefixDelegate* delegate) |
30 : prefix_delegate_(delegate) { | 31 : prefix_delegate_(delegate) { |
31 } | 32 } |
32 | 33 |
33 PrefixSelector::~PrefixSelector() { | 34 PrefixSelector::~PrefixSelector() { |
| 35 ui::InputMethod* input_method = prefix_delegate_->GetInputMethod(); |
| 36 if (input_method) |
| 37 input_method->DetachTextInputClient(this); |
34 } | 38 } |
35 | 39 |
36 void PrefixSelector::OnViewBlur() { | 40 void PrefixSelector::OnViewBlur() { |
37 ClearText(); | 41 ClearText(); |
38 } | 42 } |
39 | 43 |
40 void PrefixSelector::SetCompositionText( | 44 void PrefixSelector::SetCompositionText( |
41 const ui::CompositionText& composition) { | 45 const ui::CompositionText& composition) { |
42 } | 46 } |
43 | 47 |
44 void PrefixSelector::ConfirmCompositionText() { | 48 void PrefixSelector::ConfirmCompositionText() { |
45 } | 49 } |
46 | 50 |
47 void PrefixSelector::ClearCompositionText() { | 51 void PrefixSelector::ClearCompositionText() { |
48 } | 52 } |
49 | 53 |
50 void PrefixSelector::InsertText(const base::string16& text) { | 54 void PrefixSelector::InsertText(const base::string16& text) { |
51 OnTextInput(text); | 55 OnTextInput(text); |
52 } | 56 } |
53 | 57 |
54 void PrefixSelector::InsertChar(base::char16 ch, int flags) { | 58 void PrefixSelector::InsertChar(base::char16 ch, int flags) { |
55 OnTextInput(base::string16(1, ch)); | 59 OnTextInput(base::string16(1, ch)); |
56 } | 60 } |
57 | 61 |
58 gfx::NativeWindow PrefixSelector::GetAttachedWindow() const { | |
59 return prefix_delegate_->GetWidget()->GetNativeWindow(); | |
60 } | |
61 | |
62 ui::TextInputType PrefixSelector::GetTextInputType() const { | 62 ui::TextInputType PrefixSelector::GetTextInputType() const { |
63 return ui::TEXT_INPUT_TYPE_TEXT; | 63 return ui::TEXT_INPUT_TYPE_TEXT; |
64 } | 64 } |
65 | 65 |
66 ui::TextInputMode PrefixSelector::GetTextInputMode() const { | 66 ui::TextInputMode PrefixSelector::GetTextInputMode() const { |
67 return ui::TEXT_INPUT_MODE_DEFAULT; | 67 return ui::TEXT_INPUT_MODE_DEFAULT; |
68 } | 68 } |
69 | 69 |
70 int PrefixSelector::GetTextInputFlags() const { | 70 int PrefixSelector::GetTextInputFlags() const { |
71 return 0; | 71 return 0; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return (model_text.size() >= lower_text.size()) && | 190 return (model_text.size() >= lower_text.size()) && |
191 (model_text.compare(0, lower_text.size(), lower_text) == 0); | 191 (model_text.compare(0, lower_text.size(), lower_text) == 0); |
192 } | 192 } |
193 | 193 |
194 void PrefixSelector::ClearText() { | 194 void PrefixSelector::ClearText() { |
195 current_text_.clear(); | 195 current_text_.clear(); |
196 time_of_last_key_ = base::TimeTicks(); | 196 time_of_last_key_ = base::TimeTicks(); |
197 } | 197 } |
198 | 198 |
199 } // namespace views | 199 } // namespace views |
OLD | NEW |