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