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