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