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