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 )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
147 DALI_TYPE_REGISTRATION_END()
149 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
151 /// Retrieves a filename from a value that is a Property::Map
152 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
154 std::string filename;
155 const Property::Map* map = value.GetMap();
158 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
161 filenameValue->Get( filename );
169 Toolkit::TextField TextField::New()
171 // Create the implementation, temporarily owned by this handle on stack
172 IntrusivePtr< TextField > impl = new TextField();
174 // Pass ownership to CustomActor handle
175 Toolkit::TextField handle( *impl );
177 // Second-phase init of the implementation
178 // This can only be done after the CustomActor connection has been made...
184 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
186 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
188 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
192 TextField& impl( GetImpl( textField ) );
193 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
194 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
198 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
200 int backend = value.Get< int >();
201 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
203 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
204 if( DevelText::RENDERING_VECTOR_BASED == backend )
206 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
209 if( impl.mRenderingBackend != backend )
211 impl.mRenderingBackend = backend;
212 impl.mRenderer.Reset();
214 // When using the vector-based rendering, the size of the GLyphs are different
215 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
216 impl.mController->SetGlyphType( glyphType );
220 case Toolkit::TextField::Property::TEXT:
222 const std::string& text = value.Get< std::string >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
225 impl.mController->SetText( text );
228 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
230 const std::string& text = value.Get< std::string >();
231 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
233 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
236 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
238 const std::string& text = value.Get< std::string >();
239 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
241 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
244 case Toolkit::TextField::Property::FONT_FAMILY:
246 const std::string& fontFamily = value.Get< std::string >();
247 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
248 impl.mController->SetDefaultFontFamily( fontFamily );
251 case Toolkit::TextField::Property::FONT_STYLE:
253 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
256 case Toolkit::TextField::Property::POINT_SIZE:
258 const float pointSize = value.Get< float >();
259 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
261 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
263 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
267 case Toolkit::TextField::Property::MAX_LENGTH:
269 const int max = value.Get< int >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
272 impl.mController->SetMaximumNumberOfCharacters( max );
275 case Toolkit::TextField::Property::EXCEED_POLICY:
277 impl.mExceedPolicy = value.Get<int>();
279 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
281 impl.EnableClipping();
285 UnparentAndReset( impl.mStencil );
287 impl.RequestTextRelayout();
290 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
292 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
293 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
295 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
296 impl.mController->SetHorizontalAlignment( alignment );
300 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
302 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
303 if( GetVerticalAlignmentEnumeration( value, alignment ) )
305 impl.mController->SetVerticalAlignment( alignment );
306 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
310 case Toolkit::TextField::Property::TEXT_COLOR:
312 const Vector4& textColor = value.Get< Vector4 >();
313 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 );
315 if( impl.mController->GetDefaultColor() != textColor )
317 impl.mController->SetDefaultColor( textColor );
318 impl.mController->SetInputColor( textColor );
319 impl.mRenderer.Reset();
323 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
325 const Vector4& textColor = value.Get< Vector4 >();
326 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 );
328 if( impl.mController->GetPlaceholderTextColor() != textColor )
330 impl.mController->SetPlaceholderTextColor( textColor );
331 impl.mRenderer.Reset();
335 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
337 const Vector4& color = value.Get< Vector4 >();
338 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 );
340 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
341 impl.RequestTextRelayout();
344 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
346 const Vector4& color = value.Get< Vector4 >();
347 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 );
349 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
350 impl.RequestTextRelayout();
353 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
355 const bool enable = value.Get< bool >();
356 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
358 impl.mController->SetEnableCursorBlink( enable );
359 impl.RequestTextRelayout();
362 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
364 const float interval = value.Get< float >();
365 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
367 impl.mDecorator->SetCursorBlinkInterval( interval );
370 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
372 const float duration = value.Get< float >();
373 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
375 impl.mDecorator->SetCursorBlinkDuration( duration );
378 case Toolkit::TextField::Property::CURSOR_WIDTH:
380 const int width = value.Get< int >();
381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
383 impl.mDecorator->SetCursorWidth( width );
384 impl.mController->GetLayoutEngine().SetCursorWidth( width );
387 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
389 const std::string imageFileName = value.Get< std::string >();
390 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
392 if( imageFileName.size() )
394 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
395 impl.RequestTextRelayout();
399 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
401 const std::string imageFileName = value.Get< std::string >();
402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
404 if( imageFileName.size() )
406 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
407 impl.RequestTextRelayout();
411 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
413 const float threshold = value.Get< float >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
416 impl.mDecorator->SetScrollThreshold( threshold );
419 case Toolkit::TextField::Property::SCROLL_SPEED:
421 const float speed = value.Get< float >();
422 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
424 impl.mDecorator->SetScrollSpeed( speed );
427 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
429 const std::string filename = GetImageFileNameFromPropertyValue( value );
431 if( filename.size() )
433 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
434 impl.RequestTextRelayout();
438 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
440 const std::string filename = GetImageFileNameFromPropertyValue( value );
442 if( filename.size() )
444 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
445 impl.RequestTextRelayout();
449 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
451 const std::string filename = GetImageFileNameFromPropertyValue( value );
453 if( filename.size() )
455 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
456 impl.RequestTextRelayout();
460 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
462 const std::string filename = GetImageFileNameFromPropertyValue( value );
464 if( filename.size() )
466 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
467 impl.RequestTextRelayout();
471 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
473 const std::string filename = GetImageFileNameFromPropertyValue( value );
475 if( filename.size() )
477 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
478 impl.RequestTextRelayout();
482 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
484 const std::string filename = GetImageFileNameFromPropertyValue( value );
486 if( filename.size() )
488 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
489 impl.RequestTextRelayout();
493 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
495 const Vector4 color = value.Get< Vector4 >();
496 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 );
498 impl.mDecorator->SetHighlightColor( color );
499 impl.RequestTextRelayout();
502 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
504 const Rect<int> box = value.Get< Rect<int> >();
505 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 );
507 impl.mDecorator->SetBoundingBox( box );
508 impl.RequestTextRelayout();
511 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
513 const Property::Map* map = value.GetMap();
516 impl.mInputMethodOptions.ApplyProperty( *map );
518 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
520 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
521 if (control == textField)
523 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
527 case Toolkit::TextField::Property::INPUT_COLOR:
529 const Vector4 inputColor = value.Get< Vector4 >();
530 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 );
532 impl.mController->SetInputColor( inputColor );
535 case Toolkit::TextField::Property::ENABLE_MARKUP:
537 const bool enableMarkup = value.Get<bool>();
538 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
540 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
543 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
545 const std::string& fontFamily = value.Get< std::string >();
546 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
547 impl.mController->SetInputFontFamily( fontFamily );
550 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
552 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
555 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
557 const float pointSize = value.Get< float >();
558 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
559 impl.mController->SetInputFontPointSize( pointSize );
562 case Toolkit::TextField::Property::UNDERLINE:
564 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
567 impl.mRenderer.Reset();
571 case Toolkit::TextField::Property::INPUT_UNDERLINE:
573 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
576 impl.mRenderer.Reset();
580 case Toolkit::TextField::Property::SHADOW:
582 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
585 impl.mRenderer.Reset();
589 case Toolkit::TextField::Property::INPUT_SHADOW:
591 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
594 impl.mRenderer.Reset();
598 case Toolkit::TextField::Property::EMBOSS:
600 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
603 impl.mRenderer.Reset();
607 case Toolkit::TextField::Property::INPUT_EMBOSS:
609 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
612 impl.mRenderer.Reset();
616 case Toolkit::TextField::Property::OUTLINE:
618 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
621 impl.mRenderer.Reset();
625 case Toolkit::TextField::Property::INPUT_OUTLINE:
627 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
630 impl.mRenderer.Reset();
634 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
636 const Property::Map* map = value.GetMap();
639 impl.mController->SetHiddenInputOption(*map);
643 case Toolkit::TextField::Property::PIXEL_SIZE:
645 const float pixelSize = value.Get< float >();
646 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
648 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
650 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
654 case Toolkit::TextField::Property::ENABLE_SELECTION:
656 const bool enableSelection = value.Get< bool >();
657 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
658 impl.mController->SetSelectionEnabled( enableSelection );
661 case Toolkit::TextField::Property::PLACEHOLDER:
663 const Property::Map* map = value.GetMap();
666 impl.mController->SetPlaceholderProperty( *map );
670 case Toolkit::TextField::Property::ELLIPSIS:
672 const bool ellipsis = value.Get<bool>();
673 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
675 impl.mController->SetTextElideEnabled( ellipsis );
678 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
680 const bool shiftSelection = value.Get<bool>();
681 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
683 impl.mController->SetShiftSelectionEnabled( shiftSelection );
686 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
688 const bool grabHandleEnabled = value.Get<bool>();
689 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
691 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
694 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
696 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
699 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
701 const bool grabHandlePopupEnabled = value.Get<bool>();
702 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
704 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
707 case Toolkit::DevelTextField::Property::BACKGROUND:
709 const Vector4 backgroundColor = value.Get< Vector4 >();
710 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 );
712 impl.mController->SetBackgroundEnabled( true );
713 impl.mController->SetBackgroundColor( backgroundColor );
716 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
718 uint32_t start = static_cast<uint32_t>(value.Get< int >());
719 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
720 impl.SetTextSelectionRange( &start, nullptr );
723 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
725 uint32_t end = static_cast<uint32_t>(value.Get< int >());
726 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
727 impl.SetTextSelectionRange( nullptr, &end );
730 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
732 const bool editable = value.Get< bool >();
733 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
734 impl.SetEditable( editable );
737 case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
739 const float scale = value.Get< float >();
740 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale );
742 if( !Equals( impl.mController->GetFontSizeScale(), scale ) )
744 impl.mController->SetFontSizeScale( scale );
752 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
754 Property::Value value;
756 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
760 TextField& impl( GetImpl( textField ) );
761 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
762 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
766 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
768 value = impl.mRenderingBackend;
771 case Toolkit::TextField::Property::TEXT:
774 impl.mController->GetText( text );
775 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
779 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
782 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
786 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
789 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
793 case Toolkit::TextField::Property::FONT_FAMILY:
795 value = impl.mController->GetDefaultFontFamily();
798 case Toolkit::TextField::Property::FONT_STYLE:
800 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
803 case Toolkit::TextField::Property::POINT_SIZE:
805 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
808 case Toolkit::TextField::Property::MAX_LENGTH:
810 value = impl.mController->GetMaximumNumberOfCharacters();
813 case Toolkit::TextField::Property::EXCEED_POLICY:
815 value = impl.mExceedPolicy;
818 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
820 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
824 value = std::string( name );
828 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
830 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
834 value = std::string( name );
838 case Toolkit::TextField::Property::TEXT_COLOR:
840 value = impl.mController->GetDefaultColor();
843 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
845 value = impl.mController->GetPlaceholderTextColor();
848 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
850 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
853 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
855 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
858 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
860 value = impl.mController->GetEnableCursorBlink();
863 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
865 value = impl.mDecorator->GetCursorBlinkInterval();
868 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
870 value = impl.mDecorator->GetCursorBlinkDuration();
873 case Toolkit::TextField::Property::CURSOR_WIDTH:
875 value = impl.mDecorator->GetCursorWidth();
878 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
880 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
883 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
885 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
888 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
890 value = impl.mDecorator->GetScrollThreshold();
893 case Toolkit::TextField::Property::SCROLL_SPEED:
895 value = impl.mDecorator->GetScrollSpeed();
898 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
900 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
903 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
905 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
908 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
910 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
913 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
915 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
918 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
920 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
923 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
925 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
928 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
930 value = impl.mDecorator->GetHighlightColor();
933 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
935 Rect<int> boundingBox;
936 impl.mDecorator->GetBoundingBox( boundingBox );
940 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
943 impl.mInputMethodOptions.RetrieveProperty( map );
947 case Toolkit::TextField::Property::INPUT_COLOR:
949 value = impl.mController->GetInputColor();
952 case Toolkit::TextField::Property::ENABLE_MARKUP:
954 value = impl.mController->IsMarkupProcessorEnabled();
957 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
959 value = impl.mController->GetInputFontFamily();
962 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
964 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
967 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
969 value = impl.mController->GetInputFontPointSize();
972 case Toolkit::TextField::Property::UNDERLINE:
974 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
977 case Toolkit::TextField::Property::INPUT_UNDERLINE:
979 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
982 case Toolkit::TextField::Property::SHADOW:
984 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
987 case Toolkit::TextField::Property::INPUT_SHADOW:
989 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
992 case Toolkit::TextField::Property::EMBOSS:
994 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
997 case Toolkit::TextField::Property::INPUT_EMBOSS:
999 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1002 case Toolkit::TextField::Property::OUTLINE:
1004 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1007 case Toolkit::TextField::Property::INPUT_OUTLINE:
1009 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1012 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1015 impl.mController->GetHiddenInputOption(map);
1019 case Toolkit::TextField::Property::PIXEL_SIZE:
1021 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1024 case Toolkit::TextField::Property::ENABLE_SELECTION:
1026 value = impl.mController->IsSelectionEnabled();
1029 case Toolkit::TextField::Property::PLACEHOLDER:
1032 impl.mController->GetPlaceholderProperty( map );
1036 case Toolkit::TextField::Property::ELLIPSIS:
1038 value = impl.mController->IsTextElideEnabled();
1041 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1043 value = impl.mController->IsShiftSelectionEnabled();
1046 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1048 value = impl.mController->IsGrabHandleEnabled();
1051 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1053 value = impl.mController->IsMatchSystemLanguageDirection();
1056 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1058 value = impl.mController->IsGrabHandlePopupEnabled();
1061 case Toolkit::DevelTextField::Property::BACKGROUND:
1063 value = impl.mController->GetBackgroundColor();
1066 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1068 value = impl.mController->GetSelectedText( );
1071 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1073 Uint32Pair range = impl.GetTextSelectionRange( );
1074 value = static_cast<int>(range.first);
1077 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1079 Uint32Pair range = impl.GetTextSelectionRange( );
1080 value = static_cast<int>(range.second);
1083 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1085 value = impl.IsEditable();
1088 case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE:
1090 value = impl.mController->GetFontSizeScale();
1099 void TextField::SelectWholeText()
1101 if( mController && mController->IsShowingRealText() )
1103 mController->SelectWholeText();
1108 void TextField::SelectNone()
1110 if( mController && mController->IsShowingRealText() )
1112 mController->SelectNone();
1116 string TextField::GetSelectedText() const
1118 string selectedText = "";
1119 if( mController && mController->IsShowingRealText() )
1121 selectedText = mController->GetSelectedText( );
1123 return selectedText;
1126 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1128 if( mController && mController->IsShowingRealText() )
1130 mController->SetTextSelectionRange( start, end );
1135 Uint32Pair TextField::GetTextSelectionRange() const
1138 if( mController && mController->IsShowingRealText() )
1140 range = mController->GetTextSelectionRange();
1146 InputMethodContext TextField::GetInputMethodContext()
1148 return mInputMethodContext;
1151 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1153 Dali::BaseHandle handle( object );
1155 bool connected( true );
1156 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1158 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1160 field.TextChangedSignal().Connect( tracker, functor );
1162 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1164 field.MaxLengthReachedSignal().Connect( tracker, functor );
1166 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1168 field.InputStyleChangedSignal().Connect( tracker, functor );
1172 // signalName does not match any signal
1179 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1181 return mTextChangedSignal;
1184 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1186 return mMaxLengthReachedSignal;
1189 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1191 return mInputStyleChangedSignal;
1194 void TextField::OnInitialize()
1196 Actor self = Self();
1198 mController = Text::Controller::New( this, this ,this);
1200 // When using the vector-based rendering, the size of the GLyphs are different
1201 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1202 mController->SetGlyphType( glyphType );
1204 mDecorator = Text::Decorator::New( *mController,
1207 mInputMethodContext = InputMethodContext::New( self );
1209 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1211 // Enables the text input.
1212 mController->EnableTextInput( mDecorator, mInputMethodContext );
1214 // Enables the horizontal scrolling after the text input has been enabled.
1215 mController->SetHorizontalScrollEnabled( true );
1217 // Disables the vertical scrolling.
1218 mController->SetVerticalScrollEnabled( false );
1220 // Disable the smooth handle panning.
1221 mController->SetSmoothHandlePanEnabled( false );
1223 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1224 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1226 // Sets layoutDirection value
1227 Dali::Stage stage = Dali::Stage::GetCurrent();
1228 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1229 mController->SetLayoutDirection( layoutDirection );
1231 // Forward input events to controller
1232 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1233 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1235 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1237 // Set BoundingBox to stage size if not already set.
1238 Rect<int> boundingBox;
1239 mDecorator->GetBoundingBox( boundingBox );
1241 if( boundingBox.IsEmpty() )
1243 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1244 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1247 // Flip vertically the 'left' selection handle
1248 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1250 // Fill-parent area by default
1251 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1252 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1253 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1255 //Enable highightability
1256 self.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true );
1258 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1260 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1265 DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) {
1266 return std::unique_ptr< Dali::Accessibility::Accessible >(
1267 new AccessibleImpl( actor, Dali::Accessibility::Role::ENTRY ) );
1271 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1273 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1277 case StyleChange::DEFAULT_FONT_CHANGE:
1279 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1280 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1281 // Property system did not set the font so should update it.
1282 mController->UpdateAfterFontChange( newFont );
1287 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1289 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1293 case StyleChange::THEME_CHANGE:
1295 // Nothing to do, let control base class handle this
1300 // Up call to Control
1301 Control::OnStyleChange( styleManager, change );
1304 Vector3 TextField::GetNaturalSize()
1307 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1309 Vector3 naturalSize = mController->GetNaturalSize();
1310 naturalSize.width += ( padding.start + padding.end );
1311 naturalSize.height += ( padding.top + padding.bottom );
1316 float TextField::GetHeightForWidth( float width )
1319 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1320 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1323 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1325 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1327 Actor self = Self();
1330 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1332 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1334 // Support Right-To-Left of padding
1335 Dali::LayoutDirection::Type layoutDirection;
1336 if( mController->IsMatchSystemLanguageDirection() )
1338 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1342 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1344 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1346 std::swap( padding.start, padding.end );
1351 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1355 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1358 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1360 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1363 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1366 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1368 mDecorator->Relayout( size );
1373 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1376 RenderText( updateTextType );
1380 // The text-field emits signals when the input style changes. These changes of style are
1381 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1382 // can't be emitted during the size negotiation as the callbacks may update the UI.
1383 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1384 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1386 if( Adaptor::IsAvailable() )
1388 Adaptor& adaptor = Adaptor::Get();
1390 if( NULL == mIdleCallback )
1392 // @note: The callback manager takes the ownership of the callback object.
1393 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1394 adaptor.AddIdle( mIdleCallback, false );
1400 Text::ControllerPtr TextField::getController() { return mController; }
1402 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1404 Actor renderableActor;
1406 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1410 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1412 renderableActor = mRenderer->Render( mController->GetView(),
1414 Property::INVALID_INDEX, // Animatable property not supported
1416 DepthIndex::CONTENT );
1419 if( renderableActor != mRenderableActor )
1421 UnparentAndReset( mBackgroundActor );
1422 UnparentAndReset( mRenderableActor );
1423 mRenderableActor = renderableActor;
1425 if ( mRenderableActor )
1427 mBackgroundActor = mController->CreateBackgroundActor();
1432 if( mRenderableActor )
1434 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1436 float renderableActorPositionX, renderableActorPositionY;
1440 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1441 renderableActorPositionY = scrollOffset.y;
1446 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1448 // Support Right-To-Left of padding
1449 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1450 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1452 std::swap( padding.start, padding.end );
1455 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1456 renderableActorPositionY = scrollOffset.y + padding.top;
1459 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1461 // Make sure the actors are parented correctly with/without clipping
1462 Actor self = mStencil ? mStencil : Self();
1464 Actor highlightActor;
1466 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1467 endIt = mClippingDecorationActors.end();
1472 it->LowerToBottom();
1474 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1476 highlightActor = *it;
1479 mClippingDecorationActors.clear();
1481 self.Add( mRenderableActor );
1483 if ( mBackgroundActor )
1485 if ( mDecorator && mDecorator->IsHighlightVisible() )
1487 self.Add( mBackgroundActor );
1488 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1489 mBackgroundActor.LowerBelow( highlightActor );
1493 mRenderableActor.Add( mBackgroundActor );
1494 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1495 mBackgroundActor.LowerToBottom();
1501 void TextField::OnKeyInputFocusGained()
1503 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1504 if ( mInputMethodContext && IsEditable() )
1506 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1508 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1510 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1512 // Notify that the text editing start.
1513 mInputMethodContext.Activate();
1515 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1516 mInputMethodContext.SetRestoreAfterFocusLost( true );
1518 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1522 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1525 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1527 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1530 void TextField::OnKeyInputFocusLost()
1532 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1533 if ( mInputMethodContext )
1535 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1536 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1537 mInputMethodContext.SetRestoreAfterFocusLost( false );
1539 // Notify that the text editing finish.
1540 mInputMethodContext.Deactivate();
1542 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1544 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1548 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1551 mController->KeyboardFocusLostEvent();
1553 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1556 bool TextField::OnAccessibilityActivated()
1562 void TextField::OnTap( const TapGesture& gesture )
1564 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1565 if ( mInputMethodContext && IsEditable() )
1567 mInputMethodContext.Activate();
1569 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1571 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1572 const Vector2& localPoint = gesture.GetLocalPoint();
1573 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1578 void TextField::OnPan( const PanGesture& gesture )
1580 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1583 void TextField::OnLongPress( const LongPressGesture& gesture )
1585 if ( mInputMethodContext && IsEditable() )
1587 mInputMethodContext.Activate();
1590 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1591 const Vector2& localPoint = gesture.GetLocalPoint();
1592 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1597 bool TextField::OnKeyEvent( const KeyEvent& event )
1599 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1601 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1603 // Make sure ClearKeyInputFocus when only key is up
1604 if( event.GetState() == KeyEvent::UP )
1606 ClearKeyInputFocus();
1611 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1613 // Do nothing when enter is comming.
1617 return mController->KeyEvent( event );
1620 void TextField::RequestTextRelayout()
1625 bool TextField::IsEditable() const
1627 return mController->IsEditable();
1630 void TextField::SetEditable( bool editable )
1632 mController->SetEditable(editable);
1633 if ( mInputMethodContext && !editable )
1635 mInputMethodContext.Deactivate();
1639 void TextField::TextInserted( unsigned int position, unsigned int length, const std::string &content )
1641 if( Accessibility::IsUp() )
1643 Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content );
1647 void TextField::TextDeleted( unsigned int position, unsigned int length, const std::string &content )
1649 if( Accessibility::IsUp() )
1651 Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content );
1655 void TextField::CaretMoved( unsigned int position )
1657 if( Accessibility::IsUp() )
1659 Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position );
1663 void TextField::TextChanged()
1665 Dali::Toolkit::TextField handle( GetOwner() );
1666 mTextChangedSignal.Emit( handle );
1669 void TextField::MaxLengthReached()
1671 Dali::Toolkit::TextField handle( GetOwner() );
1672 mMaxLengthReachedSignal.Emit( handle );
1675 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1677 Dali::Toolkit::TextField handle( GetOwner() );
1679 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1681 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1683 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1685 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1687 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1689 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1691 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1693 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1695 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1697 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1699 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1701 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1703 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1705 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1707 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1709 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1711 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1713 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1715 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1717 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1719 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1722 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1725 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1731 mClippingDecorationActors.push_back( actor );
1735 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1736 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1737 Self().Add( actor );
1738 mActiveLayer = actor;
1743 void TextField::OnSceneConnect( Dali::Actor actor )
1745 if ( mHasBeenStaged )
1747 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1751 mHasBeenStaged = true;
1755 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1757 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1758 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1761 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1766 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1771 void TextField::EnableClipping()
1775 // Creates an extra control to be used as stencil buffer.
1776 mStencil = Control::New();
1777 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1778 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1780 // Creates a background visual. Even if the color is transparent it updates the stencil.
1781 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1782 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1783 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1785 // Enable the clipping property.
1786 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1787 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1789 Self().Add( mStencil );
1793 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1795 mController->PasteClipboardItemEvent();
1798 void TextField::KeyboardStatusChanged(bool keyboardShown)
1800 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1802 // Just hide the grab handle when keyboard is hidden.
1803 if (!keyboardShown )
1805 mController->KeyboardFocusLostEvent();
1809 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1813 void TextField::OnSceneConnection( int depth )
1815 // Sets the depth to the visuals inside the text's decorator.
1816 mDecorator->SetTextDepth( depth );
1818 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1820 // Call the Control::OnSceneConnection() to set the depth of the background.
1821 Control::OnSceneConnection( depth );
1824 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1829 void TextField::OnIdleSignal()
1831 // Emits the change of input style signals.
1832 mController->ProcessInputStyleChangedSignals();
1834 // Set the pointer to null as the callback manager deletes the callback after execute it.
1835 mIdleCallback = NULL;
1838 TextField::TextField()
1839 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1840 mIdleCallback( NULL ),
1841 mAlignmentOffset( 0.f ),
1842 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1843 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1844 mHasBeenStaged( false )
1848 TextField::~TextField()
1850 UnparentAndReset( mStencil );
1852 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1854 Adaptor::Get().RemoveIdle( mIdleCallback );
1858 std::string TextField::AccessibleImpl::GetName()
1860 auto slf = Toolkit::TextField::DownCast( self );
1861 return slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1864 std::string TextField::AccessibleImpl::GetText( size_t startOffset,
1867 if( endOffset <= startOffset )
1870 auto slf = Toolkit::TextField::DownCast( self );
1872 slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1874 if( startOffset > txt.size() || endOffset > txt.size() )
1877 return txt.substr( startOffset, endOffset - startOffset );
1880 size_t TextField::AccessibleImpl::GetCharacterCount()
1882 auto slf = Toolkit::TextField::DownCast( self );
1884 slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1889 size_t TextField::AccessibleImpl::GetCaretOffset()
1891 auto slf = Toolkit::TextField::DownCast( self );
1892 return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition();
1895 bool TextField::AccessibleImpl::SetCaretOffset(size_t offset)
1897 auto slf = Toolkit::TextField::DownCast( self );
1898 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1899 if (offset > txt.size())
1902 auto& slfImpl = Dali::Toolkit::GetImpl( slf );
1903 slfImpl.getController()->ResetCursorPosition( offset );
1904 slfImpl.RequestTextRelayout();
1908 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1909 size_t offset, Dali::Accessibility::TextBoundary boundary )
1911 auto slf = Toolkit::TextField::DownCast( self );
1912 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get< std::string >();
1913 auto txt_size = txt.size();
1915 auto range = Dali::Accessibility::Range{};
1919 case Dali::Accessibility::TextBoundary::CHARACTER:
1921 if (offset < txt_size)
1923 range.content = txt[offset];
1924 range.startOffset = offset;
1925 range.endOffset = offset + 1;
1929 case Dali::Accessibility::TextBoundary::WORD:
1930 case Dali::Accessibility::TextBoundary::LINE:
1932 auto txt_c_string = txt.c_str();
1933 auto breaks = std::vector< char >( txt_size, 0 );
1934 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1935 Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1937 Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data());
1940 while( index < txt_size && counter <= offset )
1945 while(breaks[index])
1951 if (boundary == Dali::Accessibility::TextBoundary::WORD)
1953 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1956 if ((counter > 0) && ((counter - 1) == offset))
1958 range.content = txt.substr(start, index - start + 1);
1959 range.startOffset = start;
1960 range.endOffset = index + 1;
1962 if (boundary == Dali::Accessibility::TextBoundary::LINE)
1967 case Dali::Accessibility::TextBoundary::SENTENCE:
1969 /* not supported by efl */
1972 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1974 /* Paragraph is not supported by libunibreak library */
1984 Dali::Accessibility::Range
1985 TextField::AccessibleImpl::GetSelection( size_t selectionNum )
1987 // Since DALi supports only one selection indexes higher than 0 are ignored
1988 if( selectionNum > 0 )
1991 auto slf = Toolkit::TextField::DownCast( self );
1992 auto ctrl = Dali::Toolkit::GetImpl( slf ).getController();
1994 ctrl->RetrieveSelection( ret );
1995 auto r = ctrl->GetSelectionIndexes();
1997 return { static_cast<size_t>(r.first), static_cast<size_t>(r.second), ret };
2000 bool TextField::AccessibleImpl::RemoveSelection( size_t selectionNum )
2002 // Since DALi supports only one selection indexes higher than 0 are ignored
2003 if( selectionNum > 0 )
2006 auto slf = Toolkit::TextField::DownCast( self );
2007 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
2011 bool TextField::AccessibleImpl::SetSelection( size_t selectionNum,
2015 // Since DALi supports only one selection indexes higher than 0 are ignored
2016 if( selectionNum > 0 )
2019 auto slf = Toolkit::TextField::DownCast( self );
2020 Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
2025 bool TextField::AccessibleImpl::CopyText( size_t startPosition,
2026 size_t endPosition )
2028 if( endPosition <= startPosition )
2031 auto slf = Toolkit::TextField::DownCast( self );
2032 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2033 Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2038 bool TextField::AccessibleImpl::CutText( size_t startPosition,
2039 size_t endPosition )
2041 if( endPosition <= startPosition )
2044 auto slf = Toolkit::TextField::DownCast( self );
2045 auto txt = slf.GetProperty( Toolkit::TextField::Property::TEXT ).Get<std::string>();
2046 Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) );
2048 slf.SetProperty( Toolkit::TextField::Property::TEXT,
2049 txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size()));
2054 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
2056 using namespace Dali::Accessibility;
2058 auto states = Control::Impl::AccessibleImpl::CalculateStates();
2060 states[State::EDITABLE] = true;
2061 states[State::FOCUSABLE] = true;
2063 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
2064 if (self == focusControl)
2066 states[State::FOCUSED] = true;
2072 } // namespace Internal
2074 } // namespace Toolkit