cleanup auto scroll in text label
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/image-loading.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/devel-api/text/rendering-backend.h>
33 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
34 #include <dali-toolkit/internal/styling/style-manager-impl.h>
35 #include <dali-toolkit/internal/text/property-string-parser.h>
36 #include <dali-toolkit/internal/text/rendering/text-backend.h>
37 #include <dali-toolkit/internal/text/text-definitions.h>
38 #include <dali-toolkit/internal/text/text-effects-style.h>
39 #include <dali-toolkit/internal/text/text-font-style.h>
40 #include <dali-toolkit/internal/text/text-view.h>
41 #include <dali-toolkit/public-api/text/text-enumerations.h>
42
43 #include <dali-toolkit/devel-api/controls/control-devel.h>
44 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
45 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
46 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
47 #include <dali-toolkit/public-api/align-enumerations.h>
48 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
49 #include <dali-toolkit/public-api/visuals/visual-properties.h>
50
51 // DEVEL INCLUDES
52 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
53
54 using namespace Dali::Toolkit::Text;
55
56 namespace Dali
57 {
58 namespace Toolkit
59 {
60 namespace Internal
61 {
62 namespace
63 {
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
65
66 /**
67  * @brief How the text visual should be aligned vertically inside the control.
68  *
69  * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
70  * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
71  */
72 const float VERTICAL_ALIGNMENT_TABLE[Text::VerticalAlignment::BOTTOM + 1] =
73   {
74     0.0f, // VerticalAlignment::TOP
75     0.5f, // VerticalAlignment::CENTER
76     1.0f  // VerticalAlignment::BOTTOM
77 };
78
79 const std::string TEXT_FIT_ENABLE_KEY("enable");
80 const std::string TEXT_FIT_MIN_SIZE_KEY("minSize");
81 const std::string TEXT_FIT_MAX_SIZE_KEY("maxSize");
82 const std::string TEXT_FIT_STEP_SIZE_KEY("stepSize");
83 const std::string TEXT_FIT_FONT_SIZE_KEY("fontSize");
84 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY("fontSizeType");
85
86 #if defined(DEBUG_ENABLED)
87 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
88 #endif
89
90 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
91   {
92     {"IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE},
93     {"FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP},
94 };
95 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof(AUTO_SCROLL_STOP_MODE_TABLE) / sizeof(AUTO_SCROLL_STOP_MODE_TABLE[0]);
96
97 // Type registration
98 BaseHandle Create()
99 {
100   return Toolkit::TextLabel::New();
101 }
102
103 // clang-format off
104 // Setup properties, signals and actions using the type-registry.
105 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextLabel, Toolkit::Control, Create);
106
107 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "text",                         STRING,  TEXT                           )
108 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "fontFamily",                   STRING,  FONT_FAMILY                    )
109 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "fontStyle",                    MAP,     FONT_STYLE                     )
110 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "pointSize",                    FLOAT,   POINT_SIZE                     )
111 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "multiLine",                    BOOLEAN, MULTI_LINE                     )
112 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "horizontalAlignment",          STRING,  HORIZONTAL_ALIGNMENT           )
113 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "verticalAlignment",            STRING,  VERTICAL_ALIGNMENT             )
114 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "enableMarkup",                 BOOLEAN, ENABLE_MARKUP                  )
115 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "enableAutoScroll",             BOOLEAN, ENABLE_AUTO_SCROLL             )
116 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollSpeed",              INTEGER, AUTO_SCROLL_SPEED              )
117 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollLoopCount",          INTEGER, AUTO_SCROLL_LOOP_COUNT         )
118 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollGap",                FLOAT,   AUTO_SCROLL_GAP                )
119 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "lineSpacing",                  FLOAT,   LINE_SPACING                   )
120 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "underline",                    MAP,     UNDERLINE                      )
121 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "shadow",                       MAP,     SHADOW                         )
122 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "emboss",                       MAP,     EMBOSS                         )
123 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "outline",                      MAP,     OUTLINE                        )
124 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "pixelSize",                    FLOAT,   PIXEL_SIZE                     )
125 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "ellipsis",                     BOOLEAN, ELLIPSIS                       )
126 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollLoopDelay",          FLOAT,   AUTO_SCROLL_LOOP_DELAY         )
127 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "autoScrollStopMode",           STRING,  AUTO_SCROLL_STOP_MODE          )
128 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit,       TextLabel, "lineCount",                    INTEGER, LINE_COUNT                     )
129 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextLabel, "lineWrapMode",                 INTEGER, LINE_WRAP_MODE                 )
130 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextLabel, "textDirection",                INTEGER, TEXT_DIRECTION                 )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "verticalLineAlignment",        INTEGER, VERTICAL_LINE_ALIGNMENT        )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "textBackground",               MAP,     BACKGROUND                     )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "ignoreSpacesAfterText",        BOOLEAN, IGNORE_SPACES_AFTER_TEXT       )
134 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION)
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "textFit",                      MAP,     TEXT_FIT                       )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "minLineSize",                  FLOAT,   MIN_LINE_SIZE                  )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "renderingBackend",             INTEGER, RENDERING_BACKEND              )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "fontSizeScale",                FLOAT,   FONT_SIZE_SCALE                )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "enableFontSizeScale",          BOOLEAN, ENABLE_FONT_SIZE_SCALE         )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "ellipsisPosition",             INTEGER, ELLIPSIS_POSITION              )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "strikethrough",                MAP,     STRIKETHROUGH                  )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "characterSpacing",             FLOAT,   CHARACTER_SPACING              )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextLabel, "relativeLineSize",             FLOAT,   RELATIVE_LINE_SIZE             )
144
145 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT(Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR   )
146 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0)
147 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1)
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorBlue",  TEXT_COLOR_BLUE,  TEXT_COLOR, 2)
149 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit,    TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3)
150
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED)
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED)
153
154 DALI_TYPE_REGISTRATION_END()
155 // clang-format on
156
157 /// Parses the property map for the TEXT_FIT property
158 void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* propertiesMap)
159 {
160   if(propertiesMap && !propertiesMap->Empty())
161   {
162     bool                     enabled      = false;
163     float                    minSize      = 0.f;
164     float                    maxSize      = 0.f;
165     float                    stepSize     = 0.f;
166     bool                     isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
167     Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
168
169     const unsigned int numberOfItems = propertiesMap->Count();
170
171     // Parses and applies
172     for(unsigned int index = 0u; index < numberOfItems; ++index)
173     {
174       const KeyValuePair& valueGet = propertiesMap->GetKeyValue(index);
175
176       if((Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey) || (TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey))
177       {
178         /// Enable key.
179         enabled = valueGet.second.Get<bool>();
180       }
181       else if((Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey))
182       {
183         /// min size.
184         minSize      = valueGet.second.Get<float>();
185         isMinSizeSet = true;
186       }
187       else if((Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey) || (TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey))
188       {
189         /// max size.
190         maxSize      = valueGet.second.Get<float>();
191         isMaxSizeSet = true;
192       }
193       else if((Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey) || (TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey))
194       {
195         /// step size.
196         stepSize      = valueGet.second.Get<float>();
197         isStepSizeSet = true;
198       }
199       else if((Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey) || (TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey))
200       {
201         if("pixelSize" == valueGet.second.Get<std::string>())
202         {
203           type = Controller::FontSizeType::PIXEL_SIZE;
204         }
205       }
206     }
207
208     controller->SetTextFitEnabled(enabled);
209     if(isMinSizeSet)
210     {
211       controller->SetTextFitMinSize(minSize, type);
212     }
213     if(isMaxSizeSet)
214     {
215       controller->SetTextFitMaxSize(maxSize, type);
216     }
217     if(isStepSizeSet)
218     {
219       controller->SetTextFitStepSize(stepSize, type);
220     }
221   }
222 }
223
224 } // namespace
225
226 Toolkit::TextLabel TextLabel::New(ControlBehaviour additionalBehaviour)
227 {
228   // Create the implementation, temporarily owned by this handle on stack
229   IntrusivePtr<TextLabel> impl = new TextLabel(additionalBehaviour);
230
231   // Pass ownership to CustomActor handle
232   Toolkit::TextLabel handle(*impl);
233
234   // Second-phase init of the implementation
235   // This can only be done after the CustomActor connection has been made...
236   impl->Initialize();
237
238   return handle;
239 }
240
241 void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
242 {
243   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
244
245   if(label)
246   {
247     TextLabel& impl(GetImpl(label));
248     DALI_ASSERT_ALWAYS(impl.mController && "No text contoller");
249
250     switch(index)
251     {
252       case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
253       {
254         int backend = value.Get<int>();
255
256 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
257         if(DevelText::RENDERING_VECTOR_BASED == backend)
258         {
259           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
260         }
261 #endif
262         if(impl.mRenderingBackend != backend)
263         {
264           impl.mRenderingBackend = backend;
265           impl.mTextUpdateNeeded = true;
266
267           // When using the vector-based rendering, the size of the GLyphs are different
268           TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
269           impl.mController->SetGlyphType(glyphType);
270         }
271         break;
272       }
273       case Toolkit::TextLabel::Property::TEXT:
274       {
275         impl.mController->SetText(value.Get<std::string>());
276
277         if(impl.mController->HasAnchors())
278         {
279           // Forward input events to controller
280           impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
281         }
282         else
283         {
284           impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
285         }
286
287         break;
288       }
289       case Toolkit::TextLabel::Property::FONT_FAMILY:
290       {
291         const std::string& fontFamily = value.Get<std::string>();
292
293         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str());
294         impl.mController->SetDefaultFontFamily(fontFamily);
295         break;
296       }
297       case Toolkit::TextLabel::Property::FONT_STYLE:
298       {
299         SetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
300         break;
301       }
302       case Toolkit::TextLabel::Property::POINT_SIZE:
303       {
304         const float pointSize = value.Get<float>();
305
306         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE), pointSize))
307         {
308           impl.mController->SetDefaultFontSize(pointSize, Text::Controller::POINT_SIZE);
309         }
310         break;
311       }
312       case Toolkit::TextLabel::Property::MULTI_LINE:
313       {
314         impl.mController->SetMultiLineEnabled(value.Get<bool>());
315         break;
316       }
317       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
318       {
319         Text::HorizontalAlignment::Type alignment(static_cast<Text::HorizontalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
320         if(Text::GetHorizontalAlignmentEnumeration(value, alignment))
321         {
322           impl.mController->SetHorizontalAlignment(alignment);
323         }
324         break;
325       }
326       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
327       {
328         Toolkit::Text::VerticalAlignment::Type alignment(static_cast<Text::VerticalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
329         if(Text::GetVerticalAlignmentEnumeration(value, alignment))
330         {
331           impl.mController->SetVerticalAlignment(alignment);
332         }
333         break;
334       }
335       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
336       {
337         const bool enableMarkup = value.Get<bool>();
338         impl.mController->SetMarkupProcessorEnabled(enableMarkup);
339
340         if(impl.mController->HasAnchors())
341         {
342           // Forward input events to controller
343           impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
344         }
345         else
346         {
347           impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
348         }
349         break;
350       }
351       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
352       {
353         const bool enableAutoScroll = value.Get<bool>();
354         impl.mLastAutoScrollEnabled = enableAutoScroll;
355         // If request to auto scroll is the same as current state then do nothing.
356         if(enableAutoScroll != impl.mController->IsAutoScrollEnabled())
357         {
358           // If request is disable (false) and auto scrolling is enabled then need to stop it
359           if(enableAutoScroll == false)
360           {
361             if(impl.mTextScroller)
362             {
363               impl.mTextScroller->StopScrolling();
364             }
365           }
366           // If request is enable (true) then start autoscroll as not already running
367           else
368           {
369             impl.mController->SetAutoScrollEnabled(enableAutoScroll);
370           }
371         }
372         break;
373       }
374       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
375       {
376         Text::TextScrollerPtr                        textScroller = impl.GetTextScroller();
377         Toolkit::TextLabel::AutoScrollStopMode::Type stopMode     = textScroller->GetStopMode();
378         if(Scripting::GetEnumerationProperty<Toolkit::TextLabel::AutoScrollStopMode::Type>(value,
379                                                                                            AUTO_SCROLL_STOP_MODE_TABLE,
380                                                                                            AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
381                                                                                            stopMode))
382         {
383           textScroller->SetStopMode(stopMode);
384         }
385         break;
386       }
387       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
388       {
389         impl.GetTextScroller()->SetSpeed(value.Get<int>());
390         break;
391       }
392       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
393       {
394         impl.GetTextScroller()->SetLoopCount(value.Get<int>());
395         break;
396       }
397       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
398       {
399         impl.GetTextScroller()->SetLoopDelay(value.Get<float>());
400         break;
401       }
402       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
403       {
404         impl.GetTextScroller()->SetGap(value.Get<float>());
405         break;
406       }
407       case Toolkit::TextLabel::Property::LINE_SPACING:
408       {
409         const float lineSpacing = value.Get<float>();
410         impl.mTextUpdateNeeded  = impl.mController->SetDefaultLineSpacing(lineSpacing) || impl.mTextUpdateNeeded;
411         break;
412       }
413       case Toolkit::TextLabel::Property::UNDERLINE:
414       {
415         impl.mTextUpdateNeeded = SetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
416         break;
417       }
418       case Toolkit::TextLabel::Property::SHADOW:
419       {
420         impl.mTextUpdateNeeded = SetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
421         break;
422       }
423       case Toolkit::TextLabel::Property::EMBOSS:
424       {
425         impl.mTextUpdateNeeded = SetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
426         break;
427       }
428       case Toolkit::TextLabel::Property::OUTLINE:
429       {
430         impl.mTextUpdateNeeded = SetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
431         break;
432       }
433       case Toolkit::TextLabel::Property::PIXEL_SIZE:
434       {
435         const float pixelSize = value.Get<float>();
436         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize);
437
438         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
439         {
440           impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
441         }
442         break;
443       }
444       case Toolkit::TextLabel::Property::ELLIPSIS:
445       {
446         const bool ellipsis = value.Get<bool>();
447         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
448
449         impl.mController->SetTextElideEnabled(ellipsis);
450         break;
451       }
452       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
453       {
454         Text::LineWrap::Mode lineWrapMode(static_cast<Text::LineWrap::Mode>(-1)); // Set to invalid value to ensure a valid mode does get set
455         if(GetLineWrapModeEnumeration(value, lineWrapMode))
456         {
457           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
458           impl.mController->SetLineWrapMode(lineWrapMode);
459         }
460         break;
461       }
462       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
463       {
464         if(impl.mController->GetTextModel())
465         {
466           DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>(value.Get<int>());
467
468           impl.mController->SetVerticalLineAlignment(alignment);
469
470           // Property doesn't affect the layout, only Visual must be updated
471           TextVisual::EnableRendererUpdate(impl.mVisual);
472
473           // No need to trigger full re-layout. Instead call UpdateRenderer() directly
474           TextVisual::UpdateRenderer(impl.mVisual);
475         }
476         break;
477       }
478       case Toolkit::DevelTextLabel::Property::BACKGROUND:
479       {
480         impl.mTextUpdateNeeded = SetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
481         break;
482       }
483       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
484       {
485         impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
486         break;
487       }
488       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
489       {
490         impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
491         break;
492       }
493       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
494       {
495         ParseTextFitProperty(impl.mController, value.GetMap());
496         impl.mController->SetTextFitChanged(true);
497         break;
498       }
499       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
500       {
501         const float lineSize   = value.Get<float>();
502         impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
503         break;
504       }
505       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
506       {
507         const float scale = value.Get<float>();
508         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale);
509
510         if(!Equals(impl.mController->GetFontSizeScale(), scale))
511         {
512           impl.mController->SetFontSizeScale(scale);
513         }
514         break;
515       }
516       case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
517       {
518         const bool enableFontSizeScale = value.Get<bool>();
519         if(!Equals(impl.mController->IsFontSizeScaleEnabled(), enableFontSizeScale))
520         {
521           impl.mController->SetFontSizeScaleEnabled(enableFontSizeScale);
522         }
523         break;
524       }
525       case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
526       {
527         DevelText::EllipsisPosition::Type ellipsisPositionType(static_cast<DevelText::EllipsisPosition::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
528         if(GetEllipsisPositionTypeEnumeration(value, ellipsisPositionType))
529         {
530           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
531           impl.mController->SetEllipsisPosition(ellipsisPositionType);
532         }
533         break;
534       }
535       case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
536       {
537         impl.mTextUpdateNeeded = SetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
538         break;
539       }
540       case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
541       {
542         const float characterSpacing = value.Get<float>();
543         impl.mController->SetCharacterSpacing(characterSpacing);
544         break;
545       }
546       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
547       {
548         const float relativeLineSize = value.Get<float>();
549         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
550
551         impl.mController->SetRelativeLineSize(relativeLineSize);
552         break;
553       }
554     }
555
556     // Request relayout when text update is needed. It's necessary to call it
557     // as changing the property not via UI interaction brings no effect if only
558     // the mTextUpdateNeeded is changed.
559     if(impl.mTextUpdateNeeded)
560     {
561       // need to request relayout as size of text may have changed
562       impl.RequestTextRelayout();
563     }
564   }
565 }
566
567 Text::ControllerPtr TextLabel::GetTextController()
568 {
569   return mController;
570 }
571
572 Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index)
573 {
574   Property::Value value;
575
576   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
577
578   if(label)
579   {
580     TextLabel& impl(GetImpl(label));
581     DALI_ASSERT_DEBUG(impl.mController && "No text contoller");
582
583     switch(index)
584     {
585       case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
586       {
587         value = impl.mRenderingBackend;
588         break;
589       }
590       case Toolkit::TextLabel::Property::TEXT:
591       {
592         std::string text;
593         impl.mController->GetText(text);
594         value = text;
595         break;
596       }
597       case Toolkit::TextLabel::Property::FONT_FAMILY:
598       {
599         value = impl.mController->GetDefaultFontFamily();
600         break;
601       }
602       case Toolkit::TextLabel::Property::FONT_STYLE:
603       {
604         GetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
605         break;
606       }
607       case Toolkit::TextLabel::Property::POINT_SIZE:
608       {
609         value = impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE);
610         break;
611       }
612       case Toolkit::TextLabel::Property::MULTI_LINE:
613       {
614         value = impl.mController->IsMultiLineEnabled();
615         break;
616       }
617       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
618       {
619         const char* name = Text::GetHorizontalAlignmentString(impl.mController->GetHorizontalAlignment());
620
621         if(name)
622         {
623           value = std::string(name);
624         }
625         break;
626       }
627       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
628       {
629         const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
630         if(name)
631         {
632           value = std::string(name);
633         }
634         break;
635       }
636       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
637       {
638         value = impl.mController->IsMarkupProcessorEnabled();
639         break;
640       }
641       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
642       {
643         value = impl.mController->IsAutoScrollEnabled();
644         break;
645       }
646       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
647       {
648         if(impl.mTextScroller)
649         {
650           const char* mode = Scripting::GetEnumerationName<Toolkit::TextLabel::AutoScrollStopMode::Type>(impl.mTextScroller->GetStopMode(),
651                                                                                                          AUTO_SCROLL_STOP_MODE_TABLE,
652                                                                                                          AUTO_SCROLL_STOP_MODE_TABLE_COUNT);
653           if(mode)
654           {
655             value = std::string(mode);
656           }
657         }
658         break;
659       }
660       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
661       {
662         if(impl.mTextScroller)
663         {
664           value = impl.mTextScroller->GetSpeed();
665         }
666         break;
667       }
668       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
669       {
670         if(impl.mTextScroller)
671         {
672           value = impl.mTextScroller->GetLoopCount();
673         }
674         break;
675       }
676       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
677       {
678         if(impl.mTextScroller)
679         {
680           value = impl.mTextScroller->GetLoopDelay();
681         }
682         break;
683       }
684       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
685       {
686         if(impl.mTextScroller)
687         {
688           value = impl.mTextScroller->GetGap();
689         }
690         break;
691       }
692       case Toolkit::TextLabel::Property::LINE_SPACING:
693       {
694         value = impl.mController->GetDefaultLineSpacing();
695         break;
696       }
697       case Toolkit::TextLabel::Property::UNDERLINE:
698       {
699         GetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
700         break;
701       }
702       case Toolkit::TextLabel::Property::SHADOW:
703       {
704         GetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
705         break;
706       }
707       case Toolkit::TextLabel::Property::EMBOSS:
708       {
709         GetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
710         break;
711       }
712       case Toolkit::TextLabel::Property::OUTLINE:
713       {
714         GetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
715         break;
716       }
717       case Toolkit::TextLabel::Property::PIXEL_SIZE:
718       {
719         value = impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE);
720         break;
721       }
722       case Toolkit::TextLabel::Property::ELLIPSIS:
723       {
724         value = impl.mController->IsTextElideEnabled();
725         break;
726       }
727       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
728       {
729         value = impl.mController->GetLineWrapMode();
730         break;
731       }
732       case Toolkit::TextLabel::Property::LINE_COUNT:
733       {
734         float width = label.GetProperty(Actor::Property::SIZE_WIDTH).Get<float>();
735         value       = impl.mController->GetLineCount(width);
736         break;
737       }
738       case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
739       {
740         value = impl.mController->GetTextDirection();
741         break;
742       }
743       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
744       {
745         value = impl.mController->GetVerticalLineAlignment();
746         break;
747       }
748       case Toolkit::DevelTextLabel::Property::BACKGROUND:
749       {
750         GetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
751         break;
752       }
753       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
754       {
755         value = impl.mController->IsIgnoreSpacesAfterText();
756         break;
757       }
758       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
759       {
760         value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
761         break;
762       }
763       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
764       {
765         const bool  enabled   = impl.mController->IsTextFitEnabled();
766         const float minSize   = impl.mController->GetTextFitMinSize();
767         const float maxSize   = impl.mController->GetTextFitMaxSize();
768         const float stepSize  = impl.mController->GetTextFitStepSize();
769         const float pointSize = impl.mController->GetTextFitPointSize();
770
771         Property::Map map;
772         map.Insert(TEXT_FIT_ENABLE_KEY, enabled);
773         map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize);
774         map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize);
775         map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize);
776         map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize);
777         map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize");
778
779         value = map;
780         break;
781       }
782       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
783       {
784         value = impl.mController->GetDefaultLineSize();
785         break;
786       }
787       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
788       {
789         value = impl.mController->GetFontSizeScale();
790         break;
791       }
792       case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
793       {
794         value = impl.mController->IsFontSizeScaleEnabled();
795         break;
796       }
797       case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
798       {
799         value = impl.mController->GetEllipsisPosition();
800         break;
801       }
802       case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
803       {
804         GetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
805         break;
806       }
807       case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
808       {
809         value = impl.mController->GetCharacterSpacing();
810         break;
811       }
812       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
813       {
814         value = impl.mController->GetRelativeLineSize();
815         break;
816       }
817     }
818   }
819
820   return value;
821 }
822
823 bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
824 {
825   Dali::BaseHandle handle(object);
826
827   bool               connected(true);
828   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(handle);
829
830   if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
831   {
832     if(label)
833     {
834       Internal::TextLabel& labelImpl(GetImpl(label));
835       labelImpl.AnchorClickedSignal().Connect(tracker, functor);
836     }
837   }
838   else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED))
839   {
840     if(label)
841     {
842       Internal::TextLabel& labelImpl(GetImpl(label));
843       labelImpl.TextFitChangedSignal().Connect(tracker, functor);
844     }
845   }
846   else
847   {
848     // signalName does not match any signal
849     connected = false;
850   }
851
852   return connected;
853 }
854
855 DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal()
856 {
857   return mAnchorClickedSignal;
858 }
859
860 DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal()
861 {
862   return mTextFitChangedSignal;
863 }
864
865 void TextLabel::OnInitialize()
866 {
867   Actor self = Self();
868
869   Property::Map propertyMap;
870   propertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
871
872   mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
873   DevelControl::RegisterVisual(*this, Toolkit::TextLabel::Property::TEXT, mVisual);
874
875   TextVisual::SetAnimatableTextColorProperty(mVisual, Toolkit::TextLabel::Property::TEXT_COLOR);
876
877   mController = TextVisual::GetController(mVisual);
878   DALI_ASSERT_DEBUG(mController && "Invalid Text Controller")
879
880   mController->SetControlInterface(this);
881   mController->SetAnchorControlInterface(this);
882
883   // Use height-for-width negotiation by default
884   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
885   self.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
886
887   // Enable the text ellipsis.
888   mController->SetTextElideEnabled(true); // If false then text larger than control will overflow
889
890   // Sets layoutDirection value
891   Dali::Stage                 stage           = Dali::Stage::GetCurrent();
892   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
893   mController->SetLayoutDirection(layoutDirection);
894
895   self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
896
897   Layout::Engine& engine = mController->GetLayoutEngine();
898   engine.SetCursorWidth(0u); // Do not layout space for the cursor.
899
900   // Accessibility
901   self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::LABEL);
902   self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
903
904   Accessibility::Bridge::EnabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
905   Accessibility::Bridge::DisabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
906 }
907
908 DevelControl::ControlAccessible* TextLabel::CreateAccessibleObject()
909 {
910   return new TextLabelAccessible(Self());
911 }
912
913 void TextLabel::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
914 {
915   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
916
917   switch(change)
918   {
919     case StyleChange::DEFAULT_FONT_CHANGE:
920     {
921       // Property system did not set the font so should update it.
922       const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
923       DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str());
924       mController->UpdateAfterFontChange(newFont);
925       RelayoutRequest();
926       break;
927     }
928     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
929     {
930       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
931       RelayoutRequest();
932       break;
933     }
934     case StyleChange::THEME_CHANGE:
935     {
936       // Nothing to do, let control base class handle this
937       break;
938     }
939   }
940
941   // Up call to Control
942   Control::OnStyleChange(styleManager, change);
943 }
944
945 void TextLabel::OnTap(const TapGesture& gesture)
946 {
947   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnTap %p\n", mController.Get());
948
949   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
950   Extents padding;
951   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
952   const Vector2& localPoint = gesture.GetLocalPoint();
953   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
954 }
955
956 void TextLabel::AnchorClicked(const std::string& href)
957 {
958   Dali::Toolkit::TextLabel handle(GetOwner());
959   mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
960 }
961
962 Vector3 TextLabel::GetNaturalSize()
963 {
964   Extents padding;
965   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
966
967   Vector3 naturalSize = mController->GetNaturalSize();
968   naturalSize.width += (padding.start + padding.end);
969   naturalSize.height += (padding.top + padding.bottom);
970
971   return naturalSize;
972 }
973
974 float TextLabel::GetHeightForWidth(float width)
975 {
976   Extents padding;
977   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
978
979   return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
980 }
981
982 void TextLabel::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
983 {
984   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index);
985
986   switch(index)
987   {
988     case Toolkit::TextLabel::Property::TEXT_COLOR:
989     {
990       const Vector4& textColor = propertyValue.Get<Vector4>();
991       if(mController->GetDefaultColor() != textColor)
992       {
993         mController->SetDefaultColor(textColor);
994         mTextUpdateNeeded = true;
995       }
996       break;
997     }
998     case Toolkit::TextLabel::Property::TEXT:
999     case Toolkit::TextLabel::Property::ENABLE_MARKUP:
1000     {
1001       CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1002       break;
1003     }
1004     default:
1005     {
1006       Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
1007       break;
1008     }
1009   }
1010 }
1011
1012 void TextLabel::OnSceneConnection(int depth)
1013 {
1014   if(mController->IsAutoScrollEnabled() || mLastAutoScrollEnabled)
1015   {
1016     mController->SetAutoScrollEnabled(true);
1017   }
1018   Control::OnSceneConnection(depth);
1019 }
1020
1021 void TextLabel::OnSceneDisconnection()
1022 {
1023   if(mTextScroller)
1024   {
1025     if(mLastAutoScrollEnabled && !mController->IsAutoScrollEnabled())
1026     {
1027       mLastAutoScrollEnabled = false;
1028     }
1029
1030     const Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = mTextScroller->GetStopMode();
1031     mTextScroller->SetStopMode(Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE);
1032     mTextScroller->StopScrolling();
1033     mTextScroller->SetStopMode(stopMode);
1034   }
1035   Control::OnSceneDisconnection();
1036 }
1037
1038 void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
1039 {
1040   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
1041
1042   Actor self = Self();
1043
1044   Extents padding;
1045   padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1046
1047   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
1048
1049   if(mController->IsTextFitEnabled())
1050   {
1051     mController->FitPointSizeforLayout(contentSize);
1052     mController->SetTextFitContentSize(contentSize);
1053   }
1054
1055   // Support Right-To-Left
1056   Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
1057
1058   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
1059
1060   if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
1061   {
1062     DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", (mController->IsAutoScrollEnabled()) ? "true" : "false", this);
1063
1064     // Update the visual
1065     TextVisual::EnableRendererUpdate(mVisual);
1066
1067     // Support Right-To-Left of padding
1068     if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
1069     {
1070       std::swap(padding.start, padding.end);
1071     }
1072
1073     // Calculate the size of the visual that can fit the text
1074     Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1075     layoutSize.x    = contentSize.x;
1076
1077     const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1078     if(shadowOffset.y > Math::MACHINE_EPSILON_1)
1079     {
1080       layoutSize.y += shadowOffset.y;
1081     }
1082
1083     float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1084     layoutSize.y += outlineWidth * 2.0f;
1085     layoutSize.y = std::min(layoutSize.y, contentSize.y);
1086
1087     // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1088     Vector2 alignmentOffset;
1089     alignmentOffset.x = 0.0f;
1090     alignmentOffset.y = (contentSize.y - layoutSize.y) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1091
1092     const int maxTextureSize = Dali::GetMaxTextureSize();
1093     if(layoutSize.width > maxTextureSize)
1094     {
1095       DALI_LOG_WARNING("layoutSize(%f) > maxTextureSize(%d): To guarantee the behavior of Texture::New, layoutSize must not be bigger than maxTextureSize\n", layoutSize.width, maxTextureSize);
1096       layoutSize.width = maxTextureSize;
1097     }
1098
1099     Property::Map visualTransform;
1100     visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize)
1101       .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1102       .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.start, padding.top) + alignmentOffset)
1103       .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1104       .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
1105       .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN);
1106     mVisual.SetTransformAndSize(visualTransform, size);
1107
1108     if(mController->IsAutoScrollEnabled())
1109     {
1110       SetUpAutoScrolling();
1111     }
1112
1113     mTextUpdateNeeded = false;
1114   }
1115
1116   if(mController->IsTextFitChanged())
1117   {
1118     EmitTextFitChangedSignal();
1119     mController->SetTextFitChanged(false);
1120   }
1121 }
1122
1123 void TextLabel::RequestTextRelayout()
1124 {
1125   RelayoutRequest();
1126   // Signal that a Relayout may be needed
1127 }
1128
1129 void TextLabel::SetUpAutoScrolling()
1130 {
1131   const Size&                    controlSize     = mController->GetView().GetControlSize();
1132   const Size                     textNaturalSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
1133   const Text::CharacterDirection direction       = mController->GetAutoScrollDirection();
1134
1135   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y);
1136
1137   if(!mTextScroller)
1138   {
1139     DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
1140
1141     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1142     mTextScroller = Text::TextScroller::New(*this);
1143   }
1144
1145   // Calculate the actual gap before scrolling wraps.
1146   int     textPadding = std::max(controlSize.x - textNaturalSize.x, 0.0f);
1147   float   wrapGap     = std::max(mTextScroller->GetGap(), textPadding);
1148   Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1149
1150   // Create a texture of the text for scrolling
1151   Size      verifiedSize   = textureSize;
1152   const int maxTextureSize = Dali::GetMaxTextureSize();
1153
1154   //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1155   bool actualellipsis = mController->IsTextElideEnabled();
1156   if(verifiedSize.width > maxTextureSize)
1157   {
1158     verifiedSize.width = maxTextureSize;
1159     if(textNaturalSize.width > maxTextureSize)
1160     {
1161       mController->SetTextElideEnabled(true);
1162       mController->SetAutoScrollMaxTextureExceeded(true);
1163     }
1164     GetHeightForWidth(maxTextureSize);
1165     wrapGap = std::max(maxTextureSize - textNaturalSize.width, 0.0f);
1166   }
1167
1168   Text::TypesetterPtr typesetter = Text::Typesetter::New(mController->GetTextModel());
1169
1170   PixelData data    = typesetter->Render(verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888); // ignore the horizontal alignment
1171   Texture   texture = Texture::New(Dali::TextureType::TEXTURE_2D,
1172                                  data.GetPixelFormat(),
1173                                  data.GetWidth(),
1174                                  data.GetHeight());
1175   texture.Upload(data);
1176
1177   TextureSet textureSet = TextureSet::New();
1178   textureSet.SetTexture(0u, texture);
1179
1180   // Filter mode needs to be set to linear to produce better quality while scaling.
1181   Sampler sampler = Sampler::New();
1182   sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR);
1183   sampler.SetWrapMode(Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT); // Wrap the texture in the x direction
1184   textureSet.SetSampler(0u, sampler);
1185
1186   // Set parameters for scrolling
1187   Renderer renderer = static_cast<Internal::Visual::Base&>(GetImplementation(mVisual)).GetRenderer();
1188   mTextScroller->SetParameters(Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment());
1189   mController->SetTextElideEnabled(actualellipsis);
1190   mController->SetAutoScrollMaxTextureExceeded(false);
1191 }
1192
1193 void TextLabel::ScrollingFinished()
1194 {
1195   // Pure Virtual from TextScroller Interface
1196   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1197   mController->SetAutoScrollEnabled(false);
1198   RequestTextRelayout();
1199 }
1200
1201 void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1202 {
1203   mController->ChangedLayoutDirection();
1204 }
1205
1206 void TextLabel::EmitTextFitChangedSignal()
1207 {
1208   Dali::Toolkit::TextLabel handle(GetOwner());
1209   mTextFitChangedSignal.Emit(handle);
1210 }
1211
1212 void TextLabel::OnAccessibilityStatusChanged()
1213 {
1214   CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1215 }
1216
1217 TextLabel::TextLabel(ControlBehaviour additionalBehavior)
1218 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehavior)),
1219   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1220   mTextUpdateNeeded(false),
1221   mLastAutoScrollEnabled(false)
1222 {
1223 }
1224
1225 TextLabel::~TextLabel()
1226 {
1227 }
1228
1229 Vector<Vector2> TextLabel::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1230 {
1231   return mController->GetTextSize(startIndex, endIndex);
1232 }
1233
1234 Vector<Vector2> TextLabel::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1235 {
1236   return mController->GetTextPosition(startIndex, endIndex);
1237 }
1238
1239 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
1240 {
1241   return GetWholeText();
1242 }
1243
1244 Property::Index TextLabel::TextLabelAccessible::GetNamePropertyIndex()
1245 {
1246   return Toolkit::TextLabel::Property::TEXT;
1247 }
1248
1249 const std::vector<Toolkit::TextAnchor>& TextLabel::TextLabelAccessible::GetTextAnchors() const
1250 {
1251   auto self = Toolkit::TextLabel::DownCast(Self());
1252
1253   return Toolkit::GetImpl(self).mAnchorActors;
1254 }
1255
1256 Toolkit::Text::ControllerPtr TextLabel::TextLabelAccessible::GetTextController() const
1257 {
1258   auto self = Toolkit::TextLabel::DownCast(Self());
1259
1260   return Toolkit::GetImpl(self).GetTextController();
1261 }
1262
1263 } // namespace Internal
1264
1265 } // namespace Toolkit
1266
1267 } // namespace Dali