[AT-SPI] Update #include paths to AT-SPI interfaces
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_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/devel-api/atspi-interfaces/hypertext.h>
23 #include <dali/devel-api/atspi-interfaces/text.h>
24 #include <dali/public-api/object/property-map.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
30 #include <dali-toolkit/internal/text/text-control-interface.h>
31 #include <dali-toolkit/internal/text/text-controller.h>
32 #include <dali-toolkit/internal/text/text-scroller-interface.h>
33 #include <dali-toolkit/internal/text/text-scroller.h>
34 #include <dali-toolkit/internal/visuals/text/text-visual.h>
35 #include <dali-toolkit/public-api/controls/control-impl.h>
36 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
37
38 namespace Dali
39 {
40 namespace Toolkit
41 {
42 namespace Internal
43 {
44 /**
45  * @brief A control which renders a short text string.
46  */
47 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface, public Text::AnchorControlInterface
48 {
49 public:
50   /**
51    * @copydoc Dali::Toollkit::TextLabel::New()
52    */
53   static Toolkit::TextLabel New();
54
55   // Properties
56
57   /**
58    * @brief Called when a property of an object of this type is set.
59    *
60    * @param[in] object The object whose property is set.
61    * @param[in] index The property index.
62    * @param[in] value The new property value.
63    */
64   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
65
66   /**
67    * @brief Called to retrieve a property of an object of this type.
68    *
69    * @param[in] object The object whose property is to be retrieved.
70    * @param[in] index The property index.
71    * @return The current value of the property.
72    */
73   static Property::Value GetProperty(BaseObject* object, Property::Index index);
74
75   /**
76    * @copydoc Dali::Toollkit::TextLabel::AnchorClickedSignal()
77    */
78   DevelTextLabel::AnchorClickedSignalType& AnchorClickedSignal();
79
80   /**
81    * @copydoc Dali::Toollkit::TextLabel::TextFitChangedSignal()
82    */
83   DevelTextLabel::TextFitChangedSignalType& TextFitChangedSignal();
84
85   /**
86    * Connects a callback function with the object's signals.
87    * @param[in] object The object providing the signal.
88    * @param[in] tracker Used to disconnect the signal.
89    * @param[in] signalName The signal to connect to.
90    * @param[in] functor A newly allocated FunctorDelegate.
91    * @return True if the signal was connected.
92    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
93    */
94   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
95
96   /**
97    * @brief Gets text controller
98    *
99    * @return The text controller
100    */
101   Text::ControllerPtr GetTextController();
102
103   /**
104    * @brief Get the rendered size of a specific text range.
105    * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
106    * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
107    *
108    * @param[in] startIndex start index of the text requested to calculate size for.
109    * @param[in] endIndex end index(included) of the text requested to calculate size for.
110    * @return list of sizes of the reuested text.
111    */
112   Vector<Vector2> GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const;
113
114   /**
115    * @brief Get the top/left rendered position of a specific text range.
116    * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
117    * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
118    *
119    * @param[in] startIndex start index of the text requested to get position to.
120    * @param[in] endIndex end index(included) of the text requested to get position to.
121    * @return list of positions of the requested text.
122    */
123   Vector<Vector2> GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const;
124
125 private: // From Control
126   /**
127    * @copydoc Control::OnInitialize()
128    */
129   void OnInitialize() override;
130
131   /**
132    * @copydoc Control::OnStyleChange()
133    */
134   void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
135
136   /**
137    * @copydoc Control::OnRelayout()
138    */
139   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
140
141   /**
142    * @copydoc Control::OnTap()
143    */
144   void OnTap(const TapGesture& tap) override;
145
146   /**
147    * @copydoc Control::GetNaturalSize()
148    */
149   Vector3 GetNaturalSize() override;
150
151   /**
152    * @copydoc Control::GetHeightForWidth()
153    */
154   float GetHeightForWidth(float width) override;
155
156   /**
157    * @copydoc Control::OnPropertySet()
158    */
159   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
160
161   // From ControlInterface
162
163   /**
164    * @copydoc Text::ControlInterface::RequestTextRelayout()
165    */
166   void RequestTextRelayout() override;
167
168 private: // from TextScroller
169   /**
170    * @copydoc Text::ScrollerInterface::ScrollingFinished()
171    */
172   void ScrollingFinished() override;
173
174 public: // From AnchorControlInterface
175   /**
176    * @copydoc Text::AnchorControlInterface::AnchorClicked()
177    */
178   void AnchorClicked(const std::string& href) override;
179
180 private: // Implementation
181   /**
182    * Construct a new TextLabel.
183    */
184   TextLabel();
185
186   /**
187    * A reference counted object may only be deleted by calling Unreference()
188    */
189   virtual ~TextLabel();
190
191 private:
192   // Undefined copy constructor and assignment operators
193   TextLabel(const TextLabel&);
194   TextLabel& operator=(const TextLabel& rhs);
195
196   /**
197    * @brief Set up Autoscrolling
198    */
199   void SetUpAutoScrolling();
200
201   /**
202    * Creates a text-scroller if one has not been created.
203    * @return The text scroller.
204    */
205   Text::TextScrollerPtr GetTextScroller()
206   {
207     if(!mTextScroller)
208     {
209       mTextScroller = Text::TextScroller::New(*this);
210     }
211     return mTextScroller;
212   }
213
214   /**
215    * @brief Callback function for when the layout is changed.
216    * @param[in] actor The actor whose layoutDirection is changed.
217    * @param[in] type  The layoutDirection.
218    */
219   void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
220
221   /**
222    * @brief Emits TextFitChanged signal.
223    */
224   void EmitTextFitChangedSignal();
225   void OnAccessibilityStatusChanged();
226
227 private: // Data
228   Text::ControllerPtr   mController;
229   Text::TextScrollerPtr mTextScroller;
230
231   Toolkit::Visual::Base mVisual;
232
233   std::vector<Toolkit::TextAnchor> mAnchorActors;
234
235   // Signals
236   Toolkit::DevelTextLabel::AnchorClickedSignalType  mAnchorClickedSignal;
237   Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal;
238
239   int  mRenderingBackend;
240   bool mTextUpdateNeeded : 1;
241
242 protected:
243   /**
244    * @brief This structure is to connect TextLabel with Accessible functions.
245    */
246   struct AccessibleImpl : public DevelControl::AccessibleImpl,
247                           public virtual Dali::Accessibility::Text,
248                           public virtual Dali::Accessibility::Hypertext
249   {
250     using DevelControl::AccessibleImpl::AccessibleImpl;
251
252     /**
253      * @copydoc Dali::Accessibility::Text::GetText()
254      */
255     std::string GetText(size_t startOffset, size_t endOffset) override;
256
257     /**
258      * @copydoc Dali::Accessibility::Text::GetCharacterCount()
259      */
260     size_t GetCharacterCount() override;
261
262     /**
263      * @copydoc Dali::Accessibility::Text::GetCursorOffset()
264      */
265     size_t GetCursorOffset() override;
266
267     /**
268      * @copydoc Dali::Accessibility::Text::SetCursorOffset()
269      */
270     bool SetCursorOffset(size_t offset) override;
271
272     /**
273      * @copydoc Dali::Accessibility::Text::GetTextAtOffset()
274      */
275     Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
276
277     /**
278      * @copydoc Dali::Accessibility::Text::GetRangeOfSelection()
279      */
280     Accessibility::Range GetRangeOfSelection(size_t selectionIndex) override;
281
282     /**
283      * @copydoc Dali::Accessibility::Text::RemoveSelection()
284      */
285     bool RemoveSelection(size_t selectionIndex) override;
286
287     /**
288      * @copydoc Dali::Accessibility::Text::SetRangeOfSelection()
289      */
290     bool SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset) override;
291
292     /**
293      * @copydoc Dali::Accessibility::Text::GetNameRaw()
294      */
295     std::string GetNameRaw() override;
296
297     /**
298      * @copydoc Dali::Accessibility::Text::GetNamePropertyIndex()
299      */
300     Property::Index GetNamePropertyIndex() override;
301
302     /**
303      * @copydoc Dali::Accessibility::Hypertext::GetLink()
304      */
305     Accessibility::Hyperlink* GetLink(int32_t linkIndex) const override;
306
307     /**
308      * @copydoc Dali::Accessibility::Hypertext::GetLinkIndex()
309      */
310     int32_t GetLinkIndex(int32_t characterOffset) const override;
311
312     /**
313      * @copydoc Dali::Accessibility::Hypertext::GetLinkCount()
314      */
315     int32_t GetLinkCount() const override;
316   };
317 };
318
319 } // namespace Internal
320
321 // Helpers for public-api forwarding methods
322
323 inline Toolkit::Internal::TextLabel& GetImpl(Toolkit::TextLabel& textLabel)
324 {
325   DALI_ASSERT_ALWAYS(textLabel);
326
327   Dali::RefObject& handle = textLabel.GetImplementation();
328
329   return static_cast<Toolkit::Internal::TextLabel&>(handle);
330 }
331
332 inline const Toolkit::Internal::TextLabel& GetImpl(const Toolkit::TextLabel& textLabel)
333 {
334   DALI_ASSERT_ALWAYS(textLabel);
335
336   const Dali::RefObject& handle = textLabel.GetImplementation();
337
338   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
339 }
340
341 } // namespace Toolkit
342
343 } // namespace Dali
344
345 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H