Merge "Changed ShadowView to use new custom effects and ImageView." into devel/master
[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/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
37
38 using namespace Dali::Toolkit::Text;
39
40 namespace Dali
41 {
42
43 namespace Toolkit
44 {
45
46 namespace Internal
47 {
48
49 namespace // unnamed namespace
50 {
51
52 #if defined(DEBUG_ENABLED)
53   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
54 #endif
55
56   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 } // unnamed namespace
58
59 namespace
60 {
61
62 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
63 {
64   { "BEGIN",  Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN  },
65   { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
66   { "END",    Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END    },
67 };
68 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
69
70 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
71 {
72   { "TOP",    Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP    },
73   { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
74   { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
75 };
76 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
77
78 // Type registration
79 BaseHandle Create()
80 {
81   return Toolkit::TextField::New();
82 }
83
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
86
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend",                    INTEGER,   RENDERING_BACKEND                    )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text",                                 STRING,    TEXT                                 )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text",                     STRING,    PLACEHOLDER_TEXT                     )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused",             STRING,    PLACEHOLDER_TEXT_FOCUSED             )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family",                          STRING,    FONT_FAMILY                          )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style",                           STRING,    FONT_STYLE                           )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size",                           FLOAT,     POINT_SIZE                           )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length",                           INTEGER,   MAX_LENGTH                           )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy",                        INTEGER,   EXCEED_POLICY                        )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment",                 STRING,    HORIZONTAL_ALIGNMENT                 )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment",                   STRING,    VERTICAL_ALIGNMENT                   )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color",                           VECTOR4,   TEXT_COLOR                           )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color",               VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset",                        VECTOR2,   SHADOW_OFFSET                        )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color",                         VECTOR4,   SHADOW_COLOR                         )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color",                 VECTOR4,   PRIMARY_CURSOR_COLOR                 )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color",               VECTOR4,   SECONDARY_CURSOR_COLOR               )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink",                  BOOLEAN,   ENABLE_CURSOR_BLINK                  )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval",                FLOAT,     CURSOR_BLINK_INTERVAL                )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration",                FLOAT,     CURSOR_BLINK_DURATION                )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-width",                         INTEGER,   CURSOR_WIDTH                         )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image",                    STRING,    GRAB_HANDLE_IMAGE                    )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image",            STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold",                     FLOAT,     SCROLL_THRESHOLD                     )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed",                         FLOAT,     SCROLL_SPEED                         )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left",          MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right",         MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left",  MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-left",   MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-right",  MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color",            VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box",              RECTANGLE, DECORATION_BOUNDING_BOX              )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings",                MAP,       INPUT_METHOD_SETTINGS                )
121
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed",       SIGNAL_TEXT_CHANGED )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
124
125 DALI_TYPE_REGISTRATION_END()
126
127 } // namespace
128
129 Toolkit::TextField TextField::New()
130 {
131   // Create the implementation, temporarily owned by this handle on stack
132   IntrusivePtr< TextField > impl = new TextField();
133
134   // Pass ownership to CustomActor handle
135   Toolkit::TextField handle( *impl );
136
137   // Second-phase init of the implementation
138   // This can only be done after the CustomActor connection has been made...
139   impl->Initialize();
140
141   return handle;
142 }
143
144 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
145 {
146   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
147
148   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
149
150
151   if( textField )
152   {
153     TextField& impl( GetImpl( textField ) );
154
155     switch( index )
156     {
157       case Toolkit::TextField::Property::RENDERING_BACKEND:
158       {
159         int backend = value.Get< int >();
160         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
161
162         if( impl.mRenderingBackend != backend )
163         {
164           impl.mRenderingBackend = backend;
165           impl.mRenderer.Reset();
166           impl.RequestTextRelayout();
167         }
168         break;
169       }
170       case Toolkit::TextField::Property::TEXT:
171       {
172         if( impl.mController )
173         {
174           const std::string text = value.Get< std::string >();
175           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
176
177           impl.mController->SetText( text );
178         }
179         break;
180       }
181       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
182       {
183         if( impl.mController )
184         {
185           const std::string text = value.Get< std::string >();
186           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
187
188           impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
189         }
190         break;
191       }
192       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
193       {
194         if( impl.mController )
195         {
196           const std::string text = value.Get< std::string >();
197           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
198
199           impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
200         }
201         break;
202       }
203       case Toolkit::TextField::Property::FONT_FAMILY:
204       {
205         if( impl.mController )
206         {
207           const std::string fontFamily = value.Get< std::string >();
208           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
209           impl.mController->SetDefaultFontFamily( fontFamily );
210         }
211         break;
212       }
213       case Toolkit::TextField::Property::FONT_STYLE:
214       {
215         SetFontStyleProperty( impl.mController, value );
216         break;
217       }
218       case Toolkit::TextField::Property::POINT_SIZE:
219       {
220         if( impl.mController )
221         {
222           const float pointSize = value.Get< float >();
223           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
224
225           if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
226           {
227             impl.mController->SetDefaultPointSize( pointSize );
228           }
229         }
230         break;
231       }
232       case Toolkit::TextField::Property::MAX_LENGTH:
233       {
234         if( impl.mController )
235         {
236           const int max = value.Get< int >();
237           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
238
239           impl.mController->SetMaximumNumberOfCharacters( max );
240         }
241         break;
242       }
243       case Toolkit::TextField::Property::EXCEED_POLICY:
244       {
245         // TODO
246         break;
247       }
248       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
249       {
250         if( impl.mController )
251         {
252           const std::string alignStr = value.Get< std::string >();
253           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
254
255           LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
256           if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
257                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE,
258                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
259                                                                               alignment ) )
260           {
261             impl.mController->SetHorizontalAlignment( alignment );
262           }
263         }
264         break;
265       }
266       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
267       {
268         if( impl.mController )
269         {
270           const std::string alignStr = value.Get< std::string >();
271           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
272
273           LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
274           if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
275                                                                             VERTICAL_ALIGNMENT_STRING_TABLE,
276                                                                             VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
277                                                                             alignment ) )
278           {
279             impl.mController->SetVerticalAlignment( alignment );
280           }
281         }
282         break;
283       }
284       case Toolkit::TextField::Property::TEXT_COLOR:
285       {
286         if( impl.mController )
287         {
288           const Vector4 textColor = value.Get< Vector4 >();
289           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 );
290
291           if( impl.mController->GetTextColor() != textColor )
292           {
293             impl.mController->SetTextColor( textColor );
294             impl.mRenderer.Reset();
295           }
296         }
297         break;
298       }
299       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
300       {
301         if( impl.mController )
302         {
303           const Vector4 textColor = value.Get< Vector4 >();
304           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 );
305
306           if( impl.mController->GetPlaceholderTextColor() != textColor )
307           {
308             impl.mController->SetPlaceholderTextColor( textColor );
309             impl.mRenderer.Reset();
310           }
311         }
312         break;
313       }
314       case Toolkit::TextField::Property::SHADOW_OFFSET:
315       {
316         if( impl.mController )
317         {
318           const Vector2 shadowOffset = value.Get< Vector2 >();
319           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
320
321           if ( impl.mController->GetShadowOffset() != shadowOffset )
322           {
323             impl.mController->SetShadowOffset( shadowOffset );
324             impl.mRenderer.Reset();
325           }
326         }
327         break;
328       }
329       case Toolkit::TextField::Property::SHADOW_COLOR:
330       {
331         if( impl.mController )
332         {
333           const Vector4 shadowColor = value.Get< Vector4 >();
334           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 );
335
336           if ( impl.mController->GetShadowColor() != shadowColor )
337           {
338             impl.mController->SetShadowColor( shadowColor );
339             impl.mRenderer.Reset();
340           }
341         }
342         break;
343       }
344       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
345       {
346         if( impl.mDecorator )
347         {
348           const Vector4 color = value.Get< Vector4 >();
349           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 );
350
351           impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
352           impl.RequestTextRelayout();
353         }
354         break;
355       }
356       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
357       {
358         if( impl.mDecorator )
359         {
360           const Vector4 color = value.Get< Vector4 >();
361           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 );
362
363           impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
364           impl.RequestTextRelayout();
365         }
366         break;
367       }
368       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
369       {
370         if( impl.mController )
371         {
372           const bool enable = value.Get< bool >();
373           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
374
375           impl.mController->SetEnableCursorBlink( enable );
376           impl.RequestTextRelayout();
377         }
378         break;
379       }
380       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
381       {
382         if( impl.mDecorator )
383         {
384           const float interval = value.Get< float >();
385           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
386
387           impl.mDecorator->SetCursorBlinkInterval( interval );
388         }
389         break;
390       }
391       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
392       {
393         if( impl.mDecorator )
394         {
395           const float duration = value.Get< float >();
396           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
397
398           impl.mDecorator->SetCursorBlinkDuration( duration );
399         }
400         break;
401       }
402       case Toolkit::TextField::Property::CURSOR_WIDTH:
403       {
404         if( impl.mDecorator )
405         {
406           const int width = value.Get< int >();
407           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
408
409           impl.mDecorator->SetCursorWidth( width );
410           impl.mController->GetLayoutEngine().SetCursorWidth( width );
411         }
412         break;
413       }
414       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
415       {
416         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
417         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
418
419         if( impl.mDecorator )
420         {
421           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
422           impl.RequestTextRelayout();
423         }
424         break;
425       }
426       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
427       {
428         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
429         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
430
431         if( impl.mDecorator )
432         {
433           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
434           impl.RequestTextRelayout();
435         }
436         break;
437       }
438       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
439       {
440         const float threshold = value.Get< float >();
441         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
442
443         if( impl.mDecorator )
444         {
445           impl.mDecorator->SetScrollThreshold( threshold );
446         }
447         break;
448       }
449       case Toolkit::TextField::Property::SCROLL_SPEED:
450       {
451         const float speed = value.Get< float >();
452         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
453
454         if( impl.mDecorator )
455         {
456           impl.mDecorator->SetScrollSpeed( speed );
457         }
458         break;
459       }
460       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
461       {
462         const Image image = Scripting::NewImage( value );
463
464         if( impl.mDecorator && image )
465         {
466           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
467           impl.RequestTextRelayout();
468         }
469         break;
470       }
471       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
472       {
473         const Image image = Scripting::NewImage( value );
474
475         if( impl.mDecorator && image )
476         {
477           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
478           impl.RequestTextRelayout();
479         }
480         break;
481       }
482       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
483       {
484         const Image image = Scripting::NewImage( value );
485
486         if( impl.mDecorator && image )
487         {
488           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
489           impl.RequestTextRelayout();
490         }
491         break;
492       }
493       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
494       {
495         const Image image = Scripting::NewImage( value );
496
497         if( impl.mDecorator && image )
498         {
499           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
500           impl.RequestTextRelayout();
501         }
502         break;
503       }
504       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
505       {
506         const Image image = Scripting::NewImage( value );
507
508         if( impl.mDecorator && image )
509         {
510           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
511           impl.RequestTextRelayout();
512         }
513         break;
514       }
515       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
516       {
517         const Image image = Scripting::NewImage( value );
518
519         if( impl.mDecorator && image )
520         {
521           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
522           impl.RequestTextRelayout();
523         }
524         break;
525       }
526       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
527       {
528         const Vector4 color = value.Get< Vector4 >();
529         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 );
530
531         if( impl.mDecorator )
532         {
533           impl.mDecorator->SetHighlightColor( color );
534           impl.RequestTextRelayout();
535         }
536         break;
537       }
538       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
539       {
540         if( impl.mDecorator )
541         {
542           const Rect<int> box = value.Get< Rect<int> >();
543           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 );
544
545           impl.mDecorator->SetBoundingBox( box );
546           impl.RequestTextRelayout();
547         }
548         break;
549       }
550       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
551       {
552         const Property::Map map = value.Get<Property::Map>();
553         VirtualKeyboard::ApplySettings( map );
554         break;
555       }
556     } // switch
557   } // textfield
558 }
559
560 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
561 {
562   Property::Value value;
563
564   Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
565
566   if( textField )
567   {
568     TextField& impl( GetImpl( textField ) );
569
570     switch( index )
571     {
572       case Toolkit::TextField::Property::RENDERING_BACKEND:
573       {
574         value = impl.mRenderingBackend;
575         break;
576       }
577       case Toolkit::TextField::Property::TEXT:
578       {
579         if( impl.mController )
580         {
581           std::string text;
582           impl.mController->GetText( text );
583           DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
584           value = text;
585         }
586         break;
587       }
588       case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
589       {
590         if( impl.mController )
591         {
592           std::string text;
593           impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
594           value = text;
595         }
596         break;
597       }
598       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
599       {
600         if( impl.mController )
601         {
602           std::string text;
603           impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
604           value = text;
605         }
606         break;
607       }
608       case Toolkit::TextField::Property::FONT_FAMILY:
609       {
610         if( impl.mController )
611         {
612           value = impl.mController->GetDefaultFontFamily();
613         }
614         break;
615       }
616       case Toolkit::TextField::Property::FONT_STYLE:
617       {
618         GetFontStyleProperty( impl.mController, value );
619         break;
620       }
621       case Toolkit::TextField::Property::POINT_SIZE:
622       {
623         if( impl.mController )
624         {
625           value = impl.mController->GetDefaultPointSize();
626         }
627         break;
628       }
629       case Toolkit::TextField::Property::MAX_LENGTH:
630       {
631         if( impl.mController )
632         {
633           value = impl.mController->GetMaximumNumberOfCharacters();
634         }
635         break;
636       }
637       case Toolkit::TextField::Property::EXCEED_POLICY:
638       {
639         value = impl.mExceedPolicy;
640         break;
641       }
642       case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
643       {
644         if( impl.mController )
645         {
646           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
647                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE,
648                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
649           if( name )
650           {
651             value = std::string( name );
652           }
653         }
654         break;
655       }
656       case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
657       {
658         if( impl.mController )
659         {
660           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
661                                                                                                               VERTICAL_ALIGNMENT_STRING_TABLE,
662                                                                                                               VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
663           if( name )
664           {
665             value = std::string( name );
666           }
667         }
668         break;
669       }
670       case Toolkit::TextField::Property::TEXT_COLOR:
671       {
672         if ( impl.mController )
673         {
674           value = impl.mController->GetTextColor();
675         }
676         break;
677       }
678       case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
679       {
680         if ( impl.mController )
681         {
682           value = impl.mController->GetPlaceholderTextColor();
683         }
684         break;
685       }
686       case Toolkit::TextField::Property::SHADOW_OFFSET:
687       {
688         if ( impl.mController )
689         {
690           value = impl.mController->GetShadowOffset();
691         }
692         break;
693       }
694       case Toolkit::TextField::Property::SHADOW_COLOR:
695       {
696         if ( impl.mController )
697         {
698           value = impl.mController->GetShadowColor();
699         }
700         break;
701       }
702       case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
703       {
704         if( impl.mDecorator )
705         {
706           value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
707         }
708         break;
709       }
710       case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
711       {
712         if( impl.mDecorator )
713         {
714           value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
715         }
716         break;
717       }
718       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
719       {
720         value = impl.mController->GetEnableCursorBlink();
721         break;
722       }
723       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
724       {
725         if( impl.mDecorator )
726         {
727           value = impl.mDecorator->GetCursorBlinkInterval();
728         }
729         break;
730       }
731       case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
732       {
733         if( impl.mDecorator )
734         {
735           value = impl.mDecorator->GetCursorBlinkDuration();
736         }
737         break;
738       }
739       case Toolkit::TextField::Property::CURSOR_WIDTH:
740       {
741         if( impl.mDecorator )
742         {
743           value = impl.mDecorator->GetCursorWidth();
744         }
745         break;
746       }
747       case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
748       {
749         if( impl.mDecorator )
750         {
751           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
752           if( image )
753           {
754             value = image.GetUrl();
755           }
756         }
757         break;
758       }
759       case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
760       {
761         if( impl.mDecorator )
762         {
763           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
764           if( image )
765           {
766             value = image.GetUrl();
767           }
768         }
769         break;
770       }
771       case Toolkit::TextField::Property::SCROLL_THRESHOLD:
772       {
773         if( impl.mDecorator )
774         {
775           value = impl.mDecorator->GetScrollThreshold();
776         }
777         break;
778       }
779       case Toolkit::TextField::Property::SCROLL_SPEED:
780       {
781         if( impl.mDecorator )
782         {
783           value = impl.mDecorator->GetScrollSpeed();
784         }
785         break;
786       }
787       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
788       {
789         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
790         break;
791       }
792       case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
793       {
794         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
795         break;
796       }
797       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
798       {
799         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
800         break;
801       }
802       case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
803       {
804         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
805         break;
806       }
807       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
808       {
809         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
810         break;
811       }
812       case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
813       {
814         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
815         break;
816       }
817       case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
818       {
819         if( impl.mDecorator )
820         {
821           value = impl.mDecorator->GetHighlightColor();
822         }
823         break;
824       }
825       case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
826       {
827         if( impl.mDecorator )
828         {
829           Rect<int> boundingBox;
830           impl.mDecorator->GetBoundingBox( boundingBox );
831           value = boundingBox;
832         }
833         break;
834       }
835       case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
836       {
837         break;
838       }
839     } //switch
840   }
841
842   return value;
843 }
844
845 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
846 {
847   Dali::BaseHandle handle( object );
848
849   bool connected( true );
850   Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
851
852   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
853   {
854     field.TextChangedSignal().Connect( tracker, functor );
855   }
856   else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
857   {
858     field.MaxLengthReachedSignal().Connect( tracker, functor );
859   }
860   else
861   {
862     // signalName does not match any signal
863     connected = false;
864   }
865
866   return connected;
867 }
868
869 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
870 {
871   return mTextChangedSignal;
872 }
873
874 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
875 {
876   return mMaxLengthReachedSignal;
877 }
878
879 void TextField::OnInitialize()
880 {
881   Actor self = Self();
882
883   mController = Text::Controller::New( *this );
884
885   mDecorator = Text::Decorator::New( *mController,
886                                      *mController );
887
888   mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
889
890   mController->EnableTextInput( mDecorator );
891
892   // Forward input events to controller
893   EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
894   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
895
896   self.TouchedSignal().Connect( this, &TextField::OnTouched );
897
898   // Set BoundingBox to stage size if not already set.
899   Rect<int> boundingBox;
900   mDecorator->GetBoundingBox( boundingBox );
901
902   if( boundingBox.IsEmpty() )
903   {
904     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
905     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
906   }
907
908   // Flip vertically the 'left' selection handle
909   mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
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(), TEXT_DEPTH_INDEX );
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