2 * Copyright (c) 2018 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/adaptors/adaptor.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/rendering-backend.h>
35 #include <dali-toolkit/public-api/text/text-enumerations.h>
36 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
49 using namespace Dali::Toolkit::Text;
60 namespace // unnamed namespace
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
67 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 } // unnamed namespace
75 return Toolkit::TextField::New();
78 // Setup properties, signals and actions using the type-registry.
79 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
135 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
136 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
139 DALI_TYPE_REGISTRATION_END()
143 Toolkit::TextField TextField::New()
145 // Create the implementation, temporarily owned by this handle on stack
146 IntrusivePtr< TextField > impl = new TextField();
148 // Pass ownership to CustomActor handle
149 Toolkit::TextField handle( *impl );
151 // Second-phase init of the implementation
152 // This can only be done after the CustomActor connection has been made...
158 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
160 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
162 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
167 TextField& impl( GetImpl( textField ) );
171 case Toolkit::TextField::Property::RENDERING_BACKEND:
173 int backend = value.Get< int >();
174 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
176 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
177 if( Text::RENDERING_VECTOR_BASED == backend )
179 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
182 if( impl.mRenderingBackend != backend )
184 impl.mRenderingBackend = backend;
185 impl.mRenderer.Reset();
187 if( impl.mController )
189 // When using the vector-based rendering, the size of the GLyphs are different
190 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
191 impl.mController->SetGlyphType( glyphType );
196 case Toolkit::TextField::Property::TEXT:
198 if( impl.mController )
200 const std::string& text = value.Get< std::string >();
201 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
203 impl.mController->SetText( text );
207 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
209 if( impl.mController )
211 const std::string& text = value.Get< std::string >();
212 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
214 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
218 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
220 if( impl.mController )
222 const std::string& text = value.Get< std::string >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
225 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
229 case Toolkit::TextField::Property::FONT_FAMILY:
231 if( impl.mController )
233 const std::string& fontFamily = value.Get< std::string >();
234 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
235 impl.mController->SetDefaultFontFamily( fontFamily );
239 case Toolkit::TextField::Property::FONT_STYLE:
241 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
244 case Toolkit::TextField::Property::POINT_SIZE:
246 if( impl.mController )
248 const float pointSize = value.Get< float >();
249 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
251 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
253 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
258 case Toolkit::TextField::Property::MAX_LENGTH:
260 if( impl.mController )
262 const int max = value.Get< int >();
263 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
265 impl.mController->SetMaximumNumberOfCharacters( max );
269 case Toolkit::TextField::Property::EXCEED_POLICY:
271 impl.mExceedPolicy = value.Get<int>();
273 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
275 impl.EnableClipping();
279 UnparentAndReset( impl.mStencil );
281 impl.RequestTextRelayout();
284 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
286 if( impl.mController )
288 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
289 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
291 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
292 impl.mController->SetHorizontalAlignment( alignment );
297 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
299 if( impl.mController )
301 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
302 if( GetVerticalAlignmentEnumeration( value, alignment ) )
304 impl.mController->SetVerticalAlignment( alignment );
305 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
310 case Toolkit::TextField::Property::TEXT_COLOR:
312 if( impl.mController )
314 const Vector4& textColor = value.Get< Vector4 >();
315 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 );
317 if( impl.mController->GetDefaultColor() != textColor )
319 impl.mController->SetDefaultColor( textColor );
320 impl.mController->SetInputColor( textColor );
321 impl.mRenderer.Reset();
326 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
328 if( impl.mController )
330 const Vector4& textColor = value.Get< Vector4 >();
331 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 );
333 if( impl.mController->GetPlaceholderTextColor() != textColor )
335 impl.mController->SetPlaceholderTextColor( textColor );
336 impl.mRenderer.Reset();
341 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
343 if( impl.mDecorator )
345 const Vector4& color = value.Get< Vector4 >();
346 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 );
348 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
349 impl.RequestTextRelayout();
353 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
355 if( impl.mDecorator )
357 const Vector4& color = value.Get< Vector4 >();
358 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 );
360 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
361 impl.RequestTextRelayout();
365 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
367 if( impl.mController )
369 const bool enable = value.Get< bool >();
370 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
372 impl.mController->SetEnableCursorBlink( enable );
373 impl.RequestTextRelayout();
377 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
379 if( impl.mDecorator )
381 const float interval = value.Get< float >();
382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
384 impl.mDecorator->SetCursorBlinkInterval( interval );
388 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
390 if( impl.mDecorator )
392 const float duration = value.Get< float >();
393 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
395 impl.mDecorator->SetCursorBlinkDuration( duration );
399 case Toolkit::TextField::Property::CURSOR_WIDTH:
401 if( impl.mDecorator )
403 const int width = value.Get< int >();
404 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
406 impl.mDecorator->SetCursorWidth( width );
407 impl.mController->GetLayoutEngine().SetCursorWidth( width );
411 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
413 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
416 if( impl.mDecorator )
418 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
419 impl.RequestTextRelayout();
423 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
425 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
426 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
428 if( impl.mDecorator )
430 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
431 impl.RequestTextRelayout();
435 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
437 const float threshold = value.Get< float >();
438 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
440 if( impl.mDecorator )
442 impl.mDecorator->SetScrollThreshold( threshold );
446 case Toolkit::TextField::Property::SCROLL_SPEED:
448 const float speed = value.Get< float >();
449 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
451 if( impl.mDecorator )
453 impl.mDecorator->SetScrollSpeed( speed );
457 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
459 const Image image = Scripting::NewImage( value );
461 if( impl.mDecorator && image )
463 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
464 impl.RequestTextRelayout();
468 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
470 const Image image = Scripting::NewImage( value );
472 if( impl.mDecorator && image )
474 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
475 impl.RequestTextRelayout();
479 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
481 const Image image = Scripting::NewImage( value );
483 if( impl.mDecorator && image )
485 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
486 impl.RequestTextRelayout();
490 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
492 const Image image = Scripting::NewImage( value );
494 if( impl.mDecorator && image )
496 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
497 impl.RequestTextRelayout();
501 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
503 const Image image = Scripting::NewImage( value );
505 if( impl.mDecorator && image )
507 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
508 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
514 const Image image = Scripting::NewImage( value );
516 if( impl.mDecorator && image )
518 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
519 impl.RequestTextRelayout();
523 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
525 const Vector4 color = value.Get< Vector4 >();
526 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 );
528 if( impl.mDecorator )
530 impl.mDecorator->SetHighlightColor( color );
531 impl.RequestTextRelayout();
535 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
537 if( impl.mDecorator )
539 const Rect<int> box = value.Get< Rect<int> >();
540 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 );
542 impl.mDecorator->SetBoundingBox( box );
543 impl.RequestTextRelayout();
547 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
549 const Property::Map* map = value.GetMap();
552 impl.mInputMethodOptions.ApplyProperty( *map );
554 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
556 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
557 if (control == textField)
559 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
563 case Toolkit::TextField::Property::INPUT_COLOR:
565 if( impl.mController )
567 const Vector4 inputColor = value.Get< Vector4 >();
568 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 );
570 impl.mController->SetInputColor( inputColor );
574 case Toolkit::TextField::Property::ENABLE_MARKUP:
576 if( impl.mController )
578 const bool enableMarkup = value.Get<bool>();
579 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
581 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
585 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
587 if( impl.mController )
589 const std::string& fontFamily = value.Get< std::string >();
590 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
591 impl.mController->SetInputFontFamily( fontFamily );
595 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
597 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
600 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
602 if( impl.mController )
604 const float pointSize = value.Get< float >();
605 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
606 impl.mController->SetInputFontPointSize( pointSize );
610 case Toolkit::TextField::Property::UNDERLINE:
612 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
615 impl.mRenderer.Reset();
619 case Toolkit::TextField::Property::INPUT_UNDERLINE:
621 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
624 impl.mRenderer.Reset();
628 case Toolkit::TextField::Property::SHADOW:
630 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
633 impl.mRenderer.Reset();
637 case Toolkit::TextField::Property::INPUT_SHADOW:
639 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
642 impl.mRenderer.Reset();
646 case Toolkit::TextField::Property::EMBOSS:
648 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
651 impl.mRenderer.Reset();
655 case Toolkit::TextField::Property::INPUT_EMBOSS:
657 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
660 impl.mRenderer.Reset();
664 case Toolkit::TextField::Property::OUTLINE:
666 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
669 impl.mRenderer.Reset();
673 case Toolkit::TextField::Property::INPUT_OUTLINE:
675 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
678 impl.mRenderer.Reset();
682 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
684 const Property::Map* map = value.GetMap();
687 impl.mController->SetHiddenInputOption(*map);
691 case Toolkit::TextField::Property::PIXEL_SIZE:
693 if( impl.mController )
695 const float pixelSize = value.Get< float >();
696 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
698 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
700 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
705 case Toolkit::TextField::Property::ENABLE_SELECTION:
707 if( impl.mController )
709 const bool enableSelection = value.Get< bool >();
710 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
711 impl.mController->SetSelectionEnabled( enableSelection );
715 case Toolkit::TextField::Property::PLACEHOLDER:
717 const Property::Map* map = value.GetMap();
720 impl.mController->SetPlaceholderProperty( *map );
724 case Toolkit::TextField::Property::ELLIPSIS:
726 if( impl.mController )
728 const bool ellipsis = value.Get<bool>();
729 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
731 impl.mController->SetTextElideEnabled( ellipsis );
735 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
737 if( impl.mController )
739 const bool shiftSelection = value.Get<bool>();
740 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
742 impl.mController->SetShiftSelectionEnabled( shiftSelection );
746 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
748 if( impl.mController )
750 const bool grabHandleEnabled = value.Get<bool>();
751 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
753 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
757 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
759 if( impl.mController )
761 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
769 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
771 Property::Value value;
773 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
777 TextField& impl( GetImpl( textField ) );
781 case Toolkit::TextField::Property::RENDERING_BACKEND:
783 value = impl.mRenderingBackend;
786 case Toolkit::TextField::Property::TEXT:
788 if( impl.mController )
791 impl.mController->GetText( text );
792 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
797 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
799 if( impl.mController )
802 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
807 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
809 if( impl.mController )
812 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
817 case Toolkit::TextField::Property::FONT_FAMILY:
819 if( impl.mController )
821 value = impl.mController->GetDefaultFontFamily();
825 case Toolkit::TextField::Property::FONT_STYLE:
827 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
830 case Toolkit::TextField::Property::POINT_SIZE:
832 if( impl.mController )
834 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
838 case Toolkit::TextField::Property::MAX_LENGTH:
840 if( impl.mController )
842 value = impl.mController->GetMaximumNumberOfCharacters();
846 case Toolkit::TextField::Property::EXCEED_POLICY:
848 value = impl.mExceedPolicy;
851 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
853 if( impl.mController )
855 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
859 value = std::string( name );
864 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
866 if( impl.mController )
868 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
872 value = std::string( name );
877 case Toolkit::TextField::Property::TEXT_COLOR:
879 if ( impl.mController )
881 value = impl.mController->GetDefaultColor();
885 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
887 if ( impl.mController )
889 value = impl.mController->GetPlaceholderTextColor();
893 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
895 if( impl.mDecorator )
897 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
901 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
903 if( impl.mDecorator )
905 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
909 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
911 value = impl.mController->GetEnableCursorBlink();
914 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
916 if( impl.mDecorator )
918 value = impl.mDecorator->GetCursorBlinkInterval();
922 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
924 if( impl.mDecorator )
926 value = impl.mDecorator->GetCursorBlinkDuration();
930 case Toolkit::TextField::Property::CURSOR_WIDTH:
932 if( impl.mDecorator )
934 value = impl.mDecorator->GetCursorWidth();
938 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
940 if( impl.mDecorator )
942 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
945 value = image.GetUrl();
950 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
952 if( impl.mDecorator )
954 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
957 value = image.GetUrl();
962 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
964 if( impl.mDecorator )
966 value = impl.mDecorator->GetScrollThreshold();
970 case Toolkit::TextField::Property::SCROLL_SPEED:
972 if( impl.mDecorator )
974 value = impl.mDecorator->GetScrollSpeed();
978 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
980 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
983 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
985 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
988 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
990 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
993 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
995 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
998 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1000 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1003 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1005 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1008 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1010 if( impl.mDecorator )
1012 value = impl.mDecorator->GetHighlightColor();
1016 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1018 if( impl.mDecorator )
1020 Rect<int> boundingBox;
1021 impl.mDecorator->GetBoundingBox( boundingBox );
1022 value = boundingBox;
1026 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1029 impl.mInputMethodOptions.RetrieveProperty( map );
1033 case Toolkit::TextField::Property::INPUT_COLOR:
1035 if( impl.mController )
1037 value = impl.mController->GetInputColor();
1041 case Toolkit::TextField::Property::ENABLE_MARKUP:
1043 if( impl.mController )
1045 value = impl.mController->IsMarkupProcessorEnabled();
1049 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1051 if( impl.mController )
1053 value = impl.mController->GetInputFontFamily();
1057 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1059 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1062 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1064 if( impl.mController )
1066 value = impl.mController->GetInputFontPointSize();
1070 case Toolkit::TextField::Property::UNDERLINE:
1072 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1075 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1077 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1080 case Toolkit::TextField::Property::SHADOW:
1082 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1085 case Toolkit::TextField::Property::INPUT_SHADOW:
1087 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1090 case Toolkit::TextField::Property::EMBOSS:
1092 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1095 case Toolkit::TextField::Property::INPUT_EMBOSS:
1097 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1100 case Toolkit::TextField::Property::OUTLINE:
1102 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1105 case Toolkit::TextField::Property::INPUT_OUTLINE:
1107 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1110 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1113 impl.mController->GetHiddenInputOption(map);
1117 case Toolkit::TextField::Property::PIXEL_SIZE:
1119 if( impl.mController )
1121 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1125 case Toolkit::TextField::Property::ENABLE_SELECTION:
1127 if( impl.mController )
1129 value = impl.mController->IsSelectionEnabled();
1133 case Toolkit::TextField::Property::PLACEHOLDER:
1136 impl.mController->GetPlaceholderProperty( map );
1140 case Toolkit::TextField::Property::ELLIPSIS:
1142 if( impl.mController )
1144 value = impl.mController->IsTextElideEnabled();
1148 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1150 if( impl.mController )
1152 value = impl.mController->IsShiftSelectionEnabled();
1156 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1158 if( impl.mController )
1160 value = impl.mController->IsGrabHandleEnabled();
1164 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1166 if( impl.mController )
1168 value = impl.mController->IsMatchSystemLanguageDirection();
1178 InputMethodContext TextField::GetInputMethodContext()
1180 return mInputMethodContext;
1183 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1185 Dali::BaseHandle handle( object );
1187 bool connected( true );
1188 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1190 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1192 field.TextChangedSignal().Connect( tracker, functor );
1194 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1196 field.MaxLengthReachedSignal().Connect( tracker, functor );
1198 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1200 field.InputStyleChangedSignal().Connect( tracker, functor );
1204 // signalName does not match any signal
1211 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1213 return mTextChangedSignal;
1216 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1218 return mMaxLengthReachedSignal;
1221 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1223 return mInputStyleChangedSignal;
1226 void TextField::OnInitialize()
1228 Actor self = Self();
1230 mController = Text::Controller::New( this, this );
1232 // When using the vector-based rendering, the size of the GLyphs are different
1233 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1234 mController->SetGlyphType( glyphType );
1236 mDecorator = Text::Decorator::New( *mController,
1239 mInputMethodContext = InputMethodContext::New();
1241 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1243 // Enables the text input.
1244 mController->EnableTextInput( mDecorator, mInputMethodContext );
1246 // Enables the horizontal scrolling after the text input has been enabled.
1247 mController->SetHorizontalScrollEnabled( true );
1249 // Disables the vertical scrolling.
1250 mController->SetVerticalScrollEnabled( false );
1252 // Disable the smooth handle panning.
1253 mController->SetSmoothHandlePanEnabled( false );
1255 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1256 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1258 // Sets layoutDirection value
1259 Dali::Stage stage = Dali::Stage::GetCurrent();
1260 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1261 mController->SetLayoutDirection( layoutDirection );
1263 // Forward input events to controller
1264 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1265 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1267 self.TouchSignal().Connect( this, &TextField::OnTouched );
1269 // Set BoundingBox to stage size if not already set.
1270 Rect<int> boundingBox;
1271 mDecorator->GetBoundingBox( boundingBox );
1273 if( boundingBox.IsEmpty() )
1275 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1276 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1279 // Flip vertically the 'left' selection handle
1280 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1282 // Fill-parent area by default
1283 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1284 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1285 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1287 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1289 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1295 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1297 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1301 case StyleChange::DEFAULT_FONT_CHANGE:
1303 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1304 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1305 // Property system did not set the font so should update it.
1306 mController->UpdateAfterFontChange( newFont );
1311 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1313 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1317 case StyleChange::THEME_CHANGE:
1319 // Nothing to do, let control base class handle this
1324 // Up call to Control
1325 Control::OnStyleChange( styleManager, change );
1328 Vector3 TextField::GetNaturalSize()
1331 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1333 Vector3 naturalSize = mController->GetNaturalSize();
1334 naturalSize.width += ( padding.start + padding.end );
1335 naturalSize.height += ( padding.top + padding.bottom );
1340 float TextField::GetHeightForWidth( float width )
1343 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1344 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1347 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1349 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1351 Actor self = Self();
1354 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1356 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1358 // Support Right-To-Left of padding
1359 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1360 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1362 std::swap( padding.start, padding.end );
1367 mStencil.SetPosition( padding.start, padding.top );
1371 mActiveLayer.SetPosition( padding.start, padding.top );
1374 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1376 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1382 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1384 mDecorator->Relayout( size );
1389 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1392 RenderText( updateTextType );
1396 // The text-field emits signals when the input style changes. These changes of style are
1397 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1398 // can't be emitted during the size negotiation as the callbacks may update the UI.
1399 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1400 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1402 if( Adaptor::IsAvailable() )
1404 Adaptor& adaptor = Adaptor::Get();
1406 if( NULL == mIdleCallback )
1408 // @note: The callback manager takes the ownership of the callback object.
1409 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1410 adaptor.AddIdle( mIdleCallback, false );
1416 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1418 Actor renderableActor;
1420 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1424 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1426 renderableActor = mRenderer->Render( mController->GetView(),
1428 Property::INVALID_INDEX, // Animatable property not supported
1430 DepthIndex::CONTENT );
1433 if( renderableActor != mRenderableActor )
1435 UnparentAndReset( mRenderableActor );
1436 mRenderableActor = renderableActor;
1440 if( mRenderableActor )
1442 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1446 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1451 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1453 // Support Right-To-Left of padding
1454 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1455 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1457 std::swap( padding.start, padding.end );
1460 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1464 // Make sure the actors are parented correctly with/without clipping
1465 Actor self = mStencil ? mStencil : Self();
1467 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1468 endIt = mClippingDecorationActors.end();
1473 it->LowerToBottom();
1475 mClippingDecorationActors.clear();
1477 self.Add( mRenderableActor );
1481 void TextField::OnKeyInputFocusGained()
1483 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1484 if ( mInputMethodContext )
1486 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1488 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1490 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1492 // Notify that the text editing start.
1493 mInputMethodContext.Activate();
1495 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1496 mInputMethodContext.SetRestoreAfterFocusLost( true );
1498 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1502 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1505 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1507 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1510 void TextField::OnKeyInputFocusLost()
1512 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1513 if ( mInputMethodContext )
1515 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1516 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1517 mInputMethodContext.SetRestoreAfterFocusLost( false );
1519 // Notify that the text editing finish.
1520 mInputMethodContext.Deactivate();
1522 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1524 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1528 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1531 mController->KeyboardFocusLostEvent();
1533 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1536 void TextField::OnTap( const TapGesture& gesture )
1538 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1539 if ( mInputMethodContext )
1541 mInputMethodContext.Activate();
1543 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1545 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1546 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1551 void TextField::OnPan( const PanGesture& gesture )
1553 mController->PanEvent( gesture.state, gesture.displacement );
1556 void TextField::OnLongPress( const LongPressGesture& gesture )
1558 if ( mInputMethodContext )
1560 mInputMethodContext.Activate();
1563 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1564 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1569 bool TextField::OnKeyEvent( const KeyEvent& event )
1571 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1573 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1575 // Make sure ClearKeyInputFocus when only key is up
1576 if( event.state == KeyEvent::Up )
1578 ClearKeyInputFocus();
1583 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1585 // Do nothing when enter is comming.
1589 return mController->KeyEvent( event );
1592 void TextField::RequestTextRelayout()
1597 void TextField::TextChanged()
1599 Dali::Toolkit::TextField handle( GetOwner() );
1600 mTextChangedSignal.Emit( handle );
1603 void TextField::MaxLengthReached()
1605 Dali::Toolkit::TextField handle( GetOwner() );
1606 mMaxLengthReachedSignal.Emit( handle );
1609 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1611 Dali::Toolkit::TextField handle( GetOwner() );
1613 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1615 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1617 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1619 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1621 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1623 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1625 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1627 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1629 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1631 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1633 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1635 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1637 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1639 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1641 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1643 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1645 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1647 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1649 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1651 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1653 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1656 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1659 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1665 mClippingDecorationActors.push_back( actor );
1669 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1670 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1671 Self().Add( actor );
1672 mActiveLayer = actor;
1677 void TextField::OnStageConnect( Dali::Actor actor )
1679 if ( mHasBeenStaged )
1681 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1685 mHasBeenStaged = true;
1689 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1691 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1692 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1695 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1699 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1704 Scripting::CreatePropertyMap( image, map );
1710 void TextField::EnableClipping()
1714 // Creates an extra control to be used as stencil buffer.
1715 mStencil = Control::New();
1716 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1717 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1719 // Creates a background visual. Even if the color is transparent it updates the stencil.
1720 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1721 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1722 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1724 // Enable the clipping property.
1725 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1726 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1728 Self().Add( mStencil );
1732 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1734 mController->PasteClipboardItemEvent();
1737 void TextField::KeyboardStatusChanged(bool keyboardShown)
1739 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1741 // Just hide the grab handle when keyboard is hidden.
1742 if (!keyboardShown )
1744 mController->KeyboardFocusLostEvent();
1748 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1752 void TextField::OnStageConnection( int depth )
1754 // Sets the depth to the visuals inside the text's decorator.
1755 mDecorator->SetTextDepth( depth );
1757 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1759 // Call the Control::OnStageConnection() to set the depth of the background.
1760 Control::OnStageConnection( depth );
1763 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1768 void TextField::OnIdleSignal()
1770 // Emits the change of input style signals.
1771 mController->ProcessInputStyleChangedSignals();
1773 // Set the pointer to null as the callback manager deletes the callback after execute it.
1774 mIdleCallback = NULL;
1777 TextField::TextField()
1778 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1779 mIdleCallback( NULL ),
1780 mAlignmentOffset( 0.f ),
1781 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1782 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1783 mHasBeenStaged( false )
1787 TextField::~TextField()
1789 UnparentAndReset( mStencil );
1791 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1793 Adaptor::Get().RemoveIdle( mIdleCallback );
1797 } // namespace Internal
1799 } // namespace Toolkit