[ATSPI] Implementation of Hypertext and Hyperlink in text controls
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-anchor-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_ANCHOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_ANCHOR_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/controls/text-controls/text-anchor-devel.h>
26 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
27 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 /**
36  * @brief A control which renders anchor (hyperlink) in hypertext.
37  */
38 class TextAnchor : public Control
39 {
40 public:
41   /**
42    * @copydoc Dali::Toollkit::TextAnchor::New()
43    */
44   static Toolkit::TextAnchor New();
45
46   // Properties
47
48   /**
49    * @brief Called when a property of an object of this type is set.
50    *
51    * @param[in] object The object whose property is set.
52    * @param[in] index The property index.
53    * @param[in] value The new property value.
54    */
55   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
56
57   /**
58    * @brief Called to retrieve a property of an object of this type.
59    *
60    * @param[in] object The object whose property is to be retrieved.
61    * @param[in] index The property index.
62    * @return The current value of the property.
63    */
64   static Property::Value GetProperty(BaseObject* object, Property::Index index);
65
66 private: // From Control
67   /**
68    * @copydoc Control::OnInitialize()
69    */
70   void OnInitialize() override;
71
72   /**
73    * @copydoc Control::OnPropertySet()
74    */
75   // void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
76
77   /**
78    * @copydoc Control::OnAccessibilityActivated()
79    */
80   bool OnAccessibilityActivated() override;
81
82 private: // Implementation
83   /**
84    * Construct a new TextAnchor.
85    */
86   TextAnchor();
87
88   /**
89    * A reference counted object may only be deleted by calling Unreference()
90    */
91   virtual ~TextAnchor();
92
93 private:
94   // Undefined copy constructor and assignment operators
95   TextAnchor(const TextAnchor&);
96   TextAnchor& operator=(const TextAnchor& rhs);
97
98   //Data
99   int         mStartCharacterIndex;
100   int         mEndCharacterIndex;
101   std::string mUri;
102
103 protected:
104   /**
105    * @brief This structure is to connect TextAnchor with Accessible functions.
106    */
107   struct AccessibleImpl : public DevelControl::AccessibleImpl,
108                           public virtual Dali::Accessibility::Hyperlink
109   {
110     using DevelControl::AccessibleImpl::AccessibleImpl;
111     /**
112      * @copydoc Dali::Accessibility::Hyperlink::GetEndIndex()
113      */
114     int32_t GetEndIndex() const override;
115
116     /**
117      * @copydoc Dali::Accessibility::Hyperlink::GetStartIndex()
118      */
119     int32_t GetStartIndex() const override;
120
121     /**
122      * @copydoc Dali::Accessibility::Hyperlink::GetAnchorCount()
123      */
124     int32_t GetAnchorCount() const override;
125
126     /**
127      * @copydoc Dali::Accessibility::Hyperlink::GetAnchorAccessible()
128      */
129     Accessible* GetAnchorAccessible(int32_t anchorIndex) const override;
130
131     /**
132      * @copydoc Dali::Accessibility::Hyperlink::GetAnchorUri()
133      */
134     std::string GetAnchorUri(int32_t anchorIndex) const override;
135
136     /**
137      * @copydoc Dali::Accessibility::Hyperlink::IsValid()
138      */
139     bool IsValid() const override;
140   };
141 };
142
143 inline Toolkit::Internal::TextAnchor& GetImpl(Toolkit::TextAnchor& textAnchor)
144 {
145   DALI_ASSERT_ALWAYS(textAnchor);
146
147   Dali::RefObject& handle = textAnchor.GetImplementation();
148
149   return static_cast<Toolkit::Internal::TextAnchor&>(handle);
150 }
151
152 inline const Toolkit::Internal::TextAnchor& GetImpl(const Toolkit::TextAnchor& textAnchor)
153 {
154   DALI_ASSERT_ALWAYS(textAnchor);
155
156   const Dali::RefObject& handle = textAnchor.GetImplementation();
157
158   return static_cast<const Toolkit::Internal::TextAnchor&>(handle);
159 }
160
161 } // namespace Internal
162
163 } // namespace Toolkit
164
165 } // namespace Dali
166
167 #endif // DALI_TOOLKIT_INTERNAL_TEXT_ANCHOR_H