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