[Tizen] Optimize EmitStateChanged to reduce dbus call 28/317728/1
authorYoungsun Suh <youngsun.suh@samsung.com>
Fri, 13 Sep 2024 00:47:07 +0000 (09:47 +0900)
committerYoungsun Suh <youngsun.suh@samsung.com>
Fri, 13 Sep 2024 07:13:04 +0000 (16:13 +0900)
Change-Id: I316cec6b797ebf7a8b63f8051658738d9aef2e9a

[AT-SPI] Add Accessible::IsHighlighted()

This helper allows to simplify multiple comparisons of Self() to
GetCurrentlyHighlightedActor() to simply checking IsHighlighted().

Change-Id: I61354dc7b0cec90facdc4005ae0b6063697c8fc5

dali/devel-api/adaptor-framework/accessibility.cpp
dali/devel-api/adaptor-framework/actor-accessible.cpp
dali/devel-api/adaptor-framework/actor-accessible.h
dali/devel-api/adaptor-framework/proxy-accessible.h
dali/devel-api/atspi-interfaces/accessible.h
dali/internal/accessibility/bridge/accessible.cpp
dali/internal/accessibility/bridge/bridge-base.h

index c3f73f1..cfa97ac 100644 (file)
@@ -376,6 +376,13 @@ void Accessible::SetCurrentlyHighlightedActor(Dali::Actor actor)
   }
 }
 
+bool Accessible::IsHighlighted() const
+{
+  Dali::Actor self = GetInternalActor();
+
+  return self && self == GetCurrentlyHighlightedActor();
+}
+
 Dali::Actor Accessible::GetHighlightActor()
 {
   return IsUp() ? Bridge::GetCurrentBridge()->mData->mHighlightActor : Dali::Actor{};
@@ -480,15 +487,14 @@ public:
       return false;
     }
 
-    auto self = Self();
-    if(self != GetCurrentlyHighlightedActor())
+    if(!IsHighlighted())
     {
       return false;
     }
 
     SetCurrentlyHighlightedActor({});
 
-    auto                             window     = Dali::DevelWindow::Get(self);
+    auto                             window     = Dali::DevelWindow::Get(Self());
     Dali::Internal::Adaptor::Window& windowImpl = Dali::GetImplementation(window);
     windowImpl.EmitAccessibilityHighlightSignal(false);
 
index fbf16ee..e3c0de1 100644 (file)
@@ -121,7 +121,7 @@ std::size_t ActorAccessible::GetIndexInParent()
   throw std::domain_error{"actor is not a child of its parent"};
 }
 
-Dali::Actor ActorAccessible::GetInternalActor()
+Dali::Actor ActorAccessible::GetInternalActor() const
 {
   return Self();
 }
index d91cf75..ba74c1e 100644 (file)
@@ -87,7 +87,7 @@ public:
   /**
    * @copydoc Dali::Accessibility::Accessible::GetInternalActor()
    */
-  Dali::Actor GetInternalActor() final;
+  Dali::Actor GetInternalActor() const final;
 
   /**
    * @copydoc Dali::Accessibility::Component::GetLayer()
index d7b5e73..8aa5426 100644 (file)
@@ -129,7 +129,7 @@ public:
     return {};
   }
 
-  Dali::Actor GetInternalActor() override
+  Dali::Actor GetInternalActor() const override
   {
     return Dali::Actor{};
   }
index 4a2e485..7804164 100644 (file)
@@ -343,6 +343,13 @@ public:
   virtual bool IsProxy() const;
 
   /**
+   * @brief Checks if this is highlighted
+   *
+   * @return True if highlighted, false otherwise
+   */
+  bool IsHighlighted() const;
+
+  /**
    * @brief Gets unique address on accessibility bus.
    *
    * @return The Address class containing address
@@ -385,7 +392,7 @@ public:
    *
    * @return The internal Actor
    */
-  virtual Dali::Actor GetInternalActor() = 0;
+  virtual Dali::Actor GetInternalActor() const = 0;
 
   /**
    * @brief Sets whether to listen for post render callback.
index 64ef00f..ed8fc1e 100644 (file)
@@ -40,15 +40,27 @@ bool UpdateLastEmitted(std::map<State, int>& lastEmitted, State state, int newVa
   return inserted || updated;
 }
 
-bool RoleTriggersContextRebuilding(Role role)
+bool IsModalRole(Role role)
 {
-  return role == Role::POPUP_MENU || role == Role::PANEL || role == Role::DIALOG || role == Role::PAGE_TAB || role == Role::WINDOW;
+  return role == Role::POPUP_MENU || role == Role::PANEL || role == Role::DIALOG || role == Role::PAGE_TAB;
 }
 
-// Allowing duplicate showing event for some roles as it used to rebuild context after switching default label in Accessibility V1.
-bool ShouldForceEmit(Accessible* accessible, State state)
+bool IsWindowRole(Role role)
 {
-  return state == State::SHOWING && RoleTriggersContextRebuilding(accessible->GetRole());
+  return role == Role::WINDOW || role == Role::FRAME || role == Role::INPUT_METHOD_WINDOW;
+}
+
+bool ShouldEmitVisible(Accessible* accessible)
+{
+  Role role = accessible->GetRole();
+  return IsWindowRole(role);
+}
+
+bool ShouldEmitShowing(Accessible* accessible, bool showing)
+{
+  Role role = accessible->GetRole();
+  return IsWindowRole(role) || IsModalRole(role) || (showing && role == Role::NOTIFICATION) ||
+         (!showing && accessible->IsHighlighted()) || accessible->GetStates()[State::MODAL];
 }
 
 } // namespace
@@ -78,7 +90,28 @@ void Accessible::EmitStateChanged(State state, int newValue, int reserved)
 {
   if(auto bridgeData = GetBridgeData())
   {
-    if(UpdateLastEmitted(mLastEmittedState, state, newValue) || ShouldForceEmit(this, state))
+    bool shouldEmit{false};
+
+    switch(state)
+    {
+      case State::SHOWING:
+      {
+        shouldEmit = ShouldEmitShowing(this, static_cast<bool>(newValue));
+        break;
+      }
+      case State::VISIBLE:
+      {
+        shouldEmit = ShouldEmitVisible(this);
+        break;
+      }
+      default:
+      {
+        shouldEmit = UpdateLastEmitted(mLastEmittedState, state, newValue);
+        break;
+      }
+    }
+
+    if(shouldEmit)
     {
       bridgeData->mBridge->EmitStateChanged(shared_from_this(), state, newValue, reserved);
     }
index ecb4aec..fa3cf93 100644 (file)
@@ -160,7 +160,7 @@ public:
     return {};
   }
 
-  Dali::Actor GetInternalActor() override
+  Dali::Actor GetInternalActor() const override
   {
     return Dali::Actor{};
   }