keyboard_layout_manager.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/keyboard/ui/keyboard_layout_manager.h"
  5. #include "ash/keyboard/ui/keyboard_ui_controller.h"
  6. #include "base/trace_event/trace_event.h"
  7. #include "ui/compositor/layer_animator.h"
  8. #include "ui/display/display.h"
  9. #include "ui/display/screen.h"
  10. namespace keyboard {
  11. KeyboardLayoutManager::KeyboardLayoutManager(KeyboardUIController* controller)
  12. : controller_(controller) {}
  13. KeyboardLayoutManager::~KeyboardLayoutManager() = default;
  14. // Overridden from aura::LayoutManager
  15. void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
  16. // Reset the keyboard window bounds when it gets added to the keyboard
  17. // container to ensure that its bounds are valid.
  18. SetChildBounds(child, child->GetBoundsInRootWindow());
  19. }
  20. void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
  21. const gfx::Rect& requested_bounds) {
  22. aura::Window* contents_window = controller_->GetKeyboardWindow();
  23. if (contents_window != child) {
  24. // Let the bounds change to go through for windows other than the virtual
  25. // keyboard contents window. This is needed because IME candidate window is
  26. // put in VirtualKeyboardContainer managed by this layout manager.
  27. if (child->bounds() != requested_bounds)
  28. SetChildBoundsDirect(child, requested_bounds);
  29. return;
  30. }
  31. TRACE_EVENT0("vk", "KeyboardLayoutSetChildBounds");
  32. // The requested bounds must be adjusted.
  33. aura::Window* root_window = controller_->GetRootWindow();
  34. // If the keyboard has been deactivated, this reference will be null.
  35. if (!root_window)
  36. return;
  37. DisplayUtil display_util;
  38. const display::Display& display =
  39. display_util.GetNearestDisplayToWindow(root_window);
  40. const gfx::Vector2d display_offset =
  41. display.bounds().origin().OffsetFromOrigin();
  42. const gfx::Rect new_bounds =
  43. controller_->AdjustSetBoundsRequest(display.bounds(),
  44. requested_bounds + display_offset) -
  45. display_offset;
  46. // Keyboard bounds should only be reset when the contents window bounds
  47. // actually change. Otherwise it interrupts the initial animation of showing
  48. // the keyboard. Described in crbug.com/356753.
  49. gfx::Rect old_bounds = contents_window->GetTargetBounds();
  50. if (new_bounds == old_bounds)
  51. return;
  52. SetChildBoundsDirect(contents_window, new_bounds);
  53. }
  54. } // namespace keyboard