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 47d375776347948b08702b733f5a5d051d63c015..6929dcb6a77b914aabad16f36baac4ff8fdd61c4 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. @@ -3212,6 +3212,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 5410c9d207bad1da2f733e153630400f50642617..1696658f38b965f69146c76c7f48d04a15a2cc8d 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. @@ -651,6 +651,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 9a0aad0d4a3dada0faec031d155c6d346355e8a5..8852c53847bbe2f906aff4bdacc355fc41cf5021 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. @@ -485,6 +486,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 51522e60d6dc14f1113cc438558b6b393c3fe73a..153ed02f493a83ef9ca354cc18736f9394fc9a72 100644
  60. --- a/content/browser/renderer_host/text_input_manager.h
  61. +++ b/content/browser/renderer_host/text_input_manager.h
  62. @@ -72,6 +72,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. @@ -308,6 +312,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 5511e34ec19a1adf99086a33930ae0266b7b8099..e0dbe46268a7dfeb9d496e7436bf1e474855bbda 100644
  80. --- a/content/browser/web_contents/web_contents_impl.cc
  81. +++ b/content/browser/web_contents/web_contents_impl.cc
  82. @@ -9658,7 +9658,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. }