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