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 fcebf9670a8ae3ca5d80522431e6bfa346d7a6e5..6c5e0cf494a4f1070f1a2ab04b34332cb9fcb999 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. @@ -2908,6 +2908,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 e44b23e055f985fea140a41a87f10a5423f7c77d..d1e09b159746ad13de9f3fea6b189bb9db041434 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. @@ -628,6 +628,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 a73f08700e77443b1229ee35f99356be57d376f5..d37da7f122cdd326499d9e89fc83bef89d726014 100644
  38. --- a/content/browser/renderer_host/text_input_manager.cc
  39. +++ b/content/browser/renderer_host/text_input_manager.cc
  40. @@ -167,6 +167,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. @@ -453,6 +454,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 01993347572548e46d8583c0bb568be4f12c7207..c679db5de0e2b60867b8f4b30c9b72b63420d694 100644
  60. --- a/content/browser/renderer_host/text_input_manager.h
  61. +++ b/content/browser/renderer_host/text_input_manager.h
  62. @@ -71,6 +71,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. @@ -277,6 +281,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 8fa03cce47dfb7680859e73b2858685e03cf6b3d..89c9c331775171bda62b84da8069fc3ccef8ad3f 100644
  80. --- a/content/browser/web_contents/web_contents_impl.cc
  81. +++ b/content/browser/web_contents/web_contents_impl.cc
  82. @@ -8753,7 +8753,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. }