[Tizen] Add AutofillContainer class and autofill implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
1 /*
2  * Copyright (c) 2020 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-field-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/devel-api/adaptor-framework/key-devel.h>
26 #include <dali/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
42 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/rendering/text-backend.h>
45 #include <dali-toolkit/internal/text/text-effects-style.h>
46 #include <dali-toolkit/internal/text/text-font-style.h>
47 #include <dali-toolkit/internal/text/text-view.h>
48 #include <dali-toolkit/internal/styling/style-manager-impl.h>
49 #include <dali-toolkit/devel-api/controls/control-devel.h>
50 #include <dali/integration-api/adaptor-framework/adaptor.h>
51
52 using namespace Dali::Toolkit::Text;
53
54 namespace Dali
55 {
56
57 namespace Toolkit
58 {
59
60 namespace Internal
61 {
62
63 namespace // unnamed namespace
64 {
65
66 #if defined(DEBUG_ENABLED)
67   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
68 #endif
69
70   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
71 } // unnamed namespace
72
73 namespace
74 {
75 // Type registration
76 BaseHandle Create()
77 {
78   return Toolkit::TextField::New();
79 }
80
81 // Setup properties, signals and actions using the type-registry.
82 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
83
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text",                                 STRING,    TEXT                                 )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText",                      STRING,    PLACEHOLDER_TEXT                     )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused",               STRING,    PLACEHOLDER_TEXT_FOCUSED             )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily",                           STRING,    FONT_FAMILY                          )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle",                            MAP,       FONT_STYLE                           )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize",                            FLOAT,     POINT_SIZE                           )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength",                            INTEGER,   MAX_LENGTH                           )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy",                         INTEGER,   EXCEED_POLICY                        )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment",                  STRING,    HORIZONTAL_ALIGNMENT                 )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment",                    STRING,    VERTICAL_ALIGNMENT                   )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor",                            VECTOR4,   TEXT_COLOR                           )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor",                 VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor",                   VECTOR4,   PRIMARY_CURSOR_COLOR                 )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor",                 VECTOR4,   SECONDARY_CURSOR_COLOR               )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink",                    BOOLEAN,   ENABLE_CURSOR_BLINK                  )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval",                  FLOAT,     CURSOR_BLINK_INTERVAL                )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration",                  FLOAT,     CURSOR_BLINK_DURATION                )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth",                          INTEGER,   CURSOR_WIDTH                         )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage",                      STRING,    GRAB_HANDLE_IMAGE                    )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage",               STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold",                      FLOAT,     SCROLL_THRESHOLD                     )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed",                          FLOAT,     SCROLL_SPEED                         )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft",             MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight",            MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft",      MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight",     MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft",       MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight",      MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor",              VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox",                RECTANGLE, DECORATION_BOUNDING_BOX              )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings",                  MAP,       INPUT_METHOD_SETTINGS                )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor",                           VECTOR4,   INPUT_COLOR                          )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup",                         BOOLEAN,   ENABLE_MARKUP                        )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily",                      STRING,    INPUT_FONT_FAMILY                    )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle",                       MAP,       INPUT_FONT_STYLE                     )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize",                       FLOAT,     INPUT_POINT_SIZE                     )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline",                            MAP,       UNDERLINE                            )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline",                       MAP,       INPUT_UNDERLINE                      )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow",                               MAP,       SHADOW                               )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow",                          MAP,       INPUT_SHADOW                         )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss",                               MAP,       EMBOSS                               )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss",                          MAP,       INPUT_EMBOSS                         )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline",                              MAP,       OUTLINE                              )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline",                         MAP,       INPUT_OUTLINE                        )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings",                  MAP,       HIDDEN_INPUT_SETTINGS                )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize",                            FLOAT,     PIXEL_SIZE                           )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection",                      BOOLEAN,   ENABLE_SELECTION                     )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder",                          MAP,       PLACEHOLDER                          )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis",                             BOOLEAN,   ELLIPSIS                             )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection",           BOOLEAN,   ENABLE_SHIFT_SELECTION               )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle",               BOOLEAN,   ENABLE_GRAB_HANDLE                   )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection",   BOOLEAN,   MATCH_SYSTEM_LANGUAGE_DIRECTION      )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup",          BOOLEAN,   ENABLE_GRAB_HANDLE_POPUP             )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground",                 VECTOR4,   BACKGROUND                           )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText",         STRING,    SELECTED_TEXT                        )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend",               INTEGER,   RENDERING_BACKEND                    )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart",              INTEGER,   SELECTED_TEXT_START                  )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd",                INTEGER,   SELECTED_TEXT_END                    )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing",                  BOOLEAN,   ENABLE_EDITING                       )
143 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "fontSizeScale",                  FLOAT,     FONT_SIZE_SCALE                      )
144 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorPosition",          INTEGER,   PRIMARY_CURSOR_POSITION              )
145
146 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged",        SIGNAL_TEXT_CHANGED )
147 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached",   SIGNAL_MAX_LENGTH_REACHED )
148 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
149
150 DALI_TYPE_REGISTRATION_END()
151
152 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
153
154 /// Retrieves a filename from a value that is a Property::Map
155 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
156 {
157   std::string filename;
158   const Property::Map* map = value.GetMap();
159   if( map )
160   {
161     const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
162     if( filenameValue )
163     {
164       filenameValue->Get( filename );
165     }
166   }
167   return filename;
168 }
169
170 } // namespace
171
172 Toolkit::TextField TextField::New()
173 {
174   // Create the implementation, temporarily owned by this handle on stack
175   IntrusivePtr< TextField > impl = new TextField();
176
177   // Pass ownership to CustomActor handle
178   Toolkit::TextField handle( *impl );
179
180   // Second-phase init of the implementation
181   // This can only be done after the CustomActor connection has been made...
182   impl->Initialize();
183
184   return handle;
185 }
186
187 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
188 {
189   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
190
191   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
192
193   if( textField )
194   {
195     TextField& impl( GetImpl( textField ) );
196     DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
197     DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
198
199     switch( index )
200     {
201       case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
202       {
203         int backend = value.Get< int >();
204         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
205
206 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
207         if( DevelText::RENDERING_VECTOR_BASED == backend )
208         {
209           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
210         }
211 #endif
212         if( impl.mRenderingBackend != backend )
213         {
214           impl.mRenderingBackend = backend;
215           impl.mRenderer.Reset();
216
217           // When using the vector-based rendering, the size of the GLyphs are different
218           TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
219           impl.mController->SetGlyphType( glyphType );
220         }
221         break;
222       }
223       case Toolkit::TextField::Property::TEXT:
224       {
225         const std::string& text = value.Get< std::string >();
226         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
227
228         impl.mController->SetText( text );
229         break;
230       }
231       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
232       {
233         const std::string& text = value.Get< std::string >();
234         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
235
236         impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
237         break;
238       }
239       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
240       {
241         const std::string& text = value.Get< std::string >();
242         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
243
244         impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
245         break;
246       }
247       case Toolkit::TextField::Property::FONT_FAMILY:
248       {
249         const std::string& fontFamily = value.Get< std::string >();
250         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
251         impl.mController->SetDefaultFontFamily( fontFamily );
252         break;
253       }
254       case Toolkit::TextField::Property::FONT_STYLE:
255       {
256         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
257         break;
258       }
259       case Toolkit::TextField::Property::POINT_SIZE:
260       {
261         const float pointSize = value.Get< float >();
262         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
263
264         if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
265         {
266           impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
267         }
268         break;
269       }
270       case Toolkit::TextField::Property::MAX_LENGTH:
271       {
272         const int max = value.Get< int >();
273         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
274
275         impl.mController->SetMaximumNumberOfCharacters( max );
276         break;
277       }
278       case Toolkit::TextField::Property::EXCEED_POLICY:
279       {
280         impl.mExceedPolicy = value.Get<int>();
281
282         if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
283         {
284           impl.EnableClipping();
285         }
286         else
287         {
288           UnparentAndReset( impl.mStencil );
289         }
290         impl.RequestTextRelayout();
291         break;
292       }
293       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
294       {
295         Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
296         if( GetHorizontalAlignmentEnumeration( value, alignment ) )
297         {
298           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
299           impl.mController->SetHorizontalAlignment( alignment );
300         }
301         break;
302       }
303       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
304       {
305         Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
306         if( GetVerticalAlignmentEnumeration( value, alignment ) )
307         {
308           impl.mController->SetVerticalAlignment( alignment );
309           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
310         }
311         break;
312       }
313       case Toolkit::TextField::Property::TEXT_COLOR:
314       {
315         const Vector4& textColor = value.Get< Vector4 >();
316         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
317
318         if( impl.mController->GetDefaultColor() != textColor )
319         {
320           impl.mController->SetDefaultColor( textColor );
321           impl.mController->SetInputColor( textColor );
322           impl.mRenderer.Reset();
323         }
324         break;
325       }
326       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
327       {
328         const Vector4& textColor = value.Get< Vector4 >();
329         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
330
331         if( impl.mController->GetPlaceholderTextColor() != textColor )
332         {
333           impl.mController->SetPlaceholderTextColor( textColor );
334           impl.mRenderer.Reset();
335         }
336         break;
337       }
338       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
339       {
340         const Vector4& color = value.Get< Vector4 >();
341         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
342
343         impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
344         impl.RequestTextRelayout();
345         break;
346       }
347       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
348       {
349         const Vector4& color = value.Get< Vector4 >();
350         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
351
352         impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
353         impl.RequestTextRelayout();
354         break;
355       }
356       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
357       {
358         const bool enable = value.Get< bool >();
359         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
360
361         impl.mController->SetEnableCursorBlink( enable );
362         impl.RequestTextRelayout();
363         break;
364       }
365       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
366       {
367         const float interval = value.Get< float >();
368         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
369
370         impl.mDecorator->SetCursorBlinkInterval( interval );
371         break;
372       }
373       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
374       {
375         const float duration = value.Get< float >();
376         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
377
378         impl.mDecorator->SetCursorBlinkDuration( duration );
379         break;
380       }
381       case Toolkit::TextField::Property::CURSOR_WIDTH:
382       {
383         const int width = value.Get< int >();
384         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
385
386         impl.mDecorator->SetCursorWidth( width );
387         impl.mController->GetLayoutEngine().SetCursorWidth( width );
388         break;
389       }
390       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
391       {
392         const std::string imageFileName = value.Get< std::string >();
393         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
394
395         if( imageFileName.size() )
396         {
397           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
398           impl.RequestTextRelayout();
399         }
400         break;
401       }
402       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
403       {
404         const std::string imageFileName = value.Get< std::string >();
405         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
406
407         if( imageFileName.size() )
408         {
409           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
410           impl.RequestTextRelayout();
411         }
412         break;
413       }
414       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
415       {
416         const float threshold = value.Get< float >();
417         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
418
419         impl.mDecorator->SetScrollThreshold( threshold );
420         break;
421       }
422       case Toolkit::TextField::Property::SCROLL_SPEED:
423       {
424         const float speed = value.Get< float >();
425         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
426
427         impl.mDecorator->SetScrollSpeed( speed );
428         break;
429       }
430       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
431       {
432         const std::string filename = GetImageFileNameFromPropertyValue( value );
433
434         if( filename.size() )
435         {
436           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
437           impl.RequestTextRelayout();
438         }
439         break;
440       }
441       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
442       {
443         const std::string filename = GetImageFileNameFromPropertyValue( value );
444
445         if( filename.size() )
446         {
447           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
448           impl.RequestTextRelayout();
449         }
450         break;
451       }
452       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
453       {
454         const std::string filename = GetImageFileNameFromPropertyValue( value );
455
456         if( filename.size() )
457         {
458           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
459           impl.RequestTextRelayout();
460         }
461         break;
462       }
463       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
464       {
465         const std::string filename = GetImageFileNameFromPropertyValue( value );
466
467         if( filename.size() )
468         {
469           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
470           impl.RequestTextRelayout();
471         }
472         break;
473       }
474       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
475       {
476         const std::string filename = GetImageFileNameFromPropertyValue( value );
477
478         if( filename.size() )
479         {
480           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
481           impl.RequestTextRelayout();
482         }
483         break;
484       }
485       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
486       {
487         const std::string filename = GetImageFileNameFromPropertyValue( value );
488
489         if( filename.size() )
490         {
491           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
492           impl.RequestTextRelayout();
493         }
494         break;
495       }
496       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
497       {
498         const Vector4 color = value.Get< Vector4 >();
499         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
500
501         impl.mDecorator->SetHighlightColor( color );
502         impl.RequestTextRelayout();
503         break;
504       }
505       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
506       {
507         const Rect<int> box = value.Get< Rect<int> >();
508         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
509
510         impl.mDecorator->SetBoundingBox( box );
511         impl.RequestTextRelayout();
512         break;
513       }
514       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
515       {
516         const Property::Map* map = value.GetMap();
517         if (map)
518         {
519           impl.mInputMethodOptions.ApplyProperty( *map );
520         }
521         impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
522
523         Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
524         if (control == textField)
525         {
526           impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
527         }
528         break;
529       }
530       case Toolkit::TextField::Property::INPUT_COLOR:
531       {
532         const Vector4 inputColor = value.Get< Vector4 >();
533         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
534
535         impl.mController->SetInputColor( inputColor );
536         break;
537       }
538       case Toolkit::TextField::Property::ENABLE_MARKUP:
539       {
540         const bool enableMarkup = value.Get<bool>();
541         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
542
543         impl.mController->SetMarkupProcessorEnabled( enableMarkup );
544         break;
545       }
546       case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
547       {
548         const std::string& fontFamily = value.Get< std::string >();
549         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
550         impl.mController->SetInputFontFamily( fontFamily );
551         break;
552       }
553       case Toolkit::TextField::Property::INPUT_FONT_STYLE:
554       {
555         SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
556         break;
557       }
558       case Toolkit::TextField::Property::INPUT_POINT_SIZE:
559       {
560         const float pointSize = value.Get< float >();
561         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
562         impl.mController->SetInputFontPointSize( pointSize );
563         break;
564       }
565       case Toolkit::TextField::Property::UNDERLINE:
566       {
567         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
568         if( update )
569         {
570           impl.mRenderer.Reset();
571         }
572         break;
573       }
574       case Toolkit::TextField::Property::INPUT_UNDERLINE:
575       {
576         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
577         if( update )
578         {
579           impl.mRenderer.Reset();
580         }
581         break;
582       }
583       case Toolkit::TextField::Property::SHADOW:
584       {
585         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
586         if( update )
587         {
588           impl.mRenderer.Reset();
589         }
590         break;
591       }
592       case Toolkit::TextField::Property::INPUT_SHADOW:
593       {
594         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
595         if( update )
596         {
597           impl.mRenderer.Reset();
598         }
599         break;
600       }
601       case Toolkit::TextField::Property::EMBOSS:
602       {
603         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
604         if( update )
605         {
606           impl.mRenderer.Reset();
607         }
608         break;
609       }
610       case Toolkit::TextField::Property::INPUT_EMBOSS:
611       {
612         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
613         if( update )
614         {
615           impl.mRenderer.Reset();
616         }
617         break;
618       }
619       case Toolkit::TextField::Property::OUTLINE:
620       {
621         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
622         if( update )
623         {
624           impl.mRenderer.Reset();
625         }
626         break;
627       }
628       case Toolkit::TextField::Property::INPUT_OUTLINE:
629       {
630         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
631         if( update )
632         {
633           impl.mRenderer.Reset();
634         }
635         break;
636       }
637       case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
638       {
639         const Property::Map* map = value.GetMap();
640         if (map)
641         {
642           impl.mController->SetHiddenInputOption(*map);
643         }
644         break;
645       }
646       case Toolkit::TextField::Property::PIXEL_SIZE:
647       {
648         const float pixelSize = value.Get< float >();
649         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
650
651         if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
652         {
653           impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
654         }
655         break;
656       }
657       case Toolkit::TextField::Property::ENABLE_SELECTION:
658       {
659         const bool enableSelection = value.Get< bool >();
660         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
661         impl.mController->SetSelectionEnabled( enableSelection );
662         break;
663       }
664       case Toolkit::TextField::Property::PLACEHOLDER:
665       {
666         const Property::Map* map = value.GetMap();
667         if( map )
668         {
669           impl.mController->SetPlaceholderProperty( *map );
670         }
671         break;
672       }
673       case Toolkit::TextField::Property::ELLIPSIS:
674       {
675         const bool ellipsis = value.Get<bool>();
676         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
677
678         impl.mController->SetTextElideEnabled( ellipsis );
679         break;
680       }
681       case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
682       {
683         const bool shiftSelection = value.Get<bool>();
684         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
685
686         impl.mController->SetShiftSelectionEnabled( shiftSelection );
687         break;
688       }
689       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
690       {
691         const bool grabHandleEnabled = value.Get<bool>();
692         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
693
694         impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
695         break;
696       }
697       case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
698       {
699         impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
700         break;
701       }
702       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
703       {
704         const bool grabHandlePopupEnabled = value.Get<bool>();
705         DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
706
707         impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
708         break;
709       }
710       case Toolkit::DevelTextField::Property::BACKGROUND:
711       {
712         const Vector4 backgroundColor = value.Get< Vector4 >();
713         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a );
714
715         impl.mController->SetBackgroundEnabled( true );
716         impl.mController->SetBackgroundColor( backgroundColor );
717         break;
718       }
719       case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
720       {
721         uint32_t start = static_cast<uint32_t>(value.Get< int >());
722         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
723         impl.SetTextSelectionRange( &start, nullptr );
724         break;
725       }
726       case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
727       {
728         uint32_t end = static_cast<uint32_t>(value.Get< int >());
729         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
730         impl.SetTextSelectionRange( nullptr, &end );
731         break;
732       }
733       case Toolkit::DevelTextField::Property::ENABLE_EDITING:
734       {
735         const bool editable = value.Get< bool >();
736         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
737         impl.SetEditable( editable );
738         break;
739       }
740       case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
741       {
742         const float scale = value.Get< float >();
743         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale );
744
745         if( !Equals( impl.mController->GetFontSizeScale(), scale ) )
746         {
747           impl.mController->SetFontSizeScale( scale );
748         }
749         break;
750       }
751       case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
752       {
753         uint32_t position = static_cast<uint32_t>(value.Get< int >());
754         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position );
755         if (impl.mController->SetPrimaryCursorPosition( position ))
756         {
757           impl.SetKeyInputFocus();
758         }
759         break;
760       }
761     } // switch
762   } // textfield
763 }
764
765 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
766 {
767   Property::Value value;
768
769   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
770
771   if( textField )
772   {
773     TextField& impl( GetImpl( textField ) );
774     DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
775     DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
776
777     switch( index )
778     {
779       case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
780       {
781         value = impl.mRenderingBackend;
782         break;
783       }
784       case Toolkit::TextField::Property::TEXT:
785       {
786         std::string text;
787         impl.mController->GetText( text );
788         DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
789         value = text;
790         break;
791       }
792       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
793       {
794         std::string text;
795         impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
796         value = text;
797         break;
798       }
799       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
800       {
801         std::string text;
802         impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
803         value = text;
804         break;
805       }
806       case Toolkit::TextField::Property::FONT_FAMILY:
807       {
808         value = impl.mController->GetDefaultFontFamily();
809         break;
810       }
811       case Toolkit::TextField::Property::FONT_STYLE:
812       {
813         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
814         break;
815       }
816       case Toolkit::TextField::Property::POINT_SIZE:
817       {
818         value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
819         break;
820       }
821       case Toolkit::TextField::Property::MAX_LENGTH:
822       {
823         value = impl.mController->GetMaximumNumberOfCharacters();
824         break;
825       }
826       case Toolkit::TextField::Property::EXCEED_POLICY:
827       {
828         value = impl.mExceedPolicy;
829         break;
830       }
831       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
832       {
833         const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
834
835         if ( name )
836         {
837           value = std::string( name );
838         }
839         break;
840       }
841       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
842       {
843         const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
844
845         if( name )
846         {
847           value = std::string( name );
848         }
849         break;
850       }
851       case Toolkit::TextField::Property::TEXT_COLOR:
852       {
853         value = impl.mController->GetDefaultColor();
854         break;
855       }
856       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
857       {
858         value = impl.mController->GetPlaceholderTextColor();
859         break;
860       }
861       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
862       {
863         value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
864         break;
865       }
866       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
867       {
868         value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
869         break;
870       }
871       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
872       {
873         value = impl.mController->GetEnableCursorBlink();
874         break;
875       }
876       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
877       {
878         value = impl.mDecorator->GetCursorBlinkInterval();
879         break;
880       }
881       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
882       {
883         value = impl.mDecorator->GetCursorBlinkDuration();
884         break;
885       }
886       case Toolkit::TextField::Property::CURSOR_WIDTH:
887       {
888         value = impl.mDecorator->GetCursorWidth();
889         break;
890       }
891       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
892       {
893         value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
894         break;
895       }
896       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
897       {
898         value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
899         break;
900       }
901       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
902       {
903         value = impl.mDecorator->GetScrollThreshold();
904         break;
905       }
906       case Toolkit::TextField::Property::SCROLL_SPEED:
907       {
908         value = impl.mDecorator->GetScrollSpeed();
909         break;
910       }
911       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
912       {
913         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
914         break;
915       }
916       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
917       {
918         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
919         break;
920       }
921       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
922       {
923         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
924         break;
925       }
926       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
927       {
928         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
929         break;
930       }
931       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
932       {
933         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
934         break;
935       }
936       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
937       {
938         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
939         break;
940       }
941       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
942       {
943         value = impl.mDecorator->GetHighlightColor();
944         break;
945       }
946       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
947       {
948         Rect<int> boundingBox;
949         impl.mDecorator->GetBoundingBox( boundingBox );
950         value = boundingBox;
951         break;
952       }
953       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
954       {
955         Property::Map map;
956         impl.mInputMethodOptions.RetrieveProperty( map );
957         value = map;
958         break;
959       }
960       case Toolkit::TextField::Property::INPUT_COLOR:
961       {
962         value = impl.mController->GetInputColor();
963         break;
964       }
965       case Toolkit::TextField::Property::ENABLE_MARKUP:
966       {
967         value = impl.mController->IsMarkupProcessorEnabled();
968         break;
969       }
970       case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
971       {
972         value = impl.mController->GetInputFontFamily();
973         break;
974       }
975       case Toolkit::TextField::Property::INPUT_FONT_STYLE:
976       {
977         GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
978         break;
979       }
980       case Toolkit::TextField::Property::INPUT_POINT_SIZE:
981       {
982         value = impl.mController->GetInputFontPointSize();
983         break;
984       }
985       case Toolkit::TextField::Property::UNDERLINE:
986       {
987         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
988         break;
989       }
990       case Toolkit::TextField::Property::INPUT_UNDERLINE:
991       {
992         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
993         break;
994       }
995       case Toolkit::TextField::Property::SHADOW:
996       {
997         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
998         break;
999       }
1000       case Toolkit::TextField::Property::INPUT_SHADOW:
1001       {
1002         GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1003         break;
1004       }
1005       case Toolkit::TextField::Property::EMBOSS:
1006       {
1007         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1008         break;
1009       }
1010       case Toolkit::TextField::Property::INPUT_EMBOSS:
1011       {
1012         GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1013         break;
1014       }
1015       case Toolkit::TextField::Property::OUTLINE:
1016       {
1017         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1018         break;
1019       }
1020       case Toolkit::TextField::Property::INPUT_OUTLINE:
1021       {
1022         GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1023         break;
1024       }
1025       case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1026       {
1027         Property::Map map;
1028         impl.mController->GetHiddenInputOption(map);
1029         value = map;
1030         break;
1031       }
1032       case Toolkit::TextField::Property::PIXEL_SIZE:
1033       {
1034         value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1035         break;
1036       }
1037       case Toolkit::TextField::Property::ENABLE_SELECTION:
1038       {
1039         value = impl.mController->IsSelectionEnabled();
1040         break;
1041       }
1042       case Toolkit::TextField::Property::PLACEHOLDER:
1043       {
1044         Property::Map map;
1045         impl.mController->GetPlaceholderProperty( map );
1046         value = map;
1047         break;
1048       }
1049       case Toolkit::TextField::Property::ELLIPSIS:
1050       {
1051         value = impl.mController->IsTextElideEnabled();
1052         break;
1053       }
1054       case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1055       {
1056         value = impl.mController->IsShiftSelectionEnabled();
1057         break;
1058       }
1059       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1060       {
1061         value = impl.mController->IsGrabHandleEnabled();
1062         break;
1063       }
1064       case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1065       {
1066         value = impl.mController->IsMatchSystemLanguageDirection();
1067         break;
1068       }
1069       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1070       {
1071         value = impl.mController->IsGrabHandlePopupEnabled();
1072         break;
1073       }
1074       case Toolkit::DevelTextField::Property::BACKGROUND:
1075       {
1076         value = impl.mController->GetBackgroundColor();
1077         break;
1078       }
1079       case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1080       {
1081         value = impl.mController->GetSelectedText( );
1082         break;
1083       }
1084       case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1085       {
1086         Uint32Pair range = impl.GetTextSelectionRange( );
1087         value = static_cast<int>(range.first);
1088         break;
1089       }
1090       case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1091       {
1092         Uint32Pair range = impl.GetTextSelectionRange( );
1093         value = static_cast<int>(range.second);
1094         break;
1095       }
1096       case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1097       {
1098         value = impl.IsEditable();
1099         break;
1100       }
1101       case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
1102       {
1103         value = impl.mController->GetFontSizeScale();
1104         break;
1105       }
1106       case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
1107       {
1108         value = static_cast<int>(impl.mController->GetPrimaryCursorPosition());
1109         break;
1110       }
1111     } //switch
1112   }
1113
1114   return value;
1115 }
1116
1117 void TextField::SelectWholeText()
1118 {
1119   if( mController && mController->IsShowingRealText() )
1120   {
1121     mController->SelectWholeText();
1122     SetKeyInputFocus();
1123   }
1124 }
1125
1126 void TextField::SelectNone()
1127 {
1128   if( mController && mController->IsShowingRealText() )
1129   {
1130     mController->SelectNone();
1131   }
1132 }
1133
1134 string TextField::GetSelectedText() const
1135 {
1136   string selectedText = "";
1137   if( mController && mController->IsShowingRealText() )
1138   {
1139     selectedText = mController->GetSelectedText( );
1140   }
1141   return selectedText;
1142 }
1143
1144 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1145 {
1146   if( mController && mController->IsShowingRealText() )
1147   {
1148     mController->SetTextSelectionRange( start, end );
1149     SetKeyInputFocus();
1150   }
1151 }
1152
1153 Uint32Pair TextField::GetTextSelectionRange() const
1154 {
1155   Uint32Pair range;
1156   if( mController && mController->IsShowingRealText() )
1157   {
1158     range = mController->GetTextSelectionRange();
1159   }
1160   return range;
1161 }
1162
1163
1164 InputMethodContext TextField::GetInputMethodContext()
1165 {
1166   return mInputMethodContext;
1167 }
1168
1169 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1170 {
1171   Dali::BaseHandle handle( object );
1172
1173   bool connected( true );
1174   Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1175
1176   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1177   {
1178     field.TextChangedSignal().Connect( tracker, functor );
1179   }
1180   else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1181   {
1182     field.MaxLengthReachedSignal().Connect( tracker, functor );
1183   }
1184   else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1185   {
1186     field.InputStyleChangedSignal().Connect( tracker, functor );
1187   }
1188   else
1189   {
1190     // signalName does not match any signal
1191     connected = false;
1192   }
1193
1194   return connected;
1195 }
1196
1197 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1198 {
1199   return mTextChangedSignal;
1200 }
1201
1202 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1203 {
1204   return mMaxLengthReachedSignal;
1205 }
1206
1207 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1208 {
1209   return mInputStyleChangedSignal;
1210 }
1211
1212 void TextField::OnInitialize()
1213 {
1214   Actor self = Self();
1215
1216   mController = Text::Controller::New( this, this ,this);
1217
1218   // When using the vector-based rendering, the size of the GLyphs are different
1219   TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1220   mController->SetGlyphType( glyphType );
1221
1222   mDecorator = Text::Decorator::New( *mController,
1223                                      *mController );
1224
1225   mInputMethodContext = InputMethodContext::New( self );
1226
1227   mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1228
1229   // Enables the text input.
1230   mController->EnableTextInput( mDecorator, mInputMethodContext );
1231
1232   // Enables the horizontal scrolling after the text input has been enabled.
1233   mController->SetHorizontalScrollEnabled( true );
1234
1235   // Disables the vertical scrolling.
1236   mController->SetVerticalScrollEnabled( false );
1237
1238   // Disable the smooth handle panning.
1239   mController->SetSmoothHandlePanEnabled( false );
1240
1241   mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1242   mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1243
1244   // Sets layoutDirection value
1245   Dali::Stage stage = Dali::Stage::GetCurrent();
1246   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1247   mController->SetLayoutDirection( layoutDirection );
1248
1249   // Forward input events to controller
1250   EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1251   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1252
1253   self.TouchedSignal().Connect( this, &TextField::OnTouched );
1254
1255   // Set BoundingBox to stage size if not already set.
1256   Rect<int> boundingBox;
1257   mDecorator->GetBoundingBox( boundingBox );
1258
1259   if( boundingBox.IsEmpty() )
1260   {
1261     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1262     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1263   }
1264
1265   // Flip vertically the 'left' selection handle
1266   mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1267
1268   // Fill-parent area by default
1269   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1270   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1271   self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1272
1273   //Enable highightability
1274   self.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true );
1275
1276   DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1277
1278   if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1279   {
1280     EnableClipping();
1281   }
1282
1283   DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) {
1284     return std::unique_ptr< Dali::Accessibility::Accessible >(
1285       new AccessibleImpl( actor, Dali::Accessibility::Role::ENTRY ) );
1286   } );
1287 }
1288
1289 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1290 {
1291   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1292
1293   switch ( change )
1294   {
1295     case StyleChange::DEFAULT_FONT_CHANGE:
1296     {
1297       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1298       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1299       // Property system did not set the font so should update it.
1300       mController->UpdateAfterFontChange( newFont );
1301       RelayoutRequest();
1302       break;
1303     }
1304
1305     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1306     {
1307       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1308       RelayoutRequest();
1309       break;
1310     }
1311     case StyleChange::THEME_CHANGE:
1312     {
1313       // Nothing to do, let control base class handle this
1314       break;
1315     }
1316   }
1317
1318   // Up call to Control
1319   Control::OnStyleChange( styleManager, change );
1320 }
1321
1322 Vector3 TextField::GetNaturalSize()
1323 {
1324   Extents padding;
1325   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1326
1327   Vector3 naturalSize = mController->GetNaturalSize();
1328   naturalSize.width += ( padding.start + padding.end );
1329   naturalSize.height += ( padding.top + padding.bottom );
1330
1331   return naturalSize;
1332 }
1333
1334 float TextField::GetHeightForWidth( float width )
1335 {
1336   Extents padding;
1337   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1338   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1339 }
1340
1341 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1342 {
1343   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1344
1345   Actor self = Self();
1346
1347   Extents padding;
1348   padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1349
1350   Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1351
1352   // Support Right-To-Left of padding
1353   Dali::LayoutDirection::Type layoutDirection;
1354   if( mController->IsMatchSystemLanguageDirection() )
1355   {
1356     layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1357   }
1358   else
1359   {
1360     layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1361   }
1362   if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1363   {
1364     std::swap( padding.start, padding.end );
1365   }
1366
1367   if( mStencil )
1368   {
1369     mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1370   }
1371   if( mActiveLayer )
1372   {
1373     mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1374   }
1375
1376   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1377
1378   if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1379       !mRenderer )
1380   {
1381     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1382
1383     if( mDecorator &&
1384         ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1385     {
1386       mDecorator->Relayout( size );
1387     }
1388
1389     if( !mRenderer )
1390     {
1391       mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1392     }
1393
1394     RenderText( updateTextType );
1395
1396   }
1397
1398   // The text-field emits signals when the input style changes. These changes of style are
1399   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1400   // can't be emitted during the size negotiation as the callbacks may update the UI.
1401   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1402   if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1403   {
1404     if( Adaptor::IsAvailable() )
1405     {
1406       Adaptor& adaptor = Adaptor::Get();
1407
1408       if( NULL == mIdleCallback )
1409       {
1410         // @note: The callback manager takes the ownership of the callback object.
1411         mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1412         adaptor.AddIdle( mIdleCallback, false );
1413       }
1414     }
1415   }
1416 }
1417
1418 Text::ControllerPtr TextField::getController() { return mController; }
1419
1420 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1421 {
1422   Actor renderableActor;
1423
1424   if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1425   {
1426     if( mRenderer )
1427     {
1428       Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1429
1430       renderableActor = mRenderer->Render( mController->GetView(),
1431                                            handle,
1432                                            Property::INVALID_INDEX, // Animatable property not supported
1433                                            mAlignmentOffset,
1434                                            DepthIndex::CONTENT );
1435     }
1436
1437     if( renderableActor != mRenderableActor )
1438     {
1439       UnparentAndReset( mBackgroundActor );
1440       UnparentAndReset( mRenderableActor );
1441       mRenderableActor = renderableActor;
1442
1443       if ( mRenderableActor )
1444       {
1445         mBackgroundActor = mController->CreateBackgroundActor();
1446       }
1447     }
1448   }
1449
1450   if( mRenderableActor )
1451   {
1452     const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1453
1454     float renderableActorPositionX, renderableActorPositionY;
1455
1456     if( mStencil )
1457     {
1458       renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1459       renderableActorPositionY = scrollOffset.y;
1460     }
1461     else
1462     {
1463       Extents padding;
1464       padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1465
1466       // Support Right-To-Left of padding
1467       Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1468       if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1469       {
1470         std::swap( padding.start, padding.end );
1471       }
1472
1473       renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1474       renderableActorPositionY = scrollOffset.y + padding.top;
1475     }
1476
1477     mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1478
1479     // Make sure the actors are parented correctly with/without clipping
1480     Actor self = mStencil ? mStencil : Self();
1481
1482     Actor highlightActor;
1483
1484     for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1485            endIt = mClippingDecorationActors.end();
1486          it != endIt;
1487          ++it )
1488     {
1489       self.Add( *it );
1490       it->LowerToBottom();
1491
1492       if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1493       {
1494         highlightActor = *it;
1495       }
1496     }
1497     mClippingDecorationActors.clear();
1498
1499     self.Add( mRenderableActor );
1500
1501     if ( mBackgroundActor )
1502     {
1503       if ( mDecorator && mDecorator->IsHighlightVisible() )
1504       {
1505         self.Add( mBackgroundActor );
1506         mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1507         mBackgroundActor.LowerBelow( highlightActor );
1508       }
1509       else
1510       {
1511         mRenderableActor.Add( mBackgroundActor );
1512         mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1513         mBackgroundActor.LowerToBottom();
1514       }
1515     }
1516   }
1517 }
1518
1519 void TextField::OnKeyInputFocusGained()
1520 {
1521   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1522   if( mInputMethodContext && IsEditable() )
1523   {
1524     // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
1525     mInputMethodContext.ApplyOptions( mInputMethodOptions );
1526     mInputMethodContext.NotifyTextInputMultiLine( false );
1527
1528     mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1529
1530     mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1531
1532     // Notify that the text editing start.
1533     mInputMethodContext.Activate();
1534
1535     // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1536     mInputMethodContext.SetRestoreAfterFocusLost( true );
1537   }
1538
1539   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1540   if( notifier )
1541   {
1542     notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1543   }
1544
1545   Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1546   Internal::Control& controlImpl = GetImplementation( control );
1547   Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1548   bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1549   if( enableAutofill )
1550   {
1551     Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1552     container.SetFocusedControl( control );
1553
1554     Internal::AutofillContainer& containerImpl = GetImpl( container );
1555     Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1556     if( containerGroup != nullptr )
1557     {
1558       containerGroup.RequestAuthentication();
1559     }
1560
1561   }
1562   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1563
1564   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1565 }
1566
1567 void TextField::OnKeyInputFocusLost()
1568 {
1569   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1570   if ( mInputMethodContext )
1571   {
1572     mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1573     // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1574     mInputMethodContext.SetRestoreAfterFocusLost( false );
1575
1576     // Notify that the text editing finish.
1577     mInputMethodContext.Deactivate();
1578
1579     mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1580   }
1581   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1582
1583   if ( notifier )
1584   {
1585     notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1586   }
1587
1588   mController->KeyboardFocusLostEvent();
1589
1590   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1591 }
1592
1593 bool TextField::OnAccessibilityActivated()
1594 {
1595   SetKeyInputFocus();
1596   return true;
1597 }
1598
1599 void TextField::OnTap( const TapGesture& gesture )
1600 {
1601   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1602   if ( mInputMethodContext && IsEditable() )
1603   {
1604     mInputMethodContext.Activate();
1605   }
1606   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1607   Extents padding;
1608   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1609   const Vector2& localPoint = gesture.GetLocalPoint();
1610   mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1611
1612   SetKeyInputFocus();
1613 }
1614
1615 void TextField::OnPan( const PanGesture& gesture )
1616 {
1617   mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1618 }
1619
1620 void TextField::OnLongPress( const LongPressGesture& gesture )
1621 {
1622   if ( mInputMethodContext && IsEditable() )
1623   {
1624     mInputMethodContext.Activate();
1625   }
1626   Extents padding;
1627   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1628   const Vector2& localPoint = gesture.GetLocalPoint();
1629   mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1630
1631   SetKeyInputFocus();
1632 }
1633
1634 bool TextField::OnKeyEvent( const KeyEvent& event )
1635 {
1636   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1637
1638   if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1639   {
1640     // Make sure ClearKeyInputFocus when only key is up
1641     if( event.GetState() == KeyEvent::UP )
1642     {
1643       ClearKeyInputFocus();
1644     }
1645
1646     return true;
1647   }
1648   else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1649   {
1650     // Do nothing when enter is comming.
1651     return false;
1652   }
1653
1654   return mController->KeyEvent( event );
1655 }
1656
1657 void TextField::RequestTextRelayout()
1658 {
1659   RelayoutRequest();
1660 }
1661
1662 bool TextField::IsEditable() const
1663 {
1664   return mController->IsEditable();
1665 }
1666
1667 void TextField::SetEditable( bool editable )
1668 {
1669   mController->SetEditable(editable);
1670   if ( mInputMethodContext && !editable )
1671   {
1672     mInputMethodContext.Deactivate();
1673   }
1674 }
1675
1676 void TextField::TextInserted( unsigned int position, unsigned int length, const std::string &content )
1677 {
1678   if( Accessibility::IsUp() )
1679   {
1680     Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content );
1681   }
1682 }
1683
1684 void TextField::TextDeleted( unsigned int position, unsigned int length, const std::string &content )
1685 {
1686   if( Accessibility::IsUp() )
1687   {
1688     Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content );
1689   }
1690 }
1691
1692 void TextField::CaretMoved( unsigned int position )
1693 {
1694   if( Accessibility::IsUp() )
1695   {
1696     Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position );
1697   }
1698 }
1699
1700 void TextField::TextChanged()
1701 {
1702   Dali::Toolkit::TextField handle( GetOwner() );
1703   mTextChangedSignal.Emit( handle );
1704 }
1705
1706 void TextField::MaxLengthReached()
1707 {
1708   Dali::Toolkit::TextField handle( GetOwner() );
1709   mMaxLengthReachedSignal.Emit( handle );
1710 }
1711
1712 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1713 {
1714   Dali::Toolkit::TextField handle( GetOwner() );
1715
1716   Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1717
1718   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1719   {
1720     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1721   }
1722   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1723   {
1724     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1725   }
1726   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1727   {
1728     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1729   }
1730   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1731   {
1732     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1733   }
1734   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1735   {
1736     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1737   }
1738   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1739   {
1740     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1741   }
1742   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1743   {
1744     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1745   }
1746   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1747   {
1748     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1749   }
1750   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1751   {
1752     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1753   }
1754   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1755   {
1756     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1757   }
1758
1759   mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1760 }
1761
1762 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1763 {
1764   if( actor )
1765   {
1766     if( needsClipping )
1767     {
1768       mClippingDecorationActors.push_back( actor );
1769     }
1770     else
1771     {
1772       actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1773       actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1774       Self().Add( actor );
1775       mActiveLayer = actor;
1776     }
1777   }
1778 }
1779
1780 void TextField::OnSceneConnect( Dali::Actor actor )
1781 {
1782   if ( mHasBeenStaged )
1783   {
1784     RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1785   }
1786   else
1787   {
1788     mHasBeenStaged = true;
1789   }
1790 }
1791
1792 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1793 {
1794   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1795   return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1796 }
1797
1798 void TextField::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1799 {
1800   if( mDecorator )
1801   {
1802     Property::Map map;
1803     map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1804     value = map;
1805   }
1806 }
1807
1808 void TextField::EnableClipping()
1809 {
1810   if( !mStencil )
1811   {
1812     // Creates an extra control to be used as stencil buffer.
1813     mStencil = Control::New();
1814     mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1815     mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1816
1817     // Creates a background visual. Even if the color is transparent it updates the stencil.
1818     mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1819                           Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1820                           Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1821
1822     // Enable the clipping property.
1823     mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1824     mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1825
1826     Self().Add( mStencil );
1827   }
1828 }
1829
1830 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1831 {
1832   mController->PasteClipboardItemEvent();
1833 }
1834
1835 void TextField::KeyboardStatusChanged(bool keyboardShown)
1836 {
1837   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1838
1839   // Just hide the grab handle when keyboard is hidden.
1840   if (!keyboardShown )
1841   {
1842     mController->KeyboardFocusLostEvent();
1843   }
1844   else
1845   {
1846     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1847   }
1848 }
1849
1850 void TextField::OnSceneConnection( int depth )
1851 {
1852   // Sets the depth to the visuals inside the text's decorator.
1853   mDecorator->SetTextDepth( depth );
1854
1855   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1856
1857   // Call the Control::OnSceneConnection() to set the depth of the background.
1858   Control::OnSceneConnection( depth );
1859 }
1860
1861 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1862 {
1863   return false;
1864 }
1865
1866 void TextField::OnIdleSignal()
1867 {
1868   // Emits the change of input style signals.
1869   mController->ProcessInputStyleChangedSignals();
1870
1871   // Set the pointer to null as the callback manager deletes the callback after execute it.
1872   mIdleCallback = NULL;
1873 }
1874
1875 TextField::TextField()
1876 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1877   mIdleCallback( NULL ),
1878   mAlignmentOffset( 0.f ),
1879   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1880   mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1881   mHasBeenStaged( false )
1882 {
1883 }
1884
1885 TextField::~TextField()
1886 {
1887   UnparentAndReset( mStencil );
1888
1889   if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1890   {
1891     Adaptor::Get().RemoveIdle( mIdleCallback );
1892   }
1893 }
1894
1895 std::string TextField::AccessibleImpl::GetName()
1896 {
1897   auto slf = Toolkit::TextField::DownCast( self );
1898   return slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1899 }
1900
1901 std::string TextField::AccessibleImpl::GetText( size_t startOffset,
1902                                                 size_t endOffset )
1903 {
1904   if( endOffset <= startOffset )
1905     return {};
1906
1907   auto slf = Toolkit::TextField::DownCast( self );
1908   auto txt =
1909       slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1910
1911   if( startOffset > txt.size() || endOffset > txt.size() )
1912     return {};
1913
1914   return txt.substr( startOffset, endOffset - startOffset );
1915 }
1916
1917 size_t TextField::AccessibleImpl::GetCharacterCount()
1918 {
1919   auto slf = Toolkit::TextField::DownCast( self );
1920   auto txt =
1921       slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1922
1923   return txt.size();
1924 }
1925
1926 size_t TextField::AccessibleImpl::GetCaretOffset()
1927 {
1928   auto slf = Toolkit::TextField::DownCast( self );
1929   return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition();
1930 }
1931
1932 bool TextField::AccessibleImpl::SetCaretOffset(size_t offset)
1933 {
1934   auto slf = Toolkit::TextField::DownCast( self );
1935   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1936   if (offset > txt.size())
1937     return false;
1938
1939   auto& slfImpl = Dali::Toolkit::GetImpl( slf );
1940   slfImpl.getController()->ResetCursorPosition( offset );
1941   slfImpl.RequestTextRelayout();
1942   return true;
1943 }
1944
1945 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1946     size_t offset, Dali::Accessibility::TextBoundary boundary )
1947 {
1948   auto slf = Toolkit::TextField::DownCast( self );
1949   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1950   auto txt_size = txt.size();
1951
1952   auto range = Dali::Accessibility::Range{};
1953
1954   switch(boundary)
1955   {
1956     case Dali::Accessibility::TextBoundary::CHARACTER:
1957       {
1958         if (offset < txt_size)
1959         {
1960           range.content = txt[offset];
1961           range.startOffset = offset;
1962           range.endOffset = offset + 1;
1963         }
1964       }
1965       break;
1966     case Dali::Accessibility::TextBoundary::WORD:
1967     case Dali::Accessibility::TextBoundary::LINE:
1968       {
1969         auto txt_c_string = txt.c_str();
1970         auto breaks = std::vector< char >( txt_size, 0 );
1971         if(boundary == Dali::Accessibility::TextBoundary::WORD)
1972           Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1973         else
1974           Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1975         auto index = 0u;
1976         auto counter = 0u;
1977         while( index < txt_size && counter <= offset )
1978         {
1979           auto start = index;
1980           if(breaks[index])
1981           {
1982             while(breaks[index])
1983               index++;
1984             counter++;
1985           }
1986           else
1987           {
1988             if (boundary == Dali::Accessibility::TextBoundary::WORD)
1989               index++;
1990             if (boundary == Dali::Accessibility::TextBoundary::LINE)
1991               counter++;
1992           }
1993           if ((counter > 0) && ((counter - 1) == offset))
1994           {
1995             range.content = txt.substr(start, index - start + 1);
1996             range.startOffset = start;
1997             range.endOffset = index + 1;
1998           }
1999           if (boundary == Dali::Accessibility::TextBoundary::LINE)
2000               index++;
2001         }
2002       }
2003       break;
2004     case Dali::Accessibility::TextBoundary::SENTENCE:
2005       {
2006         /* not supported by efl */
2007       }
2008       break;
2009     case Dali::Accessibility::TextBoundary::PARAGRAPH:
2010       {
2011         /* Paragraph is not supported by libunibreak library */
2012       }
2013       break;
2014     default:
2015       break;
2016   }
2017
2018   return range;
2019 }
2020
2021 Dali::Accessibility::Range
2022 TextField::AccessibleImpl::GetSelection( size_t selectionNum )
2023 {
2024   // Since DALi supports only one selection indexes higher than 0 are ignored
2025   if( selectionNum > 0 )
2026     return {};
2027
2028   auto slf = Toolkit::TextField::DownCast( self );
2029   auto ctrl = Dali::Toolkit::GetImpl( slf ).getController();
2030   std::string ret;
2031   ctrl->RetrieveSelection( ret );
2032   auto r = ctrl->GetSelectionIndexes();
2033
2034   return { static_cast<size_t>(r.first), static_cast<size_t>(r.second), ret };
2035 }
2036
2037 bool TextField::AccessibleImpl::RemoveSelection( size_t selectionNum )
2038 {
2039   // Since DALi supports only one selection indexes higher than 0 are ignored
2040   if( selectionNum > 0 )
2041     return false;
2042
2043   auto slf = Toolkit::TextField::DownCast( self );
2044   Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
2045   return true;
2046 }
2047
2048 bool TextField::AccessibleImpl::SetSelection( size_t selectionNum,
2049                                               size_t startOffset,
2050                                               size_t endOffset )
2051 {
2052   // Since DALi supports only one selection indexes higher than 0 are ignored
2053   if( selectionNum > 0 )
2054     return false;
2055
2056   auto slf = Toolkit::TextField::DownCast( self );
2057   Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
2058                                                                endOffset );
2059   return true;
2060 }
2061
2062 bool TextField::AccessibleImpl::CopyText( size_t startPosition,
2063                                            size_t endPosition )
2064 {
2065   if( endPosition <= startPosition )
2066     return false;
2067
2068   auto slf = Toolkit::TextField::DownCast( self );
2069   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2070   Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2071
2072   return true;
2073 }
2074
2075 bool TextField::AccessibleImpl::CutText( size_t startPosition,
2076                                           size_t endPosition )
2077 {
2078   if( endPosition <= startPosition )
2079     return false;
2080
2081   auto slf = Toolkit::TextField::DownCast( self );
2082   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2083   Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2084
2085   slf.SetProperty( Toolkit::TextField::Property::TEXT,
2086                    txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size()));
2087
2088   return true;
2089 }
2090
2091 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
2092 {
2093   using namespace Dali::Accessibility;
2094
2095   auto states = Control::Impl::AccessibleImpl::CalculateStates();
2096
2097   states[State::EDITABLE] = true;
2098   states[State::FOCUSABLE] = true;
2099
2100   Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
2101   if (self == focusControl)
2102   {
2103     states[State::FOCUSED] = true;
2104   }
2105
2106   return states;
2107 }
2108
2109 } // namespace Internal
2110
2111 } // namespace Toolkit
2112
2113 } // namespace Dali