fix_on-screen-keyboard_hides_on_input_blur_in_webview.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Kyrylo Hrechykhin <[email protected]>
  3. Date: Thu, 6 Oct 2022 18:30:53 +0200
  4. Subject: fix: on-screen-keyboard hides on input blur in webview
  5. Work around OSK not hiding by notifying RenderWidgetHostViewAura of
  6. focus node change via TextInputManager.
  7. chromium-bug: https://crbug.com/1369605
  8. diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
  9. index 7e9f2e71f08c1324a805462064d4fa485041c19f..2b4543ca40eac0f56c6408e27aac523827093724 100644
  10. --- a/content/browser/renderer_host/render_widget_host_view_aura.cc
  11. +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
  12. @@ -3220,6 +3220,12 @@ void RenderWidgetHostViewAura::OnTextSelectionChanged(
  13. }
  14. }
  15. +void RenderWidgetHostViewAura::OnFocusedInputElementChanged(
  16. + TextInputManager* text_input_manager,
  17. + RenderWidgetHostViewBase* view) {
  18. + FocusedNodeChanged(false, {});
  19. +}
  20. +
  21. void RenderWidgetHostViewAura::SetPopupChild(
  22. RenderWidgetHostViewAura* popup_child_host_view) {
  23. popup_child_host_view_ = popup_child_host_view;
  24. diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h
  25. index 06fc7daf2761ae728f3adf9eb2ef3910a14cf827..8d34f9dfd9a8625a3fab397f7b96c12c87cb8a61 100644
  26. --- a/content/browser/renderer_host/render_widget_host_view_aura.h
  27. +++ b/content/browser/renderer_host/render_widget_host_view_aura.h
  28. @@ -653,6 +653,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
  29. RenderWidgetHostViewBase* updated_view) override;
  30. void OnTextSelectionChanged(TextInputManager* text_input_mangager,
  31. RenderWidgetHostViewBase* updated_view) override;
  32. + void OnFocusedInputElementChanged(TextInputManager* text_input_manager,
  33. + RenderWidgetHostViewBase* view) override;
  34. // Detaches |this| from the input method object.
  35. // is_removed flag is true if this is called while the window is
  36. diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc
  37. index 4f1d98e960b58cf417d53c487f7eafa2b15c2c1e..1de7a9b74555e01e17ea89ac457dc4d011001a3c 100644
  38. --- a/content/browser/renderer_host/text_input_manager.cc
  39. +++ b/content/browser/renderer_host/text_input_manager.cc
  40. @@ -183,6 +183,7 @@ void TextInputManager::UpdateTextInputState(
  41. if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE &&
  42. active_view_ != view) {
  43. + NotifyFocusedInputElementChanged(active_view_);
  44. // We reached here because an IPC is received to reset the TextInputState
  45. // for |view|. But |view| != |active_view_|, which suggests that at least
  46. // one other view has become active and we have received the corresponding
  47. @@ -473,6 +474,12 @@ void TextInputManager::NotifyObserversAboutInputStateUpdate(
  48. observer.OnUpdateTextInputStateCalled(this, updated_view, did_update_state);
  49. }
  50. +void TextInputManager::NotifyFocusedInputElementChanged(
  51. + RenderWidgetHostViewBase* view) {
  52. + for (auto& observer : observer_list_)
  53. + observer.OnFocusedInputElementChanged(this, view);
  54. +}
  55. +
  56. TextInputManager::SelectionRegion::SelectionRegion() = default;
  57. TextInputManager::SelectionRegion::SelectionRegion(
  58. diff --git a/content/browser/renderer_host/text_input_manager.h b/content/browser/renderer_host/text_input_manager.h
  59. index 75df43e3cd2721a92c90c18154d53d5c203e2465..ce42c75c8face36d21f53f44c0201ac46df71d6a 100644
  60. --- a/content/browser/renderer_host/text_input_manager.h
  61. +++ b/content/browser/renderer_host/text_input_manager.h
  62. @@ -69,6 +69,10 @@ class CONTENT_EXPORT TextInputManager {
  63. virtual void OnTextSelectionChanged(
  64. TextInputManager* text_input_manager,
  65. RenderWidgetHostViewBase* updated_view) {}
  66. + // Called when focused input element has changed
  67. + virtual void OnFocusedInputElementChanged(
  68. + TextInputManager* text_input_manager,
  69. + RenderWidgetHostViewBase* updated_view) {}
  70. };
  71. // Text selection bounds.
  72. @@ -304,6 +308,7 @@ class CONTENT_EXPORT TextInputManager {
  73. void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
  74. bool did_update_state);
  75. + void NotifyFocusedInputElementChanged(RenderWidgetHostViewBase* view);
  76. // The view with active text input state, i.e., a focused <input> element.
  77. // It will be nullptr if no such view exists. Note that the active view
  78. diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
  79. index c3b563b0b727bc35f6d4499c589110644ebe9cd1..6010d9f9fc9bfeffb3e5a64de7352b52a202cbf7 100644
  80. --- a/content/browser/web_contents/web_contents_impl.cc
  81. +++ b/content/browser/web_contents/web_contents_impl.cc
  82. @@ -9772,7 +9772,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
  83. "WebContentsImpl::OnFocusedElementChangedInFrame",
  84. "render_frame_host", frame);
  85. RenderWidgetHostViewBase* root_view =
  86. - static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
  87. + static_cast<RenderWidgetHostViewBase*>(GetTopLevelRenderWidgetHostView());
  88. if (!root_view || !frame->GetView()) {
  89. return;
  90. }