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