[M120 Migration][VD][AX] Custom the focus event when setFocus to webview 61/308261/2
authorjiangyuwei <yuwei.jiang@samsung.com>
Tue, 19 Mar 2024 05:33:48 +0000 (13:33 +0800)
committerYanqing Lu <yanqing.lu@samsung.com>
Mon, 25 Mar 2024 06:53:26 +0000 (06:53 +0000)
Accessibility needs to be informed when system focus has moved
into the web area again even if focus did not change within WebCore;
And if there is no focus element, try move down to find one.

References:
  - https://review.tizen.org/gerrit/#/c/291817/

Change-Id: I2cc752397b14562e9beaca3ca107d73137750b02
Signed-off-by: jiangyuwei <yuwei.jiang@samsung.com>
third_party/blink/renderer/core/exported/web_view_impl.cc
third_party/blink/renderer/core/page/spatial_navigation.cc
third_party/blink/renderer/core/page/spatial_navigation_controller.cc
third_party/blink/renderer/core/page/spatial_navigation_controller.h
tizen_src/ewk/efl_integration/eweb_accessibility.cc

index a1e160c..684ef49 100644 (file)
 
 #if BUILDFLAG(IS_TIZEN_TV)
 #include "third_party/blink/public/platform/web_application_type.h"
+#include "third_party/blink/renderer/core/page/spatial_navigation_controller.h"
+#include "third_party/blink/renderer/modules/accessibility/ax_object_cache_impl.h"
 #include "third_party/blink/public/web/web_security_policy.h"
 #endif
 
@@ -2015,6 +2017,27 @@ void WebViewImpl::SetPageFocus(bool enable) {
               SelectionInDOMTree::Builder().Collapse(position).Build());
         }
       }
+#if BUILDFLAG(IS_TIZEN_TV)
+      if (element) {
+        // Accessibility needs to be informed that system focus has moved
+        // into the web area again, even if focus did not change within
+        // WebCore. send the notification even if the element is the same.
+        AXObjectCache* cache =
+            focused_frame->GetDocument()->ExistingAXObjectCache();
+        if (cache)
+          cache->HandleFocusedUIElementChanged(0, element);
+      } else {
+        // if no focus element and spatial navigation enabled,
+        // move to the first top element by send a fake arrow down
+        if (IsSpatialNavigationEnabled(focused_frame) && IsWebBrowser()) {
+          LOG(INFO) << "No focused element in view, navigate downward";
+          GetPage()
+              ->GetSpatialNavigationController()
+              .HandleSpatialNavigationDirection(
+                  SpatialNavigationDirection::kDown);
+        }
+      }
+#endif
     }
   } else {
     CancelPagePopup();
index 70cb3a8..e430935 100644 (file)
@@ -610,11 +610,15 @@ bool BothOnTopmostPaintLayerInStackingContext(
     return false;
 
   const LayoutObject* origin = current_interest.visible_node->GetLayoutObject();
+  if (!origin)
+    return false;
   const PaintLayer* focused_layer = origin->PaintingLayer();
   if (!focused_layer || focused_layer->IsRootLayer())
     return false;
 
   const LayoutObject* next = candidate.visible_node->GetLayoutObject();
+  if (!next)
+    return false;
   const PaintLayer* candidate_layer = next->PaintingLayer();
   if (focused_layer != candidate_layer)
     return false;
index 9886254..0f3e1a9 100644 (file)
@@ -606,4 +606,10 @@ void SpatialNavigationController::FullscreenStateChanged(Element* element) {
   }
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+bool SpatialNavigationController::HandleSpatialNavigationDirection(
+    SpatialNavigationDirection direction) {
+  return Advance(direction);
+}
+#endif
 }  // namespace blink
index 8354679..01311b6 100644 (file)
@@ -48,6 +48,10 @@ class CORE_EXPORT SpatialNavigationController final
 
   void Trace(Visitor*) const;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool HandleSpatialNavigationDirection(SpatialNavigationDirection direction);
+#endif
+
  private:
   // Entry-point into SpatialNavigation advancement. Will return true if an
   // action (moving interest or scrolling), false otherwise.
index 0882ef4..c3702dd 100644 (file)
@@ -81,8 +81,14 @@ void EWebAccessibility::NotifyAccessibilityStatus(bool is_enabled) {
   if (IsMobileProfile() || IsTvProfile())
     (is_enabled) ? AddPlug() : RemovePlug();
 
+// On TV, the Spatial Navigation and Accessibility are independent, the
+// Accessibility Status change should not trigger Spatial Navigation status
+// change. So disbale trigger SpatialNavigationStatusChange when
+// AccessibilityStatusChanged.
+#if !BUILDFLAG(IS_TIZEN_TV)
   if (observer_) {
     observer_->OnSpatialNavigationStatusChanged(is_enabled);
     observer_->OnAccessibilityStatusChanged(is_enabled);
   }
+#endif
 }