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

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

Issue 1392713002: Extract content dependency from keyboard code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 2 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 <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "content/public/browser/render_widget_host.h"
12 #include "content/public/browser/render_widget_host_iterator.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
15 #include "ui/aura/window_delegate.h" 12 #include "ui/aura/window_delegate.h"
16 #include "ui/aura/window_observer.h" 13 #include "ui/aura/window_observer.h"
17 #include "ui/base/cursor/cursor.h" 14 #include "ui/base/cursor/cursor.h"
18 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
19 #include "ui/base/ime/input_method.h" 16 #include "ui/base/ime/input_method.h"
20 #include "ui/base/ime/text_input_client.h" 17 #include "ui/base/ime/text_input_client.h"
21 #include "ui/compositor/layer_animation_observer.h" 18 #include "ui/compositor/layer_animation_observer.h"
22 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
23 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
24 #include "ui/gfx/path.h" 21 #include "ui/gfx/path.h"
25 #include "ui/gfx/skia_util.h" 22 #include "ui/gfx/skia_util.h"
26 #include "ui/keyboard/keyboard_controller_observer.h" 23 #include "ui/keyboard/keyboard_controller_observer.h"
27 #include "ui/keyboard/keyboard_controller_proxy.h"
28 #include "ui/keyboard/keyboard_layout_manager.h" 24 #include "ui/keyboard/keyboard_layout_manager.h"
25 #include "ui/keyboard/keyboard_ui.h"
29 #include "ui/keyboard/keyboard_util.h" 26 #include "ui/keyboard/keyboard_util.h"
30 #include "ui/wm/core/masked_window_targeter.h"
31 27
32 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
33 #include "base/process/launch.h" 29 #include "base/process/launch.h"
34 #include "base/sys_info.h" 30 #include "base/sys_info.h"
35 #if defined(USE_OZONE) 31 #if defined(USE_OZONE)
36 #include "ui/ozone/public/input_controller.h" 32 #include "ui/ozone/public/input_controller.h"
37 #include "ui/ozone/public/ozone_platform.h" 33 #include "ui/ozone/public/ozone_platform.h"
38 #endif 34 #endif
39 #endif // if defined(OS_CHROMEOS) 35 #endif // if defined(OS_CHROMEOS)
40 36
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return; 150 return;
155 animator_->RemoveObserver(this); 151 animator_->RemoveObserver(this);
156 callback_.Run(); 152 callback_.Run();
157 } 153 }
158 154
159 void CallbackAnimationObserver::OnLayerAnimationAborted( 155 void CallbackAnimationObserver::OnLayerAnimationAborted(
160 ui::LayerAnimationSequence* seq) { 156 ui::LayerAnimationSequence* seq) {
161 animator_->RemoveObserver(this); 157 animator_->RemoveObserver(this);
162 } 158 }
163 159
164 class WindowBoundsChangeObserver : public aura::WindowObserver {
165 public:
166 void OnWindowBoundsChanged(aura::Window* window,
167 const gfx::Rect& old_bounds,
168 const gfx::Rect& new_bounds) override;
169 void OnWindowDestroyed(aura::Window* window) override;
170
171 void AddObservedWindow(aura::Window* window);
172 void RemoveAllObservedWindows();
173
174 private:
175 std::set<aura::Window*> observed_windows_;
176 };
177
178 void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window,
179 const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) {
180 KeyboardController* controller = KeyboardController::GetInstance();
181 if (controller)
182 controller->UpdateWindowInsets(window);
183 }
184
185 void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) {
186 if (window->HasObserver(this))
187 window->RemoveObserver(this);
188 observed_windows_.erase(window);
189 }
190
191 void WindowBoundsChangeObserver::AddObservedWindow(aura::Window* window) {
192 if (!window->HasObserver(this)) {
193 window->AddObserver(this);
194 observed_windows_.insert(window);
195 }
196 }
197
198 void WindowBoundsChangeObserver::RemoveAllObservedWindows() {
199 for (std::set<aura::Window*>::iterator it = observed_windows_.begin();
200 it != observed_windows_.end(); ++it)
201 (*it)->RemoveObserver(this);
202 observed_windows_.clear();
203 }
204
205 // static 160 // static
206 KeyboardController* KeyboardController::instance_ = NULL; 161 KeyboardController* KeyboardController::instance_ = NULL;
207 162
208 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) 163 KeyboardController::KeyboardController(KeyboardUI* ui)
209 : proxy_(proxy), 164 : ui_(ui),
210 input_method_(NULL), 165 input_method_(NULL),
211 keyboard_visible_(false), 166 keyboard_visible_(false),
212 show_on_resize_(false), 167 show_on_resize_(false),
213 lock_keyboard_(false), 168 lock_keyboard_(false),
214 keyboard_mode_(FULL_WIDTH), 169 keyboard_mode_(FULL_WIDTH),
215 type_(ui::TEXT_INPUT_TYPE_NONE), 170 type_(ui::TEXT_INPUT_TYPE_NONE),
216 weak_factory_(this) { 171 weak_factory_(this) {
217 CHECK(proxy); 172 CHECK(ui);
218 input_method_ = proxy_->GetInputMethod(); 173 input_method_ = ui_->GetInputMethod();
219 input_method_->AddObserver(this); 174 input_method_->AddObserver(this);
220 window_bounds_observer_.reset(new WindowBoundsChangeObserver()); 175 ui_->SetController(this);
221 proxy_->SetController(this);
222 } 176 }
223 177
224 KeyboardController::~KeyboardController() { 178 KeyboardController::~KeyboardController() {
225 if (container_) { 179 if (container_) {
226 if (container_->GetRootWindow()) 180 if (container_->GetRootWindow())
227 container_->GetRootWindow()->RemoveObserver(this); 181 container_->GetRootWindow()->RemoveObserver(this);
228 container_->RemoveObserver(this); 182 container_->RemoveObserver(this);
229 } 183 }
230 if (input_method_) 184 if (input_method_)
231 input_method_->RemoveObserver(this); 185 input_method_->RemoveObserver(this);
232 ResetWindowInsets(); 186 ui_->SetController(nullptr);
233 proxy_->SetController(nullptr);
234 } 187 }
235 188
236 // static 189 // static
237 void KeyboardController::ResetInstance(KeyboardController* controller) { 190 void KeyboardController::ResetInstance(KeyboardController* controller) {
238 if (instance_ && instance_ != controller) 191 if (instance_ && instance_ != controller)
239 delete instance_; 192 delete instance_;
240 instance_ = controller; 193 instance_ = controller;
241 } 194 }
242 195
243 // static 196 // static
244 KeyboardController* KeyboardController::GetInstance() { 197 KeyboardController* KeyboardController::GetInstance() {
245 return instance_; 198 return instance_;
246 } 199 }
247 200
248 aura::Window* KeyboardController::GetContainerWindow() { 201 aura::Window* KeyboardController::GetContainerWindow() {
249 if (!container_.get()) { 202 if (!container_.get()) {
250 container_.reset(new aura::Window(new KeyboardWindowDelegate())); 203 container_.reset(new aura::Window(new KeyboardWindowDelegate()));
251 container_->SetName("KeyboardContainer"); 204 container_->SetName("KeyboardContainer");
252 container_->set_owned_by_parent(false); 205 container_->set_owned_by_parent(false);
253 container_->Init(ui::LAYER_NOT_DRAWN); 206 container_->Init(ui::LAYER_NOT_DRAWN);
254 container_->AddObserver(this); 207 container_->AddObserver(this);
255 container_->SetLayoutManager(new KeyboardLayoutManager(this)); 208 container_->SetLayoutManager(new KeyboardLayoutManager(this));
256 } 209 }
257 return container_.get(); 210 return container_.get();
258 } 211 }
259 212
260 void KeyboardController::NotifyKeyboardBoundsChanging( 213 void KeyboardController::NotifyKeyboardBoundsChanging(
261 const gfx::Rect& new_bounds) { 214 const gfx::Rect& new_bounds) {
262 current_keyboard_bounds_ = new_bounds; 215 current_keyboard_bounds_ = new_bounds;
263 if (proxy_->HasKeyboardWindow() && proxy_->GetKeyboardWindow()->IsVisible()) { 216 if (ui_->HasKeyboardWindow() && ui_->GetKeyboardWindow()->IsVisible()) {
264 FOR_EACH_OBSERVER(KeyboardControllerObserver, 217 FOR_EACH_OBSERVER(KeyboardControllerObserver,
265 observer_list_, 218 observer_list_,
266 OnKeyboardBoundsChanging(new_bounds)); 219 OnKeyboardBoundsChanging(new_bounds));
267 if (keyboard::IsKeyboardOverscrollEnabled()) { 220 if (keyboard::IsKeyboardOverscrollEnabled())
268 // Adjust the height of the viewport for visible windows on the primary 221 ui_->InitInsets(new_bounds);
269 // display. 222 else
270 // TODO(kevers): Add EnvObserver to properly initialize insets if a 223 ui_->ResetInsets();
271 // window is created while the keyboard is visible.
272 scoped_ptr<content::RenderWidgetHostIterator> widgets(
273 content::RenderWidgetHost::GetRenderWidgetHosts());
274 aura::Window* keyboard_window = proxy_->GetKeyboardWindow();
275 aura::Window* root_window = keyboard_window->GetRootWindow();
276 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
277 content::RenderWidgetHostView* view = widget->GetView();
278 // Can be NULL, e.g. if the RenderWidget is being destroyed or
279 // the render process crashed.
280 if (view) {
281 aura::Window* window = view->GetNativeView();
282 // If virtual keyboard failed to load, a widget that displays error
283 // message will be created and adds as a child of the virtual keyboard
284 // window. We want to avoid add BoundsChangedObserver to that window.
285 if (!keyboard_window->Contains(window) &&
286 window->GetRootWindow() == root_window) {
287 gfx::Rect window_bounds = window->GetBoundsInScreen();
288 gfx::Rect intersect = gfx::IntersectRects(window_bounds,
289 new_bounds);
290 int overlap = intersect.height();
291 if (overlap > 0 && overlap < window_bounds.height())
292 view->SetInsets(gfx::Insets(0, 0, overlap, 0));
293 else
294 view->SetInsets(gfx::Insets());
295 AddBoundsChangedObserver(window);
296 }
297 }
298 }
299 } else {
300 ResetWindowInsets();
301 }
302 } else { 224 } else {
303 current_keyboard_bounds_ = gfx::Rect(); 225 current_keyboard_bounds_ = gfx::Rect();
304 } 226 }
305 } 227 }
306 228
307 void KeyboardController::HideKeyboard(HideReason reason) { 229 void KeyboardController::HideKeyboard(HideReason reason) {
308 keyboard_visible_ = false; 230 keyboard_visible_ = false;
309 ToggleTouchEventLogging(true); 231 ToggleTouchEventLogging(true);
310 232
311 keyboard::LogKeyboardControlEvent( 233 keyboard::LogKeyboardControlEvent(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 288 }
367 289
368 void KeyboardController::ShowKeyboard(bool lock) { 290 void KeyboardController::ShowKeyboard(bool lock) {
369 set_lock_keyboard(lock); 291 set_lock_keyboard(lock);
370 ShowKeyboardInternal(); 292 ShowKeyboardInternal();
371 } 293 }
372 294
373 void KeyboardController::OnWindowHierarchyChanged( 295 void KeyboardController::OnWindowHierarchyChanged(
374 const HierarchyChangeParams& params) { 296 const HierarchyChangeParams& params) {
375 if (params.new_parent && params.target == container_.get()) 297 if (params.new_parent && params.target == container_.get())
376 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); 298 OnTextInputStateChanged(ui_->GetInputMethod()->GetTextInputClient());
377 } 299 }
378 300
379 void KeyboardController::OnWindowAddedToRootWindow(aura::Window* window) { 301 void KeyboardController::OnWindowAddedToRootWindow(aura::Window* window) {
380 if (!window->GetRootWindow()->HasObserver(this)) 302 if (!window->GetRootWindow()->HasObserver(this))
381 window->GetRootWindow()->AddObserver(this); 303 window->GetRootWindow()->AddObserver(this);
382 } 304 }
383 305
384 void KeyboardController::OnWindowRemovingFromRootWindow(aura::Window* window, 306 void KeyboardController::OnWindowRemovingFromRootWindow(aura::Window* window,
385 aura::Window* new_root) { 307 aura::Window* new_root) {
386 if (window->GetRootWindow()->HasObserver(this)) 308 if (window->GetRootWindow()->HasObserver(this))
387 window->GetRootWindow()->RemoveObserver(this); 309 window->GetRootWindow()->RemoveObserver(this);
388 } 310 }
389 311
390 void KeyboardController::OnWindowBoundsChanged(aura::Window* window, 312 void KeyboardController::OnWindowBoundsChanged(aura::Window* window,
391 const gfx::Rect& old_bounds, 313 const gfx::Rect& old_bounds,
392 const gfx::Rect& new_bounds) { 314 const gfx::Rect& new_bounds) {
393 if (!window->IsRootWindow()) 315 if (!window->IsRootWindow())
394 return; 316 return;
395 // Keep the same height when window resize. It gets called when screen 317 // Keep the same height when window resize. It gets called when screen
396 // rotate. 318 // rotate.
397 if (!keyboard_container_initialized() || !proxy_->HasKeyboardWindow()) 319 if (!keyboard_container_initialized() || !ui_->HasKeyboardWindow())
398 return; 320 return;
399 321
400 int container_height = container_->bounds().height(); 322 int container_height = container_->bounds().height();
401 if (keyboard_mode_ == FULL_WIDTH) { 323 if (keyboard_mode_ == FULL_WIDTH) {
402 container_->SetBounds(gfx::Rect(new_bounds.x(), 324 container_->SetBounds(gfx::Rect(new_bounds.x(),
403 new_bounds.bottom() - container_height, 325 new_bounds.bottom() - container_height,
404 new_bounds.width(), 326 new_bounds.width(),
405 container_height)); 327 container_height));
406 } else if (keyboard_mode_ == FLOATING) { 328 } else if (keyboard_mode_ == FLOATING) {
407 // When screen rotate, horizontally center floating virtual keyboard 329 // When screen rotate, horizontally center floating virtual keyboard
408 // window and vertically align it to the bottom. 330 // window and vertically align it to the bottom.
409 int container_width = container_->bounds().width(); 331 int container_width = container_->bounds().width();
410 container_->SetBounds(gfx::Rect( 332 container_->SetBounds(gfx::Rect(
411 new_bounds.x() + (new_bounds.width() - container_width) / 2, 333 new_bounds.x() + (new_bounds.width() - container_width) / 2,
412 new_bounds.bottom() - container_height, 334 new_bounds.bottom() - container_height,
413 container_width, 335 container_width,
414 container_height)); 336 container_height));
415 } 337 }
416 } 338 }
417 339
418 void KeyboardController::Reload() { 340 void KeyboardController::Reload() {
419 if (proxy_->HasKeyboardWindow()) { 341 if (ui_->HasKeyboardWindow()) {
420 // A reload should never try to show virtual keyboard. If keyboard is not 342 // A reload should never try to show virtual keyboard. If keyboard is not
421 // visible before reload, it should keep invisible after reload. 343 // visible before reload, it should keep invisible after reload.
422 show_on_resize_ = false; 344 show_on_resize_ = false;
423 proxy_->ReloadKeyboardIfNeeded(); 345 ui_->ReloadKeyboardIfNeeded();
424 } 346 }
425 } 347 }
426 348
427 void KeyboardController::OnTextInputStateChanged( 349 void KeyboardController::OnTextInputStateChanged(
428 const ui::TextInputClient* client) { 350 const ui::TextInputClient* client) {
429 if (!container_.get()) 351 if (!container_.get())
430 return; 352 return;
431 353
432 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; 354 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
433 355
434 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) { 356 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) {
435 if (keyboard_visible_) { 357 if (keyboard_visible_) {
436 // Set the visibility state here so that any queries for visibility 358 // Set the visibility state here so that any queries for visibility
437 // before the timer fires returns the correct future value. 359 // before the timer fires returns the correct future value.
438 keyboard_visible_ = false; 360 keyboard_visible_ = false;
439 base::MessageLoop::current()->PostDelayedTask( 361 base::MessageLoop::current()->PostDelayedTask(
440 FROM_HERE, 362 FROM_HERE,
441 base::Bind(&KeyboardController::HideKeyboard, 363 base::Bind(&KeyboardController::HideKeyboard,
442 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), 364 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC),
443 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); 365 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
444 } 366 }
445 } else { 367 } else {
446 // Abort a pending keyboard hide. 368 // Abort a pending keyboard hide.
447 if (WillHideKeyboard()) { 369 if (WillHideKeyboard()) {
448 weak_factory_.InvalidateWeakPtrs(); 370 weak_factory_.InvalidateWeakPtrs();
449 keyboard_visible_ = true; 371 keyboard_visible_ = true;
450 } 372 }
451 proxy_->SetUpdateInputType(type_); 373 ui_->SetUpdateInputType(type_);
452 // Do not explicitly show the Virtual keyboard unless it is in the process 374 // Do not explicitly show the Virtual keyboard unless it is in the process
453 // of hiding. Instead, the virtual keyboard is shown in response to a user 375 // of hiding. Instead, the virtual keyboard is shown in response to a user
454 // gesture (mouse or touch) that is received while an element has input 376 // gesture (mouse or touch) that is received while an element has input
455 // focus. Showing the keyboard requires an explicit call to 377 // focus. Showing the keyboard requires an explicit call to
456 // OnShowImeIfNeeded. 378 // OnShowImeIfNeeded.
457 } 379 }
458 } 380 }
459 381
460 void KeyboardController::OnInputMethodDestroyed( 382 void KeyboardController::OnInputMethodDestroyed(
461 const ui::InputMethod* input_method) { 383 const ui::InputMethod* input_method) {
462 DCHECK_EQ(input_method_, input_method); 384 DCHECK_EQ(input_method_, input_method);
463 input_method_ = NULL; 385 input_method_ = NULL;
464 } 386 }
465 387
466 void KeyboardController::OnShowImeIfNeeded() { 388 void KeyboardController::OnShowImeIfNeeded() {
467 ShowKeyboardInternal(); 389 ShowKeyboardInternal();
468 } 390 }
469 391
470 bool KeyboardController::ShouldEnableInsets(aura::Window* window) { 392 /*
sky 2015/10/09 18:23:29 ?
471 aura::Window* keyboard_window = proxy_->GetKeyboardWindow();
472 return (keyboard_window->GetRootWindow() == window->GetRootWindow() &&
473 keyboard::IsKeyboardOverscrollEnabled() &&
474 keyboard_window->IsVisible() && keyboard_visible_);
475 }
476
477 void KeyboardController::UpdateWindowInsets(aura::Window* window) { 393 void KeyboardController::UpdateWindowInsets(aura::Window* window) {
478 aura::Window* keyboard_window = proxy_->GetKeyboardWindow(); 394 aura::Window* keyboard_window = ui_->GetKeyboardWindow();
479 if (window == keyboard_window) 395 if (window == keyboard_window)
480 return; 396 return;
481 397
482 scoped_ptr<content::RenderWidgetHostIterator> widgets( 398 ui_->UpdateInsets(window);
483 content::RenderWidgetHost::GetRenderWidgetHosts());
484 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
485 content::RenderWidgetHostView* view = widget->GetView();
486 if (view && window->Contains(view->GetNativeView())) {
487 gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen();
488 gfx::Rect intersect =
489 gfx::IntersectRects(window_bounds, keyboard_window->bounds());
490 int overlap = ShouldEnableInsets(window) ? intersect.height() : 0;
491 if (overlap > 0 && overlap < window_bounds.height())
492 view->SetInsets(gfx::Insets(0, 0, overlap, 0));
493 else
494 view->SetInsets(gfx::Insets());
495 return;
496 }
497 }
498 } 399 }
400 */
499 401
500 void KeyboardController::ShowKeyboardInternal() { 402 void KeyboardController::ShowKeyboardInternal() {
501 if (!container_.get()) 403 if (!container_.get())
502 return; 404 return;
503 405
504 if (container_->children().empty()) { 406 if (container_->children().empty()) {
505 keyboard::MarkKeyboardLoadStarted(); 407 keyboard::MarkKeyboardLoadStarted();
506 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 408 aura::Window* keyboard = ui_->GetKeyboardWindow();
507 keyboard->Show(); 409 keyboard->Show();
508 container_->AddChild(keyboard); 410 container_->AddChild(keyboard);
509 keyboard->set_owned_by_parent(false); 411 keyboard->set_owned_by_parent(false);
510 } 412 }
511 413
512 proxy_->ReloadKeyboardIfNeeded(); 414 ui_->ReloadKeyboardIfNeeded();
513 415
514 if (keyboard_visible_) { 416 if (keyboard_visible_) {
515 return; 417 return;
516 } else if (proxy_->GetKeyboardWindow()->bounds().height() == 0) { 418 } else if (ui_->GetKeyboardWindow()->bounds().height() == 0) {
517 show_on_resize_ = true; 419 show_on_resize_ = true;
518 return; 420 return;
519 } 421 }
520 422
521 keyboard_visible_ = true; 423 keyboard_visible_ = true;
522 424
523 // If the controller is in the process of hiding the keyboard, do not log 425 // If the controller is in the process of hiding the keyboard, do not log
524 // the stat here since the keyboard will not actually be shown. 426 // the stat here since the keyboard will not actually be shown.
525 if (!WillHideKeyboard()) 427 if (!WillHideKeyboard())
526 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); 428 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
(...skipping 25 matching lines...) Expand all
552 if (keyboard_mode_ == FLOATING) { 454 if (keyboard_mode_ == FLOATING) {
553 animation_observer_.reset(); 455 animation_observer_.reset();
554 } else { 456 } else {
555 animation_observer_.reset(new CallbackAnimationObserver( 457 animation_observer_.reset(new CallbackAnimationObserver(
556 container_animator, 458 container_animator,
557 base::Bind(&KeyboardController::ShowAnimationFinished, 459 base::Bind(&KeyboardController::ShowAnimationFinished,
558 base::Unretained(this)))); 460 base::Unretained(this))));
559 container_animator->AddObserver(animation_observer_.get()); 461 container_animator->AddObserver(animation_observer_.get());
560 } 462 }
561 463
562 proxy_->ShowKeyboardContainer(container_.get()); 464 ui_->ShowKeyboardContainer(container_.get());
563 465
564 { 466 {
565 // Scope the following animation settings as we don't want to animate 467 // Scope the following animation settings as we don't want to animate
566 // visibility change that triggered by a call to the base class function 468 // visibility change that triggered by a call to the base class function
567 // ShowKeyboardContainer with these settings. The container should become 469 // ShowKeyboardContainer with these settings. The container should become
568 // visible immediately. 470 // visible immediately.
569 ui::ScopedLayerAnimationSettings settings(container_animator); 471 ui::ScopedLayerAnimationSettings settings(container_animator);
570 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); 472 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN);
571 settings.SetTransitionDuration( 473 settings.SetTransitionDuration(
572 base::TimeDelta::FromMilliseconds(kShowAnimationDurationMs)); 474 base::TimeDelta::FromMilliseconds(kShowAnimationDurationMs));
573 container_->SetTransform(gfx::Transform()); 475 container_->SetTransform(gfx::Transform());
574 container_->layer()->SetOpacity(1.0); 476 container_->layer()->SetOpacity(1.0);
575 } 477 }
576 } 478 }
577 479
578 void KeyboardController::ResetWindowInsets() {
579 const gfx::Insets insets;
580 scoped_ptr<content::RenderWidgetHostIterator> widgets(
581 content::RenderWidgetHost::GetRenderWidgetHosts());
582 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
583 content::RenderWidgetHostView* view = widget->GetView();
584 if (view)
585 view->SetInsets(insets);
586 }
587 window_bounds_observer_->RemoveAllObservedWindows();
588 }
589
590 bool KeyboardController::WillHideKeyboard() const { 480 bool KeyboardController::WillHideKeyboard() const {
591 return weak_factory_.HasWeakPtrs(); 481 return weak_factory_.HasWeakPtrs();
592 } 482 }
593 483
594 void KeyboardController::ShowAnimationFinished() { 484 void KeyboardController::ShowAnimationFinished() {
595 // Notify observers after animation finished to prevent reveal desktop 485 // Notify observers after animation finished to prevent reveal desktop
596 // background during animation. 486 // background during animation.
597 NotifyKeyboardBoundsChanging(container_->bounds()); 487 NotifyKeyboardBoundsChanging(container_->bounds());
598 proxy_->EnsureCaretInWorkArea(); 488 ui_->EnsureCaretInWorkArea();
599 } 489 }
600 490
601 void KeyboardController::HideAnimationFinished() { 491 void KeyboardController::HideAnimationFinished() {
602 proxy_->HideKeyboardContainer(container_.get()); 492 ui_->HideKeyboardContainer(container_.get());
603 }
604
605 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) {
606 aura::Window* target_window = window ? window->GetToplevelWindow() : nullptr;
607 if (target_window)
608 window_bounds_observer_->AddObservedWindow(target_window);
609 } 493 }
610 494
611 } // namespace keyboard 495 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698