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 "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 | 213 |
214 void KeyboardController::SetOverrideContentUrl(const GURL& url) { | 214 void KeyboardController::SetOverrideContentUrl(const GURL& url) { |
215 proxy_->SetOverrideContentUrl(url); | 215 proxy_->SetOverrideContentUrl(url); |
216 } | 216 } |
217 | 217 |
218 void KeyboardController::OnTextInputStateChanged( | 218 void KeyboardController::OnTextInputStateChanged( |
219 const ui::TextInputClient* client) { | 219 const ui::TextInputClient* client) { |
220 if (!container_.get()) | 220 if (!container_.get()) |
221 return; | 221 return; |
222 | 222 |
223 bool was_showing = keyboard_visible_; | 223 if (IsKeyboardUsabilityExperimentEnabled()) { |
224 bool should_show = was_showing; | 224 OnShowImeIfNeeded(); |
225 return; | |
226 } | |
227 | |
225 ui::TextInputType type = | 228 ui::TextInputType type = |
226 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 229 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
227 if (type == ui::TEXT_INPUT_TYPE_NONE && | 230 if (type == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) { |
228 !IsKeyboardUsabilityExperimentEnabled() && | 231 if (keyboard_visible_ /* && !IsKeyboardUsabilityExperimentEnabled() */) { |
229 !lock_keyboard_) { | |
230 should_show = false; | |
231 } else { | |
232 if (container_->children().empty()) { | |
233 keyboard::MarkKeyboardLoadStarted(); | |
234 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
235 keyboard->Show(); | |
236 container_->AddChild(keyboard); | |
237 } | |
238 if (type != ui::TEXT_INPUT_TYPE_NONE) | |
239 proxy_->SetUpdateInputType(type); | |
240 container_->parent()->StackChildAtTop(container_.get()); | |
241 should_show = true; | |
242 } | |
243 | |
244 if (was_showing != should_show) { | |
245 if (should_show) { | |
246 keyboard_visible_ = true; | |
247 | |
248 // If the controller is in the process of hiding the keyboard, do not log | |
249 // the stat here since the keyboard will not actually be shown. | |
250 if (!WillHideKeyboard()) | |
251 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); | |
252 | |
253 weak_factory_.InvalidateWeakPtrs(); | |
254 if (container_->IsVisible()) | |
255 return; | |
256 | |
257 NotifyKeyboardBoundsChanging(container_->children()[0]->bounds()); | |
258 | |
259 proxy_->ShowKeyboardContainer(container_.get()); | |
260 } else { | |
261 // Set the visibility state here so that any queries for visibility | 232 // Set the visibility state here so that any queries for visibility |
262 // before the timer fires returns the correct future value. | 233 // before the timer fires returns the correct future value. |
263 keyboard_visible_ = false; | 234 keyboard_visible_ = false; |
264 base::MessageLoop::current()->PostDelayedTask( | 235 base::MessageLoop::current()->PostDelayedTask( |
265 FROM_HERE, | 236 FROM_HERE, |
266 base::Bind(&KeyboardController::HideKeyboard, | 237 base::Bind(&KeyboardController::HideKeyboard, |
267 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), | 238 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), |
268 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | 239 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); |
269 } | 240 } |
241 } else { | |
242 // Abort a pending keyboard hide. | |
243 if (WillHideKeyboard()) { | |
244 weak_factory_.InvalidateWeakPtrs(); | |
245 keyboard_visible_ = true; | |
246 } | |
247 proxy_->SetUpdateInputType(type); | |
270 } | 248 } |
271 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 249 // TODO(bryeung): whenever the TextInputClient changes we need to notify the |
272 // keyboard (with the TextInputType) so that it can reset it's state (e.g. | 250 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
273 // abandon compositions in progress) | 251 // abandon compositions in progress) |
274 } | 252 } |
275 | 253 |
276 void KeyboardController::OnInputMethodDestroyed( | 254 void KeyboardController::OnInputMethodDestroyed( |
277 const ui::InputMethod* input_method) { | 255 const ui::InputMethod* input_method) { |
278 DCHECK_EQ(input_method_, input_method); | 256 DCHECK_EQ(input_method_, input_method); |
279 input_method_ = NULL; | 257 input_method_ = NULL; |
280 } | 258 } |
281 | 259 |
260 void KeyboardController::OnShowImeIfNeeded() { | |
261 if (!container_.get()) | |
262 return; | |
263 | |
264 if (container_->children().empty()) { | |
265 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
266 keyboard->Show(); | |
267 container_->AddChild(keyboard); | |
268 container_->layout_manager()->OnWindowResized(); | |
Shu Chen
2014/01/09 04:21:17
unnecessary call to OnWindowResized(), because now
kevers
2014/01/09 15:29:09
Done.
| |
269 } | |
270 if (keyboard_visible_) | |
271 return; | |
272 | |
273 keyboard_visible_ = true; | |
274 | |
275 // If the controller is in the process of hiding the keyboard, do not log | |
276 // the stat here since the keyboard will not actually be shown. | |
277 if (!WillHideKeyboard()) | |
278 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); | |
279 | |
280 weak_factory_.InvalidateWeakPtrs(); | |
281 if (container_->IsVisible()) | |
282 return; | |
283 | |
284 FOR_EACH_OBSERVER( | |
285 KeyboardControllerObserver, | |
286 observer_list_, | |
287 OnKeyboardBoundsChanging(container_->children()[0]->bounds())); | |
Shu Chen
2014/01/09 04:21:17
Why not use this?
NotifyKeyboardBoundsChanging(con
kevers
2014/01/09 15:29:09
Done.
| |
288 proxy_->ShowKeyboardContainer(container_.get()); | |
289 } | |
290 | |
282 bool KeyboardController::WillHideKeyboard() const { | 291 bool KeyboardController::WillHideKeyboard() const { |
283 return weak_factory_.HasWeakPtrs(); | 292 return weak_factory_.HasWeakPtrs(); |
284 } | 293 } |
285 | 294 |
286 } // namespace keyboard | 295 } // namespace keyboard |
OLD | NEW |