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/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, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFilter", MAP, INPUT_FILTER )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "strikethrough", MAP, STRIKETHROUGH )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
147 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "characterSpacing", FLOAT, CHARACTER_SPACING )
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered", SIGNAL_INPUT_FILTERED )
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
155 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
156 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
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;
208 bool IsHiddenInput(Toolkit::TextField textField)
210 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
211 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
212 if(mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
219 char GetSubstituteCharacter(Toolkit::TextField textField)
221 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
222 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
225 return static_cast<char>(substChar->Get<int>());
232 Toolkit::TextField TextField::New()
234 // Create the implementation, temporarily owned by this handle on stack
235 IntrusivePtr<TextField> impl = new TextField();
237 // Pass ownership to CustomActor handle
238 Toolkit::TextField handle(*impl);
240 // Second-phase init of the implementation
241 // This can only be done after the CustomActor connection has been made...
247 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
249 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
251 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
255 PropertyHandler::SetProperty(textField, index, value);
259 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
261 Property::Value value;
263 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
267 value = PropertyHandler::GetProperty(textField, index);
273 void TextField::SelectWholeText()
275 if(mController && mController->IsShowingRealText())
277 mController->SelectWholeText();
282 void TextField::SelectNone()
284 if(mController && mController->IsShowingRealText())
286 mController->SelectNone();
290 void TextField::SelectText(const uint32_t start, const uint32_t end)
292 if(mController && mController->IsShowingRealText())
294 mController->SelectText(start, end);
299 string TextField::GetSelectedText() const
301 string selectedText = "";
302 if(mController && mController->IsShowingRealText())
304 selectedText = mController->GetSelectedText();
309 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
311 if(mController && mController->IsShowingRealText())
313 mController->SetTextSelectionRange(start, end);
318 Uint32Pair TextField::GetTextSelectionRange() const
321 if(mController && mController->IsShowingRealText())
323 range = mController->GetTextSelectionRange();
328 string TextField::CopyText()
330 string copiedText = "";
331 if(mController && mController->IsShowingRealText())
333 copiedText = mController->CopyText();
338 string TextField::CutText()
341 if(mController && mController->IsShowingRealText())
343 cutText = mController->CutText();
348 void TextField::PasteText()
352 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
353 mController->PasteText();
357 InputMethodContext TextField::GetInputMethodContext()
359 return mInputMethodContext;
362 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
364 Dali::BaseHandle handle(object);
366 bool connected(true);
367 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
369 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
371 field.TextChangedSignal().Connect(tracker, functor);
373 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
375 field.MaxLengthReachedSignal().Connect(tracker, functor);
377 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
379 field.InputStyleChangedSignal().Connect(tracker, functor);
381 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
385 Internal::TextField& fieldImpl(GetImpl(field));
386 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
389 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
393 Internal::TextField& fieldImpl(GetImpl(field));
394 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
397 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
401 Internal::TextField& fieldImpl(GetImpl(field));
402 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
405 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
409 Internal::TextField& fieldImpl(GetImpl(field));
410 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
413 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
417 Internal::TextField& fieldImpl(GetImpl(field));
418 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
423 // signalName does not match any signal
430 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
432 return mTextChangedSignal;
435 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
437 return mMaxLengthReachedSignal;
440 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
442 return mInputStyleChangedSignal;
445 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
447 return mAnchorClickedSignal;
450 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
452 return mCursorPositionChangedSignal;
455 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
457 return mInputFilteredSignal;
460 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
462 return mSelectionChangedSignal;
465 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
467 return mSelectionClearedSignal;
470 void TextField::OnAccessibilityStatusChanged()
472 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
475 void TextField::OnInitialize()
479 mController = Text::Controller::New(this, this, this, this);
481 // When using the vector-based rendering, the size of the GLyphs are different
482 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
483 mController->SetGlyphType(glyphType);
485 mDecorator = Text::Decorator::New(*mController,
488 mInputMethodContext = InputMethodContext::New(self);
490 mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
492 // Enables the text input.
493 mController->EnableTextInput(mDecorator, mInputMethodContext);
495 // Enables the horizontal scrolling after the text input has been enabled.
496 mController->SetHorizontalScrollEnabled(true);
498 // Disables the vertical scrolling.
499 mController->SetVerticalScrollEnabled(false);
501 // Disable the smooth handle panning.
502 mController->SetSmoothHandlePanEnabled(false);
504 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
505 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
507 // Sets layoutDirection value
508 Dali::Stage stage = Dali::Stage::GetCurrent();
509 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
510 mController->SetLayoutDirection(layoutDirection);
512 self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
514 // Forward input events to controller
515 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
516 GetTapGestureDetector().SetMaximumTapsRequired(2);
517 GetTapGestureDetector().ReceiveAllTapEvents(true);
519 self.TouchedSignal().Connect(this, &TextField::OnTouched);
521 // Set BoundingBox to stage size if not already set.
522 Rect<int> boundingBox;
523 mDecorator->GetBoundingBox(boundingBox);
525 if(boundingBox.IsEmpty())
527 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
528 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
531 // Flip vertically the 'left' selection handle
532 mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
534 // Fill-parent area by default
535 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
536 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
537 self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
539 //Enable highightability
540 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
542 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
544 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
549 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
550 return std::unique_ptr<Dali::Accessibility::Accessible>(
551 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
554 Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
555 Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
558 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
560 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
564 case StyleChange::DEFAULT_FONT_CHANGE:
566 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
567 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
568 // Property system did not set the font so should update it.
569 mController->UpdateAfterFontChange(newFont);
574 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
576 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
580 case StyleChange::THEME_CHANGE:
582 // Nothing to do, let control base class handle this
587 // Up call to Control
588 Control::OnStyleChange(styleManager, change);
591 Vector3 TextField::GetNaturalSize()
594 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
596 Vector3 naturalSize = mController->GetNaturalSize();
597 naturalSize.width += (padding.start + padding.end);
598 naturalSize.height += (padding.top + padding.bottom);
603 float TextField::GetHeightForWidth(float width)
606 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
607 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
610 void TextField::ResizeActor(Actor& actor, const Vector2& size)
612 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
614 actor.SetProperty(Actor::Property::SIZE, size);
618 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
620 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
625 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
627 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
629 // Support Right-To-Left of padding
630 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
632 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
634 std::swap(padding.start, padding.end);
639 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
640 ResizeActor(mStencil, contentSize);
644 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
645 ResizeActor(mActiveLayer, contentSize);
648 // If there is text changed, callback is called.
651 EmitTextChangedSignal();
654 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
656 if((Text::Controller::NONE_UPDATED != updateTextType) ||
659 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
662 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
664 mDecorator->Relayout(contentSize);
669 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
672 RenderText(updateTextType);
675 if(mCursorPositionChanged)
677 EmitCursorPositionChangedSignal();
680 if(mSelectionChanged)
682 EmitSelectionChangedSignal();
685 if(mSelectionCleared)
687 EmitSelectionClearedSignal();
690 // The text-field emits signals when the input style changes. These changes of style are
691 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
692 // can't be emitted during the size negotiation as the callbacks may update the UI.
693 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
694 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
696 if(Adaptor::IsAvailable())
698 Adaptor& adaptor = Adaptor::Get();
700 if(NULL == mIdleCallback)
702 // @note: The callback manager takes the ownership of the callback object.
703 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
704 adaptor.AddIdle(mIdleCallback, false);
710 Text::ControllerPtr TextField::GetTextController()
715 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
717 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
720 void TextField::OnKeyInputFocusGained()
722 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
723 if(mInputMethodContext && IsEditable())
725 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
726 mInputMethodContext.ApplyOptions(mInputMethodOptions);
727 mInputMethodContext.NotifyTextInputMultiLine(false);
729 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
731 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
733 // Notify that the text editing start.
734 mInputMethodContext.Activate();
736 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
737 mInputMethodContext.SetRestoreAfterFocusLost(true);
739 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
743 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
746 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
748 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
751 void TextField::OnKeyInputFocusLost()
753 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
754 if(mInputMethodContext)
756 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
757 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
758 mInputMethodContext.SetRestoreAfterFocusLost(false);
760 // Notify that the text editing finish.
761 mInputMethodContext.Deactivate();
763 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
765 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
769 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
772 mController->KeyboardFocusLostEvent();
774 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
777 bool TextField::OnAccessibilityActivated()
783 void TextField::OnTap(const TapGesture& gesture)
785 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
786 if(mInputMethodContext && IsEditable())
788 mInputMethodContext.Activate();
790 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
792 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
793 const Vector2& localPoint = gesture.GetLocalPoint();
794 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
795 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
800 void TextField::OnPan(const PanGesture& gesture)
802 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
805 void TextField::OnLongPress(const LongPressGesture& gesture)
807 if(mInputMethodContext && IsEditable())
809 mInputMethodContext.Activate();
812 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
813 const Vector2& localPoint = gesture.GetLocalPoint();
814 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
819 bool TextField::OnKeyEvent(const KeyEvent& event)
821 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
823 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
825 // Make sure ClearKeyInputFocus when only key is up
826 if(event.GetState() == KeyEvent::UP)
828 ClearKeyInputFocus();
833 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
835 // Do nothing when enter is comming.
839 return mController->KeyEvent(event);
842 void TextField::RequestTextRelayout()
847 bool TextField::IsEditable() const
849 return mController->IsEditable();
852 void TextField::SetEditable(bool editable)
854 mController->SetEditable(editable);
855 if(mInputMethodContext && !editable)
857 mInputMethodContext.Deactivate();
861 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
863 if(Accessibility::IsUp())
865 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
869 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
871 if(Accessibility::IsUp())
873 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
877 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
879 if(Accessibility::IsUp())
881 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
884 if((oldPosition != newPosition) && !mCursorPositionChanged)
886 mCursorPositionChanged = true;
887 mOldPosition = oldPosition;
891 void TextField::TextChanged(bool immediate)
893 if(immediate) // Emits TextChangedSignal immediately
895 EmitTextChangedSignal();
903 void TextField::EmitTextChangedSignal()
905 Dali::Toolkit::TextField handle(GetOwner());
906 mTextChangedSignal.Emit(handle);
907 mTextChanged = false;
910 void TextField::MaxLengthReached()
912 Dali::Toolkit::TextField handle(GetOwner());
913 mMaxLengthReachedSignal.Emit(handle);
916 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
918 Dali::Toolkit::TextField handle(GetOwner());
919 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
922 void TextField::AnchorClicked(const std::string& href)
924 Dali::Toolkit::TextField handle(GetOwner());
925 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
928 void TextField::EmitCursorPositionChangedSignal()
930 Dali::Toolkit::TextField handle(GetOwner());
931 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
932 mCursorPositionChanged = false;
935 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
937 Dali::Toolkit::TextField handle(GetOwner());
938 mInputFilteredSignal.Emit(handle, type);
941 void TextField::EmitSelectionChangedSignal()
943 Dali::Toolkit::TextField handle(GetOwner());
944 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
945 mSelectionChanged = false;
948 void TextField::EmitSelectionClearedSignal()
950 Dali::Toolkit::TextField handle(GetOwner());
951 mSelectionClearedSignal.Emit(handle);
952 mSelectionCleared = 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;
964 mSelectionChanged = true;
965 mOldSelectionStart = oldStart;
966 mOldSelectionEnd = oldEnd;
968 if(mOldSelectionStart > mOldSelectionEnd)
971 uint32_t temp = mOldSelectionStart;
972 mOldSelectionStart = mOldSelectionEnd;
973 mOldSelectionEnd = temp;
978 void TextField::AddDecoration(Actor& actor, bool needsClipping)
984 mClippingDecorationActors.push_back(actor);
988 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
989 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
991 mActiveLayer = actor;
996 void TextField::GetControlBackgroundColor(Vector4& color) const
998 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
999 Property::Map* resultMap = propValue.GetMap();
1001 Property::Value* colorValue = nullptr;
1002 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1004 colorValue->Get(color);
1008 void TextField::OnSceneConnect(Dali::Actor actor)
1012 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1016 mHasBeenStaged = true;
1020 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1022 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1023 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1026 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1031 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1037 void TextField::EnableClipping()
1041 // Creates an extra control to be used as stencil buffer.
1042 mStencil = Control::New();
1043 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1044 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1046 // Creates a background visual. Even if the color is transparent it updates the stencil.
1047 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1048 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1050 // Enable the clipping property.
1051 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1052 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1054 Self().Add(mStencil);
1058 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1060 mController->PasteClipboardItemEvent();
1063 void TextField::KeyboardStatusChanged(bool keyboardShown)
1065 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1067 // Just hide the grab handle when keyboard is hidden.
1070 mController->KeyboardFocusLostEvent();
1074 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1078 void TextField::OnSceneConnection(int depth)
1080 // Sets the depth to the visuals inside the text's decorator.
1081 mDecorator->SetTextDepth(depth);
1083 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1085 // Call the Control::OnSceneConnection() to set the depth of the background.
1086 Control::OnSceneConnection(depth);
1089 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1094 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1096 mController->ChangedLayoutDirection();
1099 void TextField::OnIdleSignal()
1101 // Emits the change of input style signals.
1102 mController->ProcessInputStyleChangedSignals();
1104 // Set the pointer to null as the callback manager deletes the callback after execute it.
1105 mIdleCallback = NULL;
1108 TextField::TextField()
1109 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1110 mIdleCallback(NULL),
1111 mAlignmentOffset(0.f),
1112 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1113 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1114 mHasBeenStaged(false),
1115 mTextChanged(false),
1116 mCursorPositionChanged(false),
1117 mSelectionChanged(false),
1118 mSelectionCleared(false),
1120 mOldSelectionStart(0u),
1121 mOldSelectionEnd(0u)
1125 TextField::~TextField()
1127 UnparentAndReset(mStencil);
1129 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1131 Adaptor::Get().RemoveIdle(mIdleCallback);
1135 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1137 return mController->GetTextSize(startIndex, endIndex);
1140 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1142 return mController->GetTextPosition(startIndex, endIndex);
1145 std::string TextField::AccessibleImpl::GetName() const
1147 auto self = Toolkit::TextField::DownCast(Self());
1148 if(IsHiddenInput(self))
1153 return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1156 std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1158 if(endOffset <= startOffset)
1163 auto self = Toolkit::TextField::DownCast(Self());
1164 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1166 if(startOffset > text.size() || endOffset > text.size())
1170 if(IsHiddenInput(self))
1172 return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
1174 return text.substr(startOffset, endOffset - startOffset);
1177 size_t TextField::AccessibleImpl::GetCharacterCount() const
1179 auto self = Toolkit::TextField::DownCast(Self());
1180 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1185 size_t TextField::AccessibleImpl::GetCursorOffset() const
1187 auto self = Toolkit::TextField::DownCast(Self());
1188 return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
1191 bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
1193 auto self = Toolkit::TextField::DownCast(Self());
1194 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1195 if(offset > text.size())
1200 auto& selfImpl = Dali::Toolkit::GetImpl(self);
1201 selfImpl.GetTextController()->ResetCursorPosition(offset);
1202 selfImpl.RequestTextRelayout();
1207 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1208 size_t offset, Dali::Accessibility::TextBoundary boundary) const
1210 auto self = Toolkit::TextField::DownCast(Self());
1211 auto range = Dali::Accessibility::Range{};
1213 if(IsHiddenInput(self))
1215 // Returning empty object, as there is no possibility to parse the textfield
1216 // when its content is hidden.
1220 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1221 auto textSize = text.size();
1225 case Dali::Accessibility::TextBoundary::CHARACTER:
1227 if(offset < textSize)
1229 range.content = text[offset];
1230 range.startOffset = offset;
1231 range.endOffset = offset + 1;
1235 case Dali::Accessibility::TextBoundary::WORD:
1236 case Dali::Accessibility::TextBoundary::LINE:
1238 auto textString = text.c_str();
1239 auto breaks = std::vector<char>(textSize, 0);
1241 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1243 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1247 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1252 while(index < textSize && counter <= offset)
1257 while(breaks[index])
1265 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1269 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1275 if((counter > 0) && ((counter - 1) == offset))
1277 range.content = text.substr(start, index - start + 1);
1278 range.startOffset = start;
1279 range.endOffset = index + 1;
1282 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1289 case Dali::Accessibility::TextBoundary::SENTENCE:
1291 /* not supported by default */
1294 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1296 /* Paragraph is not supported by libunibreak library */
1306 Dali::Accessibility::Range TextField::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1308 // Since DALi supports only one selection indexes higher than 0 are ignored
1309 if(selectionIndex > 0)
1314 auto self = Toolkit::TextField::DownCast(Self());
1315 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1316 auto indices = controller->GetSelectionIndexes();
1318 auto startOffset = static_cast<size_t>(indices.first);
1319 auto endOffset = static_cast<size_t>(indices.second);
1321 if(IsHiddenInput(self))
1323 return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
1326 std::string value{};
1327 controller->RetrieveSelection(value);
1328 return {startOffset, endOffset, value};
1331 bool TextField::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1333 // Since DALi supports only one selection indexes higher than 0 are ignored
1334 if(selectionIndex > 0)
1339 auto self = Toolkit::TextField::DownCast(Self());
1340 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1344 bool TextField::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1346 // Since DALi supports only one selection indexes higher than 0 are ignored
1347 if(selectionIndex > 0)
1352 auto self = Toolkit::TextField::DownCast(Self());
1353 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1357 bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1359 if(endPosition <= startPosition)
1364 auto self = Toolkit::TextField::DownCast(Self());
1365 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1366 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1371 bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1373 if(endPosition <= startPosition)
1378 auto self = Toolkit::TextField::DownCast(Self());
1379 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1380 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1382 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1387 bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1389 if(endPosition <= startPosition)
1394 auto self = Toolkit::TextField::DownCast(Self());
1395 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1397 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1402 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
1404 using namespace Dali::Accessibility;
1406 auto states = DevelControl::ControlAccessible::CalculateStates();
1408 states[State::EDITABLE] = true;
1409 states[State::FOCUSABLE] = true;
1411 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1412 if(Self() == focusControl)
1414 states[State::FOCUSED] = true;
1420 bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1422 auto self = Toolkit::TextField::DownCast(Self());
1423 auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1425 insertedText.insert(startPosition, text);
1427 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
1432 bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
1434 auto self = Toolkit::TextField::DownCast(Self());
1435 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
1439 int32_t TextField::AccessibleImpl::GetLinkCount() const
1441 auto self = Toolkit::TextField::DownCast(Self());
1442 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1445 Accessibility::Hyperlink* TextField::AccessibleImpl::GetLink(int32_t linkIndex) const
1447 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1451 auto self = Toolkit::TextField::DownCast(Self());
1452 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1453 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1456 int32_t TextField::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1458 auto self = Toolkit::TextField::DownCast(Self());
1459 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1460 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1463 } // namespace Internal
1465 } // namespace Toolkit