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