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 )
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 )
157 DALI_TYPE_REGISTRATION_END()
160 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
162 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
164 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
166 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
168 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
170 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
172 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
174 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
176 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
178 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
180 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
182 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
184 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
186 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
188 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
190 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
192 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
194 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
196 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
198 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
200 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
202 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
204 return fieldInputStyleMask;
207 bool IsHiddenInput(Toolkit::TextField textField)
209 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
210 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
211 if(mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
218 char GetSubstituteCharacter(Toolkit::TextField textField)
220 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
221 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
224 return static_cast<char>(substChar->Get<int>());
231 Toolkit::TextField TextField::New()
233 // Create the implementation, temporarily owned by this handle on stack
234 IntrusivePtr<TextField> impl = new TextField();
236 // Pass ownership to CustomActor handle
237 Toolkit::TextField handle(*impl);
239 // Second-phase init of the implementation
240 // This can only be done after the CustomActor connection has been made...
246 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
248 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
250 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
254 PropertyHandler::SetProperty(textField, index, value);
258 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
260 Property::Value value;
262 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
266 value = PropertyHandler::GetProperty(textField, index);
272 void TextField::SelectWholeText()
274 if(mController && mController->IsShowingRealText())
276 mController->SelectWholeText();
281 void TextField::SelectNone()
283 if(mController && mController->IsShowingRealText())
285 mController->SelectNone();
289 void TextField::SelectText(const uint32_t start, const uint32_t end)
291 if(mController && mController->IsShowingRealText())
293 mController->SelectText(start, end);
298 string TextField::GetSelectedText() const
300 string selectedText = "";
301 if(mController && mController->IsShowingRealText())
303 selectedText = mController->GetSelectedText();
308 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
310 if(mController && mController->IsShowingRealText())
312 mController->SetTextSelectionRange(start, end);
317 Uint32Pair TextField::GetTextSelectionRange() const
320 if(mController && mController->IsShowingRealText())
322 range = mController->GetTextSelectionRange();
327 string TextField::CopyText()
329 string copiedText = "";
330 if(mController && mController->IsShowingRealText())
332 copiedText = mController->CopyText();
337 string TextField::CutText()
340 if(mController && mController->IsShowingRealText())
342 cutText = mController->CutText();
347 void TextField::PasteText()
351 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
352 mController->PasteText();
356 InputMethodContext TextField::GetInputMethodContext()
358 return mInputMethodContext;
361 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
363 Dali::BaseHandle handle(object);
365 bool connected(true);
366 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
368 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
370 field.TextChangedSignal().Connect(tracker, functor);
372 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
374 field.MaxLengthReachedSignal().Connect(tracker, functor);
376 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
378 field.InputStyleChangedSignal().Connect(tracker, functor);
380 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
384 Internal::TextField& fieldImpl(GetImpl(field));
385 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
388 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
392 Internal::TextField& fieldImpl(GetImpl(field));
393 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
396 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
400 Internal::TextField& fieldImpl(GetImpl(field));
401 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
404 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
408 Internal::TextField& fieldImpl(GetImpl(field));
409 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
412 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
416 Internal::TextField& fieldImpl(GetImpl(field));
417 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
422 // signalName does not match any signal
429 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
431 return mTextChangedSignal;
434 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
436 return mMaxLengthReachedSignal;
439 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
441 return mInputStyleChangedSignal;
444 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
446 return mAnchorClickedSignal;
449 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
451 return mCursorPositionChangedSignal;
454 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
456 return mInputFilteredSignal;
459 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
461 return mSelectionChangedSignal;
464 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
466 return mSelectionClearedSignal;
469 void TextField::OnAccessibilityStatusChanged()
471 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
474 void TextField::OnInitialize()
478 mController = Text::Controller::New(this, this, this, this);
480 // When using the vector-based rendering, the size of the GLyphs are different
481 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
482 mController->SetGlyphType(glyphType);
484 mDecorator = Text::Decorator::New(*mController,
487 mInputMethodContext = InputMethodContext::New(self);
489 mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
491 // Enables the text input.
492 mController->EnableTextInput(mDecorator, mInputMethodContext);
494 // Enables the horizontal scrolling after the text input has been enabled.
495 mController->SetHorizontalScrollEnabled(true);
497 // Disables the vertical scrolling.
498 mController->SetVerticalScrollEnabled(false);
500 // Disable the smooth handle panning.
501 mController->SetSmoothHandlePanEnabled(false);
503 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
504 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
506 // Sets layoutDirection value
507 Dali::Stage stage = Dali::Stage::GetCurrent();
508 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
509 mController->SetLayoutDirection(layoutDirection);
511 self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
513 // Forward input events to controller
514 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
515 GetTapGestureDetector().SetMaximumTapsRequired(2);
516 GetTapGestureDetector().ReceiveAllTapEvents(true);
518 self.TouchedSignal().Connect(this, &TextField::OnTouched);
520 // Set BoundingBox to stage size if not already set.
521 Rect<int> boundingBox;
522 mDecorator->GetBoundingBox(boundingBox);
524 if(boundingBox.IsEmpty())
526 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
527 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
530 // Flip vertically the 'left' selection handle
531 mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
533 // Fill-parent area by default
534 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
535 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
536 self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
538 //Enable highightability
539 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
541 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
543 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
548 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
549 return std::unique_ptr<Dali::Accessibility::Accessible>(
550 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
553 Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
554 Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
557 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
559 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
563 case StyleChange::DEFAULT_FONT_CHANGE:
565 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
566 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
567 // Property system did not set the font so should update it.
568 mController->UpdateAfterFontChange(newFont);
573 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
575 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
579 case StyleChange::THEME_CHANGE:
581 // Nothing to do, let control base class handle this
586 // Up call to Control
587 Control::OnStyleChange(styleManager, change);
590 Vector3 TextField::GetNaturalSize()
593 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
595 Vector3 naturalSize = mController->GetNaturalSize();
596 naturalSize.width += (padding.start + padding.end);
597 naturalSize.height += (padding.top + padding.bottom);
602 float TextField::GetHeightForWidth(float width)
605 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
606 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
609 void TextField::ResizeActor(Actor& actor, const Vector2& size)
611 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
613 actor.SetProperty(Actor::Property::SIZE, size);
617 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
619 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
624 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
626 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
628 // Support Right-To-Left of padding
629 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
631 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
633 std::swap(padding.start, padding.end);
638 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
639 ResizeActor(mStencil, contentSize);
643 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
644 ResizeActor(mActiveLayer, contentSize);
647 // If there is text changed, callback is called.
650 EmitTextChangedSignal();
653 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
655 if((Text::Controller::NONE_UPDATED != updateTextType) ||
658 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
661 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
663 mDecorator->Relayout(contentSize);
668 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
671 RenderText(updateTextType);
674 if(mCursorPositionChanged)
676 EmitCursorPositionChangedSignal();
679 if(mSelectionChanged)
681 EmitSelectionChangedSignal();
684 if(mSelectionCleared)
686 EmitSelectionClearedSignal();
689 // The text-field emits signals when the input style changes. These changes of style are
690 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
691 // can't be emitted during the size negotiation as the callbacks may update the UI.
692 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
693 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
695 if(Adaptor::IsAvailable())
697 Adaptor& adaptor = Adaptor::Get();
699 if(NULL == mIdleCallback)
701 // @note: The callback manager takes the ownership of the callback object.
702 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
703 adaptor.AddIdle(mIdleCallback, false);
709 Text::ControllerPtr TextField::GetTextController()
714 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
716 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
719 void TextField::OnKeyInputFocusGained()
721 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
722 if(mInputMethodContext && IsEditable())
724 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
725 mInputMethodContext.ApplyOptions(mInputMethodOptions);
726 mInputMethodContext.NotifyTextInputMultiLine(false);
728 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
730 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
732 // Notify that the text editing start.
733 mInputMethodContext.Activate();
735 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
736 mInputMethodContext.SetRestoreAfterFocusLost(true);
738 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
742 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
745 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
747 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
750 void TextField::OnKeyInputFocusLost()
752 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
753 if(mInputMethodContext)
755 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
756 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
757 mInputMethodContext.SetRestoreAfterFocusLost(false);
759 // Notify that the text editing finish.
760 mInputMethodContext.Deactivate();
762 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
764 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
768 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
771 mController->KeyboardFocusLostEvent();
773 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
776 bool TextField::OnAccessibilityActivated()
782 void TextField::OnTap(const TapGesture& gesture)
784 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
785 if(mInputMethodContext && IsEditable())
787 mInputMethodContext.Activate();
789 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
791 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
792 const Vector2& localPoint = gesture.GetLocalPoint();
793 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
794 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
799 void TextField::OnPan(const PanGesture& gesture)
801 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
804 void TextField::OnLongPress(const LongPressGesture& gesture)
806 if(mInputMethodContext && IsEditable())
808 mInputMethodContext.Activate();
811 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
812 const Vector2& localPoint = gesture.GetLocalPoint();
813 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
818 bool TextField::OnKeyEvent(const KeyEvent& event)
820 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
822 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
824 // Make sure ClearKeyInputFocus when only key is up
825 if(event.GetState() == KeyEvent::UP)
827 ClearKeyInputFocus();
832 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
834 // Do nothing when enter is comming.
838 return mController->KeyEvent(event);
841 void TextField::RequestTextRelayout()
846 bool TextField::IsEditable() const
848 return mController->IsEditable();
851 void TextField::SetEditable(bool editable)
853 mController->SetEditable(editable);
854 if(mInputMethodContext && !editable)
856 mInputMethodContext.Deactivate();
860 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
862 if(Accessibility::IsUp())
864 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
868 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
870 if(Accessibility::IsUp())
872 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
876 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
878 if(Accessibility::IsUp())
880 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
883 if((oldPosition != newPosition) && !mCursorPositionChanged)
885 mCursorPositionChanged = true;
886 mOldPosition = oldPosition;
890 void TextField::TextChanged(bool immediate)
892 if(immediate) // Emits TextChangedSignal immediately
894 EmitTextChangedSignal();
902 void TextField::EmitTextChangedSignal()
904 Dali::Toolkit::TextField handle(GetOwner());
905 mTextChangedSignal.Emit(handle);
906 mTextChanged = false;
909 void TextField::MaxLengthReached()
911 Dali::Toolkit::TextField handle(GetOwner());
912 mMaxLengthReachedSignal.Emit(handle);
915 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
917 Dali::Toolkit::TextField handle(GetOwner());
918 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
921 void TextField::AnchorClicked(const std::string& href)
923 Dali::Toolkit::TextField handle(GetOwner());
924 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
927 void TextField::EmitCursorPositionChangedSignal()
929 Dali::Toolkit::TextField handle(GetOwner());
930 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
931 mCursorPositionChanged = false;
934 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
936 Dali::Toolkit::TextField handle(GetOwner());
937 mInputFilteredSignal.Emit(handle, type);
940 void TextField::EmitSelectionChangedSignal()
942 Dali::Toolkit::TextField handle(GetOwner());
943 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
944 mSelectionChanged = false;
947 void TextField::EmitSelectionClearedSignal()
949 Dali::Toolkit::TextField handle(GetOwner());
950 mSelectionClearedSignal.Emit(handle);
951 mSelectionCleared = false;
954 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
956 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
958 if(newStart == newEnd)
960 mSelectionCleared = true;
963 mSelectionChanged = true;
964 mOldSelectionStart = oldStart;
965 mOldSelectionEnd = oldEnd;
967 if(mOldSelectionStart > mOldSelectionEnd)
970 uint32_t temp = mOldSelectionStart;
971 mOldSelectionStart = mOldSelectionEnd;
972 mOldSelectionEnd = temp;
977 void TextField::AddDecoration(Actor& actor, bool needsClipping)
983 mClippingDecorationActors.push_back(actor);
987 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
988 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
990 mActiveLayer = actor;
995 void TextField::GetControlBackgroundColor(Vector4& color) const
997 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
998 Property::Map* resultMap = propValue.GetMap();
1000 Property::Value* colorValue = nullptr;
1001 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1003 colorValue->Get(color);
1007 void TextField::OnSceneConnect(Dali::Actor actor)
1011 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1015 mHasBeenStaged = true;
1019 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1021 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1022 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1025 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1030 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1036 void TextField::EnableClipping()
1040 // Creates an extra control to be used as stencil buffer.
1041 mStencil = Control::New();
1042 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1043 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1045 // Creates a background visual. Even if the color is transparent it updates the stencil.
1046 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1047 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1049 // Enable the clipping property.
1050 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1051 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1053 Self().Add(mStencil);
1057 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1059 mController->PasteClipboardItemEvent();
1062 void TextField::KeyboardStatusChanged(bool keyboardShown)
1064 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1066 // Just hide the grab handle when keyboard is hidden.
1069 mController->KeyboardFocusLostEvent();
1073 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1077 void TextField::OnSceneConnection(int depth)
1079 // Sets the depth to the visuals inside the text's decorator.
1080 mDecorator->SetTextDepth(depth);
1082 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1084 // Call the Control::OnSceneConnection() to set the depth of the background.
1085 Control::OnSceneConnection(depth);
1088 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1093 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1095 mController->ChangedLayoutDirection();
1098 void TextField::OnIdleSignal()
1100 // Emits the change of input style signals.
1101 mController->ProcessInputStyleChangedSignals();
1103 // Set the pointer to null as the callback manager deletes the callback after execute it.
1104 mIdleCallback = NULL;
1107 TextField::TextField()
1108 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1109 mIdleCallback(NULL),
1110 mAlignmentOffset(0.f),
1111 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1112 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1113 mHasBeenStaged(false),
1114 mTextChanged(false),
1115 mCursorPositionChanged(false),
1116 mSelectionChanged(false),
1117 mSelectionCleared(false),
1119 mOldSelectionStart(0u),
1120 mOldSelectionEnd(0u)
1124 TextField::~TextField()
1126 UnparentAndReset(mStencil);
1128 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1130 Adaptor::Get().RemoveIdle(mIdleCallback);
1134 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1136 return mController->GetTextSize(startIndex, endIndex);
1139 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1141 return mController->GetTextPosition(startIndex, endIndex);
1144 std::string TextField::AccessibleImpl::GetName() const
1146 auto self = Toolkit::TextField::DownCast(Self());
1147 if(IsHiddenInput(self))
1152 return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1155 std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1157 if(endOffset <= startOffset)
1162 auto self = Toolkit::TextField::DownCast(Self());
1163 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1165 if(startOffset > text.size() || endOffset > text.size())
1169 if(IsHiddenInput(self))
1171 return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
1173 return text.substr(startOffset, endOffset - startOffset);
1176 size_t TextField::AccessibleImpl::GetCharacterCount() const
1178 auto self = Toolkit::TextField::DownCast(Self());
1179 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1184 size_t TextField::AccessibleImpl::GetCursorOffset() const
1186 auto self = Toolkit::TextField::DownCast(Self());
1187 return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
1190 bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
1192 auto self = Toolkit::TextField::DownCast(Self());
1193 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1194 if(offset > text.size())
1199 auto& selfImpl = Dali::Toolkit::GetImpl(self);
1200 selfImpl.GetTextController()->ResetCursorPosition(offset);
1201 selfImpl.RequestTextRelayout();
1206 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1207 size_t offset, Dali::Accessibility::TextBoundary boundary) const
1209 auto self = Toolkit::TextField::DownCast(Self());
1210 auto range = Dali::Accessibility::Range{};
1212 if(IsHiddenInput(self))
1214 // Returning empty object, as there is no possibility to parse the textfield
1215 // when its content is hidden.
1219 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1220 auto textSize = text.size();
1224 case Dali::Accessibility::TextBoundary::CHARACTER:
1226 if(offset < textSize)
1228 range.content = text[offset];
1229 range.startOffset = offset;
1230 range.endOffset = offset + 1;
1234 case Dali::Accessibility::TextBoundary::WORD:
1235 case Dali::Accessibility::TextBoundary::LINE:
1237 auto textString = text.c_str();
1238 auto breaks = std::vector<char>(textSize, 0);
1240 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1242 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1246 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1251 while(index < textSize && counter <= offset)
1256 while(breaks[index])
1264 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1268 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1274 if((counter > 0) && ((counter - 1) == offset))
1276 range.content = text.substr(start, index - start + 1);
1277 range.startOffset = start;
1278 range.endOffset = index + 1;
1281 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1288 case Dali::Accessibility::TextBoundary::SENTENCE:
1290 /* not supported by default */
1293 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1295 /* Paragraph is not supported by libunibreak library */
1305 Dali::Accessibility::Range TextField::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1307 // Since DALi supports only one selection indexes higher than 0 are ignored
1308 if(selectionIndex > 0)
1313 auto self = Toolkit::TextField::DownCast(Self());
1314 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1315 auto indices = controller->GetSelectionIndexes();
1317 auto startOffset = static_cast<size_t>(indices.first);
1318 auto endOffset = static_cast<size_t>(indices.second);
1320 if(IsHiddenInput(self))
1322 return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
1325 std::string value{};
1326 controller->RetrieveSelection(value);
1327 return {startOffset, endOffset, value};
1330 bool TextField::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1332 // Since DALi supports only one selection indexes higher than 0 are ignored
1333 if(selectionIndex > 0)
1338 auto self = Toolkit::TextField::DownCast(Self());
1339 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1343 bool TextField::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1345 // Since DALi supports only one selection indexes higher than 0 are ignored
1346 if(selectionIndex > 0)
1351 auto self = Toolkit::TextField::DownCast(Self());
1352 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1356 bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1358 if(endPosition <= startPosition)
1363 auto self = Toolkit::TextField::DownCast(Self());
1364 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1365 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1370 bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1372 if(endPosition <= startPosition)
1377 auto self = Toolkit::TextField::DownCast(Self());
1378 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1379 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1381 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1386 bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1388 if(endPosition <= startPosition)
1393 auto self = Toolkit::TextField::DownCast(Self());
1394 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1396 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1401 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
1403 using namespace Dali::Accessibility;
1405 auto states = DevelControl::ControlAccessible::CalculateStates();
1407 states[State::EDITABLE] = true;
1408 states[State::FOCUSABLE] = true;
1410 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1411 if(Self() == focusControl)
1413 states[State::FOCUSED] = true;
1419 bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1421 auto self = Toolkit::TextField::DownCast(Self());
1422 auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1424 insertedText.insert(startPosition, text);
1426 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
1431 bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
1433 auto self = Toolkit::TextField::DownCast(Self());
1434 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
1438 int32_t TextField::AccessibleImpl::GetLinkCount() const
1440 auto self = Toolkit::TextField::DownCast(Self());
1441 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1444 Accessibility::Hyperlink* TextField::AccessibleImpl::GetLink(int32_t linkIndex) const
1446 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1450 auto self = Toolkit::TextField::DownCast(Self());
1451 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1452 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1455 int32_t TextField::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1457 auto self = Toolkit::TextField::DownCast(Self());
1458 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1459 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1462 } // namespace Internal
1464 } // namespace Toolkit