From d1b4e5cbfbb76d6b74bda7c9c4f021acfd452053 Mon Sep 17 00:00:00 2001 From: Lukasz Oleksak Date: Thu, 9 Sep 2021 12:26:42 +0200 Subject: [PATCH] [ATSPI] Hypertext and Hyperlink interface support - dbus glue-code Change-Id: I76987be672b6fba5c994b909973385f4defdeef8 --- .../adaptor-framework/accessibility-impl.h | 87 ++++++++++++++++++++++ dali/internal/accessibility/bridge/accessible.cpp | 8 ++ .../accessibility/bridge/bridge-hyperlink.cpp | 78 +++++++++++++++++++ .../accessibility/bridge/bridge-hyperlink.h | 73 ++++++++++++++++++ .../accessibility/bridge/bridge-hypertext.cpp | 60 +++++++++++++++ .../accessibility/bridge/bridge-hypertext.h | 58 +++++++++++++++ dali/internal/accessibility/bridge/bridge-impl.cpp | 8 +- dali/internal/accessibility/file.list | 2 + 8 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 dali/internal/accessibility/bridge/bridge-hyperlink.cpp create mode 100644 dali/internal/accessibility/bridge/bridge-hyperlink.h create mode 100644 dali/internal/accessibility/bridge/bridge-hypertext.cpp create mode 100644 dali/internal/accessibility/bridge/bridge-hypertext.h diff --git a/dali/devel-api/adaptor-framework/accessibility-impl.h b/dali/devel-api/adaptor-framework/accessibility-impl.h index 5b05489..fed9592 100644 --- a/dali/devel-api/adaptor-framework/accessibility-impl.h +++ b/dali/devel-api/adaptor-framework/accessibility-impl.h @@ -49,6 +49,8 @@ class DALI_ADAPTOR_API Component; class DALI_ADAPTOR_API Collection; class DALI_ADAPTOR_API Action; class DALI_ADAPTOR_API Application; +class DALI_ADAPTOR_API Hypertext; +class DALI_ADAPTOR_API Hyperlink; /** * @brief Base class for different accessibility bridges. @@ -1256,6 +1258,91 @@ public: }; /** + * @brief Interface representing hypertext that can store a collection of hyperlinks. + */ +class Hypertext : public virtual Accessible +{ +public: + /** + * @brief Gets the handle to hyperlink object from a specified index in hyperlink collection of this hypertext. + * + * @param[in] linkIndex The 0-based index in hyperlink collection. + * + * @return Handle to hyperlink object at a specified index in hyperlink collection of hypertext. + */ + virtual Hyperlink* GetLink(int32_t linkIndex) const = 0; + + /** + * @brief Gets the index in hyperlink collection occupied by hyperlink which spans over a specified character offset in this hypertext. + * + * @param[in] characterOffset The 0-based index of character in hypertext. + * + * @return The value of 0-based index in hyperlink collection (-1 if there is no hyperlink at the specified character offset). + */ + virtual int32_t GetLinkIndex(int32_t characterOffset) const = 0; + + /** + * @brief Gets number of hyperlinks stored in this hypertext. + * + * @return The number of hyperlinks (zero if none or -1 if the number cannot be determined) + */ + virtual int32_t GetLinkCount() const = 0; +}; + +/** + * @brief Interface representing a hyperlink in hypertext . + */ +class Hyperlink : public virtual Accessible +{ +public: + /** + * @brief Gets the index of character in originating hypertext at which this hyperlink ends. + * + * @return The 0-based index of hyperlink's last character + 1, in its originating hypertext. + */ + virtual int32_t GetEndIndex() const = 0; + + /** + * @brief Gets the index of character in originating hypertext at which this hyperlink starts. + * + * @return The 0-based index of hyperlink's first character, in its originating hypertext. + */ + virtual int32_t GetStartIndex() const = 0; + + /** + * @brief Gets the total number of anchors which this hyperlink has. Though, typical hyperlinks will have only one anchor. + * + * @return The number of anchors. + */ + virtual int32_t GetAnchorCount() const = 0; + + /** + * @brief Gets the object associated with a particular hyperlink's anchor. + * + * @param[in] anchorIndex The 0-based index in anchor collection. + * + * @return The handle to accessible object. + */ + virtual Accessible* GetAnchorAccessible(int32_t anchorIndex) const = 0; + + /** + * @brief Gets the URI associated with a particular hyperlink's anchor. + * + * @param[in] anchorIndex The 0-based index in anchor collection. + * + * @return The string containing URI. + */ + virtual std::string GetAnchorUri(int32_t anchorIndex) const = 0; + + /** + * @brief Tells whether this hyperlink object is still valid with respect to its originating hypertext object. + * + * @return True if hyperlink object is valid, false otherwise + */ + virtual bool IsValid() const = 0; +}; + +/** * @brief Interface representing objects which can store a set of selected items. */ class DALI_ADAPTOR_API Selection : public virtual Accessible diff --git a/dali/internal/accessibility/bridge/accessible.cpp b/dali/internal/accessibility/bridge/accessible.cpp index 9cd65a3..52fa3f4 100644 --- a/dali/internal/accessibility/bridge/accessible.cpp +++ b/dali/internal/accessibility/bridge/accessible.cpp @@ -59,6 +59,14 @@ std::vector Accessible::GetInterfaces() { tmp.push_back(AtspiDbusInterfaceSelection); } + if(dynamic_cast(this)) + { + tmp.push_back(AtspiDbusInterfaceHypertext); + } + if(dynamic_cast(this)) + { + tmp.push_back(AtspiDbusInterfaceHyperlink); + } return tmp; } diff --git a/dali/internal/accessibility/bridge/bridge-hyperlink.cpp b/dali/internal/accessibility/bridge/bridge-hyperlink.cpp new file mode 100644 index 0000000..4395ff0 --- /dev/null +++ b/dali/internal/accessibility/bridge/bridge-hyperlink.cpp @@ -0,0 +1,78 @@ +/* + * 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. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + +using namespace Dali::Accessibility; + +void BridgeHyperlink::RegisterInterfaces() +{ + DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceHyperlink}; + AddGetPropertyToInterface(desc, "NAnchors", &BridgeHyperlink::GetAnchorCount); + AddGetPropertyToInterface(desc, "StartIndex", &BridgeHyperlink::GetStartIndex); + AddGetPropertyToInterface(desc, "EndIndex", &BridgeHyperlink::GetEndIndex); + AddFunctionToInterface(desc, "GetObject", &BridgeHyperlink::GetAnchorAccessible); + AddFunctionToInterface(desc, "GetURI", &BridgeHyperlink::GetAnchorUri); + AddFunctionToInterface(desc, "IsValid", &BridgeHyperlink::IsValid); + mDbusServer.addInterface("/", desc, true); +} + +Hyperlink* BridgeHyperlink::FindSelf() const +{ + auto self = BridgeBase::FindSelf(); + assert(self); + auto hyperlinkInterface = dynamic_cast(self); + if(!hyperlinkInterface) + { + throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Hyperlink interface"}; + } + return hyperlinkInterface; +} + +DBus::ValueOrError BridgeHyperlink::GetEndIndex() +{ + return FindSelf()->GetEndIndex(); +} + +DBus::ValueOrError BridgeHyperlink::GetStartIndex() +{ + return FindSelf()->GetStartIndex(); +} + +DBus::ValueOrError BridgeHyperlink::GetAnchorCount() +{ + return FindSelf()->GetAnchorCount(); +} + +DBus::ValueOrError BridgeHyperlink::GetAnchorAccessible(int32_t anchorIndex) +{ + return FindSelf()->GetAnchorAccessible(anchorIndex); +} + +DBus::ValueOrError BridgeHyperlink::GetAnchorUri(int32_t anchorIndex) +{ + return FindSelf()->GetAnchorUri(anchorIndex); +} + +DBus::ValueOrError BridgeHyperlink::IsValid() +{ + return FindSelf()->IsValid(); +} diff --git a/dali/internal/accessibility/bridge/bridge-hyperlink.h b/dali/internal/accessibility/bridge/bridge-hyperlink.h new file mode 100644 index 0000000..0b00356 --- /dev/null +++ b/dali/internal/accessibility/bridge/bridge-hyperlink.h @@ -0,0 +1,73 @@ +#ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERLINK_H +#define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERLINK_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 BridgeHyperlink : public virtual BridgeBase +{ +protected: + BridgeHyperlink() = default; + + /** + * @brief Registers Hyperlink functions to dbus interfaces. + */ + void RegisterInterfaces(); + + /** + * @brief Returns the Hyperlink object of the currently executed DBus method call. + * + * @return The Hyperlink object + */ + Dali::Accessibility::Hyperlink* FindSelf() const; + +public: + /** + * @copydoc Dali::Accessibility::Hyperlink::GetEndIndex() + */ + DBus::ValueOrError GetEndIndex(); + + /** + * @copydoc Dali::Accessibility::Hyperlink::GetStartIndex() + */ + DBus::ValueOrError GetStartIndex(); + + /** + * @copydoc Dali::Accessibility::Hyperlink::GetAnchorCount() + */ + DBus::ValueOrError GetAnchorCount(); + + /** + * @copydoc Dali::Accessibility::Hyperlink::GetAnchorAccessible() + */ + DBus::ValueOrError GetAnchorAccessible(int32_t anchorIndex); + + /** + * @copydoc Dali::Accessibility::Hyperlink::GetAnchorUri() + */ + DBus::ValueOrError GetAnchorUri(int32_t anchorIndex); + + /** + * @copydoc Dali::Accessibility::Hyperlink::IsValid() + */ + DBus::ValueOrError IsValid(); +}; + +#endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERLINK_H diff --git a/dali/internal/accessibility/bridge/bridge-hypertext.cpp b/dali/internal/accessibility/bridge/bridge-hypertext.cpp new file mode 100644 index 0000000..3a42d8d --- /dev/null +++ b/dali/internal/accessibility/bridge/bridge-hypertext.cpp @@ -0,0 +1,60 @@ +/* + * 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. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + +using namespace Dali::Accessibility; + +void BridgeHypertext::RegisterInterfaces() +{ + DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceHypertext}; + AddFunctionToInterface(desc, "GetNLinks", &BridgeHypertext::GetLinkCount); + AddFunctionToInterface(desc, "GetLink", &BridgeHypertext::GetLink); + AddFunctionToInterface(desc, "GetLinkIndex", &BridgeHypertext::GetLinkIndex); + mDbusServer.addInterface("/", desc, true); +} + +Hypertext* BridgeHypertext::FindSelf() const +{ + auto self = BridgeBase::FindSelf(); + assert(self); + auto hypertextInterface = dynamic_cast(self); + if(!hypertextInterface) + { + throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Hypertext interface"}; + } + return hypertextInterface; +} + +DBus::ValueOrError BridgeHypertext::GetLinkCount() +{ + return FindSelf()->GetLinkCount(); +} + +DBus::ValueOrError BridgeHypertext::GetLink(int32_t linkIndex) +{ + return FindSelf()->GetLink(linkIndex); +} + +DBus::ValueOrError BridgeHypertext::GetLinkIndex(int32_t characterOffset) +{ + return FindSelf()->GetLinkIndex(characterOffset); +} \ No newline at end of file diff --git a/dali/internal/accessibility/bridge/bridge-hypertext.h b/dali/internal/accessibility/bridge/bridge-hypertext.h new file mode 100644 index 0000000..c39c5f8 --- /dev/null +++ b/dali/internal/accessibility/bridge/bridge-hypertext.h @@ -0,0 +1,58 @@ +#ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERTEXT_H +#define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERTEXT_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 BridgeHypertext : public virtual BridgeBase +{ +protected: + BridgeHypertext() = default; + + /** + * @brief Registers Hypertext functions to dbus interfaces. + */ + void RegisterInterfaces(); + + /** + * @brief Returns the Hypertext object of the currently executed DBus method call. + * + * @return The Hypertext object + */ + Dali::Accessibility::Hypertext* FindSelf() const; + +public: + /** + * @copydoc Dali::Accessibility::Hypertext::GetLink() + */ + DBus::ValueOrError GetLink(int32_t linkIndex); + + /** + * @copydoc Dali::Accessibility::Hypertext::GetLinkIndex() + */ + DBus::ValueOrError GetLinkIndex(int32_t characterOffset); + + /** + * @copydoc Dali::Accessibility::Hypertext::GetLinkCount() + */ + DBus::ValueOrError GetLinkCount(); +}; + +#endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERTEXT_H \ No newline at end of file diff --git a/dali/internal/accessibility/bridge/bridge-impl.cpp b/dali/internal/accessibility/bridge/bridge-impl.cpp index b5c275e..cf6cfea 100644 --- a/dali/internal/accessibility/bridge/bridge-impl.cpp +++ b/dali/internal/accessibility/bridge/bridge-impl.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -56,7 +58,9 @@ class BridgeImpl : public virtual BridgeBase, public BridgeText, public BridgeEditableText, public BridgeSelection, - public BridgeApplication + public BridgeApplication, + public BridgeHypertext, + public BridgeHyperlink { DBus::DBusClient mAccessibilityStatusClient; DBus::DBusClient mRegistryClient; @@ -261,6 +265,8 @@ public: BridgeEditableText::RegisterInterfaces(); BridgeSelection::RegisterInterfaces(); BridgeApplication::RegisterInterfaces(); + BridgeHypertext::RegisterInterfaces(); + BridgeHyperlink::RegisterInterfaces(); RegisterOnBridge(&mApplication); diff --git a/dali/internal/accessibility/file.list b/dali/internal/accessibility/file.list index efa4476..59ffcc2 100755 --- a/dali/internal/accessibility/file.list +++ b/dali/internal/accessibility/file.list @@ -56,6 +56,8 @@ SET( adaptor_accessibility_atspi_bridge_src_files ${adaptor_accessibility_dir}/bridge/bridge-collection.cpp ${adaptor_accessibility_dir}/bridge/bridge-component.cpp ${adaptor_accessibility_dir}/bridge/bridge-editable-text.cpp + ${adaptor_accessibility_dir}/bridge/bridge-hyperlink.cpp + ${adaptor_accessibility_dir}/bridge/bridge-hypertext.cpp ${adaptor_accessibility_dir}/bridge/bridge-impl.cpp ${adaptor_accessibility_dir}/bridge/bridge-object.cpp ${adaptor_accessibility_dir}/bridge/bridge-selection.cpp -- 2.7.4