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