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 )
146 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
147 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
148 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered", SIGNAL_INPUT_FILTERED )
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
155 DALI_TYPE_REGISTRATION_END()
158 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
160 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
162 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
164 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
166 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
168 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
170 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
172 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
174 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
176 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
178 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
180 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
182 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
184 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
186 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
188 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
190 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
192 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
194 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
196 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
198 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
200 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
202 return fieldInputStyleMask;
205 bool IsHiddenInput(Toolkit::TextField textField)
207 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
208 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
209 if(mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
216 char GetSubstituteCharacter(Toolkit::TextField textField)
218 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
219 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
222 return static_cast<char>(substChar->Get<int>());
229 Toolkit::TextField TextField::New()
231 // Create the implementation, temporarily owned by this handle on stack
232 IntrusivePtr<TextField> impl = new TextField();
234 // Pass ownership to CustomActor handle
235 Toolkit::TextField handle(*impl);
237 // Second-phase init of the implementation
238 // This can only be done after the CustomActor connection has been made...
244 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
246 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
248 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
252 PropertyHandler::SetProperty(textField, index, value);
256 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
258 Property::Value value;
260 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
264 value = PropertyHandler::GetProperty(textField, index);
270 void TextField::SelectWholeText()
272 if(mController && mController->IsShowingRealText())
274 mController->SelectWholeText();
279 void TextField::SelectNone()
281 if(mController && mController->IsShowingRealText())
283 mController->SelectNone();
287 void TextField::SelectText(const uint32_t start, const uint32_t end)
289 if(mController && mController->IsShowingRealText())
291 mController->SelectText(start, end);
296 string TextField::GetSelectedText() const
298 string selectedText = "";
299 if(mController && mController->IsShowingRealText())
301 selectedText = mController->GetSelectedText();
306 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
308 if(mController && mController->IsShowingRealText())
310 mController->SetTextSelectionRange(start, end);
315 Uint32Pair TextField::GetTextSelectionRange() const
318 if(mController && mController->IsShowingRealText())
320 range = mController->GetTextSelectionRange();
325 string TextField::CopyText()
327 string copiedText = "";
328 if(mController && mController->IsShowingRealText())
330 copiedText = mController->CopyText();
335 string TextField::CutText()
338 if(mController && mController->IsShowingRealText())
340 cutText = mController->CutText();
345 void TextField::PasteText()
349 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
350 mController->PasteText();
354 InputMethodContext TextField::GetInputMethodContext()
356 return mInputMethodContext;
359 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
361 Dali::BaseHandle handle(object);
363 bool connected(true);
364 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
366 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
368 field.TextChangedSignal().Connect(tracker, functor);
370 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
372 field.MaxLengthReachedSignal().Connect(tracker, functor);
374 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
376 field.InputStyleChangedSignal().Connect(tracker, functor);
378 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
382 Internal::TextField& fieldImpl(GetImpl(field));
383 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
386 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
390 Internal::TextField& fieldImpl(GetImpl(field));
391 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
394 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
398 Internal::TextField& fieldImpl(GetImpl(field));
399 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
402 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
406 Internal::TextField& fieldImpl(GetImpl(field));
407 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
410 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
414 Internal::TextField& fieldImpl(GetImpl(field));
415 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
420 // signalName does not match any signal
427 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
429 return mTextChangedSignal;
432 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
434 return mMaxLengthReachedSignal;
437 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
439 return mInputStyleChangedSignal;
442 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
444 return mAnchorClickedSignal;
447 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
449 return mCursorPositionChangedSignal;
452 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
454 return mInputFilteredSignal;
457 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
459 return mSelectionChangedSignal;
462 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
464 return mSelectionClearedSignal;
467 void TextField::OnAccessibilityStatusChanged()
469 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
472 void TextField::OnInitialize()
476 mController = Text::Controller::New(this, this, this, this);
478 // When using the vector-based rendering, the size of the GLyphs are different
479 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
480 mController->SetGlyphType(glyphType);
482 mDecorator = Text::Decorator::New(*mController,
485 mInputMethodContext = InputMethodContext::New(self);
487 mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
489 // Enables the text input.
490 mController->EnableTextInput(mDecorator, mInputMethodContext);
492 // Enables the horizontal scrolling after the text input has been enabled.
493 mController->SetHorizontalScrollEnabled(true);
495 // Disables the vertical scrolling.
496 mController->SetVerticalScrollEnabled(false);
498 // Disable the smooth handle panning.
499 mController->SetSmoothHandlePanEnabled(false);
501 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
502 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
504 // Sets layoutDirection value
505 Dali::Stage stage = Dali::Stage::GetCurrent();
506 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
507 mController->SetLayoutDirection(layoutDirection);
509 self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
511 // Forward input events to controller
512 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
513 GetTapGestureDetector().SetMaximumTapsRequired(2);
514 GetTapGestureDetector().ReceiveAllTapEvents(true);
516 self.TouchedSignal().Connect(this, &TextField::OnTouched);
518 // Set BoundingBox to stage size if not already set.
519 Rect<int> boundingBox;
520 mDecorator->GetBoundingBox(boundingBox);
522 if(boundingBox.IsEmpty())
524 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
525 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
528 // Flip vertically the 'left' selection handle
529 mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
531 // Fill-parent area by default
532 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
533 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
534 self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
536 //Enable highightability
537 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
539 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
541 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
546 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
547 return std::unique_ptr<Dali::Accessibility::Accessible>(
548 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
551 Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
552 Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
555 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
557 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
561 case StyleChange::DEFAULT_FONT_CHANGE:
563 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
564 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
565 // Property system did not set the font so should update it.
566 mController->UpdateAfterFontChange(newFont);
571 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
573 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
577 case StyleChange::THEME_CHANGE:
579 // Nothing to do, let control base class handle this
584 // Up call to Control
585 Control::OnStyleChange(styleManager, change);
588 Vector3 TextField::GetNaturalSize()
591 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
593 Vector3 naturalSize = mController->GetNaturalSize();
594 naturalSize.width += (padding.start + padding.end);
595 naturalSize.height += (padding.top + padding.bottom);
600 float TextField::GetHeightForWidth(float width)
603 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
604 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
607 void TextField::ResizeActor(Actor& actor, const Vector2& size)
609 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
611 actor.SetProperty(Actor::Property::SIZE, size);
615 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
617 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
622 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
624 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
626 // Support Right-To-Left of padding
627 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
629 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
631 std::swap(padding.start, padding.end);
636 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
637 ResizeActor(mStencil, contentSize);
641 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
642 ResizeActor(mActiveLayer, contentSize);
645 // If there is text changed, callback is called.
648 EmitTextChangedSignal();
651 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
653 if((Text::Controller::NONE_UPDATED != updateTextType) ||
656 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
659 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
661 mDecorator->Relayout(contentSize);
666 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
669 RenderText(updateTextType);
672 if(mCursorPositionChanged)
674 EmitCursorPositionChangedSignal();
677 if(mSelectionChanged)
679 EmitSelectionChangedSignal();
682 if(mSelectionCleared)
684 EmitSelectionClearedSignal();
687 // The text-field emits signals when the input style changes. These changes of style are
688 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
689 // can't be emitted during the size negotiation as the callbacks may update the UI.
690 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
691 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
693 if(Adaptor::IsAvailable())
695 Adaptor& adaptor = Adaptor::Get();
697 if(NULL == mIdleCallback)
699 // @note: The callback manager takes the ownership of the callback object.
700 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
701 adaptor.AddIdle(mIdleCallback, false);
707 Text::ControllerPtr TextField::GetTextController()
712 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
714 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
717 void TextField::OnKeyInputFocusGained()
719 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
720 if(mInputMethodContext && IsEditable())
722 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
723 mInputMethodContext.ApplyOptions(mInputMethodOptions);
724 mInputMethodContext.NotifyTextInputMultiLine(false);
726 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
728 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
730 // Notify that the text editing start.
731 mInputMethodContext.Activate();
733 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
734 mInputMethodContext.SetRestoreAfterFocusLost(true);
736 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
740 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
743 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
745 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
748 void TextField::OnKeyInputFocusLost()
750 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
751 if(mInputMethodContext)
753 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
754 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
755 mInputMethodContext.SetRestoreAfterFocusLost(false);
757 // Notify that the text editing finish.
758 mInputMethodContext.Deactivate();
760 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
762 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
766 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
769 mController->KeyboardFocusLostEvent();
771 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
774 bool TextField::OnAccessibilityActivated()
780 void TextField::OnTap(const TapGesture& gesture)
782 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
783 if(mInputMethodContext && IsEditable())
785 mInputMethodContext.Activate();
787 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
789 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
790 const Vector2& localPoint = gesture.GetLocalPoint();
791 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
792 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
797 void TextField::OnPan(const PanGesture& gesture)
799 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
802 void TextField::OnLongPress(const LongPressGesture& gesture)
804 if(mInputMethodContext && IsEditable())
806 mInputMethodContext.Activate();
809 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
810 const Vector2& localPoint = gesture.GetLocalPoint();
811 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
816 bool TextField::OnKeyEvent(const KeyEvent& event)
818 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
820 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
822 // Make sure ClearKeyInputFocus when only key is up
823 if(event.GetState() == KeyEvent::UP)
825 ClearKeyInputFocus();
830 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
832 // Do nothing when enter is comming.
836 return mController->KeyEvent(event);
839 void TextField::RequestTextRelayout()
844 bool TextField::IsEditable() const
846 return mController->IsEditable();
849 void TextField::SetEditable(bool editable)
851 mController->SetEditable(editable);
852 if(mInputMethodContext && !editable)
854 mInputMethodContext.Deactivate();
858 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
860 if(Accessibility::IsUp())
862 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
866 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
868 if(Accessibility::IsUp())
870 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
874 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
876 if(Accessibility::IsUp())
878 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
881 if((oldPosition != newPosition) && !mCursorPositionChanged)
883 mCursorPositionChanged = true;
884 mOldPosition = oldPosition;
888 void TextField::TextChanged(bool immediate)
890 if(immediate) // Emits TextChangedSignal immediately
892 EmitTextChangedSignal();
900 void TextField::EmitTextChangedSignal()
902 Dali::Toolkit::TextField handle(GetOwner());
903 mTextChangedSignal.Emit(handle);
904 mTextChanged = false;
907 void TextField::MaxLengthReached()
909 Dali::Toolkit::TextField handle(GetOwner());
910 mMaxLengthReachedSignal.Emit(handle);
913 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
915 Dali::Toolkit::TextField handle(GetOwner());
916 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
919 void TextField::AnchorClicked(const std::string& href)
921 Dali::Toolkit::TextField handle(GetOwner());
922 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
925 void TextField::EmitCursorPositionChangedSignal()
927 Dali::Toolkit::TextField handle(GetOwner());
928 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
929 mCursorPositionChanged = false;
932 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
934 Dali::Toolkit::TextField handle(GetOwner());
935 mInputFilteredSignal.Emit(handle, type);
938 void TextField::EmitSelectionChangedSignal()
940 Dali::Toolkit::TextField handle(GetOwner());
941 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
942 mSelectionChanged = false;
945 void TextField::EmitSelectionClearedSignal()
947 Dali::Toolkit::TextField handle(GetOwner());
948 mSelectionClearedSignal.Emit(handle);
949 mSelectionCleared = false;
952 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
954 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
956 if(newStart == newEnd)
958 mSelectionCleared = true;
961 mSelectionChanged = true;
962 mOldSelectionStart = oldStart;
963 mOldSelectionEnd = oldEnd;
965 if(mOldSelectionStart > mOldSelectionEnd)
968 uint32_t temp = mOldSelectionStart;
969 mOldSelectionStart = mOldSelectionEnd;
970 mOldSelectionEnd = temp;
975 void TextField::AddDecoration(Actor& actor, bool needsClipping)
981 mClippingDecorationActors.push_back(actor);
985 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
986 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
988 mActiveLayer = actor;
993 void TextField::GetControlBackgroundColor(Vector4& color) const
995 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
996 Property::Map* resultMap = propValue.GetMap();
998 Property::Value* colorValue = nullptr;
999 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1001 colorValue->Get(color);
1005 void TextField::OnSceneConnect(Dali::Actor actor)
1009 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1013 mHasBeenStaged = true;
1017 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1019 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1020 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1023 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1028 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1034 void TextField::EnableClipping()
1038 // Creates an extra control to be used as stencil buffer.
1039 mStencil = Control::New();
1040 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1041 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1043 // Creates a background visual. Even if the color is transparent it updates the stencil.
1044 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1045 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1047 // Enable the clipping property.
1048 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1049 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1051 Self().Add(mStencil);
1055 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1057 mController->PasteClipboardItemEvent();
1060 void TextField::KeyboardStatusChanged(bool keyboardShown)
1062 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1064 // Just hide the grab handle when keyboard is hidden.
1067 mController->KeyboardFocusLostEvent();
1071 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1075 void TextField::OnSceneConnection(int depth)
1077 // Sets the depth to the visuals inside the text's decorator.
1078 mDecorator->SetTextDepth(depth);
1080 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1082 // Call the Control::OnSceneConnection() to set the depth of the background.
1083 Control::OnSceneConnection(depth);
1086 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1091 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1093 mController->ChangedLayoutDirection();
1096 void TextField::OnIdleSignal()
1098 // Emits the change of input style signals.
1099 mController->ProcessInputStyleChangedSignals();
1101 // Set the pointer to null as the callback manager deletes the callback after execute it.
1102 mIdleCallback = NULL;
1105 TextField::TextField()
1106 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1107 mIdleCallback(NULL),
1108 mAlignmentOffset(0.f),
1109 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1110 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1111 mHasBeenStaged(false),
1112 mTextChanged(false),
1113 mCursorPositionChanged(false),
1114 mSelectionChanged(false),
1115 mSelectionCleared(false),
1117 mOldSelectionStart(0u),
1118 mOldSelectionEnd(0u)
1122 TextField::~TextField()
1124 UnparentAndReset(mStencil);
1126 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1128 Adaptor::Get().RemoveIdle(mIdleCallback);
1132 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1134 return mController->GetTextSize(startIndex, endIndex);
1137 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1139 return mController->GetTextPosition(startIndex, endIndex);
1142 std::string TextField::AccessibleImpl::GetName() const
1144 auto self = Toolkit::TextField::DownCast(Self());
1145 if(IsHiddenInput(self))
1150 return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1153 std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1155 if(endOffset <= startOffset)
1160 auto self = Toolkit::TextField::DownCast(Self());
1161 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1163 if(startOffset > text.size() || endOffset > text.size())
1167 if(IsHiddenInput(self))
1169 return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
1171 return text.substr(startOffset, endOffset - startOffset);
1174 size_t TextField::AccessibleImpl::GetCharacterCount() const
1176 auto self = Toolkit::TextField::DownCast(Self());
1177 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1182 size_t TextField::AccessibleImpl::GetCursorOffset() const
1184 auto self = Toolkit::TextField::DownCast(Self());
1185 return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
1188 bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
1190 auto self = Toolkit::TextField::DownCast(Self());
1191 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1192 if(offset > text.size())
1197 auto& selfImpl = Dali::Toolkit::GetImpl(self);
1198 selfImpl.GetTextController()->ResetCursorPosition(offset);
1199 selfImpl.RequestTextRelayout();
1204 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1205 size_t offset, Dali::Accessibility::TextBoundary boundary) const
1207 auto self = Toolkit::TextField::DownCast(Self());
1208 auto range = Dali::Accessibility::Range{};
1210 if(IsHiddenInput(self))
1212 // Returning empty object, as there is no possibility to parse the textfield
1213 // when its content is hidden.
1217 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1218 auto textSize = text.size();
1222 case Dali::Accessibility::TextBoundary::CHARACTER:
1224 if(offset < textSize)
1226 range.content = text[offset];
1227 range.startOffset = offset;
1228 range.endOffset = offset + 1;
1232 case Dali::Accessibility::TextBoundary::WORD:
1233 case Dali::Accessibility::TextBoundary::LINE:
1235 auto textString = text.c_str();
1236 auto breaks = std::vector<char>(textSize, 0);
1238 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1240 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1244 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1249 while(index < textSize && counter <= offset)
1254 while(breaks[index])
1262 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1266 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1272 if((counter > 0) && ((counter - 1) == offset))
1274 range.content = text.substr(start, index - start + 1);
1275 range.startOffset = start;
1276 range.endOffset = index + 1;
1279 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1286 case Dali::Accessibility::TextBoundary::SENTENCE:
1288 /* not supported by default */
1291 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1293 /* Paragraph is not supported by libunibreak library */
1303 Dali::Accessibility::Range TextField::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1305 // Since DALi supports only one selection indexes higher than 0 are ignored
1306 if(selectionIndex > 0)
1311 auto self = Toolkit::TextField::DownCast(Self());
1312 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1313 auto indices = controller->GetSelectionIndexes();
1315 auto startOffset = static_cast<size_t>(indices.first);
1316 auto endOffset = static_cast<size_t>(indices.second);
1318 if(IsHiddenInput(self))
1320 return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
1323 std::string value{};
1324 controller->RetrieveSelection(value);
1325 return {startOffset, endOffset, value};
1328 bool TextField::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1330 // Since DALi supports only one selection indexes higher than 0 are ignored
1331 if(selectionIndex > 0)
1336 auto self = Toolkit::TextField::DownCast(Self());
1337 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1341 bool TextField::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1343 // Since DALi supports only one selection indexes higher than 0 are ignored
1344 if(selectionIndex > 0)
1349 auto self = Toolkit::TextField::DownCast(Self());
1350 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1354 bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1356 if(endPosition <= startPosition)
1361 auto self = Toolkit::TextField::DownCast(Self());
1362 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1363 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1368 bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1370 if(endPosition <= startPosition)
1375 auto self = Toolkit::TextField::DownCast(Self());
1376 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1377 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1379 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1384 bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1386 if(endPosition <= startPosition)
1391 auto self = Toolkit::TextField::DownCast(Self());
1392 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1394 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1399 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
1401 using namespace Dali::Accessibility;
1403 auto states = DevelControl::ControlAccessible::CalculateStates();
1405 states[State::EDITABLE] = true;
1406 states[State::FOCUSABLE] = true;
1408 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1409 if(Self() == focusControl)
1411 states[State::FOCUSED] = true;
1417 bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1419 auto self = Toolkit::TextField::DownCast(Self());
1420 auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1422 insertedText.insert(startPosition, text);
1424 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
1429 bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
1431 auto self = Toolkit::TextField::DownCast(Self());
1432 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
1436 int32_t TextField::AccessibleImpl::GetLinkCount() const
1438 auto self = Toolkit::TextField::DownCast(Self());
1439 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1442 Accessibility::Hyperlink* TextField::AccessibleImpl::GetLink(int32_t linkIndex) const
1444 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1448 auto self = Toolkit::TextField::DownCast(Self());
1449 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1450 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1453 int32_t TextField::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1455 auto self = Toolkit::TextField::DownCast(Self());
1456 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1457 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1460 } // namespace Internal
1462 } // namespace Toolkit