OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "ui/aura/layout_manager.h" | 8 #include "ui/aura/layout_manager.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura/window_delegate.h" | 10 #include "ui/aura/window_delegate.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 const HierarchyChangeParams& params) { | 177 const HierarchyChangeParams& params) { |
178 if (params.new_parent && params.target == container_.get()) | 178 if (params.new_parent && params.target == container_.get()) |
179 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); | 179 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); |
180 } | 180 } |
181 | 181 |
182 void KeyboardController::OnTextInputStateChanged( | 182 void KeyboardController::OnTextInputStateChanged( |
183 const ui::TextInputClient* client) { | 183 const ui::TextInputClient* client) { |
184 if (!container_.get()) | 184 if (!container_.get()) |
185 return; | 185 return; |
186 | 186 |
187 bool was_showing = keyboard_visible_; | |
188 bool should_show = was_showing; | |
189 ui::TextInputType type = | 187 ui::TextInputType type = |
190 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 188 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
191 if (type == ui::TEXT_INPUT_TYPE_NONE) { | 189 if (type == ui::TEXT_INPUT_TYPE_NONE) { |
192 should_show = false; | 190 if (keyboard_visible_) { |
193 } else { | |
194 if (container_->children().empty()) { | |
195 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
196 keyboard->Show(); | |
197 container_->AddChild(keyboard); | |
198 container_->layout_manager()->OnWindowResized(); | |
199 } | |
200 proxy_->SetUpdateInputType(type); | |
201 container_->parent()->StackChildAtTop(container_.get()); | |
202 should_show = true; | |
203 } | |
204 | |
205 if (was_showing != should_show) { | |
206 if (should_show) { | |
207 keyboard_visible_ = true; | |
208 | |
209 // If the controller is in the process of hiding the keyboard, do not log | |
210 // the stat here since the keyboard will not actually be shown. | |
211 if (!WillHideKeyboard()) | |
212 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); | |
213 | |
214 weak_factory_.InvalidateWeakPtrs(); | |
215 if (container_->IsVisible()) | |
216 return; | |
217 | |
218 FOR_EACH_OBSERVER( | |
219 KeyboardControllerObserver, | |
220 observer_list_, | |
221 OnKeyboardBoundsChanging(container_->children()[0]->bounds())); | |
222 proxy_->ShowKeyboardContainer(container_.get()); | |
223 } else { | |
224 // Set the visibility state here so that any queries for visibility | 191 // Set the visibility state here so that any queries for visibility |
225 // before the timer fires returns the correct future value. | 192 // before the timer fires returns the correct future value. |
226 keyboard_visible_ = false; | 193 keyboard_visible_ = false; |
227 base::MessageLoop::current()->PostDelayedTask( | 194 base::MessageLoop::current()->PostDelayedTask( |
228 FROM_HERE, | 195 FROM_HERE, |
229 base::Bind(&KeyboardController::HideKeyboard, | 196 base::Bind(&KeyboardController::HideKeyboard, |
230 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), | 197 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), |
231 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | 198 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); |
232 } | 199 } |
| 200 } else { |
| 201 // Abort a pending keyboard hide. |
| 202 if (WillHideKeyboard()) { |
| 203 weak_factory_.InvalidateWeakPtrs(); |
| 204 keyboard_visible_ = true; |
| 205 } |
| 206 proxy_->SetUpdateInputType(type); |
233 } | 207 } |
234 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 208 // TODO(bryeung): whenever the TextInputClient changes we need to notify the |
235 // keyboard (with the TextInputType) so that it can reset it's state (e.g. | 209 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
236 // abandon compositions in progress) | 210 // abandon compositions in progress) |
237 } | 211 } |
238 | 212 |
239 void KeyboardController::OnInputMethodDestroyed( | 213 void KeyboardController::OnInputMethodDestroyed( |
240 const ui::InputMethod* input_method) { | 214 const ui::InputMethod* input_method) { |
241 DCHECK_EQ(input_method_, input_method); | 215 DCHECK_EQ(input_method_, input_method); |
242 input_method_ = NULL; | 216 input_method_ = NULL; |
243 } | 217 } |
244 | 218 |
| 219 void KeyboardController::OnShowVirtualKeyboard() { |
| 220 if (container_->children().empty()) { |
| 221 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
| 222 keyboard->Show(); |
| 223 container_->AddChild(keyboard); |
| 224 container_->layout_manager()->OnWindowResized(); |
| 225 } |
| 226 if (keyboard_visible_) |
| 227 return; |
| 228 |
| 229 // If the controller is in the process of hiding the keyboard, do not log |
| 230 // the stat here since the keyboard will not actually be shown. |
| 231 if (!WillHideKeyboard()) |
| 232 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); |
| 233 |
| 234 weak_factory_.InvalidateWeakPtrs(); |
| 235 if (container_->IsVisible()) |
| 236 return; |
| 237 |
| 238 FOR_EACH_OBSERVER( |
| 239 KeyboardControllerObserver, |
| 240 observer_list_, |
| 241 OnKeyboardBoundsChanging(container_->children()[0]->bounds())); |
| 242 proxy_->ShowKeyboardContainer(container_.get()); |
| 243 keyboard_visible_ = true; |
| 244 } |
| 245 |
245 bool KeyboardController::WillHideKeyboard() const { | 246 bool KeyboardController::WillHideKeyboard() const { |
246 return weak_factory_.HasWeakPtrs(); | 247 return weak_factory_.HasWeakPtrs(); |
247 } | 248 } |
248 | 249 |
249 } // namespace keyboard | 250 } // namespace keyboard |
OLD | NEW |