9c3d4c8ac54aec83ae3d896c71bcc74fc6dc4f24
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
27 #include <dali/devel-api/object/type-registry-helper.h>
28 #include <dali/integration-api/debug.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/public-api/text/rendering-backend.h>
32 #include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/styling/style-manager-impl.h>
36
37 using namespace Dali::Toolkit::Text;
38
39 namespace Dali
40 {
41
42 namespace Toolkit
43 {
44
45 namespace Internal
46 {
47
48 namespace // unnamed namespace
49 {
50
51 #if defined(DEBUG_ENABLED)
52   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
53 #endif
54
55   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
56 } // unnamed namespace
57
58 namespace
59 {
60
61 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
62 {
63   { "BEGIN",  Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN  },
64   { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
65   { "END",    Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END    },
66 };
67 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
68
69 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
70 {
71   { "TOP",    Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP    },
72   { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
73   { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
74 };
75 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
76
77 // Type registration
78 BaseHandle Create()
79 {
80   return Toolkit::TextField::New();
81 }
82
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
85
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend",                    INTEGER,   RENDERING_BACKEND                    )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text",                                 STRING,    TEXT                                 )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text",                     STRING,    PLACEHOLDER_TEXT                     )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused",             STRING,    PLACEHOLDER_TEXT_FOCUSED             )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family",                          STRING,    FONT_FAMILY                          )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style",                           STRING,    FONT_STYLE                           )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size",                           FLOAT,     POINT_SIZE                           )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length",                           INTEGER,   MAX_LENGTH                           )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy",                        INTEGER,   EXCEED_POLICY                        )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment",                 STRING,    HORIZONTAL_ALIGNMENT                 )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment",                   STRING,    VERTICAL_ALIGNMENT                   )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color",                           VECTOR4,   TEXT_COLOR                           )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color",               VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset",                        VECTOR2,   SHADOW_OFFSET                        )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color",                         VECTOR4,   SHADOW_COLOR                         )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color",                 VECTOR4,   PRIMARY_CURSOR_COLOR                 )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color",               VECTOR4,   SECONDARY_CURSOR_COLOR               )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink",                  BOOLEAN,   ENABLE_CURSOR_BLINK                  )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval",                FLOAT,     CURSOR_BLINK_INTERVAL                )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration",                FLOAT,     CURSOR_BLINK_DURATION                )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-width",                         INTEGER,   CURSOR_WIDTH                         )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image",                    STRING,    GRAB_HANDLE_IMAGE                    )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image",            STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold",                     FLOAT,     SCROLL_THRESHOLD                     )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed",                         FLOAT,     SCROLL_SPEED                         )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left",          MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right",         MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left",  MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-left",   MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-right",  MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color",            VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box",              RECTANGLE, DECORATION_BOUNDING_BOX              )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings",                MAP,       INPUT_METHOD_SETTINGS                )
120
121 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed",       SIGNAL_TEXT_CHANGED )
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
123
124 DALI_TYPE_REGISTRATION_END()
125
126 } // namespace
127
128 Toolkit::TextField TextField::New()
129 {
130   // Create the implementation, temporarily owned by this handle on stack
131   IntrusivePtr< TextField > impl = new TextField();
132
133   // Pass ownership to CustomActor handle
134   Toolkit::TextField handle( *impl );
135
136   // Second-phase init of the implementation
137   // This can only be done after the CustomActor connection has been made...
138   impl->Initialize();
139
140   return handle;
141 }
142
143 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
144 {
145   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
146
147   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
148
149
150   if( textField )
151   {
152     TextField& impl( GetImpl( textField ) );
153
154     switch( index )
155     {
156       case Toolkit::TextField::Property::RENDERING_BACKEND:
157       {
158         int backend = value.Get< int >();
159         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
160
161         if( impl.mRenderingBackend != backend )
162         {
163           impl.mRenderingBackend = backend;
164           impl.mRenderer.Reset();
165           impl.RequestTextRelayout();
166         }
167         break;
168       }
169       case Toolkit::TextField::Property::TEXT:
170       {
171         if( impl.mController )
172         {
173           const std::string text = value.Get< std::string >();
174           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
175
176           impl.mController->SetText( text );
177         }
178         break;
179       }
180       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
181       {
182         if( impl.mController )
183         {
184           const std::string text = value.Get< std::string >();
185           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
186
187           impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
188         }
189         break;
190       }
191       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
192       {
193         if( impl.mController )
194         {
195           const std::string text = value.Get< std::string >();
196           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
197
198           impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
199         }
200         break;
201       }
202       case Toolkit::TextField::Property::FONT_FAMILY:
203       {
204         if( impl.mController )
205         {
206           const std::string fontFamily = value.Get< std::string >();
207           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
208
209           if( impl.mController->GetDefaultFontFamily() != fontFamily )
210           {
211             impl.mController->SetDefaultFontFamily( fontFamily, true ); // "true" as SetProperty means user defined font so don't change when system font changes.
212           }
213         }
214         break;
215       }
216       case Toolkit::TextField::Property::FONT_STYLE:
217       {
218         SetFontStyleProperty( impl.mController, value );
219         break;
220       }
221       case Toolkit::TextField::Property::POINT_SIZE:
222       {
223         if( impl.mController )
224         {
225           const float pointSize = value.Get< float >();
226           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
227
228           if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
229           {
230             impl.mController->SetDefaultPointSize( pointSize );
231           }
232         }
233         break;
234       }
235       case Toolkit::TextField::Property::MAX_LENGTH:
236       {
237         if( impl.mController )
238         {
239           const int max = value.Get< int >();
240           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
241
242           impl.mController->SetMaximumNumberOfCharacters( max );
243         }
244         break;
245       }
246       case Toolkit::TextField::Property::EXCEED_POLICY:
247       {
248         // TODO
249         break;
250       }
251       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
252       {
253         if( impl.mController )
254         {
255           const std::string alignStr = value.Get< std::string >();
256           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
257
258           LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
259           if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
260                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE,
261                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
262                                                                               alignment ) )
263           {
264             impl.mController->SetHorizontalAlignment( alignment );
265           }
266         }
267         break;
268       }
269       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
270       {
271         if( impl.mController )
272         {
273           const std::string alignStr = value.Get< std::string >();
274           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
275
276           LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
277           if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
278                                                                             VERTICAL_ALIGNMENT_STRING_TABLE,
279                                                                             VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
280                                                                             alignment ) )
281           {
282             impl.mController->SetVerticalAlignment( alignment );
283           }
284         }
285         break;
286       }
287       case Toolkit::TextField::Property::TEXT_COLOR:
288       {
289         if( impl.mController )
290         {
291           const Vector4 textColor = value.Get< Vector4 >();
292           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 );
293
294           if( impl.mController->GetTextColor() != textColor )
295           {
296             impl.mController->SetTextColor( textColor );
297             impl.mRenderer.Reset();
298           }
299         }
300         break;
301       }
302       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
303       {
304         if( impl.mController )
305         {
306           const Vector4 textColor = value.Get< Vector4 >();
307           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 );
308
309           if( impl.mController->GetPlaceholderTextColor() != textColor )
310           {
311             impl.mController->SetPlaceholderTextColor( textColor );
312             impl.mRenderer.Reset();
313           }
314         }
315         break;
316       }
317       case Toolkit::TextField::Property::SHADOW_OFFSET:
318       {
319         if( impl.mController )
320         {
321           const Vector2 shadowOffset = value.Get< Vector2 >();
322           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
323
324           if ( impl.mController->GetShadowOffset() != shadowOffset )
325           {
326             impl.mController->SetShadowOffset( shadowOffset );
327             impl.mRenderer.Reset();
328           }
329         }
330         break;
331       }
332       case Toolkit::TextField::Property::SHADOW_COLOR:
333       {
334         if( impl.mController )
335         {
336           const Vector4 shadowColor = value.Get< Vector4 >();
337           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a );
338
339           if ( impl.mController->GetShadowColor() != shadowColor )
340           {
341             impl.mController->SetShadowColor( shadowColor );
342             impl.mRenderer.Reset();
343           }
344         }
345         break;
346       }
347       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
348       {
349         if( impl.mDecorator )
350         {
351           const Vector4 color = value.Get< Vector4 >();
352           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 );
353
354           impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
355           impl.RequestTextRelayout();
356         }
357         break;
358       }
359       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
360       {
361         if( impl.mDecorator )
362         {
363           const Vector4 color = value.Get< Vector4 >();
364           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 );
365
366           impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
367           impl.RequestTextRelayout();
368         }
369         break;
370       }
371       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
372       {
373         if( impl.mController )
374         {
375           const bool enable = value.Get< bool >();
376           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
377
378           impl.mController->SetEnableCursorBlink( enable );
379           impl.RequestTextRelayout();
380         }
381         break;
382       }
383       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
384       {
385         if( impl.mDecorator )
386         {
387           const float interval = value.Get< float >();
388           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
389
390           impl.mDecorator->SetCursorBlinkInterval( interval );
391         }
392         break;
393       }
394       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
395       {
396         if( impl.mDecorator )
397         {
398           const float duration = value.Get< float >();
399           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
400
401           impl.mDecorator->SetCursorBlinkDuration( duration );
402         }
403         break;
404       }
405       case Toolkit::TextField::Property::CURSOR_WIDTH:
406       {
407         if( impl.mDecorator )
408         {
409           const int width = value.Get< int >();
410           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
411
412           impl.mDecorator->SetCursorWidth( width );
413           impl.mController->GetLayoutEngine().SetCursorWidth( width );
414         }
415         break;
416       }
417       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
418       {
419         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
420         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
421
422         if( impl.mDecorator )
423         {
424           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
425           impl.RequestTextRelayout();
426         }
427         break;
428       }
429       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
430       {
431         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
432         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
433
434         if( impl.mDecorator )
435         {
436           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
437           impl.RequestTextRelayout();
438         }
439         break;
440       }
441       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
442       {
443         const float threshold = value.Get< float >();
444         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
445
446         if( impl.mDecorator )
447         {
448           impl.mDecorator->SetScrollThreshold( threshold );
449         }
450         break;
451       }
452       case Toolkit::TextField::Property::SCROLL_SPEED:
453       {
454         const float speed = value.Get< float >();
455         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
456
457         if( impl.mDecorator )
458         {
459           impl.mDecorator->SetScrollSpeed( speed );
460         }
461         break;
462       }
463       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
464       {
465         const Image image = Scripting::NewImage( value );
466
467         if( impl.mDecorator && image )
468         {
469           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
470           impl.RequestTextRelayout();
471         }
472         break;
473       }
474       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
475       {
476         const Image image = Scripting::NewImage( value );
477
478         if( impl.mDecorator && image )
479         {
480           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481           impl.RequestTextRelayout();
482         }
483         break;
484       }
485       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
486       {
487         const Image image = Scripting::NewImage( value );
488
489         if( impl.mDecorator && image )
490         {
491           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
492           impl.RequestTextRelayout();
493         }
494         break;
495       }
496       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
497       {
498         const Image image = Scripting::NewImage( value );
499
500         if( impl.mDecorator && image )
501         {
502           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503           impl.RequestTextRelayout();
504         }
505         break;
506       }
507       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
508       {
509         const Image image = Scripting::NewImage( value );
510
511         if( impl.mDecorator && image )
512         {
513           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
514           impl.RequestTextRelayout();
515         }
516         break;
517       }
518       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
519       {
520         const Image image = Scripting::NewImage( value );
521
522         if( impl.mDecorator && image )
523         {
524           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
525           impl.RequestTextRelayout();
526         }
527         break;
528       }
529       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
530       {
531         const Vector4 color = value.Get< Vector4 >();
532         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 );
533
534         if( impl.mDecorator )
535         {
536           impl.mDecorator->SetHighlightColor( color );
537           impl.RequestTextRelayout();
538         }
539         break;
540       }
541       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
542       {
543         if( impl.mDecorator )
544         {
545           const Rect<int> box = value.Get< Rect<int> >();
546           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 );
547
548           impl.mDecorator->SetBoundingBox( box );
549           impl.RequestTextRelayout();
550         }
551         break;
552       }
553       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
554       {
555         const Property::Map map = value.Get<Property::Map>();
556         VirtualKeyboard::ApplySettings( map );
557         break;
558       }
559     } // switch
560   } // textfield
561 }
562
563 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
564 {
565   Property::Value value;
566
567   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
568
569   if( textField )
570   {
571     TextField& impl( GetImpl( textField ) );
572
573     switch( index )
574     {
575       case Toolkit::TextField::Property::RENDERING_BACKEND:
576       {
577         value = impl.mRenderingBackend;
578         break;
579       }
580       case Toolkit::TextField::Property::TEXT:
581       {
582         if( impl.mController )
583         {
584           std::string text;
585           impl.mController->GetText( text );
586           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
587           value = text;
588         }
589         break;
590       }
591       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
592       {
593         if( impl.mController )
594         {
595           std::string text;
596           impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
597           value = text;
598         }
599         break;
600       }
601       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
602       {
603         if( impl.mController )
604         {
605           std::string text;
606           impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
607           value = text;
608         }
609         break;
610       }
611       case Toolkit::TextField::Property::FONT_FAMILY:
612       {
613         if( impl.mController )
614         {
615           value = impl.mController->GetDefaultFontFamily();
616         }
617         break;
618       }
619       case Toolkit::TextField::Property::FONT_STYLE:
620       {
621         GetFontStyleProperty( impl.mController, value );
622         break;
623       }
624       case Toolkit::TextField::Property::POINT_SIZE:
625       {
626         if( impl.mController )
627         {
628           value = impl.mController->GetDefaultPointSize();
629         }
630         break;
631       }
632       case Toolkit::TextField::Property::MAX_LENGTH:
633       {
634         if( impl.mController )
635         {
636           value = impl.mController->GetMaximumNumberOfCharacters();
637         }
638         break;
639       }
640       case Toolkit::TextField::Property::EXCEED_POLICY:
641       {
642         value = impl.mExceedPolicy;
643         break;
644       }
645       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
646       {
647         if( impl.mController )
648         {
649           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
650                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE,
651                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
652           if( name )
653           {
654             value = std::string( name );
655           }
656         }
657         break;
658       }
659       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
660       {
661         if( impl.mController )
662         {
663           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
664                                                                                                               VERTICAL_ALIGNMENT_STRING_TABLE,
665                                                                                                               VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
666           if( name )
667           {
668             value = std::string( name );
669           }
670         }
671         break;
672       }
673       case Toolkit::TextField::Property::TEXT_COLOR:
674       {
675         if ( impl.mController )
676         {
677           value = impl.mController->GetTextColor();
678         }
679         break;
680       }
681       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
682       {
683         if ( impl.mController )
684         {
685           value = impl.mController->GetPlaceholderTextColor();
686         }
687         break;
688       }
689       case Toolkit::TextField::Property::SHADOW_OFFSET:
690       {
691         if ( impl.mController )
692         {
693           value = impl.mController->GetShadowOffset();
694         }
695         break;
696       }
697       case Toolkit::TextField::Property::SHADOW_COLOR:
698       {
699         if ( impl.mController )
700         {
701           value = impl.mController->GetShadowColor();
702         }
703         break;
704       }
705       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
706       {
707         if( impl.mDecorator )
708         {
709           value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
710         }
711         break;
712       }
713       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
714       {
715         if( impl.mDecorator )
716         {
717           value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
718         }
719         break;
720       }
721       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
722       {
723         value = impl.mController->GetEnableCursorBlink();
724         break;
725       }
726       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
727       {
728         if( impl.mDecorator )
729         {
730           value = impl.mDecorator->GetCursorBlinkInterval();
731         }
732         break;
733       }
734       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
735       {
736         if( impl.mDecorator )
737         {
738           value = impl.mDecorator->GetCursorBlinkDuration();
739         }
740         break;
741       }
742       case Toolkit::TextField::Property::CURSOR_WIDTH:
743       {
744         if( impl.mDecorator )
745         {
746           value = impl.mDecorator->GetCursorWidth();
747         }
748         break;
749       }
750       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
751       {
752         if( impl.mDecorator )
753         {
754           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
755           if( image )
756           {
757             value = image.GetUrl();
758           }
759         }
760         break;
761       }
762       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
763       {
764         if( impl.mDecorator )
765         {
766           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
767           if( image )
768           {
769             value = image.GetUrl();
770           }
771         }
772         break;
773       }
774       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
775       {
776         if( impl.mDecorator )
777         {
778           value = impl.mDecorator->GetScrollThreshold();
779         }
780         break;
781       }
782       case Toolkit::TextField::Property::SCROLL_SPEED:
783       {
784         if( impl.mDecorator )
785         {
786           value = impl.mDecorator->GetScrollSpeed();
787         }
788         break;
789       }
790       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
791       {
792         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
793         break;
794       }
795       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
796       {
797         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
798         break;
799       }
800       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
801       {
802         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
803         break;
804       }
805       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
806       {
807         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
808         break;
809       }
810       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
811       {
812         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
813         break;
814       }
815       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
816       {
817         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
818         break;
819       }
820       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
821       {
822         if( impl.mDecorator )
823         {
824           value = impl.mDecorator->GetHighlightColor();
825         }
826         break;
827       }
828       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
829       {
830         if( impl.mDecorator )
831         {
832           Rect<int> boundingBox;
833           impl.mDecorator->GetBoundingBox( boundingBox );
834           value = boundingBox;
835         }
836         break;
837       }
838       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
839       {
840         break;
841       }
842     } //switch
843   }
844
845   return value;
846 }
847
848 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
849 {
850   Dali::BaseHandle handle( object );
851
852   bool connected( true );
853   Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
854
855   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
856   {
857     field.TextChangedSignal().Connect( tracker, functor );
858   }
859   else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
860   {
861     field.MaxLengthReachedSignal().Connect( tracker, functor );
862   }
863   else
864   {
865     // signalName does not match any signal
866     connected = false;
867   }
868
869   return connected;
870 }
871
872 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
873 {
874   return mTextChangedSignal;
875 }
876
877 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
878 {
879   return mMaxLengthReachedSignal;
880 }
881
882 void TextField::OnInitialize()
883 {
884   Actor self = Self();
885
886   mController = Text::Controller::New( *this );
887
888   mDecorator = Text::Decorator::New( *mController,
889                                      *mController );
890
891   mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
892
893   mController->EnableTextInput( mDecorator );
894
895   // Forward input events to controller
896   EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
897   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
898
899   self.TouchedSignal().Connect( this, &TextField::OnTouched );
900
901   // Set BoundingBox to stage size if not already set.
902   Rect<int> boundingBox;
903   mDecorator->GetBoundingBox( boundingBox );
904
905   if( boundingBox.IsEmpty() )
906   {
907     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
908     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
909   }
910
911   // Fill-parent area by default
912   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
913   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
914   self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
915 }
916
917 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
918 {
919   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
920
921    switch ( change )
922    {
923      case StyleChange::DEFAULT_FONT_CHANGE:
924      {
925        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
926        std::string newFont = styleManager.GetDefaultFontFamily();
927        // Property system did not set the font so should update it.
928        mController->UpdateAfterFontChange( newFont );
929        break;
930      }
931
932      case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
933      {
934        DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
935
936        if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
937        {
938          // Property system did not set the PointSize so should update it.
939          // todo instruct text-controller to update model
940        }
941        break;
942      }
943      case StyleChange::THEME_CHANGE:
944      {
945        GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
946        break;
947      }
948    }
949 }
950
951 Vector3 TextField::GetNaturalSize()
952 {
953   return mController->GetNaturalSize();
954 }
955
956 float TextField::GetHeightForWidth( float width )
957 {
958   return mController->GetHeightForWidth( width );
959 }
960
961 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
962 {
963   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
964
965   if( mController->Relayout( size ) ||
966       !mRenderer )
967   {
968     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
969
970     if( mDecorator )
971     {
972       mDecorator->Relayout( size );
973     }
974
975     if( !mRenderer )
976     {
977       mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
978     }
979
980     EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
981     RenderText();
982   }
983 }
984
985 void TextField::RenderText()
986 {
987   Actor self = Self();
988   Actor renderableActor;
989   if( mRenderer )
990   {
991     renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
992   }
993
994   if( renderableActor != mRenderableActor )
995   {
996     UnparentAndReset( mRenderableActor );
997     mRenderableActor = renderableActor;
998   }
999
1000   if( mRenderableActor )
1001   {
1002     const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1003
1004     mRenderableActor.SetPosition( offset.x, offset.y );
1005
1006     Actor clipRootActor;
1007     if( mClipper )
1008     {
1009       clipRootActor = mClipper->GetRootActor();
1010     }
1011
1012     for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1013            endIt = mClippingDecorationActors.end();
1014          it != endIt;
1015          ++it )
1016     {
1017       Actor actor = *it;
1018
1019       if( clipRootActor )
1020       {
1021         clipRootActor.Add( actor );
1022       }
1023       else
1024       {
1025         self.Add( actor );
1026       }
1027     }
1028     mClippingDecorationActors.clear();
1029
1030     // Make sure the actor is parented correctly with/without clipping
1031     if( clipRootActor )
1032     {
1033       clipRootActor.Add( mRenderableActor );
1034     }
1035     else
1036     {
1037       self.Add( mRenderableActor );
1038     }
1039   }
1040 }
1041
1042 void TextField::OnKeyInputFocusGained()
1043 {
1044   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1045
1046   VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1047
1048   ImfManager imfManager = ImfManager::Get();
1049
1050   if ( imfManager )
1051   {
1052     imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1053
1054     // Notify that the text editing start.
1055     imfManager.Activate();
1056
1057     // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1058     imfManager.SetRestoreAfterFocusLost( true );
1059   }
1060
1061    ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1062
1063    if ( notifier )
1064    {
1065       notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1066    }
1067
1068   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1069
1070   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1071 }
1072
1073 void TextField::OnKeyInputFocusLost()
1074 {
1075   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1076
1077   VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1078
1079   ImfManager imfManager = ImfManager::Get();
1080   if ( imfManager )
1081   {
1082     // The text editing is finished. Therefore the imf manager don't have restore activation.
1083     imfManager.SetRestoreAfterFocusLost( false );
1084
1085     // Notify that the text editing finish.
1086     imfManager.Deactivate();
1087
1088     imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1089   }
1090
1091   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1092
1093   if ( notifier )
1094   {
1095     notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1096   }
1097
1098   mController->KeyboardFocusLostEvent();
1099
1100   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1101 }
1102
1103 void TextField::OnTap( const TapGesture& gesture )
1104 {
1105   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1106
1107   // Show the keyboard if it was hidden.
1108   if (!VirtualKeyboard::IsVisible())
1109   {
1110     VirtualKeyboard::Show();
1111   }
1112
1113   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1114   mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1115
1116   SetKeyInputFocus();
1117 }
1118
1119 void TextField::OnPan( const PanGesture& gesture )
1120 {
1121   mController->PanEvent( gesture.state, gesture.displacement );
1122 }
1123
1124 void TextField::OnLongPress( const LongPressGesture& gesture )
1125 {
1126   // Show the keyboard if it was hidden.
1127   if (!VirtualKeyboard::IsVisible())
1128   {
1129     VirtualKeyboard::Show();
1130   }
1131
1132   mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1133
1134   SetKeyInputFocus();
1135 }
1136
1137 bool TextField::OnKeyEvent( const KeyEvent& event )
1138 {
1139   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1140
1141   if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1142       "Return" == event.keyPressedName ) // Make a Dali key code for this
1143   {
1144     ClearKeyInputFocus();
1145     return true;
1146   }
1147
1148   return mController->KeyEvent( event );
1149 }
1150
1151 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1152 {
1153   if( actor )
1154   {
1155     if( needsClipping )
1156     {
1157       mClippingDecorationActors.push_back( actor );
1158     }
1159     else
1160     {
1161       Self().Add( actor );
1162     }
1163   }
1164 }
1165
1166 void TextField::RequestTextRelayout()
1167 {
1168   RelayoutRequest();
1169 }
1170
1171 void TextField::TextChanged()
1172 {
1173   Dali::Toolkit::TextField handle( GetOwner() );
1174   mTextChangedSignal.Emit( handle );
1175 }
1176
1177 void TextField::OnStageConnect( Dali::Actor actor )
1178 {
1179   if ( mHasBeenStaged )
1180   {
1181     RenderText();
1182   }
1183   else
1184   {
1185     mHasBeenStaged = true;
1186   }
1187 }
1188
1189 void TextField::MaxLengthReached()
1190 {
1191   Dali::Toolkit::TextField handle( GetOwner() );
1192   mMaxLengthReachedSignal.Emit( handle );
1193 }
1194
1195 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1196 {
1197   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1198   return mController->OnImfEvent( imfManager, imfEvent );
1199 }
1200
1201 void TextField::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1202 {
1203   if( mDecorator )
1204   {
1205     ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1206
1207     if ( image )
1208     {
1209       Property::Map map;
1210       Scripting::CreatePropertyMap( image, map );
1211       value = map;
1212     }
1213   }
1214 }
1215
1216 void TextField::EnableClipping( bool clipping, const Vector2& size )
1217 {
1218   if( clipping )
1219   {
1220     // Not worth to created clip actor if width or height is equal to zero.
1221     if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1222     {
1223       if( !mClipper )
1224       {
1225         Actor self = Self();
1226
1227         mClipper = Clipper::New( size );
1228         self.Add( mClipper->GetRootActor() );
1229         self.Add( mClipper->GetImageActor() );
1230       }
1231       else if ( mClipper )
1232       {
1233         mClipper->Refresh( size );
1234       }
1235     }
1236   }
1237   else
1238   {
1239     // Note - this will automatically remove the root & image actors
1240     mClipper.Reset();
1241   }
1242 }
1243
1244 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1245 {
1246   mController->PasteClipboardItemEvent();
1247 }
1248
1249 void TextField::KeyboardStatusChanged(bool keyboardShown)
1250 {
1251   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1252
1253   // Just hide the grab handle when keyboard is hidden.
1254   if (!keyboardShown )
1255   {
1256     mController->KeyboardFocusLostEvent();
1257   }
1258   else
1259   {
1260     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1261   }
1262 }
1263
1264 void TextField::OnStageConnection( int depth )
1265 {
1266   // Call the Control::OnStageConnection() to set the depth of the background.
1267   Control::OnStageConnection( depth );
1268
1269   // Sets the depth to the renderers inside the text's decorator.
1270   mDecorator->SetTextDepth( depth );
1271
1272   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1273 }
1274
1275 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1276 {
1277   return true;
1278 }
1279
1280 TextField::TextField()
1281 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1282   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1283   mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1284   mHasBeenStaged( false )
1285 {
1286 }
1287
1288 TextField::~TextField()
1289 {
1290   mClipper.Reset();
1291 }
1292
1293 } // namespace Internal
1294
1295 } // namespace Toolkit
1296
1297 } // namespace Dali