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 )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
144 DALI_TYPE_REGISTRATION_END()
148 Toolkit::TextField TextField::New()
150 // Create the implementation, temporarily owned by this handle on stack
151 IntrusivePtr< TextField > impl = new TextField();
153 // Pass ownership to CustomActor handle
154 Toolkit::TextField handle( *impl );
156 // Second-phase init of the implementation
157 // This can only be done after the CustomActor connection has been made...
163 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
165 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
167 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
172 TextField& impl( GetImpl( textField ) );
176 case Toolkit::TextField::Property::RENDERING_BACKEND:
178 int backend = value.Get< int >();
179 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
181 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
182 if( Text::RENDERING_VECTOR_BASED == backend )
184 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
187 if( impl.mRenderingBackend != backend )
189 impl.mRenderingBackend = backend;
190 impl.mRenderer.Reset();
192 if( impl.mController )
194 // When using the vector-based rendering, the size of the GLyphs are different
195 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
196 impl.mController->SetGlyphType( glyphType );
201 case Toolkit::TextField::Property::TEXT:
203 if( impl.mController )
205 const std::string& text = value.Get< std::string >();
206 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
208 impl.mController->SetText( text );
212 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
214 if( impl.mController )
216 const std::string& text = value.Get< std::string >();
217 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
219 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
223 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
225 if( impl.mController )
227 const std::string& text = value.Get< std::string >();
228 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
230 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
234 case Toolkit::TextField::Property::FONT_FAMILY:
236 if( impl.mController )
238 const std::string& fontFamily = value.Get< std::string >();
239 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
240 impl.mController->SetDefaultFontFamily( fontFamily );
244 case Toolkit::TextField::Property::FONT_STYLE:
246 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
249 case Toolkit::TextField::Property::POINT_SIZE:
251 if( impl.mController )
253 const float pointSize = value.Get< float >();
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
256 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
258 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
263 case Toolkit::TextField::Property::MAX_LENGTH:
265 if( impl.mController )
267 const int max = value.Get< int >();
268 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
270 impl.mController->SetMaximumNumberOfCharacters( max );
274 case Toolkit::TextField::Property::EXCEED_POLICY:
276 impl.mExceedPolicy = value.Get<int>();
278 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
280 impl.EnableClipping();
284 UnparentAndReset( impl.mStencil );
286 impl.RequestTextRelayout();
289 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
291 if( impl.mController )
293 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
294 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
296 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
297 impl.mController->SetHorizontalAlignment( alignment );
302 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
304 if( impl.mController )
306 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
307 if( GetVerticalAlignmentEnumeration( value, alignment ) )
309 impl.mController->SetVerticalAlignment( alignment );
310 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
315 case Toolkit::TextField::Property::TEXT_COLOR:
317 if( impl.mController )
319 const Vector4& textColor = value.Get< Vector4 >();
320 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 );
322 if( impl.mController->GetDefaultColor() != textColor )
324 impl.mController->SetDefaultColor( textColor );
325 impl.mController->SetInputColor( textColor );
326 impl.mRenderer.Reset();
331 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
333 if( impl.mController )
335 const Vector4& textColor = value.Get< Vector4 >();
336 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 );
338 if( impl.mController->GetPlaceholderTextColor() != textColor )
340 impl.mController->SetPlaceholderTextColor( textColor );
341 impl.mRenderer.Reset();
346 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
348 if( impl.mDecorator )
350 const Vector4& color = value.Get< Vector4 >();
351 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 );
353 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
354 impl.RequestTextRelayout();
358 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
360 if( impl.mDecorator )
362 const Vector4& color = value.Get< Vector4 >();
363 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 );
365 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
366 impl.RequestTextRelayout();
370 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
372 if( impl.mController )
374 const bool enable = value.Get< bool >();
375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
377 impl.mController->SetEnableCursorBlink( enable );
378 impl.RequestTextRelayout();
382 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
384 if( impl.mDecorator )
386 const float interval = value.Get< float >();
387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
389 impl.mDecorator->SetCursorBlinkInterval( interval );
393 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
395 if( impl.mDecorator )
397 const float duration = value.Get< float >();
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
400 impl.mDecorator->SetCursorBlinkDuration( duration );
404 case Toolkit::TextField::Property::CURSOR_WIDTH:
406 if( impl.mDecorator )
408 const int width = value.Get< int >();
409 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
411 impl.mDecorator->SetCursorWidth( width );
412 impl.mController->GetLayoutEngine().SetCursorWidth( width );
416 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
418 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
421 if( impl.mDecorator )
423 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
424 impl.RequestTextRelayout();
428 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
430 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
433 if( impl.mDecorator )
435 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
436 impl.RequestTextRelayout();
440 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
442 const float threshold = value.Get< float >();
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
445 if( impl.mDecorator )
447 impl.mDecorator->SetScrollThreshold( threshold );
451 case Toolkit::TextField::Property::SCROLL_SPEED:
453 const float speed = value.Get< float >();
454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
456 if( impl.mDecorator )
458 impl.mDecorator->SetScrollSpeed( speed );
462 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
464 const Image image = Scripting::NewImage( value );
466 if( impl.mDecorator && image )
468 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
469 impl.RequestTextRelayout();
473 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
475 const Image image = Scripting::NewImage( value );
477 if( impl.mDecorator && image )
479 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
480 impl.RequestTextRelayout();
484 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
486 const Image image = Scripting::NewImage( value );
488 if( impl.mDecorator && image )
490 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
491 impl.RequestTextRelayout();
495 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
497 const Image image = Scripting::NewImage( value );
499 if( impl.mDecorator && image )
501 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
502 impl.RequestTextRelayout();
506 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
508 const Image image = Scripting::NewImage( value );
510 if( impl.mDecorator && image )
512 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
513 impl.RequestTextRelayout();
517 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
519 const Image image = Scripting::NewImage( value );
521 if( impl.mDecorator && image )
523 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
524 impl.RequestTextRelayout();
528 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
530 const Vector4 color = value.Get< Vector4 >();
531 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 );
533 if( impl.mDecorator )
535 impl.mDecorator->SetHighlightColor( color );
536 impl.RequestTextRelayout();
540 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
542 if( impl.mDecorator )
544 const Rect<int> box = value.Get< Rect<int> >();
545 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 );
547 impl.mDecorator->SetBoundingBox( box );
548 impl.RequestTextRelayout();
552 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
554 const Property::Map* map = value.GetMap();
557 impl.mInputMethodOptions.ApplyProperty( *map );
559 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
561 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
562 if (control == textField)
564 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
568 case Toolkit::TextField::Property::INPUT_COLOR:
570 if( impl.mController )
572 const Vector4 inputColor = value.Get< Vector4 >();
573 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 );
575 impl.mController->SetInputColor( inputColor );
579 case Toolkit::TextField::Property::ENABLE_MARKUP:
581 if( impl.mController )
583 const bool enableMarkup = value.Get<bool>();
584 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
586 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
590 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
592 if( impl.mController )
594 const std::string& fontFamily = value.Get< std::string >();
595 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
596 impl.mController->SetInputFontFamily( fontFamily );
600 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
602 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
605 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
607 if( impl.mController )
609 const float pointSize = value.Get< float >();
610 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
611 impl.mController->SetInputFontPointSize( pointSize );
615 case Toolkit::TextField::Property::UNDERLINE:
617 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
620 impl.mRenderer.Reset();
624 case Toolkit::TextField::Property::INPUT_UNDERLINE:
626 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
629 impl.mRenderer.Reset();
633 case Toolkit::TextField::Property::SHADOW:
635 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
638 impl.mRenderer.Reset();
642 case Toolkit::TextField::Property::INPUT_SHADOW:
644 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
647 impl.mRenderer.Reset();
651 case Toolkit::TextField::Property::EMBOSS:
653 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
656 impl.mRenderer.Reset();
660 case Toolkit::TextField::Property::INPUT_EMBOSS:
662 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
665 impl.mRenderer.Reset();
669 case Toolkit::TextField::Property::OUTLINE:
671 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
674 impl.mRenderer.Reset();
678 case Toolkit::TextField::Property::INPUT_OUTLINE:
680 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
683 impl.mRenderer.Reset();
687 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
689 const Property::Map* map = value.GetMap();
692 impl.mController->SetHiddenInputOption(*map);
696 case Toolkit::TextField::Property::PIXEL_SIZE:
698 if( impl.mController )
700 const float pixelSize = value.Get< float >();
701 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
703 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
705 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
710 case Toolkit::TextField::Property::ENABLE_SELECTION:
712 if( impl.mController )
714 const bool enableSelection = value.Get< bool >();
715 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
716 impl.mController->SetSelectionEnabled( enableSelection );
720 case Toolkit::TextField::Property::PLACEHOLDER:
722 const Property::Map* map = value.GetMap();
725 impl.mController->SetPlaceholderProperty( *map );
729 case Toolkit::TextField::Property::ELLIPSIS:
731 if( impl.mController )
733 const bool ellipsis = value.Get<bool>();
734 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
736 impl.mController->SetTextElideEnabled( ellipsis );
740 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
742 if( impl.mController )
744 const bool shiftSelection = value.Get<bool>();
745 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
747 impl.mController->SetShiftSelectionEnabled( shiftSelection );
751 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
753 if( impl.mController )
755 const bool grabHandleEnabled = value.Get<bool>();
756 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
758 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
762 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
764 if( impl.mController )
766 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
770 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
772 if (impl.mController)
774 const bool grabHandlePopupEnabled = value.Get<bool>();
775 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
777 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
785 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
787 Property::Value value;
789 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
793 TextField& impl( GetImpl( textField ) );
797 case Toolkit::TextField::Property::RENDERING_BACKEND:
799 value = impl.mRenderingBackend;
802 case Toolkit::TextField::Property::TEXT:
804 if( impl.mController )
807 impl.mController->GetText( text );
808 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
813 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
815 if( impl.mController )
818 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
823 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
825 if( impl.mController )
828 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
833 case Toolkit::TextField::Property::FONT_FAMILY:
835 if( impl.mController )
837 value = impl.mController->GetDefaultFontFamily();
841 case Toolkit::TextField::Property::FONT_STYLE:
843 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
846 case Toolkit::TextField::Property::POINT_SIZE:
848 if( impl.mController )
850 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
854 case Toolkit::TextField::Property::MAX_LENGTH:
856 if( impl.mController )
858 value = impl.mController->GetMaximumNumberOfCharacters();
862 case Toolkit::TextField::Property::EXCEED_POLICY:
864 value = impl.mExceedPolicy;
867 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
869 if( impl.mController )
871 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
875 value = std::string( name );
880 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
882 if( impl.mController )
884 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
888 value = std::string( name );
893 case Toolkit::TextField::Property::TEXT_COLOR:
895 if ( impl.mController )
897 value = impl.mController->GetDefaultColor();
901 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
903 if ( impl.mController )
905 value = impl.mController->GetPlaceholderTextColor();
909 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
911 if( impl.mDecorator )
913 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
917 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
919 if( impl.mDecorator )
921 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
925 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
927 value = impl.mController->GetEnableCursorBlink();
930 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
932 if( impl.mDecorator )
934 value = impl.mDecorator->GetCursorBlinkInterval();
938 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
940 if( impl.mDecorator )
942 value = impl.mDecorator->GetCursorBlinkDuration();
946 case Toolkit::TextField::Property::CURSOR_WIDTH:
948 if( impl.mDecorator )
950 value = impl.mDecorator->GetCursorWidth();
954 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
956 if( impl.mDecorator )
958 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
961 value = image.GetUrl();
966 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
968 if( impl.mDecorator )
970 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
973 value = image.GetUrl();
978 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
980 if( impl.mDecorator )
982 value = impl.mDecorator->GetScrollThreshold();
986 case Toolkit::TextField::Property::SCROLL_SPEED:
988 if( impl.mDecorator )
990 value = impl.mDecorator->GetScrollSpeed();
994 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
996 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
999 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1001 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1004 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1006 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1009 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1011 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1014 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1016 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1019 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1021 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1024 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1026 if( impl.mDecorator )
1028 value = impl.mDecorator->GetHighlightColor();
1032 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1034 if( impl.mDecorator )
1036 Rect<int> boundingBox;
1037 impl.mDecorator->GetBoundingBox( boundingBox );
1038 value = boundingBox;
1042 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1045 impl.mInputMethodOptions.RetrieveProperty( map );
1049 case Toolkit::TextField::Property::INPUT_COLOR:
1051 if( impl.mController )
1053 value = impl.mController->GetInputColor();
1057 case Toolkit::TextField::Property::ENABLE_MARKUP:
1059 if( impl.mController )
1061 value = impl.mController->IsMarkupProcessorEnabled();
1065 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1067 if( impl.mController )
1069 value = impl.mController->GetInputFontFamily();
1073 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1075 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1078 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1080 if( impl.mController )
1082 value = impl.mController->GetInputFontPointSize();
1086 case Toolkit::TextField::Property::UNDERLINE:
1088 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1091 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1093 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1096 case Toolkit::TextField::Property::SHADOW:
1098 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1101 case Toolkit::TextField::Property::INPUT_SHADOW:
1103 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1106 case Toolkit::TextField::Property::EMBOSS:
1108 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1111 case Toolkit::TextField::Property::INPUT_EMBOSS:
1113 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1116 case Toolkit::TextField::Property::OUTLINE:
1118 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1121 case Toolkit::TextField::Property::INPUT_OUTLINE:
1123 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1126 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1129 impl.mController->GetHiddenInputOption(map);
1133 case Toolkit::TextField::Property::PIXEL_SIZE:
1135 if( impl.mController )
1137 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1141 case Toolkit::TextField::Property::ENABLE_SELECTION:
1143 if( impl.mController )
1145 value = impl.mController->IsSelectionEnabled();
1149 case Toolkit::TextField::Property::PLACEHOLDER:
1152 impl.mController->GetPlaceholderProperty( map );
1156 case Toolkit::TextField::Property::ELLIPSIS:
1158 if( impl.mController )
1160 value = impl.mController->IsTextElideEnabled();
1164 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1166 if( impl.mController )
1168 value = impl.mController->IsShiftSelectionEnabled();
1172 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1174 if( impl.mController )
1176 value = impl.mController->IsGrabHandleEnabled();
1180 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1182 if( impl.mController )
1184 value = impl.mController->IsMatchSystemLanguageDirection();
1188 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1190 if (impl.mController)
1192 value = impl.mController->IsGrabHandlePopupEnabled();
1202 void TextField::SelectWholeText()
1204 if( mController && mController->IsShowingRealText() )
1206 mController->SelectEvent( 0.f, 0.f, true );
1211 InputMethodContext TextField::GetInputMethodContext()
1213 return mInputMethodContext;
1216 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1218 Dali::BaseHandle handle( object );
1220 bool connected( true );
1221 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1223 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1225 field.TextChangedSignal().Connect( tracker, functor );
1227 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1229 field.MaxLengthReachedSignal().Connect( tracker, functor );
1231 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1233 field.InputStyleChangedSignal().Connect( tracker, functor );
1237 // signalName does not match any signal
1244 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1246 return mTextChangedSignal;
1249 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1251 return mMaxLengthReachedSignal;
1254 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1256 return mInputStyleChangedSignal;
1259 void TextField::OnInitialize()
1261 Actor self = Self();
1263 mController = Text::Controller::New( this, this );
1265 // When using the vector-based rendering, the size of the GLyphs are different
1266 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1267 mController->SetGlyphType( glyphType );
1269 mDecorator = Text::Decorator::New( *mController,
1272 mInputMethodContext = InputMethodContext::New( self );
1274 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1276 // Enables the text input.
1277 mController->EnableTextInput( mDecorator, mInputMethodContext );
1279 // Enables the horizontal scrolling after the text input has been enabled.
1280 mController->SetHorizontalScrollEnabled( true );
1282 // Disables the vertical scrolling.
1283 mController->SetVerticalScrollEnabled( false );
1285 // Disable the smooth handle panning.
1286 mController->SetSmoothHandlePanEnabled( false );
1288 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1289 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1291 // Sets layoutDirection value
1292 Dali::Stage stage = Dali::Stage::GetCurrent();
1293 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1294 mController->SetLayoutDirection( layoutDirection );
1296 // Forward input events to controller
1297 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1298 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1300 self.TouchSignal().Connect( this, &TextField::OnTouched );
1302 // Set BoundingBox to stage size if not already set.
1303 Rect<int> boundingBox;
1304 mDecorator->GetBoundingBox( boundingBox );
1306 if( boundingBox.IsEmpty() )
1308 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1309 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1312 // Flip vertically the 'left' selection handle
1313 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1315 // Fill-parent area by default
1316 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1317 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1318 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1320 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1322 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1328 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1330 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1334 case StyleChange::DEFAULT_FONT_CHANGE:
1336 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1337 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1338 // Property system did not set the font so should update it.
1339 mController->UpdateAfterFontChange( newFont );
1344 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1346 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1350 case StyleChange::THEME_CHANGE:
1352 // Nothing to do, let control base class handle this
1357 // Up call to Control
1358 Control::OnStyleChange( styleManager, change );
1361 Vector3 TextField::GetNaturalSize()
1364 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1366 Vector3 naturalSize = mController->GetNaturalSize();
1367 naturalSize.width += ( padding.start + padding.end );
1368 naturalSize.height += ( padding.top + padding.bottom );
1373 float TextField::GetHeightForWidth( float width )
1376 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1377 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1380 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1384 Actor self = Self();
1387 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1389 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1391 // Support Right-To-Left of padding
1392 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1393 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1395 std::swap( padding.start, padding.end );
1400 mStencil.SetPosition( padding.start, padding.top );
1404 mActiveLayer.SetPosition( padding.start, padding.top );
1407 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1409 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1412 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1415 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1417 mDecorator->Relayout( size );
1422 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1425 RenderText( updateTextType );
1429 // The text-field emits signals when the input style changes. These changes of style are
1430 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1431 // can't be emitted during the size negotiation as the callbacks may update the UI.
1432 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1433 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1435 if( Adaptor::IsAvailable() )
1437 Adaptor& adaptor = Adaptor::Get();
1439 if( NULL == mIdleCallback )
1441 // @note: The callback manager takes the ownership of the callback object.
1442 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1443 adaptor.AddIdle( mIdleCallback, false );
1449 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1451 Actor renderableActor;
1453 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1457 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1459 renderableActor = mRenderer->Render( mController->GetView(),
1461 Property::INVALID_INDEX, // Animatable property not supported
1463 DepthIndex::CONTENT );
1466 if( renderableActor != mRenderableActor )
1468 UnparentAndReset( mRenderableActor );
1469 mRenderableActor = renderableActor;
1473 if( mRenderableActor )
1475 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1479 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1484 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1486 // Support Right-To-Left of padding
1487 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1488 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1490 std::swap( padding.start, padding.end );
1493 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1497 // Make sure the actors are parented correctly with/without clipping
1498 Actor self = mStencil ? mStencil : Self();
1500 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1501 endIt = mClippingDecorationActors.end();
1506 it->LowerToBottom();
1508 mClippingDecorationActors.clear();
1510 self.Add( mRenderableActor );
1514 void TextField::OnKeyInputFocusGained()
1516 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1517 if( mInputMethodContext )
1519 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1521 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1523 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1525 // Notify that the text editing start.
1526 mInputMethodContext.Activate();
1528 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1529 mInputMethodContext.SetRestoreAfterFocusLost( true );
1532 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1535 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1538 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1539 Internal::Control& controlImpl = GetImplementation( control );
1540 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1541 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1542 if( enableAutofill )
1544 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1545 container.SetFocusedControl( control );
1547 Internal::AutofillContainer& containerImpl = GetImpl( container );
1548 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1549 if( containerGroup != nullptr )
1551 containerGroup.RequestAuthentication();
1555 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1557 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1560 void TextField::OnKeyInputFocusLost()
1562 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1563 if ( mInputMethodContext )
1565 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1566 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1567 mInputMethodContext.SetRestoreAfterFocusLost( false );
1569 // Notify that the text editing finish.
1570 mInputMethodContext.Deactivate();
1572 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1574 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1578 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1581 mController->KeyboardFocusLostEvent();
1583 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1586 void TextField::OnTap( const TapGesture& gesture )
1588 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1589 if ( mInputMethodContext )
1591 mInputMethodContext.Activate();
1593 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1595 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1596 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1601 void TextField::OnPan( const PanGesture& gesture )
1603 mController->PanEvent( gesture.state, gesture.displacement );
1606 void TextField::OnLongPress( const LongPressGesture& gesture )
1608 if ( mInputMethodContext )
1610 mInputMethodContext.Activate();
1613 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1614 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1619 bool TextField::OnKeyEvent( const KeyEvent& event )
1621 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1623 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1625 // Make sure ClearKeyInputFocus when only key is up
1626 if( event.state == KeyEvent::Up )
1628 ClearKeyInputFocus();
1633 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1635 // Do nothing when enter is comming.
1639 return mController->KeyEvent( event );
1642 void TextField::RequestTextRelayout()
1647 void TextField::TextChanged()
1649 Dali::Toolkit::TextField handle( GetOwner() );
1650 mTextChangedSignal.Emit( handle );
1653 void TextField::MaxLengthReached()
1655 Dali::Toolkit::TextField handle( GetOwner() );
1656 mMaxLengthReachedSignal.Emit( handle );
1659 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1661 Dali::Toolkit::TextField handle( GetOwner() );
1663 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1665 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1667 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1669 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1671 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1673 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1675 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1677 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1679 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1681 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1683 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1685 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1687 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1689 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1691 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1693 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1695 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1697 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1699 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1701 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1703 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1706 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1709 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1715 mClippingDecorationActors.push_back( actor );
1719 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1720 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1721 Self().Add( actor );
1722 mActiveLayer = actor;
1727 void TextField::OnStageConnect( Dali::Actor actor )
1729 if ( mHasBeenStaged )
1731 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1735 mHasBeenStaged = true;
1739 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1741 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1742 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1745 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1749 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1754 Scripting::CreatePropertyMap( image, map );
1760 void TextField::EnableClipping()
1764 // Creates an extra control to be used as stencil buffer.
1765 mStencil = Control::New();
1766 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1767 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1769 // Creates a background visual. Even if the color is transparent it updates the stencil.
1770 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1771 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1772 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1774 // Enable the clipping property.
1775 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1776 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1778 Self().Add( mStencil );
1782 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1784 mController->PasteClipboardItemEvent();
1787 void TextField::KeyboardStatusChanged(bool keyboardShown)
1789 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1791 // Just hide the grab handle when keyboard is hidden.
1792 if (!keyboardShown )
1794 mController->KeyboardFocusLostEvent();
1798 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1802 void TextField::OnStageConnection( int depth )
1804 // Sets the depth to the visuals inside the text's decorator.
1805 mDecorator->SetTextDepth( depth );
1807 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1809 // Call the Control::OnStageConnection() to set the depth of the background.
1810 Control::OnStageConnection( depth );
1813 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1818 void TextField::OnIdleSignal()
1820 // Emits the change of input style signals.
1821 mController->ProcessInputStyleChangedSignals();
1823 // Set the pointer to null as the callback manager deletes the callback after execute it.
1824 mIdleCallback = NULL;
1827 TextField::TextField()
1828 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1829 mIdleCallback( NULL ),
1830 mAlignmentOffset( 0.f ),
1831 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1832 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1833 mHasBeenStaged( false )
1837 TextField::~TextField()
1839 UnparentAndReset( mStencil );
1841 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1843 Adaptor::Get().RemoveIdle( mIdleCallback );
1847 } // namespace Internal
1849 } // namespace Toolkit