[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     mInputMethodContext.ApplyOptions( mInputMethodOptions );
1525
1526     mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1527
1528     mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1529
1530     // Notify that the text editing start.
1531     mInputMethodContext.Activate();
1532
1533     // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1534     mInputMethodContext.SetRestoreAfterFocusLost( true );
1535   }
1536
1537   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1538   if( notifier )
1539   {
1540     notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1541   }
1542
1543   Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1544   Internal::Control& controlImpl = GetImplementation( control );
1545   Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1546   bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1547   if( enableAutofill )
1548   {
1549     Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1550     container.SetFocusedControl( control );
1551
1552     Internal::AutofillContainer& containerImpl = GetImpl( container );
1553     Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1554     if( containerGroup != nullptr )
1555     {
1556       containerGroup.RequestAuthentication();
1557     }
1558
1559   }
1560   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1561
1562   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1563 }
1564
1565 void TextField::OnKeyInputFocusLost()
1566 {
1567   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1568   if ( mInputMethodContext )
1569   {
1570     mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1571     // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1572     mInputMethodContext.SetRestoreAfterFocusLost( false );
1573
1574     // Notify that the text editing finish.
1575     mInputMethodContext.Deactivate();
1576
1577     mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1578   }
1579   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1580
1581   if ( notifier )
1582   {
1583     notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1584   }
1585
1586   mController->KeyboardFocusLostEvent();
1587
1588   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1589 }
1590
1591 bool TextField::OnAccessibilityActivated()
1592 {
1593   SetKeyInputFocus();
1594   return true;
1595 }
1596
1597 void TextField::OnTap( const TapGesture& gesture )
1598 {
1599   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1600   if ( mInputMethodContext && IsEditable() )
1601   {
1602     mInputMethodContext.Activate();
1603   }
1604   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1605   Extents padding;
1606   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1607   const Vector2& localPoint = gesture.GetLocalPoint();
1608   mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1609
1610   SetKeyInputFocus();
1611 }
1612
1613 void TextField::OnPan( const PanGesture& gesture )
1614 {
1615   mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1616 }
1617
1618 void TextField::OnLongPress( const LongPressGesture& gesture )
1619 {
1620   if ( mInputMethodContext && IsEditable() )
1621   {
1622     mInputMethodContext.Activate();
1623   }
1624   Extents padding;
1625   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1626   const Vector2& localPoint = gesture.GetLocalPoint();
1627   mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1628
1629   SetKeyInputFocus();
1630 }
1631
1632 bool TextField::OnKeyEvent( const KeyEvent& event )
1633 {
1634   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1635
1636   if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1637   {
1638     // Make sure ClearKeyInputFocus when only key is up
1639     if( event.GetState() == KeyEvent::UP )
1640     {
1641       ClearKeyInputFocus();
1642     }
1643
1644     return true;
1645   }
1646   else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1647   {
1648     // Do nothing when enter is comming.
1649     return false;
1650   }
1651
1652   return mController->KeyEvent( event );
1653 }
1654
1655 void TextField::RequestTextRelayout()
1656 {
1657   RelayoutRequest();
1658 }
1659
1660 bool TextField::IsEditable() const
1661 {
1662   return mController->IsEditable();
1663 }
1664
1665 void TextField::SetEditable( bool editable )
1666 {
1667   mController->SetEditable(editable);
1668   if ( mInputMethodContext && !editable )
1669   {
1670     mInputMethodContext.Deactivate();
1671   }
1672 }
1673
1674 void TextField::TextInserted( unsigned int position, unsigned int length, const std::string &content )
1675 {
1676   if( Accessibility::IsUp() )
1677   {
1678     Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content );
1679   }
1680 }
1681
1682 void TextField::TextDeleted( unsigned int position, unsigned int length, const std::string &content )
1683 {
1684   if( Accessibility::IsUp() )
1685   {
1686     Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content );
1687   }
1688 }
1689
1690 void TextField::CaretMoved( unsigned int position )
1691 {
1692   if( Accessibility::IsUp() )
1693   {
1694     Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position );
1695   }
1696 }
1697
1698 void TextField::TextChanged()
1699 {
1700   Dali::Toolkit::TextField handle( GetOwner() );
1701   mTextChangedSignal.Emit( handle );
1702 }
1703
1704 void TextField::MaxLengthReached()
1705 {
1706   Dali::Toolkit::TextField handle( GetOwner() );
1707   mMaxLengthReachedSignal.Emit( handle );
1708 }
1709
1710 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1711 {
1712   Dali::Toolkit::TextField handle( GetOwner() );
1713
1714   Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1715
1716   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1717   {
1718     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1719   }
1720   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1721   {
1722     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1723   }
1724   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1725   {
1726     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1727   }
1728   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1729   {
1730     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1731   }
1732   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1733   {
1734     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1735   }
1736   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1737   {
1738     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1739   }
1740   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1741   {
1742     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1743   }
1744   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1745   {
1746     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1747   }
1748   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1749   {
1750     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1751   }
1752   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1753   {
1754     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1755   }
1756
1757   mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1758 }
1759
1760 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1761 {
1762   if( actor )
1763   {
1764     if( needsClipping )
1765     {
1766       mClippingDecorationActors.push_back( actor );
1767     }
1768     else
1769     {
1770       actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1771       actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1772       Self().Add( actor );
1773       mActiveLayer = actor;
1774     }
1775   }
1776 }
1777
1778 void TextField::OnSceneConnect( Dali::Actor actor )
1779 {
1780   if ( mHasBeenStaged )
1781   {
1782     RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1783   }
1784   else
1785   {
1786     mHasBeenStaged = true;
1787   }
1788 }
1789
1790 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1791 {
1792   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1793   return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1794 }
1795
1796 void TextField::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1797 {
1798   if( mDecorator )
1799   {
1800     Property::Map map;
1801     map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1802     value = map;
1803   }
1804 }
1805
1806 void TextField::EnableClipping()
1807 {
1808   if( !mStencil )
1809   {
1810     // Creates an extra control to be used as stencil buffer.
1811     mStencil = Control::New();
1812     mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1813     mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1814
1815     // Creates a background visual. Even if the color is transparent it updates the stencil.
1816     mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1817                           Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1818                           Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1819
1820     // Enable the clipping property.
1821     mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1822     mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1823
1824     Self().Add( mStencil );
1825   }
1826 }
1827
1828 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1829 {
1830   mController->PasteClipboardItemEvent();
1831 }
1832
1833 void TextField::KeyboardStatusChanged(bool keyboardShown)
1834 {
1835   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1836
1837   // Just hide the grab handle when keyboard is hidden.
1838   if (!keyboardShown )
1839   {
1840     mController->KeyboardFocusLostEvent();
1841   }
1842   else
1843   {
1844     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1845   }
1846 }
1847
1848 void TextField::OnSceneConnection( int depth )
1849 {
1850   // Sets the depth to the visuals inside the text's decorator.
1851   mDecorator->SetTextDepth( depth );
1852
1853   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1854
1855   // Call the Control::OnSceneConnection() to set the depth of the background.
1856   Control::OnSceneConnection( depth );
1857 }
1858
1859 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1860 {
1861   return false;
1862 }
1863
1864 void TextField::OnIdleSignal()
1865 {
1866   // Emits the change of input style signals.
1867   mController->ProcessInputStyleChangedSignals();
1868
1869   // Set the pointer to null as the callback manager deletes the callback after execute it.
1870   mIdleCallback = NULL;
1871 }
1872
1873 TextField::TextField()
1874 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1875   mIdleCallback( NULL ),
1876   mAlignmentOffset( 0.f ),
1877   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1878   mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1879   mHasBeenStaged( false )
1880 {
1881 }
1882
1883 TextField::~TextField()
1884 {
1885   UnparentAndReset( mStencil );
1886
1887   if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1888   {
1889     Adaptor::Get().RemoveIdle( mIdleCallback );
1890   }
1891 }
1892
1893 std::string TextField::AccessibleImpl::GetName()
1894 {
1895   auto slf = Toolkit::TextField::DownCast( self );
1896   return slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1897 }
1898
1899 std::string TextField::AccessibleImpl::GetText( size_t startOffset,
1900                                                 size_t endOffset )
1901 {
1902   if( endOffset <= startOffset )
1903     return {};
1904
1905   auto slf = Toolkit::TextField::DownCast( self );
1906   auto txt =
1907       slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1908
1909   if( startOffset > txt.size() || endOffset > txt.size() )
1910     return {};
1911
1912   return txt.substr( startOffset, endOffset - startOffset );
1913 }
1914
1915 size_t TextField::AccessibleImpl::GetCharacterCount()
1916 {
1917   auto slf = Toolkit::TextField::DownCast( self );
1918   auto txt =
1919       slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1920
1921   return txt.size();
1922 }
1923
1924 size_t TextField::AccessibleImpl::GetCaretOffset()
1925 {
1926   auto slf = Toolkit::TextField::DownCast( self );
1927   return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition();
1928 }
1929
1930 bool TextField::AccessibleImpl::SetCaretOffset(size_t offset)
1931 {
1932   auto slf = Toolkit::TextField::DownCast( self );
1933   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1934   if (offset > txt.size())
1935     return false;
1936
1937   auto& slfImpl = Dali::Toolkit::GetImpl( slf );
1938   slfImpl.getController()->ResetCursorPosition( offset );
1939   slfImpl.RequestTextRelayout();
1940   return true;
1941 }
1942
1943 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1944     size_t offset, Dali::Accessibility::TextBoundary boundary )
1945 {
1946   auto slf = Toolkit::TextField::DownCast( self );
1947   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1948   auto txt_size = txt.size();
1949
1950   auto range = Dali::Accessibility::Range{};
1951
1952   switch(boundary)
1953   {
1954     case Dali::Accessibility::TextBoundary::CHARACTER:
1955       {
1956         if (offset < txt_size)
1957         {
1958           range.content = txt[offset];
1959           range.startOffset = offset;
1960           range.endOffset = offset + 1;
1961         }
1962       }
1963       break;
1964     case Dali::Accessibility::TextBoundary::WORD:
1965     case Dali::Accessibility::TextBoundary::LINE:
1966       {
1967         auto txt_c_string = txt.c_str();
1968         auto breaks = std::vector< char >( txt_size, 0 );
1969         if(boundary == Dali::Accessibility::TextBoundary::WORD)
1970           Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1971         else
1972           Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1973         auto index = 0u;
1974         auto counter = 0u;
1975         while( index < txt_size && counter <= offset )
1976         {
1977           auto start = index;
1978           if(breaks[index])
1979           {
1980             while(breaks[index])
1981               index++;
1982             counter++;
1983           }
1984           else
1985           {
1986             if (boundary == Dali::Accessibility::TextBoundary::WORD)
1987               index++;
1988             if (boundary == Dali::Accessibility::TextBoundary::LINE)
1989               counter++;
1990           }
1991           if ((counter > 0) && ((counter - 1) == offset))
1992           {
1993             range.content = txt.substr(start, index - start + 1);
1994             range.startOffset = start;
1995             range.endOffset = index + 1;
1996           }
1997           if (boundary == Dali::Accessibility::TextBoundary::LINE)
1998               index++;
1999         }
2000       }
2001       break;
2002     case Dali::Accessibility::TextBoundary::SENTENCE:
2003       {
2004         /* not supported by efl */
2005       }
2006       break;
2007     case Dali::Accessibility::TextBoundary::PARAGRAPH:
2008       {
2009         /* Paragraph is not supported by libunibreak library */
2010       }
2011       break;
2012     default:
2013       break;
2014   }
2015
2016   return range;
2017 }
2018
2019 Dali::Accessibility::Range
2020 TextField::AccessibleImpl::GetSelection( size_t selectionNum )
2021 {
2022   // Since DALi supports only one selection indexes higher than 0 are ignored
2023   if( selectionNum > 0 )
2024     return {};
2025
2026   auto slf = Toolkit::TextField::DownCast( self );
2027   auto ctrl = Dali::Toolkit::GetImpl( slf ).getController();
2028   std::string ret;
2029   ctrl->RetrieveSelection( ret );
2030   auto r = ctrl->GetSelectionIndexes();
2031
2032   return { static_cast<size_t>(r.first), static_cast<size_t>(r.second), ret };
2033 }
2034
2035 bool TextField::AccessibleImpl::RemoveSelection( size_t selectionNum )
2036 {
2037   // Since DALi supports only one selection indexes higher than 0 are ignored
2038   if( selectionNum > 0 )
2039     return false;
2040
2041   auto slf = Toolkit::TextField::DownCast( self );
2042   Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
2043   return true;
2044 }
2045
2046 bool TextField::AccessibleImpl::SetSelection( size_t selectionNum,
2047                                               size_t startOffset,
2048                                               size_t endOffset )
2049 {
2050   // Since DALi supports only one selection indexes higher than 0 are ignored
2051   if( selectionNum > 0 )
2052     return false;
2053
2054   auto slf = Toolkit::TextField::DownCast( self );
2055   Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
2056                                                                endOffset );
2057   return true;
2058 }
2059
2060 bool TextField::AccessibleImpl::CopyText( size_t startPosition,
2061                                            size_t endPosition )
2062 {
2063   if( endPosition <= startPosition )
2064     return false;
2065
2066   auto slf = Toolkit::TextField::DownCast( self );
2067   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2068   Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2069
2070   return true;
2071 }
2072
2073 bool TextField::AccessibleImpl::CutText( size_t startPosition,
2074                                           size_t endPosition )
2075 {
2076   if( endPosition <= startPosition )
2077     return false;
2078
2079   auto slf = Toolkit::TextField::DownCast( self );
2080   auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2081   Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2082
2083   slf.SetProperty( Toolkit::TextField::Property::TEXT,
2084                    txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size()));
2085
2086   return true;
2087 }
2088
2089 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
2090 {
2091   using namespace Dali::Accessibility;
2092
2093   auto states = Control::Impl::AccessibleImpl::CalculateStates();
2094
2095   states[State::EDITABLE] = true;
2096   states[State::FOCUSABLE] = true;
2097
2098   Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
2099   if (self == focusControl)
2100   {
2101     states[State::FOCUSED] = true;
2102   }
2103
2104   return states;
2105 }
2106
2107 } // namespace Internal
2108
2109 } // namespace Toolkit
2110
2111 } // namespace Dali