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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (!container_) { | 141 if (!container_) { |
142 container_ = new aura::Window(new KeyboardWindowDelegate()); | 142 container_ = new aura::Window(new KeyboardWindowDelegate()); |
143 container_->SetName("KeyboardContainer"); | 143 container_->SetName("KeyboardContainer"); |
144 container_->Init(ui::LAYER_NOT_DRAWN); | 144 container_->Init(ui::LAYER_NOT_DRAWN); |
145 container_->AddObserver(this); | 145 container_->AddObserver(this); |
146 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); | 146 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); |
147 } | 147 } |
148 return container_; | 148 return container_; |
149 } | 149 } |
150 | 150 |
| 151 void KeyboardController::HideKeyboard() { |
| 152 keyboard_visible_ = false; |
| 153 |
| 154 FOR_EACH_OBSERVER(KeyboardControllerObserver, |
| 155 observer_list_, |
| 156 OnKeyboardBoundsChanging(gfx::Rect())); |
| 157 |
| 158 proxy_->HideKeyboardContainer(container_); |
| 159 } |
| 160 |
151 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { | 161 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { |
152 observer_list_.AddObserver(observer); | 162 observer_list_.AddObserver(observer); |
153 } | 163 } |
154 | 164 |
155 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { | 165 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { |
156 observer_list_.RemoveObserver(observer); | 166 observer_list_.RemoveObserver(observer); |
157 } | 167 } |
158 | 168 |
159 void KeyboardController::OnWindowHierarchyChanged( | 169 void KeyboardController::OnWindowHierarchyChanged( |
160 const HierarchyChangeParams& params) { | 170 const HierarchyChangeParams& params) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 weak_factory_.InvalidateWeakPtrs(); | 206 weak_factory_.InvalidateWeakPtrs(); |
197 if (container_->IsVisible()) | 207 if (container_->IsVisible()) |
198 return; | 208 return; |
199 | 209 |
200 FOR_EACH_OBSERVER( | 210 FOR_EACH_OBSERVER( |
201 KeyboardControllerObserver, | 211 KeyboardControllerObserver, |
202 observer_list_, | 212 observer_list_, |
203 OnKeyboardBoundsChanging(container_->children()[0]->bounds())); | 213 OnKeyboardBoundsChanging(container_->children()[0]->bounds())); |
204 proxy_->ShowKeyboardContainer(container_); | 214 proxy_->ShowKeyboardContainer(container_); |
205 } else { | 215 } else { |
| 216 // Set the visibility state here so that any queries for visibility |
| 217 // before the timer fires returns the correct future value. |
206 keyboard_visible_ = false; | 218 keyboard_visible_ = false; |
207 base::MessageLoop::current()->PostDelayedTask( | 219 base::MessageLoop::current()->PostDelayedTask( |
208 FROM_HERE, | 220 FROM_HERE, |
209 base::Bind(&KeyboardController::HideKeyboard, | 221 base::Bind(&KeyboardController::HideKeyboard, |
210 weak_factory_.GetWeakPtr()), | 222 weak_factory_.GetWeakPtr()), |
211 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | 223 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); |
212 } | 224 } |
213 } | 225 } |
214 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 226 // TODO(bryeung): whenever the TextInputClient changes we need to notify the |
215 // keyboard (with the TextInputType) so that it can reset it's state (e.g. | 227 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
216 // abandon compositions in progress) | 228 // abandon compositions in progress) |
217 } | 229 } |
218 | 230 |
219 void KeyboardController::OnInputMethodDestroyed( | 231 void KeyboardController::OnInputMethodDestroyed( |
220 const ui::InputMethod* input_method) { | 232 const ui::InputMethod* input_method) { |
221 DCHECK_EQ(input_method_, input_method); | 233 DCHECK_EQ(input_method_, input_method); |
222 input_method_ = NULL; | 234 input_method_ = NULL; |
223 } | 235 } |
224 | 236 |
225 void KeyboardController::HideKeyboard() { | |
226 FOR_EACH_OBSERVER(KeyboardControllerObserver, | |
227 observer_list_, | |
228 OnKeyboardBoundsChanging(gfx::Rect())); | |
229 proxy_->HideKeyboardContainer(container_); | |
230 } | |
231 | |
232 bool KeyboardController::WillHideKeyboard() const { | 237 bool KeyboardController::WillHideKeyboard() const { |
233 return weak_factory_.HasWeakPtrs(); | 238 return weak_factory_.HasWeakPtrs(); |
234 } | 239 } |
235 | 240 |
236 } // namespace keyboard | 241 } // namespace keyboard |
OLD | NEW |