Skip to content

Commit

Permalink
fix: update osk patch to fix more corner cases
Browse files Browse the repository at this point in the history
This is a follow up to #35921
that, it fixes more corner cases that on-screen-keyboard does not hide
for webviews.

This change has been applied in Teams for quite a while and should be
reliable enough to introduce to Electron.
  • Loading branch information
zcbenz committed Jan 26, 2024
1 parent 9e630eb commit 47ec0e5
Showing 1 changed file with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,76 @@ From: Kyrylo Hrechykhin <khrechykhin@microsoft.com>
Date: Thu, 6 Oct 2022 18:30:53 +0200
Subject: fix: on-screen-keyboard hides on input blur in webview

Changes introduced by this patch fix issue where OSK does not hide on
input rendered inside webview is blurred. This patch should be removed
when proper fix in chromium repo is available.

Note: the issue still occurs if input rendered in webview blurred due
to touch outside of webview. It is caused by webview implementation
details. Specificaly due to webview has its own tree nodes and focused
node does not change in this case.
Work around OSK not hiding by notifying RenderWidgetHostViewAura of
focus node change via TextInputManager.

chromium-bug: https://crbug.com/1369605

diff --git a/content/browser/renderer_host/render_widget_host_view_child_frame.cc b/content/browser/renderer_host/render_widget_host_view_child_frame.cc
index 090d9d58eddac80f8bd191ac4754d2e8d87c1b39..0c5c78020b98795f51f375a526f06599f9c9a273 100644
--- a/content/browser/renderer_host/render_widget_host_view_child_frame.cc
+++ b/content/browser/renderer_host/render_widget_host_view_child_frame.cc
@@ -1039,6 +1039,12 @@ RenderWidgetHostViewChildFrame::DidUpdateVisualProperties(
return viz::ScopedSurfaceIdAllocator(std::move(allocation_task));
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index 4d2de00328f0b6437789612b14a53aae79eb15ab..c1ad97a53b59ccd7528ae51f27f9863b88cdac60 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -2926,6 +2926,12 @@ void RenderWidgetHostViewAura::OnTextSelectionChanged(
}

Check failure on line 16 in patches/chromium/fix_on-screen-keyboard_hides_on_input_blur_in_webview.patch

View check run for this annotation

trop / Backportable? - 27-x-y

patches/chromium/fix_on-screen-keyboard_hides_on_input_blur_in_webview.patch#L11-L16

Patch Conflict
Raw output
++<<<<<<< HEAD
 +diff --git a/content/browser/renderer_host/render_widget_host_view_child_frame.cc b/content/browser/renderer_host/render_widget_host_view_child_frame.cc
 +index b190c86708d5ae7f207bae3e923609814bf68a52..16395c4b5fd5262885118095784db820508087dd 100644
 +--- a/content/browser/renderer_host/render_widget_host_view_child_frame.cc
 ++++ b/content/browser/renderer_host/render_widget_host_view_child_frame.cc
 +@@ -1041,6 +1041,12 @@ RenderWidgetHostViewChildFrame::DidUpdateVisualProperties(
 +   return viz::ScopedSurfaceIdAllocator(std::move(allocation_task));
++=======
+ diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
+ index 4d2de00328f0b6437789612b14a53aae79eb15ab..c1ad97a53b59ccd7528ae51f27f9863b88cdac60 100644
+ --- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+ +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
+ @@ -2926,6 +2926,12 @@ void RenderWidgetHostViewAura::OnTextSelectionChanged(
+    }
   }
   
- +void RenderWidgetHostViewChildFrame::FocusedNodeChanged(
- +    bool is_editable_node,
- +    const gfx::Rect& node_bounds_in_screen) {
- +  NOTREACHED();
+ +void RenderWidgetHostViewAura::OnFocusedInputElementChanged(
+ +    TextInputManager* text_input_manager,
+ +    RenderWidgetHostViewBase* view) {
+ +  FocusedNodeChanged(false, {});
  +}
  +
+  void RenderWidgetHostViewAura::SetPopupChild(
+      RenderWidgetHostViewAura* popup_child_host_view) {
+    popup_child_host_view_ = popup_child_host_view;
+ diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc
+ index a73f08700e77443b1229ee35f99356be57d376f5..d37da7f122cdd326499d9e89fc83bef89d726014 100644
+ --- a/content/browser/renderer_host/text_input_manager.cc
+ +++ b/content/browser/renderer_host/text_input_manager.cc
+ @@ -167,6 +167,7 @@ void TextInputManager::UpdateTextInputState(
+  
+    if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE &&
+        active_view_ != view) {
+ +    NotifyFocusedInputElementChanged(active_view_);
+      // We reached here because an IPC is received to reset the TextInputState
+      // for |view|. But |view| != |active_view_|, which suggests that at least
+      // one other view has become active and we have received the corresponding
+ @@ -453,6 +454,12 @@ void TextInputManager::NotifyObserversAboutInputStateUpdate(
+      observer.OnUpdateTextInputStateCalled(this, updated_view, did_update_state);
++>>>>>>> fix: update osk patch to fix more corner cases

Check failure on line 16 in patches/chromium/fix_on-screen-keyboard_hides_on_input_blur_in_webview.patch

View check run for this annotation

trop / Backportable? - 28-x-y

patches/chromium/fix_on-screen-keyboard_hides_on_input_blur_in_webview.patch#L11-L16

Patch Conflict
Raw output
++<<<<<<< HEAD
 +diff --git a/content/browser/renderer_host/render_widget_host_view_child_frame.cc b/content/browser/renderer_host/render_widget_host_view_child_frame.cc
 +index f5f30d5696bdd2b8b5948b18b3f7959f9078cc72..660dc5f60bad28ce345827767fc508711ea06d31 100644
 +--- a/content/browser/renderer_host/render_widget_host_view_child_frame.cc
 ++++ b/content/browser/renderer_host/render_widget_host_view_child_frame.cc
 +@@ -1046,6 +1046,12 @@ RenderWidgetHostViewChildFrame::DidUpdateVisualProperties(
 +   return viz::ScopedSurfaceIdAllocator(std::move(allocation_task));
++=======
+ diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
+ index 4d2de00328f0b6437789612b14a53aae79eb15ab..c1ad97a53b59ccd7528ae51f27f9863b88cdac60 100644
+ --- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+ +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
+ @@ -2926,6 +2926,12 @@ void RenderWidgetHostViewAura::OnTextSelectionChanged(
+    }
+  }
+  
+ +void RenderWidgetHostViewAura::OnFocusedInputElementChanged(
+ +    TextInputManager* text_input_manager,
+ +    RenderWidgetHostViewBase* view) {
+ +  FocusedNodeChanged(false, {});
+ +}
+ +
+  void RenderWidgetHostViewAura::SetPopupChild(
+      RenderWidgetHostViewAura* popup_child_host_view) {
+    popup_child_host_view_ = popup_child_host_view;
+ diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc
+ index a73f08700e77443b1229ee35f99356be57d376f5..d37da7f122cdd326499d9e89fc83bef89d726014 100644
+ --- a/content/browser/renderer_host/text_input_manager.cc
+ +++ b/content/browser/renderer_host/text_input_manager.cc
+ @@ -167,6 +167,7 @@ void TextInputManager::UpdateTextInputState(
+  
+    if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE &&
+        active_view_ != view) {
+ +    NotifyFocusedInputElementChanged(active_view_);
+      // We reached here because an IPC is received to reset the TextInputState
+      // for |view|. But |view| != |active_view_|, which suggests that at least
+      // one other view has become active and we have received the corresponding
+ @@ -453,6 +454,12 @@ void TextInputManager::NotifyObserversAboutInputStateUpdate(
+      observer.OnUpdateTextInputStateCalled(this, updated_view, did_update_state);
++>>>>>>> fix: update osk patch to fix more corner cases
}

+void RenderWidgetHostViewAura::OnFocusedInputElementChanged(
+ TextInputManager* text_input_manager,
+ RenderWidgetHostViewBase* view) {
+ FocusedNodeChanged(false, {});
+}
+
void RenderWidgetHostViewAura::SetPopupChild(
RenderWidgetHostViewAura* popup_child_host_view) {
popup_child_host_view_ = popup_child_host_view;
diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc
index a73f08700e77443b1229ee35f99356be57d376f5..d37da7f122cdd326499d9e89fc83bef89d726014 100644
--- a/content/browser/renderer_host/text_input_manager.cc
+++ b/content/browser/renderer_host/text_input_manager.cc
@@ -167,6 +167,7 @@ void TextInputManager::UpdateTextInputState(

if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE &&
active_view_ != view) {
+ NotifyFocusedInputElementChanged(active_view_);
// We reached here because an IPC is received to reset the TextInputState
// for |view|. But |view| != |active_view_|, which suggests that at least
// one other view has become active and we have received the corresponding
@@ -453,6 +454,12 @@ void TextInputManager::NotifyObserversAboutInputStateUpdate(
observer.OnUpdateTextInputStateCalled(this, updated_view, did_update_state);
}

+void RenderWidgetHostViewChildFrame::FocusedNodeChanged(
+ bool is_editable_node,
+ const gfx::Rect& node_bounds_in_screen) {
+ NOTREACHED();
+void TextInputManager::NotifyFocusedInputElementChanged(
+ RenderWidgetHostViewBase* view) {
+ for (auto& observer : observer_list_)
+ observer.OnFocusedInputElementChanged(this, view);
+}
+
ui::TextInputType RenderWidgetHostViewChildFrame::GetTextInputType() const {
if (!text_input_manager_)
return ui::TEXT_INPUT_TYPE_NONE;
diff --git a/content/browser/renderer_host/render_widget_host_view_child_frame.h b/content/browser/renderer_host/render_widget_host_view_child_frame.h
index 58b3038d3aa7ed6babab2e9f6ffe9e4670656243..b2adee153030e0e3c3bf8ae3c2877d78dce56929 100644
--- a/content/browser/renderer_host/render_widget_host_view_child_frame.h
+++ b/content/browser/renderer_host/render_widget_host_view_child_frame.h
@@ -181,6 +181,8 @@ class CONTENT_EXPORT RenderWidgetHostViewChildFrame
void DisableAutoResize(const gfx::Size& new_size) override;
viz::ScopedSurfaceIdAllocator DidUpdateVisualProperties(
const cc::RenderFrameMetadata& metadata) override;
+ void FocusedNodeChanged(bool is_editable_node,
+ const gfx::Rect& node_bounds_in_screen) override;
TextInputManager::SelectionRegion::SelectionRegion() = default;

TextInputManager::SelectionRegion::SelectionRegion(
diff --git a/content/browser/renderer_host/text_input_manager.h b/content/browser/renderer_host/text_input_manager.h
index 01993347572548e46d8583c0bb568be4f12c7207..c679db5de0e2b60867b8f4b30c9b72b63420d694 100644
--- a/content/browser/renderer_host/text_input_manager.h
+++ b/content/browser/renderer_host/text_input_manager.h
@@ -71,6 +71,10 @@ class CONTENT_EXPORT TextInputManager {
virtual void OnTextSelectionChanged(
TextInputManager* text_input_manager,
RenderWidgetHostViewBase* updated_view) {}
+ // Called when focused input element has changed
+ virtual void OnFocusedInputElementChanged(
+ TextInputManager* text_input_manager,
+ RenderWidgetHostViewBase* updated_view) {}
};

// Text selection bounds.
@@ -277,6 +281,7 @@ class CONTENT_EXPORT TextInputManager {

void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view,
bool did_update_state);
+ void NotifyFocusedInputElementChanged(RenderWidgetHostViewBase* view);

// RenderFrameMetadataProvider::Observer implementation.
void OnRenderFrameMetadataChangedBeforeActivation(
// The view with active text input state, i.e., a focused <input> element.
// It will be nullptr if no such view exists. Note that the active view
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 07ac28fe51c8f54d814c4c0718cf6f4705d0dbda..00e0321382a562ffb3733c48540d4f3071f13527 100644
--- a/content/browser/web_contents/web_contents_impl.cc
Expand Down

0 comments on commit 47ec0e5

Please sign in to comment.