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/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>
50 using namespace Dali::Toolkit::Text;
61 namespace // unnamed namespace
64 #if defined(DEBUG_ENABLED)
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
68 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
69 } // unnamed namespace
76 return Toolkit::TextField::New();
79 // Setup properties, signals and actions using the type-registry.
80 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
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 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
146 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
148 DALI_TYPE_REGISTRATION_END()
150 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
152 /// Retrieves a filename from a value that is a Property::Map
153 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
155 std::string filename;
156 const Property::Map* map = value.GetMap();
159 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
162 filenameValue->Get( filename );
170 Toolkit::TextField TextField::New()
172 // Create the implementation, temporarily owned by this handle on stack
173 IntrusivePtr< TextField > impl = new TextField();
175 // Pass ownership to CustomActor handle
176 Toolkit::TextField handle( *impl );
178 // Second-phase init of the implementation
179 // This can only be done after the CustomActor connection has been made...
185 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
187 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
189 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
193 TextField& impl( GetImpl( textField ) );
194 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
195 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
199 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
201 int backend = value.Get< int >();
202 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
204 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
205 if( DevelText::RENDERING_VECTOR_BASED == backend )
207 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
210 if( impl.mRenderingBackend != backend )
212 impl.mRenderingBackend = backend;
213 impl.mRenderer.Reset();
215 // When using the vector-based rendering, the size of the GLyphs are different
216 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
217 impl.mController->SetGlyphType( glyphType );
221 case Toolkit::TextField::Property::TEXT:
223 const std::string& text = value.Get< std::string >();
224 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
226 impl.mController->SetText( text );
229 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
231 const std::string& text = value.Get< std::string >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
234 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
237 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
239 const std::string& text = value.Get< std::string >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
242 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
245 case Toolkit::TextField::Property::FONT_FAMILY:
247 const std::string& fontFamily = value.Get< std::string >();
248 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
249 impl.mController->SetDefaultFontFamily( fontFamily );
252 case Toolkit::TextField::Property::FONT_STYLE:
254 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
257 case Toolkit::TextField::Property::POINT_SIZE:
259 const float pointSize = value.Get< float >();
260 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
262 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
264 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
268 case Toolkit::TextField::Property::MAX_LENGTH:
270 const int max = value.Get< int >();
271 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
273 impl.mController->SetMaximumNumberOfCharacters( max );
276 case Toolkit::TextField::Property::EXCEED_POLICY:
278 impl.mExceedPolicy = value.Get<int>();
280 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
282 impl.EnableClipping();
286 UnparentAndReset( impl.mStencil );
288 impl.RequestTextRelayout();
291 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
293 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
294 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
296 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
297 impl.mController->SetHorizontalAlignment( alignment );
301 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
303 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
304 if( GetVerticalAlignmentEnumeration( value, alignment ) )
306 impl.mController->SetVerticalAlignment( alignment );
307 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
311 case Toolkit::TextField::Property::TEXT_COLOR:
313 const Vector4& textColor = value.Get< Vector4 >();
314 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 );
316 if( impl.mController->GetDefaultColor() != textColor )
318 impl.mController->SetDefaultColor( textColor );
319 impl.mController->SetInputColor( textColor );
320 impl.mRenderer.Reset();
324 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
326 const Vector4& textColor = value.Get< Vector4 >();
327 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 );
329 if( impl.mController->GetPlaceholderTextColor() != textColor )
331 impl.mController->SetPlaceholderTextColor( textColor );
332 impl.mRenderer.Reset();
336 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
338 const Vector4& color = value.Get< Vector4 >();
339 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 );
341 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
342 impl.RequestTextRelayout();
345 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
347 const Vector4& color = value.Get< Vector4 >();
348 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 );
350 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
351 impl.RequestTextRelayout();
354 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
356 const bool enable = value.Get< bool >();
357 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
359 impl.mController->SetEnableCursorBlink( enable );
360 impl.RequestTextRelayout();
363 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
365 const float interval = value.Get< float >();
366 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
368 impl.mDecorator->SetCursorBlinkInterval( interval );
371 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
373 const float duration = value.Get< float >();
374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
376 impl.mDecorator->SetCursorBlinkDuration( duration );
379 case Toolkit::TextField::Property::CURSOR_WIDTH:
381 const int width = value.Get< int >();
382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
384 impl.mDecorator->SetCursorWidth( width );
385 impl.mController->GetLayoutEngine().SetCursorWidth( width );
388 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
390 const std::string imageFileName = value.Get< std::string >();
391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
393 if( imageFileName.size() )
395 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
396 impl.RequestTextRelayout();
400 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
402 const std::string imageFileName = value.Get< std::string >();
403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
405 if( imageFileName.size() )
407 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
408 impl.RequestTextRelayout();
412 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
414 const float threshold = value.Get< float >();
415 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
417 impl.mDecorator->SetScrollThreshold( threshold );
420 case Toolkit::TextField::Property::SCROLL_SPEED:
422 const float speed = value.Get< float >();
423 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
425 impl.mDecorator->SetScrollSpeed( speed );
428 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
430 const std::string filename = GetImageFileNameFromPropertyValue( value );
432 if( filename.size() )
434 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
435 impl.RequestTextRelayout();
439 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
441 const std::string filename = GetImageFileNameFromPropertyValue( value );
443 if( filename.size() )
445 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
446 impl.RequestTextRelayout();
450 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
452 const std::string filename = GetImageFileNameFromPropertyValue( value );
454 if( filename.size() )
456 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
457 impl.RequestTextRelayout();
461 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
463 const std::string filename = GetImageFileNameFromPropertyValue( value );
465 if( filename.size() )
467 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
468 impl.RequestTextRelayout();
472 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
474 const std::string filename = GetImageFileNameFromPropertyValue( value );
476 if( filename.size() )
478 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
479 impl.RequestTextRelayout();
483 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
485 const std::string filename = GetImageFileNameFromPropertyValue( value );
487 if( filename.size() )
489 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
490 impl.RequestTextRelayout();
494 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
496 const Vector4 color = value.Get< Vector4 >();
497 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 );
499 impl.mDecorator->SetHighlightColor( color );
500 impl.RequestTextRelayout();
503 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
505 const Rect<int> box = value.Get< Rect<int> >();
506 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 );
508 impl.mDecorator->SetBoundingBox( box );
509 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
514 const Property::Map* map = value.GetMap();
517 impl.mInputMethodOptions.ApplyProperty( *map );
519 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
521 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
522 if (control == textField)
524 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
528 case Toolkit::TextField::Property::INPUT_COLOR:
530 const Vector4 inputColor = value.Get< Vector4 >();
531 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 );
533 impl.mController->SetInputColor( inputColor );
536 case Toolkit::TextField::Property::ENABLE_MARKUP:
538 const bool enableMarkup = value.Get<bool>();
539 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
541 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
544 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
546 const std::string& fontFamily = value.Get< std::string >();
547 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
548 impl.mController->SetInputFontFamily( fontFamily );
551 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
553 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
556 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
558 const float pointSize = value.Get< float >();
559 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
560 impl.mController->SetInputFontPointSize( pointSize );
563 case Toolkit::TextField::Property::UNDERLINE:
565 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
568 impl.mRenderer.Reset();
572 case Toolkit::TextField::Property::INPUT_UNDERLINE:
574 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
577 impl.mRenderer.Reset();
581 case Toolkit::TextField::Property::SHADOW:
583 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
586 impl.mRenderer.Reset();
590 case Toolkit::TextField::Property::INPUT_SHADOW:
592 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
595 impl.mRenderer.Reset();
599 case Toolkit::TextField::Property::EMBOSS:
601 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
604 impl.mRenderer.Reset();
608 case Toolkit::TextField::Property::INPUT_EMBOSS:
610 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
613 impl.mRenderer.Reset();
617 case Toolkit::TextField::Property::OUTLINE:
619 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
622 impl.mRenderer.Reset();
626 case Toolkit::TextField::Property::INPUT_OUTLINE:
628 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
631 impl.mRenderer.Reset();
635 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
637 const Property::Map* map = value.GetMap();
640 impl.mController->SetHiddenInputOption(*map);
644 case Toolkit::TextField::Property::PIXEL_SIZE:
646 const float pixelSize = value.Get< float >();
647 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
649 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
651 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
655 case Toolkit::TextField::Property::ENABLE_SELECTION:
657 const bool enableSelection = value.Get< bool >();
658 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
659 impl.mController->SetSelectionEnabled( enableSelection );
662 case Toolkit::TextField::Property::PLACEHOLDER:
664 const Property::Map* map = value.GetMap();
667 impl.mController->SetPlaceholderProperty( *map );
671 case Toolkit::TextField::Property::ELLIPSIS:
673 const bool ellipsis = value.Get<bool>();
674 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
676 impl.mController->SetTextElideEnabled( ellipsis );
679 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
681 const bool shiftSelection = value.Get<bool>();
682 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
684 impl.mController->SetShiftSelectionEnabled( shiftSelection );
687 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
689 const bool grabHandleEnabled = value.Get<bool>();
690 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
692 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
695 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
697 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
700 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
702 const bool grabHandlePopupEnabled = value.Get<bool>();
703 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
705 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
708 case Toolkit::DevelTextField::Property::BACKGROUND:
710 const Vector4 backgroundColor = value.Get< Vector4 >();
711 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 );
713 impl.mController->SetBackgroundEnabled( true );
714 impl.mController->SetBackgroundColor( backgroundColor );
717 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
719 uint32_t start = static_cast<uint32_t>(value.Get< int >());
720 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
721 impl.SetTextSelectionRange( &start, nullptr );
724 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
726 uint32_t end = static_cast<uint32_t>(value.Get< int >());
727 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
728 impl.SetTextSelectionRange( nullptr, &end );
731 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
733 const bool editable = value.Get< bool >();
734 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
735 impl.SetEditable( editable );
738 case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
740 const float scale = value.Get< float >();
741 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale );
743 if( !Equals( impl.mController->GetFontSizeScale(), scale ) )
745 impl.mController->SetFontSizeScale( scale );
749 case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
751 uint32_t position = static_cast<uint32_t>(value.Get< int >());
752 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position );
753 if (impl.mController->SetPrimaryCursorPosition( position ))
755 impl.SetKeyInputFocus();
763 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
765 Property::Value value;
767 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
771 TextField& impl( GetImpl( textField ) );
772 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
773 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
777 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
779 value = impl.mRenderingBackend;
782 case Toolkit::TextField::Property::TEXT:
785 impl.mController->GetText( text );
786 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
790 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
793 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
797 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
800 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
804 case Toolkit::TextField::Property::FONT_FAMILY:
806 value = impl.mController->GetDefaultFontFamily();
809 case Toolkit::TextField::Property::FONT_STYLE:
811 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
814 case Toolkit::TextField::Property::POINT_SIZE:
816 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
819 case Toolkit::TextField::Property::MAX_LENGTH:
821 value = impl.mController->GetMaximumNumberOfCharacters();
824 case Toolkit::TextField::Property::EXCEED_POLICY:
826 value = impl.mExceedPolicy;
829 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
831 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
835 value = std::string( name );
839 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
841 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
845 value = std::string( name );
849 case Toolkit::TextField::Property::TEXT_COLOR:
851 value = impl.mController->GetDefaultColor();
854 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
856 value = impl.mController->GetPlaceholderTextColor();
859 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
861 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
864 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
866 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
869 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
871 value = impl.mController->GetEnableCursorBlink();
874 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
876 value = impl.mDecorator->GetCursorBlinkInterval();
879 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
881 value = impl.mDecorator->GetCursorBlinkDuration();
884 case Toolkit::TextField::Property::CURSOR_WIDTH:
886 value = impl.mDecorator->GetCursorWidth();
889 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
891 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
894 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
896 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
899 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
901 value = impl.mDecorator->GetScrollThreshold();
904 case Toolkit::TextField::Property::SCROLL_SPEED:
906 value = impl.mDecorator->GetScrollSpeed();
909 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
911 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
914 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
916 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
919 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
921 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
924 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
926 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
929 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
931 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
934 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
936 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
939 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
941 value = impl.mDecorator->GetHighlightColor();
944 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
946 Rect<int> boundingBox;
947 impl.mDecorator->GetBoundingBox( boundingBox );
951 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
954 impl.mInputMethodOptions.RetrieveProperty( map );
958 case Toolkit::TextField::Property::INPUT_COLOR:
960 value = impl.mController->GetInputColor();
963 case Toolkit::TextField::Property::ENABLE_MARKUP:
965 value = impl.mController->IsMarkupProcessorEnabled();
968 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
970 value = impl.mController->GetInputFontFamily();
973 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
975 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
978 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
980 value = impl.mController->GetInputFontPointSize();
983 case Toolkit::TextField::Property::UNDERLINE:
985 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
988 case Toolkit::TextField::Property::INPUT_UNDERLINE:
990 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
993 case Toolkit::TextField::Property::SHADOW:
995 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
998 case Toolkit::TextField::Property::INPUT_SHADOW:
1000 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1003 case Toolkit::TextField::Property::EMBOSS:
1005 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1008 case Toolkit::TextField::Property::INPUT_EMBOSS:
1010 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1013 case Toolkit::TextField::Property::OUTLINE:
1015 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1018 case Toolkit::TextField::Property::INPUT_OUTLINE:
1020 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1023 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1026 impl.mController->GetHiddenInputOption(map);
1030 case Toolkit::TextField::Property::PIXEL_SIZE:
1032 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1035 case Toolkit::TextField::Property::ENABLE_SELECTION:
1037 value = impl.mController->IsSelectionEnabled();
1040 case Toolkit::TextField::Property::PLACEHOLDER:
1043 impl.mController->GetPlaceholderProperty( map );
1047 case Toolkit::TextField::Property::ELLIPSIS:
1049 value = impl.mController->IsTextElideEnabled();
1052 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1054 value = impl.mController->IsShiftSelectionEnabled();
1057 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1059 value = impl.mController->IsGrabHandleEnabled();
1062 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1064 value = impl.mController->IsMatchSystemLanguageDirection();
1067 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1069 value = impl.mController->IsGrabHandlePopupEnabled();
1072 case Toolkit::DevelTextField::Property::BACKGROUND:
1074 value = impl.mController->GetBackgroundColor();
1077 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1079 value = impl.mController->GetSelectedText( );
1082 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1084 Uint32Pair range = impl.GetTextSelectionRange( );
1085 value = static_cast<int>(range.first);
1088 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1090 Uint32Pair range = impl.GetTextSelectionRange( );
1091 value = static_cast<int>(range.second);
1094 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1096 value = impl.IsEditable();
1099 case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
1101 value = impl.mController->GetFontSizeScale();
1104 case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
1106 value = static_cast<int>(impl.mController->GetPrimaryCursorPosition());
1115 void TextField::SelectWholeText()
1117 if( mController && mController->IsShowingRealText() )
1119 mController->SelectWholeText();
1124 void TextField::SelectNone()
1126 if( mController && mController->IsShowingRealText() )
1128 mController->SelectNone();
1132 string TextField::GetSelectedText() const
1134 string selectedText = "";
1135 if( mController && mController->IsShowingRealText() )
1137 selectedText = mController->GetSelectedText( );
1139 return selectedText;
1142 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1144 if( mController && mController->IsShowingRealText() )
1146 mController->SetTextSelectionRange( start, end );
1151 Uint32Pair TextField::GetTextSelectionRange() const
1154 if( mController && mController->IsShowingRealText() )
1156 range = mController->GetTextSelectionRange();
1162 InputMethodContext TextField::GetInputMethodContext()
1164 return mInputMethodContext;
1167 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1169 Dali::BaseHandle handle( object );
1171 bool connected( true );
1172 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1174 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1176 field.TextChangedSignal().Connect( tracker, functor );
1178 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1180 field.MaxLengthReachedSignal().Connect( tracker, functor );
1182 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1184 field.InputStyleChangedSignal().Connect( tracker, functor );
1188 // signalName does not match any signal
1195 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1197 return mTextChangedSignal;
1200 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1202 return mMaxLengthReachedSignal;
1205 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1207 return mInputStyleChangedSignal;
1210 void TextField::OnInitialize()
1212 Actor self = Self();
1214 mController = Text::Controller::New( this, this ,this);
1216 // When using the vector-based rendering, the size of the GLyphs are different
1217 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1218 mController->SetGlyphType( glyphType );
1220 mDecorator = Text::Decorator::New( *mController,
1223 mInputMethodContext = InputMethodContext::New( self );
1225 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1227 // Enables the text input.
1228 mController->EnableTextInput( mDecorator, mInputMethodContext );
1230 // Enables the horizontal scrolling after the text input has been enabled.
1231 mController->SetHorizontalScrollEnabled( true );
1233 // Disables the vertical scrolling.
1234 mController->SetVerticalScrollEnabled( false );
1236 // Disable the smooth handle panning.
1237 mController->SetSmoothHandlePanEnabled( false );
1239 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1240 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1242 // Sets layoutDirection value
1243 Dali::Stage stage = Dali::Stage::GetCurrent();
1244 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1245 mController->SetLayoutDirection( layoutDirection );
1247 // Forward input events to controller
1248 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1249 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1251 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1253 // Set BoundingBox to stage size if not already set.
1254 Rect<int> boundingBox;
1255 mDecorator->GetBoundingBox( boundingBox );
1257 if( boundingBox.IsEmpty() )
1259 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1260 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1263 // Flip vertically the 'left' selection handle
1264 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1266 // Fill-parent area by default
1267 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1268 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1269 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1271 //Enable highightability
1272 self.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true );
1274 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1276 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1281 DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) {
1282 return std::unique_ptr< Dali::Accessibility::Accessible >(
1283 new AccessibleImpl( actor, Dali::Accessibility::Role::ENTRY ) );
1287 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1289 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1293 case StyleChange::DEFAULT_FONT_CHANGE:
1295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1296 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1297 // Property system did not set the font so should update it.
1298 mController->UpdateAfterFontChange( newFont );
1303 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1305 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1309 case StyleChange::THEME_CHANGE:
1311 // Nothing to do, let control base class handle this
1316 // Up call to Control
1317 Control::OnStyleChange( styleManager, change );
1320 Vector3 TextField::GetNaturalSize()
1323 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1325 Vector3 naturalSize = mController->GetNaturalSize();
1326 naturalSize.width += ( padding.start + padding.end );
1327 naturalSize.height += ( padding.top + padding.bottom );
1332 float TextField::GetHeightForWidth( float width )
1335 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1336 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1339 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1341 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1343 Actor self = Self();
1346 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1348 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1350 // Support Right-To-Left of padding
1351 Dali::LayoutDirection::Type layoutDirection;
1352 if( mController->IsMatchSystemLanguageDirection() )
1354 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1358 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1360 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1362 std::swap( padding.start, padding.end );
1367 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1371 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1374 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1376 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1382 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1384 mDecorator->Relayout( size );
1389 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1392 RenderText( updateTextType );
1396 // The text-field emits signals when the input style changes. These changes of style are
1397 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1398 // can't be emitted during the size negotiation as the callbacks may update the UI.
1399 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1400 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1402 if( Adaptor::IsAvailable() )
1404 Adaptor& adaptor = Adaptor::Get();
1406 if( NULL == mIdleCallback )
1408 // @note: The callback manager takes the ownership of the callback object.
1409 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1410 adaptor.AddIdle( mIdleCallback, false );
1416 Text::ControllerPtr TextField::getController() { return mController; }
1418 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1420 Actor renderableActor;
1422 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1426 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1428 renderableActor = mRenderer->Render( mController->GetView(),
1430 Property::INVALID_INDEX, // Animatable property not supported
1432 DepthIndex::CONTENT );
1435 if( renderableActor != mRenderableActor )
1437 UnparentAndReset( mBackgroundActor );
1438 UnparentAndReset( mRenderableActor );
1439 mRenderableActor = renderableActor;
1441 if ( mRenderableActor )
1443 mBackgroundActor = mController->CreateBackgroundActor();
1448 if( mRenderableActor )
1450 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1452 float renderableActorPositionX, renderableActorPositionY;
1456 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1457 renderableActorPositionY = scrollOffset.y;
1462 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1464 // Support Right-To-Left of padding
1465 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1466 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1468 std::swap( padding.start, padding.end );
1471 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1472 renderableActorPositionY = scrollOffset.y + padding.top;
1475 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1477 // Make sure the actors are parented correctly with/without clipping
1478 Actor self = mStencil ? mStencil : Self();
1480 Actor highlightActor;
1482 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1483 endIt = mClippingDecorationActors.end();
1488 it->LowerToBottom();
1490 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1492 highlightActor = *it;
1495 mClippingDecorationActors.clear();
1497 self.Add( mRenderableActor );
1499 if ( mBackgroundActor )
1501 if ( mDecorator && mDecorator->IsHighlightVisible() )
1503 self.Add( mBackgroundActor );
1504 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1505 mBackgroundActor.LowerBelow( highlightActor );
1509 mRenderableActor.Add( mBackgroundActor );
1510 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1511 mBackgroundActor.LowerToBottom();
1517 void TextField::OnKeyInputFocusGained()
1519 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1520 if ( mInputMethodContext && IsEditable() )
1522 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1524 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1526 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1528 // Notify that the text editing start.
1529 mInputMethodContext.Activate();
1531 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1532 mInputMethodContext.SetRestoreAfterFocusLost( true );
1534 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1538 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1541 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1543 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1546 void TextField::OnKeyInputFocusLost()
1548 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1549 if ( mInputMethodContext )
1551 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1552 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1553 mInputMethodContext.SetRestoreAfterFocusLost( false );
1555 // Notify that the text editing finish.
1556 mInputMethodContext.Deactivate();
1558 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1560 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1564 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1567 mController->KeyboardFocusLostEvent();
1569 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1572 bool TextField::OnAccessibilityActivated()
1578 void TextField::OnTap( const TapGesture& gesture )
1580 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1581 if ( mInputMethodContext && IsEditable() )
1583 mInputMethodContext.Activate();
1585 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1587 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1588 const Vector2& localPoint = gesture.GetLocalPoint();
1589 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1594 void TextField::OnPan( const PanGesture& gesture )
1596 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1599 void TextField::OnLongPress( const LongPressGesture& gesture )
1601 if ( mInputMethodContext && IsEditable() )
1603 mInputMethodContext.Activate();
1606 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1607 const Vector2& localPoint = gesture.GetLocalPoint();
1608 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1613 bool TextField::OnKeyEvent( const KeyEvent& event )
1615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1617 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1619 // Make sure ClearKeyInputFocus when only key is up
1620 if( event.GetState() == KeyEvent::UP )
1622 ClearKeyInputFocus();
1627 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1629 // Do nothing when enter is comming.
1633 return mController->KeyEvent( event );
1636 void TextField::RequestTextRelayout()
1641 bool TextField::IsEditable() const
1643 return mController->IsEditable();
1646 void TextField::SetEditable( bool editable )
1648 mController->SetEditable(editable);
1649 if ( mInputMethodContext && !editable )
1651 mInputMethodContext.Deactivate();
1655 void TextField::TextInserted( unsigned int position, unsigned int length, const std::string &content )
1657 if( Accessibility::IsUp() )
1659 Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content );
1663 void TextField::TextDeleted( unsigned int position, unsigned int length, const std::string &content )
1665 if( Accessibility::IsUp() )
1667 Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content );
1671 void TextField::CaretMoved( unsigned int position )
1673 if( Accessibility::IsUp() )
1675 Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position );
1679 void TextField::TextChanged()
1681 Dali::Toolkit::TextField handle( GetOwner() );
1682 mTextChangedSignal.Emit( handle );
1685 void TextField::MaxLengthReached()
1687 Dali::Toolkit::TextField handle( GetOwner() );
1688 mMaxLengthReachedSignal.Emit( handle );
1691 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1693 Dali::Toolkit::TextField handle( GetOwner() );
1695 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1697 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1699 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1701 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1703 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1705 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1707 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1709 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1711 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1713 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1715 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1717 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1719 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1721 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1723 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1725 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1727 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1729 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1731 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1733 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1735 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1738 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1741 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1747 mClippingDecorationActors.push_back( actor );
1751 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1752 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1753 Self().Add( actor );
1754 mActiveLayer = actor;
1759 void TextField::OnSceneConnect( Dali::Actor actor )
1761 if ( mHasBeenStaged )
1763 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1767 mHasBeenStaged = true;
1771 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1773 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1774 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1777 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1782 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1787 void TextField::EnableClipping()
1791 // Creates an extra control to be used as stencil buffer.
1792 mStencil = Control::New();
1793 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1794 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1796 // Creates a background visual. Even if the color is transparent it updates the stencil.
1797 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1798 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1799 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1801 // Enable the clipping property.
1802 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1803 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1805 Self().Add( mStencil );
1809 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1811 mController->PasteClipboardItemEvent();
1814 void TextField::KeyboardStatusChanged(bool keyboardShown)
1816 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1818 // Just hide the grab handle when keyboard is hidden.
1819 if (!keyboardShown )
1821 mController->KeyboardFocusLostEvent();
1825 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1829 void TextField::OnSceneConnection( int depth )
1831 // Sets the depth to the visuals inside the text's decorator.
1832 mDecorator->SetTextDepth( depth );
1834 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1836 // Call the Control::OnSceneConnection() to set the depth of the background.
1837 Control::OnSceneConnection( depth );
1840 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1845 void TextField::OnIdleSignal()
1847 // Emits the change of input style signals.
1848 mController->ProcessInputStyleChangedSignals();
1850 // Set the pointer to null as the callback manager deletes the callback after execute it.
1851 mIdleCallback = NULL;
1854 TextField::TextField()
1855 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1856 mIdleCallback( NULL ),
1857 mAlignmentOffset( 0.f ),
1858 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1859 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1860 mHasBeenStaged( false )
1864 TextField::~TextField()
1866 UnparentAndReset( mStencil );
1868 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1870 Adaptor::Get().RemoveIdle( mIdleCallback );
1874 std::string TextField::AccessibleImpl::GetName()
1876 auto slf = Toolkit::TextField::DownCast( self );
1877 return slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1880 std::string TextField::AccessibleImpl::GetText( size_t startOffset,
1883 if( endOffset <= startOffset )
1886 auto slf = Toolkit::TextField::DownCast( self );
1888 slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1890 if( startOffset > txt.size() || endOffset > txt.size() )
1893 return txt.substr( startOffset, endOffset - startOffset );
1896 size_t TextField::AccessibleImpl::GetCharacterCount()
1898 auto slf = Toolkit::TextField::DownCast( self );
1900 slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1905 size_t TextField::AccessibleImpl::GetCaretOffset()
1907 auto slf = Toolkit::TextField::DownCast( self );
1908 return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition();
1911 bool TextField::AccessibleImpl::SetCaretOffset(size_t offset)
1913 auto slf = Toolkit::TextField::DownCast( self );
1914 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1915 if (offset > txt.size())
1918 auto& slfImpl = Dali::Toolkit::GetImpl( slf );
1919 slfImpl.getController()->ResetCursorPosition( offset );
1920 slfImpl.RequestTextRelayout();
1924 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1925 size_t offset, Dali::Accessibility::TextBoundary boundary )
1927 auto slf = Toolkit::TextField::DownCast( self );
1928 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1929 auto txt_size = txt.size();
1931 auto range = Dali::Accessibility::Range{};
1935 case Dali::Accessibility::TextBoundary::CHARACTER:
1937 if (offset < txt_size)
1939 range.content = txt[offset];
1940 range.startOffset = offset;
1941 range.endOffset = offset + 1;
1945 case Dali::Accessibility::TextBoundary::WORD:
1946 case Dali::Accessibility::TextBoundary::LINE:
1948 auto txt_c_string = txt.c_str();
1949 auto breaks = std::vector< char >( txt_size, 0 );
1950 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1951 Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1953 Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1956 while( index < txt_size && counter <= offset )
1961 while(breaks[index])
1967 if (boundary == Dali::Accessibility::TextBoundary::WORD)
1969 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1972 if ((counter > 0) && ((counter - 1) == offset))
1974 range.content = txt.substr(start, index - start + 1);
1975 range.startOffset = start;
1976 range.endOffset = index + 1;
1978 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1983 case Dali::Accessibility::TextBoundary::SENTENCE:
1985 /* not supported by efl */
1988 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1990 /* Paragraph is not supported by libunibreak library */
2000 Dali::Accessibility::Range
2001 TextField::AccessibleImpl::GetSelection( size_t selectionNum )
2003 // Since DALi supports only one selection indexes higher than 0 are ignored
2004 if( selectionNum > 0 )
2007 auto slf = Toolkit::TextField::DownCast( self );
2008 auto ctrl = Dali::Toolkit::GetImpl( slf ).getController();
2010 ctrl->RetrieveSelection( ret );
2011 auto r = ctrl->GetSelectionIndexes();
2013 return { static_cast<size_t>(r.first), static_cast<size_t>(r.second), ret };
2016 bool TextField::AccessibleImpl::RemoveSelection( size_t selectionNum )
2018 // Since DALi supports only one selection indexes higher than 0 are ignored
2019 if( selectionNum > 0 )
2022 auto slf = Toolkit::TextField::DownCast( self );
2023 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
2027 bool TextField::AccessibleImpl::SetSelection( size_t selectionNum,
2031 // Since DALi supports only one selection indexes higher than 0 are ignored
2032 if( selectionNum > 0 )
2035 auto slf = Toolkit::TextField::DownCast( self );
2036 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
2041 bool TextField::AccessibleImpl::CopyText( size_t startPosition,
2042 size_t endPosition )
2044 if( endPosition <= startPosition )
2047 auto slf = Toolkit::TextField::DownCast( self );
2048 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2049 Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2054 bool TextField::AccessibleImpl::CutText( size_t startPosition,
2055 size_t endPosition )
2057 if( endPosition <= startPosition )
2060 auto slf = Toolkit::TextField::DownCast( self );
2061 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2062 Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2064 slf.SetProperty( Toolkit::TextField::Property::TEXT,
2065 txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size()));
2070 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
2072 using namespace Dali::Accessibility;
2074 auto states = Control::Impl::AccessibleImpl::CalculateStates();
2076 states[State::EDITABLE] = true;
2077 states[State::FOCUSABLE] = true;
2079 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
2080 if (self == focusControl)
2082 states[State::FOCUSED] = true;
2088 } // namespace Internal
2090 } // namespace Toolkit