2 * Copyright (c) 2022 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>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/key-devel.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/key.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/object/type-registry-helper.h>
34 #include <dali-toolkit/devel-api/controls/control-devel.h>
35 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
38 #include <dali-toolkit/internal/controls/text-controls/text-field-property-handler.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40 #include <dali-toolkit/internal/text/rendering/text-backend.h>
41 #include <dali-toolkit/internal/text/text-effects-style.h>
42 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
43 #include <dali-toolkit/internal/text/text-font-style.h>
44 #include <dali-toolkit/internal/text/text-view.h>
45 #include <dali-toolkit/public-api/text/text-enumerations.h>
46 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
47 #include <dali-toolkit/public-api/visuals/visual-properties.h>
48 #include <dali/integration-api/adaptor-framework/adaptor.h>
50 using namespace Dali::Toolkit::Text;
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gTextFieldLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
62 namespace // unnamed namespace
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
65 } // unnamed namespace
72 return Toolkit::TextField::New();
76 // Setup properties, signals and actions using the type-registry.
77 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
79 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "text", STRING, TEXT )
80 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
81 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
82 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
83 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
84 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
85 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "underline", MAP, UNDERLINE )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "shadow", MAP, SHADOW )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "emboss", MAP, EMBOSS )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "outline", MAP, OUTLINE )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
128 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
129 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
130 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
133 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
134 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFilter", MAP, INPUT_FILTER )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "strikethrough", MAP, STRIKETHROUGH )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "characterSpacing", FLOAT, CHARACTER_SPACING )
148 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered", SIGNAL_INPUT_FILTERED )
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
155 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
156 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionStarted", SIGNAL_SELECTION_STARTED )
158 DALI_TYPE_REGISTRATION_END()
161 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
163 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
165 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
167 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
169 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
171 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
173 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
175 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
177 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
179 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
181 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
183 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
185 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
187 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
189 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
191 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
193 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
195 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
197 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
199 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
201 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
203 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
205 return fieldInputStyleMask;
210 Toolkit::TextField TextField::New()
212 // Create the implementation, temporarily owned by this handle on stack
213 IntrusivePtr<TextField> impl = new TextField();
215 // Pass ownership to CustomActor handle
216 Toolkit::TextField handle(*impl);
218 // Second-phase init of the implementation
219 // This can only be done after the CustomActor connection has been made...
225 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
227 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
229 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
233 PropertyHandler::SetProperty(textField, index, value);
237 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
239 Property::Value value;
241 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
245 value = PropertyHandler::GetProperty(textField, index);
251 void TextField::SelectWholeText()
253 if(mController && mController->IsShowingRealText())
255 mController->SelectWholeText();
260 void TextField::SelectNone()
262 if(mController && mController->IsShowingRealText())
264 mController->SelectNone();
268 void TextField::SelectText(const uint32_t start, const uint32_t end)
270 if(mController && mController->IsShowingRealText())
272 mController->SelectText(start, end);
277 string TextField::GetSelectedText() const
279 string selectedText = "";
280 if(mController && mController->IsShowingRealText())
282 selectedText = mController->GetSelectedText();
287 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
289 if(mController && mController->IsShowingRealText())
291 mController->SetTextSelectionRange(start, end);
296 Uint32Pair TextField::GetTextSelectionRange() const
299 if(mController && mController->IsShowingRealText())
301 range = mController->GetTextSelectionRange();
306 string TextField::CopyText()
308 string copiedText = "";
309 if(mController && mController->IsShowingRealText())
311 copiedText = mController->CopyText();
316 string TextField::CutText()
319 if(mController && mController->IsShowingRealText())
321 cutText = mController->CutText();
326 void TextField::PasteText()
330 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
331 mController->PasteText();
335 InputMethodContext TextField::GetInputMethodContext()
337 return mInputMethodContext;
340 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
342 Dali::BaseHandle handle(object);
344 bool connected(true);
345 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
347 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
349 field.TextChangedSignal().Connect(tracker, functor);
351 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
353 field.MaxLengthReachedSignal().Connect(tracker, functor);
355 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
357 field.InputStyleChangedSignal().Connect(tracker, functor);
359 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
363 Internal::TextField& fieldImpl(GetImpl(field));
364 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
367 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
371 Internal::TextField& fieldImpl(GetImpl(field));
372 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
375 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
379 Internal::TextField& fieldImpl(GetImpl(field));
380 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
383 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
387 Internal::TextField& fieldImpl(GetImpl(field));
388 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
391 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
395 Internal::TextField& fieldImpl(GetImpl(field));
396 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
399 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
403 Internal::TextField& fieldImpl(GetImpl(field));
404 fieldImpl.SelectionStartedSignal().Connect(tracker, functor);
409 // signalName does not match any signal
416 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
418 return mTextChangedSignal;
421 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
423 return mMaxLengthReachedSignal;
426 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
428 return mInputStyleChangedSignal;
431 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
433 return mAnchorClickedSignal;
436 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
438 return mCursorPositionChangedSignal;
441 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
443 return mInputFilteredSignal;
446 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
448 return mSelectionChangedSignal;
451 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
453 return mSelectionClearedSignal;
456 DevelTextField::SelectionStartedSignalType& TextField::SelectionStartedSignal()
458 return mSelectionStartedSignal;
461 void TextField::OnAccessibilityStatusChanged()
463 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
466 void TextField::OnInitialize()
470 mController = Text::Controller::New(this, this, this, this);
472 // When using the vector-based rendering, the size of the GLyphs are different
473 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
474 mController->SetGlyphType(glyphType);
476 mDecorator = Text::Decorator::New(*mController,
479 mInputMethodContext = InputMethodContext::New(self);
481 mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
483 // Enables the text input.
484 mController->EnableTextInput(mDecorator, mInputMethodContext);
486 // Enables the horizontal scrolling after the text input has been enabled.
487 mController->SetHorizontalScrollEnabled(true);
489 // Disables the vertical scrolling.
490 mController->SetVerticalScrollEnabled(false);
492 // Disable the smooth handle panning.
493 mController->SetSmoothHandlePanEnabled(false);
495 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
496 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
498 // Sets layoutDirection value
499 Dali::Stage stage = Dali::Stage::GetCurrent();
500 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
501 mController->SetLayoutDirection(layoutDirection);
503 self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
505 // Forward input events to controller
506 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
507 GetTapGestureDetector().SetMaximumTapsRequired(2);
508 GetTapGestureDetector().ReceiveAllTapEvents(true);
510 self.TouchedSignal().Connect(this, &TextField::OnTouched);
512 // Set BoundingBox to stage size if not already set.
513 Rect<int> boundingBox;
514 mDecorator->GetBoundingBox(boundingBox);
516 if(boundingBox.IsEmpty())
518 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
519 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
522 // Flip vertically the 'left' selection handle
523 mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
525 // Fill-parent area by default
526 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
527 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
528 self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
530 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
532 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
538 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY);
539 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
541 Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
542 Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
545 DevelControl::ControlAccessible* TextField::CreateAccessibleObject()
547 return new TextFieldAccessible(Self());
550 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
552 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
556 case StyleChange::DEFAULT_FONT_CHANGE:
558 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
559 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
560 // Property system did not set the font so should update it.
561 mController->UpdateAfterFontChange(newFont);
566 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
568 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
572 case StyleChange::THEME_CHANGE:
574 // Nothing to do, let control base class handle this
579 // Up call to Control
580 Control::OnStyleChange(styleManager, change);
583 Vector3 TextField::GetNaturalSize()
586 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
588 Vector3 naturalSize = mController->GetNaturalSize();
589 naturalSize.width += (padding.start + padding.end);
590 naturalSize.height += (padding.top + padding.bottom);
595 float TextField::GetHeightForWidth(float width)
598 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
599 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
602 void TextField::ResizeActor(Actor& actor, const Vector2& size)
604 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
606 actor.SetProperty(Actor::Property::SIZE, size);
610 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
612 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
617 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
619 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
621 // Support Right-To-Left of padding
622 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
624 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
626 std::swap(padding.start, padding.end);
631 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
632 ResizeActor(mStencil, contentSize);
636 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
637 ResizeActor(mActiveLayer, contentSize);
641 mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
642 ResizeActor(mCursorLayer, contentSize);
645 // If there is text changed, callback is called.
648 EmitTextChangedSignal();
651 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
653 if((Text::Controller::NONE_UPDATED != updateTextType) ||
656 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
659 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
661 mDecorator->Relayout(contentSize);
666 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
669 RenderText(updateTextType);
672 if(mCursorPositionChanged)
674 EmitCursorPositionChangedSignal();
677 if(mSelectionStarted)
679 EmitSelectionStartedSignal();
682 if(mSelectionChanged)
684 EmitSelectionChangedSignal();
687 if(mSelectionCleared)
689 EmitSelectionClearedSignal();
692 // The text-field emits signals when the input style changes. These changes of style are
693 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
694 // can't be emitted during the size negotiation as the callbacks may update the UI.
695 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
696 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
698 if(Adaptor::IsAvailable())
700 Adaptor& adaptor = Adaptor::Get();
702 if(NULL == mIdleCallback)
704 // @note: The callback manager takes the ownership of the callback object.
705 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
706 adaptor.AddIdle(mIdleCallback, false);
712 Text::ControllerPtr TextField::GetTextController()
717 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
719 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
722 void TextField::OnKeyInputFocusGained()
724 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
725 if(mInputMethodContext && IsEditable())
727 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
728 mInputMethodContext.ApplyOptions(mInputMethodOptions);
729 mInputMethodContext.NotifyTextInputMultiLine(false);
731 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
733 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
735 // Notify that the text editing start.
736 mInputMethodContext.Activate();
738 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
739 mInputMethodContext.SetRestoreAfterFocusLost(true);
741 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
745 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
748 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
750 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
753 void TextField::OnKeyInputFocusLost()
755 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
756 if(mInputMethodContext)
758 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
759 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
760 mInputMethodContext.SetRestoreAfterFocusLost(false);
762 // Notify that the text editing finish.
763 mInputMethodContext.Deactivate();
765 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
767 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
771 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
774 mController->KeyboardFocusLostEvent();
776 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
779 bool TextField::OnAccessibilityActivated()
785 void TextField::OnTap(const TapGesture& gesture)
787 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
788 if(mInputMethodContext && IsEditable())
790 mInputMethodContext.Activate();
792 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
794 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
795 const Vector2& localPoint = gesture.GetLocalPoint();
796 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
797 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
802 void TextField::OnPan(const PanGesture& gesture)
804 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
807 void TextField::OnLongPress(const LongPressGesture& gesture)
809 if(mInputMethodContext && IsEditable())
811 mInputMethodContext.Activate();
814 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
815 const Vector2& localPoint = gesture.GetLocalPoint();
816 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
821 bool TextField::OnKeyEvent(const KeyEvent& event)
823 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
825 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
827 // Make sure ClearKeyInputFocus when only key is up
828 if(event.GetState() == KeyEvent::UP)
830 ClearKeyInputFocus();
835 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
837 // Do nothing when enter is comming.
841 return mController->KeyEvent(event);
844 void TextField::RequestTextRelayout()
849 bool TextField::IsEditable() const
851 return mController->IsEditable();
854 void TextField::SetEditable(bool editable)
856 mController->SetEditable(editable);
857 if(mInputMethodContext && !editable)
859 mInputMethodContext.Deactivate();
863 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
865 GetAccessibleObject()->EmitTextInserted(position, length, content);
868 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
870 GetAccessibleObject()->EmitTextDeleted(position, length, content);
873 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
875 GetAccessibleObject()->EmitTextCursorMoved(newPosition);
877 if((oldPosition != newPosition) && !mCursorPositionChanged)
879 mCursorPositionChanged = true;
880 mOldPosition = oldPosition;
884 void TextField::TextChanged(bool immediate)
886 if(immediate) // Emits TextChangedSignal immediately
888 EmitTextChangedSignal();
896 void TextField::EmitTextChangedSignal()
898 Dali::Toolkit::TextField handle(GetOwner());
899 mTextChangedSignal.Emit(handle);
900 mTextChanged = false;
903 void TextField::MaxLengthReached()
905 Dali::Toolkit::TextField handle(GetOwner());
906 mMaxLengthReachedSignal.Emit(handle);
909 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
911 Dali::Toolkit::TextField handle(GetOwner());
912 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
915 void TextField::AnchorClicked(const std::string& href)
917 Dali::Toolkit::TextField handle(GetOwner());
918 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
921 void TextField::EmitCursorPositionChangedSignal()
923 Dali::Toolkit::TextField handle(GetOwner());
924 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
925 mCursorPositionChanged = false;
928 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
930 Dali::Toolkit::TextField handle(GetOwner());
931 mInputFilteredSignal.Emit(handle, type);
934 void TextField::EmitSelectionChangedSignal()
936 Dali::Toolkit::TextField handle(GetOwner());
937 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
938 mSelectionChanged = false;
941 void TextField::EmitSelectionClearedSignal()
943 Dali::Toolkit::TextField handle(GetOwner());
944 mSelectionClearedSignal.Emit(handle);
945 mSelectionCleared = false;
948 void TextField::EmitSelectionStartedSignal()
950 Dali::Toolkit::TextField handle(GetOwner());
951 mSelectionStartedSignal.Emit(handle);
952 mSelectionStarted = false;
955 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
957 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
959 if(newStart == newEnd)
961 mSelectionCleared = true;
965 if(oldStart == oldEnd)
967 mSelectionStarted = true;
971 mSelectionChanged = true;
972 mOldSelectionStart = oldStart;
973 mOldSelectionEnd = oldEnd;
975 if(mOldSelectionStart > mOldSelectionEnd)
978 uint32_t temp = mOldSelectionStart;
979 mOldSelectionStart = mOldSelectionEnd;
980 mOldSelectionEnd = temp;
985 void TextField::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
991 mClippingDecorationActors.push_back(actor);
994 // If the actor is a layer type, add it.
995 if(type == DecorationType::ACTIVE_LAYER)
997 AddLayer(mActiveLayer, actor);
999 else if(type == DecorationType::CURSOR_LAYER)
1001 AddLayer(mCursorLayer, actor);
1006 void TextField::AddLayer(Actor& layer, Actor& actor)
1008 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1009 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1014 void TextField::GetControlBackgroundColor(Vector4& color) const
1016 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1017 Property::Map* resultMap = propValue.GetMap();
1019 Property::Value* colorValue = nullptr;
1020 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1022 colorValue->Get(color);
1026 void TextField::OnSceneConnect(Dali::Actor actor)
1030 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1034 mHasBeenStaged = true;
1038 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1040 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1041 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1044 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1049 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1055 void TextField::EnableClipping()
1059 // Creates an extra control to be used as stencil buffer.
1060 mStencil = Control::New();
1061 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1062 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1064 // Creates a background visual. Even if the color is transparent it updates the stencil.
1065 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1066 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1068 // Enable the clipping property.
1069 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1070 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1072 Self().Add(mStencil);
1076 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1078 mController->PasteClipboardItemEvent();
1081 void TextField::KeyboardStatusChanged(bool keyboardShown)
1083 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1085 // Just hide the grab handle when keyboard is hidden.
1088 mController->KeyboardFocusLostEvent();
1092 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1096 void TextField::OnSceneConnection(int depth)
1098 // Sets the depth to the visuals inside the text's decorator.
1099 mDecorator->SetTextDepth(depth);
1101 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1103 // Call the Control::OnSceneConnection() to set the depth of the background.
1104 Control::OnSceneConnection(depth);
1107 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1112 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1114 mController->ChangedLayoutDirection();
1117 void TextField::OnIdleSignal()
1119 // Emits the change of input style signals.
1120 mController->ProcessInputStyleChangedSignals();
1122 // Set the pointer to null as the callback manager deletes the callback after execute it.
1123 mIdleCallback = NULL;
1126 TextField::TextField()
1127 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1128 mIdleCallback(NULL),
1129 mAlignmentOffset(0.f),
1130 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1131 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1132 mHasBeenStaged(false),
1133 mTextChanged(false),
1134 mCursorPositionChanged(false),
1135 mSelectionChanged(false),
1136 mSelectionCleared(false),
1138 mOldSelectionStart(0u),
1139 mOldSelectionEnd(0u),
1140 mSelectionStarted(false)
1144 TextField::~TextField()
1146 UnparentAndReset(mStencil);
1148 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1150 Adaptor::Get().RemoveIdle(mIdleCallback);
1154 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1156 return mController->GetTextSize(startIndex, endIndex);
1159 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1161 return mController->GetTextPosition(startIndex, endIndex);
1164 std::string TextField::TextFieldAccessible::GetName() const
1171 return GetWholeText();
1174 const std::vector<Toolkit::TextAnchor>& TextField::TextFieldAccessible::GetTextAnchors() const
1176 auto self = Toolkit::TextField::DownCast(Self());
1178 return Toolkit::GetImpl(self).mAnchorActors;
1181 Toolkit::Text::ControllerPtr TextField::TextFieldAccessible::GetTextController() const
1183 auto self = Toolkit::TextField::DownCast(Self());
1185 return Toolkit::GetImpl(self).GetTextController();
1188 std::uint32_t TextField::TextFieldAccessible::GetSubstituteCharacter() const
1190 auto self = Toolkit::TextField::DownCast(Self());
1191 auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
1192 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
1196 return static_cast<std::uint32_t>(substChar->Get<int>());
1199 return TextControlAccessible::GetSubstituteCharacter();
1202 bool TextField::TextFieldAccessible::IsHiddenInput() const
1204 auto self = Toolkit::TextField::DownCast(Self());
1205 auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
1206 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
1208 return (mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE));
1211 void TextField::TextFieldAccessible::RequestTextRelayout()
1213 auto self = Toolkit::TextField::DownCast(Self());
1214 auto& selfImpl = Toolkit::GetImpl(self);
1216 selfImpl.RequestTextRelayout();
1219 } // namespace Internal
1221 } // namespace Toolkit