container_behavior.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2017 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. #ifndef ASH_KEYBOARD_UI_CONTAINER_BEHAVIOR_H_
  5. #define ASH_KEYBOARD_UI_CONTAINER_BEHAVIOR_H_
  6. #include "ash/keyboard/ui/keyboard_export.h"
  7. #include "ash/public/cpp/keyboard/keyboard_types.h"
  8. #include "ui/display/display.h"
  9. #include "ui/events/event.h"
  10. #include "ui/gfx/geometry/rect.h"
  11. #include "ui/gfx/geometry/vector2d.h"
  12. namespace aura {
  13. class Window;
  14. }
  15. namespace ui {
  16. class LocatedEvent;
  17. class ScopedLayerAnimationSettings;
  18. } // namespace ui
  19. namespace wm {
  20. class ScopedHidingAnimationSettings;
  21. }
  22. namespace keyboard {
  23. // Represents and encapsulates how the keyboard container should visually behave
  24. // within the workspace window.
  25. class KEYBOARD_EXPORT ContainerBehavior {
  26. public:
  27. class Delegate {
  28. public:
  29. virtual ~Delegate() {}
  30. virtual gfx::Rect GetBoundsInScreen() const = 0;
  31. virtual bool IsKeyboardLocked() const = 0;
  32. virtual void MoveKeyboardWindow(const gfx::Rect& new_bounds) = 0;
  33. virtual void MoveKeyboardWindowToDisplay(const display::Display& display,
  34. const gfx::Rect& new_bounds) = 0;
  35. // Needed for ContainerFullWidthBehavior to forward gestures to the shelf.
  36. virtual void TransferGestureEventToShelf(const ui::GestureEvent& event) = 0;
  37. };
  38. explicit ContainerBehavior(Delegate* delegate);
  39. virtual ~ContainerBehavior();
  40. // Apply changes to the animation settings to animate the keyboard container
  41. // showing.
  42. virtual void DoShowingAnimation(
  43. aura::Window* container,
  44. ui::ScopedLayerAnimationSettings* animation_settings) = 0;
  45. // Apply changes to the animation settings to animate the keyboard container
  46. // hiding.
  47. virtual void DoHidingAnimation(
  48. aura::Window* container,
  49. wm::ScopedHidingAnimationSettings* animation_settings) = 0;
  50. // Initialize the starting state of the keyboard container for the showing
  51. // animation.
  52. virtual void InitializeShowAnimationStartingState(
  53. aura::Window* container) = 0;
  54. // Used by the layout manager to intercept any bounds setting request to
  55. // adjust the request to different bounds, if necessary. This method gets
  56. // called at any time during the keyboard's life cycle. The bounds are in
  57. // global screen coordinates.
  58. virtual gfx::Rect AdjustSetBoundsRequest(
  59. const gfx::Rect& display_bounds,
  60. const gfx::Rect& requested_bounds_in_screen_coords) = 0;
  61. // Used to set the bounds to the default location. This is generally called
  62. // during initialization, but may also be have identical behavior to
  63. // AdjustSetBoundsRequest in the case of constant layouts such as the fixed
  64. // full-width keyboard.
  65. virtual void SetCanonicalBounds(aura::Window* container,
  66. const gfx::Rect& display_bounds) = 0;
  67. // A ContainerBehavior can choose to not allow overscroll to be used. It is
  68. // important to note that the word "Allowed" is used because whether or not
  69. // overscroll is "enabled" depends on multiple external factors.
  70. virtual bool IsOverscrollAllowed() const = 0;
  71. virtual void SavePosition(const gfx::Rect& keyboard_bounds_in_screen,
  72. const gfx::Size& screen_size) = 0;
  73. virtual bool HandlePointerEvent(const ui::LocatedEvent& event,
  74. const display::Display& current_display) = 0;
  75. virtual bool HandleGestureEvent(const ui::GestureEvent& event,
  76. const gfx::Rect& bounds_in_screen) = 0;
  77. virtual ContainerType GetType() const = 0;
  78. // Removing focus from a text field should cause the keyboard to be dismissed.
  79. virtual bool TextBlurHidesKeyboard() const = 0;
  80. // Sets a region of the keyboard window that is occluded by the keyboard.
  81. // This is called by the IME extension code. By default, this call is ignored.
  82. // Container behaviors that listen for this call should override this method.
  83. virtual void SetOccludedBounds(const gfx::Rect& occluded_bounds_in_window) {}
  84. // Gets the region of the keyboard window that is occluded by the keyboard, or
  85. // an empty rectangle if nothing is occluded. The occluded region is
  86. // considered to be 'unusable', so the window manager or other system UI
  87. // should respond to the occluded bounds (e.g. by moving windows out of the
  88. // occluded region).
  89. //
  90. // The occluded bounds must be completely contained in the visual bounds.
  91. virtual gfx::Rect GetOccludedBounds(
  92. const gfx::Rect& visual_bounds_in_window) const = 0;
  93. // Any region of the screen that is occluded by the keyboard should cause the
  94. // workspace to change its layout.
  95. virtual bool OccludedBoundsAffectWorkspaceLayout() const = 0;
  96. // Sets floating keyboard drggable rect.
  97. virtual void SetDraggableArea(const gfx::Rect& rect) = 0;
  98. // Sets the area of the keyboard window that should not move off screen. Any
  99. // area outside of this can be moved off the user's screen. Note the bounds
  100. // here are relative to the window's origin.
  101. virtual void SetAreaToRemainOnScreen(const gfx::Rect& rect) = 0;
  102. protected:
  103. Delegate* delegate_;
  104. // The opacity of virtual keyboard container when show animation
  105. // starts or hide animation finishes. This cannot be zero because we
  106. // call Show() on the keyboard window before setting the opacity
  107. // back to 1.0. Since windows are not allowed to be shown with zero
  108. // opacity, we always animate to 0.01 instead.
  109. static constexpr float kAnimationStartOrAfterHideOpacity = 0.01f;
  110. };
  111. } // namespace keyboard
  112. #endif // ASH_KEYBOARD_UI_CONTAINER_BEHAVIOR_H_