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