[ATSPI] Hypertext and Hyperlink interface support - dbus glue-code 58/263758/17
authorLukasz Oleksak <l.oleksak@samsung.com>
Thu, 9 Sep 2021 10:26:42 +0000 (12:26 +0200)
committerLukasz Oleksak <l.oleksak@samsung.com>
Mon, 22 Nov 2021 09:06:39 +0000 (09:06 +0000)
Change-Id: I76987be672b6fba5c994b909973385f4defdeef8

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

index 5b05489..fed9592 100644 (file)
@@ -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
index 9cd65a3..52fa3f4 100644 (file)
@@ -59,6 +59,14 @@ std::vector<std::string> Accessible::GetInterfaces()
   {
     tmp.push_back(AtspiDbusInterfaceSelection);
   }
+  if(dynamic_cast<Hypertext*>(this))
+  {
+    tmp.push_back(AtspiDbusInterfaceHypertext);
+  }
+  if(dynamic_cast<Hyperlink*>(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 (file)
index 0000000..4395ff0
--- /dev/null
@@ -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 <string>
+
+// INTERNAL INCLUDES
+#include <dali/internal/accessibility/bridge/bridge-hyperlink.h>
+
+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<Hyperlink*>(self);
+  if(!hyperlinkInterface)
+  {
+    throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Hyperlink interface"};
+  }
+  return hyperlinkInterface;
+}
+
+DBus::ValueOrError<int32_t> BridgeHyperlink::GetEndIndex()
+{
+  return FindSelf()->GetEndIndex();
+}
+
+DBus::ValueOrError<int32_t> BridgeHyperlink::GetStartIndex()
+{
+  return FindSelf()->GetStartIndex();
+}
+
+DBus::ValueOrError<int32_t> BridgeHyperlink::GetAnchorCount()
+{
+  return FindSelf()->GetAnchorCount();
+}
+
+DBus::ValueOrError<Dali::Accessibility::Accessible*> BridgeHyperlink::GetAnchorAccessible(int32_t anchorIndex)
+{
+  return FindSelf()->GetAnchorAccessible(anchorIndex);
+}
+
+DBus::ValueOrError<std::string> BridgeHyperlink::GetAnchorUri(int32_t anchorIndex)
+{
+  return FindSelf()->GetAnchorUri(anchorIndex);
+}
+
+DBus::ValueOrError<bool> 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 (file)
index 0000000..0b00356
--- /dev/null
@@ -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 <dali/internal/accessibility/bridge/bridge-base.h>
+
+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<int32_t> GetEndIndex();
+
+  /**
+   * @copydoc Dali::Accessibility::Hyperlink::GetStartIndex()
+   */
+  DBus::ValueOrError<int32_t> GetStartIndex();
+
+  /**
+   * @copydoc Dali::Accessibility::Hyperlink::GetAnchorCount()
+   */
+  DBus::ValueOrError<int32_t> GetAnchorCount();
+
+  /**
+   * @copydoc Dali::Accessibility::Hyperlink::GetAnchorAccessible()
+   */
+  DBus::ValueOrError<Dali::Accessibility::Accessible*> GetAnchorAccessible(int32_t anchorIndex);
+
+  /**
+   * @copydoc Dali::Accessibility::Hyperlink::GetAnchorUri()
+   */
+  DBus::ValueOrError<std::string> GetAnchorUri(int32_t anchorIndex);
+
+  /**
+   * @copydoc Dali::Accessibility::Hyperlink::IsValid()
+   */
+  DBus::ValueOrError<bool> 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 (file)
index 0000000..3a42d8d
--- /dev/null
@@ -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 <string>
+
+// INTERNAL INCLUDES
+#include <dali/internal/accessibility/bridge/bridge-hypertext.h>
+
+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<Hypertext*>(self);
+  if(!hypertextInterface)
+  {
+    throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Hypertext interface"};
+  }
+  return hypertextInterface;
+}
+
+DBus::ValueOrError<int32_t> BridgeHypertext::GetLinkCount()
+{
+  return FindSelf()->GetLinkCount();
+}
+
+DBus::ValueOrError<Dali::Accessibility::Accessible*> BridgeHypertext::GetLink(int32_t linkIndex)
+{
+  return FindSelf()->GetLink(linkIndex);
+}
+
+DBus::ValueOrError<int32_t> 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 (file)
index 0000000..c39c5f8
--- /dev/null
@@ -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 <dali/internal/accessibility/bridge/bridge-base.h>
+
+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<Dali::Accessibility::Accessible*> GetLink(int32_t linkIndex);
+
+  /**
+   * @copydoc Dali::Accessibility::Hypertext::GetLinkIndex()
+   */
+  DBus::ValueOrError<int32_t> GetLinkIndex(int32_t characterOffset);
+
+  /**
+   * @copydoc Dali::Accessibility::Hypertext::GetLinkCount()
+   */
+  DBus::ValueOrError<int32_t> GetLinkCount();
+};
+
+#endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_HYPERTEXT_H
\ No newline at end of file
index b5c275e..cf6cfea 100644 (file)
@@ -32,6 +32,8 @@
 #include <dali/internal/accessibility/bridge/bridge-collection.h>
 #include <dali/internal/accessibility/bridge/bridge-component.h>
 #include <dali/internal/accessibility/bridge/bridge-editable-text.h>
+#include <dali/internal/accessibility/bridge/bridge-hypertext.h>
+#include <dali/internal/accessibility/bridge/bridge-hyperlink.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>
@@ -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);
 
index efa4476..59ffcc2 100755 (executable)
@@ -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