keyboard_ui.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2015 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_KEYBOARD_UI_H_
  5. #define ASH_KEYBOARD_UI_KEYBOARD_UI_H_
  6. #include "ash/keyboard/ui/keyboard_export.h"
  7. #include "base/callback_forward.h"
  8. #include "ui/base/ime/text_input_type.h"
  9. #include "ui/events/gestures/gesture_types.h"
  10. namespace aura {
  11. class Window;
  12. }
  13. namespace ui {
  14. class InputMethod;
  15. }
  16. namespace keyboard {
  17. class KeyboardUIController;
  18. // Interface representing a window containing virtual keyboard UI.
  19. class KEYBOARD_EXPORT KeyboardUI {
  20. public:
  21. using LoadCallback = base::OnceCallback<void()>;
  22. KeyboardUI();
  23. KeyboardUI(const KeyboardUI&) = delete;
  24. KeyboardUI& operator=(const KeyboardUI&) = delete;
  25. virtual ~KeyboardUI();
  26. // Begin loading the virtual keyboard window asynchronously.
  27. // Returns a window immediately, but the UI within the window is not
  28. // guaranteed to be fully loaded until |callback| is called.
  29. // |callback| must be called after this function returns.
  30. // This function can only be called once.
  31. virtual aura::Window* LoadKeyboardWindow(LoadCallback callback) = 0;
  32. // Gets the virtual keyboard window i.e. the WebContents window where
  33. // keyboard extensions are loaded. Returns null if the window has not started
  34. // loading.
  35. virtual aura::Window* GetKeyboardWindow() const = 0;
  36. // Get the gesture consumer for the keyboard, which may be different to the
  37. // window itself if there are nested windows.
  38. virtual ui::GestureConsumer* GetGestureConsumer() const = 0;
  39. // Gets the InputMethod that will provide notifications about changes in the
  40. // text input context.
  41. virtual ui::InputMethod* GetInputMethod() = 0;
  42. // Shows the keyboard window. The default implementation simply calls |Show|
  43. // on the window. An overridden implementation can set up animations or delay
  44. // the visibility change.
  45. virtual void ShowKeyboardWindow();
  46. // Hides the keyboard window. The default implementation simply calls |Hide|
  47. // on the window. An overridden implementation can set up animations or delay
  48. // the visibility change.
  49. virtual void HideKeyboardWindow();
  50. // Reloads virtual keyboard URL if the current keyboard's web content URL is
  51. // different. The URL can be different if user switch from password field to
  52. // any other type input field.
  53. // At password field, the system virtual keyboard is forced to load even if
  54. // the current IME provides a customized virtual keyboard. This is needed to
  55. // prevent IME virtual keyboard logging user's password. Once user switch to
  56. // other input fields, the virtual keyboard should switch back to the IME
  57. // provided keyboard, or keep using the system virtual keyboard if IME doesn't
  58. // provide one.
  59. // TODO(https://crbug.com/845780): Change this to accept a callback.
  60. virtual void ReloadKeyboardIfNeeded() = 0;
  61. // |controller| may be null when KeyboardUIController is being destroyed.
  62. void SetController(KeyboardUIController* controller);
  63. protected:
  64. KeyboardUIController* keyboard_controller() { return keyboard_controller_; }
  65. private:
  66. KeyboardUIController* keyboard_controller_ = nullptr;
  67. };
  68. } // namespace keyboard
  69. #endif // ASH_KEYBOARD_UI_KEYBOARD_UI_H_