[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / popup / popup-impl.cpp
index 768a978..9c9a1f2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
@@ -342,11 +343,12 @@ void Popup::OnInitialize()
 
   SetupTouch();
 
-  DevelControl::AppendAccessibilityAttribute(self, "sub-role", "Alert");
+  self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::DIALOG);
+}
 
-  DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
-    return std::unique_ptr<Dali::Accessibility::Accessible>(new AccessibleImpl(actor, Dali::Accessibility::Role::DIALOG, true));
-  });
+DevelControl::ControlAccessible* Popup::CreateAccessibleObject()
+{
+  return new PopupAccessible(Self());
 }
 
 Popup::~Popup()
@@ -725,25 +727,16 @@ void Popup::SetDisplayState(Toolkit::Popup::DisplayState displayState)
     return;
   }
 
-  auto* accessible = Dali::Accessibility::Accessible::Get(Self());
-  if(display)
-  {
-    Dali::Accessibility::Bridge::GetCurrentBridge()->AddPopup(accessible);
-    accessible->EmitStateChanged(Dali::Accessibility::State::SHOWING, 1, 0);
-  }
-  else
-  {
-    accessible->EmitStateChanged(Dali::Accessibility::State::SHOWING, 0, 0);
-    Dali::Accessibility::Bridge::GetCurrentBridge()->RemovePopup(accessible);
-  }
-
   // Convert the bool state to the actual display state to use.
-  mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
+  mDisplayState    = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
+  auto* accessible = Dali::Accessibility::Accessible::Get(Self());
 
   if(display)
   {
     // Update the state to indicate the current intent.
     mDisplayState = Toolkit::Popup::SHOWING;
+    Dali::Accessibility::Bridge::GetCurrentBridge()->RegisterDefaultLabel(accessible);
+    accessible->EmitShowing(true);
 
     // We want the popup to have key input focus when it is displayed
     SetKeyInputFocus();
@@ -797,8 +790,9 @@ void Popup::SetDisplayState(Toolkit::Popup::DisplayState displayState)
   else // Not visible.
   {
     mDisplayState = Toolkit::Popup::HIDING;
+    Dali::Accessibility::Bridge::GetCurrentBridge()->UnregisterDefaultLabel(accessible);
     ClearKeyInputFocus();
-
+    accessible->EmitShowing(false);
     // Restore the keyboard focus when popup is hidden.
     if(mPreviousFocusedActor && mPreviousFocusedActor.GetProperty<bool>(Actor::Property::KEYBOARD_FOCUSABLE))
     {
@@ -993,7 +987,7 @@ void Popup::SetTailVisibility(bool visible)
   mLayoutDirty = true;
 }
 
-const bool Popup::IsTailVisible() const
+bool Popup::IsTailVisible() const
 {
   return mTailVisible;
 }
@@ -1071,7 +1065,7 @@ void Popup::SetBackingEnabled(bool enabled)
   mLayoutDirty    = true;
 }
 
-const bool Popup::IsBackingEnabled() const
+bool Popup::IsBackingEnabled() const
 {
   return mBackingEnabled;
 }
@@ -1090,7 +1084,7 @@ const Vector4& Popup::GetBackingColor() const
 
 void Popup::SetTailUpImage(std::string image)
 {
-  mTailUpImage = image;
+  mTailUpImage = std::move(image);
   mLayoutDirty = true;
   LayoutTail();
 }
@@ -1102,7 +1096,7 @@ const std::string& Popup::GetTailUpImage() const
 
 void Popup::SetTailDownImage(std::string image)
 {
-  mTailDownImage = image;
+  mTailDownImage = std::move(image);
   mLayoutDirty   = true;
   LayoutTail();
 }
@@ -1114,7 +1108,7 @@ const std::string& Popup::GetTailDownImage() const
 
 void Popup::SetTailLeftImage(std::string image)
 {
-  mTailLeftImage = image;
+  mTailLeftImage = std::move(image);
   mLayoutDirty   = true;
   LayoutTail();
 }
@@ -1126,7 +1120,7 @@ const std::string& Popup::GetTailLeftImage() const
 
 void Popup::SetTailRightImage(std::string image)
 {
-  mTailRightImage = image;
+  mTailRightImage = std::move(image);
   mLayoutDirty    = true;
   LayoutTail();
 }
@@ -1145,7 +1139,7 @@ void Popup::SetTouchTransparent(bool enabled)
   }
 }
 
-const bool Popup::IsTouchTransparent() const
+bool Popup::IsTouchTransparent() const
 {
   return mTouchTransparent;
 }
@@ -1312,7 +1306,7 @@ void Popup::SetProperty(BaseObject* object, Property::Index propertyIndex, const
         std::string valueString;
         if(value.Get(valueString))
         {
-          Toolkit::ImageView actor = Toolkit::ImageView::New(valueString);
+          Toolkit::ImageView actor = Toolkit::ImageView::New(std::move(valueString));
           popupImpl.SetPopupBackgroundImage(actor);
         }
         break;
@@ -1347,7 +1341,7 @@ void Popup::SetProperty(BaseObject* object, Property::Index propertyIndex, const
         std::string valueString;
         if(value.Get(valueString))
         {
-          popupImpl.SetTailUpImage(valueString);
+          popupImpl.SetTailUpImage(std::move(valueString));
         }
         break;
       }
@@ -1356,7 +1350,7 @@ void Popup::SetProperty(BaseObject* object, Property::Index propertyIndex, const
         std::string valueString;
         if(value.Get(valueString))
         {
-          popupImpl.SetTailDownImage(valueString);
+          popupImpl.SetTailDownImage(std::move(valueString));
         }
         break;
       }
@@ -1365,7 +1359,7 @@ void Popup::SetProperty(BaseObject* object, Property::Index propertyIndex, const
         std::string valueString;
         if(value.Get(valueString))
         {
-          popupImpl.SetTailLeftImage(valueString);
+          popupImpl.SetTailLeftImage(std::move(valueString));
         }
         break;
       }
@@ -1374,7 +1368,7 @@ void Popup::SetProperty(BaseObject* object, Property::Index propertyIndex, const
         std::string valueString;
         if(value.Get(valueString))
         {
-          popupImpl.SetTailRightImage(valueString);
+          popupImpl.SetTailRightImage(std::move(valueString));
         }
         break;
       }
@@ -1398,21 +1392,21 @@ Property::Value Popup::GetProperty(BaseObject* object, Property::Index propertyI
       {
         Property::Map map;
         Scripting::CreatePropertyMap(popupImpl.GetTitle(), map);
-        value = map;
+        value = std::move(map);
         break;
       }
       case Toolkit::Popup::Property::CONTENT:
       {
         Property::Map map;
         Scripting::CreatePropertyMap(popupImpl.GetContent(), map);
-        value = map;
+        value = std::move(map);
         break;
       }
       case Toolkit::Popup::Property::FOOTER:
       {
         Property::Map map;
         Scripting::CreatePropertyMap(popupImpl.GetFooter(), map);
-        value = map;
+        value = std::move(map);
         break;
       }
       case Toolkit::Popup::Property::DISPLAY_STATE:
@@ -1454,14 +1448,14 @@ Property::Value Popup::GetProperty(BaseObject* object, Property::Index propertyI
       {
         // Note: Cannot retrieve property map from animation.
         Property::Map map;
-        value = map;
+        value = std::move(map);
         break;
       }
       case Toolkit::Popup::Property::EXIT_ANIMATION:
       {
         // Note: Cannot retrieve property map from animation.
         Property::Map map;
-        value = map;
+        value = std::move(map);
         break;
       }
       case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
@@ -2001,15 +1995,15 @@ void Popup::SetupTouch()
   }
 }
 
-std::string Popup::AccessibleImpl::GetNameRaw()
+std::string Popup::PopupAccessible::GetNameRaw() const
 {
-  auto        popup = Toolkit::Popup::DownCast(self);
+  auto        popup = Toolkit::Popup::DownCast(Self());
   std::string title;
   Actor       popupTitle = popup.GetTitle();
   if(popupTitle)
   {
     std::string titleText = popupTitle.GetProperty<std::string>(Toolkit::TextLabel::Property::TEXT);
-    title                 = titleText;
+    title                 = std::move(titleText);
   }
   else
   {
@@ -2017,19 +2011,20 @@ std::string Popup::AccessibleImpl::GetNameRaw()
     if(popupContent)
     {
       std::string contentText = popupContent.GetProperty<std::string>(Toolkit::TextLabel::Property::TEXT);
-      title                   = contentText;
+      title                   = std::move(contentText);
     }
   }
   return title;
 }
 
-Dali::Accessibility::States Popup::AccessibleImpl::CalculateStates()
+Dali::Accessibility::States Popup::PopupAccessible::CalculateStates()
 {
-  auto states       = Control::Impl::AccessibleImpl::CalculateStates();
-  auto popup        = Toolkit::Popup::DownCast(self);
+  auto states       = DevelControl::ControlAccessible::CalculateStates();
+  auto popup        = Toolkit::Popup::DownCast(Self());
   auto displayState = popup.GetProperty<std::string>(Toolkit::Popup::Property::DISPLAY_STATE);
 
   states[Dali::Accessibility::State::SHOWING] = (displayState == "SHOWN" || displayState == "SHOWING");
+  states[Dali::Accessibility::State::MODAL]   = true;
 
   return states;
 }