Keep Blink's focus and EflWindow's focus in sync 46/323246/7
authorGajendra N <gajendra.n@samsung.com>
Thu, 24 Apr 2025 08:14:10 +0000 (13:44 +0530)
committerBot Blink <blinkbot@samsung.com>
Fri, 25 Apr 2025 05:42:07 +0000 (05:42 +0000)
For html elements with autofocus property, initial focus is set
by blink which was not updated to EflWindow through which the
key events are dispatched to blink, resulting in key input not
displayed on textfiled despite caret blinking.
This commit makes sure Blink and EflWindow & its ecore/evas objects
focuses are in sync.

Initial |autofocus| flow:

WebContentsImpl::SetInitialFocus()
WebContentsViewAura::SetInitialFocus()
WebContentsViewAura::Focus()
RenderWidgetHostViewAura::Focus()
RWHVAuraCommonHelper::Focus()
EflWindow::UpdateFocus()
{ecore/evas/elm}_focus_set()

Change-Id: I5a757abfbf01d429d41100e8b5993826da3e29cc
Signed-off-by: Gajendra N <gajendra.n@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_common_helper_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_common_helper_efl.h
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window.cc
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_window.h
ui/platform_window/platform_window.h

index bd36e84bd07bc8094cd9953b4341b9652f75f5d6..559dce765f892e066f6379b05c5bf4d68a7393e3 100644 (file)
@@ -301,6 +301,36 @@ void RWHVAuraCommonHelperEfl::OnGetNumberFieldAttributes(
   }
 }
 
+void RWHVAuraCommonHelperEfl::Focus(bool focus) {
+  if (!rwhva()->window()) {
+    return;
+  }
+
+  aura::WindowTreeHost* window_host = rwhva()->window()->GetHost();
+  if (!window_host) {
+    return;
+  }
+
+  static_cast<aura::WindowTreeHostPlatform*>(window_host)
+      ->platform_window()
+      ->UpdateFocus(focus);
+}
+
+bool RWHVAuraCommonHelperEfl::HasFocus() {
+  if (!rwhva()->window()) {
+    return false;
+  }
+
+  aura::WindowTreeHost* window_host = rwhva()->window()->GetHost();
+  if (!window_host) {
+    return false;
+  }
+
+  return static_cast<aura::WindowTreeHostPlatform*>(window_host)
+      ->platform_window()
+      ->HasFocus();
+}
+
 void RWHVAuraCommonHelperEfl::SetPageVisibility(bool visible) {
   LOG(INFO) << __FUNCTION__ << ", visible : " << visible;
   if (visible) {
index 63dd279736c21b9458cebd60a819067fcb123a49..b32ee2ebf68e906d6728059e63d2978a4c6d6ea4 100644 (file)
@@ -84,8 +84,8 @@ class CONTENT_EXPORT RWHVAuraCommonHelperEfl {
   virtual void DidGetContentSnapshot(const SkBitmap& bitmap, int request_id);
   virtual void Show() {}
   virtual void Hide() {}
-  virtual void Focus(bool focus) {}
-  virtual bool HasFocus() { return false; }
+  virtual void Focus(bool focus);
+  virtual bool HasFocus();
   virtual gfx::Size GetVisibleViewportSize() { return gfx::Size(); }
   virtual gfx::Size GetPhysicalBackingSize() const { return gfx::Size(); }
   virtual void HandleGestureBegin() {}
index 01ee70652c91f07d83b86d534e12c6832749a52a..f9b3a166a97bb27d5c45793386777fe75b01e017 100644 (file)
@@ -162,6 +162,7 @@ void EflWindow::Show(bool inactive) {
   ecore_wl2_window_show(wl_window_);
 #endif
   ecore_evas_show(ee_);
+  ecore_evas_focus_set(ee_, true);
 
   // Request to redraw window surface when showing. If not, a black screen will
   // appear.
@@ -355,6 +356,11 @@ bool EflWindow::CanDispatchEvent(const PlatformEvent& event) {
 }
 
 void EflWindow::UpdateFocus(bool focused) {
+  if (ee_ && !base::CommandLine::ForCurrentProcess()->HasSwitch(
+                 switches::kEnableOffscreenRendering)) {
+    ecore_evas_focus_set(ee_, focused);
+  }
+
   if (elm_win_) {
     evas_object_focus_set(events_overlay_, focused);
     elm_object_focus_set(events_overlay_, focused);
index 37b3d27c1142e091939b9927c4ffe2001dd27618..10ee4d1a2bef9bd6e2347039c8615895ac79247e 100644 (file)
@@ -79,6 +79,7 @@ class EflWindow : public PlatformWindow, public PlatformEventDispatcher {
                                     void* ime_window) override;
 
   void UpdateFocus(bool focused) override;
+  bool HasFocus() override { return has_focus_; }
   void SetFocus(bool focused) { has_focus_ = focused; }
 
   void OnWindowLostCapture();
index 1bebaa1b6e671b193043dd8f45eabf033a9d2b52..9b48a531afa959822723ebd99dfa2c3aaa5e2546 100644 (file)
@@ -244,6 +244,7 @@ class COMPONENT_EXPORT(PLATFORM_WINDOW) PlatformWindow
   // Sets view created in RWHVAura as events overlay for offscreen rendering.
   virtual void SetEventsOverlayForOffscreen(Evas_Object*, void*) {}
   virtual void UpdateFocus(bool focused) {}
+  virtual bool HasFocus() { return false; }
 
   virtual EflEventHandler* GetEventHandler() { return nullptr; }
 #endif