[AT-SPI] Add Selection interface 13/258913/10
authorArtur Świgoń <a.swigon@samsung.com>
Thu, 27 May 2021 13:31:47 +0000 (15:31 +0200)
committerArtur Świgoń <a.swigon@samsung.com>
Tue, 8 Jun 2021 12:40:19 +0000 (14:40 +0200)
Change-Id: I893f79a9ccfb7e39fb257a798c297dc22f107cea

dali/devel-api/adaptor-framework/accessibility-impl.h
dali/internal/accessibility/bridge/accessible.cpp
dali/internal/accessibility/bridge/bridge-impl.cpp
dali/internal/accessibility/bridge/bridge-selection.cpp [new file with mode: 0644]
dali/internal/accessibility/bridge/bridge-selection.h [new file with mode: 0644]
dali/internal/accessibility/file.list

index cb7c0b3..f8032fc 100644 (file)
@@ -1051,6 +1051,89 @@ public:
 };
 
 /**
+ * @brief Interface representing objects which can store a set of selected items
+ */
+class DALI_ADAPTOR_API Selection : public virtual Accessible
+{
+public:
+  /**
+   * @brief Gets number of selected children
+   *
+   * @return number of selected children (zero if none)
+   */
+  virtual int GetSelectedChildrenCount() = 0;
+
+  /**
+   * @brief Gets a specific selected child
+   *
+   * @param selectedChildIndex index of the selected child
+   *
+   * @note @p selectedChildIndex refers to the list of selected children,
+   * not the list of all children
+   *
+   * @return selected child or nullptr if index is invalid
+   */
+  virtual Accessible* GetSelectedChild(int selectedChildIndex) = 0;
+
+  /**
+   * @brief Selects a child
+   *
+   * @param childIndex index of the child
+   *
+   * @return true on success, false otherwise
+   */
+  virtual bool SelectChild(int childIndex) = 0;
+
+  /**
+   * @brief Deselects a selected child
+   *
+   * @param selectedChildIndex index of the selected child
+   *
+   * @note @p selectedChildIndex refers to the list of selected children,
+   * not the list of all children
+   *
+   * @return true on success, false otherwise
+   *
+   * @see Dali::Accessibility::Selection::DeselectChild
+   */
+  virtual bool DeselectSelectedChild(int selectedChildIndex) = 0;
+
+  /**
+   * @brief Checks whether a child is selected
+   *
+   * @param childIndex index of the child
+   *
+   * @return true if given child is selected, false otherwise
+   */
+  virtual bool IsChildSelected(int childIndex) = 0;
+
+  /**
+   * @brief Selects all children
+   *
+   * @return true on success, false otherwise
+   */
+  virtual bool SelectAll() = 0;
+
+  /**
+   * @brief Deselects all children
+   *
+   * @return true on success, false otherwise
+   */
+  virtual bool ClearSelection() = 0;
+
+  /**
+   * @brief Deselects a child
+   *
+   * @param childIndex index of the child
+   *
+   * @return true on success, false otherwise
+   *
+   * @see Dali::Accessibility::Selection::DeselectSelectedChild
+   */
+  virtual bool DeselectChild(int childIndex) = 0;
+};
+
+/**
  * @brief minimalistic, always empty Accessible object with settable address
  *
  * For those situations, where you want to return address in different bridge
index 3a30b4b..b1bb36e 100644 (file)
@@ -55,6 +55,10 @@ std::vector<std::string> Accessible::GetInterfaces()
       tmp.push_back(AtspiDbusInterfaceAction);
     }
   }
+  if(dynamic_cast<Selection*>(this))
+  {
+    tmp.push_back(AtspiDbusInterfaceSelection);
+  }
   return tmp;
 }
 
index 85e6dc3..80b3fb4 100644 (file)
@@ -33,6 +33,7 @@
 #include <dali/internal/accessibility/bridge/bridge-component.h>
 #include <dali/internal/accessibility/bridge/bridge-editable-text.h>
 #include <dali/internal/accessibility/bridge/bridge-object.h>
+#include <dali/internal/accessibility/bridge/bridge-selection.h>
 #include <dali/internal/accessibility/bridge/bridge-text.h>
 #include <dali/internal/accessibility/bridge/bridge-value.h>
 #include <dali/internal/accessibility/bridge/dummy-atspi.h>
@@ -49,7 +50,8 @@ class BridgeImpl : public virtual BridgeBase,
                    public BridgeAction,
                    public BridgeValue,
                    public BridgeText,
-                   public BridgeEditableText
+                   public BridgeEditableText,
+                   public BridgeSelection
 {
   DBus::DBusClient                                              listenOnAtspiEnabledSignalClient;
   DBus::DBusClient                                              registryClient, directReadingClient;
@@ -242,6 +244,7 @@ public:
     BridgeValue::RegisterInterfaces();
     BridgeText::RegisterInterfaces();
     BridgeEditableText::RegisterInterfaces();
+    BridgeSelection::RegisterInterfaces();
 
     RegisterOnBridge(&application);
 
diff --git a/dali/internal/accessibility/bridge/bridge-selection.cpp b/dali/internal/accessibility/bridge/bridge-selection.cpp
new file mode 100644 (file)
index 0000000..949bc55
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/accessibility/bridge/bridge-selection.h>
+
+using namespace Dali::Accessibility;
+
+void BridgeSelection::RegisterInterfaces()
+{
+  DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceSelection};
+  AddGetPropertyToInterface(desc, "NSelectedChildren", &BridgeSelection::GetSelectedChildrenCount);
+  AddFunctionToInterface(desc, "GetSelectedChild", &BridgeSelection::GetSelectedChild);
+  AddFunctionToInterface(desc, "SelectChild", &BridgeSelection::SelectChild);
+  AddFunctionToInterface(desc, "DeselectSelectedChild", &BridgeSelection::DeselectSelectedChild);
+  AddFunctionToInterface(desc, "IsChildSelected", &BridgeSelection::IsChildSelected);
+  AddFunctionToInterface(desc, "SelectAll", &BridgeSelection::SelectAll);
+  AddFunctionToInterface(desc, "ClearSelection", &BridgeSelection::ClearSelection);
+  AddFunctionToInterface(desc, "DeselectChild", &BridgeSelection::DeselectChild);
+  dbusServer.addInterface("/", desc, true);
+}
+
+Selection* BridgeSelection::FindSelf() const
+{
+  auto s = BridgeBase::FindSelf();
+  assert(s);
+  auto s2 = dynamic_cast<Selection*>(s);
+  if(!s2)
+    throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Selection interface"};
+  return s2;
+}
+
+DBus::ValueOrError<int32_t> BridgeSelection::GetSelectedChildrenCount()
+{
+  return FindSelf()->GetSelectedChildrenCount();
+}
+
+DBus::ValueOrError<Dali::Accessibility::Accessible*> BridgeSelection::GetSelectedChild(int32_t selectedChildIndex)
+{
+  return FindSelf()->GetSelectedChild(selectedChildIndex);
+}
+
+DBus::ValueOrError<bool> BridgeSelection::SelectChild(int32_t childIndex)
+{
+  return FindSelf()->SelectChild(childIndex);
+}
+
+DBus::ValueOrError<bool> BridgeSelection::DeselectSelectedChild(int32_t selectedChildIndex)
+{
+  return FindSelf()->DeselectSelectedChild(selectedChildIndex);
+}
+
+DBus::ValueOrError<bool> BridgeSelection::IsChildSelected(int32_t childIndex)
+{
+  return FindSelf()->IsChildSelected(childIndex);
+}
+
+DBus::ValueOrError<bool> BridgeSelection::SelectAll()
+{
+  return FindSelf()->SelectAll();
+}
+
+DBus::ValueOrError<bool> BridgeSelection::ClearSelection()
+{
+  return FindSelf()->ClearSelection();
+}
+
+DBus::ValueOrError<bool> BridgeSelection::DeselectChild(int32_t childIndex)
+{
+  return FindSelf()->DeselectChild(childIndex);
+}
diff --git a/dali/internal/accessibility/bridge/bridge-selection.h b/dali/internal/accessibility/bridge/bridge-selection.h
new file mode 100644 (file)
index 0000000..ceb920d
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_SELECTION_H
+#define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_SELECTION_H
+
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/internal/accessibility/bridge/bridge-base.h>
+
+class BridgeSelection : public virtual BridgeBase
+{
+protected:
+  BridgeSelection() = default;
+
+  void RegisterInterfaces();
+
+  Dali::Accessibility::Selection* FindSelf() const;
+
+public:
+  DBus::ValueOrError<int32_t> GetSelectedChildrenCount();
+  DBus::ValueOrError<Dali::Accessibility::Accessible*> GetSelectedChild(int32_t selectedChildIndex);
+  DBus::ValueOrError<bool> SelectChild(int32_t childIndex);
+  DBus::ValueOrError<bool> DeselectSelectedChild(int32_t selectedChildIndex);
+  DBus::ValueOrError<bool> IsChildSelected(int32_t childIndex);
+  DBus::ValueOrError<bool> SelectAll();
+  DBus::ValueOrError<bool> ClearSelection();
+  DBus::ValueOrError<bool> DeselectChild(int32_t childIndex);
+};
+
+#endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_SELECTION_H
index bfdad24..e62ef56 100755 (executable)
@@ -57,6 +57,7 @@ SET( adaptor_accessibility_atspi_bridge_src_files
     ${adaptor_accessibility_dir}/bridge/bridge-editable-text.cpp
     ${adaptor_accessibility_dir}/bridge/bridge-impl.cpp
     ${adaptor_accessibility_dir}/bridge/bridge-object.cpp
+    ${adaptor_accessibility_dir}/bridge/bridge-selection.cpp
     ${adaptor_accessibility_dir}/bridge/bridge-text.cpp
     ${adaptor_accessibility_dir}/bridge/bridge-value.cpp
     ${adaptor_accessibility_dir}/bridge/component.cpp