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