2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/devel-api/adaptor-framework/key-devel.h>
26 #include <dali/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
42 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/rendering/text-backend.h>
45 #include <dali-toolkit/internal/text/text-effects-style.h>
46 #include <dali-toolkit/internal/text/text-font-style.h>
47 #include <dali-toolkit/internal/text/text-view.h>
48 #include <dali-toolkit/internal/styling/style-manager-impl.h>
49 #include <dali-toolkit/devel-api/controls/control-devel.h>
50 #include <dali/integration-api/adaptor-framework/adaptor.h>
52 using namespace Dali::Toolkit::Text;
63 namespace // unnamed namespace
66 #if defined(DEBUG_ENABLED)
67 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
70 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
71 } // unnamed namespace
78 return Toolkit::TextField::New();
81 // Setup properties, signals and actions using the type-registry.
82 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
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 if( impl.mController )
721 uint32_t start = static_cast<uint32_t>(value.Get< int >());
722 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
723 impl.SetTextSelectionRange( &start, nullptr );
727 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
729 if( impl.mController )
731 uint32_t end = static_cast<uint32_t>(value.Get< int >());
732 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
733 impl.SetTextSelectionRange( nullptr, &end );
737 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
739 const bool editable = value.Get< bool >();
740 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
741 impl.SetEditable( editable );
748 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
750 Property::Value value;
752 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
756 TextField& impl( GetImpl( textField ) );
757 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
758 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
762 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
764 value = impl.mRenderingBackend;
767 case Toolkit::TextField::Property::TEXT:
770 impl.mController->GetText( text );
771 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
775 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
778 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
782 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
785 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
789 case Toolkit::TextField::Property::FONT_FAMILY:
791 value = impl.mController->GetDefaultFontFamily();
794 case Toolkit::TextField::Property::FONT_STYLE:
796 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
799 case Toolkit::TextField::Property::POINT_SIZE:
801 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
804 case Toolkit::TextField::Property::MAX_LENGTH:
806 value = impl.mController->GetMaximumNumberOfCharacters();
809 case Toolkit::TextField::Property::EXCEED_POLICY:
811 value = impl.mExceedPolicy;
814 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
816 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
820 value = std::string( name );
824 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
826 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
830 value = std::string( name );
834 case Toolkit::TextField::Property::TEXT_COLOR:
836 value = impl.mController->GetDefaultColor();
839 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
841 value = impl.mController->GetPlaceholderTextColor();
844 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
846 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
849 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
851 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
854 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
856 value = impl.mController->GetEnableCursorBlink();
859 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
861 value = impl.mDecorator->GetCursorBlinkInterval();
864 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
866 value = impl.mDecorator->GetCursorBlinkDuration();
869 case Toolkit::TextField::Property::CURSOR_WIDTH:
871 value = impl.mDecorator->GetCursorWidth();
874 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
876 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
879 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
881 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
884 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
886 value = impl.mDecorator->GetScrollThreshold();
889 case Toolkit::TextField::Property::SCROLL_SPEED:
891 value = impl.mDecorator->GetScrollSpeed();
894 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
896 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
899 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
901 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
904 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
906 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
909 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
911 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
914 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
916 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
919 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
921 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
924 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
926 value = impl.mDecorator->GetHighlightColor();
929 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
931 Rect<int> boundingBox;
932 impl.mDecorator->GetBoundingBox( boundingBox );
936 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
939 impl.mInputMethodOptions.RetrieveProperty( map );
943 case Toolkit::TextField::Property::INPUT_COLOR:
945 value = impl.mController->GetInputColor();
948 case Toolkit::TextField::Property::ENABLE_MARKUP:
950 value = impl.mController->IsMarkupProcessorEnabled();
953 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
955 value = impl.mController->GetInputFontFamily();
958 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
960 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
963 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
965 value = impl.mController->GetInputFontPointSize();
968 case Toolkit::TextField::Property::UNDERLINE:
970 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
973 case Toolkit::TextField::Property::INPUT_UNDERLINE:
975 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
978 case Toolkit::TextField::Property::SHADOW:
980 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
983 case Toolkit::TextField::Property::INPUT_SHADOW:
985 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
988 case Toolkit::TextField::Property::EMBOSS:
990 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
993 case Toolkit::TextField::Property::INPUT_EMBOSS:
995 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
998 case Toolkit::TextField::Property::OUTLINE:
1000 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1003 case Toolkit::TextField::Property::INPUT_OUTLINE:
1005 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1008 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1011 impl.mController->GetHiddenInputOption(map);
1015 case Toolkit::TextField::Property::PIXEL_SIZE:
1017 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1020 case Toolkit::TextField::Property::ENABLE_SELECTION:
1022 value = impl.mController->IsSelectionEnabled();
1025 case Toolkit::TextField::Property::PLACEHOLDER:
1028 impl.mController->GetPlaceholderProperty( map );
1032 case Toolkit::TextField::Property::ELLIPSIS:
1034 value = impl.mController->IsTextElideEnabled();
1037 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1039 value = impl.mController->IsShiftSelectionEnabled();
1042 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1044 value = impl.mController->IsGrabHandleEnabled();
1047 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1049 value = impl.mController->IsMatchSystemLanguageDirection();
1052 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1054 value = impl.mController->IsGrabHandlePopupEnabled();
1057 case Toolkit::DevelTextField::Property::BACKGROUND:
1059 value = impl.mController->GetBackgroundColor();
1062 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1064 value = impl.mController->GetSelectedText( );
1067 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1069 Uint32Pair range = impl.GetTextSelectionRange( );
1070 value = static_cast<int>(range.first);
1073 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1075 Uint32Pair range = impl.GetTextSelectionRange( );
1076 value = static_cast<int>(range.second);
1079 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1081 value = impl.IsEditable();
1090 void TextField::SelectWholeText()
1092 if( mController && mController->IsShowingRealText() )
1094 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1099 void TextField::SelectNone()
1101 if( mController && mController->IsShowingRealText() )
1103 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1108 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1110 if( mController && mController->IsShowingRealText() )
1112 mController->SetTextSelectionRange( start, end );
1117 Uint32Pair TextField::GetTextSelectionRange() const
1120 if( mController && mController->IsShowingRealText() )
1122 range = mController->GetTextSelectionRange();
1128 InputMethodContext TextField::GetInputMethodContext()
1130 return mInputMethodContext;
1133 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1135 Dali::BaseHandle handle( object );
1137 bool connected( true );
1138 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1140 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1142 field.TextChangedSignal().Connect( tracker, functor );
1144 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1146 field.MaxLengthReachedSignal().Connect( tracker, functor );
1148 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1150 field.InputStyleChangedSignal().Connect( tracker, functor );
1154 // signalName does not match any signal
1161 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1163 return mTextChangedSignal;
1166 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1168 return mMaxLengthReachedSignal;
1171 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1173 return mInputStyleChangedSignal;
1176 void TextField::OnInitialize()
1178 Actor self = Self();
1180 mController = Text::Controller::New( this, this ,this);
1182 // When using the vector-based rendering, the size of the GLyphs are different
1183 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1184 mController->SetGlyphType( glyphType );
1186 mDecorator = Text::Decorator::New( *mController,
1189 mInputMethodContext = InputMethodContext::New( self );
1191 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1193 // Enables the text input.
1194 mController->EnableTextInput( mDecorator, mInputMethodContext );
1196 // Enables the horizontal scrolling after the text input has been enabled.
1197 mController->SetHorizontalScrollEnabled( true );
1199 // Disables the vertical scrolling.
1200 mController->SetVerticalScrollEnabled( false );
1202 // Disable the smooth handle panning.
1203 mController->SetSmoothHandlePanEnabled( false );
1205 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1206 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1208 // Sets layoutDirection value
1209 Dali::Stage stage = Dali::Stage::GetCurrent();
1210 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1211 mController->SetLayoutDirection( layoutDirection );
1213 // Forward input events to controller
1214 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1215 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1217 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1219 // Set BoundingBox to stage size if not already set.
1220 Rect<int> boundingBox;
1221 mDecorator->GetBoundingBox( boundingBox );
1223 if( boundingBox.IsEmpty() )
1225 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1226 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1229 // Flip vertically the 'left' selection handle
1230 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1232 // Fill-parent area by default
1233 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1234 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1235 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1237 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1239 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1245 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1247 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1251 case StyleChange::DEFAULT_FONT_CHANGE:
1253 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1254 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1255 // Property system did not set the font so should update it.
1256 mController->UpdateAfterFontChange( newFont );
1261 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1263 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1267 case StyleChange::THEME_CHANGE:
1269 // Nothing to do, let control base class handle this
1274 // Up call to Control
1275 Control::OnStyleChange( styleManager, change );
1278 Vector3 TextField::GetNaturalSize()
1281 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1283 Vector3 naturalSize = mController->GetNaturalSize();
1284 naturalSize.width += ( padding.start + padding.end );
1285 naturalSize.height += ( padding.top + padding.bottom );
1290 float TextField::GetHeightForWidth( float width )
1293 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1294 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1297 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1299 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1301 Actor self = Self();
1304 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1306 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1308 // Support Right-To-Left of padding
1309 Dali::LayoutDirection::Type layoutDirection;
1310 if( mController->IsMatchSystemLanguageDirection() )
1312 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1316 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1318 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1320 std::swap( padding.start, padding.end );
1325 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1329 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1332 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1334 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1337 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1340 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1342 mDecorator->Relayout( size );
1347 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1350 RenderText( updateTextType );
1354 // The text-field emits signals when the input style changes. These changes of style are
1355 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1356 // can't be emitted during the size negotiation as the callbacks may update the UI.
1357 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1358 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1360 if( Adaptor::IsAvailable() )
1362 Adaptor& adaptor = Adaptor::Get();
1364 if( NULL == mIdleCallback )
1366 // @note: The callback manager takes the ownership of the callback object.
1367 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1368 adaptor.AddIdle( mIdleCallback, false );
1374 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1376 Actor renderableActor;
1378 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1382 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1384 renderableActor = mRenderer->Render( mController->GetView(),
1386 Property::INVALID_INDEX, // Animatable property not supported
1388 DepthIndex::CONTENT );
1391 if( renderableActor != mRenderableActor )
1393 UnparentAndReset( mBackgroundActor );
1394 UnparentAndReset( mRenderableActor );
1395 mRenderableActor = renderableActor;
1397 if ( mRenderableActor )
1399 mBackgroundActor = mController->CreateBackgroundActor();
1404 if( mRenderableActor )
1406 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1408 float renderableActorPositionX, renderableActorPositionY;
1412 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1413 renderableActorPositionY = scrollOffset.y;
1418 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1420 // Support Right-To-Left of padding
1421 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1422 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1424 std::swap( padding.start, padding.end );
1427 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1428 renderableActorPositionY = scrollOffset.y + padding.top;
1431 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1433 // Make sure the actors are parented correctly with/without clipping
1434 Actor self = mStencil ? mStencil : Self();
1436 Actor highlightActor;
1438 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1439 endIt = mClippingDecorationActors.end();
1444 it->LowerToBottom();
1446 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1448 highlightActor = *it;
1451 mClippingDecorationActors.clear();
1453 self.Add( mRenderableActor );
1455 if ( mBackgroundActor )
1457 if ( mDecorator && mDecorator->IsHighlightVisible() )
1459 self.Add( mBackgroundActor );
1460 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1461 mBackgroundActor.LowerBelow( highlightActor );
1465 mRenderableActor.Add( mBackgroundActor );
1466 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1467 mBackgroundActor.LowerToBottom();
1473 void TextField::OnKeyInputFocusGained()
1475 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1476 if( mInputMethodContext && IsEditable() )
1478 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1480 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1482 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1484 // Notify that the text editing start.
1485 mInputMethodContext.Activate();
1487 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1488 mInputMethodContext.SetRestoreAfterFocusLost( true );
1491 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1494 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1497 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1498 Internal::Control& controlImpl = GetImplementation( control );
1499 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1500 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1501 if( enableAutofill )
1503 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1504 container.SetFocusedControl( control );
1506 Internal::AutofillContainer& containerImpl = GetImpl( container );
1507 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1508 if( containerGroup != nullptr )
1510 containerGroup.RequestAuthentication();
1514 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1516 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1519 void TextField::OnKeyInputFocusLost()
1521 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1522 if ( mInputMethodContext )
1524 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1525 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1526 mInputMethodContext.SetRestoreAfterFocusLost( false );
1528 // Notify that the text editing finish.
1529 mInputMethodContext.Deactivate();
1531 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1533 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1537 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1540 mController->KeyboardFocusLostEvent();
1542 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1545 void TextField::OnTap( const TapGesture& gesture )
1547 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1548 if ( mInputMethodContext && IsEditable() )
1550 mInputMethodContext.Activate();
1552 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1554 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1555 const Vector2& localPoint = gesture.GetLocalPoint();
1556 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1561 void TextField::OnPan( const PanGesture& gesture )
1563 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1566 void TextField::OnLongPress( const LongPressGesture& gesture )
1568 if ( mInputMethodContext && IsEditable() )
1570 mInputMethodContext.Activate();
1573 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1574 const Vector2& localPoint = gesture.GetLocalPoint();
1575 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1580 bool TextField::OnKeyEvent( const KeyEvent& event )
1582 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1584 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1586 // Make sure ClearKeyInputFocus when only key is up
1587 if( event.GetState() == KeyEvent::UP )
1589 ClearKeyInputFocus();
1594 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1596 // Do nothing when enter is comming.
1600 return mController->KeyEvent( event );
1603 void TextField::RequestTextRelayout()
1608 bool TextField::IsEditable() const
1610 return mController->IsEditable();
1613 void TextField::SetEditable( bool editable )
1615 mController->SetEditable(editable);
1616 if ( mInputMethodContext && !editable )
1618 mInputMethodContext.Deactivate();
1622 void TextField::TextChanged()
1624 Dali::Toolkit::TextField handle( GetOwner() );
1625 mTextChangedSignal.Emit( handle );
1628 void TextField::MaxLengthReached()
1630 Dali::Toolkit::TextField handle( GetOwner() );
1631 mMaxLengthReachedSignal.Emit( handle );
1634 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1636 Dali::Toolkit::TextField handle( GetOwner() );
1638 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1640 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1642 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1644 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1646 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1648 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1650 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1652 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1654 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1656 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1658 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1660 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1662 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1664 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1666 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1668 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1670 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1672 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1674 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1676 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1678 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1681 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1684 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1690 mClippingDecorationActors.push_back( actor );
1694 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1695 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1696 Self().Add( actor );
1697 mActiveLayer = actor;
1702 void TextField::OnSceneConnect( Dali::Actor actor )
1704 if ( mHasBeenStaged )
1706 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1710 mHasBeenStaged = true;
1714 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1716 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1717 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1720 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1725 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1730 void TextField::EnableClipping()
1734 // Creates an extra control to be used as stencil buffer.
1735 mStencil = Control::New();
1736 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1737 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1739 // Creates a background visual. Even if the color is transparent it updates the stencil.
1740 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1741 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1742 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1744 // Enable the clipping property.
1745 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1746 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1748 Self().Add( mStencil );
1752 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1754 mController->PasteClipboardItemEvent();
1757 void TextField::KeyboardStatusChanged(bool keyboardShown)
1759 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1761 // Just hide the grab handle when keyboard is hidden.
1762 if (!keyboardShown )
1764 mController->KeyboardFocusLostEvent();
1768 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1772 void TextField::OnSceneConnection( int depth )
1774 // Sets the depth to the visuals inside the text's decorator.
1775 mDecorator->SetTextDepth( depth );
1777 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1779 // Call the Control::OnSceneConnection() to set the depth of the background.
1780 Control::OnSceneConnection( depth );
1783 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1788 void TextField::OnIdleSignal()
1790 // Emits the change of input style signals.
1791 mController->ProcessInputStyleChangedSignals();
1793 // Set the pointer to null as the callback manager deletes the callback after execute it.
1794 mIdleCallback = NULL;
1797 TextField::TextField()
1798 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1799 mIdleCallback( NULL ),
1800 mAlignmentOffset( 0.f ),
1801 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1802 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1803 mHasBeenStaged( false )
1807 TextField::~TextField()
1809 UnparentAndReset( mStencil );
1811 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1813 Adaptor::Get().RemoveIdle( mIdleCallback );
1817 } // namespace Internal
1819 } // namespace Toolkit