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/views/ime/input_method_bridge.h" | 5 #include "ui/views/ime/input_method_bridge.h" |
6 | 6 |
7 #include "ui/base/ime/input_method.h" | 7 #include "ui/base/ime/input_method.h" |
8 #include "ui/gfx/rect.h" | 8 #include "ui/gfx/rect.h" |
9 #include "ui/views/view.h" | 9 #include "ui/views/view.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
11 | 11 |
12 namespace views { | 12 namespace views { |
13 | 13 |
14 InputMethodBridge::InputMethodBridge(internal::InputMethodDelegate* delegate, | 14 InputMethodBridge::InputMethodBridge(internal::InputMethodDelegate* delegate, |
15 ui::InputMethod* host) | 15 ui::InputMethod* host) |
16 : host_(host), | 16 : host_(host), |
17 context_focused_(false) { | 17 context_focused_(false) { |
18 DCHECK(host_); | |
19 set_delegate(delegate); | 18 set_delegate(delegate); |
20 } | 19 } |
21 | 20 |
22 InputMethodBridge::~InputMethodBridge() { | 21 InputMethodBridge::~InputMethodBridge() { |
23 if (host_->GetTextInputClient() == this) | 22 if (host_ && host_->GetTextInputClient() == this) |
Ben Goodger (Google)
2011/12/20 21:02:02
so, if host_ is set in the ctor, and, per your doc
Yusuke Sato
2011/12/21 16:57:27
For Chrome with the aura_shell, the checks are not
| |
24 host_->SetFocusedTextInputClient(NULL); | 23 host_->SetFocusedTextInputClient(NULL); |
25 } | 24 } |
26 | 25 |
27 void InputMethodBridge::Init(Widget* widget) { | 26 void InputMethodBridge::Init(Widget* widget) { |
28 InputMethodBase::Init(widget); | 27 InputMethodBase::Init(widget); |
29 } | 28 } |
30 | 29 |
31 void InputMethodBridge::OnFocus() { | 30 void InputMethodBridge::OnFocus() { |
32 DCHECK(!widget_focused()); | 31 // Disabling the DCHECK for now since views_unittests seems to call |
32 // views::InputMethod::OnFocus and OnBlur in a wrong way. | |
33 // TODO(yusukes): Reenable it once views_unittests are fixed. | |
34 // DCHECK(!widget_focused()); | |
33 InputMethodBase::OnFocus(); | 35 InputMethodBase::OnFocus(); |
34 | 36 |
35 // Ask the system-wide IME to send all TextInputClient messages to |this| | 37 // Ask the system-wide IME to send all TextInputClient messages to |this| |
36 // object. | 38 // object. |
37 host_->SetFocusedTextInputClient(this); | 39 if (host_) |
40 host_->SetFocusedTextInputClient(this); | |
38 | 41 |
39 // TODO(yusukes): We don't need to call OnTextInputTypeChanged() once we move | 42 // TODO(yusukes): We don't need to call OnTextInputTypeChanged() once we move |
40 // text input type tracker code to ui::InputMethodBase. | 43 // text input type tracker code to ui::InputMethodBase. |
41 if (GetFocusedView()) | 44 if (GetFocusedView()) |
42 OnTextInputTypeChanged(GetFocusedView()); | 45 OnTextInputTypeChanged(GetFocusedView()); |
43 } | 46 } |
44 | 47 |
45 void InputMethodBridge::OnBlur() { | 48 void InputMethodBridge::OnBlur() { |
46 DCHECK(widget_focused()); | 49 // TODO(yusukes): Reenable it once views_unittests are fixed. |
50 // DCHECK(widget_focused()); | |
47 | 51 |
48 ConfirmCompositionText(); | 52 ConfirmCompositionText(); |
49 InputMethodBase::OnBlur(); | 53 InputMethodBase::OnBlur(); |
50 if (host_->GetTextInputClient() == this) | 54 if (host_ && host_->GetTextInputClient() == this) |
51 host_->SetFocusedTextInputClient(NULL); | 55 host_->SetFocusedTextInputClient(NULL); |
52 } | 56 } |
53 | 57 |
54 void InputMethodBridge::DispatchKeyEvent(const KeyEvent& key) { | 58 void InputMethodBridge::DispatchKeyEvent(const KeyEvent& key) { |
55 DCHECK(key.type() == ui::ET_KEY_PRESSED || key.type() == ui::ET_KEY_RELEASED); | 59 DCHECK(key.type() == ui::ET_KEY_PRESSED || key.type() == ui::ET_KEY_RELEASED); |
56 DCHECK(widget_focused()); | 60 DCHECK(widget_focused()); |
57 | 61 |
58 // We can just dispatch the event here since the |key| is already processed by | 62 // We can just dispatch the event here since the |key| is already processed by |
59 // the system-wide IME. | 63 // the system-wide IME. |
60 DispatchKeyEventPostIME(key); | 64 DispatchKeyEventPostIME(key); |
61 } | 65 } |
62 | 66 |
63 void InputMethodBridge::OnTextInputTypeChanged(View* view) { | 67 void InputMethodBridge::OnTextInputTypeChanged(View* view) { |
64 if (IsViewFocused(view)) | 68 if (host_ && IsViewFocused(view)) |
65 host_->OnTextInputTypeChanged(this); | 69 host_->OnTextInputTypeChanged(this); |
66 InputMethodBase::OnTextInputTypeChanged(view); | 70 InputMethodBase::OnTextInputTypeChanged(view); |
67 } | 71 } |
68 | 72 |
69 void InputMethodBridge::OnCaretBoundsChanged(View* view) { | 73 void InputMethodBridge::OnCaretBoundsChanged(View* view) { |
70 if (IsViewFocused(view) && !IsTextInputTypeNone()) | 74 if (host_ && IsViewFocused(view) && !IsTextInputTypeNone()) |
71 host_->OnCaretBoundsChanged(this); | 75 host_->OnCaretBoundsChanged(this); |
72 } | 76 } |
73 | 77 |
74 void InputMethodBridge::CancelComposition(View* view) { | 78 void InputMethodBridge::CancelComposition(View* view) { |
75 if (IsViewFocused(view)) | 79 if (host_ && IsViewFocused(view)) |
76 host_->CancelComposition(this); | 80 host_->CancelComposition(this); |
77 } | 81 } |
78 | 82 |
79 std::string InputMethodBridge::GetInputLocale() { | 83 std::string InputMethodBridge::GetInputLocale() { |
80 return host_->GetInputLocale(); | 84 return host_ ? host_->GetInputLocale() : ""; |
81 } | 85 } |
82 | 86 |
83 base::i18n::TextDirection InputMethodBridge::GetInputTextDirection() { | 87 base::i18n::TextDirection InputMethodBridge::GetInputTextDirection() { |
84 return host_->GetInputTextDirection(); | 88 return host_ ? host_->GetInputTextDirection() : base::i18n::UNKNOWN_DIRECTION; |
85 } | 89 } |
86 | 90 |
87 bool InputMethodBridge::IsActive() { | 91 bool InputMethodBridge::IsActive() { |
88 return host_->IsActive(); | 92 return host_ ? host_->IsActive() : false; |
89 } | 93 } |
90 | 94 |
91 // Overridden from TextInputClient. Forward an event from the system-wide IME | 95 // Overridden from TextInputClient. Forward an event from the system-wide IME |
92 // to the text input |client|, which is e.g. views::NativeTextfieldViews. | 96 // to the text input |client|, which is e.g. views::NativeTextfieldViews. |
93 void InputMethodBridge::SetCompositionText( | 97 void InputMethodBridge::SetCompositionText( |
94 const ui::CompositionText& composition) { | 98 const ui::CompositionText& composition) { |
95 TextInputClient* client = GetTextInputClient(); | 99 TextInputClient* client = GetTextInputClient(); |
96 if (client) | 100 if (client) |
97 client->SetCompositionText(composition); | 101 client->SetCompositionText(composition); |
98 } | 102 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 void InputMethodBridge::OnWillChangeFocus(View* focused_before, View* focused) { | 199 void InputMethodBridge::OnWillChangeFocus(View* focused_before, View* focused) { |
196 ConfirmCompositionText(); | 200 ConfirmCompositionText(); |
197 } | 201 } |
198 | 202 |
199 void InputMethodBridge::OnDidChangeFocus(View* focused_before, View* focused) { | 203 void InputMethodBridge::OnDidChangeFocus(View* focused_before, View* focused) { |
200 OnTextInputTypeChanged(GetFocusedView()); | 204 OnTextInputTypeChanged(GetFocusedView()); |
201 OnCaretBoundsChanged(GetFocusedView()); | 205 OnCaretBoundsChanged(GetFocusedView()); |
202 } | 206 } |
203 | 207 |
204 } // namespace views | 208 } // namespace views |
OLD | NEW |