From 66f123a1c2a1be3b788c65dbd49e59ff0b58c3e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Artur=20=C5=9Awigo=C5=84?= Date: Thu, 27 May 2021 15:31:47 +0200 Subject: [PATCH] [AT-SPI] Add Selection interface Change-Id: I893f79a9ccfb7e39fb257a798c297dc22f107cea --- .../adaptor-framework/accessibility-impl.h | 83 +++++++++++++++++++++ dali/internal/accessibility/bridge/accessible.cpp | 4 + dali/internal/accessibility/bridge/bridge-impl.cpp | 5 +- .../accessibility/bridge/bridge-selection.cpp | 85 ++++++++++++++++++++++ .../accessibility/bridge/bridge-selection.h | 44 +++++++++++ dali/internal/accessibility/file.list | 1 + 6 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 dali/internal/accessibility/bridge/bridge-selection.cpp create mode 100644 dali/internal/accessibility/bridge/bridge-selection.h diff --git a/dali/devel-api/adaptor-framework/accessibility-impl.h b/dali/devel-api/adaptor-framework/accessibility-impl.h index cb7c0b3..f8032fc 100644 --- a/dali/devel-api/adaptor-framework/accessibility-impl.h +++ b/dali/devel-api/adaptor-framework/accessibility-impl.h @@ -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 diff --git a/dali/internal/accessibility/bridge/accessible.cpp b/dali/internal/accessibility/bridge/accessible.cpp index 3a30b4b..b1bb36e 100644 --- a/dali/internal/accessibility/bridge/accessible.cpp +++ b/dali/internal/accessibility/bridge/accessible.cpp @@ -55,6 +55,10 @@ std::vector Accessible::GetInterfaces() tmp.push_back(AtspiDbusInterfaceAction); } } + if(dynamic_cast(this)) + { + tmp.push_back(AtspiDbusInterfaceSelection); + } return tmp; } diff --git a/dali/internal/accessibility/bridge/bridge-impl.cpp b/dali/internal/accessibility/bridge/bridge-impl.cpp index 85e6dc3..80b3fb4 100644 --- a/dali/internal/accessibility/bridge/bridge-impl.cpp +++ b/dali/internal/accessibility/bridge/bridge-impl.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -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 index 0000000..949bc55 --- /dev/null +++ b/dali/internal/accessibility/bridge/bridge-selection.cpp @@ -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 + +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(s); + if(!s2) + throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Selection interface"}; + return s2; +} + +DBus::ValueOrError BridgeSelection::GetSelectedChildrenCount() +{ + return FindSelf()->GetSelectedChildrenCount(); +} + +DBus::ValueOrError BridgeSelection::GetSelectedChild(int32_t selectedChildIndex) +{ + return FindSelf()->GetSelectedChild(selectedChildIndex); +} + +DBus::ValueOrError BridgeSelection::SelectChild(int32_t childIndex) +{ + return FindSelf()->SelectChild(childIndex); +} + +DBus::ValueOrError BridgeSelection::DeselectSelectedChild(int32_t selectedChildIndex) +{ + return FindSelf()->DeselectSelectedChild(selectedChildIndex); +} + +DBus::ValueOrError BridgeSelection::IsChildSelected(int32_t childIndex) +{ + return FindSelf()->IsChildSelected(childIndex); +} + +DBus::ValueOrError BridgeSelection::SelectAll() +{ + return FindSelf()->SelectAll(); +} + +DBus::ValueOrError BridgeSelection::ClearSelection() +{ + return FindSelf()->ClearSelection(); +} + +DBus::ValueOrError 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 index 0000000..ceb920d --- /dev/null +++ b/dali/internal/accessibility/bridge/bridge-selection.h @@ -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 + +class BridgeSelection : public virtual BridgeBase +{ +protected: + BridgeSelection() = default; + + void RegisterInterfaces(); + + Dali::Accessibility::Selection* FindSelf() const; + +public: + DBus::ValueOrError GetSelectedChildrenCount(); + DBus::ValueOrError GetSelectedChild(int32_t selectedChildIndex); + DBus::ValueOrError SelectChild(int32_t childIndex); + DBus::ValueOrError DeselectSelectedChild(int32_t selectedChildIndex); + DBus::ValueOrError IsChildSelected(int32_t childIndex); + DBus::ValueOrError SelectAll(); + DBus::ValueOrError ClearSelection(); + DBus::ValueOrError DeselectChild(int32_t childIndex); +}; + +#endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_SELECTION_H diff --git a/dali/internal/accessibility/file.list b/dali/internal/accessibility/file.list index bfdad24..e62ef56 100755 --- a/dali/internal/accessibility/file.list +++ b/dali/internal/accessibility/file.list @@ -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 -- 2.7.4