[AT-SPI] Rename AccessibleImpl to <Control>Accessible
[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         // If request to auto scroll is the same as current state then do nothing.
355         if(enableAutoScroll != impl.mController->IsAutoScrollEnabled())
356         {
357           // If request is disable (false) and auto scrolling is enabled then need to stop it
358           if(enableAutoScroll == false)
359           {
360             if(impl.mTextScroller)
361             {
362               impl.mTextScroller->StopScrolling();
363             }
364           }
365           // If request is enable (true) then start autoscroll as not already running
366           else
367           {
368             impl.mController->SetAutoScrollEnabled(enableAutoScroll);
369           }
370         }
371         break;
372       }
373       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
374       {
375         Text::TextScrollerPtr                        textScroller = impl.GetTextScroller();
376         Toolkit::TextLabel::AutoScrollStopMode::Type stopMode     = textScroller->GetStopMode();
377         if(Scripting::GetEnumerationProperty<Toolkit::TextLabel::AutoScrollStopMode::Type>(value,
378                                                                                            AUTO_SCROLL_STOP_MODE_TABLE,
379                                                                                            AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
380                                                                                            stopMode))
381         {
382           textScroller->SetStopMode(stopMode);
383         }
384         break;
385       }
386       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
387       {
388         impl.GetTextScroller()->SetSpeed(value.Get<int>());
389         break;
390       }
391       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
392       {
393         impl.GetTextScroller()->SetLoopCount(value.Get<int>());
394         break;
395       }
396       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
397       {
398         impl.GetTextScroller()->SetLoopDelay(value.Get<float>());
399         break;
400       }
401       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
402       {
403         impl.GetTextScroller()->SetGap(value.Get<float>());
404         break;
405       }
406       case Toolkit::TextLabel::Property::LINE_SPACING:
407       {
408         const float lineSpacing = value.Get<float>();
409         impl.mTextUpdateNeeded  = impl.mController->SetDefaultLineSpacing(lineSpacing) || impl.mTextUpdateNeeded;
410         break;
411       }
412       case Toolkit::TextLabel::Property::UNDERLINE:
413       {
414         impl.mTextUpdateNeeded = SetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
415         break;
416       }
417       case Toolkit::TextLabel::Property::SHADOW:
418       {
419         impl.mTextUpdateNeeded = SetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
420         break;
421       }
422       case Toolkit::TextLabel::Property::EMBOSS:
423       {
424         impl.mTextUpdateNeeded = SetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
425         break;
426       }
427       case Toolkit::TextLabel::Property::OUTLINE:
428       {
429         impl.mTextUpdateNeeded = SetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
430         break;
431       }
432       case Toolkit::TextLabel::Property::PIXEL_SIZE:
433       {
434         const float pixelSize = value.Get<float>();
435         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize);
436
437         if(!Equals(impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE), pixelSize))
438         {
439           impl.mController->SetDefaultFontSize(pixelSize, Text::Controller::PIXEL_SIZE);
440         }
441         break;
442       }
443       case Toolkit::TextLabel::Property::ELLIPSIS:
444       {
445         const bool ellipsis = value.Get<bool>();
446         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis);
447
448         impl.mController->SetTextElideEnabled(ellipsis);
449         break;
450       }
451       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
452       {
453         Text::LineWrap::Mode lineWrapMode(static_cast<Text::LineWrap::Mode>(-1)); // Set to invalid value to ensure a valid mode does get set
454         if(GetLineWrapModeEnumeration(value, lineWrapMode))
455         {
456           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode);
457           impl.mController->SetLineWrapMode(lineWrapMode);
458         }
459         break;
460       }
461       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
462       {
463         if(impl.mController->GetTextModel())
464         {
465           DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>(value.Get<int>());
466
467           impl.mController->SetVerticalLineAlignment(alignment);
468
469           // Property doesn't affect the layout, only Visual must be updated
470           TextVisual::EnableRendererUpdate(impl.mVisual);
471
472           // No need to trigger full re-layout. Instead call UpdateRenderer() directly
473           TextVisual::UpdateRenderer(impl.mVisual);
474         }
475         break;
476       }
477       case Toolkit::DevelTextLabel::Property::BACKGROUND:
478       {
479         impl.mTextUpdateNeeded = SetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
480         break;
481       }
482       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
483       {
484         impl.mController->SetIgnoreSpacesAfterText(value.Get<bool>());
485         break;
486       }
487       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
488       {
489         impl.mController->SetMatchLayoutDirection(value.Get<bool>() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS);
490         break;
491       }
492       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
493       {
494         ParseTextFitProperty(impl.mController, value.GetMap());
495         impl.mController->SetTextFitChanged(true);
496         break;
497       }
498       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
499       {
500         const float lineSize   = value.Get<float>();
501         impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize(lineSize) || impl.mTextUpdateNeeded;
502         break;
503       }
504       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
505       {
506         const float scale = value.Get<float>();
507         DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale);
508
509         if(!Equals(impl.mController->GetFontSizeScale(), scale))
510         {
511           impl.mController->SetFontSizeScale(scale);
512         }
513         break;
514       }
515       case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
516       {
517         const bool enableFontSizeScale = value.Get<bool>();
518         if(!Equals(impl.mController->IsFontSizeScaleEnabled(), enableFontSizeScale))
519         {
520           impl.mController->SetFontSizeScaleEnabled(enableFontSizeScale);
521         }
522         break;
523       }
524       case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
525       {
526         DevelText::EllipsisPosition::Type ellipsisPositionType(static_cast<DevelText::EllipsisPosition::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
527         if(GetEllipsisPositionTypeEnumeration(value, ellipsisPositionType))
528         {
529           DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel %p EllipsisPosition::Type %d\n", impl.mController.Get(), ellipsisPositionType);
530           impl.mController->SetEllipsisPosition(ellipsisPositionType);
531         }
532         break;
533       }
534       case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
535       {
536         impl.mTextUpdateNeeded = SetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT) || impl.mTextUpdateNeeded;
537         break;
538       }
539       case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
540       {
541         const float characterSpacing = value.Get<float>();
542         impl.mController->SetCharacterSpacing(characterSpacing);
543         break;
544       }
545       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
546       {
547         const float relativeLineSize = value.Get<float>();
548         DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
549
550         impl.mController->SetRelativeLineSize(relativeLineSize);
551         break;
552       }
553     }
554
555     // Request relayout when text update is needed. It's necessary to call it
556     // as changing the property not via UI interaction brings no effect if only
557     // the mTextUpdateNeeded is changed.
558     if(impl.mTextUpdateNeeded)
559     {
560       // need to request relayout as size of text may have changed
561       impl.RequestTextRelayout();
562     }
563   }
564 }
565
566 Text::ControllerPtr TextLabel::GetTextController()
567 {
568   return mController;
569 }
570
571 Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index)
572 {
573   Property::Value value;
574
575   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(Dali::BaseHandle(object));
576
577   if(label)
578   {
579     TextLabel& impl(GetImpl(label));
580     DALI_ASSERT_DEBUG(impl.mController && "No text contoller");
581
582     switch(index)
583     {
584       case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
585       {
586         value = impl.mRenderingBackend;
587         break;
588       }
589       case Toolkit::TextLabel::Property::TEXT:
590       {
591         std::string text;
592         impl.mController->GetText(text);
593         value = text;
594         break;
595       }
596       case Toolkit::TextLabel::Property::FONT_FAMILY:
597       {
598         value = impl.mController->GetDefaultFontFamily();
599         break;
600       }
601       case Toolkit::TextLabel::Property::FONT_STYLE:
602       {
603         GetFontStyleProperty(impl.mController, value, Text::FontStyle::DEFAULT);
604         break;
605       }
606       case Toolkit::TextLabel::Property::POINT_SIZE:
607       {
608         value = impl.mController->GetDefaultFontSize(Text::Controller::POINT_SIZE);
609         break;
610       }
611       case Toolkit::TextLabel::Property::MULTI_LINE:
612       {
613         value = impl.mController->IsMultiLineEnabled();
614         break;
615       }
616       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
617       {
618         const char* name = Text::GetHorizontalAlignmentString(impl.mController->GetHorizontalAlignment());
619
620         if(name)
621         {
622           value = std::string(name);
623         }
624         break;
625       }
626       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
627       {
628         const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
629         if(name)
630         {
631           value = std::string(name);
632         }
633         break;
634       }
635       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
636       {
637         value = impl.mController->IsMarkupProcessorEnabled();
638         break;
639       }
640       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
641       {
642         value = impl.mController->IsAutoScrollEnabled();
643         break;
644       }
645       case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
646       {
647         if(impl.mTextScroller)
648         {
649           const char* mode = Scripting::GetEnumerationName<Toolkit::TextLabel::AutoScrollStopMode::Type>(impl.mTextScroller->GetStopMode(),
650                                                                                                          AUTO_SCROLL_STOP_MODE_TABLE,
651                                                                                                          AUTO_SCROLL_STOP_MODE_TABLE_COUNT);
652           if(mode)
653           {
654             value = std::string(mode);
655           }
656         }
657         break;
658       }
659       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
660       {
661         if(impl.mTextScroller)
662         {
663           value = impl.mTextScroller->GetSpeed();
664         }
665         break;
666       }
667       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
668       {
669         if(impl.mTextScroller)
670         {
671           value = impl.mTextScroller->GetLoopCount();
672         }
673         break;
674       }
675       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
676       {
677         if(impl.mTextScroller)
678         {
679           value = impl.mTextScroller->GetLoopDelay();
680         }
681         break;
682       }
683       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
684       {
685         if(impl.mTextScroller)
686         {
687           value = impl.mTextScroller->GetGap();
688         }
689         break;
690       }
691       case Toolkit::TextLabel::Property::LINE_SPACING:
692       {
693         value = impl.mController->GetDefaultLineSpacing();
694         break;
695       }
696       case Toolkit::TextLabel::Property::UNDERLINE:
697       {
698         GetUnderlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
699         break;
700       }
701       case Toolkit::TextLabel::Property::SHADOW:
702       {
703         GetShadowProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
704         break;
705       }
706       case Toolkit::TextLabel::Property::EMBOSS:
707       {
708         GetEmbossProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
709         break;
710       }
711       case Toolkit::TextLabel::Property::OUTLINE:
712       {
713         GetOutlineProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
714         break;
715       }
716       case Toolkit::TextLabel::Property::PIXEL_SIZE:
717       {
718         value = impl.mController->GetDefaultFontSize(Text::Controller::PIXEL_SIZE);
719         break;
720       }
721       case Toolkit::TextLabel::Property::ELLIPSIS:
722       {
723         value = impl.mController->IsTextElideEnabled();
724         break;
725       }
726       case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
727       {
728         value = impl.mController->GetLineWrapMode();
729         break;
730       }
731       case Toolkit::TextLabel::Property::LINE_COUNT:
732       {
733         float width = label.GetProperty(Actor::Property::SIZE_WIDTH).Get<float>();
734         value       = impl.mController->GetLineCount(width);
735         break;
736       }
737       case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
738       {
739         value = impl.mController->GetTextDirection();
740         break;
741       }
742       case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
743       {
744         value = impl.mController->GetVerticalLineAlignment();
745         break;
746       }
747       case Toolkit::DevelTextLabel::Property::BACKGROUND:
748       {
749         GetBackgroundProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
750         break;
751       }
752       case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
753       {
754         value = impl.mController->IsIgnoreSpacesAfterText();
755         break;
756       }
757       case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
758       {
759         value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS;
760         break;
761       }
762       case Toolkit::DevelTextLabel::Property::TEXT_FIT:
763       {
764         const bool  enabled   = impl.mController->IsTextFitEnabled();
765         const float minSize   = impl.mController->GetTextFitMinSize();
766         const float maxSize   = impl.mController->GetTextFitMaxSize();
767         const float stepSize  = impl.mController->GetTextFitStepSize();
768         const float pointSize = impl.mController->GetTextFitPointSize();
769
770         Property::Map map;
771         map.Insert(TEXT_FIT_ENABLE_KEY, enabled);
772         map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize);
773         map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize);
774         map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize);
775         map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize);
776         map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize");
777
778         value = map;
779         break;
780       }
781       case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
782       {
783         value = impl.mController->GetDefaultLineSize();
784         break;
785       }
786       case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE:
787       {
788         value = impl.mController->GetFontSizeScale();
789         break;
790       }
791       case Toolkit::DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE:
792       {
793         value = impl.mController->IsFontSizeScaleEnabled();
794         break;
795       }
796       case Toolkit::DevelTextLabel::Property::ELLIPSIS_POSITION:
797       {
798         value = impl.mController->GetEllipsisPosition();
799         break;
800       }
801       case Toolkit::DevelTextLabel::Property::STRIKETHROUGH:
802       {
803         GetStrikethroughProperties(impl.mController, value, Text::EffectStyle::DEFAULT);
804         break;
805       }
806       case Toolkit::DevelTextLabel::Property::CHARACTER_SPACING:
807       {
808         value = impl.mController->GetCharacterSpacing();
809         break;
810       }
811       case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
812       {
813         value = impl.mController->GetRelativeLineSize();
814         break;
815       }
816     }
817   }
818
819   return value;
820 }
821
822 bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
823 {
824   Dali::BaseHandle handle(object);
825
826   bool               connected(true);
827   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast(handle);
828
829   if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
830   {
831     if(label)
832     {
833       Internal::TextLabel& labelImpl(GetImpl(label));
834       labelImpl.AnchorClickedSignal().Connect(tracker, functor);
835     }
836   }
837   else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED))
838   {
839     if(label)
840     {
841       Internal::TextLabel& labelImpl(GetImpl(label));
842       labelImpl.TextFitChangedSignal().Connect(tracker, functor);
843     }
844   }
845   else
846   {
847     // signalName does not match any signal
848     connected = false;
849   }
850
851   return connected;
852 }
853
854 DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal()
855 {
856   return mAnchorClickedSignal;
857 }
858
859 DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal()
860 {
861   return mTextFitChangedSignal;
862 }
863
864 void TextLabel::OnInitialize()
865 {
866   Actor self = Self();
867
868   Property::Map propertyMap;
869   propertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
870
871   mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
872   DevelControl::RegisterVisual(*this, Toolkit::TextLabel::Property::TEXT, mVisual);
873
874   TextVisual::SetAnimatableTextColorProperty(mVisual, Toolkit::TextLabel::Property::TEXT_COLOR);
875
876   mController = TextVisual::GetController(mVisual);
877   DALI_ASSERT_DEBUG(mController && "Invalid Text Controller")
878
879   mController->SetControlInterface(this);
880   mController->SetAnchorControlInterface(this);
881
882   // Use height-for-width negotiation by default
883   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
884   self.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
885
886   // Enable highlightability
887   self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
888
889   // Enable the text ellipsis.
890   mController->SetTextElideEnabled(true); // If false then text larger than control will overflow
891
892   // Sets layoutDirection value
893   Dali::Stage                 stage           = Dali::Stage::GetCurrent();
894   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
895   mController->SetLayoutDirection(layoutDirection);
896
897   self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
898
899   Layout::Engine& engine = mController->GetLayoutEngine();
900   engine.SetCursorWidth(0u); // Do not layout space for the cursor.
901
902   DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
903     return std::make_unique<TextLabelAccessible>(actor, Dali::Accessibility::Role::LABEL);
904   });
905
906   Accessibility::Bridge::EnabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
907   Accessibility::Bridge::DisabledSignal().Connect(this, &TextLabel::OnAccessibilityStatusChanged);
908 }
909
910 void TextLabel::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
911 {
912   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
913
914   switch(change)
915   {
916     case StyleChange::DEFAULT_FONT_CHANGE:
917     {
918       // Property system did not set the font so should update it.
919       const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
920       DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str());
921       mController->UpdateAfterFontChange(newFont);
922       RelayoutRequest();
923       break;
924     }
925     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
926     {
927       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
928       RelayoutRequest();
929       break;
930     }
931     case StyleChange::THEME_CHANGE:
932     {
933       // Nothing to do, let control base class handle this
934       break;
935     }
936   }
937
938   // Up call to Control
939   Control::OnStyleChange(styleManager, change);
940 }
941
942 void TextLabel::OnTap(const TapGesture& gesture)
943 {
944   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnTap %p\n", mController.Get());
945
946   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
947   Extents padding;
948   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
949   const Vector2& localPoint = gesture.GetLocalPoint();
950   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
951 }
952
953 void TextLabel::AnchorClicked(const std::string& href)
954 {
955   Dali::Toolkit::TextLabel handle(GetOwner());
956   mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
957 }
958
959 Vector3 TextLabel::GetNaturalSize()
960 {
961   Extents padding;
962   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
963
964   Vector3 naturalSize = mController->GetNaturalSize();
965   naturalSize.width += (padding.start + padding.end);
966   naturalSize.height += (padding.top + padding.bottom);
967
968   return naturalSize;
969 }
970
971 float TextLabel::GetHeightForWidth(float width)
972 {
973   Extents padding;
974   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
975
976   return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
977 }
978
979 void TextLabel::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
980 {
981   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index);
982
983   switch(index)
984   {
985     case Toolkit::TextLabel::Property::TEXT_COLOR:
986     {
987       const Vector4& textColor = propertyValue.Get<Vector4>();
988       if(mController->GetDefaultColor() != textColor)
989       {
990         mController->SetDefaultColor(textColor);
991         mTextUpdateNeeded = true;
992       }
993       break;
994     }
995     case Toolkit::TextLabel::Property::TEXT:
996     case Toolkit::TextLabel::Property::ENABLE_MARKUP:
997     {
998       CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
999       break;
1000     }
1001     default:
1002     {
1003       Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
1004       break;
1005     }
1006   }
1007 }
1008
1009 void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container)
1010 {
1011   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n");
1012
1013   Actor self = Self();
1014
1015   Extents padding;
1016   padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
1017
1018   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
1019
1020   if(mController->IsTextFitEnabled())
1021   {
1022     mController->FitPointSizeforLayout(contentSize);
1023     mController->SetTextFitContentSize(contentSize);
1024   }
1025
1026   // Support Right-To-Left
1027   Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
1028
1029   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
1030
1031   if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded)
1032   {
1033     DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", (mController->IsAutoScrollEnabled()) ? "true" : "false", this);
1034
1035     // Update the visual
1036     TextVisual::EnableRendererUpdate(mVisual);
1037
1038     // Support Right-To-Left of padding
1039     if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
1040     {
1041       std::swap(padding.start, padding.end);
1042     }
1043
1044     // Calculate the size of the visual that can fit the text
1045     Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1046     layoutSize.x    = contentSize.x;
1047
1048     const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1049     if(shadowOffset.y > Math::MACHINE_EPSILON_1)
1050     {
1051       layoutSize.y += shadowOffset.y;
1052     }
1053
1054     float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1055     layoutSize.y += outlineWidth * 2.0f;
1056     layoutSize.y = std::min(layoutSize.y, contentSize.y);
1057
1058     // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1059     Vector2 alignmentOffset;
1060     alignmentOffset.x = 0.0f;
1061     alignmentOffset.y = (contentSize.y - layoutSize.y) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1062
1063     Property::Map visualTransform;
1064     visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize)
1065       .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1066       .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.start, padding.top) + alignmentOffset)
1067       .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
1068       .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
1069       .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN);
1070     mVisual.SetTransformAndSize(visualTransform, size);
1071
1072     if(mController->IsAutoScrollEnabled())
1073     {
1074       SetUpAutoScrolling();
1075     }
1076
1077     mTextUpdateNeeded = false;
1078   }
1079
1080   if(mController->IsTextFitChanged())
1081   {
1082     EmitTextFitChangedSignal();
1083     mController->SetTextFitChanged(false);
1084   }
1085 }
1086
1087 void TextLabel::RequestTextRelayout()
1088 {
1089   RelayoutRequest();
1090   // Signal that a Relayout may be needed
1091 }
1092
1093 void TextLabel::SetUpAutoScrolling()
1094 {
1095   const Size&                    controlSize     = mController->GetView().GetControlSize();
1096   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.
1097   const Text::CharacterDirection direction       = mController->GetAutoScrollDirection();
1098
1099   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y);
1100
1101   if(!mTextScroller)
1102   {
1103     DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n");
1104
1105     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1106     mTextScroller = Text::TextScroller::New(*this);
1107   }
1108
1109   // Calculate the actual gap before scrolling wraps.
1110   int     textPadding = std::max(controlSize.x - textNaturalSize.x, 0.0f);
1111   float   wrapGap     = std::max(mTextScroller->GetGap(), textPadding);
1112   Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1113
1114   // Create a texture of the text for scrolling
1115   Size      verifiedSize   = textureSize;
1116   const int maxTextureSize = Dali::GetMaxTextureSize();
1117
1118   //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1119   bool actualellipsis = mController->IsTextElideEnabled();
1120   if(verifiedSize.width > maxTextureSize)
1121   {
1122     verifiedSize.width = maxTextureSize;
1123     if(textNaturalSize.width > maxTextureSize)
1124     {
1125       mController->SetTextElideEnabled(true);
1126     }
1127     GetHeightForWidth(maxTextureSize);
1128     wrapGap = std::max(maxTextureSize - textNaturalSize.width, 0.0f);
1129   }
1130
1131   Text::TypesetterPtr typesetter = Text::Typesetter::New(mController->GetTextModel());
1132
1133   PixelData data    = typesetter->Render(verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888); // ignore the horizontal alignment
1134   Texture   texture = Texture::New(Dali::TextureType::TEXTURE_2D,
1135                                  data.GetPixelFormat(),
1136                                  data.GetWidth(),
1137                                  data.GetHeight());
1138   texture.Upload(data);
1139
1140   TextureSet textureSet = TextureSet::New();
1141   textureSet.SetTexture(0u, texture);
1142
1143   // Filter mode needs to be set to linear to produce better quality while scaling.
1144   Sampler sampler = Sampler::New();
1145   sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR);
1146   sampler.SetWrapMode(Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT); // Wrap the texture in the x direction
1147   textureSet.SetSampler(0u, sampler);
1148
1149   // Set parameters for scrolling
1150   Renderer renderer = static_cast<Internal::Visual::Base&>(GetImplementation(mVisual)).GetRenderer();
1151   mTextScroller->SetParameters(Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment());
1152   mController->SetTextElideEnabled(actualellipsis);
1153 }
1154
1155 void TextLabel::ScrollingFinished()
1156 {
1157   // Pure Virtual from TextScroller Interface
1158   DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1159   mController->SetAutoScrollEnabled(false);
1160   RequestTextRelayout();
1161 }
1162
1163 void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1164 {
1165   mController->ChangedLayoutDirection();
1166 }
1167
1168 void TextLabel::EmitTextFitChangedSignal()
1169 {
1170   Dali::Toolkit::TextLabel handle(GetOwner());
1171   mTextFitChangedSignal.Emit(handle);
1172 }
1173
1174 void TextLabel::OnAccessibilityStatusChanged()
1175 {
1176   CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
1177 }
1178
1179 TextLabel::TextLabel(ControlBehaviour additionalBehavior)
1180 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehavior)),
1181   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1182   mTextUpdateNeeded(false)
1183 {
1184 }
1185
1186 TextLabel::~TextLabel()
1187 {
1188 }
1189
1190 Vector<Vector2> TextLabel::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1191 {
1192   return mController->GetTextSize(startIndex, endIndex);
1193 }
1194
1195 Vector<Vector2> TextLabel::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1196 {
1197   return mController->GetTextPosition(startIndex, endIndex);
1198 }
1199
1200 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
1201 {
1202   auto self = Toolkit::TextLabel::DownCast(Self());
1203   return self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1204 }
1205
1206 Property::Index TextLabel::TextLabelAccessible::GetNamePropertyIndex()
1207 {
1208   return Toolkit::TextLabel::Property::TEXT;
1209 }
1210
1211 std::string TextLabel::TextLabelAccessible::GetText(size_t startOffset, size_t endOffset) const
1212 {
1213   if(endOffset <= startOffset)
1214   {
1215     return {};
1216   }
1217
1218   auto self = Toolkit::TextLabel::DownCast(Self());
1219   auto text = self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1220
1221   if(startOffset > text.size() || endOffset > text.size())
1222   {
1223     return {};
1224   }
1225
1226   return text.substr(startOffset, endOffset - startOffset);
1227 }
1228
1229 size_t TextLabel::TextLabelAccessible::GetCharacterCount() const
1230 {
1231   auto self = Toolkit::TextLabel::DownCast(Self());
1232   auto text = self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1233
1234   return text.size();
1235 }
1236
1237 size_t TextLabel::TextLabelAccessible::GetCursorOffset() const
1238 {
1239   return {};
1240 }
1241
1242 bool TextLabel::TextLabelAccessible::SetCursorOffset(size_t offset)
1243 {
1244   return {};
1245 }
1246
1247 Dali::Accessibility::Range TextLabel::TextLabelAccessible::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const
1248 {
1249   auto self     = Toolkit::TextLabel::DownCast(Self());
1250   auto text     = self.GetProperty(Toolkit::TextLabel::Property::TEXT).Get<std::string>();
1251   auto textSize = text.size();
1252
1253   auto range = Dali::Accessibility::Range{};
1254
1255   switch(boundary)
1256   {
1257     case Dali::Accessibility::TextBoundary::CHARACTER:
1258     {
1259       if(offset < textSize)
1260       {
1261         range.content     = text[offset];
1262         range.startOffset = offset;
1263         range.endOffset   = offset + 1;
1264       }
1265       break;
1266     }
1267     case Dali::Accessibility::TextBoundary::WORD:
1268     case Dali::Accessibility::TextBoundary::LINE:
1269     {
1270       auto textString = text.c_str();
1271       auto breaks     = std::vector<char>(textSize, 0);
1272
1273       if(boundary == Dali::Accessibility::TextBoundary::WORD)
1274       {
1275         Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1276       }
1277       else
1278       {
1279         Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1280       }
1281
1282       auto index   = 0u;
1283       auto counter = 0u;
1284       while(index < textSize && counter <= offset)
1285       {
1286         auto start = index;
1287         if(breaks[index])
1288         {
1289           while(breaks[index])
1290           {
1291             index++;
1292           }
1293           counter++;
1294         }
1295         else
1296         {
1297           if(boundary == Dali::Accessibility::TextBoundary::WORD)
1298           {
1299             index++;
1300           }
1301           if(boundary == Dali::Accessibility::TextBoundary::LINE)
1302           {
1303             counter++;
1304           }
1305         }
1306
1307         if((counter > 0) && ((counter - 1) == offset))
1308         {
1309           range.content     = text.substr(start, index - start + 1);
1310           range.startOffset = start;
1311           range.endOffset   = index + 1;
1312         }
1313
1314         if(boundary == Dali::Accessibility::TextBoundary::LINE)
1315         {
1316           index++;
1317         }
1318       }
1319       break;
1320     }
1321     case Dali::Accessibility::TextBoundary::SENTENCE:
1322     {
1323       /* not supported by default */
1324       break;
1325     }
1326     case Dali::Accessibility::TextBoundary::PARAGRAPH:
1327     {
1328       /* Paragraph is not supported by libunibreak library */
1329       break;
1330     }
1331     default:
1332       break;
1333   }
1334
1335   return range;
1336 }
1337
1338 Dali::Accessibility::Range TextLabel::TextLabelAccessible::GetRangeOfSelection(size_t selectionIndex) const
1339 {
1340   // Since DALi supports only one selection indexes higher than 0 are ignored
1341   if(selectionIndex > 0)
1342   {
1343     return {};
1344   }
1345
1346   auto        self       = Toolkit::TextLabel::DownCast(Self());
1347   auto        controller = Dali::Toolkit::GetImpl(self).GetTextController();
1348   std::string value{};
1349   controller->RetrieveSelection(value);
1350   auto indices = controller->GetSelectionIndexes();
1351
1352   return {static_cast<size_t>(indices.first), static_cast<size_t>(indices.second), value};
1353 }
1354
1355 bool TextLabel::TextLabelAccessible::RemoveSelection(size_t selectionIndex)
1356 {
1357   // Since DALi supports only one selection indexes higher than 0 are ignored
1358   if(selectionIndex > 0)
1359   {
1360     return false;
1361   }
1362
1363   auto self = Toolkit::TextLabel::DownCast(Self());
1364   Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1365   return true;
1366 }
1367
1368 bool TextLabel::TextLabelAccessible::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1369 {
1370   // Since DALi supports only one selection indexes higher than 0 are ignored
1371   if(selectionIndex > 0)
1372   {
1373     return false;
1374   }
1375
1376   auto self = Toolkit::TextLabel::DownCast(Self());
1377   Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1378   return true;
1379 }
1380
1381 Rect<> TextLabel::TextLabelAccessible::GetRangeExtents(size_t startOffset, size_t endOffset, Accessibility::CoordinateType type)
1382 {
1383   if (endOffset <= startOffset || endOffset <= 0)
1384   {
1385     return {0, 0, 0, 0};
1386   }
1387
1388   auto self = Toolkit::TextLabel::DownCast(Self());
1389   auto rect = Dali::Toolkit::GetImpl(self).GetTextController()->GetTextBoundingRectangle(startOffset, endOffset - 1);
1390
1391   auto componentExtents = this->GetExtents(type);
1392
1393   rect.x += componentExtents.x;
1394   rect.y += componentExtents.y;
1395
1396   return rect;
1397 }
1398
1399 int32_t TextLabel::TextLabelAccessible::GetLinkCount() const
1400 {
1401   auto self = Toolkit::TextLabel::DownCast(Self());
1402   return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1403 }
1404
1405 Accessibility::Hyperlink* TextLabel::TextLabelAccessible::GetLink(int32_t linkIndex) const
1406 {
1407   if(linkIndex < 0 || linkIndex >= GetLinkCount())
1408   {
1409     return nullptr;
1410   }
1411   auto self        = Toolkit::TextLabel::DownCast(Self());
1412   auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1413   return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1414 }
1415
1416 int32_t TextLabel::TextLabelAccessible::GetLinkIndex(int32_t characterOffset) const
1417 {
1418   auto self       = Toolkit::TextLabel::DownCast(Self());
1419   auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1420   return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1421 }
1422
1423 } // namespace Internal
1424
1425 } // namespace Toolkit
1426
1427 } // namespace Dali