2 * Copyright (c) 2019 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/devel-api/adaptor-framework/key-devel.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/object/property-helper-devel.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.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/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
39 #include <dali-toolkit/public-api/visuals/visual-properties.h>
40 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
41 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
42 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
43 #include <dali-toolkit/internal/text/rendering/text-backend.h>
44 #include <dali-toolkit/internal/text/text-effects-style.h>
45 #include <dali-toolkit/internal/text/text-font-style.h>
46 #include <dali-toolkit/internal/text/text-view.h>
47 #include <dali-toolkit/internal/styling/style-manager-impl.h>
48 #include <dali-toolkit/devel-api/controls/control-devel.h>
49 #include <dali/integration-api/adaptor-framework/adaptor.h>
51 using namespace Dali::Toolkit::Text;
62 namespace // unnamed namespace
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
69 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
70 } // unnamed namespace
77 return Toolkit::TextField::New();
80 // Setup properties, signals and actions using the type-registry.
81 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
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, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", MAP, BACKGROUND )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
145 DALI_TYPE_REGISTRATION_END()
149 Toolkit::TextField TextField::New()
151 // Create the implementation, temporarily owned by this handle on stack
152 IntrusivePtr< TextField > impl = new TextField();
154 // Pass ownership to CustomActor handle
155 Toolkit::TextField handle( *impl );
157 // Second-phase init of the implementation
158 // This can only be done after the CustomActor connection has been made...
164 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
166 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
168 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
173 TextField& impl( GetImpl( textField ) );
177 case Toolkit::TextField::Property::RENDERING_BACKEND:
179 int backend = value.Get< int >();
180 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
182 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
183 if( Text::RENDERING_VECTOR_BASED == backend )
185 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
188 if( impl.mRenderingBackend != backend )
190 impl.mRenderingBackend = backend;
191 impl.mRenderer.Reset();
193 if( impl.mController )
195 // When using the vector-based rendering, the size of the GLyphs are different
196 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
197 impl.mController->SetGlyphType( glyphType );
202 case Toolkit::TextField::Property::TEXT:
204 if( impl.mController )
206 const std::string& text = value.Get< std::string >();
207 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
209 impl.mController->SetText( text );
213 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
215 if( impl.mController )
217 const std::string& text = value.Get< std::string >();
218 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
220 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
224 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
226 if( impl.mController )
228 const std::string& text = value.Get< std::string >();
229 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
231 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
235 case Toolkit::TextField::Property::FONT_FAMILY:
237 if( impl.mController )
239 const std::string& fontFamily = value.Get< std::string >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
241 impl.mController->SetDefaultFontFamily( fontFamily );
245 case Toolkit::TextField::Property::FONT_STYLE:
247 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
250 case Toolkit::TextField::Property::POINT_SIZE:
252 if( impl.mController )
254 const float pointSize = value.Get< float >();
255 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
257 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
259 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
264 case Toolkit::TextField::Property::MAX_LENGTH:
266 if( impl.mController )
268 const int max = value.Get< int >();
269 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
271 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 if( impl.mController )
294 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
295 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
297 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
298 impl.mController->SetHorizontalAlignment( alignment );
303 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
305 if( impl.mController )
307 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
308 if( GetVerticalAlignmentEnumeration( value, alignment ) )
310 impl.mController->SetVerticalAlignment( alignment );
311 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
316 case Toolkit::TextField::Property::TEXT_COLOR:
318 if( impl.mController )
320 const Vector4& textColor = value.Get< Vector4 >();
321 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 );
323 if( impl.mController->GetDefaultColor() != textColor )
325 impl.mController->SetDefaultColor( textColor );
326 impl.mController->SetInputColor( textColor );
327 impl.mRenderer.Reset();
332 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
334 if( impl.mController )
336 const Vector4& textColor = value.Get< Vector4 >();
337 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 );
339 if( impl.mController->GetPlaceholderTextColor() != textColor )
341 impl.mController->SetPlaceholderTextColor( textColor );
342 impl.mRenderer.Reset();
347 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
349 if( impl.mDecorator )
351 const Vector4& color = value.Get< Vector4 >();
352 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 );
354 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
355 impl.RequestTextRelayout();
359 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
361 if( impl.mDecorator )
363 const Vector4& color = value.Get< Vector4 >();
364 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 );
366 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
367 impl.RequestTextRelayout();
371 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
373 if( impl.mController )
375 const bool enable = value.Get< bool >();
376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
378 impl.mController->SetEnableCursorBlink( enable );
379 impl.RequestTextRelayout();
383 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
385 if( impl.mDecorator )
387 const float interval = value.Get< float >();
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
390 impl.mDecorator->SetCursorBlinkInterval( interval );
394 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
396 if( impl.mDecorator )
398 const float duration = value.Get< float >();
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
401 impl.mDecorator->SetCursorBlinkDuration( duration );
405 case Toolkit::TextField::Property::CURSOR_WIDTH:
407 if( impl.mDecorator )
409 const int width = value.Get< int >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
412 impl.mDecorator->SetCursorWidth( width );
413 impl.mController->GetLayoutEngine().SetCursorWidth( width );
417 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
419 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
422 if( impl.mDecorator )
424 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
425 impl.RequestTextRelayout();
429 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
431 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
434 if( impl.mDecorator )
436 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
437 impl.RequestTextRelayout();
441 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
443 const float threshold = value.Get< float >();
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
446 if( impl.mDecorator )
448 impl.mDecorator->SetScrollThreshold( threshold );
452 case Toolkit::TextField::Property::SCROLL_SPEED:
454 const float speed = value.Get< float >();
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
457 if( impl.mDecorator )
459 impl.mDecorator->SetScrollSpeed( speed );
463 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
465 const Image image = Scripting::NewImage( value );
467 if( impl.mDecorator && image )
469 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
470 impl.RequestTextRelayout();
474 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
476 const Image image = Scripting::NewImage( value );
478 if( impl.mDecorator && image )
480 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
487 const Image image = Scripting::NewImage( value );
489 if( impl.mDecorator && image )
491 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
498 const Image image = Scripting::NewImage( value );
500 if( impl.mDecorator && image )
502 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator && image )
513 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
520 const Image image = Scripting::NewImage( value );
522 if( impl.mDecorator && image )
524 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
525 impl.RequestTextRelayout();
529 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
531 const Vector4 color = value.Get< Vector4 >();
532 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 );
534 if( impl.mDecorator )
536 impl.mDecorator->SetHighlightColor( color );
537 impl.RequestTextRelayout();
541 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
543 if( impl.mDecorator )
545 const Rect<int> box = value.Get< Rect<int> >();
546 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 );
548 impl.mDecorator->SetBoundingBox( box );
549 impl.RequestTextRelayout();
553 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
555 const Property::Map* map = value.GetMap();
558 impl.mInputMethodOptions.ApplyProperty( *map );
560 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
562 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
563 if (control == textField)
565 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
569 case Toolkit::TextField::Property::INPUT_COLOR:
571 if( impl.mController )
573 const Vector4 inputColor = value.Get< Vector4 >();
574 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 );
576 impl.mController->SetInputColor( inputColor );
580 case Toolkit::TextField::Property::ENABLE_MARKUP:
582 if( impl.mController )
584 const bool enableMarkup = value.Get<bool>();
585 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
587 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
591 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
593 if( impl.mController )
595 const std::string& fontFamily = value.Get< std::string >();
596 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
597 impl.mController->SetInputFontFamily( fontFamily );
601 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
603 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
606 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
608 if( impl.mController )
610 const float pointSize = value.Get< float >();
611 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
612 impl.mController->SetInputFontPointSize( pointSize );
616 case Toolkit::TextField::Property::UNDERLINE:
618 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
621 impl.mRenderer.Reset();
625 case Toolkit::TextField::Property::INPUT_UNDERLINE:
627 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
630 impl.mRenderer.Reset();
634 case Toolkit::TextField::Property::SHADOW:
636 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
639 impl.mRenderer.Reset();
643 case Toolkit::TextField::Property::INPUT_SHADOW:
645 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
648 impl.mRenderer.Reset();
652 case Toolkit::TextField::Property::EMBOSS:
654 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
657 impl.mRenderer.Reset();
661 case Toolkit::TextField::Property::INPUT_EMBOSS:
663 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
666 impl.mRenderer.Reset();
670 case Toolkit::TextField::Property::OUTLINE:
672 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
675 impl.mRenderer.Reset();
679 case Toolkit::TextField::Property::INPUT_OUTLINE:
681 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
684 impl.mRenderer.Reset();
688 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
690 const Property::Map* map = value.GetMap();
693 impl.mController->SetHiddenInputOption(*map);
697 case Toolkit::TextField::Property::PIXEL_SIZE:
699 if( impl.mController )
701 const float pixelSize = value.Get< float >();
702 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
704 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
706 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
711 case Toolkit::TextField::Property::ENABLE_SELECTION:
713 if( impl.mController )
715 const bool enableSelection = value.Get< bool >();
716 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
717 impl.mController->SetSelectionEnabled( enableSelection );
721 case Toolkit::TextField::Property::PLACEHOLDER:
723 const Property::Map* map = value.GetMap();
726 impl.mController->SetPlaceholderProperty( *map );
730 case Toolkit::TextField::Property::ELLIPSIS:
732 if( impl.mController )
734 const bool ellipsis = value.Get<bool>();
735 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
737 impl.mController->SetTextElideEnabled( ellipsis );
741 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
743 if( impl.mController )
745 const bool shiftSelection = value.Get<bool>();
746 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
748 impl.mController->SetShiftSelectionEnabled( shiftSelection );
752 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
754 if( impl.mController )
756 const bool grabHandleEnabled = value.Get<bool>();
757 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
759 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
763 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
765 if( impl.mController )
767 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
771 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
773 if( impl.mController )
775 const bool grabHandlePopupEnabled = value.Get<bool>();
776 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
778 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
782 case Toolkit::DevelTextField::Property::BACKGROUND:
784 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
787 impl.mRenderer.Reset();
795 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
797 Property::Value value;
799 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
803 TextField& impl( GetImpl( textField ) );
807 case Toolkit::TextField::Property::RENDERING_BACKEND:
809 value = impl.mRenderingBackend;
812 case Toolkit::TextField::Property::TEXT:
814 if( impl.mController )
817 impl.mController->GetText( text );
818 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
823 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
825 if( impl.mController )
828 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
833 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
835 if( impl.mController )
838 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
843 case Toolkit::TextField::Property::FONT_FAMILY:
845 if( impl.mController )
847 value = impl.mController->GetDefaultFontFamily();
851 case Toolkit::TextField::Property::FONT_STYLE:
853 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
856 case Toolkit::TextField::Property::POINT_SIZE:
858 if( impl.mController )
860 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
864 case Toolkit::TextField::Property::MAX_LENGTH:
866 if( impl.mController )
868 value = impl.mController->GetMaximumNumberOfCharacters();
872 case Toolkit::TextField::Property::EXCEED_POLICY:
874 value = impl.mExceedPolicy;
877 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
879 if( impl.mController )
881 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
885 value = std::string( name );
890 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
892 if( impl.mController )
894 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
898 value = std::string( name );
903 case Toolkit::TextField::Property::TEXT_COLOR:
905 if ( impl.mController )
907 value = impl.mController->GetDefaultColor();
911 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
913 if ( impl.mController )
915 value = impl.mController->GetPlaceholderTextColor();
919 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
921 if( impl.mDecorator )
923 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
927 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
929 if( impl.mDecorator )
931 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
935 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
937 value = impl.mController->GetEnableCursorBlink();
940 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
942 if( impl.mDecorator )
944 value = impl.mDecorator->GetCursorBlinkInterval();
948 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
950 if( impl.mDecorator )
952 value = impl.mDecorator->GetCursorBlinkDuration();
956 case Toolkit::TextField::Property::CURSOR_WIDTH:
958 if( impl.mDecorator )
960 value = impl.mDecorator->GetCursorWidth();
964 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
966 if( impl.mDecorator )
968 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
971 value = image.GetUrl();
976 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
978 if( impl.mDecorator )
980 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
983 value = image.GetUrl();
988 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
990 if( impl.mDecorator )
992 value = impl.mDecorator->GetScrollThreshold();
996 case Toolkit::TextField::Property::SCROLL_SPEED:
998 if( impl.mDecorator )
1000 value = impl.mDecorator->GetScrollSpeed();
1004 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1006 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1009 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1011 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1014 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1016 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1019 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1021 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1024 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1026 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1029 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1031 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1034 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1036 if( impl.mDecorator )
1038 value = impl.mDecorator->GetHighlightColor();
1042 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1044 if( impl.mDecorator )
1046 Rect<int> boundingBox;
1047 impl.mDecorator->GetBoundingBox( boundingBox );
1048 value = boundingBox;
1052 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1055 impl.mInputMethodOptions.RetrieveProperty( map );
1059 case Toolkit::TextField::Property::INPUT_COLOR:
1061 if( impl.mController )
1063 value = impl.mController->GetInputColor();
1067 case Toolkit::TextField::Property::ENABLE_MARKUP:
1069 if( impl.mController )
1071 value = impl.mController->IsMarkupProcessorEnabled();
1075 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1077 if( impl.mController )
1079 value = impl.mController->GetInputFontFamily();
1083 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1085 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1088 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1090 if( impl.mController )
1092 value = impl.mController->GetInputFontPointSize();
1096 case Toolkit::TextField::Property::UNDERLINE:
1098 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1101 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1103 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1106 case Toolkit::TextField::Property::SHADOW:
1108 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1111 case Toolkit::TextField::Property::INPUT_SHADOW:
1113 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1116 case Toolkit::TextField::Property::EMBOSS:
1118 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1121 case Toolkit::TextField::Property::INPUT_EMBOSS:
1123 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1126 case Toolkit::TextField::Property::OUTLINE:
1128 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1131 case Toolkit::TextField::Property::INPUT_OUTLINE:
1133 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1136 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1139 impl.mController->GetHiddenInputOption(map);
1143 case Toolkit::TextField::Property::PIXEL_SIZE:
1145 if( impl.mController )
1147 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1151 case Toolkit::TextField::Property::ENABLE_SELECTION:
1153 if( impl.mController )
1155 value = impl.mController->IsSelectionEnabled();
1159 case Toolkit::TextField::Property::PLACEHOLDER:
1162 impl.mController->GetPlaceholderProperty( map );
1166 case Toolkit::TextField::Property::ELLIPSIS:
1168 if( impl.mController )
1170 value = impl.mController->IsTextElideEnabled();
1174 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1176 if( impl.mController )
1178 value = impl.mController->IsShiftSelectionEnabled();
1182 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1184 if( impl.mController )
1186 value = impl.mController->IsGrabHandleEnabled();
1190 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1192 if( impl.mController )
1194 value = impl.mController->IsMatchSystemLanguageDirection();
1198 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1200 if (impl.mController)
1202 value = impl.mController->IsGrabHandlePopupEnabled();
1206 case Toolkit::DevelTextField::Property::BACKGROUND:
1208 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1217 void TextField::SelectWholeText()
1219 if( mController && mController->IsShowingRealText() )
1221 mController->SelectEvent( 0.f, 0.f, true );
1226 InputMethodContext TextField::GetInputMethodContext()
1228 return mInputMethodContext;
1231 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1233 Dali::BaseHandle handle( object );
1235 bool connected( true );
1236 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1238 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1240 field.TextChangedSignal().Connect( tracker, functor );
1242 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1244 field.MaxLengthReachedSignal().Connect( tracker, functor );
1246 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1248 field.InputStyleChangedSignal().Connect( tracker, functor );
1252 // signalName does not match any signal
1259 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1261 return mTextChangedSignal;
1264 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1266 return mMaxLengthReachedSignal;
1269 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1271 return mInputStyleChangedSignal;
1274 void TextField::OnInitialize()
1276 Actor self = Self();
1278 mController = Text::Controller::New( this, this );
1280 // When using the vector-based rendering, the size of the GLyphs are different
1281 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1282 mController->SetGlyphType( glyphType );
1284 mDecorator = Text::Decorator::New( *mController,
1287 mInputMethodContext = InputMethodContext::New( self );
1289 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1291 // Enables the text input.
1292 mController->EnableTextInput( mDecorator, mInputMethodContext );
1294 // Enables the horizontal scrolling after the text input has been enabled.
1295 mController->SetHorizontalScrollEnabled( true );
1297 // Disables the vertical scrolling.
1298 mController->SetVerticalScrollEnabled( false );
1300 // Disable the smooth handle panning.
1301 mController->SetSmoothHandlePanEnabled( false );
1303 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1304 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1306 // Sets layoutDirection value
1307 Dali::Stage stage = Dali::Stage::GetCurrent();
1308 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1309 mController->SetLayoutDirection( layoutDirection );
1311 // Forward input events to controller
1312 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1313 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1315 self.TouchSignal().Connect( this, &TextField::OnTouched );
1317 // Set BoundingBox to stage size if not already set.
1318 Rect<int> boundingBox;
1319 mDecorator->GetBoundingBox( boundingBox );
1321 if( boundingBox.IsEmpty() )
1323 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1324 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1327 // Flip vertically the 'left' selection handle
1328 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1330 // Fill-parent area by default
1331 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1332 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1333 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1335 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1337 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1343 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1345 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1349 case StyleChange::DEFAULT_FONT_CHANGE:
1351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1352 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1353 // Property system did not set the font so should update it.
1354 mController->UpdateAfterFontChange( newFont );
1359 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1361 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1365 case StyleChange::THEME_CHANGE:
1367 // Nothing to do, let control base class handle this
1372 // Up call to Control
1373 Control::OnStyleChange( styleManager, change );
1376 Vector3 TextField::GetNaturalSize()
1379 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1381 Vector3 naturalSize = mController->GetNaturalSize();
1382 naturalSize.width += ( padding.start + padding.end );
1383 naturalSize.height += ( padding.top + padding.bottom );
1388 float TextField::GetHeightForWidth( float width )
1391 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1392 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1395 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1399 Actor self = Self();
1402 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1404 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1406 // Support Right-To-Left of padding
1407 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1408 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1410 std::swap( padding.start, padding.end );
1415 mStencil.SetPosition( padding.start, padding.top );
1419 mActiveLayer.SetPosition( padding.start, padding.top );
1422 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1424 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1427 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1430 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1432 mDecorator->Relayout( size );
1437 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1440 RenderText( updateTextType );
1444 // The text-field emits signals when the input style changes. These changes of style are
1445 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1446 // can't be emitted during the size negotiation as the callbacks may update the UI.
1447 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1448 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1450 if( Adaptor::IsAvailable() )
1452 Adaptor& adaptor = Adaptor::Get();
1454 if( NULL == mIdleCallback )
1456 // @note: The callback manager takes the ownership of the callback object.
1457 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1458 adaptor.AddIdle( mIdleCallback, false );
1464 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1466 Actor renderableActor;
1468 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1472 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1474 renderableActor = mRenderer->Render( mController->GetView(),
1476 Property::INVALID_INDEX, // Animatable property not supported
1478 DepthIndex::CONTENT );
1481 if( renderableActor != mRenderableActor )
1483 UnparentAndReset( mBackgroundActor );
1484 UnparentAndReset( mRenderableActor );
1485 mRenderableActor = renderableActor;
1487 if ( mRenderableActor )
1489 mBackgroundActor = mController->CreateBackgroundActor();
1494 if( mRenderableActor )
1496 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1498 float renderableActorPositionX, renderableActorPositionY;
1502 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1503 renderableActorPositionY = scrollOffset.y;
1508 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1510 // Support Right-To-Left of padding
1511 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1512 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1514 std::swap( padding.start, padding.end );
1517 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1518 renderableActorPositionY = scrollOffset.y + padding.top;
1521 mRenderableActor.SetPosition( renderableActorPositionX, renderableActorPositionY );
1523 // Make sure the actors are parented correctly with/without clipping
1524 Actor self = mStencil ? mStencil : Self();
1526 Actor highlightActor;
1528 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1529 endIt = mClippingDecorationActors.end();
1534 it->LowerToBottom();
1536 if ( it->GetName() == "HighlightActor" )
1538 highlightActor = *it;
1541 mClippingDecorationActors.clear();
1543 self.Add( mRenderableActor );
1545 if ( mBackgroundActor )
1547 if ( mDecorator && mDecorator->IsHighlightVisible() )
1549 self.Add( mBackgroundActor );
1550 mBackgroundActor.SetPosition( renderableActorPositionX, renderableActorPositionY); // In text field's coords.
1551 mBackgroundActor.LowerBelow( highlightActor );
1555 mRenderableActor.Add( mBackgroundActor );
1556 mBackgroundActor.SetPosition( 0.0f, 0.0f ); // In renderable actor's coords.
1557 mBackgroundActor.LowerToBottom();
1563 void TextField::OnKeyInputFocusGained()
1565 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1566 if( mInputMethodContext )
1568 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1570 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1572 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1574 // Notify that the text editing start.
1575 mInputMethodContext.Activate();
1577 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1578 mInputMethodContext.SetRestoreAfterFocusLost( true );
1581 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1584 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1587 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1588 Internal::Control& controlImpl = GetImplementation( control );
1589 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1590 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1591 if( enableAutofill )
1593 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1594 container.SetFocusedControl( control );
1596 Internal::AutofillContainer& containerImpl = GetImpl( container );
1597 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1598 if( containerGroup != nullptr )
1600 containerGroup.RequestAuthentication();
1604 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1606 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1609 void TextField::OnKeyInputFocusLost()
1611 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1612 if ( mInputMethodContext )
1614 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1615 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1616 mInputMethodContext.SetRestoreAfterFocusLost( false );
1618 // Notify that the text editing finish.
1619 mInputMethodContext.Deactivate();
1621 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1623 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1627 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1630 mController->KeyboardFocusLostEvent();
1632 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1635 void TextField::OnTap( const TapGesture& gesture )
1637 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1638 if ( mInputMethodContext )
1640 mInputMethodContext.Activate();
1642 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1644 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1645 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1650 void TextField::OnPan( const PanGesture& gesture )
1652 mController->PanEvent( gesture.state, gesture.displacement );
1655 void TextField::OnLongPress( const LongPressGesture& gesture )
1657 if ( mInputMethodContext )
1659 mInputMethodContext.Activate();
1662 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1663 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1668 bool TextField::OnKeyEvent( const KeyEvent& event )
1670 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1672 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1674 // Make sure ClearKeyInputFocus when only key is up
1675 if( event.state == KeyEvent::Up )
1677 ClearKeyInputFocus();
1682 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1684 // Do nothing when enter is comming.
1688 return mController->KeyEvent( event );
1691 void TextField::RequestTextRelayout()
1696 void TextField::TextChanged()
1698 Dali::Toolkit::TextField handle( GetOwner() );
1699 mTextChangedSignal.Emit( handle );
1702 void TextField::MaxLengthReached()
1704 Dali::Toolkit::TextField handle( GetOwner() );
1705 mMaxLengthReachedSignal.Emit( handle );
1708 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1710 Dali::Toolkit::TextField handle( GetOwner() );
1712 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1714 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1716 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1718 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1720 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1722 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1724 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1726 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1728 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1730 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1732 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1734 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1736 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1738 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1740 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1742 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1744 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1746 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1748 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1750 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1752 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1755 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1758 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1764 mClippingDecorationActors.push_back( actor );
1768 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1769 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1770 Self().Add( actor );
1771 mActiveLayer = actor;
1776 void TextField::OnStageConnect( Dali::Actor actor )
1778 if ( mHasBeenStaged )
1780 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1784 mHasBeenStaged = true;
1788 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1790 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1791 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1794 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1798 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1803 Scripting::CreatePropertyMap( image, map );
1809 void TextField::EnableClipping()
1813 // Creates an extra control to be used as stencil buffer.
1814 mStencil = Control::New();
1815 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1816 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1818 // Creates a background visual. Even if the color is transparent it updates the stencil.
1819 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1820 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1821 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1823 // Enable the clipping property.
1824 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1825 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1827 Self().Add( mStencil );
1831 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1833 mController->PasteClipboardItemEvent();
1836 void TextField::KeyboardStatusChanged(bool keyboardShown)
1838 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1840 // Just hide the grab handle when keyboard is hidden.
1841 if (!keyboardShown )
1843 mController->KeyboardFocusLostEvent();
1847 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1851 void TextField::OnStageConnection( int depth )
1853 // Sets the depth to the visuals inside the text's decorator.
1854 mDecorator->SetTextDepth( depth );
1856 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1858 // Call the Control::OnStageConnection() to set the depth of the background.
1859 Control::OnStageConnection( depth );
1862 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1867 void TextField::OnIdleSignal()
1869 // Emits the change of input style signals.
1870 mController->ProcessInputStyleChangedSignals();
1872 // Set the pointer to null as the callback manager deletes the callback after execute it.
1873 mIdleCallback = NULL;
1876 TextField::TextField()
1877 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1878 mIdleCallback( NULL ),
1879 mAlignmentOffset( 0.f ),
1880 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1881 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1882 mHasBeenStaged( false )
1886 TextField::~TextField()
1888 UnparentAndReset( mStencil );
1890 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1892 Adaptor::Get().RemoveIdle( mIdleCallback );
1896 } // namespace Internal
1898 } // namespace Toolkit