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