Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: ui/keyboard/keyboard_controller.cc

Issue 20526005: Implement virtual keyboard hiding. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase yet again Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (!container_) { 140 if (!container_) {
141 container_ = new aura::Window(new KeyboardWindowDelegate()); 141 container_ = new aura::Window(new KeyboardWindowDelegate());
142 container_->SetName("KeyboardContainer"); 142 container_->SetName("KeyboardContainer");
143 container_->Init(ui::LAYER_NOT_DRAWN); 143 container_->Init(ui::LAYER_NOT_DRAWN);
144 container_->AddObserver(this); 144 container_->AddObserver(this);
145 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); 145 container_->SetLayoutManager(new KeyboardLayoutManager(container_));
146 } 146 }
147 return container_; 147 return container_;
148 } 148 }
149 149
150 void KeyboardController::HideKeyboard() {
151 keyboard_visible_ = false;
152
153 FOR_EACH_OBSERVER(KeyboardControllerObserver,
154 observer_list_,
155 OnKeyboardBoundsChanging(gfx::Rect()));
156
157 proxy_->HideKeyboardContainer(container_);
158 }
159
150 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { 160 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) {
151 observer_list_.AddObserver(observer); 161 observer_list_.AddObserver(observer);
152 } 162 }
153 163
154 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { 164 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) {
155 observer_list_.RemoveObserver(observer); 165 observer_list_.RemoveObserver(observer);
156 } 166 }
157 167
158 void KeyboardController::OnWindowHierarchyChanged( 168 void KeyboardController::OnWindowHierarchyChanged(
159 const HierarchyChangeParams& params) { 169 const HierarchyChangeParams& params) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 weak_factory_.InvalidateWeakPtrs(); 202 weak_factory_.InvalidateWeakPtrs();
193 if (container_->IsVisible()) 203 if (container_->IsVisible())
194 return; 204 return;
195 205
196 FOR_EACH_OBSERVER( 206 FOR_EACH_OBSERVER(
197 KeyboardControllerObserver, 207 KeyboardControllerObserver,
198 observer_list_, 208 observer_list_,
199 OnKeyboardBoundsChanging(container_->children()[0]->bounds())); 209 OnKeyboardBoundsChanging(container_->children()[0]->bounds()));
200 proxy_->ShowKeyboardContainer(container_); 210 proxy_->ShowKeyboardContainer(container_);
201 } else { 211 } else {
212 // Set the visibility state here so that any queries for visibility
213 // before the timer fires returns the correct future value.
202 keyboard_visible_ = false; 214 keyboard_visible_ = false;
203 base::MessageLoop::current()->PostDelayedTask( 215 base::MessageLoop::current()->PostDelayedTask(
204 FROM_HERE, 216 FROM_HERE,
205 base::Bind(&KeyboardController::HideKeyboard, 217 base::Bind(&KeyboardController::HideKeyboard,
206 weak_factory_.GetWeakPtr()), 218 weak_factory_.GetWeakPtr()),
207 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); 219 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
208 } 220 }
209 } 221 }
210 // TODO(bryeung): whenever the TextInputClient changes we need to notify the 222 // TODO(bryeung): whenever the TextInputClient changes we need to notify the
211 // keyboard (with the TextInputType) so that it can reset it's state (e.g. 223 // keyboard (with the TextInputType) so that it can reset it's state (e.g.
212 // abandon compositions in progress) 224 // abandon compositions in progress)
213 } 225 }
214 226
215 void KeyboardController::OnInputMethodDestroyed( 227 void KeyboardController::OnInputMethodDestroyed(
216 const ui::InputMethod* input_method) { 228 const ui::InputMethod* input_method) {
217 DCHECK_EQ(input_method_, input_method); 229 DCHECK_EQ(input_method_, input_method);
218 input_method_ = NULL; 230 input_method_ = NULL;
219 } 231 }
220 232
221 void KeyboardController::HideKeyboard() {
222 FOR_EACH_OBSERVER(KeyboardControllerObserver,
223 observer_list_,
224 OnKeyboardBoundsChanging(gfx::Rect()));
225 proxy_->HideKeyboardContainer(container_);
226 }
227
228 bool KeyboardController::WillHideKeyboard() const { 233 bool KeyboardController::WillHideKeyboard() const {
229 return weak_factory_.HasWeakPtrs(); 234 return weak_factory_.HasWeakPtrs();
230 } 235 }
231 236
232 } // namespace keyboard 237 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698