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