2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
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>
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/controls/control/control-data-impl.h>
42 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/rendering/text-backend.h>
45 #include <dali-toolkit/internal/text/text-effects-style.h>
46 #include <dali-toolkit/internal/text/text-font-style.h>
47 #include <dali-toolkit/internal/text/text-view.h>
48 #include <dali-toolkit/internal/styling/style-manager-impl.h>
49 #include <dali-toolkit/devel-api/controls/control-devel.h>
50 #include <dali/integration-api/adaptor-framework/adaptor.h>
52 using namespace Dali::Toolkit::Text;
63 namespace // unnamed namespace
66 #if defined(DEBUG_ENABLED)
67 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
70 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
71 } // unnamed namespace
78 return Toolkit::TextField::New();
81 // Setup properties, signals and actions using the type-registry.
82 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
143 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
144 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
146 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
147 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
148 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
150 DALI_TYPE_REGISTRATION_END()
152 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
154 /// Retrieves a filename from a value that is a Property::Map
155 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
157 std::string filename;
158 const Property::Map* map = value.GetMap();
161 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
164 filenameValue->Get( filename );
172 Toolkit::TextField TextField::New()
174 // Create the implementation, temporarily owned by this handle on stack
175 IntrusivePtr< TextField > impl = new TextField();
177 // Pass ownership to CustomActor handle
178 Toolkit::TextField handle( *impl );
180 // Second-phase init of the implementation
181 // This can only be done after the CustomActor connection has been made...
187 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
189 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
191 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
195 TextField& impl( GetImpl( textField ) );
196 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
197 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
201 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
203 int backend = value.Get< int >();
204 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
206 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
207 if( DevelText::RENDERING_VECTOR_BASED == backend )
209 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
212 if( impl.mRenderingBackend != backend )
214 impl.mRenderingBackend = backend;
215 impl.mRenderer.Reset();
217 // When using the vector-based rendering, the size of the GLyphs are different
218 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
219 impl.mController->SetGlyphType( glyphType );
223 case Toolkit::TextField::Property::TEXT:
225 const std::string& text = value.Get< std::string >();
226 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
228 impl.mController->SetText( text );
231 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
233 const std::string& text = value.Get< std::string >();
234 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
236 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
239 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
241 const std::string& text = value.Get< std::string >();
242 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
244 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
247 case Toolkit::TextField::Property::FONT_FAMILY:
249 const std::string& fontFamily = value.Get< std::string >();
250 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
251 impl.mController->SetDefaultFontFamily( fontFamily );
254 case Toolkit::TextField::Property::FONT_STYLE:
256 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
259 case Toolkit::TextField::Property::POINT_SIZE:
261 const float pointSize = value.Get< float >();
262 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
264 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
266 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
270 case Toolkit::TextField::Property::MAX_LENGTH:
272 const int max = value.Get< int >();
273 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
275 impl.mController->SetMaximumNumberOfCharacters( max );
278 case Toolkit::TextField::Property::EXCEED_POLICY:
280 impl.mExceedPolicy = value.Get<int>();
282 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
284 impl.EnableClipping();
288 UnparentAndReset( impl.mStencil );
290 impl.RequestTextRelayout();
293 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
295 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
296 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
298 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
299 impl.mController->SetHorizontalAlignment( alignment );
303 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
305 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
306 if( GetVerticalAlignmentEnumeration( value, alignment ) )
308 impl.mController->SetVerticalAlignment( alignment );
309 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
313 case Toolkit::TextField::Property::TEXT_COLOR:
315 const Vector4& textColor = value.Get< Vector4 >();
316 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 );
318 if( impl.mController->GetDefaultColor() != textColor )
320 impl.mController->SetDefaultColor( textColor );
321 impl.mController->SetInputColor( textColor );
322 impl.mRenderer.Reset();
326 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
328 const Vector4& textColor = value.Get< Vector4 >();
329 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 );
331 if( impl.mController->GetPlaceholderTextColor() != textColor )
333 impl.mController->SetPlaceholderTextColor( textColor );
334 impl.mRenderer.Reset();
338 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
340 const Vector4& color = value.Get< Vector4 >();
341 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 );
343 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
344 impl.RequestTextRelayout();
347 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
349 const Vector4& color = value.Get< Vector4 >();
350 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 );
352 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
353 impl.RequestTextRelayout();
356 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
358 const bool enable = value.Get< bool >();
359 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
361 impl.mController->SetEnableCursorBlink( enable );
362 impl.RequestTextRelayout();
365 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
367 const float interval = value.Get< float >();
368 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
370 impl.mDecorator->SetCursorBlinkInterval( interval );
373 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
375 const float duration = value.Get< float >();
376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
378 impl.mDecorator->SetCursorBlinkDuration( duration );
381 case Toolkit::TextField::Property::CURSOR_WIDTH:
383 const int width = value.Get< int >();
384 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
386 impl.mDecorator->SetCursorWidth( width );
387 impl.mController->GetLayoutEngine().SetCursorWidth( width );
390 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
392 const std::string imageFileName = value.Get< std::string >();
393 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
395 if( imageFileName.size() )
397 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
398 impl.RequestTextRelayout();
402 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
404 const std::string imageFileName = value.Get< std::string >();
405 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
407 if( imageFileName.size() )
409 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
410 impl.RequestTextRelayout();
414 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
416 const float threshold = value.Get< float >();
417 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
419 impl.mDecorator->SetScrollThreshold( threshold );
422 case Toolkit::TextField::Property::SCROLL_SPEED:
424 const float speed = value.Get< float >();
425 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
427 impl.mDecorator->SetScrollSpeed( speed );
430 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
432 const std::string filename = GetImageFileNameFromPropertyValue( value );
434 if( filename.size() )
436 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
437 impl.RequestTextRelayout();
441 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
443 const std::string filename = GetImageFileNameFromPropertyValue( value );
445 if( filename.size() )
447 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
448 impl.RequestTextRelayout();
452 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
454 const std::string filename = GetImageFileNameFromPropertyValue( value );
456 if( filename.size() )
458 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
459 impl.RequestTextRelayout();
463 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
465 const std::string filename = GetImageFileNameFromPropertyValue( value );
467 if( filename.size() )
469 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
470 impl.RequestTextRelayout();
474 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
476 const std::string filename = GetImageFileNameFromPropertyValue( value );
478 if( filename.size() )
480 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
487 const std::string filename = GetImageFileNameFromPropertyValue( value );
489 if( filename.size() )
491 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
498 const Vector4 color = value.Get< Vector4 >();
499 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 );
501 impl.mDecorator->SetHighlightColor( color );
502 impl.RequestTextRelayout();
505 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
507 const Rect<int> box = value.Get< Rect<int> >();
508 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 );
510 impl.mDecorator->SetBoundingBox( box );
511 impl.RequestTextRelayout();
514 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
516 const Property::Map* map = value.GetMap();
519 impl.mInputMethodOptions.ApplyProperty( *map );
521 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
523 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
524 if (control == textField)
526 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
530 case Toolkit::TextField::Property::INPUT_COLOR:
532 const Vector4 inputColor = value.Get< Vector4 >();
533 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 );
535 impl.mController->SetInputColor( inputColor );
538 case Toolkit::TextField::Property::ENABLE_MARKUP:
540 const bool enableMarkup = value.Get<bool>();
541 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
543 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
546 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
548 const std::string& fontFamily = value.Get< std::string >();
549 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
550 impl.mController->SetInputFontFamily( fontFamily );
553 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
555 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
558 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
560 const float pointSize = value.Get< float >();
561 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
562 impl.mController->SetInputFontPointSize( pointSize );
565 case Toolkit::TextField::Property::UNDERLINE:
567 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
570 impl.mRenderer.Reset();
574 case Toolkit::TextField::Property::INPUT_UNDERLINE:
576 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
579 impl.mRenderer.Reset();
583 case Toolkit::TextField::Property::SHADOW:
585 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
588 impl.mRenderer.Reset();
592 case Toolkit::TextField::Property::INPUT_SHADOW:
594 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
597 impl.mRenderer.Reset();
601 case Toolkit::TextField::Property::EMBOSS:
603 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
606 impl.mRenderer.Reset();
610 case Toolkit::TextField::Property::INPUT_EMBOSS:
612 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
615 impl.mRenderer.Reset();
619 case Toolkit::TextField::Property::OUTLINE:
621 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
624 impl.mRenderer.Reset();
628 case Toolkit::TextField::Property::INPUT_OUTLINE:
630 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
633 impl.mRenderer.Reset();
637 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
639 const Property::Map* map = value.GetMap();
642 impl.mController->SetHiddenInputOption(*map);
646 case Toolkit::TextField::Property::PIXEL_SIZE:
648 const float pixelSize = value.Get< float >();
649 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
651 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
653 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
657 case Toolkit::TextField::Property::ENABLE_SELECTION:
659 const bool enableSelection = value.Get< bool >();
660 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
661 impl.mController->SetSelectionEnabled( enableSelection );
664 case Toolkit::TextField::Property::PLACEHOLDER:
666 const Property::Map* map = value.GetMap();
669 impl.mController->SetPlaceholderProperty( *map );
673 case Toolkit::TextField::Property::ELLIPSIS:
675 const bool ellipsis = value.Get<bool>();
676 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
678 impl.mController->SetTextElideEnabled( ellipsis );
681 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
683 const bool shiftSelection = value.Get<bool>();
684 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
686 impl.mController->SetShiftSelectionEnabled( shiftSelection );
689 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
691 const bool grabHandleEnabled = value.Get<bool>();
692 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
694 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
697 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
699 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
702 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
704 const bool grabHandlePopupEnabled = value.Get<bool>();
705 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
707 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
710 case Toolkit::DevelTextField::Property::BACKGROUND:
712 const Vector4 backgroundColor = value.Get< Vector4 >();
713 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 );
715 impl.mController->SetBackgroundEnabled( true );
716 impl.mController->SetBackgroundColor( backgroundColor );
719 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
721 uint32_t start = static_cast<uint32_t>(value.Get< int >());
722 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
723 impl.SetTextSelectionRange( &start, nullptr );
726 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
728 uint32_t end = static_cast<uint32_t>(value.Get< int >());
729 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
730 impl.SetTextSelectionRange( nullptr, &end );
733 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
735 const bool editable = value.Get< bool >();
736 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
737 impl.SetEditable( editable );
740 case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
742 const float scale = value.Get< float >();
743 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale );
745 if( !Equals( impl.mController->GetFontSizeScale(), scale ) )
747 impl.mController->SetFontSizeScale( scale );
751 case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
753 uint32_t position = static_cast<uint32_t>(value.Get< int >());
754 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position );
755 if (impl.mController->SetPrimaryCursorPosition( position ))
757 impl.SetKeyInputFocus();
765 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
767 Property::Value value;
769 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
773 TextField& impl( GetImpl( textField ) );
774 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
775 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
779 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
781 value = impl.mRenderingBackend;
784 case Toolkit::TextField::Property::TEXT:
787 impl.mController->GetText( text );
788 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
792 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
795 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
799 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
802 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
806 case Toolkit::TextField::Property::FONT_FAMILY:
808 value = impl.mController->GetDefaultFontFamily();
811 case Toolkit::TextField::Property::FONT_STYLE:
813 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
816 case Toolkit::TextField::Property::POINT_SIZE:
818 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
821 case Toolkit::TextField::Property::MAX_LENGTH:
823 value = impl.mController->GetMaximumNumberOfCharacters();
826 case Toolkit::TextField::Property::EXCEED_POLICY:
828 value = impl.mExceedPolicy;
831 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
833 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
837 value = std::string( name );
841 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
843 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
847 value = std::string( name );
851 case Toolkit::TextField::Property::TEXT_COLOR:
853 value = impl.mController->GetDefaultColor();
856 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
858 value = impl.mController->GetPlaceholderTextColor();
861 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
863 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
866 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
868 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
871 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
873 value = impl.mController->GetEnableCursorBlink();
876 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
878 value = impl.mDecorator->GetCursorBlinkInterval();
881 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
883 value = impl.mDecorator->GetCursorBlinkDuration();
886 case Toolkit::TextField::Property::CURSOR_WIDTH:
888 value = impl.mDecorator->GetCursorWidth();
891 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
893 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
896 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
898 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
901 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
903 value = impl.mDecorator->GetScrollThreshold();
906 case Toolkit::TextField::Property::SCROLL_SPEED:
908 value = impl.mDecorator->GetScrollSpeed();
911 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
913 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
916 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
918 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
921 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
923 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
926 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
928 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
931 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
933 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
936 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
938 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
941 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
943 value = impl.mDecorator->GetHighlightColor();
946 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
948 Rect<int> boundingBox;
949 impl.mDecorator->GetBoundingBox( boundingBox );
953 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
956 impl.mInputMethodOptions.RetrieveProperty( map );
960 case Toolkit::TextField::Property::INPUT_COLOR:
962 value = impl.mController->GetInputColor();
965 case Toolkit::TextField::Property::ENABLE_MARKUP:
967 value = impl.mController->IsMarkupProcessorEnabled();
970 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
972 value = impl.mController->GetInputFontFamily();
975 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
977 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
980 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
982 value = impl.mController->GetInputFontPointSize();
985 case Toolkit::TextField::Property::UNDERLINE:
987 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
990 case Toolkit::TextField::Property::INPUT_UNDERLINE:
992 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
995 case Toolkit::TextField::Property::SHADOW:
997 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1000 case Toolkit::TextField::Property::INPUT_SHADOW:
1002 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1005 case Toolkit::TextField::Property::EMBOSS:
1007 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1010 case Toolkit::TextField::Property::INPUT_EMBOSS:
1012 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1015 case Toolkit::TextField::Property::OUTLINE:
1017 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1020 case Toolkit::TextField::Property::INPUT_OUTLINE:
1022 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1025 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1028 impl.mController->GetHiddenInputOption(map);
1032 case Toolkit::TextField::Property::PIXEL_SIZE:
1034 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1037 case Toolkit::TextField::Property::ENABLE_SELECTION:
1039 value = impl.mController->IsSelectionEnabled();
1042 case Toolkit::TextField::Property::PLACEHOLDER:
1045 impl.mController->GetPlaceholderProperty( map );
1049 case Toolkit::TextField::Property::ELLIPSIS:
1051 value = impl.mController->IsTextElideEnabled();
1054 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1056 value = impl.mController->IsShiftSelectionEnabled();
1059 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1061 value = impl.mController->IsGrabHandleEnabled();
1064 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1066 value = impl.mController->IsMatchSystemLanguageDirection();
1069 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1071 value = impl.mController->IsGrabHandlePopupEnabled();
1074 case Toolkit::DevelTextField::Property::BACKGROUND:
1076 value = impl.mController->GetBackgroundColor();
1079 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1081 value = impl.mController->GetSelectedText( );
1084 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1086 Uint32Pair range = impl.GetTextSelectionRange( );
1087 value = static_cast<int>(range.first);
1090 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1092 Uint32Pair range = impl.GetTextSelectionRange( );
1093 value = static_cast<int>(range.second);
1096 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1098 value = impl.IsEditable();
1101 case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
1103 value = impl.mController->GetFontSizeScale();
1106 case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
1108 value = static_cast<int>(impl.mController->GetPrimaryCursorPosition());
1117 void TextField::SelectWholeText()
1119 if( mController && mController->IsShowingRealText() )
1121 mController->SelectWholeText();
1126 void TextField::SelectNone()
1128 if( mController && mController->IsShowingRealText() )
1130 mController->SelectNone();
1134 string TextField::GetSelectedText() const
1136 string selectedText = "";
1137 if( mController && mController->IsShowingRealText() )
1139 selectedText = mController->GetSelectedText( );
1141 return selectedText;
1144 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1146 if( mController && mController->IsShowingRealText() )
1148 mController->SetTextSelectionRange( start, end );
1153 Uint32Pair TextField::GetTextSelectionRange() const
1156 if( mController && mController->IsShowingRealText() )
1158 range = mController->GetTextSelectionRange();
1164 InputMethodContext TextField::GetInputMethodContext()
1166 return mInputMethodContext;
1169 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1171 Dali::BaseHandle handle( object );
1173 bool connected( true );
1174 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1176 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1178 field.TextChangedSignal().Connect( tracker, functor );
1180 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1182 field.MaxLengthReachedSignal().Connect( tracker, functor );
1184 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1186 field.InputStyleChangedSignal().Connect( tracker, functor );
1190 // signalName does not match any signal
1197 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1199 return mTextChangedSignal;
1202 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1204 return mMaxLengthReachedSignal;
1207 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1209 return mInputStyleChangedSignal;
1212 void TextField::OnInitialize()
1214 Actor self = Self();
1216 mController = Text::Controller::New( this, this ,this);
1218 // When using the vector-based rendering, the size of the GLyphs are different
1219 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1220 mController->SetGlyphType( glyphType );
1222 mDecorator = Text::Decorator::New( *mController,
1225 mInputMethodContext = InputMethodContext::New( self );
1227 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1229 // Enables the text input.
1230 mController->EnableTextInput( mDecorator, mInputMethodContext );
1232 // Enables the horizontal scrolling after the text input has been enabled.
1233 mController->SetHorizontalScrollEnabled( true );
1235 // Disables the vertical scrolling.
1236 mController->SetVerticalScrollEnabled( false );
1238 // Disable the smooth handle panning.
1239 mController->SetSmoothHandlePanEnabled( false );
1241 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1242 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1244 // Sets layoutDirection value
1245 Dali::Stage stage = Dali::Stage::GetCurrent();
1246 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1247 mController->SetLayoutDirection( layoutDirection );
1249 // Forward input events to controller
1250 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1251 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1253 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1255 // Set BoundingBox to stage size if not already set.
1256 Rect<int> boundingBox;
1257 mDecorator->GetBoundingBox( boundingBox );
1259 if( boundingBox.IsEmpty() )
1261 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1262 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1265 // Flip vertically the 'left' selection handle
1266 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1268 // Fill-parent area by default
1269 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1270 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1271 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1273 //Enable highightability
1274 self.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true );
1276 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1278 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1283 DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) {
1284 return std::unique_ptr< Dali::Accessibility::Accessible >(
1285 new AccessibleImpl( actor, Dali::Accessibility::Role::ENTRY ) );
1289 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1291 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1295 case StyleChange::DEFAULT_FONT_CHANGE:
1297 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1298 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1299 // Property system did not set the font so should update it.
1300 mController->UpdateAfterFontChange( newFont );
1305 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1307 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1311 case StyleChange::THEME_CHANGE:
1313 // Nothing to do, let control base class handle this
1318 // Up call to Control
1319 Control::OnStyleChange( styleManager, change );
1322 Vector3 TextField::GetNaturalSize()
1325 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1327 Vector3 naturalSize = mController->GetNaturalSize();
1328 naturalSize.width += ( padding.start + padding.end );
1329 naturalSize.height += ( padding.top + padding.bottom );
1334 float TextField::GetHeightForWidth( float width )
1337 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1338 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1341 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1343 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1345 Actor self = Self();
1348 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1350 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1352 // Support Right-To-Left of padding
1353 Dali::LayoutDirection::Type layoutDirection;
1354 if( mController->IsMatchSystemLanguageDirection() )
1356 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1360 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1362 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1364 std::swap( padding.start, padding.end );
1369 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1373 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1376 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1378 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1384 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1386 mDecorator->Relayout( size );
1391 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1394 RenderText( updateTextType );
1398 // The text-field emits signals when the input style changes. These changes of style are
1399 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1400 // can't be emitted during the size negotiation as the callbacks may update the UI.
1401 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1402 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1404 if( Adaptor::IsAvailable() )
1406 Adaptor& adaptor = Adaptor::Get();
1408 if( NULL == mIdleCallback )
1410 // @note: The callback manager takes the ownership of the callback object.
1411 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1412 adaptor.AddIdle( mIdleCallback, false );
1418 Text::ControllerPtr TextField::getController() { return mController; }
1420 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1422 Actor renderableActor;
1424 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1428 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1430 renderableActor = mRenderer->Render( mController->GetView(),
1432 Property::INVALID_INDEX, // Animatable property not supported
1434 DepthIndex::CONTENT );
1437 if( renderableActor != mRenderableActor )
1439 UnparentAndReset( mBackgroundActor );
1440 UnparentAndReset( mRenderableActor );
1441 mRenderableActor = renderableActor;
1443 if ( mRenderableActor )
1445 mBackgroundActor = mController->CreateBackgroundActor();
1450 if( mRenderableActor )
1452 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1454 float renderableActorPositionX, renderableActorPositionY;
1458 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1459 renderableActorPositionY = scrollOffset.y;
1464 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1466 // Support Right-To-Left of padding
1467 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1468 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1470 std::swap( padding.start, padding.end );
1473 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1474 renderableActorPositionY = scrollOffset.y + padding.top;
1477 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1479 // Make sure the actors are parented correctly with/without clipping
1480 Actor self = mStencil ? mStencil : Self();
1482 Actor highlightActor;
1484 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1485 endIt = mClippingDecorationActors.end();
1490 it->LowerToBottom();
1492 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1494 highlightActor = *it;
1497 mClippingDecorationActors.clear();
1499 self.Add( mRenderableActor );
1501 if ( mBackgroundActor )
1503 if ( mDecorator && mDecorator->IsHighlightVisible() )
1505 self.Add( mBackgroundActor );
1506 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1507 mBackgroundActor.LowerBelow( highlightActor );
1511 mRenderableActor.Add( mBackgroundActor );
1512 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1513 mBackgroundActor.LowerToBottom();
1519 void TextField::OnKeyInputFocusGained()
1521 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1522 if( mInputMethodContext && IsEditable() )
1524 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1526 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1528 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1530 // Notify that the text editing start.
1531 mInputMethodContext.Activate();
1533 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1534 mInputMethodContext.SetRestoreAfterFocusLost( true );
1537 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1540 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1543 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1544 Internal::Control& controlImpl = GetImplementation( control );
1545 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1546 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1547 if( enableAutofill )
1549 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1550 container.SetFocusedControl( control );
1552 Internal::AutofillContainer& containerImpl = GetImpl( container );
1553 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1554 if( containerGroup != nullptr )
1556 containerGroup.RequestAuthentication();
1560 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1562 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1565 void TextField::OnKeyInputFocusLost()
1567 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1568 if ( mInputMethodContext )
1570 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1571 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1572 mInputMethodContext.SetRestoreAfterFocusLost( false );
1574 // Notify that the text editing finish.
1575 mInputMethodContext.Deactivate();
1577 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1579 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1583 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1586 mController->KeyboardFocusLostEvent();
1588 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1591 bool TextField::OnAccessibilityActivated()
1597 void TextField::OnTap( const TapGesture& gesture )
1599 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1600 if ( mInputMethodContext && IsEditable() )
1602 mInputMethodContext.Activate();
1604 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1606 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1607 const Vector2& localPoint = gesture.GetLocalPoint();
1608 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1613 void TextField::OnPan( const PanGesture& gesture )
1615 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1618 void TextField::OnLongPress( const LongPressGesture& gesture )
1620 if ( mInputMethodContext && IsEditable() )
1622 mInputMethodContext.Activate();
1625 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1626 const Vector2& localPoint = gesture.GetLocalPoint();
1627 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1632 bool TextField::OnKeyEvent( const KeyEvent& event )
1634 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1636 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1638 // Make sure ClearKeyInputFocus when only key is up
1639 if( event.GetState() == KeyEvent::UP )
1641 ClearKeyInputFocus();
1646 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1648 // Do nothing when enter is comming.
1652 return mController->KeyEvent( event );
1655 void TextField::RequestTextRelayout()
1660 bool TextField::IsEditable() const
1662 return mController->IsEditable();
1665 void TextField::SetEditable( bool editable )
1667 mController->SetEditable(editable);
1668 if ( mInputMethodContext && !editable )
1670 mInputMethodContext.Deactivate();
1674 void TextField::TextInserted( unsigned int position, unsigned int length, const std::string &content )
1676 if( Accessibility::IsUp() )
1678 Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content );
1682 void TextField::TextDeleted( unsigned int position, unsigned int length, const std::string &content )
1684 if( Accessibility::IsUp() )
1686 Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content );
1690 void TextField::CaretMoved( unsigned int position )
1692 if( Accessibility::IsUp() )
1694 Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position );
1698 void TextField::TextChanged()
1700 Dali::Toolkit::TextField handle( GetOwner() );
1701 mTextChangedSignal.Emit( handle );
1704 void TextField::MaxLengthReached()
1706 Dali::Toolkit::TextField handle( GetOwner() );
1707 mMaxLengthReachedSignal.Emit( handle );
1710 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1712 Dali::Toolkit::TextField handle( GetOwner() );
1714 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1716 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1718 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1720 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1722 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1724 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1726 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1728 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1730 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1732 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1734 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1736 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1738 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1740 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1742 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1744 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1746 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1748 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1750 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1752 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1754 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1757 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1760 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1766 mClippingDecorationActors.push_back( actor );
1770 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1771 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1772 Self().Add( actor );
1773 mActiveLayer = actor;
1778 void TextField::OnSceneConnect( Dali::Actor actor )
1780 if ( mHasBeenStaged )
1782 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1786 mHasBeenStaged = true;
1790 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1792 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1793 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1796 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1801 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1806 void TextField::EnableClipping()
1810 // Creates an extra control to be used as stencil buffer.
1811 mStencil = Control::New();
1812 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1813 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1815 // Creates a background visual. Even if the color is transparent it updates the stencil.
1816 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1817 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1818 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1820 // Enable the clipping property.
1821 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1822 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1824 Self().Add( mStencil );
1828 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1830 mController->PasteClipboardItemEvent();
1833 void TextField::KeyboardStatusChanged(bool keyboardShown)
1835 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1837 // Just hide the grab handle when keyboard is hidden.
1838 if (!keyboardShown )
1840 mController->KeyboardFocusLostEvent();
1844 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1848 void TextField::OnSceneConnection( int depth )
1850 // Sets the depth to the visuals inside the text's decorator.
1851 mDecorator->SetTextDepth( depth );
1853 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1855 // Call the Control::OnSceneConnection() to set the depth of the background.
1856 Control::OnSceneConnection( depth );
1859 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1864 void TextField::OnIdleSignal()
1866 // Emits the change of input style signals.
1867 mController->ProcessInputStyleChangedSignals();
1869 // Set the pointer to null as the callback manager deletes the callback after execute it.
1870 mIdleCallback = NULL;
1873 TextField::TextField()
1874 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1875 mIdleCallback( NULL ),
1876 mAlignmentOffset( 0.f ),
1877 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1878 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1879 mHasBeenStaged( false )
1883 TextField::~TextField()
1885 UnparentAndReset( mStencil );
1887 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1889 Adaptor::Get().RemoveIdle( mIdleCallback );
1893 std::string TextField::AccessibleImpl::GetName()
1895 auto slf = Toolkit::TextField::DownCast( self );
1896 return slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1899 std::string TextField::AccessibleImpl::GetText( size_t startOffset,
1902 if( endOffset <= startOffset )
1905 auto slf = Toolkit::TextField::DownCast( self );
1907 slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1909 if( startOffset > txt.size() || endOffset > txt.size() )
1912 return txt.substr( startOffset, endOffset - startOffset );
1915 size_t TextField::AccessibleImpl::GetCharacterCount()
1917 auto slf = Toolkit::TextField::DownCast( self );
1919 slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1924 size_t TextField::AccessibleImpl::GetCaretOffset()
1926 auto slf = Toolkit::TextField::DownCast( self );
1927 return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition();
1930 bool TextField::AccessibleImpl::SetCaretOffset(size_t offset)
1932 auto slf = Toolkit::TextField::DownCast( self );
1933 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1934 if (offset > txt.size())
1937 auto& slfImpl = Dali::Toolkit::GetImpl( slf );
1938 slfImpl.getController()->ResetCursorPosition( offset );
1939 slfImpl.RequestTextRelayout();
1943 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1944 size_t offset, Dali::Accessibility::TextBoundary boundary )
1946 auto slf = Toolkit::TextField::DownCast( self );
1947 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1948 auto txt_size = txt.size();
1950 auto range = Dali::Accessibility::Range{};
1954 case Dali::Accessibility::TextBoundary::CHARACTER:
1956 if (offset < txt_size)
1958 range.content = txt[offset];
1959 range.startOffset = offset;
1960 range.endOffset = offset + 1;
1964 case Dali::Accessibility::TextBoundary::WORD:
1965 case Dali::Accessibility::TextBoundary::LINE:
1967 auto txt_c_string = txt.c_str();
1968 auto breaks = std::vector< char >( txt_size, 0 );
1969 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1970 Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1972 Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1975 while( index < txt_size && counter <= offset )
1980 while(breaks[index])
1986 if (boundary == Dali::Accessibility::TextBoundary::WORD)
1988 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1991 if ((counter > 0) && ((counter - 1) == offset))
1993 range.content = txt.substr(start, index - start + 1);
1994 range.startOffset = start;
1995 range.endOffset = index + 1;
1997 if (boundary == Dali::Accessibility::TextBoundary::LINE)
2002 case Dali::Accessibility::TextBoundary::SENTENCE:
2004 /* not supported by efl */
2007 case Dali::Accessibility::TextBoundary::PARAGRAPH:
2009 /* Paragraph is not supported by libunibreak library */
2019 Dali::Accessibility::Range
2020 TextField::AccessibleImpl::GetSelection( size_t selectionNum )
2022 // Since DALi supports only one selection indexes higher than 0 are ignored
2023 if( selectionNum > 0 )
2026 auto slf = Toolkit::TextField::DownCast( self );
2027 auto ctrl = Dali::Toolkit::GetImpl( slf ).getController();
2029 ctrl->RetrieveSelection( ret );
2030 auto r = ctrl->GetSelectionIndexes();
2032 return { static_cast<size_t>(r.first), static_cast<size_t>(r.second), ret };
2035 bool TextField::AccessibleImpl::RemoveSelection( size_t selectionNum )
2037 // Since DALi supports only one selection indexes higher than 0 are ignored
2038 if( selectionNum > 0 )
2041 auto slf = Toolkit::TextField::DownCast( self );
2042 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
2046 bool TextField::AccessibleImpl::SetSelection( size_t selectionNum,
2050 // Since DALi supports only one selection indexes higher than 0 are ignored
2051 if( selectionNum > 0 )
2054 auto slf = Toolkit::TextField::DownCast( self );
2055 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
2060 bool TextField::AccessibleImpl::CopyText( size_t startPosition,
2061 size_t endPosition )
2063 if( endPosition <= startPosition )
2066 auto slf = Toolkit::TextField::DownCast( self );
2067 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2068 Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2073 bool TextField::AccessibleImpl::CutText( size_t startPosition,
2074 size_t endPosition )
2076 if( endPosition <= startPosition )
2079 auto slf = Toolkit::TextField::DownCast( self );
2080 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2081 Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2083 slf.SetProperty( Toolkit::TextField::Property::TEXT,
2084 txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size()));
2089 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
2091 using namespace Dali::Accessibility;
2093 auto states = Control::Impl::AccessibleImpl::CalculateStates();
2095 states[State::EDITABLE] = true;
2096 states[State::FOCUSABLE] = true;
2098 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
2099 if (self == focusControl)
2101 states[State::FOCUSED] = true;
2107 } // namespace Internal
2109 } // namespace Toolkit