[Tizen][ATSPI] Accessibility initial implementation
[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/actors/actor-devel.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/text/text-enumerations.h>
36 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-devel.h>
38 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47
48 using namespace Dali::Toolkit::Text;
49
50 namespace Dali
51 {
52
53 namespace Toolkit
54 {
55
56 namespace Internal
57 {
58
59 namespace // unnamed namespace
60 {
61
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
64 #endif
65
66 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
67 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
68 } // unnamed namespace
69
70 namespace
71 {
72 const char* const SCROLL_BAR_POSITION("sourcePosition");
73 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
74 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
75 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
76
77 // Type registration
78 BaseHandle Create()
79 {
80   return Toolkit::TextEditor::New();
81 }
82
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
85
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend",                     INTEGER,   RENDERING_BACKEND                    )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text",                                 STRING,    TEXT                                 )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor",                            VECTOR4,   TEXT_COLOR                           )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily",                           STRING,    FONT_FAMILY                          )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle",                            MAP,       FONT_STYLE                           )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize",                            FLOAT,     POINT_SIZE                           )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment",                  STRING,    HORIZONTAL_ALIGNMENT                 )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold",                      FLOAT,     SCROLL_THRESHOLD                     )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed",                          FLOAT,     SCROLL_SPEED                         )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor",                   VECTOR4,   PRIMARY_CURSOR_COLOR                 )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor",                 VECTOR4,   SECONDARY_CURSOR_COLOR               )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink",                    BOOLEAN,   ENABLE_CURSOR_BLINK                  )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval",                  FLOAT,     CURSOR_BLINK_INTERVAL                )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration",                  FLOAT,     CURSOR_BLINK_DURATION                )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth",                          INTEGER,   CURSOR_WIDTH                         )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage",                      STRING,    GRAB_HANDLE_IMAGE                    )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage",               STRING,    GRAB_HANDLE_PRESSED_IMAGE            )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft",             MAP,       SELECTION_HANDLE_IMAGE_LEFT          )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight",            MAP,       SELECTION_HANDLE_IMAGE_RIGHT         )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft",      MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT  )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight",     MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft",       MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT   )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight",      MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT  )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor",              VECTOR4,   SELECTION_HIGHLIGHT_COLOR            )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox",                RECTANGLE, DECORATION_BOUNDING_BOX              )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup",                         BOOLEAN,   ENABLE_MARKUP                        )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor",                           VECTOR4,   INPUT_COLOR                          )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily",                      STRING,    INPUT_FONT_FAMILY                    )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle",                       MAP,       INPUT_FONT_STYLE                     )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize",                       FLOAT,     INPUT_POINT_SIZE                     )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineSpacing",                          FLOAT,     LINE_SPACING                         )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputLineSpacing",                     FLOAT,     INPUT_LINE_SPACING                   )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "underline",                            MAP,       UNDERLINE                            )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputUnderline",                       MAP,       INPUT_UNDERLINE                      )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "shadow",                               MAP,       SHADOW                               )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputShadow",                          MAP,       INPUT_SHADOW                         )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "emboss",                               MAP,       EMBOSS                               )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputEmboss",                          MAP,       INPUT_EMBOSS                         )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "outline",                              MAP,       OUTLINE                              )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputOutline",                         MAP,       INPUT_OUTLINE                        )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "smoothScroll",                         BOOLEAN,   SMOOTH_SCROLL                        )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "smoothScrollDuration",                 FLOAT,     SMOOTH_SCROLL_DURATION               )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableScrollBar",                      BOOLEAN,   ENABLE_SCROLL_BAR                    )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration",                FLOAT,     SCROLL_BAR_SHOW_DURATION             )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration",                FLOAT,     SCROLL_BAR_FADE_DURATION             )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize",                            FLOAT,     PIXEL_SIZE                           )
132 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount",                  INTEGER,   LINE_COUNT                           )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableSelection",                      BOOLEAN,   ENABLE_SELECTION                     )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholder",                          MAP,       PLACEHOLDER                          )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineWrapMode",                         INTEGER,   LINE_WRAP_MODE                       )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText",                STRING,    PLACEHOLDER_TEXT                     )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor",           VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableShiftSelection",           BOOLEAN,   ENABLE_SHIFT_SELECTION               )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle",               BOOLEAN,   ENABLE_GRAB_HANDLE                   )
140
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
143
144 DALI_TYPE_REGISTRATION_END()
145
146 } // namespace
147
148 Toolkit::TextEditor TextEditor::New()
149 {
150   // Create the implementation, temporarily owned by this handle on stack
151   IntrusivePtr< TextEditor > impl = new TextEditor();
152
153   // Pass ownership to CustomActor handle
154   Toolkit::TextEditor handle( *impl );
155
156   // Second-phase init of the implementation
157   // This can only be done after the CustomActor connection has been made...
158   impl->Initialize();
159
160   return handle;
161 }
162
163 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
164 {
165   Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
166
167   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
168
169
170   if( textEditor )
171   {
172     TextEditor& impl( GetImpl( textEditor ) );
173
174     switch( index )
175     {
176       case Toolkit::TextEditor::Property::RENDERING_BACKEND:
177       {
178         int backend = value.Get< int >();
179         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
180
181         if( impl.mRenderingBackend != backend )
182         {
183           impl.mRenderingBackend = backend;
184           impl.mRenderer.Reset();
185           impl.RequestTextRelayout();
186         }
187         break;
188       }
189       case Toolkit::TextEditor::Property::TEXT:
190       {
191         if( impl.mController )
192         {
193           const std::string& text = value.Get< std::string >();
194           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
195
196           impl.mController->SetText( text );
197         }
198         break;
199       }
200       case Toolkit::TextEditor::Property::TEXT_COLOR:
201       {
202         if( impl.mController )
203         {
204           const Vector4& textColor = value.Get< Vector4 >();
205           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 );
206
207           if( impl.mController->GetDefaultColor() != textColor )
208           {
209             impl.mController->SetDefaultColor( textColor );
210             impl.mController->SetInputColor( textColor );
211             impl.mRenderer.Reset();
212           }
213         }
214         break;
215       }
216       case Toolkit::TextEditor::Property::FONT_FAMILY:
217       {
218         if( impl.mController )
219         {
220           const std::string& fontFamily = value.Get< std::string >();
221           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
222           impl.mController->SetDefaultFontFamily( fontFamily );
223         }
224         break;
225       }
226       case Toolkit::TextEditor::Property::FONT_STYLE:
227       {
228         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
229         break;
230       }
231       case Toolkit::TextEditor::Property::POINT_SIZE:
232       {
233         if( impl.mController )
234         {
235           const float pointSize = value.Get< float >();
236           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
237
238           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
239           {
240             impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
241           }
242         }
243         break;
244       }
245       case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
246       {
247         if( impl.mController )
248         {
249           Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
250           if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
251           {
252             DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
253             impl.mController->SetHorizontalAlignment( alignment );
254           }
255         }
256         break;
257       }
258       case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
259       {
260         const float threshold = value.Get< float >();
261         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
262
263         if( impl.mDecorator )
264         {
265           impl.mDecorator->SetScrollThreshold( threshold );
266         }
267         break;
268       }
269       case Toolkit::TextEditor::Property::SCROLL_SPEED:
270       {
271         const float speed = value.Get< float >();
272         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
273
274         if( impl.mDecorator )
275         {
276           impl.mDecorator->SetScrollSpeed( speed );
277         }
278         break;
279       }
280       case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
281       {
282         if( impl.mDecorator )
283         {
284           const Vector4& color = value.Get< Vector4 >();
285           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 );
286
287           impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
288           impl.RequestTextRelayout();
289         }
290         break;
291       }
292       case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
293       {
294         if( impl.mDecorator )
295         {
296           const Vector4& color = value.Get< Vector4 >();
297           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 );
298
299           impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
300           impl.RequestTextRelayout();
301         }
302         break;
303       }
304       case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
305       {
306         if( impl.mController )
307         {
308           const bool enable = value.Get< bool >();
309           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
310
311           impl.mController->SetEnableCursorBlink( enable );
312           impl.RequestTextRelayout();
313         }
314         break;
315       }
316       case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
317       {
318         if( impl.mDecorator )
319         {
320           const float interval = value.Get< float >();
321           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
322
323           impl.mDecorator->SetCursorBlinkInterval( interval );
324         }
325         break;
326       }
327       case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
328       {
329         if( impl.mDecorator )
330         {
331           const float duration = value.Get< float >();
332           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
333
334           impl.mDecorator->SetCursorBlinkDuration( duration );
335         }
336         break;
337       }
338       case Toolkit::TextEditor::Property::CURSOR_WIDTH:
339       {
340         if( impl.mDecorator )
341         {
342           const int width = value.Get< int >();
343           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
344
345           impl.mDecorator->SetCursorWidth( width );
346           impl.mController->GetLayoutEngine().SetCursorWidth( width );
347         }
348         break;
349       }
350       case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
351       {
352         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
353         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
354
355         if( impl.mDecorator )
356         {
357           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
358           impl.RequestTextRelayout();
359         }
360         break;
361       }
362       case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
363       {
364         const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
365         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
366
367         if( impl.mDecorator )
368         {
369           impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
370           impl.RequestTextRelayout();
371         }
372         break;
373       }
374       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
375       {
376         const Image image = Scripting::NewImage( value );
377
378         if( impl.mDecorator && image )
379         {
380           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
381           impl.RequestTextRelayout();
382         }
383         break;
384       }
385       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
386       {
387         const Image image = Scripting::NewImage( value );
388
389         if( impl.mDecorator && image )
390         {
391           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
392           impl.RequestTextRelayout();
393         }
394         break;
395       }
396       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
397       {
398         const Image image = Scripting::NewImage( value );
399
400         if( impl.mDecorator && image )
401         {
402           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
403           impl.RequestTextRelayout();
404         }
405         break;
406       }
407       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
408       {
409         const Image image = Scripting::NewImage( value );
410
411         if( impl.mDecorator && image )
412         {
413           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
414           impl.RequestTextRelayout();
415         }
416         break;
417       }
418       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
419       {
420         const Image image = Scripting::NewImage( value );
421
422         if( impl.mDecorator && image )
423         {
424           impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
425           impl.RequestTextRelayout();
426         }
427         break;
428       }
429       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
430       {
431         const Image image = Scripting::NewImage( value );
432
433         if( impl.mDecorator && image )
434         {
435           impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
436           impl.RequestTextRelayout();
437         }
438         break;
439       }
440       case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
441       {
442         const Vector4 color = value.Get< Vector4 >();
443         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 );
444
445         if( impl.mDecorator )
446         {
447           impl.mDecorator->SetHighlightColor( color );
448           impl.RequestTextRelayout();
449         }
450         break;
451       }
452       case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
453       {
454         if( impl.mDecorator )
455         {
456           const Rect<int>& box = value.Get< Rect<int> >();
457           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 );
458
459           impl.mDecorator->SetBoundingBox( box );
460           impl.RequestTextRelayout();
461         }
462         break;
463       }
464       case Toolkit::TextEditor::Property::ENABLE_MARKUP:
465       {
466         if( impl.mController )
467         {
468           const bool enableMarkup = value.Get<bool>();
469           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
470
471           impl.mController->SetMarkupProcessorEnabled( enableMarkup );
472         }
473         break;
474       }
475       case Toolkit::TextEditor::Property::INPUT_COLOR:
476       {
477         if( impl.mController )
478         {
479           const Vector4& inputColor = value.Get< Vector4 >();
480           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 );
481
482           impl.mController->SetInputColor( inputColor );
483         }
484         break;
485       }
486       case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
487       {
488         if( impl.mController )
489         {
490           const std::string& fontFamily = value.Get< std::string >();
491           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
492           impl.mController->SetInputFontFamily( fontFamily );
493         }
494         break;
495       }
496       case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
497       {
498         SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
499         break;
500       }
501       case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
502       {
503         if( impl.mController )
504         {
505           const float pointSize = value.Get< float >();
506           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
507           impl.mController->SetInputFontPointSize( pointSize );
508         }
509         break;
510       }
511       case Toolkit::TextEditor::Property::LINE_SPACING:
512       {
513         if( impl.mController )
514         {
515
516           // The line spacing isn't supported by the TextEditor. Since it's
517           // supported by the TextEditor for now it must be ignored. The
518           // property is being shadowed locally so its value isn't affected.
519           const float lineSpacing = value.Get<float>();
520           impl.mLineSpacing = lineSpacing;
521           // set it to 0.0 due to missing implementation
522           impl.mController->SetDefaultLineSpacing( 0.0f );
523           impl.mRenderer.Reset();
524         }
525         break;
526       }
527       case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
528       {
529         if( impl.mController )
530         {
531           const float lineSpacing = value.Get<float>();
532           impl.mController->SetInputLineSpacing( lineSpacing );
533           impl.mRenderer.Reset();
534         }
535         break;
536       }
537       case Toolkit::TextEditor::Property::UNDERLINE:
538       {
539         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
540         if( update )
541         {
542           impl.mRenderer.Reset();
543         }
544         break;
545       }
546       case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
547       {
548         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
549         if( update )
550         {
551           impl.mRenderer.Reset();
552         }
553         break;
554       }
555       case Toolkit::TextEditor::Property::SHADOW:
556       {
557         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
558         if( update )
559         {
560           impl.mRenderer.Reset();
561         }
562         break;
563       }
564       case Toolkit::TextEditor::Property::INPUT_SHADOW:
565       {
566         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
567         if( update )
568         {
569           impl.mRenderer.Reset();
570         }
571         break;
572       }
573       case Toolkit::TextEditor::Property::EMBOSS:
574       {
575         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
576         if( update )
577         {
578           impl.mRenderer.Reset();
579         }
580         break;
581       }
582       case Toolkit::TextEditor::Property::INPUT_EMBOSS:
583       {
584         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
585         if( update )
586         {
587           impl.mRenderer.Reset();
588         }
589         break;
590       }
591       case Toolkit::TextEditor::Property::OUTLINE:
592       {
593         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
594         if( update )
595         {
596           impl.mRenderer.Reset();
597         }
598         break;
599       }
600       case Toolkit::TextEditor::Property::INPUT_OUTLINE:
601       {
602         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
603         if( update )
604         {
605           impl.mRenderer.Reset();
606         }
607         break;
608       }
609       case Toolkit::TextEditor::Property::SMOOTH_SCROLL:
610       {
611         const bool enable = value.Get< bool >();
612         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SMOOTH_SCROLL %d\n", enable );
613
614         impl.mScrollAnimationEnabled = enable;
615         break;
616       }
617       case Toolkit::TextEditor::Property::SMOOTH_SCROLL_DURATION:
618       {
619         const float duration = value.Get< float >();
620         DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SMOOTH_SCROLL_DURATION %f\n", duration );
621
622         impl.mScrollAnimationDuration = duration;
623         if ( impl.mTextVerticalScroller )
624         {
625           impl.mTextVerticalScroller->SetDuration( duration );
626         }
627         break;
628       }
629       case Toolkit::TextEditor::Property::ENABLE_SCROLL_BAR:
630       {
631         const bool enable = value.Get< bool >();
632         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SHOW_SCROLL_BAR %d\n", enable );
633
634         impl.mScrollBarEnabled = enable;
635         break;
636       }
637       case Toolkit::TextEditor::Property::SCROLL_BAR_SHOW_DURATION:
638       {
639         const float duration = value.Get< float >();
640         DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SCROLL_BAR_SHOW_DURATION %f\n", duration );
641
642         impl.mAnimationPeriod.delaySeconds = duration;
643         break;
644       }
645       case Toolkit::TextEditor::Property::SCROLL_BAR_FADE_DURATION:
646       {
647         const float duration = value.Get< float >();
648         DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SCROLL_BAR_FADE_DURATION %f\n", duration );
649
650         impl.mAnimationPeriod.durationSeconds = duration;
651         break;
652       }
653       case Toolkit::TextEditor::Property::PIXEL_SIZE:
654       {
655         if( impl.mController )
656         {
657           const float pixelSize = value.Get< float >();
658           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
659
660           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
661           {
662             impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
663           }
664         }
665         break;
666       }
667       case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT:
668       {
669         if( impl.mController )
670         {
671           const std::string& text = value.Get< std::string >();
672           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnPropertySet %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
673
674           impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
675         }
676         break;
677       }
678       case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR:
679       {
680         if( impl.mController )
681         {
682           const Vector4& textColor = value.Get< Vector4 >();
683           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
684
685           if( impl.mController->GetPlaceholderTextColor() != textColor )
686           {
687             impl.mController->SetPlaceholderTextColor( textColor );
688             impl.mRenderer.Reset();
689           }
690         }
691         break;
692       }
693       case Toolkit::TextEditor::Property::ENABLE_SELECTION:
694       {
695         if( impl.mController )
696         {
697           const bool enableSelection = value.Get< bool >();
698           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
699           impl.mController->SetSelectionEnabled( enableSelection );
700         }
701         break;
702       }
703       case Toolkit::TextEditor::Property::PLACEHOLDER:
704       {
705         const Property::Map* map = value.GetMap();
706         if( map )
707         {
708           impl.mController->SetPlaceholderProperty( *map );
709         }
710         break;
711       }
712       case Toolkit::TextEditor::Property::LINE_WRAP_MODE:
713       {
714         if( impl.mController )
715         {
716           Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
717           if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
718           {
719             DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
720             impl.mController->SetLineWrapMode( lineWrapMode );
721           }
722         }
723         break;
724       }
725       case Toolkit::DevelTextEditor::Property::ENABLE_SHIFT_SELECTION:
726       {
727         if( impl.mController )
728         {
729           const bool shiftSelection = value.Get<bool>();
730           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
731
732           impl.mController->SetShiftSelectionEnabled( shiftSelection );
733         }
734         break;
735       }
736       case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE:
737       {
738         if( impl.mController )
739         {
740           const bool grabHandleEnabled = value.Get<bool>();
741           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
742
743           impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
744         }
745         break;
746       }
747     } // switch
748   } // texteditor
749 }
750
751 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
752 {
753   Property::Value value;
754
755   Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
756
757   if( textEditor )
758   {
759     TextEditor& impl( GetImpl( textEditor ) );
760
761     switch( index )
762     {
763       case Toolkit::TextEditor::Property::RENDERING_BACKEND:
764       {
765         value = impl.mRenderingBackend;
766         break;
767       }
768       case Toolkit::TextEditor::Property::TEXT:
769       {
770         if( impl.mController )
771         {
772           std::string text;
773           impl.mController->GetText( text );
774           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
775           value = text;
776         }
777         break;
778       }
779       case Toolkit::TextEditor::Property::TEXT_COLOR:
780       {
781         if ( impl.mController )
782         {
783           value = impl.mController->GetDefaultColor();
784         }
785         break;
786       }
787       case Toolkit::TextEditor::Property::FONT_FAMILY:
788       {
789         if( impl.mController )
790         {
791           value = impl.mController->GetDefaultFontFamily();
792         }
793         break;
794       }
795       case Toolkit::TextEditor::Property::FONT_STYLE:
796       {
797         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
798         break;
799       }
800       case Toolkit::TextEditor::Property::POINT_SIZE:
801       {
802         if( impl.mController )
803         {
804           value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
805         }
806         break;
807       }
808       case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
809       {
810         if( impl.mController )
811         {
812           const char* name = GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
813           if( name )
814           {
815             value = std::string( name );
816           }
817         }
818         break;
819       }
820       case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
821       {
822         if( impl.mDecorator )
823         {
824           value = impl.mDecorator->GetScrollThreshold();
825         }
826         break;
827       }
828       case Toolkit::TextEditor::Property::SCROLL_SPEED:
829       {
830         if( impl.mDecorator )
831         {
832           value = impl.mDecorator->GetScrollSpeed();
833         }
834         break;
835       }
836       case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
837       {
838         if( impl.mDecorator )
839         {
840           value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
841         }
842         break;
843       }
844       case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
845       {
846         if( impl.mDecorator )
847         {
848           value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
849         }
850         break;
851       }
852       case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
853       {
854         value = impl.mController->GetEnableCursorBlink();
855         break;
856       }
857       case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
858       {
859         if( impl.mDecorator )
860         {
861           value = impl.mDecorator->GetCursorBlinkInterval();
862         }
863         break;
864       }
865       case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
866       {
867         if( impl.mDecorator )
868         {
869           value = impl.mDecorator->GetCursorBlinkDuration();
870         }
871         break;
872       }
873       case Toolkit::TextEditor::Property::CURSOR_WIDTH:
874       {
875         if( impl.mDecorator )
876         {
877           value = impl.mDecorator->GetCursorWidth();
878         }
879         break;
880       }
881       case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
882       {
883         if( impl.mDecorator )
884         {
885           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
886           if( image )
887           {
888             value = image.GetUrl();
889           }
890         }
891         break;
892       }
893       case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
894       {
895         if( impl.mDecorator )
896         {
897           ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
898           if( image )
899           {
900             value = image.GetUrl();
901           }
902         }
903         break;
904       }
905       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
906       {
907         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
908         break;
909       }
910       case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
911       {
912         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
913         break;
914       }
915       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
916       {
917         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
918         break;
919       }
920       case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
921       {
922         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
923         break;
924       }
925       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
926       {
927         impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
928         break;
929       }
930       case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
931       {
932         impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
933         break;
934       }
935       case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
936       {
937         if( impl.mDecorator )
938         {
939           value = impl.mDecorator->GetHighlightColor();
940         }
941         break;
942       }
943       case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
944       {
945         if( impl.mDecorator )
946         {
947           Rect<int> boundingBox;
948           impl.mDecorator->GetBoundingBox( boundingBox );
949           value = boundingBox;
950         }
951         break;
952       }
953       case Toolkit::TextEditor::Property::ENABLE_MARKUP:
954       {
955         if( impl.mController )
956         {
957           value = impl.mController->IsMarkupProcessorEnabled();
958         }
959         break;
960       }
961       case Toolkit::TextEditor::Property::INPUT_COLOR:
962       {
963         if( impl.mController )
964         {
965           value = impl.mController->GetInputColor();
966         }
967         break;
968       }
969       case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
970       {
971         if( impl.mController )
972         {
973           value = impl.mController->GetInputFontFamily();
974         }
975         break;
976       }
977       case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
978       {
979         GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
980         break;
981       }
982       case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
983       {
984         if( impl.mController )
985         {
986           value = impl.mController->GetInputFontPointSize();
987         }
988         break;
989       }
990       case Toolkit::TextEditor::Property::LINE_SPACING:
991       {
992         if( impl.mController )
993         {
994           // LINE_SPACING isn't implemented for the TextEditor. Returning
995           // only shadowed value, not the real one.
996           value = impl.mLineSpacing;
997         }
998         break;
999       }
1000       case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
1001       {
1002         if( impl.mController )
1003         {
1004           value = impl.mController->GetInputLineSpacing();
1005         }
1006         break;
1007       }
1008       case Toolkit::TextEditor::Property::UNDERLINE:
1009       {
1010         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1011         break;
1012       }
1013       case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
1014       {
1015         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1016         break;
1017       }
1018       case Toolkit::TextEditor::Property::SHADOW:
1019       {
1020         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1021         break;
1022       }
1023       case Toolkit::TextEditor::Property::INPUT_SHADOW:
1024       {
1025         GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1026         break;
1027       }
1028       case Toolkit::TextEditor::Property::EMBOSS:
1029       {
1030         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1031         break;
1032       }
1033       case Toolkit::TextEditor::Property::INPUT_EMBOSS:
1034       {
1035         GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1036         break;
1037       }
1038       case Toolkit::TextEditor::Property::OUTLINE:
1039       {
1040         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1041         break;
1042       }
1043       case Toolkit::TextEditor::Property::INPUT_OUTLINE:
1044       {
1045         GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1046         break;
1047       }
1048       case Toolkit::TextEditor::Property::SMOOTH_SCROLL:
1049       {
1050         value = impl.mScrollAnimationEnabled;
1051         break;
1052       }
1053       case Toolkit::TextEditor::Property::SMOOTH_SCROLL_DURATION:
1054       {
1055         value = impl.mScrollAnimationDuration;
1056         break;
1057       }
1058       case Toolkit::TextEditor::Property::ENABLE_SCROLL_BAR:
1059       {
1060         value = impl.mScrollBarEnabled;
1061         break;
1062       }
1063       case Toolkit::TextEditor::Property::SCROLL_BAR_SHOW_DURATION:
1064       {
1065         value = impl.mAnimationPeriod.delaySeconds;
1066         break;
1067       }
1068       case Toolkit::TextEditor::Property::SCROLL_BAR_FADE_DURATION:
1069       {
1070         value = impl.mAnimationPeriod.durationSeconds;
1071         break;
1072       }
1073       case Toolkit::TextEditor::Property::PIXEL_SIZE:
1074       {
1075         if( impl.mController )
1076         {
1077           value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1078         }
1079         break;
1080       }
1081       case Toolkit::TextEditor::Property::LINE_COUNT:
1082       {
1083         if( impl.mController )
1084         {
1085           float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
1086           value = impl.mController->GetLineCount( width );
1087         }
1088         break;
1089       }
1090       case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT:
1091       {
1092         if( impl.mController )
1093         {
1094           std::string text;
1095           impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1096           value = text;
1097         }
1098         break;
1099       }
1100       case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR:
1101       {
1102         if( impl.mController )
1103         {
1104           value = impl.mController->GetPlaceholderTextColor();
1105         }
1106         break;
1107       }
1108       case Toolkit::TextEditor::Property::ENABLE_SELECTION:
1109       {
1110         if( impl.mController )
1111         {
1112           value = impl.mController->IsSelectionEnabled();
1113         }
1114         break;
1115       }
1116       case Toolkit::TextEditor::Property::PLACEHOLDER:
1117       {
1118         Property::Map map;
1119         impl.mController->GetPlaceholderProperty( map );
1120         value = map;
1121         break;
1122       }
1123       case Toolkit::TextEditor::Property::LINE_WRAP_MODE:
1124       {
1125         if( impl.mController )
1126         {
1127           value = impl.mController->GetLineWrapMode();
1128         }
1129         break;
1130       }
1131       case Toolkit::DevelTextEditor::Property::ENABLE_SHIFT_SELECTION:
1132       {
1133         if( impl.mController )
1134         {
1135           value = impl.mController->IsShiftSelectionEnabled();
1136         }
1137         break;
1138       }
1139       case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE:
1140       {
1141         if( impl.mController )
1142         {
1143           value = impl.mController->IsGrabHandleEnabled();
1144         }
1145         break;
1146       }
1147     } //switch
1148   }
1149
1150   return value;
1151 }
1152
1153 Text::ControllerPtr TextEditor::getController() { return mController; }
1154
1155 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1156 {
1157   Dali::BaseHandle handle( object );
1158
1159   bool connected( true );
1160   Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
1161
1162   if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1163   {
1164     editor.TextChangedSignal().Connect( tracker, functor );
1165   }
1166   else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1167   {
1168     editor.InputStyleChangedSignal().Connect( tracker, functor );
1169   }
1170   else
1171   {
1172     // signalName does not match any signal
1173     connected = false;
1174   }
1175
1176   return connected;
1177 }
1178
1179 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
1180 {
1181   return mTextChangedSignal;
1182 }
1183
1184 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
1185 {
1186   return mInputStyleChangedSignal;
1187 }
1188
1189 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
1190 {
1191   return mScrollStateChangedSignal;
1192 }
1193
1194 void TextEditor::OnInitialize()
1195 {
1196   Actor self = Self();
1197
1198   mController = Text::Controller::New( this, this );
1199
1200   mDecorator = Text::Decorator::New( *mController,
1201                                      *mController );
1202
1203   mController->GetLayoutEngine().SetLayout( Layout::Engine::MULTI_LINE_BOX );
1204
1205   // Enables the text input.
1206   mController->EnableTextInput( mDecorator );
1207
1208   // Enables the vertical scrolling after the text input has been enabled.
1209   mController->SetVerticalScrollEnabled( true );
1210
1211   // Disables the horizontal scrolling.
1212   mController->SetHorizontalScrollEnabled( false );
1213
1214   // Sets the maximum number of characters.
1215   mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
1216
1217   // Enable the smooth handle panning.
1218   mController->SetSmoothHandlePanEnabled( true );
1219
1220   mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1221   mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1222
1223   // Forward input events to controller
1224   EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1225   GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1226
1227   mImfManager = ImfManager::Get();
1228
1229   self.TouchSignal().Connect( this, &TextEditor::OnTouched );
1230
1231   // Set BoundingBox to stage size if not already set.
1232   Rect<int> boundingBox;
1233   mDecorator->GetBoundingBox( boundingBox );
1234
1235   if( boundingBox.IsEmpty() )
1236   {
1237     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1238     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1239   }
1240
1241   // Whether to flip the selection handles as soon as they cross.
1242   mDecorator->FlipSelectionHandlesOnCrossEnabled( true );
1243
1244   // Set the default scroll speed.
1245   mDecorator->SetScrollSpeed( DEFAULT_SCROLL_SPEED );
1246
1247   // Fill-parent area by default
1248   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1249   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1250   self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
1251
1252   // Creates an extra control to be used as stencil buffer.
1253   mStencil = Control::New();
1254   mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1255   mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1256
1257   // Creates a background visual. Even if the color is transparent it updates the stencil.
1258   mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1259                         Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1260                         Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1261
1262   // Enable the clipping property.
1263   mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1264   mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1265
1266   self.Add( mStencil );
1267 }
1268
1269 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1270 {
1271   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
1272
1273   switch ( change )
1274   {
1275     case StyleChange::DEFAULT_FONT_CHANGE:
1276     {
1277       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
1278       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1279       // Property system did not set the font so should update it.
1280       mController->UpdateAfterFontChange( newFont );
1281       RelayoutRequest();
1282       break;
1283     }
1284
1285     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1286     {
1287       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1288       RelayoutRequest();
1289       break;
1290     }
1291     case StyleChange::THEME_CHANGE:
1292     {
1293       // Nothing to do, let control base class handle this
1294       break;
1295     }
1296   }
1297
1298   // Up call to Control
1299   Control::OnStyleChange( styleManager, change );
1300 }
1301
1302 Vector3 TextEditor::GetNaturalSize()
1303 {
1304   Extents padding;
1305   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1306
1307   Vector3 naturalSize = mController->GetNaturalSize();
1308   naturalSize.width += ( padding.start + padding.end );
1309   naturalSize.height += ( padding.top + padding.bottom );
1310
1311   return naturalSize;
1312 }
1313
1314 float TextEditor::GetHeightForWidth( float width )
1315 {
1316   Extents padding;
1317   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1318   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1319 }
1320
1321 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
1322 {
1323   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
1324
1325   Actor self = Self();
1326
1327   Extents padding;
1328   padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1329
1330   Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1331
1332   // Support Right-To-Left of padding
1333   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1334   if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1335   {
1336     std::swap( padding.start, padding.end );
1337   }
1338
1339   if( mStencil )
1340   {
1341     mStencil.SetPosition( padding.start, padding.top );
1342   }
1343   if( mActiveLayer )
1344   {
1345     mActiveLayer.SetPosition( padding.start, padding.top );
1346   }
1347
1348   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1349
1350   if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1351       !mRenderer )
1352   {
1353     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
1354
1355     if( mDecorator &&
1356         ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1357     {
1358       mDecorator->Relayout( size );
1359     }
1360
1361     if( !mRenderer )
1362     {
1363       mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1364     }
1365
1366     RenderText( updateTextType );
1367
1368   }
1369
1370   // The text-editor emits signals when the input style changes. These changes of style are
1371   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1372   // can't be emitted during the size negotiation as the callbacks may update the UI.
1373   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1374   if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1375   {
1376     if( Adaptor::IsAvailable() )
1377     {
1378       Adaptor& adaptor = Adaptor::Get();
1379
1380       if( NULL == mIdleCallback )
1381       {
1382         // @note: The callback manager takes the ownership of the callback object.
1383         mIdleCallback = MakeCallback( this, &TextEditor::OnIdleSignal );
1384         adaptor.AddIdle( mIdleCallback );
1385       }
1386     }
1387   }
1388 }
1389
1390 void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
1391 {
1392   Actor renderableActor;
1393
1394   if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1395   {
1396     if( mRenderer )
1397     {
1398       Dali::Toolkit::TextEditor handle = Dali::Toolkit::TextEditor( GetOwner() );
1399
1400       renderableActor = mRenderer->Render( mController->GetView(),
1401                                            handle,
1402                                            Property::INVALID_INDEX, // Animatable property not supported
1403                                            mAlignmentOffset,
1404                                            DepthIndex::CONTENT );
1405     }
1406
1407     if( renderableActor != mRenderableActor )
1408     {
1409       UnparentAndReset( mRenderableActor );
1410       mRenderableActor = renderableActor;
1411     }
1412   }
1413
1414   if( mRenderableActor )
1415   {
1416     // Make sure the actors are parented correctly with/without clipping
1417     Actor self = mStencil ? mStencil : Self();
1418
1419     for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1420            endIt = mClippingDecorationActors.end();
1421          it != endIt;
1422          ++it )
1423     {
1424       self.Add( *it );
1425       it->LowerToBottom();
1426     }
1427     mClippingDecorationActors.clear();
1428
1429     self.Add( mRenderableActor );
1430
1431     ApplyScrollPosition();
1432   }
1433   UpdateScrollBar();
1434 }
1435
1436 void TextEditor::OnKeyInputFocusGained()
1437 {
1438   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
1439
1440   mImfManager.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
1441
1442   mImfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
1443
1444   // Notify that the text editing start.
1445   mImfManager.Activate();
1446
1447   // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1448   mImfManager.SetRestoreAfterFocusLost( true );
1449
1450    ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1451
1452    if ( notifier )
1453    {
1454       notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
1455    }
1456
1457   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1458
1459   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1460 }
1461
1462 void TextEditor::OnKeyInputFocusLost()
1463 {
1464   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
1465
1466   mImfManager.StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
1467
1468   // The text editing is finished. Therefore the imf manager don't have restore activation.
1469   mImfManager.SetRestoreAfterFocusLost( false );
1470
1471   // Notify that the text editing finish.
1472   mImfManager.Deactivate();
1473
1474   mImfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
1475
1476   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1477
1478   if ( notifier )
1479   {
1480     notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
1481   }
1482
1483   mController->KeyboardFocusLostEvent();
1484
1485   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1486 }
1487
1488 void TextEditor::OnTap( const TapGesture& gesture )
1489 {
1490   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
1491
1492   mImfManager.Activate();
1493
1494   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1495   Extents padding;
1496   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1497   mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1498
1499   SetKeyInputFocus();
1500 }
1501
1502 void TextEditor::OnPan( const PanGesture& gesture )
1503 {
1504   mController->PanEvent( gesture.state, gesture.displacement );
1505 }
1506
1507 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1508 {
1509   mImfManager.Activate();
1510
1511   Extents padding;
1512   padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1513   mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1514
1515   SetKeyInputFocus();
1516 }
1517
1518 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1519 {
1520   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1521
1522   if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1523   {
1524     // Make sure ClearKeyInputFocus when only key is up
1525     if( event.state == KeyEvent::Up )
1526     {
1527       ClearKeyInputFocus();
1528     }
1529
1530     return true;
1531   }
1532
1533   return mController->KeyEvent( event );
1534 }
1535
1536 void TextEditor::RequestTextRelayout()
1537 {
1538   RelayoutRequest();
1539 }
1540
1541 void TextEditor::TextChanged()
1542 {
1543   Dali::Toolkit::TextEditor handle( GetOwner() );
1544   mTextChangedSignal.Emit( handle );
1545 }
1546
1547 void TextEditor::MaxLengthReached()
1548 {
1549   // Nothing to do as TextEditor doesn't emit a max length reached signal.
1550 }
1551
1552 void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1553 {
1554   Dali::Toolkit::TextEditor handle( GetOwner() );
1555
1556   Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
1557
1558   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1559   {
1560     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR );
1561   }
1562   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1563   {
1564     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY );
1565   }
1566   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1567   {
1568     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE );
1569   }
1570   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1571   {
1572     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1573   }
1574   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1575   {
1576     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1577   }
1578   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1579   {
1580     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1581   }
1582   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_LINE_SPACING ) )
1583   {
1584     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING );
1585   }
1586   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1587   {
1588     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE );
1589   }
1590   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1591   {
1592     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW );
1593   }
1594   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1595   {
1596     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS );
1597   }
1598   if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1599   {
1600     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE );
1601   }
1602
1603   mInputStyleChangedSignal.Emit( handle, editorInputStyleMask );
1604 }
1605
1606 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1607 {
1608   if( actor )
1609   {
1610     if( needsClipping )
1611     {
1612       mClippingDecorationActors.push_back( actor );
1613     }
1614     else
1615     {
1616       actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1617       actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1618       Self().Add( actor );
1619       mActiveLayer = actor;
1620     }
1621   }
1622 }
1623
1624 void TextEditor::UpdateScrollBar()
1625 {
1626   using namespace Dali;
1627
1628   float scrollPosition;
1629   float controlSize;
1630   float layoutSize;
1631   bool latestScrolled;
1632
1633   if ( !mScrollBarEnabled )
1634   {
1635     return;
1636   }
1637   latestScrolled = mController->GetTextScrollInfo( scrollPosition, controlSize, layoutSize );
1638   if ( !latestScrolled || controlSize > layoutSize)
1639   {
1640     return;
1641   }
1642
1643   CustomActor self = Self();
1644   if( !mScrollBar )
1645   {
1646     mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::Vertical );
1647     mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::Variable );
1648     mScrollBar.SetParentOrigin( ParentOrigin::TOP_RIGHT );
1649     mScrollBar.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
1650     mScrollBar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1651     mScrollBar.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
1652
1653     // Register the scroll position property
1654     Property::Index propertyScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION, scrollPosition );
1655     // Register the minimum scroll position property
1656     Property::Index propertyMinScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MIN, 0.0f );
1657     // Register the maximum scroll position property
1658     Property::Index propertyMaxScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize) );
1659     // Register the scroll content size property
1660     Property::Index propertyScrollContentSize = self.RegisterProperty( SCROLL_BAR_CONTENT_SIZE, layoutSize );
1661
1662     mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1663
1664     // Set style name of ScrollBar for styling
1665     mScrollBar.SetStyleName("TextEditorScrollBar");
1666     Toolkit::Control scrollIndicator = Toolkit::Control::DownCast( mScrollBar.GetScrollIndicator() );
1667     if( scrollIndicator )
1668     {
1669       // Set style name of ScrollBarIndicator for styling
1670       scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1671     }
1672
1673     self.Add( mScrollBar );
1674   }
1675   else
1676   {
1677     Property::Index propertyScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION );
1678     Property::Index propertyMaxScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION_MAX );
1679     Property::Index propertyScrollContentSize = self.GetPropertyIndex( SCROLL_BAR_CONTENT_SIZE );
1680
1681     self.SetProperty( propertyScrollPosition, scrollPosition );
1682     self.SetProperty( propertyMaxScrollPosition, (layoutSize - controlSize) );
1683     self.SetProperty( propertyScrollContentSize, layoutSize );
1684   }
1685
1686   // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1687   if( !mScrollStarted )
1688   {
1689     mScrollStarted = true;
1690     Dali::Toolkit::TextEditor handle( GetOwner() );
1691     mScrollStateChangedSignal.Emit( handle, Toolkit::TextEditor::Scroll::STARTED );
1692   }
1693
1694   Actor indicator = mScrollBar.GetScrollIndicator();
1695   if( mAnimation )
1696   {
1697     mAnimation.Stop(); // Cancel any animation
1698   }
1699   else
1700   {
1701     mAnimation = Animation::New( mAnimationPeriod.durationSeconds );
1702   }
1703   indicator.SetOpacity(1.0f);
1704   mAnimation.AnimateTo( Property( indicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod );
1705   mAnimation.Play();
1706   mAnimation.FinishedSignal().Connect( this, &TextEditor::OnScrollIndicatorAnimationFinished );
1707 }
1708
1709 void TextEditor::OnScrollIndicatorAnimationFinished( Animation& animation )
1710 {
1711   // If animation is successfully ended, then emit ScrollStateChangedSignal
1712   if( animation.GetCurrentProgress() == 0.0f )
1713   {
1714     mScrollStarted = false;
1715     Dali::Toolkit::TextEditor handle( GetOwner() );
1716     mScrollStateChangedSignal.Emit( handle, Toolkit::TextEditor::Scroll::FINISHED );
1717   }
1718 }
1719
1720 void TextEditor::OnStageConnect( Dali::Actor actor )
1721 {
1722   if ( mHasBeenStaged )
1723   {
1724     RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1725   }
1726   else
1727   {
1728     mHasBeenStaged = true;
1729   }
1730 }
1731
1732 ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1733 {
1734   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1735   return mController->OnImfEvent( imfManager, imfEvent );
1736 }
1737
1738 void TextEditor::GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1739 {
1740   if( mDecorator )
1741   {
1742     ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1743
1744     if ( image )
1745     {
1746       Property::Map map;
1747       Scripting::CreatePropertyMap( image, map );
1748       value = map;
1749     }
1750   }
1751 }
1752
1753 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1754 {
1755   mController->PasteClipboardItemEvent();
1756 }
1757
1758 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1759 {
1760   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1761
1762   // Just hide the grab handle when keyboard is hidden.
1763   if (!keyboardShown )
1764   {
1765     mController->KeyboardFocusLostEvent();
1766   }
1767   else
1768   {
1769     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1770   }
1771 }
1772
1773 void TextEditor::OnStageConnection( int depth )
1774 {
1775   // Sets the depth to the visuals inside the text's decorator.
1776   mDecorator->SetTextDepth( depth );
1777
1778   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1779
1780   // Call the Control::OnStageConnection() to set the depth of the background.
1781   Control::OnStageConnection( depth );
1782 }
1783
1784 bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
1785 {
1786   return true;
1787 }
1788
1789 void TextEditor::OnIdleSignal()
1790 {
1791   // Emits the change of input style signals.
1792   mController->ProcessInputStyleChangedSignals();
1793
1794   // Set the pointer to null as the callback manager deletes the callback after execute it.
1795   mIdleCallback = NULL;
1796 }
1797
1798 void TextEditor::ApplyScrollPosition()
1799 {
1800   const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1801   float scrollAmount = 0.0f;
1802
1803   if ( mScrollAnimationEnabled )
1804   {
1805     scrollAmount = mController->GetScrollAmountByUserInput();
1806   }
1807   if ( mTextVerticalScroller )
1808   {
1809     mTextVerticalScroller->CheckStartAnimation( mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount );
1810   }
1811   else if ( Equals( scrollAmount, 0.0f, Math::MACHINE_EPSILON_1 ))
1812   {
1813     mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount );
1814   }
1815   else
1816   {
1817     mTextVerticalScroller = Text::TextVerticalScroller::New();
1818     if ( !Equals( mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1 ))
1819     {
1820       mTextVerticalScroller->SetDuration( mScrollAnimationDuration );
1821     }
1822     mTextVerticalScroller->CheckStartAnimation( mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount );
1823   }
1824 }
1825
1826 TextEditor::TextEditor()
1827 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1828   mAnimationPeriod( 0.0f, 0.0f ),
1829   mIdleCallback( NULL ),
1830   mAlignmentOffset( 0.f ),
1831   mScrollAnimationDuration( 0.f ),
1832   mLineSpacing( 0.f ),
1833   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1834   mHasBeenStaged( false ),
1835   mScrollAnimationEnabled( false ),
1836   mScrollBarEnabled( false ),
1837   mScrollStarted( false )
1838 {
1839   SetAccessibilityConstructor( []( Dali::Actor actor ) {
1840     return std::unique_ptr< Dali::Accessibility::Accessible >(
1841         new AccessibleImpl( actor, Dali::Accessibility::Role::Text ) );
1842   } );
1843 }
1844
1845 TextEditor::~TextEditor()
1846 {
1847   UnparentAndReset( mStencil );
1848
1849   if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1850   {
1851     // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1852     Adaptor::Get().RemoveIdle( mIdleCallback );
1853   }
1854 }
1855
1856 std::string TextEditor::AccessibleImpl::GetName()
1857 {
1858   auto slf = Toolkit::TextEditor::DownCast( self );
1859   return slf.GetProperty( Toolkit::TextEditor::Property::TEXT )
1860       .Get< std::string >();
1861 }
1862
1863 std::string TextEditor::AccessibleImpl::GetText( size_t startOffset,
1864                                                  size_t endOffset )
1865 {
1866   if( endOffset <= startOffset )
1867     return {};
1868
1869   auto slf = Toolkit::TextEditor::DownCast( self );
1870   auto txt =
1871       slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >();
1872
1873   if( txt.size() > startOffset || txt.size() > endOffset )
1874     return {};
1875
1876   return txt.substr( startOffset, endOffset - startOffset );
1877 }
1878
1879 size_t TextEditor::AccessibleImpl::GetCharacterCount()
1880 {
1881   auto slf = Toolkit::TextEditor::DownCast( self );
1882   auto txt =
1883       slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >();
1884
1885   return txt.size();
1886 }
1887
1888 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(
1889     size_t offset, Dali::Accessibility::TextBoundary boundary )
1890 {
1891   return {};
1892 }
1893
1894 Dali::Accessibility::Range
1895 TextEditor::AccessibleImpl::GetSelection( size_t selectionNum )
1896 {
1897   // Since DALi supports only one selection indexes higher than 0 are ignored
1898   if( selectionNum > 0 )
1899     return {};
1900
1901   auto slf = Toolkit::TextEditor::DownCast( self );
1902   std::string ret;
1903   Dali::Toolkit::GetImpl( slf ).getController()->RetrieveSelection( ret );
1904
1905   return Dali::Accessibility::Range( 0, ret.size(), ret );
1906 }
1907
1908 bool TextEditor::AccessibleImpl::RemoveSelection( size_t selectionNum )
1909 {
1910   // Since DALi supports only one selection indexes higher than 0 are ignored
1911   if( selectionNum > 0 )
1912     return false;
1913
1914   auto slf = Toolkit::TextEditor::DownCast( self );
1915   std::string ret;
1916   Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
1917   return true;
1918 }
1919
1920 bool TextEditor::AccessibleImpl::SetSelection( size_t selectionNum,
1921                                                size_t startOffset,
1922                                                size_t endOffset )
1923 {
1924   // Since DALi supports only one selection indexes higher than 0 are ignored
1925   if( selectionNum > 0 )
1926     return false;
1927
1928   auto slf = Toolkit::TextEditor::DownCast( self );
1929   std::string ret;
1930   Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
1931                                                                endOffset );
1932   return true;
1933 }
1934
1935 bool TextEditor::AccessibleImpl::CopyText( size_t startPosition,
1936                                            size_t endPosition )
1937 {
1938   return {};
1939 }
1940
1941 bool TextEditor::AccessibleImpl::CutText( size_t startPosition,
1942                                           size_t endPosition )
1943 {
1944   return {};
1945 }
1946
1947 } // namespace Internal
1948
1949 } // namespace Toolkit
1950
1951 } // namespace Dali