2 * Copyright (c) 2021 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/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/text/rendering-backend.h>
38 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
39 #include <dali-toolkit/internal/controls/text-controls/text-field-property-handler.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/public-api/text/text-enumerations.h>
47 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
48 #include <dali-toolkit/public-api/visuals/visual-properties.h>
49 #include <dali/integration-api/adaptor-framework/adaptor.h>
51 using namespace Dali::Toolkit::Text;
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextFieldLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
63 namespace // unnamed namespace
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
66 } // unnamed namespace
73 return Toolkit::TextField::New();
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
80 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "text", STRING, TEXT )
81 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
82 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
83 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
84 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
85 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "underline", MAP, UNDERLINE )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "emboss", MAP, EMBOSS )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
129 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
130 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
134 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "fontSizeScale", FLOAT, 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 )
145 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
146 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
147 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
148 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered", SIGNAL_INPUT_FILTERED )
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
154 DALI_TYPE_REGISTRATION_END()
157 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
159 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
161 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
163 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
165 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
167 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
169 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
171 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
173 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
175 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
177 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
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_SLANT))
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_UNDERLINE))
187 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
189 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
191 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
193 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
195 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
197 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
199 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
201 return fieldInputStyleMask;
204 bool IsHiddenInput(Toolkit::TextField textField)
206 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
207 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
208 if (mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
215 char GetSubstituteCharacter(Toolkit::TextField textField)
217 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
218 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
221 return static_cast<char>(substChar->Get<int>());
228 Toolkit::TextField TextField::New()
230 // Create the implementation, temporarily owned by this handle on stack
231 IntrusivePtr<TextField> impl = new TextField();
233 // Pass ownership to CustomActor handle
234 Toolkit::TextField handle(*impl);
236 // Second-phase init of the implementation
237 // This can only be done after the CustomActor connection has been made...
243 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
245 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
247 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
251 PropertyHandler::SetProperty(textField, index, value);
255 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
257 Property::Value value;
259 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
263 value = PropertyHandler::GetProperty(textField, index);
269 void TextField::SelectWholeText()
271 if(mController && mController->IsShowingRealText())
273 mController->SelectWholeText();
278 void TextField::SelectNone()
280 if(mController && mController->IsShowingRealText())
282 mController->SelectNone();
286 void TextField::SelectText(const uint32_t start, const uint32_t end)
288 if(mController && mController->IsShowingRealText())
290 mController->SelectText(start, end);
295 string TextField::GetSelectedText() const
297 string selectedText = "";
298 if(mController && mController->IsShowingRealText())
300 selectedText = mController->GetSelectedText();
305 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
307 if(mController && mController->IsShowingRealText())
309 mController->SetTextSelectionRange(start, end);
314 Uint32Pair TextField::GetTextSelectionRange() const
317 if(mController && mController->IsShowingRealText())
319 range = mController->GetTextSelectionRange();
324 string TextField::CopyText()
326 string copiedText = "";
327 if(mController && mController->IsShowingRealText())
329 copiedText = mController->CopyText();
334 string TextField::CutText()
337 if(mController && mController->IsShowingRealText())
339 cutText = mController->CutText();
344 void TextField::PasteText()
348 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
349 mController->PasteText();
353 InputMethodContext TextField::GetInputMethodContext()
355 return mInputMethodContext;
358 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
360 Dali::BaseHandle handle(object);
362 bool connected(true);
363 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
365 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
367 field.TextChangedSignal().Connect(tracker, functor);
369 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
371 field.MaxLengthReachedSignal().Connect(tracker, functor);
373 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
375 field.InputStyleChangedSignal().Connect(tracker, functor);
377 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
381 Internal::TextField& fieldImpl(GetImpl(field));
382 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
385 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
389 Internal::TextField& fieldImpl(GetImpl(field));
390 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
393 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
397 Internal::TextField& fieldImpl(GetImpl(field));
398 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
401 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
405 Internal::TextField& fieldImpl(GetImpl(field));
406 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
409 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
413 Internal::TextField& fieldImpl(GetImpl(field));
414 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
419 // signalName does not match any signal
426 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
428 return mTextChangedSignal;
431 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
433 return mMaxLengthReachedSignal;
436 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
438 return mInputStyleChangedSignal;
441 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
443 return mAnchorClickedSignal;
446 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
448 return mCursorPositionChangedSignal;
451 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
453 return mInputFilteredSignal;
456 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
458 return mSelectionChangedSignal;
461 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
463 return mSelectionClearedSignal;
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 //Enable highightability
531 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
533 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
535 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
540 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
541 return std::unique_ptr<Dali::Accessibility::Accessible>(
542 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
546 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
548 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
552 case StyleChange::DEFAULT_FONT_CHANGE:
554 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
555 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
556 // Property system did not set the font so should update it.
557 mController->UpdateAfterFontChange(newFont);
562 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
564 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
568 case StyleChange::THEME_CHANGE:
570 // Nothing to do, let control base class handle this
575 // Up call to Control
576 Control::OnStyleChange(styleManager, change);
579 Vector3 TextField::GetNaturalSize()
582 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
584 Vector3 naturalSize = mController->GetNaturalSize();
585 naturalSize.width += (padding.start + padding.end);
586 naturalSize.height += (padding.top + padding.bottom);
591 float TextField::GetHeightForWidth(float width)
594 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
595 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
598 void TextField::ResizeActor(Actor& actor, const Vector2& size)
600 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
602 actor.SetProperty(Actor::Property::SIZE, size);
606 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
608 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
613 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
615 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
617 // Support Right-To-Left of padding
618 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
620 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
622 std::swap(padding.start, padding.end);
627 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
628 ResizeActor(mStencil, contentSize);
632 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
633 ResizeActor(mActiveLayer, contentSize);
636 // If there is text changed, callback is called.
639 EmitTextChangedSignal();
642 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
644 if((Text::Controller::NONE_UPDATED != updateTextType) ||
647 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
650 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
652 mDecorator->Relayout(contentSize);
657 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
660 RenderText(updateTextType);
663 if(mCursorPositionChanged)
665 EmitCursorPositionChangedSignal();
668 if(mSelectionChanged)
670 EmitSelectionChangedSignal();
673 if(mSelectionCleared)
675 EmitSelectionClearedSignal();
678 // The text-field emits signals when the input style changes. These changes of style are
679 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
680 // can't be emitted during the size negotiation as the callbacks may update the UI.
681 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
682 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
684 if(Adaptor::IsAvailable())
686 Adaptor& adaptor = Adaptor::Get();
688 if(NULL == mIdleCallback)
690 // @note: The callback manager takes the ownership of the callback object.
691 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
692 adaptor.AddIdle(mIdleCallback, false);
698 Text::ControllerPtr TextField::GetTextController()
703 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
705 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, updateTextType);
708 void TextField::OnKeyInputFocusGained()
710 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
711 if(mInputMethodContext && IsEditable())
713 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
714 mInputMethodContext.ApplyOptions(mInputMethodOptions);
715 mInputMethodContext.NotifyTextInputMultiLine(false);
717 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
719 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
721 // Notify that the text editing start.
722 mInputMethodContext.Activate();
724 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
725 mInputMethodContext.SetRestoreAfterFocusLost(true);
727 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
731 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
734 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
736 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
739 void TextField::OnKeyInputFocusLost()
741 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
742 if(mInputMethodContext)
744 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
745 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
746 mInputMethodContext.SetRestoreAfterFocusLost(false);
748 // Notify that the text editing finish.
749 mInputMethodContext.Deactivate();
751 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
753 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
757 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
760 mController->KeyboardFocusLostEvent();
762 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
765 bool TextField::OnAccessibilityActivated()
771 void TextField::OnTap(const TapGesture& gesture)
773 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
774 if(mInputMethodContext && IsEditable())
776 mInputMethodContext.Activate();
778 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
780 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
781 const Vector2& localPoint = gesture.GetLocalPoint();
782 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
783 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
788 void TextField::OnPan(const PanGesture& gesture)
790 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
793 void TextField::OnLongPress(const LongPressGesture& gesture)
795 if(mInputMethodContext && IsEditable())
797 mInputMethodContext.Activate();
800 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
801 const Vector2& localPoint = gesture.GetLocalPoint();
802 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
807 bool TextField::OnKeyEvent(const KeyEvent& event)
809 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
811 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
813 // Make sure ClearKeyInputFocus when only key is up
814 if(event.GetState() == KeyEvent::UP)
816 ClearKeyInputFocus();
821 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
823 // Do nothing when enter is comming.
827 return mController->KeyEvent(event);
830 void TextField::RequestTextRelayout()
835 bool TextField::IsEditable() const
837 return mController->IsEditable();
840 void TextField::SetEditable(bool editable)
842 mController->SetEditable(editable);
843 if(mInputMethodContext && !editable)
845 mInputMethodContext.Deactivate();
849 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
851 if(Accessibility::IsUp())
853 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
857 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
859 if(Accessibility::IsUp())
861 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
865 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
867 if(Accessibility::IsUp())
869 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
872 if((oldPosition != newPosition) && !mCursorPositionChanged)
874 mCursorPositionChanged = true;
875 mOldPosition = oldPosition;
879 void TextField::TextChanged(bool immediate)
881 if(immediate) // Emits TextChangedSignal immediately
883 EmitTextChangedSignal();
891 void TextField::EmitTextChangedSignal()
893 Dali::Toolkit::TextField handle(GetOwner());
894 mTextChangedSignal.Emit(handle);
895 mTextChanged = false;
898 void TextField::MaxLengthReached()
900 Dali::Toolkit::TextField handle(GetOwner());
901 mMaxLengthReachedSignal.Emit(handle);
904 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
906 Dali::Toolkit::TextField handle(GetOwner());
907 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
910 void TextField::AnchorClicked(const std::string& href)
912 Dali::Toolkit::TextField handle(GetOwner());
913 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
916 void TextField::EmitCursorPositionChangedSignal()
918 Dali::Toolkit::TextField handle(GetOwner());
919 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
920 mCursorPositionChanged = false;
923 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
925 Dali::Toolkit::TextField handle(GetOwner());
926 mInputFilteredSignal.Emit(handle, type);
929 void TextField::EmitSelectionChangedSignal()
931 Dali::Toolkit::TextField handle(GetOwner());
932 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
933 mSelectionChanged = false;
936 void TextField::EmitSelectionClearedSignal()
938 Dali::Toolkit::TextField handle(GetOwner());
939 mSelectionClearedSignal.Emit(handle);
940 mSelectionCleared = false;
943 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
945 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
947 if(newStart == newEnd)
949 mSelectionCleared = true;
952 mSelectionChanged = true;
953 mOldSelectionStart = oldStart;
954 mOldSelectionEnd = oldEnd;
956 if(mOldSelectionStart > mOldSelectionEnd)
959 uint32_t temp = mOldSelectionStart;
960 mOldSelectionStart = mOldSelectionEnd;
961 mOldSelectionEnd = temp;
966 void TextField::AddDecoration(Actor& actor, bool needsClipping)
972 mClippingDecorationActors.push_back(actor);
976 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
977 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
979 mActiveLayer = actor;
984 void TextField::GetControlBackgroundColor(Vector4& color) const
986 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
987 Property::Map* resultMap = propValue.GetMap();
989 Property::Value* colorValue = nullptr;
990 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
992 colorValue->Get(color);
996 void TextField::OnSceneConnect(Dali::Actor actor)
1000 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1004 mHasBeenStaged = true;
1008 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1010 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1011 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1014 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1019 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1025 void TextField::EnableClipping()
1029 // Creates an extra control to be used as stencil buffer.
1030 mStencil = Control::New();
1031 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1032 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1034 // Creates a background visual. Even if the color is transparent it updates the stencil.
1035 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1036 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1038 // Enable the clipping property.
1039 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1040 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1042 Self().Add(mStencil);
1046 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1048 mController->PasteClipboardItemEvent();
1051 void TextField::KeyboardStatusChanged(bool keyboardShown)
1053 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1055 // Just hide the grab handle when keyboard is hidden.
1058 mController->KeyboardFocusLostEvent();
1062 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1066 void TextField::OnSceneConnection(int depth)
1068 // Sets the depth to the visuals inside the text's decorator.
1069 mDecorator->SetTextDepth(depth);
1071 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1073 // Call the Control::OnSceneConnection() to set the depth of the background.
1074 Control::OnSceneConnection(depth);
1077 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1082 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1084 mController->ChangedLayoutDirection();
1087 void TextField::OnIdleSignal()
1089 // Emits the change of input style signals.
1090 mController->ProcessInputStyleChangedSignals();
1092 // Set the pointer to null as the callback manager deletes the callback after execute it.
1093 mIdleCallback = NULL;
1096 TextField::TextField()
1097 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1098 mIdleCallback(NULL),
1099 mAlignmentOffset(0.f),
1100 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1101 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1102 mHasBeenStaged(false),
1103 mTextChanged(false),
1104 mCursorPositionChanged(false),
1105 mSelectionChanged(false),
1106 mSelectionCleared(false),
1108 mOldSelectionStart(0u),
1109 mOldSelectionEnd(0u)
1113 TextField::~TextField()
1115 UnparentAndReset(mStencil);
1117 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1119 Adaptor::Get().RemoveIdle(mIdleCallback);
1123 std::string TextField::AccessibleImpl::GetName()
1125 auto self = Toolkit::TextField::DownCast(Self());
1126 if (IsHiddenInput(self))
1131 return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1134 std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset)
1136 if(endOffset <= startOffset)
1141 auto self = Toolkit::TextField::DownCast(Self());
1142 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1144 if(startOffset > text.size() || endOffset > text.size())
1148 if(IsHiddenInput(self))
1150 return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
1152 return text.substr(startOffset, endOffset - startOffset);
1155 size_t TextField::AccessibleImpl::GetCharacterCount()
1157 auto self = Toolkit::TextField::DownCast(Self());
1158 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1163 size_t TextField::AccessibleImpl::GetCursorOffset()
1165 auto self = Toolkit::TextField::DownCast(Self());
1166 return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
1169 bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
1171 auto self = Toolkit::TextField::DownCast(Self());
1172 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1173 if(offset > text.size())
1178 auto& selfImpl = Dali::Toolkit::GetImpl(self);
1179 selfImpl.GetTextController()->ResetCursorPosition(offset);
1180 selfImpl.RequestTextRelayout();
1185 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1186 size_t offset, Dali::Accessibility::TextBoundary boundary)
1188 auto self = Toolkit::TextField::DownCast(Self());
1189 auto range = Dali::Accessibility::Range{};
1191 if(IsHiddenInput(self))
1193 // Returning empty object, as there is no possibility to parse the textfield
1194 // when its content is hidden.
1198 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1199 auto textSize = text.size();
1203 case Dali::Accessibility::TextBoundary::CHARACTER:
1205 if(offset < textSize)
1207 range.content = text[offset];
1208 range.startOffset = offset;
1209 range.endOffset = offset + 1;
1213 case Dali::Accessibility::TextBoundary::WORD:
1214 case Dali::Accessibility::TextBoundary::LINE:
1216 auto textString = text.c_str();
1217 auto breaks = std::vector<char>(textSize, 0);
1219 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1221 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1225 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1230 while(index < textSize && counter <= offset)
1235 while(breaks[index])
1243 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1247 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1253 if((counter > 0) && ((counter - 1) == offset))
1255 range.content = text.substr(start, index - start + 1);
1256 range.startOffset = start;
1257 range.endOffset = index + 1;
1260 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1267 case Dali::Accessibility::TextBoundary::SENTENCE:
1269 /* not supported by default */
1272 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1274 /* Paragraph is not supported by libunibreak library */
1284 Dali::Accessibility::Range TextField::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex)
1286 // Since DALi supports only one selection indexes higher than 0 are ignored
1287 if(selectionIndex > 0)
1292 auto self = Toolkit::TextField::DownCast(Self());
1293 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1294 auto indices = controller->GetSelectionIndexes();
1296 auto startOffset = static_cast<size_t>(indices.first);
1297 auto endOffset = static_cast<size_t>(indices.second);
1299 if (IsHiddenInput(self))
1301 return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
1304 std::string value{};
1305 controller->RetrieveSelection(value);
1306 return {startOffset, endOffset, value};
1309 bool TextField::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1311 // Since DALi supports only one selection indexes higher than 0 are ignored
1312 if(selectionIndex > 0)
1317 auto self = Toolkit::TextField::DownCast(Self());
1318 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1322 bool TextField::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1324 // Since DALi supports only one selection indexes higher than 0 are ignored
1325 if(selectionIndex > 0)
1330 auto self = Toolkit::TextField::DownCast(Self());
1331 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1335 bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1337 if(endPosition <= startPosition)
1342 auto self = Toolkit::TextField::DownCast(Self());
1343 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1344 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1349 bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1351 if(endPosition <= startPosition)
1356 auto self = Toolkit::TextField::DownCast(Self());
1357 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1358 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1360 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1365 bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1367 if(endPosition <= startPosition)
1372 auto self = Toolkit::TextField::DownCast(Self());
1373 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1375 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1380 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
1382 using namespace Dali::Accessibility;
1384 auto states = DevelControl::AccessibleImpl::CalculateStates();
1386 states[State::EDITABLE] = true;
1387 states[State::FOCUSABLE] = true;
1389 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1390 if(mSelf == focusControl)
1392 states[State::FOCUSED] = true;
1398 bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1400 auto self = Toolkit::TextField::DownCast(Self());
1401 auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1403 insertedText.insert(startPosition, text);
1405 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
1410 bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
1412 auto self = Toolkit::TextField::DownCast(Self());
1413 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
1417 } // namespace Internal
1419 } // namespace Toolkit