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 )
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 if( impl.mController )
720 uint32_t start = static_cast<uint32_t>(value.Get< int >());
721 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
722 impl.SetTextSelectionRange( &start, nullptr );
726 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
728 if( impl.mController )
730 uint32_t end = static_cast<uint32_t>(value.Get< int >());
731 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
732 impl.SetTextSelectionRange( nullptr, &end );
740 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
742 Property::Value value;
744 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
748 TextField& impl( GetImpl( textField ) );
749 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
750 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
754 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
756 value = impl.mRenderingBackend;
759 case Toolkit::TextField::Property::TEXT:
762 impl.mController->GetText( text );
763 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
767 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
770 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
774 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
777 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
781 case Toolkit::TextField::Property::FONT_FAMILY:
783 value = impl.mController->GetDefaultFontFamily();
786 case Toolkit::TextField::Property::FONT_STYLE:
788 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
791 case Toolkit::TextField::Property::POINT_SIZE:
793 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
796 case Toolkit::TextField::Property::MAX_LENGTH:
798 value = impl.mController->GetMaximumNumberOfCharacters();
801 case Toolkit::TextField::Property::EXCEED_POLICY:
803 value = impl.mExceedPolicy;
806 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
808 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
812 value = std::string( name );
816 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
818 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
822 value = std::string( name );
826 case Toolkit::TextField::Property::TEXT_COLOR:
828 value = impl.mController->GetDefaultColor();
831 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
833 value = impl.mController->GetPlaceholderTextColor();
836 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
838 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
841 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
843 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
846 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
848 value = impl.mController->GetEnableCursorBlink();
851 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
853 value = impl.mDecorator->GetCursorBlinkInterval();
856 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
858 value = impl.mDecorator->GetCursorBlinkDuration();
861 case Toolkit::TextField::Property::CURSOR_WIDTH:
863 value = impl.mDecorator->GetCursorWidth();
866 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
868 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
871 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
873 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
876 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
878 value = impl.mDecorator->GetScrollThreshold();
881 case Toolkit::TextField::Property::SCROLL_SPEED:
883 value = impl.mDecorator->GetScrollSpeed();
886 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
888 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
891 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
893 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
896 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
898 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
901 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
903 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
906 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
908 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
911 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
913 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
916 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
918 value = impl.mDecorator->GetHighlightColor();
921 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
923 Rect<int> boundingBox;
924 impl.mDecorator->GetBoundingBox( boundingBox );
928 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
931 impl.mInputMethodOptions.RetrieveProperty( map );
935 case Toolkit::TextField::Property::INPUT_COLOR:
937 value = impl.mController->GetInputColor();
940 case Toolkit::TextField::Property::ENABLE_MARKUP:
942 value = impl.mController->IsMarkupProcessorEnabled();
945 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
947 value = impl.mController->GetInputFontFamily();
950 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
952 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
955 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
957 value = impl.mController->GetInputFontPointSize();
960 case Toolkit::TextField::Property::UNDERLINE:
962 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
965 case Toolkit::TextField::Property::INPUT_UNDERLINE:
967 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
970 case Toolkit::TextField::Property::SHADOW:
972 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
975 case Toolkit::TextField::Property::INPUT_SHADOW:
977 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
980 case Toolkit::TextField::Property::EMBOSS:
982 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
985 case Toolkit::TextField::Property::INPUT_EMBOSS:
987 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
990 case Toolkit::TextField::Property::OUTLINE:
992 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
995 case Toolkit::TextField::Property::INPUT_OUTLINE:
997 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1000 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1003 impl.mController->GetHiddenInputOption(map);
1007 case Toolkit::TextField::Property::PIXEL_SIZE:
1009 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1012 case Toolkit::TextField::Property::ENABLE_SELECTION:
1014 value = impl.mController->IsSelectionEnabled();
1017 case Toolkit::TextField::Property::PLACEHOLDER:
1020 impl.mController->GetPlaceholderProperty( map );
1024 case Toolkit::TextField::Property::ELLIPSIS:
1026 value = impl.mController->IsTextElideEnabled();
1029 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1031 value = impl.mController->IsShiftSelectionEnabled();
1034 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1036 value = impl.mController->IsGrabHandleEnabled();
1039 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1041 value = impl.mController->IsMatchSystemLanguageDirection();
1044 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1046 value = impl.mController->IsGrabHandlePopupEnabled();
1049 case Toolkit::DevelTextField::Property::BACKGROUND:
1051 value = impl.mController->GetBackgroundColor();
1054 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1056 value = impl.mController->GetSelectedText( );
1059 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1061 Uint32Pair range = impl.GetTextSelectionRange( );
1062 value = static_cast<int>(range.first);
1065 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1067 Uint32Pair range = impl.GetTextSelectionRange( );
1068 value = static_cast<int>(range.second);
1077 void TextField::SelectWholeText()
1079 if( mController && mController->IsShowingRealText() )
1081 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1086 void TextField::SelectNone()
1088 if( mController && mController->IsShowingRealText() )
1090 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1095 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1097 if( mController && mController->IsShowingRealText() )
1099 mController->SetTextSelectionRange( start, end );
1104 Uint32Pair TextField::GetTextSelectionRange() const
1107 if( mController && mController->IsShowingRealText() )
1109 range = mController->GetTextSelectionRange();
1115 InputMethodContext TextField::GetInputMethodContext()
1117 return mInputMethodContext;
1120 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1122 Dali::BaseHandle handle( object );
1124 bool connected( true );
1125 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1127 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1129 field.TextChangedSignal().Connect( tracker, functor );
1131 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1133 field.MaxLengthReachedSignal().Connect( tracker, functor );
1135 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1137 field.InputStyleChangedSignal().Connect( tracker, functor );
1141 // signalName does not match any signal
1148 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1150 return mTextChangedSignal;
1153 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1155 return mMaxLengthReachedSignal;
1158 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1160 return mInputStyleChangedSignal;
1163 void TextField::OnInitialize()
1165 Actor self = Self();
1167 mController = Text::Controller::New( this, this ,this);
1169 // When using the vector-based rendering, the size of the GLyphs are different
1170 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1171 mController->SetGlyphType( glyphType );
1173 mDecorator = Text::Decorator::New( *mController,
1176 mInputMethodContext = InputMethodContext::New( self );
1178 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1180 // Enables the text input.
1181 mController->EnableTextInput( mDecorator, mInputMethodContext );
1183 // Enables the horizontal scrolling after the text input has been enabled.
1184 mController->SetHorizontalScrollEnabled( true );
1186 // Disables the vertical scrolling.
1187 mController->SetVerticalScrollEnabled( false );
1189 // Disable the smooth handle panning.
1190 mController->SetSmoothHandlePanEnabled( false );
1192 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1193 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1195 // Sets layoutDirection value
1196 Dali::Stage stage = Dali::Stage::GetCurrent();
1197 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1198 mController->SetLayoutDirection( layoutDirection );
1200 // Forward input events to controller
1201 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1202 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1204 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1206 // Set BoundingBox to stage size if not already set.
1207 Rect<int> boundingBox;
1208 mDecorator->GetBoundingBox( boundingBox );
1210 if( boundingBox.IsEmpty() )
1212 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1213 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1216 // Flip vertically the 'left' selection handle
1217 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1219 // Fill-parent area by default
1220 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1221 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1222 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1224 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1226 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1232 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1234 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1238 case StyleChange::DEFAULT_FONT_CHANGE:
1240 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1241 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1242 // Property system did not set the font so should update it.
1243 mController->UpdateAfterFontChange( newFont );
1248 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1250 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1254 case StyleChange::THEME_CHANGE:
1256 // Nothing to do, let control base class handle this
1261 // Up call to Control
1262 Control::OnStyleChange( styleManager, change );
1265 Vector3 TextField::GetNaturalSize()
1268 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1270 Vector3 naturalSize = mController->GetNaturalSize();
1271 naturalSize.width += ( padding.start + padding.end );
1272 naturalSize.height += ( padding.top + padding.bottom );
1277 float TextField::GetHeightForWidth( float width )
1280 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1281 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1284 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1286 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1288 Actor self = Self();
1291 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1293 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1295 // Support Right-To-Left of padding
1296 Dali::LayoutDirection::Type layoutDirection;
1297 if( mController->IsMatchSystemLanguageDirection() )
1299 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1303 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1305 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1307 std::swap( padding.start, padding.end );
1312 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1316 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1319 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1321 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1324 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1327 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1329 mDecorator->Relayout( size );
1334 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1337 RenderText( updateTextType );
1341 // The text-field emits signals when the input style changes. These changes of style are
1342 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1343 // can't be emitted during the size negotiation as the callbacks may update the UI.
1344 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1345 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1347 if( Adaptor::IsAvailable() )
1349 Adaptor& adaptor = Adaptor::Get();
1351 if( NULL == mIdleCallback )
1353 // @note: The callback manager takes the ownership of the callback object.
1354 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1355 adaptor.AddIdle( mIdleCallback, false );
1361 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1363 Actor renderableActor;
1365 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1369 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1371 renderableActor = mRenderer->Render( mController->GetView(),
1373 Property::INVALID_INDEX, // Animatable property not supported
1375 DepthIndex::CONTENT );
1378 if( renderableActor != mRenderableActor )
1380 UnparentAndReset( mBackgroundActor );
1381 UnparentAndReset( mRenderableActor );
1382 mRenderableActor = renderableActor;
1384 if ( mRenderableActor )
1386 mBackgroundActor = mController->CreateBackgroundActor();
1391 if( mRenderableActor )
1393 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1395 float renderableActorPositionX, renderableActorPositionY;
1399 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1400 renderableActorPositionY = scrollOffset.y;
1405 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1407 // Support Right-To-Left of padding
1408 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1409 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1411 std::swap( padding.start, padding.end );
1414 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1415 renderableActorPositionY = scrollOffset.y + padding.top;
1418 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1420 // Make sure the actors are parented correctly with/without clipping
1421 Actor self = mStencil ? mStencil : Self();
1423 Actor highlightActor;
1425 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1426 endIt = mClippingDecorationActors.end();
1431 it->LowerToBottom();
1433 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1435 highlightActor = *it;
1438 mClippingDecorationActors.clear();
1440 self.Add( mRenderableActor );
1442 if ( mBackgroundActor )
1444 if ( mDecorator && mDecorator->IsHighlightVisible() )
1446 self.Add( mBackgroundActor );
1447 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1448 mBackgroundActor.LowerBelow( highlightActor );
1452 mRenderableActor.Add( mBackgroundActor );
1453 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1454 mBackgroundActor.LowerToBottom();
1460 void TextField::OnKeyInputFocusGained()
1462 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1463 if( mInputMethodContext )
1465 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1467 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1469 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1471 // Notify that the text editing start.
1472 mInputMethodContext.Activate();
1474 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1475 mInputMethodContext.SetRestoreAfterFocusLost( true );
1478 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1481 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1484 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1485 Internal::Control& controlImpl = GetImplementation( control );
1486 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1487 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1488 if( enableAutofill )
1490 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1491 container.SetFocusedControl( control );
1493 Internal::AutofillContainer& containerImpl = GetImpl( container );
1494 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1495 if( containerGroup != nullptr )
1497 containerGroup.RequestAuthentication();
1501 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1503 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1506 void TextField::OnKeyInputFocusLost()
1508 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1509 if ( mInputMethodContext )
1511 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1512 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1513 mInputMethodContext.SetRestoreAfterFocusLost( false );
1515 // Notify that the text editing finish.
1516 mInputMethodContext.Deactivate();
1518 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1520 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1524 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1527 mController->KeyboardFocusLostEvent();
1529 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1532 void TextField::OnTap( const TapGesture& gesture )
1534 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1535 if ( mInputMethodContext )
1537 mInputMethodContext.Activate();
1539 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1541 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1542 const Vector2& localPoint = gesture.GetLocalPoint();
1543 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1548 void TextField::OnPan( const PanGesture& gesture )
1550 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1553 void TextField::OnLongPress( const LongPressGesture& gesture )
1555 if ( mInputMethodContext )
1557 mInputMethodContext.Activate();
1560 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1561 const Vector2& localPoint = gesture.GetLocalPoint();
1562 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1567 bool TextField::OnKeyEvent( const KeyEvent& event )
1569 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1571 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1573 // Make sure ClearKeyInputFocus when only key is up
1574 if( event.GetState() == KeyEvent::UP )
1576 ClearKeyInputFocus();
1581 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1583 // Do nothing when enter is comming.
1587 return mController->KeyEvent( event );
1590 void TextField::RequestTextRelayout()
1595 void TextField::TextChanged()
1597 Dali::Toolkit::TextField handle( GetOwner() );
1598 mTextChangedSignal.Emit( handle );
1601 void TextField::MaxLengthReached()
1603 Dali::Toolkit::TextField handle( GetOwner() );
1604 mMaxLengthReachedSignal.Emit( handle );
1607 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1609 Dali::Toolkit::TextField handle( GetOwner() );
1611 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1613 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1615 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1617 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1619 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1621 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1623 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1625 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1627 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1629 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1631 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1633 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1635 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1637 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1639 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1641 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1643 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1645 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1647 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1649 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1651 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1654 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1657 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1663 mClippingDecorationActors.push_back( actor );
1667 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1668 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1669 Self().Add( actor );
1670 mActiveLayer = actor;
1675 void TextField::OnSceneConnect( Dali::Actor actor )
1677 if ( mHasBeenStaged )
1679 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1683 mHasBeenStaged = true;
1687 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1689 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1690 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1693 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1698 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1703 void TextField::EnableClipping()
1707 // Creates an extra control to be used as stencil buffer.
1708 mStencil = Control::New();
1709 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1710 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1712 // Creates a background visual. Even if the color is transparent it updates the stencil.
1713 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1714 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1715 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1717 // Enable the clipping property.
1718 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1719 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1721 Self().Add( mStencil );
1725 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1727 mController->PasteClipboardItemEvent();
1730 void TextField::KeyboardStatusChanged(bool keyboardShown)
1732 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1734 // Just hide the grab handle when keyboard is hidden.
1735 if (!keyboardShown )
1737 mController->KeyboardFocusLostEvent();
1741 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1745 void TextField::OnSceneConnection( int depth )
1747 // Sets the depth to the visuals inside the text's decorator.
1748 mDecorator->SetTextDepth( depth );
1750 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1752 // Call the Control::OnSceneConnection() to set the depth of the background.
1753 Control::OnSceneConnection( depth );
1756 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1761 void TextField::OnIdleSignal()
1763 // Emits the change of input style signals.
1764 mController->ProcessInputStyleChangedSignals();
1766 // Set the pointer to null as the callback manager deletes the callback after execute it.
1767 mIdleCallback = NULL;
1770 TextField::TextField()
1771 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1772 mIdleCallback( NULL ),
1773 mAlignmentOffset( 0.f ),
1774 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1775 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1776 mHasBeenStaged( false )
1780 TextField::~TextField()
1782 UnparentAndReset( mStencil );
1784 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1786 Adaptor::Get().RemoveIdle( mIdleCallback );
1790 } // namespace Internal
1792 } // namespace Toolkit