text_input_host.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2018 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 UI_VIEWS_COCOA_TEXT_INPUT_HOST_H_
  5. #define UI_VIEWS_COCOA_TEXT_INPUT_HOST_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "components/remote_cocoa/common/text_input_host.mojom.h"
  8. #include "mojo/public/cpp/bindings/associated_receiver.h"
  9. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  10. #include "ui/views/views_export.h"
  11. namespace ui {
  12. class TextInputClient;
  13. } // namespace ui
  14. namespace views {
  15. class NativeWidgetMacNSWindowHost;
  16. class VIEWS_EXPORT TextInputHost : public remote_cocoa::mojom::TextInputHost {
  17. public:
  18. explicit TextInputHost(NativeWidgetMacNSWindowHost* host_impl);
  19. TextInputHost(const TextInputHost&) = delete;
  20. TextInputHost& operator=(const TextInputHost&) = delete;
  21. ~TextInputHost() override;
  22. void BindReceiver(
  23. mojo::PendingAssociatedReceiver<remote_cocoa::mojom::TextInputHost>
  24. receiver);
  25. // Set the current TextInputClient.
  26. void SetTextInputClient(ui::TextInputClient* new_text_input_client);
  27. // Return a pointer to the host's ui::TextInputClient.
  28. // TODO(ccameron): Remove the need for this call.
  29. ui::TextInputClient* GetTextInputClient() const;
  30. private:
  31. // remote_cocoa::mojom::TextInputHost:
  32. bool HasClient(bool* out_has_client) override;
  33. bool HasInputContext(bool* out_has_input_context) override;
  34. bool IsRTL(bool* out_is_rtl) override;
  35. bool GetSelectionRange(gfx::Range* out_range) override;
  36. bool GetSelectionText(bool* out_result, std::u16string* out_text) override;
  37. void InsertText(const std::u16string& text, bool as_character) override;
  38. void DeleteRange(const gfx::Range& range) override;
  39. void SetCompositionText(const std::u16string& text,
  40. const gfx::Range& selected_range,
  41. const gfx::Range& replacement_range) override;
  42. void ConfirmCompositionText() override;
  43. bool HasCompositionText(bool* out_has_composition_text) override;
  44. bool GetCompositionTextRange(gfx::Range* out_composition_range) override;
  45. bool GetAttributedSubstringForRange(const gfx::Range& requested_range,
  46. std::u16string* out_text,
  47. gfx::Range* out_actual_range) override;
  48. bool GetFirstRectForRange(const gfx::Range& requested_range,
  49. gfx::Rect* out_rect,
  50. gfx::Range* out_actual_range) override;
  51. // remote_cocoa::mojom::TextInputHost synchronous methods:
  52. void HasClient(HasClientCallback callback) override;
  53. void HasInputContext(HasInputContextCallback callback) override;
  54. void IsRTL(IsRTLCallback callback) override;
  55. void GetSelectionRange(GetSelectionRangeCallback callback) override;
  56. void GetSelectionText(GetSelectionTextCallback callback) override;
  57. void HasCompositionText(HasCompositionTextCallback callback) override;
  58. void GetCompositionTextRange(
  59. GetCompositionTextRangeCallback callback) override;
  60. void GetAttributedSubstringForRange(
  61. const gfx::Range& requested_range,
  62. GetAttributedSubstringForRangeCallback callback) override;
  63. void GetFirstRectForRange(const gfx::Range& requested_range,
  64. GetFirstRectForRangeCallback callback) override;
  65. // Weak. If non-null the TextInputClient of the currently focused views::View
  66. // in the hierarchy rooted at the root view of |host_impl_|. Owned by the
  67. // focused views::View.
  68. raw_ptr<ui::TextInputClient> text_input_client_ = nullptr;
  69. // The TextInputClient about to be set. Requests for a new -inputContext will
  70. // use this, but while the input is changing the NSView still needs to service
  71. // IME requests using the old |text_input_client_|.
  72. raw_ptr<ui::TextInputClient> pending_text_input_client_ = nullptr;
  73. const raw_ptr<NativeWidgetMacNSWindowHost> host_impl_;
  74. mojo::AssociatedReceiver<remote_cocoa::mojom::TextInputHost> mojo_receiver_{
  75. this};
  76. };
  77. } // namespace views
  78. #endif // UI_VIEWS_COCOA_TEXT_INPUT_HOST_H_