Added code for stylable transitions
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.cpp
1 /*
2  * Copyright (c) 2016 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-editor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring>
23 #include <limits>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptors/adaptor.h>
30 #include <dali/integration-api/debug.h>
31
32 // INTERNAL INCLUDES
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
35 #include <dali-toolkit/internal/text/rendering/text-backend.h>
36 #include <dali-toolkit/internal/text/text-effects-style.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
38 #include <dali-toolkit/internal/text/text-view.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40
41 using namespace Dali::Toolkit::Text;
42
43 namespace Dali
44 {
45
46 namespace Toolkit
47 {
48
49 namespace Internal
50 {
51
52 namespace // unnamed namespace
53 {
54
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
57 #endif
58
59 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
60 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
61 } // unnamed namespace
62
63 namespace
64 {
65
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
67 {
68   { "BEGIN",  Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN  },
69   { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
70   { "END",    Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END    },
71 };
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
73
74 // Type registration
75 BaseHandle Create()
76 {
77   return Toolkit::TextEditor::New();
78 }
79
80 // Setup properties, signals and actions using the type-registry.
81 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
82
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend",                     INTEGER,   RENDERING_BACKEND                    )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text",                                 STRING,    TEXT                                 )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor",                            VECTOR4,   TEXT_COLOR                           )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily",                           STRING,    FONT_FAMILY                          )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle",                            STRING,    FONT_STYLE                           )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize",                            FLOAT,     POINT_SIZE                           )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment",                  STRING,    HORIZONTAL_ALIGNMENT                 )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold",                      FLOAT,     SCROLL_THRESHOLD                     )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed",                          FLOAT,     SCROLL_SPEED                         )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor",                   VECTOR4,   PRIMARY_CURSOR_COLOR                 )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor",                 VECTOR4,   SECONDARY_CURSOR_COLOR               )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink",                    BOOLEAN,   ENABLE_CURSOR_BLINK                  )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval",                  FLOAT,     CURSOR_BLINK_INTERVAL                )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration",                  FLOAT,     CURSOR_BLINK_DURATION                )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth",                          INTEGER,   CURSOR_WIDTH                         )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage",                      STRING,    GRAB_HANDLE_IMAGE                    )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage",               STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft",             MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight",            MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft",      MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight",     MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft",       MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight",      MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor",              VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox",                RECTANGLE, DECORATION_BOUNDING_BOX              )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup",                         BOOLEAN,   ENABLE_MARKUP                        )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor",                           VECTOR4,   INPUT_COLOR                          )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily",                      STRING,    INPUT_FONT_FAMILY                    )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle",                       STRING,    INPUT_FONT_STYLE                     )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize",                       FLOAT,     INPUT_POINT_SIZE                     )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineSpacing",                          FLOAT,     LINE_SPACING                         )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputLineSpacing",                     FLOAT,     INPUT_LINE_SPACING                   )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "underline",                            STRING,    UNDERLINE                            )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputUnderline",                       STRING,    INPUT_UNDERLINE                      )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "shadow",                               STRING,    SHADOW                               )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputShadow",                          STRING,    INPUT_SHADOW                         )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "emboss",                               STRING,    EMBOSS                               )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputEmboss",                          STRING,    INPUT_EMBOSS                         )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "outline",                              STRING,    OUTLINE                              )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputOutline",                         STRING,    INPUT_OUTLINE                        )
123
124 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
125 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
126
127 DALI_TYPE_REGISTRATION_END()
128
129 } // namespace
130
131 Toolkit::TextEditor TextEditor::New()
132 {
133   // Create the implementation, temporarily owned by this handle on stack
134   IntrusivePtr< TextEditor > impl = new TextEditor();
135
136   // Pass ownership to CustomActor handle
137   Toolkit::TextEditor handle( *impl );
138
139   // Second-phase init of the implementation
140   // This can only be done after the CustomActor connection has been made...
141   impl->Initialize();
142
143   return handle;
144 }
145
146 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
147 {
148   Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
149
150   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
151
152
153   if( textEditor )
154   {
155     TextEditor& impl( GetImpl( textEditor ) );
156
157     switch( index )
158     {
159       case Toolkit::TextEditor::Property::RENDERING_BACKEND:
160       {
161         int backend = value.Get< int >();
162         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
163
164         if( impl.mRenderingBackend != backend )
165         {
166           impl.mRenderingBackend = backend;
167           impl.mRenderer.Reset();
168           impl.RequestTextRelayout();
169         }
170         break;
171       }
172       case Toolkit::TextEditor::Property::TEXT:
173       {
174         if( impl.mController )
175         {
176           const std::string text = value.Get< std::string >();
177           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
178
179           impl.mController->SetText( text );
180         }
181         break;
182       }
183       case Toolkit::TextEditor::Property::TEXT_COLOR:
184       {
185         if( impl.mController )
186         {
187           const Vector4 textColor = value.Get< Vector4 >();
188           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
189
190           if( impl.mController->GetTextColor() != textColor )
191           {
192             impl.mController->SetTextColor( textColor );
193             impl.mController->SetInputColor( textColor );
194             impl.mRenderer.Reset();
195           }
196         }
197         break;
198       }
199       case Toolkit::TextEditor::Property::FONT_FAMILY:
200       {
201         if( impl.mController )
202         {
203           const std::string fontFamily = value.Get< std::string >();
204           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
205           impl.mController->SetDefaultFontFamily( fontFamily );
206         }
207         break;
208       }
209       case Toolkit::TextEditor::Property::FONT_STYLE:
210       {
211         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
212         break;
213       }
214       case Toolkit::TextEditor::Property::POINT_SIZE:
215       {
216         if( impl.mController )
217         {
218           const float pointSize = value.Get< float >();
219           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
220
221           if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
222           {
223             impl.mController->SetDefaultPointSize( pointSize );
224           }
225         }
226         break;
227       }
228       case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
229       {
230         if( impl.mController )
231         {
232           const std::string alignStr = value.Get< std::string >();
233           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
234
235           LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
236           if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
237                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE,
238                                                                               HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
239                                                                               alignment ) )
240           {
241             impl.mController->SetHorizontalAlignment( alignment );
242           }
243         }
244         break;
245       }
246       case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
247       {
248         const float threshold = value.Get< float >();
249         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
250
251         if( impl.mDecorator )
252         {
253           impl.mDecorator->SetScrollThreshold( threshold );
254         }
255         break;
256       }
257       case Toolkit::TextEditor::Property::SCROLL_SPEED:
258       {
259         const float speed = value.Get< float >();
260         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
261
262         if( impl.mDecorator )
263         {
264           impl.mDecorator->SetScrollSpeed( speed );
265         }
266         break;
267       }
268       case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
269       {
270         if( impl.mDecorator )
271         {
272           const Vector4 color = value.Get< Vector4 >();
273           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
274
275           impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
276           impl.RequestTextRelayout();
277         }
278         break;
279       }
280       case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
281       {
282         if( impl.mDecorator )
283         {
284           const Vector4 color = value.Get< Vector4 >();
285           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
286
287           impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
288           impl.RequestTextRelayout();
289         }
290         break;
291       }
292       case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
293       {
294         if( impl.mController )
295         {
296           const bool enable = value.Get< bool >();
297           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
298
299           impl.mController->SetEnableCursorBlink( enable );
300           impl.RequestTextRelayout();
301         }
302         break;
303       }
304       case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
305       {
306         if( impl.mDecorator )
307         {
308           const float interval = value.Get< float >();
309           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
310
311           impl.mDecorator->SetCursorBlinkInterval( interval );
312         }
313         break;
314       }
315       case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
316       {
317         if( impl.mDecorator )
318         {
319           const float duration = value.Get< float >();
320           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
321
322           impl.mDecorator->SetCursorBlinkDuration( duration );
323         }
324         break;
325       }
326       case Toolkit::TextEditor::Property::CURSOR_WIDTH:
327       {
328         if( impl.mDecorator )
329         {
330           const int width = value.Get< int >();
331           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
332
333           impl.mDecorator->SetCursorWidth( width );
334           impl.mController->GetLayoutEngine().SetCursorWidth( width );
335         }
336         break;
337       }
338       case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
339       {
340         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
341         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
342
343         if( impl.mDecorator )
344         {
345           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
346           impl.RequestTextRelayout();
347         }
348         break;
349       }
350       case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
351       {
352         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
353         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
354
355         if( impl.mDecorator )
356         {
357           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
358           impl.RequestTextRelayout();
359         }
360         break;
361       }
362       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
363       {
364         const Image image = Scripting::NewImage( value );
365
366         if( impl.mDecorator && image )
367         {
368           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
369           impl.RequestTextRelayout();
370         }
371         break;
372       }
373       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
374       {
375         const Image image = Scripting::NewImage( value );
376
377         if( impl.mDecorator && image )
378         {
379           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
380           impl.RequestTextRelayout();
381         }
382         break;
383       }
384       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
385       {
386         const Image image = Scripting::NewImage( value );
387
388         if( impl.mDecorator && image )
389         {
390           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
391           impl.RequestTextRelayout();
392         }
393         break;
394       }
395       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
396       {
397         const Image image = Scripting::NewImage( value );
398
399         if( impl.mDecorator && image )
400         {
401           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
402           impl.RequestTextRelayout();
403         }
404         break;
405       }
406       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
407       {
408         const Image image = Scripting::NewImage( value );
409
410         if( impl.mDecorator && image )
411         {
412           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
413           impl.RequestTextRelayout();
414         }
415         break;
416       }
417       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
418       {
419         const Image image = Scripting::NewImage( value );
420
421         if( impl.mDecorator && image )
422         {
423           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
424           impl.RequestTextRelayout();
425         }
426         break;
427       }
428       case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
429       {
430         const Vector4 color = value.Get< Vector4 >();
431         DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
432
433         if( impl.mDecorator )
434         {
435           impl.mDecorator->SetHighlightColor( color );
436           impl.RequestTextRelayout();
437         }
438         break;
439       }
440       case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
441       {
442         if( impl.mDecorator )
443         {
444           const Rect<int> box = value.Get< Rect<int> >();
445           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
446
447           impl.mDecorator->SetBoundingBox( box );
448           impl.RequestTextRelayout();
449         }
450         break;
451       }
452       case Toolkit::TextEditor::Property::ENABLE_MARKUP:
453       {
454         if( impl.mController )
455         {
456           const bool enableMarkup = value.Get<bool>();
457           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
458
459           impl.mController->SetMarkupProcessorEnabled( enableMarkup );
460         }
461         break;
462       }
463       case Toolkit::TextEditor::Property::INPUT_COLOR:
464       {
465         if( impl.mController )
466         {
467           const Vector4 inputColor = value.Get< Vector4 >();
468           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
469
470           impl.mController->SetInputColor( inputColor );
471         }
472         break;
473       }
474       case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
475       {
476         if( impl.mController )
477         {
478           const std::string fontFamily = value.Get< std::string >();
479           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
480           impl.mController->SetInputFontFamily( fontFamily );
481         }
482         break;
483       }
484       case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
485       {
486         SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
487         break;
488       }
489       case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
490       {
491         if( impl.mController )
492         {
493           const float pointSize = value.Get< float >();
494           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
495           impl.mController->SetInputFontPointSize( pointSize );
496         }
497         break;
498       }
499       case Toolkit::TextEditor::Property::LINE_SPACING:
500       {
501         if( impl.mController )
502         {
503           const float lineSpacing = value.Get<float>();
504           impl.mController->SetDefaultLineSpacing( lineSpacing );
505           impl.mRenderer.Reset();
506         }
507         break;
508       }
509       case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
510       {
511         if( impl.mController )
512         {
513           const float lineSpacing = value.Get<float>();
514           impl.mController->SetInputLineSpacing( lineSpacing );
515           impl.mRenderer.Reset();
516         }
517         break;
518       }
519       case Toolkit::TextEditor::Property::UNDERLINE:
520       {
521         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
522         if( update )
523         {
524           impl.mRenderer.Reset();
525         }
526         break;
527       }
528       case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
529       {
530         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
531         if( update )
532         {
533           impl.mRenderer.Reset();
534         }
535         break;
536       }
537       case Toolkit::TextEditor::Property::SHADOW:
538       {
539         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
540         if( update )
541         {
542           impl.mRenderer.Reset();
543         }
544         break;
545       }
546       case Toolkit::TextEditor::Property::INPUT_SHADOW:
547       {
548         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
549         if( update )
550         {
551           impl.mRenderer.Reset();
552         }
553         break;
554       }
555       case Toolkit::TextEditor::Property::EMBOSS:
556       {
557         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
558         if( update )
559         {
560           impl.mRenderer.Reset();
561         }
562         break;
563       }
564       case Toolkit::TextEditor::Property::INPUT_EMBOSS:
565       {
566         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
567         if( update )
568         {
569           impl.mRenderer.Reset();
570         }
571         break;
572       }
573       case Toolkit::TextEditor::Property::OUTLINE:
574       {
575         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
576         if( update )
577         {
578           impl.mRenderer.Reset();
579         }
580         break;
581       }
582       case Toolkit::TextEditor::Property::INPUT_OUTLINE:
583       {
584         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
585         if( update )
586         {
587           impl.mRenderer.Reset();
588         }
589         break;
590       }
591     } // switch
592   } // texteditor
593 }
594
595 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
596 {
597   Property::Value value;
598
599   Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
600
601   if( textEditor )
602   {
603     TextEditor& impl( GetImpl( textEditor ) );
604
605     switch( index )
606     {
607       case Toolkit::TextEditor::Property::RENDERING_BACKEND:
608       {
609         value = impl.mRenderingBackend;
610         break;
611       }
612       case Toolkit::TextEditor::Property::TEXT:
613       {
614         if( impl.mController )
615         {
616           std::string text;
617           impl.mController->GetText( text );
618           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
619           value = text;
620         }
621         break;
622       }
623       case Toolkit::TextEditor::Property::TEXT_COLOR:
624       {
625         if ( impl.mController )
626         {
627           value = impl.mController->GetTextColor();
628         }
629         break;
630       }
631       case Toolkit::TextEditor::Property::FONT_FAMILY:
632       {
633         if( impl.mController )
634         {
635           value = impl.mController->GetDefaultFontFamily();
636         }
637         break;
638       }
639       case Toolkit::TextEditor::Property::FONT_STYLE:
640       {
641         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
642         break;
643       }
644       case Toolkit::TextEditor::Property::POINT_SIZE:
645       {
646         if( impl.mController )
647         {
648           value = impl.mController->GetDefaultPointSize();
649         }
650         break;
651       }
652       case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
653       {
654         if( impl.mController )
655         {
656           const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
657                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE,
658                                                                                                                 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
659           if( name )
660           {
661             value = std::string( name );
662           }
663         }
664         break;
665       }
666       case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
667       {
668         if( impl.mDecorator )
669         {
670           value = impl.mDecorator->GetScrollThreshold();
671         }
672         break;
673       }
674       case Toolkit::TextEditor::Property::SCROLL_SPEED:
675       {
676         if( impl.mDecorator )
677         {
678           value = impl.mDecorator->GetScrollSpeed();
679         }
680         break;
681       }
682       case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
683       {
684         if( impl.mDecorator )
685         {
686           value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
687         }
688         break;
689       }
690       case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
691       {
692         if( impl.mDecorator )
693         {
694           value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
695         }
696         break;
697       }
698       case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
699       {
700         value = impl.mController->GetEnableCursorBlink();
701         break;
702       }
703       case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
704       {
705         if( impl.mDecorator )
706         {
707           value = impl.mDecorator->GetCursorBlinkInterval();
708         }
709         break;
710       }
711       case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
712       {
713         if( impl.mDecorator )
714         {
715           value = impl.mDecorator->GetCursorBlinkDuration();
716         }
717         break;
718       }
719       case Toolkit::TextEditor::Property::CURSOR_WIDTH:
720       {
721         if( impl.mDecorator )
722         {
723           value = impl.mDecorator->GetCursorWidth();
724         }
725         break;
726       }
727       case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
728       {
729         if( impl.mDecorator )
730         {
731           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
732           if( image )
733           {
734             value = image.GetUrl();
735           }
736         }
737         break;
738       }
739       case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
740       {
741         if( impl.mDecorator )
742         {
743           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
744           if( image )
745           {
746             value = image.GetUrl();
747           }
748         }
749         break;
750       }
751       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
752       {
753         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
754         break;
755       }
756       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
757       {
758         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
759         break;
760       }
761       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
762       {
763         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
764         break;
765       }
766       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
767       {
768         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
769         break;
770       }
771       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
772       {
773         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
774         break;
775       }
776       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
777       {
778         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
779         break;
780       }
781       case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
782       {
783         if( impl.mDecorator )
784         {
785           value = impl.mDecorator->GetHighlightColor();
786         }
787         break;
788       }
789       case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
790       {
791         if( impl.mDecorator )
792         {
793           Rect<int> boundingBox;
794           impl.mDecorator->GetBoundingBox( boundingBox );
795           value = boundingBox;
796         }
797         break;
798       }
799       case Toolkit::TextEditor::Property::ENABLE_MARKUP:
800       {
801         if( impl.mController )
802         {
803           value = impl.mController->IsMarkupProcessorEnabled();
804         }
805         break;
806       }
807       case Toolkit::TextEditor::Property::INPUT_COLOR:
808       {
809         if( impl.mController )
810         {
811           value = impl.mController->GetInputColor();
812         }
813         break;
814       }
815       case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
816       {
817         if( impl.mController )
818         {
819           value = impl.mController->GetInputFontFamily();
820         }
821         break;
822       }
823       case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
824       {
825         GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
826         break;
827       }
828       case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
829       {
830         if( impl.mController )
831         {
832           value = impl.mController->GetInputFontPointSize();
833         }
834         break;
835       }
836       case Toolkit::TextEditor::Property::LINE_SPACING:
837       {
838         if( impl.mController )
839         {
840           value = impl.mController->GetDefaultLineSpacing();
841         }
842         break;
843       }
844       case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
845       {
846         if( impl.mController )
847         {
848           value = impl.mController->GetInputLineSpacing();
849         }
850         break;
851       }
852       case Toolkit::TextEditor::Property::UNDERLINE:
853       {
854         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
855         break;
856       }
857       case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
858       {
859         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
860         break;
861       }
862       case Toolkit::TextEditor::Property::SHADOW:
863       {
864         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
865         break;
866       }
867       case Toolkit::TextEditor::Property::INPUT_SHADOW:
868       {
869         GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
870         break;
871       }
872       case Toolkit::TextEditor::Property::EMBOSS:
873       {
874         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
875         break;
876       }
877       case Toolkit::TextEditor::Property::INPUT_EMBOSS:
878       {
879         GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
880         break;
881       }
882       case Toolkit::TextEditor::Property::OUTLINE:
883       {
884         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
885         break;
886       }
887       case Toolkit::TextEditor::Property::INPUT_OUTLINE:
888       {
889         GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
890         break;
891       }
892     } //switch
893   }
894
895   return value;
896 }
897
898 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
899 {
900   Dali::BaseHandle handle( object );
901
902   bool connected( true );
903   Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
904
905   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
906   {
907     editor.TextChangedSignal().Connect( tracker, functor );
908   }
909   else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
910   {
911     editor.InputStyleChangedSignal().Connect( tracker, functor );
912   }
913   else
914   {
915     // signalName does not match any signal
916     connected = false;
917   }
918
919   return connected;
920 }
921
922 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
923 {
924   return mTextChangedSignal;
925 }
926
927 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
928 {
929   return mInputStyleChangedSignal;
930 }
931
932 void TextEditor::OnInitialize()
933 {
934   Actor self = Self();
935
936   mController = Text::Controller::New( *this );
937
938   mDecorator = Text::Decorator::New( *mController,
939                                      *mController );
940
941   mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX );
942
943   // Enables the text input.
944   mController->EnableTextInput( mDecorator );
945
946   // Enables the vertical scrolling after the text input has been enabled.
947   mController->SetVerticalScrollEnabled( true );
948
949   // Disables the horizontal scrolling.
950   mController->SetHorizontalScrollEnabled( false );
951
952   mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
953
954   // Enable the smooth handle panning.
955   mController->SetSmoothHandlePanEnabled( true );
956
957   // Forward input events to controller
958   EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
959   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
960
961   self.TouchSignal().Connect( this, &TextEditor::OnTouched );
962
963   // Set BoundingBox to stage size if not already set.
964   Rect<int> boundingBox;
965   mDecorator->GetBoundingBox( boundingBox );
966
967   if( boundingBox.IsEmpty() )
968   {
969     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
970     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
971   }
972
973   // Whether to flip the selection handles as soon as they cross.
974   mDecorator->FlipSelectionHandlesOnCrossEnabled( true );
975
976   // Set the default scroll speed.
977   mDecorator->SetScrollSpeed( DEFAULT_SCROLL_SPEED );
978
979   // Fill-parent area by default
980   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
981   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
982   self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
983 }
984
985 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
986 {
987   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
988
989   switch ( change )
990   {
991     case StyleChange::DEFAULT_FONT_CHANGE:
992     {
993       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
994       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
995       // Property system did not set the font so should update it.
996       mController->UpdateAfterFontChange( newFont );
997       break;
998     }
999
1000     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1001     {
1002       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1003       break;
1004     }
1005     case StyleChange::THEME_CHANGE:
1006     {
1007       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1008       break;
1009     }
1010   }
1011 }
1012
1013 Vector3 TextEditor::GetNaturalSize()
1014 {
1015   return mController->GetNaturalSize();
1016 }
1017
1018 float TextEditor::GetHeightForWidth( float width )
1019 {
1020   return mController->GetHeightForWidth( width );
1021 }
1022
1023 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
1024 {
1025   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
1026
1027   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1028
1029   if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1030       !mRenderer )
1031   {
1032     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
1033
1034     if( mDecorator &&
1035         ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1036     {
1037       mDecorator->Relayout( size );
1038     }
1039
1040     if( !mRenderer )
1041     {
1042       mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1043     }
1044
1045     EnableClipping( true, size );
1046     RenderText( updateTextType );
1047   }
1048
1049   // The text-editor emits signals when the input style changes. These changes of style are
1050   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1051   // can't be emitted during the size negotiation as the callbacks may update the UI.
1052   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1053   if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1054   {
1055     if( Adaptor::IsAvailable() )
1056     {
1057       Adaptor& adaptor = Adaptor::Get();
1058
1059       if( NULL == mIdleCallback )
1060       {
1061         // @note: The callback manager takes the ownership of the callback object.
1062         mIdleCallback = MakeCallback( this, &TextEditor::OnIdleSignal );
1063         adaptor.AddIdle( mIdleCallback );
1064       }
1065     }
1066   }
1067 }
1068
1069 void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
1070 {
1071   Actor self = Self();
1072   Actor renderableActor;
1073
1074   if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1075   {
1076     if( mRenderer )
1077     {
1078       renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1079     }
1080
1081     if( renderableActor != mRenderableActor )
1082     {
1083       UnparentAndReset( mRenderableActor );
1084       mRenderableActor = renderableActor;
1085     }
1086   }
1087
1088   if( mRenderableActor )
1089   {
1090     const Vector2& scrollOffset = mController->GetScrollPosition();
1091
1092     mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
1093
1094     Actor clipRootActor;
1095     if( mClipper )
1096     {
1097       clipRootActor = mClipper->GetRootActor();
1098     }
1099
1100     for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1101            endIt = mClippingDecorationActors.end();
1102          it != endIt;
1103          ++it )
1104     {
1105       Actor actor = *it;
1106
1107       if( clipRootActor )
1108       {
1109         clipRootActor.Add( actor );
1110       }
1111       else
1112       {
1113         self.Add( actor );
1114       }
1115     }
1116     mClippingDecorationActors.clear();
1117
1118     // Make sure the actor is parented correctly with/without clipping
1119     if( clipRootActor )
1120     {
1121       clipRootActor.Add( mRenderableActor );
1122     }
1123     else
1124     {
1125       self.Add( mRenderableActor );
1126     }
1127   }
1128 }
1129
1130 void TextEditor::OnKeyInputFocusGained()
1131 {
1132   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
1133
1134   VirtualKeyboard::StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
1135
1136   ImfManager imfManager = ImfManager::Get();
1137
1138   if ( imfManager )
1139   {
1140     imfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
1141
1142     // Notify that the text editing start.
1143     imfManager.Activate();
1144
1145     // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1146     imfManager.SetRestoreAfterFocusLost( true );
1147   }
1148
1149    ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1150
1151    if ( notifier )
1152    {
1153       notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
1154    }
1155
1156   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1157
1158   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1159 }
1160
1161 void TextEditor::OnKeyInputFocusLost()
1162 {
1163   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
1164
1165   VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
1166
1167   ImfManager imfManager = ImfManager::Get();
1168   if ( imfManager )
1169   {
1170     // The text editing is finished. Therefore the imf manager don't have restore activation.
1171     imfManager.SetRestoreAfterFocusLost( false );
1172
1173     // Notify that the text editing finish.
1174     imfManager.Deactivate();
1175
1176     imfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
1177   }
1178
1179   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1180
1181   if ( notifier )
1182   {
1183     notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
1184   }
1185
1186   mController->KeyboardFocusLostEvent();
1187
1188   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1189 }
1190
1191 void TextEditor::OnTap( const TapGesture& gesture )
1192 {
1193   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
1194
1195   // Show the keyboard if it was hidden.
1196   if (!VirtualKeyboard::IsVisible())
1197   {
1198     VirtualKeyboard::Show();
1199   }
1200
1201   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1202   mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1203
1204   SetKeyInputFocus();
1205 }
1206
1207 void TextEditor::OnPan( const PanGesture& gesture )
1208 {
1209   mController->PanEvent( gesture.state, gesture.displacement );
1210 }
1211
1212 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1213 {
1214   // Show the keyboard if it was hidden.
1215   if (!VirtualKeyboard::IsVisible())
1216   {
1217     VirtualKeyboard::Show();
1218   }
1219
1220   mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1221
1222   SetKeyInputFocus();
1223 }
1224
1225 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1226 {
1227   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1228
1229   if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1230   {
1231     ClearKeyInputFocus();
1232     return true;
1233   }
1234
1235   return mController->KeyEvent( event );
1236 }
1237
1238 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1239 {
1240   if( actor )
1241   {
1242     if( needsClipping )
1243     {
1244       mClippingDecorationActors.push_back( actor );
1245     }
1246     else
1247     {
1248       Self().Add( actor );
1249     }
1250   }
1251 }
1252
1253 void TextEditor::RequestTextRelayout()
1254 {
1255   RelayoutRequest();
1256 }
1257
1258 void TextEditor::TextChanged()
1259 {
1260   Dali::Toolkit::TextEditor handle( GetOwner() );
1261   mTextChangedSignal.Emit( handle );
1262 }
1263
1264 void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1265 {
1266   Dali::Toolkit::TextEditor handle( GetOwner() );
1267
1268   Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
1269
1270   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1271   {
1272     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR );
1273   }
1274   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1275   {
1276     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY );
1277   }
1278   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1279   {
1280     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE );
1281   }
1282   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1283   {
1284     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1285   }
1286   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1287   {
1288     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1289   }
1290   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1291   {
1292     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1293   }
1294   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_LINE_SPACING ) )
1295   {
1296     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING );
1297   }
1298   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1299   {
1300     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE );
1301   }
1302   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1303   {
1304     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW );
1305   }
1306   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1307   {
1308     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS );
1309   }
1310   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1311   {
1312     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE );
1313   }
1314
1315   mInputStyleChangedSignal.Emit( handle, editorInputStyleMask );
1316 }
1317
1318 void TextEditor::MaxLengthReached()
1319 {
1320   // Nothing to do as TextEditor doesn't emit a max length reached signal.
1321 }
1322
1323 void TextEditor::OnStageConnect( Dali::Actor actor )
1324 {
1325   if ( mHasBeenStaged )
1326   {
1327     RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1328   }
1329   else
1330   {
1331     mHasBeenStaged = true;
1332   }
1333 }
1334
1335 ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1336 {
1337   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1338   return mController->OnImfEvent( imfManager, imfEvent );
1339 }
1340
1341 void TextEditor::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1342 {
1343   if( mDecorator )
1344   {
1345     ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1346
1347     if ( image )
1348     {
1349       Property::Map map;
1350       Scripting::CreatePropertyMap( image, map );
1351       value = map;
1352     }
1353   }
1354 }
1355
1356 void TextEditor::EnableClipping( bool clipping, const Vector2& size )
1357 {
1358   if( clipping )
1359   {
1360     // Not worth to created clip actor if width or height is equal to zero.
1361     if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1362     {
1363       if( !mClipper )
1364       {
1365         Actor self = Self();
1366
1367         mClipper = Clipper::New( size );
1368         self.Add( mClipper->GetRootActor() );
1369         self.Add( mClipper->GetImageView() );
1370       }
1371       else if ( mClipper )
1372       {
1373         mClipper->Refresh( size );
1374       }
1375     }
1376   }
1377   else
1378   {
1379     // Note - this will automatically remove the root actor & the image view
1380     mClipper.Reset();
1381   }
1382 }
1383
1384 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1385 {
1386   mController->PasteClipboardItemEvent();
1387 }
1388
1389 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1390 {
1391   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1392
1393   // Just hide the grab handle when keyboard is hidden.
1394   if (!keyboardShown )
1395   {
1396     mController->KeyboardFocusLostEvent();
1397   }
1398   else
1399   {
1400     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1401   }
1402 }
1403
1404 void TextEditor::OnStageConnection( int depth )
1405 {
1406   // Call the Control::OnStageConnection() to set the depth of the background.
1407   Control::OnStageConnection( depth );
1408
1409   // Sets the depth to the visuals inside the text's decorator.
1410   mDecorator->SetTextDepth( depth );
1411
1412   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1413 }
1414
1415 bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
1416 {
1417   return true;
1418 }
1419
1420 void TextEditor::OnIdleSignal()
1421 {
1422   // Emits the change of input style signals.
1423   mController->ProcessInputStyleChangedSignals();
1424
1425   // Set the pointer to null as the callback manager deletes the callback after execute it.
1426   mIdleCallback = NULL;
1427 }
1428
1429 TextEditor::TextEditor()
1430 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1431   mIdleCallback( NULL ),
1432   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1433   mHasBeenStaged( false )
1434 {
1435 }
1436
1437 TextEditor::~TextEditor()
1438 {
1439   mClipper.Reset();
1440
1441   if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1442   {
1443     // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1444     Adaptor::Get().RemoveIdle( mIdleCallback );
1445   }
1446 }
1447
1448 } // namespace Internal
1449
1450 } // namespace Toolkit
1451
1452 } // namespace Dali