2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/devel-api/adaptor-framework/key-devel.h>
26 #include <dali/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/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>
48 #include <dali/integration-api/adaptor-framework/adaptor.h>
50 using namespace Dali::Toolkit::Text;
61 namespace // unnamed namespace
64 #if defined(DEBUG_ENABLED)
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
68 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
69 } // unnamed namespace
76 return Toolkit::TextField::New();
79 // Setup properties, signals and actions using the type-registry.
80 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
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 )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
136 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
143 DALI_TYPE_REGISTRATION_END()
145 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
147 /// Retrieves a filename from a value that is a Property::Map
148 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
150 std::string filename;
151 const Property::Map* map = value.GetMap();
154 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
157 filenameValue->Get( filename );
165 Toolkit::TextField TextField::New()
167 // Create the implementation, temporarily owned by this handle on stack
168 IntrusivePtr< TextField > impl = new TextField();
170 // Pass ownership to CustomActor handle
171 Toolkit::TextField handle( *impl );
173 // Second-phase init of the implementation
174 // This can only be done after the CustomActor connection has been made...
180 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
182 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
188 TextField& impl( GetImpl( textField ) );
189 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
190 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
194 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
196 int backend = value.Get< int >();
197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
199 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
200 if( DevelText::RENDERING_VECTOR_BASED == backend )
202 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
205 if( impl.mRenderingBackend != backend )
207 impl.mRenderingBackend = backend;
208 impl.mRenderer.Reset();
210 // When using the vector-based rendering, the size of the GLyphs are different
211 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
212 impl.mController->SetGlyphType( glyphType );
216 case Toolkit::TextField::Property::TEXT:
218 const std::string& text = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
221 impl.mController->SetText( text );
224 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
226 const std::string& text = value.Get< std::string >();
227 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
229 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
232 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
234 const std::string& text = value.Get< std::string >();
235 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
237 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
240 case Toolkit::TextField::Property::FONT_FAMILY:
242 const std::string& fontFamily = value.Get< std::string >();
243 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
244 impl.mController->SetDefaultFontFamily( fontFamily );
247 case Toolkit::TextField::Property::FONT_STYLE:
249 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
252 case Toolkit::TextField::Property::POINT_SIZE:
254 const float pointSize = value.Get< float >();
255 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
257 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
259 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
263 case Toolkit::TextField::Property::MAX_LENGTH:
265 const int max = value.Get< int >();
266 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
268 impl.mController->SetMaximumNumberOfCharacters( max );
271 case Toolkit::TextField::Property::EXCEED_POLICY:
273 impl.mExceedPolicy = value.Get<int>();
275 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
277 impl.EnableClipping();
281 UnparentAndReset( impl.mStencil );
283 impl.RequestTextRelayout();
286 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
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 );
296 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
298 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
299 if( GetVerticalAlignmentEnumeration( value, alignment ) )
301 impl.mController->SetVerticalAlignment( alignment );
302 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
306 case Toolkit::TextField::Property::TEXT_COLOR:
308 const Vector4& textColor = value.Get< Vector4 >();
309 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 );
311 if( impl.mController->GetDefaultColor() != textColor )
313 impl.mController->SetDefaultColor( textColor );
314 impl.mController->SetInputColor( textColor );
315 impl.mRenderer.Reset();
319 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
321 const Vector4& textColor = value.Get< Vector4 >();
322 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 );
324 if( impl.mController->GetPlaceholderTextColor() != textColor )
326 impl.mController->SetPlaceholderTextColor( textColor );
327 impl.mRenderer.Reset();
331 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
333 const Vector4& color = value.Get< Vector4 >();
334 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 );
336 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
337 impl.RequestTextRelayout();
340 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
342 const Vector4& color = value.Get< Vector4 >();
343 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 );
345 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
346 impl.RequestTextRelayout();
349 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
351 const bool enable = value.Get< bool >();
352 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
354 impl.mController->SetEnableCursorBlink( enable );
355 impl.RequestTextRelayout();
358 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
360 const float interval = value.Get< float >();
361 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
363 impl.mDecorator->SetCursorBlinkInterval( interval );
366 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
368 const float duration = value.Get< float >();
369 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
371 impl.mDecorator->SetCursorBlinkDuration( duration );
374 case Toolkit::TextField::Property::CURSOR_WIDTH:
376 const int width = value.Get< int >();
377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
379 impl.mDecorator->SetCursorWidth( width );
380 impl.mController->GetLayoutEngine().SetCursorWidth( width );
383 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
385 const std::string imageFileName = value.Get< std::string >();
386 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
388 if( imageFileName.size() )
390 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
391 impl.RequestTextRelayout();
395 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
397 const std::string imageFileName = value.Get< std::string >();
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
400 if( imageFileName.size() )
402 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
403 impl.RequestTextRelayout();
407 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
409 const float threshold = value.Get< float >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
412 impl.mDecorator->SetScrollThreshold( threshold );
415 case Toolkit::TextField::Property::SCROLL_SPEED:
417 const float speed = value.Get< float >();
418 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
420 impl.mDecorator->SetScrollSpeed( speed );
423 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
425 const std::string filename = GetImageFileNameFromPropertyValue( value );
427 if( filename.size() )
429 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
430 impl.RequestTextRelayout();
434 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
436 const std::string filename = GetImageFileNameFromPropertyValue( value );
438 if( filename.size() )
440 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
441 impl.RequestTextRelayout();
445 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
447 const std::string filename = GetImageFileNameFromPropertyValue( value );
449 if( filename.size() )
451 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
452 impl.RequestTextRelayout();
456 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
458 const std::string filename = GetImageFileNameFromPropertyValue( value );
460 if( filename.size() )
462 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
463 impl.RequestTextRelayout();
467 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
469 const std::string filename = GetImageFileNameFromPropertyValue( value );
471 if( filename.size() )
473 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
474 impl.RequestTextRelayout();
478 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
480 const std::string filename = GetImageFileNameFromPropertyValue( value );
482 if( filename.size() )
484 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
485 impl.RequestTextRelayout();
489 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
491 const Vector4 color = value.Get< Vector4 >();
492 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 );
494 impl.mDecorator->SetHighlightColor( color );
495 impl.RequestTextRelayout();
498 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
500 const Rect<int> box = value.Get< Rect<int> >();
501 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 );
503 impl.mDecorator->SetBoundingBox( box );
504 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
509 const Property::Map* map = value.GetMap();
512 impl.mInputMethodOptions.ApplyProperty( *map );
514 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
516 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
517 if (control == textField)
519 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
523 case Toolkit::TextField::Property::INPUT_COLOR:
525 const Vector4 inputColor = value.Get< Vector4 >();
526 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 );
528 impl.mController->SetInputColor( inputColor );
531 case Toolkit::TextField::Property::ENABLE_MARKUP:
533 const bool enableMarkup = value.Get<bool>();
534 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
536 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
539 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
541 const std::string& fontFamily = value.Get< std::string >();
542 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
543 impl.mController->SetInputFontFamily( fontFamily );
546 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
548 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
551 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
553 const float pointSize = value.Get< float >();
554 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
555 impl.mController->SetInputFontPointSize( pointSize );
558 case Toolkit::TextField::Property::UNDERLINE:
560 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
563 impl.mRenderer.Reset();
567 case Toolkit::TextField::Property::INPUT_UNDERLINE:
569 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
572 impl.mRenderer.Reset();
576 case Toolkit::TextField::Property::SHADOW:
578 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
581 impl.mRenderer.Reset();
585 case Toolkit::TextField::Property::INPUT_SHADOW:
587 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
590 impl.mRenderer.Reset();
594 case Toolkit::TextField::Property::EMBOSS:
596 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
599 impl.mRenderer.Reset();
603 case Toolkit::TextField::Property::INPUT_EMBOSS:
605 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
608 impl.mRenderer.Reset();
612 case Toolkit::TextField::Property::OUTLINE:
614 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
617 impl.mRenderer.Reset();
621 case Toolkit::TextField::Property::INPUT_OUTLINE:
623 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
626 impl.mRenderer.Reset();
630 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
632 const Property::Map* map = value.GetMap();
635 impl.mController->SetHiddenInputOption(*map);
639 case Toolkit::TextField::Property::PIXEL_SIZE:
641 const float pixelSize = value.Get< float >();
642 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
644 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
646 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
650 case Toolkit::TextField::Property::ENABLE_SELECTION:
652 const bool enableSelection = value.Get< bool >();
653 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
654 impl.mController->SetSelectionEnabled( enableSelection );
657 case Toolkit::TextField::Property::PLACEHOLDER:
659 const Property::Map* map = value.GetMap();
662 impl.mController->SetPlaceholderProperty( *map );
666 case Toolkit::TextField::Property::ELLIPSIS:
668 const bool ellipsis = value.Get<bool>();
669 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
671 impl.mController->SetTextElideEnabled( ellipsis );
674 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
676 const bool shiftSelection = value.Get<bool>();
677 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
679 impl.mController->SetShiftSelectionEnabled( shiftSelection );
682 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
684 const bool grabHandleEnabled = value.Get<bool>();
685 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
687 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
690 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
692 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
695 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
697 const bool grabHandlePopupEnabled = value.Get<bool>();
698 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
700 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
703 case Toolkit::DevelTextField::Property::BACKGROUND:
705 const Vector4 backgroundColor = value.Get< Vector4 >();
706 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 );
708 impl.mController->SetBackgroundEnabled( true );
709 impl.mController->SetBackgroundColor( backgroundColor );
716 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
718 Property::Value value;
720 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
724 TextField& impl( GetImpl( textField ) );
725 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
726 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
730 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
732 value = impl.mRenderingBackend;
735 case Toolkit::TextField::Property::TEXT:
738 impl.mController->GetText( text );
739 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
743 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
746 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
750 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
753 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
757 case Toolkit::TextField::Property::FONT_FAMILY:
759 value = impl.mController->GetDefaultFontFamily();
762 case Toolkit::TextField::Property::FONT_STYLE:
764 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
767 case Toolkit::TextField::Property::POINT_SIZE:
769 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
772 case Toolkit::TextField::Property::MAX_LENGTH:
774 value = impl.mController->GetMaximumNumberOfCharacters();
777 case Toolkit::TextField::Property::EXCEED_POLICY:
779 value = impl.mExceedPolicy;
782 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
784 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
788 value = std::string( name );
792 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
794 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
798 value = std::string( name );
802 case Toolkit::TextField::Property::TEXT_COLOR:
804 value = impl.mController->GetDefaultColor();
807 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
809 value = impl.mController->GetPlaceholderTextColor();
812 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
814 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
817 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
819 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
822 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
824 value = impl.mController->GetEnableCursorBlink();
827 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
829 value = impl.mDecorator->GetCursorBlinkInterval();
832 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
834 value = impl.mDecorator->GetCursorBlinkDuration();
837 case Toolkit::TextField::Property::CURSOR_WIDTH:
839 value = impl.mDecorator->GetCursorWidth();
842 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
844 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
847 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
849 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
852 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
854 value = impl.mDecorator->GetScrollThreshold();
857 case Toolkit::TextField::Property::SCROLL_SPEED:
859 value = impl.mDecorator->GetScrollSpeed();
862 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
864 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
867 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
869 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
872 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
874 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
877 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
879 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
882 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
884 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
887 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
889 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
892 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
894 value = impl.mDecorator->GetHighlightColor();
897 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
899 Rect<int> boundingBox;
900 impl.mDecorator->GetBoundingBox( boundingBox );
904 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
907 impl.mInputMethodOptions.RetrieveProperty( map );
911 case Toolkit::TextField::Property::INPUT_COLOR:
913 value = impl.mController->GetInputColor();
916 case Toolkit::TextField::Property::ENABLE_MARKUP:
918 value = impl.mController->IsMarkupProcessorEnabled();
921 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
923 value = impl.mController->GetInputFontFamily();
926 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
928 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
931 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
933 value = impl.mController->GetInputFontPointSize();
936 case Toolkit::TextField::Property::UNDERLINE:
938 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
941 case Toolkit::TextField::Property::INPUT_UNDERLINE:
943 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
946 case Toolkit::TextField::Property::SHADOW:
948 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
951 case Toolkit::TextField::Property::INPUT_SHADOW:
953 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
956 case Toolkit::TextField::Property::EMBOSS:
958 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
961 case Toolkit::TextField::Property::INPUT_EMBOSS:
963 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
966 case Toolkit::TextField::Property::OUTLINE:
968 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
971 case Toolkit::TextField::Property::INPUT_OUTLINE:
973 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
976 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
979 impl.mController->GetHiddenInputOption(map);
983 case Toolkit::TextField::Property::PIXEL_SIZE:
985 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
988 case Toolkit::TextField::Property::ENABLE_SELECTION:
990 value = impl.mController->IsSelectionEnabled();
993 case Toolkit::TextField::Property::PLACEHOLDER:
996 impl.mController->GetPlaceholderProperty( map );
1000 case Toolkit::TextField::Property::ELLIPSIS:
1002 value = impl.mController->IsTextElideEnabled();
1005 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1007 value = impl.mController->IsShiftSelectionEnabled();
1010 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1012 value = impl.mController->IsGrabHandleEnabled();
1015 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1017 value = impl.mController->IsMatchSystemLanguageDirection();
1020 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1022 value = impl.mController->IsGrabHandlePopupEnabled();
1025 case Toolkit::DevelTextField::Property::BACKGROUND:
1027 value = impl.mController->GetBackgroundColor();
1030 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1032 value = impl.mController->GetSelectedText( );
1041 void TextField::SelectWholeText()
1043 if( mController && mController->IsShowingRealText() )
1045 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1050 void TextField::SelectNone()
1052 if( mController && mController->IsShowingRealText() )
1054 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1059 InputMethodContext TextField::GetInputMethodContext()
1061 return mInputMethodContext;
1064 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1066 Dali::BaseHandle handle( object );
1068 bool connected( true );
1069 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1071 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1073 field.TextChangedSignal().Connect( tracker, functor );
1075 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1077 field.MaxLengthReachedSignal().Connect( tracker, functor );
1079 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1081 field.InputStyleChangedSignal().Connect( tracker, functor );
1085 // signalName does not match any signal
1092 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1094 return mTextChangedSignal;
1097 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1099 return mMaxLengthReachedSignal;
1102 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1104 return mInputStyleChangedSignal;
1107 void TextField::OnInitialize()
1109 Actor self = Self();
1111 mController = Text::Controller::New( this, this );
1113 // When using the vector-based rendering, the size of the GLyphs are different
1114 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1115 mController->SetGlyphType( glyphType );
1117 mDecorator = Text::Decorator::New( *mController,
1120 mInputMethodContext = InputMethodContext::New( self );
1122 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1124 // Enables the text input.
1125 mController->EnableTextInput( mDecorator, mInputMethodContext );
1127 // Enables the horizontal scrolling after the text input has been enabled.
1128 mController->SetHorizontalScrollEnabled( true );
1130 // Disables the vertical scrolling.
1131 mController->SetVerticalScrollEnabled( false );
1133 // Disable the smooth handle panning.
1134 mController->SetSmoothHandlePanEnabled( false );
1136 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1137 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1139 // Sets layoutDirection value
1140 Dali::Stage stage = Dali::Stage::GetCurrent();
1141 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1142 mController->SetLayoutDirection( layoutDirection );
1144 // Forward input events to controller
1145 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1146 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1148 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1150 // Set BoundingBox to stage size if not already set.
1151 Rect<int> boundingBox;
1152 mDecorator->GetBoundingBox( boundingBox );
1154 if( boundingBox.IsEmpty() )
1156 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1157 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1160 // Flip vertically the 'left' selection handle
1161 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1163 // Fill-parent area by default
1164 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1165 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1166 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1168 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1170 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1176 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1178 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1182 case StyleChange::DEFAULT_FONT_CHANGE:
1184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1185 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1186 // Property system did not set the font so should update it.
1187 mController->UpdateAfterFontChange( newFont );
1192 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1194 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1198 case StyleChange::THEME_CHANGE:
1200 // Nothing to do, let control base class handle this
1205 // Up call to Control
1206 Control::OnStyleChange( styleManager, change );
1209 Vector3 TextField::GetNaturalSize()
1212 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1214 Vector3 naturalSize = mController->GetNaturalSize();
1215 naturalSize.width += ( padding.start + padding.end );
1216 naturalSize.height += ( padding.top + padding.bottom );
1221 float TextField::GetHeightForWidth( float width )
1224 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1225 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1228 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1230 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1232 Actor self = Self();
1235 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1237 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1239 // Support Right-To-Left of padding
1240 Dali::LayoutDirection::Type layoutDirection;
1241 if( mController->IsMatchSystemLanguageDirection() )
1243 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1247 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1249 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1251 std::swap( padding.start, padding.end );
1256 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1260 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1263 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1265 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1268 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1271 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1273 mDecorator->Relayout( size );
1278 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1281 RenderText( updateTextType );
1285 // The text-field emits signals when the input style changes. These changes of style are
1286 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1287 // can't be emitted during the size negotiation as the callbacks may update the UI.
1288 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1289 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1291 if( Adaptor::IsAvailable() )
1293 Adaptor& adaptor = Adaptor::Get();
1295 if( NULL == mIdleCallback )
1297 // @note: The callback manager takes the ownership of the callback object.
1298 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1299 adaptor.AddIdle( mIdleCallback, false );
1305 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1307 Actor renderableActor;
1309 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1313 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1315 renderableActor = mRenderer->Render( mController->GetView(),
1317 Property::INVALID_INDEX, // Animatable property not supported
1319 DepthIndex::CONTENT );
1322 if( renderableActor != mRenderableActor )
1324 UnparentAndReset( mBackgroundActor );
1325 UnparentAndReset( mRenderableActor );
1326 mRenderableActor = renderableActor;
1328 if ( mRenderableActor )
1330 mBackgroundActor = mController->CreateBackgroundActor();
1335 if( mRenderableActor )
1337 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1339 float renderableActorPositionX, renderableActorPositionY;
1343 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1344 renderableActorPositionY = scrollOffset.y;
1349 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1351 // Support Right-To-Left of padding
1352 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1353 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1355 std::swap( padding.start, padding.end );
1358 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1359 renderableActorPositionY = scrollOffset.y + padding.top;
1362 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1364 // Make sure the actors are parented correctly with/without clipping
1365 Actor self = mStencil ? mStencil : Self();
1367 Actor highlightActor;
1369 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1370 endIt = mClippingDecorationActors.end();
1375 it->LowerToBottom();
1377 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1379 highlightActor = *it;
1382 mClippingDecorationActors.clear();
1384 self.Add( mRenderableActor );
1386 if ( mBackgroundActor )
1388 if ( mDecorator && mDecorator->IsHighlightVisible() )
1390 self.Add( mBackgroundActor );
1391 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1392 mBackgroundActor.LowerBelow( highlightActor );
1396 mRenderableActor.Add( mBackgroundActor );
1397 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1398 mBackgroundActor.LowerToBottom();
1404 void TextField::OnKeyInputFocusGained()
1406 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1407 if ( mInputMethodContext )
1409 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1411 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1413 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1415 // Notify that the text editing start.
1416 mInputMethodContext.Activate();
1418 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1419 mInputMethodContext.SetRestoreAfterFocusLost( true );
1421 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1425 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1428 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1430 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1433 void TextField::OnKeyInputFocusLost()
1435 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1436 if ( mInputMethodContext )
1438 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1439 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1440 mInputMethodContext.SetRestoreAfterFocusLost( false );
1442 // Notify that the text editing finish.
1443 mInputMethodContext.Deactivate();
1445 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1447 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1451 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1454 mController->KeyboardFocusLostEvent();
1456 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1459 void TextField::OnTap( const TapGesture& gesture )
1461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1462 if ( mInputMethodContext )
1464 mInputMethodContext.Activate();
1466 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1468 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1469 const Vector2& localPoint = gesture.GetLocalPoint();
1470 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1475 void TextField::OnPan( const PanGesture& gesture )
1477 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1480 void TextField::OnLongPress( const LongPressGesture& gesture )
1482 if ( mInputMethodContext )
1484 mInputMethodContext.Activate();
1487 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1488 const Vector2& localPoint = gesture.GetLocalPoint();
1489 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1494 bool TextField::OnKeyEvent( const KeyEvent& event )
1496 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1498 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1500 // Make sure ClearKeyInputFocus when only key is up
1501 if( event.GetState() == KeyEvent::UP )
1503 ClearKeyInputFocus();
1508 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1510 // Do nothing when enter is comming.
1514 return mController->KeyEvent( event );
1517 void TextField::RequestTextRelayout()
1522 void TextField::TextChanged()
1524 Dali::Toolkit::TextField handle( GetOwner() );
1525 mTextChangedSignal.Emit( handle );
1528 void TextField::MaxLengthReached()
1530 Dali::Toolkit::TextField handle( GetOwner() );
1531 mMaxLengthReachedSignal.Emit( handle );
1534 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1536 Dali::Toolkit::TextField handle( GetOwner() );
1538 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1540 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1542 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1544 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1546 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1548 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1550 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1552 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1554 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1556 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1558 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1560 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1562 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1564 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1566 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1568 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1570 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1572 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1574 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1576 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1578 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1581 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1584 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1590 mClippingDecorationActors.push_back( actor );
1594 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1595 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1596 Self().Add( actor );
1597 mActiveLayer = actor;
1602 void TextField::OnSceneConnect( Dali::Actor actor )
1604 if ( mHasBeenStaged )
1606 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1610 mHasBeenStaged = true;
1614 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1616 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1617 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1620 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1625 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1630 void TextField::EnableClipping()
1634 // Creates an extra control to be used as stencil buffer.
1635 mStencil = Control::New();
1636 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1637 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1639 // Creates a background visual. Even if the color is transparent it updates the stencil.
1640 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1641 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1642 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1644 // Enable the clipping property.
1645 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1646 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1648 Self().Add( mStencil );
1652 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1654 mController->PasteClipboardItemEvent();
1657 void TextField::KeyboardStatusChanged(bool keyboardShown)
1659 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1661 // Just hide the grab handle when keyboard is hidden.
1662 if (!keyboardShown )
1664 mController->KeyboardFocusLostEvent();
1668 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1672 void TextField::OnSceneConnection( int depth )
1674 // Sets the depth to the visuals inside the text's decorator.
1675 mDecorator->SetTextDepth( depth );
1677 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1679 // Call the Control::OnSceneConnection() to set the depth of the background.
1680 Control::OnSceneConnection( depth );
1683 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1688 void TextField::OnIdleSignal()
1690 // Emits the change of input style signals.
1691 mController->ProcessInputStyleChangedSignals();
1693 // Set the pointer to null as the callback manager deletes the callback after execute it.
1694 mIdleCallback = NULL;
1697 TextField::TextField()
1698 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1699 mIdleCallback( NULL ),
1700 mAlignmentOffset( 0.f ),
1701 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1702 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1703 mHasBeenStaged( false )
1707 TextField::~TextField()
1709 UnparentAndReset( mStencil );
1711 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1713 Adaptor::Get().RemoveIdle( mIdleCallback );
1717 } // namespace Internal
1719 } // namespace Toolkit