Merge "Improve asynchronous SVG loading performance" into devel/master
[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) 2020 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/public-api/object/property-map.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
27 #include <dali-toolkit/internal/text/text-control-interface.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29 #include <dali-toolkit/internal/text/text-scroller-interface.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-scroller.h>
32 #include <dali-toolkit/internal/visuals/text/text-visual.h>
33 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
34
35
36 namespace Dali
37 {
38
39 namespace Toolkit
40 {
41
42 namespace Internal
43 {
44
45 /**
46  * @brief A control which renders a short text string.
47  */
48 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
49 {
50 public:
51
52   /**
53    * @copydoc Dali::Toollkit::TextLabel::New()
54    */
55   static Toolkit::TextLabel New();
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   Text::ControllerPtr getController();
78
79 private: // From Control
80
81   /**
82    * @copydoc Control::OnInitialize()
83    */
84   void OnInitialize() override;
85
86   /**
87    * @copydoc Control::OnStyleChange()
88    */
89   void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
90
91   /**
92    * @copydoc Control::OnRelayout()
93    */
94   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
95
96   /**
97    * @copydoc Control::GetNaturalSize()
98    */
99   Vector3 GetNaturalSize() override;
100
101   /**
102    * @copydoc Control::GetHeightForWidth()
103    */
104   float GetHeightForWidth( float width ) override;
105
106   /**
107    * @copydoc Control::OnPropertySet()
108    */
109   void OnPropertySet( Property::Index index, const Property::Value& propertyValue ) override ;
110
111   // From ControlInterface
112
113   /**
114    * @copydoc Text::ControlInterface::RequestTextRelayout()
115    */
116   void RequestTextRelayout() override;
117
118 private: // from TextScroller
119
120   /**
121    * @copydoc Text::ScrollerInterface::ScrollingFinished()
122    */
123   void ScrollingFinished() override;
124
125 private: // Implementation
126
127   /**
128    * Construct a new TextLabel.
129    */
130   TextLabel();
131
132   /**
133    * A reference counted object may only be deleted by calling Unreference()
134    */
135   virtual ~TextLabel();
136
137 private:
138
139   // Undefined copy constructor and assignment operators
140   TextLabel(const TextLabel&);
141   TextLabel& operator=(const TextLabel& rhs);
142
143   /**
144    * @brief Set up Autoscrolling
145    */
146   void SetUpAutoScrolling();
147
148   /**
149    * Creates a text-scroller if one has not been created.
150    * @return The text scroller.
151    */
152   Text::TextScrollerPtr GetTextScroller()
153   {
154     if( !mTextScroller )
155     {
156       mTextScroller = Text::TextScroller::New( *this );
157     }
158     return mTextScroller;
159   }
160
161 private: // Data
162
163   Text::ControllerPtr mController;
164   Text::TextScrollerPtr mTextScroller;
165
166   Toolkit::Visual::Base mVisual;
167
168   int mRenderingBackend;
169   bool mTextUpdateNeeded:1;
170
171 protected:
172   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
173                           public virtual Dali::Accessibility::Text
174   {
175     using Control::Impl::AccessibleImpl::AccessibleImpl;
176
177     std::string GetText( size_t startOffset, size_t endOffset ) override;
178     size_t GetCharacterCount() override;
179     size_t GetCaretOffset() override;
180     bool SetCaretOffset(size_t offset) override;
181     Dali::Accessibility::Range
182     GetTextAtOffset( size_t offset,
183                      Dali::Accessibility::TextBoundary boundary ) override;
184     Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
185     bool RemoveSelection( size_t selectionNum ) override;
186     bool SetSelection( size_t selectionNum, size_t startOffset,
187                        size_t endOffset ) override;
188     std::string GetNameRaw() override;
189     Property::Index GetNamePropertyIndex() override;
190   };
191 };
192
193 } // namespace Internal
194
195 // Helpers for public-api forwarding methods
196
197 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
198 {
199   DALI_ASSERT_ALWAYS(textLabel);
200
201   Dali::RefObject& handle = textLabel.GetImplementation();
202
203   return static_cast<Toolkit::Internal::TextLabel&>(handle);
204 }
205
206 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
207 {
208   DALI_ASSERT_ALWAYS(textLabel);
209
210   const Dali::RefObject& handle = textLabel.GetImplementation();
211
212   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
213 }
214
215 } // namespace Toolkit
216
217 } // namespace Dali
218
219 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H