2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/key-devel.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/key.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/object/type-registry-helper.h>
34 #include <dali-toolkit/devel-api/controls/control-devel.h>
35 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/text/rendering-backend.h>
38 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
39 #include <dali-toolkit/internal/controls/text-controls/text-field-property-handler.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/public-api/text/text-enumerations.h>
47 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
48 #include <dali-toolkit/public-api/visuals/visual-properties.h>
49 #include <dali/integration-api/adaptor-framework/adaptor.h>
51 using namespace Dali::Toolkit::Text;
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextFieldLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
63 namespace // unnamed namespace
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
66 } // unnamed namespace
73 return Toolkit::TextField::New();
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
80 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "text", STRING, TEXT )
81 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
82 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
83 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
84 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
85 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "underline", MAP, UNDERLINE )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "emboss", MAP, EMBOSS )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
129 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
130 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
134 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFilter", MAP, INPUT_FILTER )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "strikethrough", MAP, STRIKETHROUGH )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
147 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
148 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered", SIGNAL_INPUT_FILTERED )
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
156 DALI_TYPE_REGISTRATION_END()
159 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
161 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
163 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
165 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
167 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
169 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
171 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
173 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
175 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
177 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
179 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
181 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
183 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
185 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
187 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
189 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
191 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
193 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
195 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
197 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
199 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
201 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
203 return fieldInputStyleMask;
206 bool IsHiddenInput(Toolkit::TextField textField)
208 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
209 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
210 if(mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
217 char GetSubstituteCharacter(Toolkit::TextField textField)
219 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
220 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
223 return static_cast<char>(substChar->Get<int>());
230 Toolkit::TextField TextField::New()
232 // Create the implementation, temporarily owned by this handle on stack
233 IntrusivePtr<TextField> impl = new TextField();
235 // Pass ownership to CustomActor handle
236 Toolkit::TextField handle(*impl);
238 // Second-phase init of the implementation
239 // This can only be done after the CustomActor connection has been made...
245 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
247 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
249 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
253 PropertyHandler::SetProperty(textField, index, value);
257 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
259 Property::Value value;
261 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
265 value = PropertyHandler::GetProperty(textField, index);
271 void TextField::SelectWholeText()
273 if(mController && mController->IsShowingRealText())
275 mController->SelectWholeText();
280 void TextField::SelectNone()
282 if(mController && mController->IsShowingRealText())
284 mController->SelectNone();
288 void TextField::SelectText(const uint32_t start, const uint32_t end)
290 if(mController && mController->IsShowingRealText())
292 mController->SelectText(start, end);
297 string TextField::GetSelectedText() const
299 string selectedText = "";
300 if(mController && mController->IsShowingRealText())
302 selectedText = mController->GetSelectedText();
307 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
309 if(mController && mController->IsShowingRealText())
311 mController->SetTextSelectionRange(start, end);
316 Uint32Pair TextField::GetTextSelectionRange() const
319 if(mController && mController->IsShowingRealText())
321 range = mController->GetTextSelectionRange();
326 string TextField::CopyText()
328 string copiedText = "";
329 if(mController && mController->IsShowingRealText())
331 copiedText = mController->CopyText();
336 string TextField::CutText()
339 if(mController && mController->IsShowingRealText())
341 cutText = mController->CutText();
346 void TextField::PasteText()
350 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
351 mController->PasteText();
355 InputMethodContext TextField::GetInputMethodContext()
357 return mInputMethodContext;
360 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
362 Dali::BaseHandle handle(object);
364 bool connected(true);
365 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
367 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
369 field.TextChangedSignal().Connect(tracker, functor);
371 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
373 field.MaxLengthReachedSignal().Connect(tracker, functor);
375 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
377 field.InputStyleChangedSignal().Connect(tracker, functor);
379 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
383 Internal::TextField& fieldImpl(GetImpl(field));
384 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
387 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
391 Internal::TextField& fieldImpl(GetImpl(field));
392 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
395 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
399 Internal::TextField& fieldImpl(GetImpl(field));
400 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
403 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
407 Internal::TextField& fieldImpl(GetImpl(field));
408 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
411 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
415 Internal::TextField& fieldImpl(GetImpl(field));
416 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
421 // signalName does not match any signal
428 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
430 return mTextChangedSignal;
433 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
435 return mMaxLengthReachedSignal;
438 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
440 return mInputStyleChangedSignal;
443 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
445 return mAnchorClickedSignal;
448 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
450 return mCursorPositionChangedSignal;
453 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
455 return mInputFilteredSignal;
458 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
460 return mSelectionChangedSignal;
463 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
465 return mSelectionClearedSignal;
468 void TextField::OnAccessibilityStatusChanged()
470 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
473 void TextField::OnInitialize()
477 mController = Text::Controller::New(this, this, this, this);
479 // When using the vector-based rendering, the size of the GLyphs are different
480 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
481 mController->SetGlyphType(glyphType);
483 mDecorator = Text::Decorator::New(*mController,
486 mInputMethodContext = InputMethodContext::New(self);
488 mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
490 // Enables the text input.
491 mController->EnableTextInput(mDecorator, mInputMethodContext);
493 // Enables the horizontal scrolling after the text input has been enabled.
494 mController->SetHorizontalScrollEnabled(true);
496 // Disables the vertical scrolling.
497 mController->SetVerticalScrollEnabled(false);
499 // Disable the smooth handle panning.
500 mController->SetSmoothHandlePanEnabled(false);
502 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
503 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
505 // Sets layoutDirection value
506 Dali::Stage stage = Dali::Stage::GetCurrent();
507 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
508 mController->SetLayoutDirection(layoutDirection);
510 self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
512 // Forward input events to controller
513 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
514 GetTapGestureDetector().SetMaximumTapsRequired(2);
515 GetTapGestureDetector().ReceiveAllTapEvents(true);
517 self.TouchedSignal().Connect(this, &TextField::OnTouched);
519 // Set BoundingBox to stage size if not already set.
520 Rect<int> boundingBox;
521 mDecorator->GetBoundingBox(boundingBox);
523 if(boundingBox.IsEmpty())
525 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
526 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
529 // Flip vertically the 'left' selection handle
530 mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
532 // Fill-parent area by default
533 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
534 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
535 self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
537 //Enable highightability
538 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
540 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
542 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
547 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
548 return std::unique_ptr<Dali::Accessibility::Accessible>(
549 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
552 Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
553 Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
556 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
558 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
562 case StyleChange::DEFAULT_FONT_CHANGE:
564 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
565 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
566 // Property system did not set the font so should update it.
567 mController->UpdateAfterFontChange(newFont);
572 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
574 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
578 case StyleChange::THEME_CHANGE:
580 // Nothing to do, let control base class handle this
585 // Up call to Control
586 Control::OnStyleChange(styleManager, change);
589 Vector3 TextField::GetNaturalSize()
592 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
594 Vector3 naturalSize = mController->GetNaturalSize();
595 naturalSize.width += (padding.start + padding.end);
596 naturalSize.height += (padding.top + padding.bottom);
601 float TextField::GetHeightForWidth(float width)
604 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
605 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
608 void TextField::ResizeActor(Actor& actor, const Vector2& size)
610 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
612 actor.SetProperty(Actor::Property::SIZE, size);
616 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
618 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
623 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
625 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
627 // Support Right-To-Left of padding
628 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
630 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
632 std::swap(padding.start, padding.end);
637 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
638 ResizeActor(mStencil, contentSize);
642 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
643 ResizeActor(mActiveLayer, contentSize);
646 // If there is text changed, callback is called.
649 EmitTextChangedSignal();
652 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
654 if((Text::Controller::NONE_UPDATED != updateTextType) ||
657 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
660 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
662 mDecorator->Relayout(contentSize);
667 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
670 RenderText(updateTextType);
673 if(mCursorPositionChanged)
675 EmitCursorPositionChangedSignal();
678 if(mSelectionChanged)
680 EmitSelectionChangedSignal();
683 if(mSelectionCleared)
685 EmitSelectionClearedSignal();
688 // The text-field emits signals when the input style changes. These changes of style are
689 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
690 // can't be emitted during the size negotiation as the callbacks may update the UI.
691 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
692 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
694 if(Adaptor::IsAvailable())
696 Adaptor& adaptor = Adaptor::Get();
698 if(NULL == mIdleCallback)
700 // @note: The callback manager takes the ownership of the callback object.
701 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
702 adaptor.AddIdle(mIdleCallback, false);
708 Text::ControllerPtr TextField::GetTextController()
713 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
715 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
718 void TextField::OnKeyInputFocusGained()
720 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
721 if(mInputMethodContext && IsEditable())
723 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
724 mInputMethodContext.ApplyOptions(mInputMethodOptions);
725 mInputMethodContext.NotifyTextInputMultiLine(false);
727 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
729 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
731 // Notify that the text editing start.
732 mInputMethodContext.Activate();
734 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
735 mInputMethodContext.SetRestoreAfterFocusLost(true);
737 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
741 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
744 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
746 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
749 void TextField::OnKeyInputFocusLost()
751 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
752 if(mInputMethodContext)
754 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
755 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
756 mInputMethodContext.SetRestoreAfterFocusLost(false);
758 // Notify that the text editing finish.
759 mInputMethodContext.Deactivate();
761 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
763 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
767 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
770 mController->KeyboardFocusLostEvent();
772 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
775 bool TextField::OnAccessibilityActivated()
781 void TextField::OnTap(const TapGesture& gesture)
783 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
784 if(mInputMethodContext && IsEditable())
786 mInputMethodContext.Activate();
788 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
790 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
791 const Vector2& localPoint = gesture.GetLocalPoint();
792 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
793 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
798 void TextField::OnPan(const PanGesture& gesture)
800 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
803 void TextField::OnLongPress(const LongPressGesture& gesture)
805 if(mInputMethodContext && IsEditable())
807 mInputMethodContext.Activate();
810 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
811 const Vector2& localPoint = gesture.GetLocalPoint();
812 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
817 bool TextField::OnKeyEvent(const KeyEvent& event)
819 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
821 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
823 // Make sure ClearKeyInputFocus when only key is up
824 if(event.GetState() == KeyEvent::UP)
826 ClearKeyInputFocus();
831 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
833 // Do nothing when enter is comming.
837 return mController->KeyEvent(event);
840 void TextField::RequestTextRelayout()
845 bool TextField::IsEditable() const
847 return mController->IsEditable();
850 void TextField::SetEditable(bool editable)
852 mController->SetEditable(editable);
853 if(mInputMethodContext && !editable)
855 mInputMethodContext.Deactivate();
859 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
861 if(Accessibility::IsUp())
863 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
867 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
869 if(Accessibility::IsUp())
871 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
875 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
877 if(Accessibility::IsUp())
879 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
882 if((oldPosition != newPosition) && !mCursorPositionChanged)
884 mCursorPositionChanged = true;
885 mOldPosition = oldPosition;
889 void TextField::TextChanged(bool immediate)
891 if(immediate) // Emits TextChangedSignal immediately
893 EmitTextChangedSignal();
901 void TextField::EmitTextChangedSignal()
903 Dali::Toolkit::TextField handle(GetOwner());
904 mTextChangedSignal.Emit(handle);
905 mTextChanged = false;
908 void TextField::MaxLengthReached()
910 Dali::Toolkit::TextField handle(GetOwner());
911 mMaxLengthReachedSignal.Emit(handle);
914 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
916 Dali::Toolkit::TextField handle(GetOwner());
917 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
920 void TextField::AnchorClicked(const std::string& href)
922 Dali::Toolkit::TextField handle(GetOwner());
923 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
926 void TextField::EmitCursorPositionChangedSignal()
928 Dali::Toolkit::TextField handle(GetOwner());
929 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
930 mCursorPositionChanged = false;
933 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
935 Dali::Toolkit::TextField handle(GetOwner());
936 mInputFilteredSignal.Emit(handle, type);
939 void TextField::EmitSelectionChangedSignal()
941 Dali::Toolkit::TextField handle(GetOwner());
942 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
943 mSelectionChanged = false;
946 void TextField::EmitSelectionClearedSignal()
948 Dali::Toolkit::TextField handle(GetOwner());
949 mSelectionClearedSignal.Emit(handle);
950 mSelectionCleared = false;
953 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
955 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
957 if(newStart == newEnd)
959 mSelectionCleared = true;
962 mSelectionChanged = true;
963 mOldSelectionStart = oldStart;
964 mOldSelectionEnd = oldEnd;
966 if(mOldSelectionStart > mOldSelectionEnd)
969 uint32_t temp = mOldSelectionStart;
970 mOldSelectionStart = mOldSelectionEnd;
971 mOldSelectionEnd = temp;
976 void TextField::AddDecoration(Actor& actor, bool needsClipping)
982 mClippingDecorationActors.push_back(actor);
986 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
987 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
989 mActiveLayer = actor;
994 void TextField::GetControlBackgroundColor(Vector4& color) const
996 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
997 Property::Map* resultMap = propValue.GetMap();
999 Property::Value* colorValue = nullptr;
1000 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1002 colorValue->Get(color);
1006 void TextField::OnSceneConnect(Dali::Actor actor)
1010 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1014 mHasBeenStaged = true;
1018 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1020 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1021 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1024 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1029 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1035 void TextField::EnableClipping()
1039 // Creates an extra control to be used as stencil buffer.
1040 mStencil = Control::New();
1041 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1042 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1044 // Creates a background visual. Even if the color is transparent it updates the stencil.
1045 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1046 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1048 // Enable the clipping property.
1049 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1050 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1052 Self().Add(mStencil);
1056 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1058 mController->PasteClipboardItemEvent();
1061 void TextField::KeyboardStatusChanged(bool keyboardShown)
1063 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1065 // Just hide the grab handle when keyboard is hidden.
1068 mController->KeyboardFocusLostEvent();
1072 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1076 void TextField::OnSceneConnection(int depth)
1078 // Sets the depth to the visuals inside the text's decorator.
1079 mDecorator->SetTextDepth(depth);
1081 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1083 // Call the Control::OnSceneConnection() to set the depth of the background.
1084 Control::OnSceneConnection(depth);
1087 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1092 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1094 mController->ChangedLayoutDirection();
1097 void TextField::OnIdleSignal()
1099 // Emits the change of input style signals.
1100 mController->ProcessInputStyleChangedSignals();
1102 // Set the pointer to null as the callback manager deletes the callback after execute it.
1103 mIdleCallback = NULL;
1106 TextField::TextField()
1107 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1108 mIdleCallback(NULL),
1109 mAlignmentOffset(0.f),
1110 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1111 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1112 mHasBeenStaged(false),
1113 mTextChanged(false),
1114 mCursorPositionChanged(false),
1115 mSelectionChanged(false),
1116 mSelectionCleared(false),
1118 mOldSelectionStart(0u),
1119 mOldSelectionEnd(0u)
1123 TextField::~TextField()
1125 UnparentAndReset(mStencil);
1127 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1129 Adaptor::Get().RemoveIdle(mIdleCallback);
1133 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1135 return mController->GetTextSize(startIndex, endIndex);
1138 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1140 return mController->GetTextPosition(startIndex, endIndex);
1143 std::string TextField::AccessibleImpl::GetName()
1145 auto self = Toolkit::TextField::DownCast(Self());
1146 if(IsHiddenInput(self))
1151 return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1154 std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset)
1156 if(endOffset <= startOffset)
1161 auto self = Toolkit::TextField::DownCast(Self());
1162 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1164 if(startOffset > text.size() || endOffset > text.size())
1168 if(IsHiddenInput(self))
1170 return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
1172 return text.substr(startOffset, endOffset - startOffset);
1175 size_t TextField::AccessibleImpl::GetCharacterCount()
1177 auto self = Toolkit::TextField::DownCast(Self());
1178 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1183 size_t TextField::AccessibleImpl::GetCursorOffset()
1185 auto self = Toolkit::TextField::DownCast(Self());
1186 return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
1189 bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
1191 auto self = Toolkit::TextField::DownCast(Self());
1192 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1193 if(offset > text.size())
1198 auto& selfImpl = Dali::Toolkit::GetImpl(self);
1199 selfImpl.GetTextController()->ResetCursorPosition(offset);
1200 selfImpl.RequestTextRelayout();
1205 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1206 size_t offset, Dali::Accessibility::TextBoundary boundary)
1208 auto self = Toolkit::TextField::DownCast(Self());
1209 auto range = Dali::Accessibility::Range{};
1211 if(IsHiddenInput(self))
1213 // Returning empty object, as there is no possibility to parse the textfield
1214 // when its content is hidden.
1218 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1219 auto textSize = text.size();
1223 case Dali::Accessibility::TextBoundary::CHARACTER:
1225 if(offset < textSize)
1227 range.content = text[offset];
1228 range.startOffset = offset;
1229 range.endOffset = offset + 1;
1233 case Dali::Accessibility::TextBoundary::WORD:
1234 case Dali::Accessibility::TextBoundary::LINE:
1236 auto textString = text.c_str();
1237 auto breaks = std::vector<char>(textSize, 0);
1239 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1241 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1245 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1250 while(index < textSize && counter <= offset)
1255 while(breaks[index])
1263 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1267 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1273 if((counter > 0) && ((counter - 1) == offset))
1275 range.content = text.substr(start, index - start + 1);
1276 range.startOffset = start;
1277 range.endOffset = index + 1;
1280 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1287 case Dali::Accessibility::TextBoundary::SENTENCE:
1289 /* not supported by default */
1292 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1294 /* Paragraph is not supported by libunibreak library */
1304 Dali::Accessibility::Range TextField::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex)
1306 // Since DALi supports only one selection indexes higher than 0 are ignored
1307 if(selectionIndex > 0)
1312 auto self = Toolkit::TextField::DownCast(Self());
1313 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1314 auto indices = controller->GetSelectionIndexes();
1316 auto startOffset = static_cast<size_t>(indices.first);
1317 auto endOffset = static_cast<size_t>(indices.second);
1319 if(IsHiddenInput(self))
1321 return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
1324 std::string value{};
1325 controller->RetrieveSelection(value);
1326 return {startOffset, endOffset, value};
1329 bool TextField::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1331 // Since DALi supports only one selection indexes higher than 0 are ignored
1332 if(selectionIndex > 0)
1337 auto self = Toolkit::TextField::DownCast(Self());
1338 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1342 bool TextField::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1344 // Since DALi supports only one selection indexes higher than 0 are ignored
1345 if(selectionIndex > 0)
1350 auto self = Toolkit::TextField::DownCast(Self());
1351 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1355 bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1357 if(endPosition <= startPosition)
1362 auto self = Toolkit::TextField::DownCast(Self());
1363 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1364 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1369 bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1371 if(endPosition <= startPosition)
1376 auto self = Toolkit::TextField::DownCast(Self());
1377 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1378 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1380 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1385 bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1387 if(endPosition <= startPosition)
1392 auto self = Toolkit::TextField::DownCast(Self());
1393 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1395 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1400 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
1402 using namespace Dali::Accessibility;
1404 auto states = DevelControl::AccessibleImpl::CalculateStates();
1406 states[State::EDITABLE] = true;
1407 states[State::FOCUSABLE] = true;
1409 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1410 if(mSelf == focusControl)
1412 states[State::FOCUSED] = true;
1418 bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1420 auto self = Toolkit::TextField::DownCast(Self());
1421 auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1423 insertedText.insert(startPosition, text);
1425 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
1430 bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
1432 auto self = Toolkit::TextField::DownCast(Self());
1433 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
1437 int32_t TextField::AccessibleImpl::GetLinkCount() const
1439 auto self = Toolkit::TextField::DownCast(Self());
1440 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1443 Accessibility::Hyperlink* TextField::AccessibleImpl::GetLink(int32_t linkIndex) const
1445 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1449 auto self = Toolkit::TextField::DownCast(Self());
1450 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1451 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1454 int32_t TextField::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1456 auto self = Toolkit::TextField::DownCast(Self());
1457 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1458 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1461 } // namespace Internal
1463 } // namespace Toolkit