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", VECTOR4, BACKGROUND )
140 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
146 DALI_TYPE_REGISTRATION_END()
150 Toolkit::TextField TextField::New()
152 // Create the implementation, temporarily owned by this handle on stack
153 IntrusivePtr< TextField > impl = new TextField();
155 // Pass ownership to CustomActor handle
156 Toolkit::TextField handle( *impl );
158 // Second-phase init of the implementation
159 // This can only be done after the CustomActor connection has been made...
165 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
167 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
169 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
174 TextField& impl( GetImpl( textField ) );
178 case Toolkit::TextField::Property::RENDERING_BACKEND:
180 int backend = value.Get< int >();
181 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
183 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
184 if( Text::RENDERING_VECTOR_BASED == backend )
186 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
189 if( impl.mRenderingBackend != backend )
191 impl.mRenderingBackend = backend;
192 impl.mRenderer.Reset();
194 if( impl.mController )
196 // When using the vector-based rendering, the size of the GLyphs are different
197 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
198 impl.mController->SetGlyphType( glyphType );
203 case Toolkit::TextField::Property::TEXT:
205 if( impl.mController )
207 const std::string& text = value.Get< std::string >();
208 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
210 impl.mController->SetText( text );
214 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
216 if( impl.mController )
218 const std::string& text = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
221 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
225 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
227 if( impl.mController )
229 const std::string& text = value.Get< std::string >();
230 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
232 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
236 case Toolkit::TextField::Property::FONT_FAMILY:
238 if( impl.mController )
240 const std::string& fontFamily = value.Get< std::string >();
241 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
242 impl.mController->SetDefaultFontFamily( fontFamily );
246 case Toolkit::TextField::Property::FONT_STYLE:
248 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
251 case Toolkit::TextField::Property::POINT_SIZE:
253 if( impl.mController )
255 const float pointSize = value.Get< float >();
256 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
258 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
260 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
265 case Toolkit::TextField::Property::MAX_LENGTH:
267 if( impl.mController )
269 const int max = value.Get< int >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
272 impl.mController->SetMaximumNumberOfCharacters( max );
276 case Toolkit::TextField::Property::EXCEED_POLICY:
278 impl.mExceedPolicy = value.Get<int>();
280 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
282 impl.EnableClipping();
286 UnparentAndReset( impl.mStencil );
288 impl.RequestTextRelayout();
291 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
293 if( impl.mController )
295 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
296 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
298 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
299 impl.mController->SetHorizontalAlignment( alignment );
304 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
306 if( impl.mController )
308 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
309 if( GetVerticalAlignmentEnumeration( value, alignment ) )
311 impl.mController->SetVerticalAlignment( alignment );
312 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
317 case Toolkit::TextField::Property::TEXT_COLOR:
319 if( impl.mController )
321 const Vector4& textColor = value.Get< Vector4 >();
322 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 );
324 if( impl.mController->GetDefaultColor() != textColor )
326 impl.mController->SetDefaultColor( textColor );
327 impl.mController->SetInputColor( textColor );
328 impl.mRenderer.Reset();
333 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
335 if( impl.mController )
337 const Vector4& textColor = value.Get< Vector4 >();
338 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 );
340 if( impl.mController->GetPlaceholderTextColor() != textColor )
342 impl.mController->SetPlaceholderTextColor( textColor );
343 impl.mRenderer.Reset();
348 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
350 if( impl.mDecorator )
352 const Vector4& color = value.Get< Vector4 >();
353 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 );
355 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
356 impl.RequestTextRelayout();
360 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
362 if( impl.mDecorator )
364 const Vector4& color = value.Get< Vector4 >();
365 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 );
367 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
368 impl.RequestTextRelayout();
372 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
374 if( impl.mController )
376 const bool enable = value.Get< bool >();
377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
379 impl.mController->SetEnableCursorBlink( enable );
380 impl.RequestTextRelayout();
384 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
386 if( impl.mDecorator )
388 const float interval = value.Get< float >();
389 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
391 impl.mDecorator->SetCursorBlinkInterval( interval );
395 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
397 if( impl.mDecorator )
399 const float duration = value.Get< float >();
400 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
402 impl.mDecorator->SetCursorBlinkDuration( duration );
406 case Toolkit::TextField::Property::CURSOR_WIDTH:
408 if( impl.mDecorator )
410 const int width = value.Get< int >();
411 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
413 impl.mDecorator->SetCursorWidth( width );
414 impl.mController->GetLayoutEngine().SetCursorWidth( width );
418 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
420 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
421 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
423 if( impl.mDecorator )
425 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
426 impl.RequestTextRelayout();
430 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
432 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
433 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
435 if( impl.mDecorator )
437 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
438 impl.RequestTextRelayout();
442 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
444 const float threshold = value.Get< float >();
445 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
447 if( impl.mDecorator )
449 impl.mDecorator->SetScrollThreshold( threshold );
453 case Toolkit::TextField::Property::SCROLL_SPEED:
455 const float speed = value.Get< float >();
456 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
458 if( impl.mDecorator )
460 impl.mDecorator->SetScrollSpeed( speed );
464 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
466 const Image image = Scripting::NewImage( value );
468 if( impl.mDecorator && image )
470 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
471 impl.RequestTextRelayout();
475 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
477 const Image image = Scripting::NewImage( value );
479 if( impl.mDecorator && image )
481 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
482 impl.RequestTextRelayout();
486 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
488 const Image image = Scripting::NewImage( value );
490 if( impl.mDecorator && image )
492 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
493 impl.RequestTextRelayout();
497 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
499 const Image image = Scripting::NewImage( value );
501 if( impl.mDecorator && image )
503 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
504 impl.RequestTextRelayout();
508 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
510 const Image image = Scripting::NewImage( value );
512 if( impl.mDecorator && image )
514 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
515 impl.RequestTextRelayout();
519 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
521 const Image image = Scripting::NewImage( value );
523 if( impl.mDecorator && image )
525 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
526 impl.RequestTextRelayout();
530 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
532 const Vector4 color = value.Get< Vector4 >();
533 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 );
535 if( impl.mDecorator )
537 impl.mDecorator->SetHighlightColor( color );
538 impl.RequestTextRelayout();
542 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
544 if( impl.mDecorator )
546 const Rect<int> box = value.Get< Rect<int> >();
547 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 );
549 impl.mDecorator->SetBoundingBox( box );
550 impl.RequestTextRelayout();
554 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
556 const Property::Map* map = value.GetMap();
559 impl.mInputMethodOptions.ApplyProperty( *map );
561 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
563 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
564 if (control == textField)
566 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
570 case Toolkit::TextField::Property::INPUT_COLOR:
572 if( impl.mController )
574 const Vector4 inputColor = value.Get< Vector4 >();
575 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 );
577 impl.mController->SetInputColor( inputColor );
581 case Toolkit::TextField::Property::ENABLE_MARKUP:
583 if( impl.mController )
585 const bool enableMarkup = value.Get<bool>();
586 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
588 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
592 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
594 if( impl.mController )
596 const std::string& fontFamily = value.Get< std::string >();
597 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
598 impl.mController->SetInputFontFamily( fontFamily );
602 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
604 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
607 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
609 if( impl.mController )
611 const float pointSize = value.Get< float >();
612 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
613 impl.mController->SetInputFontPointSize( pointSize );
617 case Toolkit::TextField::Property::UNDERLINE:
619 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
622 impl.mRenderer.Reset();
626 case Toolkit::TextField::Property::INPUT_UNDERLINE:
628 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
631 impl.mRenderer.Reset();
635 case Toolkit::TextField::Property::SHADOW:
637 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
640 impl.mRenderer.Reset();
644 case Toolkit::TextField::Property::INPUT_SHADOW:
646 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
649 impl.mRenderer.Reset();
653 case Toolkit::TextField::Property::EMBOSS:
655 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
658 impl.mRenderer.Reset();
662 case Toolkit::TextField::Property::INPUT_EMBOSS:
664 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
667 impl.mRenderer.Reset();
671 case Toolkit::TextField::Property::OUTLINE:
673 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
676 impl.mRenderer.Reset();
680 case Toolkit::TextField::Property::INPUT_OUTLINE:
682 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
685 impl.mRenderer.Reset();
689 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
691 const Property::Map* map = value.GetMap();
694 impl.mController->SetHiddenInputOption(*map);
698 case Toolkit::TextField::Property::PIXEL_SIZE:
700 if( impl.mController )
702 const float pixelSize = value.Get< float >();
703 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
705 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
707 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
712 case Toolkit::TextField::Property::ENABLE_SELECTION:
714 if( impl.mController )
716 const bool enableSelection = value.Get< bool >();
717 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
718 impl.mController->SetSelectionEnabled( enableSelection );
722 case Toolkit::TextField::Property::PLACEHOLDER:
724 const Property::Map* map = value.GetMap();
727 impl.mController->SetPlaceholderProperty( *map );
731 case Toolkit::TextField::Property::ELLIPSIS:
733 if( impl.mController )
735 const bool ellipsis = value.Get<bool>();
736 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
738 impl.mController->SetTextElideEnabled( ellipsis );
742 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
744 if( impl.mController )
746 const bool shiftSelection = value.Get<bool>();
747 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
749 impl.mController->SetShiftSelectionEnabled( shiftSelection );
753 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
755 if( impl.mController )
757 const bool grabHandleEnabled = value.Get<bool>();
758 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
760 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
764 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
766 if( impl.mController )
768 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
772 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
774 if( impl.mController )
776 const bool grabHandlePopupEnabled = value.Get<bool>();
777 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
779 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
783 case Toolkit::DevelTextField::Property::BACKGROUND:
785 if( impl.mController )
787 const Vector4 backgroundColor = value.Get< Vector4 >();
788 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a );
790 impl.mController->SetBackgroundEnabled( true );
791 impl.mController->SetBackgroundColor( backgroundColor );
799 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
801 Property::Value value;
803 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
807 TextField& impl( GetImpl( textField ) );
811 case Toolkit::TextField::Property::RENDERING_BACKEND:
813 value = impl.mRenderingBackend;
816 case Toolkit::TextField::Property::TEXT:
818 if( impl.mController )
821 impl.mController->GetText( text );
822 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
827 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
829 if( impl.mController )
832 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
837 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
839 if( impl.mController )
842 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
847 case Toolkit::TextField::Property::FONT_FAMILY:
849 if( impl.mController )
851 value = impl.mController->GetDefaultFontFamily();
855 case Toolkit::TextField::Property::FONT_STYLE:
857 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
860 case Toolkit::TextField::Property::POINT_SIZE:
862 if( impl.mController )
864 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
868 case Toolkit::TextField::Property::MAX_LENGTH:
870 if( impl.mController )
872 value = impl.mController->GetMaximumNumberOfCharacters();
876 case Toolkit::TextField::Property::EXCEED_POLICY:
878 value = impl.mExceedPolicy;
881 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
883 if( impl.mController )
885 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
889 value = std::string( name );
894 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
896 if( impl.mController )
898 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
902 value = std::string( name );
907 case Toolkit::TextField::Property::TEXT_COLOR:
909 if ( impl.mController )
911 value = impl.mController->GetDefaultColor();
915 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
917 if ( impl.mController )
919 value = impl.mController->GetPlaceholderTextColor();
923 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
925 if( impl.mDecorator )
927 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
931 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
933 if( impl.mDecorator )
935 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
939 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
941 value = impl.mController->GetEnableCursorBlink();
944 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
946 if( impl.mDecorator )
948 value = impl.mDecorator->GetCursorBlinkInterval();
952 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
954 if( impl.mDecorator )
956 value = impl.mDecorator->GetCursorBlinkDuration();
960 case Toolkit::TextField::Property::CURSOR_WIDTH:
962 if( impl.mDecorator )
964 value = impl.mDecorator->GetCursorWidth();
968 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
970 if( impl.mDecorator )
972 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
975 value = image.GetUrl();
980 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
982 if( impl.mDecorator )
984 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
987 value = image.GetUrl();
992 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
994 if( impl.mDecorator )
996 value = impl.mDecorator->GetScrollThreshold();
1000 case Toolkit::TextField::Property::SCROLL_SPEED:
1002 if( impl.mDecorator )
1004 value = impl.mDecorator->GetScrollSpeed();
1008 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1010 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1013 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1015 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1018 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1020 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1023 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1025 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1028 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1030 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1033 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1035 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1038 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1040 if( impl.mDecorator )
1042 value = impl.mDecorator->GetHighlightColor();
1046 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1048 if( impl.mDecorator )
1050 Rect<int> boundingBox;
1051 impl.mDecorator->GetBoundingBox( boundingBox );
1052 value = boundingBox;
1056 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1059 impl.mInputMethodOptions.RetrieveProperty( map );
1063 case Toolkit::TextField::Property::INPUT_COLOR:
1065 if( impl.mController )
1067 value = impl.mController->GetInputColor();
1071 case Toolkit::TextField::Property::ENABLE_MARKUP:
1073 if( impl.mController )
1075 value = impl.mController->IsMarkupProcessorEnabled();
1079 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1081 if( impl.mController )
1083 value = impl.mController->GetInputFontFamily();
1087 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1089 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1092 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1094 if( impl.mController )
1096 value = impl.mController->GetInputFontPointSize();
1100 case Toolkit::TextField::Property::UNDERLINE:
1102 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1105 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1107 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1110 case Toolkit::TextField::Property::SHADOW:
1112 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1115 case Toolkit::TextField::Property::INPUT_SHADOW:
1117 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1120 case Toolkit::TextField::Property::EMBOSS:
1122 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1125 case Toolkit::TextField::Property::INPUT_EMBOSS:
1127 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1130 case Toolkit::TextField::Property::OUTLINE:
1132 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1135 case Toolkit::TextField::Property::INPUT_OUTLINE:
1137 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1140 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1143 impl.mController->GetHiddenInputOption(map);
1147 case Toolkit::TextField::Property::PIXEL_SIZE:
1149 if( impl.mController )
1151 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1155 case Toolkit::TextField::Property::ENABLE_SELECTION:
1157 if( impl.mController )
1159 value = impl.mController->IsSelectionEnabled();
1163 case Toolkit::TextField::Property::PLACEHOLDER:
1166 impl.mController->GetPlaceholderProperty( map );
1170 case Toolkit::TextField::Property::ELLIPSIS:
1172 if( impl.mController )
1174 value = impl.mController->IsTextElideEnabled();
1178 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1180 if( impl.mController )
1182 value = impl.mController->IsShiftSelectionEnabled();
1186 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1188 if( impl.mController )
1190 value = impl.mController->IsGrabHandleEnabled();
1194 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1196 if( impl.mController )
1198 value = impl.mController->IsMatchSystemLanguageDirection();
1202 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1204 if( impl.mController )
1206 value = impl.mController->IsGrabHandlePopupEnabled();
1210 case Toolkit::DevelTextField::Property::BACKGROUND:
1212 if( impl.mController )
1214 value = impl.mController->GetBackgroundColor();
1218 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1220 if( impl.mController )
1222 value = impl.mController->GetSelectedText( );
1232 void TextField::SelectWholeText()
1234 if( mController && mController->IsShowingRealText() )
1236 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1241 void TextField::SelectNone()
1243 if( mController && mController->IsShowingRealText() )
1245 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1250 InputMethodContext TextField::GetInputMethodContext()
1252 return mInputMethodContext;
1255 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1257 Dali::BaseHandle handle( object );
1259 bool connected( true );
1260 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1262 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1264 field.TextChangedSignal().Connect( tracker, functor );
1266 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1268 field.MaxLengthReachedSignal().Connect( tracker, functor );
1270 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1272 field.InputStyleChangedSignal().Connect( tracker, functor );
1276 // signalName does not match any signal
1283 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1285 return mTextChangedSignal;
1288 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1290 return mMaxLengthReachedSignal;
1293 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1295 return mInputStyleChangedSignal;
1298 void TextField::OnInitialize()
1300 Actor self = Self();
1302 mController = Text::Controller::New( this, this );
1304 // When using the vector-based rendering, the size of the GLyphs are different
1305 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1306 mController->SetGlyphType( glyphType );
1308 mDecorator = Text::Decorator::New( *mController,
1311 mInputMethodContext = InputMethodContext::New( self );
1313 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1315 // Enables the text input.
1316 mController->EnableTextInput( mDecorator, mInputMethodContext );
1318 // Enables the horizontal scrolling after the text input has been enabled.
1319 mController->SetHorizontalScrollEnabled( true );
1321 // Disables the vertical scrolling.
1322 mController->SetVerticalScrollEnabled( false );
1324 // Disable the smooth handle panning.
1325 mController->SetSmoothHandlePanEnabled( false );
1327 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1328 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1330 // Sets layoutDirection value
1331 Dali::Stage stage = Dali::Stage::GetCurrent();
1332 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1333 mController->SetLayoutDirection( layoutDirection );
1335 // Forward input events to controller
1336 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1337 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1339 self.TouchSignal().Connect( this, &TextField::OnTouched );
1341 // Set BoundingBox to stage size if not already set.
1342 Rect<int> boundingBox;
1343 mDecorator->GetBoundingBox( boundingBox );
1345 if( boundingBox.IsEmpty() )
1347 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1348 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1351 // Flip vertically the 'left' selection handle
1352 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1354 // Fill-parent area by default
1355 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1356 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1357 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1359 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1361 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1367 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1369 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1373 case StyleChange::DEFAULT_FONT_CHANGE:
1375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1376 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1377 // Property system did not set the font so should update it.
1378 mController->UpdateAfterFontChange( newFont );
1383 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1385 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1389 case StyleChange::THEME_CHANGE:
1391 // Nothing to do, let control base class handle this
1396 // Up call to Control
1397 Control::OnStyleChange( styleManager, change );
1400 Vector3 TextField::GetNaturalSize()
1403 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1405 Vector3 naturalSize = mController->GetNaturalSize();
1406 naturalSize.width += ( padding.start + padding.end );
1407 naturalSize.height += ( padding.top + padding.bottom );
1412 float TextField::GetHeightForWidth( float width )
1415 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1416 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1419 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1421 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1423 Actor self = Self();
1426 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1428 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1430 // Support Right-To-Left of padding
1431 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1432 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1434 std::swap( padding.start, padding.end );
1439 mStencil.SetPosition( padding.start, padding.top );
1443 mActiveLayer.SetPosition( padding.start, padding.top );
1446 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1448 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1451 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1454 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1456 mDecorator->Relayout( size );
1461 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1464 RenderText( updateTextType );
1468 // The text-field emits signals when the input style changes. These changes of style are
1469 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1470 // can't be emitted during the size negotiation as the callbacks may update the UI.
1471 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1472 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1474 if( Adaptor::IsAvailable() )
1476 Adaptor& adaptor = Adaptor::Get();
1478 if( NULL == mIdleCallback )
1480 // @note: The callback manager takes the ownership of the callback object.
1481 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1482 adaptor.AddIdle( mIdleCallback, false );
1488 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1490 Actor renderableActor;
1492 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1496 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1498 renderableActor = mRenderer->Render( mController->GetView(),
1500 Property::INVALID_INDEX, // Animatable property not supported
1502 DepthIndex::CONTENT );
1505 if( renderableActor != mRenderableActor )
1507 UnparentAndReset( mBackgroundActor );
1508 UnparentAndReset( mRenderableActor );
1509 mRenderableActor = renderableActor;
1511 if ( mRenderableActor )
1513 mBackgroundActor = mController->CreateBackgroundActor();
1518 if( mRenderableActor )
1520 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1522 float renderableActorPositionX, renderableActorPositionY;
1526 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1527 renderableActorPositionY = scrollOffset.y;
1532 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1534 // Support Right-To-Left of padding
1535 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1536 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1538 std::swap( padding.start, padding.end );
1541 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1542 renderableActorPositionY = scrollOffset.y + padding.top;
1545 mRenderableActor.SetPosition( renderableActorPositionX, renderableActorPositionY );
1547 // Make sure the actors are parented correctly with/without clipping
1548 Actor self = mStencil ? mStencil : Self();
1550 Actor highlightActor;
1552 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1553 endIt = mClippingDecorationActors.end();
1558 it->LowerToBottom();
1560 if ( it->GetName() == "HighlightActor" )
1562 highlightActor = *it;
1565 mClippingDecorationActors.clear();
1567 self.Add( mRenderableActor );
1569 if ( mBackgroundActor )
1571 if ( mDecorator && mDecorator->IsHighlightVisible() )
1573 self.Add( mBackgroundActor );
1574 mBackgroundActor.SetPosition( renderableActorPositionX, renderableActorPositionY); // In text field's coords.
1575 mBackgroundActor.LowerBelow( highlightActor );
1579 mRenderableActor.Add( mBackgroundActor );
1580 mBackgroundActor.SetPosition( 0.0f, 0.0f ); // In renderable actor's coords.
1581 mBackgroundActor.LowerToBottom();
1587 void TextField::OnKeyInputFocusGained()
1589 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1590 if( mInputMethodContext )
1592 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1594 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1596 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1598 // Notify that the text editing start.
1599 mInputMethodContext.Activate();
1601 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1602 mInputMethodContext.SetRestoreAfterFocusLost( true );
1605 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1608 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1611 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1612 Internal::Control& controlImpl = GetImplementation( control );
1613 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1614 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1615 if( enableAutofill )
1617 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1618 container.SetFocusedControl( control );
1620 Internal::AutofillContainer& containerImpl = GetImpl( container );
1621 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1622 if( containerGroup != nullptr )
1624 containerGroup.RequestAuthentication();
1628 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1630 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1633 void TextField::OnKeyInputFocusLost()
1635 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1636 if ( mInputMethodContext )
1638 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1639 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1640 mInputMethodContext.SetRestoreAfterFocusLost( false );
1642 // Notify that the text editing finish.
1643 mInputMethodContext.Deactivate();
1645 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1647 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1651 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1654 mController->KeyboardFocusLostEvent();
1656 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1659 void TextField::OnTap( const TapGesture& gesture )
1661 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1662 if ( mInputMethodContext )
1664 mInputMethodContext.Activate();
1666 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1668 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1669 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1674 void TextField::OnPan( const PanGesture& gesture )
1676 mController->PanEvent( gesture.state, gesture.displacement );
1679 void TextField::OnLongPress( const LongPressGesture& gesture )
1681 if ( mInputMethodContext )
1683 mInputMethodContext.Activate();
1686 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1687 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1692 bool TextField::OnKeyEvent( const KeyEvent& event )
1694 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1696 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1698 // Make sure ClearKeyInputFocus when only key is up
1699 if( event.state == KeyEvent::Up )
1701 ClearKeyInputFocus();
1706 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1708 // Do nothing when enter is comming.
1712 return mController->KeyEvent( event );
1715 void TextField::RequestTextRelayout()
1720 void TextField::TextChanged()
1722 Dali::Toolkit::TextField handle( GetOwner() );
1723 mTextChangedSignal.Emit( handle );
1726 void TextField::MaxLengthReached()
1728 Dali::Toolkit::TextField handle( GetOwner() );
1729 mMaxLengthReachedSignal.Emit( handle );
1732 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1734 Dali::Toolkit::TextField handle( GetOwner() );
1736 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1738 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1740 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1742 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1744 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1746 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1748 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1750 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1752 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1754 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1756 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1758 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1760 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1762 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1764 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1766 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1768 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1770 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1772 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1774 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1776 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1779 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1782 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1788 mClippingDecorationActors.push_back( actor );
1792 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1793 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1794 Self().Add( actor );
1795 mActiveLayer = actor;
1800 void TextField::OnStageConnect( Dali::Actor actor )
1802 if ( mHasBeenStaged )
1804 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1808 mHasBeenStaged = true;
1812 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1814 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1815 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1818 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1822 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1827 Scripting::CreatePropertyMap( image, map );
1833 void TextField::EnableClipping()
1837 // Creates an extra control to be used as stencil buffer.
1838 mStencil = Control::New();
1839 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1840 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1842 // Creates a background visual. Even if the color is transparent it updates the stencil.
1843 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1844 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1845 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1847 // Enable the clipping property.
1848 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1849 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1851 Self().Add( mStencil );
1855 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1857 mController->PasteClipboardItemEvent();
1860 void TextField::KeyboardStatusChanged(bool keyboardShown)
1862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1864 // Just hide the grab handle when keyboard is hidden.
1865 if (!keyboardShown )
1867 mController->KeyboardFocusLostEvent();
1871 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1875 void TextField::OnStageConnection( int depth )
1877 // Sets the depth to the visuals inside the text's decorator.
1878 mDecorator->SetTextDepth( depth );
1880 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1882 // Call the Control::OnStageConnection() to set the depth of the background.
1883 Control::OnStageConnection( depth );
1886 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1891 void TextField::OnIdleSignal()
1893 // Emits the change of input style signals.
1894 mController->ProcessInputStyleChangedSignals();
1896 // Set the pointer to null as the callback manager deletes the callback after execute it.
1897 mIdleCallback = NULL;
1900 TextField::TextField()
1901 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1902 mIdleCallback( NULL ),
1903 mAlignmentOffset( 0.f ),
1904 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1905 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1906 mHasBeenStaged( false )
1910 TextField::~TextField()
1912 UnparentAndReset( mStencil );
1914 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1916 Adaptor::Get().RemoveIdle( mIdleCallback );
1920 } // namespace Internal
1922 } // namespace Toolkit