2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/key-devel.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/key.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/object/type-registry-helper.h>
34 #include <dali-toolkit/devel-api/controls/control-devel.h>
35 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/text/rendering-backend.h>
38 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
39 #include <dali-toolkit/internal/controls/text-controls/text-field-property-handler.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/public-api/text/text-enumerations.h>
47 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
48 #include <dali-toolkit/public-api/visuals/visual-properties.h>
49 #include <dali/integration-api/adaptor-framework/adaptor.h>
51 using namespace Dali::Toolkit::Text;
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextFieldLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
63 namespace // unnamed namespace
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
66 } // unnamed namespace
73 return Toolkit::TextField::New();
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
80 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "text", STRING, TEXT )
81 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
82 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
83 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
84 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
85 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "underline", MAP, UNDERLINE )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "emboss", MAP, EMBOSS )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
129 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
130 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
134 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFilter", MAP, INPUT_FILTER )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "strikethrough", MAP, STRIKETHROUGH )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
148 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
149 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered", SIGNAL_INPUT_FILTERED )
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
155 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
156 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionStarted", SIGNAL_SELECTION_STARTED )
158 DALI_TYPE_REGISTRATION_END()
161 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
163 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
165 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
167 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
169 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
171 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
173 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
175 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
177 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
179 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
181 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
183 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
185 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
187 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
189 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
191 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
193 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
195 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
197 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
199 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
201 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
203 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
205 return fieldInputStyleMask;
208 bool IsHiddenInput(Toolkit::TextField textField)
210 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
211 auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
212 if(mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
219 char GetSubstituteCharacter(Toolkit::TextField textField)
221 Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
222 auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
225 return static_cast<char>(substChar->Get<int>());
232 Toolkit::TextField TextField::New()
234 // Create the implementation, temporarily owned by this handle on stack
235 IntrusivePtr<TextField> impl = new TextField();
237 // Pass ownership to CustomActor handle
238 Toolkit::TextField handle(*impl);
240 // Second-phase init of the implementation
241 // This can only be done after the CustomActor connection has been made...
247 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
249 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
251 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
255 PropertyHandler::SetProperty(textField, index, value);
259 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
261 Property::Value value;
263 Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
267 value = PropertyHandler::GetProperty(textField, index);
273 void TextField::SelectWholeText()
275 if(mController && mController->IsShowingRealText())
277 mController->SelectWholeText();
282 void TextField::SelectNone()
284 if(mController && mController->IsShowingRealText())
286 mController->SelectNone();
290 void TextField::SelectText(const uint32_t start, const uint32_t end)
292 if(mController && mController->IsShowingRealText())
294 mController->SelectText(start, end);
299 string TextField::GetSelectedText() const
301 string selectedText = "";
302 if(mController && mController->IsShowingRealText())
304 selectedText = mController->GetSelectedText();
309 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
311 if(mController && mController->IsShowingRealText())
313 mController->SetTextSelectionRange(start, end);
318 Uint32Pair TextField::GetTextSelectionRange() const
321 if(mController && mController->IsShowingRealText())
323 range = mController->GetTextSelectionRange();
328 string TextField::CopyText()
330 string copiedText = "";
331 if(mController && mController->IsShowingRealText())
333 copiedText = mController->CopyText();
338 string TextField::CutText()
341 if(mController && mController->IsShowingRealText())
343 cutText = mController->CutText();
348 void TextField::PasteText()
352 SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
353 mController->PasteText();
357 InputMethodContext TextField::GetInputMethodContext()
359 return mInputMethodContext;
362 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
364 Dali::BaseHandle handle(object);
366 bool connected(true);
367 Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
369 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
371 field.TextChangedSignal().Connect(tracker, functor);
373 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
375 field.MaxLengthReachedSignal().Connect(tracker, functor);
377 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
379 field.InputStyleChangedSignal().Connect(tracker, functor);
381 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
385 Internal::TextField& fieldImpl(GetImpl(field));
386 fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
389 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
393 Internal::TextField& fieldImpl(GetImpl(field));
394 fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
397 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
401 Internal::TextField& fieldImpl(GetImpl(field));
402 fieldImpl.InputFilteredSignal().Connect(tracker, functor);
405 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
409 Internal::TextField& fieldImpl(GetImpl(field));
410 fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
413 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
417 Internal::TextField& fieldImpl(GetImpl(field));
418 fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
421 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
425 Internal::TextField& fieldImpl(GetImpl(field));
426 fieldImpl.SelectionStartedSignal().Connect(tracker, functor);
431 // signalName does not match any signal
438 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
440 return mTextChangedSignal;
443 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
445 return mMaxLengthReachedSignal;
448 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
450 return mInputStyleChangedSignal;
453 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
455 return mAnchorClickedSignal;
458 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
460 return mCursorPositionChangedSignal;
463 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
465 return mInputFilteredSignal;
468 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
470 return mSelectionChangedSignal;
473 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
475 return mSelectionClearedSignal;
478 DevelTextField::SelectionStartedSignalType& TextField::SelectionStartedSignal()
480 return mSelectionStartedSignal;
483 void TextField::OnAccessibilityStatusChanged()
485 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
488 void TextField::OnInitialize()
492 mController = Text::Controller::New(this, this, this, this);
494 // When using the vector-based rendering, the size of the GLyphs are different
495 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
496 mController->SetGlyphType(glyphType);
498 mDecorator = Text::Decorator::New(*mController,
501 mInputMethodContext = InputMethodContext::New(self);
503 mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
505 // Enables the text input.
506 mController->EnableTextInput(mDecorator, mInputMethodContext);
508 // Enables the horizontal scrolling after the text input has been enabled.
509 mController->SetHorizontalScrollEnabled(true);
511 // Disables the vertical scrolling.
512 mController->SetVerticalScrollEnabled(false);
514 // Disable the smooth handle panning.
515 mController->SetSmoothHandlePanEnabled(false);
517 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
518 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
520 // Sets layoutDirection value
521 Dali::Stage stage = Dali::Stage::GetCurrent();
522 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
523 mController->SetLayoutDirection(layoutDirection);
525 self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
527 // Forward input events to controller
528 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
529 GetTapGestureDetector().SetMaximumTapsRequired(2);
530 GetTapGestureDetector().ReceiveAllTapEvents(true);
532 self.TouchedSignal().Connect(this, &TextField::OnTouched);
534 // Set BoundingBox to stage size if not already set.
535 Rect<int> boundingBox;
536 mDecorator->GetBoundingBox(boundingBox);
538 if(boundingBox.IsEmpty())
540 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
541 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
544 // Flip vertically the 'left' selection handle
545 mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
547 // Fill-parent area by default
548 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
549 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
550 self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
552 //Enable highightability
553 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
555 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
557 if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
562 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
563 return std::unique_ptr<Dali::Accessibility::Accessible>(
564 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
567 Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
568 Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
571 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
573 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
577 case StyleChange::DEFAULT_FONT_CHANGE:
579 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
580 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
581 // Property system did not set the font so should update it.
582 mController->UpdateAfterFontChange(newFont);
587 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
589 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
593 case StyleChange::THEME_CHANGE:
595 // Nothing to do, let control base class handle this
600 // Up call to Control
601 Control::OnStyleChange(styleManager, change);
604 Vector3 TextField::GetNaturalSize()
607 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
609 Vector3 naturalSize = mController->GetNaturalSize();
610 naturalSize.width += (padding.start + padding.end);
611 naturalSize.height += (padding.top + padding.bottom);
616 float TextField::GetHeightForWidth(float width)
619 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
620 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
623 void TextField::ResizeActor(Actor& actor, const Vector2& size)
625 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
627 actor.SetProperty(Actor::Property::SIZE, size);
631 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
633 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
638 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
640 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
642 // Support Right-To-Left of padding
643 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
645 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
647 std::swap(padding.start, padding.end);
652 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
653 ResizeActor(mStencil, contentSize);
657 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
658 ResizeActor(mActiveLayer, contentSize);
661 // If there is text changed, callback is called.
664 EmitTextChangedSignal();
667 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
669 if((Text::Controller::NONE_UPDATED != updateTextType) ||
672 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
675 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
677 mDecorator->Relayout(contentSize);
682 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
685 RenderText(updateTextType);
688 if(mCursorPositionChanged)
690 EmitCursorPositionChangedSignal();
693 if(mSelectionStarted)
695 EmitSelectionStartedSignal();
698 if(mSelectionChanged)
700 EmitSelectionChangedSignal();
703 if(mSelectionCleared)
705 EmitSelectionClearedSignal();
708 // The text-field emits signals when the input style changes. These changes of style are
709 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
710 // can't be emitted during the size negotiation as the callbacks may update the UI.
711 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
712 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
714 if(Adaptor::IsAvailable())
716 Adaptor& adaptor = Adaptor::Get();
718 if(NULL == mIdleCallback)
720 // @note: The callback manager takes the ownership of the callback object.
721 mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
722 adaptor.AddIdle(mIdleCallback, false);
728 Text::ControllerPtr TextField::GetTextController()
733 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
735 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
738 void TextField::OnKeyInputFocusGained()
740 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
741 if(mInputMethodContext && IsEditable())
743 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
744 mInputMethodContext.ApplyOptions(mInputMethodOptions);
745 mInputMethodContext.NotifyTextInputMultiLine(false);
747 mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
749 mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
751 // Notify that the text editing start.
752 mInputMethodContext.Activate();
754 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
755 mInputMethodContext.SetRestoreAfterFocusLost(true);
757 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
761 notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
764 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
766 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
769 void TextField::OnKeyInputFocusLost()
771 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
772 if(mInputMethodContext)
774 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
775 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
776 mInputMethodContext.SetRestoreAfterFocusLost(false);
778 // Notify that the text editing finish.
779 mInputMethodContext.Deactivate();
781 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
783 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
787 notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
790 mController->KeyboardFocusLostEvent();
792 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
795 bool TextField::OnAccessibilityActivated()
801 void TextField::OnTap(const TapGesture& gesture)
803 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
804 if(mInputMethodContext && IsEditable())
806 mInputMethodContext.Activate();
808 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
810 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
811 const Vector2& localPoint = gesture.GetLocalPoint();
812 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
813 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
818 void TextField::OnPan(const PanGesture& gesture)
820 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
823 void TextField::OnLongPress(const LongPressGesture& gesture)
825 if(mInputMethodContext && IsEditable())
827 mInputMethodContext.Activate();
830 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
831 const Vector2& localPoint = gesture.GetLocalPoint();
832 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
837 bool TextField::OnKeyEvent(const KeyEvent& event)
839 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
841 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
843 // Make sure ClearKeyInputFocus when only key is up
844 if(event.GetState() == KeyEvent::UP)
846 ClearKeyInputFocus();
851 else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
853 // Do nothing when enter is comming.
857 return mController->KeyEvent(event);
860 void TextField::RequestTextRelayout()
865 bool TextField::IsEditable() const
867 return mController->IsEditable();
870 void TextField::SetEditable(bool editable)
872 mController->SetEditable(editable);
873 if(mInputMethodContext && !editable)
875 mInputMethodContext.Deactivate();
879 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
881 if(Accessibility::IsUp())
883 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
887 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
889 if(Accessibility::IsUp())
891 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
895 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
897 if(Accessibility::IsUp())
899 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
902 if((oldPosition != newPosition) && !mCursorPositionChanged)
904 mCursorPositionChanged = true;
905 mOldPosition = oldPosition;
909 void TextField::TextChanged(bool immediate)
911 if(immediate) // Emits TextChangedSignal immediately
913 EmitTextChangedSignal();
921 void TextField::EmitTextChangedSignal()
923 Dali::Toolkit::TextField handle(GetOwner());
924 mTextChangedSignal.Emit(handle);
925 mTextChanged = false;
928 void TextField::MaxLengthReached()
930 Dali::Toolkit::TextField handle(GetOwner());
931 mMaxLengthReachedSignal.Emit(handle);
934 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
936 Dali::Toolkit::TextField handle(GetOwner());
937 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
940 void TextField::AnchorClicked(const std::string& href)
942 Dali::Toolkit::TextField handle(GetOwner());
943 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
946 void TextField::EmitCursorPositionChangedSignal()
948 Dali::Toolkit::TextField handle(GetOwner());
949 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
950 mCursorPositionChanged = false;
953 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
955 Dali::Toolkit::TextField handle(GetOwner());
956 mInputFilteredSignal.Emit(handle, type);
959 void TextField::EmitSelectionChangedSignal()
961 Dali::Toolkit::TextField handle(GetOwner());
962 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
963 mSelectionChanged = false;
966 void TextField::EmitSelectionClearedSignal()
968 Dali::Toolkit::TextField handle(GetOwner());
969 mSelectionClearedSignal.Emit(handle);
970 mSelectionCleared = false;
973 void TextField::EmitSelectionStartedSignal()
975 Dali::Toolkit::TextField handle(GetOwner());
976 mSelectionStartedSignal.Emit(handle);
977 mSelectionStarted = false;
980 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
982 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
984 if(newStart == newEnd)
986 mSelectionCleared = true;
990 if(oldStart == oldEnd)
992 mSelectionStarted = true;
996 mSelectionChanged = true;
997 mOldSelectionStart = oldStart;
998 mOldSelectionEnd = oldEnd;
1000 if(mOldSelectionStart > mOldSelectionEnd)
1003 uint32_t temp = mOldSelectionStart;
1004 mOldSelectionStart = mOldSelectionEnd;
1005 mOldSelectionEnd = temp;
1010 void TextField::AddDecoration(Actor& actor, bool needsClipping)
1016 mClippingDecorationActors.push_back(actor);
1020 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1021 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1023 mActiveLayer = actor;
1028 void TextField::GetControlBackgroundColor(Vector4& color) const
1030 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1031 Property::Map* resultMap = propValue.GetMap();
1033 Property::Value* colorValue = nullptr;
1034 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1036 colorValue->Get(color);
1040 void TextField::OnSceneConnect(Dali::Actor actor)
1044 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1048 mHasBeenStaged = true;
1052 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1054 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1055 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1058 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1063 map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1069 void TextField::EnableClipping()
1073 // Creates an extra control to be used as stencil buffer.
1074 mStencil = Control::New();
1075 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1076 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1078 // Creates a background visual. Even if the color is transparent it updates the stencil.
1079 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1080 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1082 // Enable the clipping property.
1083 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1084 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1086 Self().Add(mStencil);
1090 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1092 mController->PasteClipboardItemEvent();
1095 void TextField::KeyboardStatusChanged(bool keyboardShown)
1097 DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1099 // Just hide the grab handle when keyboard is hidden.
1102 mController->KeyboardFocusLostEvent();
1106 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1110 void TextField::OnSceneConnection(int depth)
1112 // Sets the depth to the visuals inside the text's decorator.
1113 mDecorator->SetTextDepth(depth);
1115 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1117 // Call the Control::OnSceneConnection() to set the depth of the background.
1118 Control::OnSceneConnection(depth);
1121 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1126 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1128 mController->ChangedLayoutDirection();
1131 void TextField::OnIdleSignal()
1133 // Emits the change of input style signals.
1134 mController->ProcessInputStyleChangedSignals();
1136 // Set the pointer to null as the callback manager deletes the callback after execute it.
1137 mIdleCallback = NULL;
1140 TextField::TextField()
1141 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1142 mIdleCallback(NULL),
1143 mAlignmentOffset(0.f),
1144 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1145 mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1146 mHasBeenStaged(false),
1147 mTextChanged(false),
1148 mCursorPositionChanged(false),
1149 mSelectionChanged(false),
1150 mSelectionCleared(false),
1152 mOldSelectionStart(0u),
1153 mOldSelectionEnd(0u),
1154 mSelectionStarted(false)
1158 TextField::~TextField()
1160 UnparentAndReset(mStencil);
1162 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1164 Adaptor::Get().RemoveIdle(mIdleCallback);
1168 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1170 return mController->GetTextSize(startIndex, endIndex);
1173 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1175 return mController->GetTextPosition(startIndex, endIndex);
1178 std::string TextField::AccessibleImpl::GetName() const
1180 auto self = Toolkit::TextField::DownCast(Self());
1181 if(IsHiddenInput(self))
1186 return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1189 std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1191 if(endOffset <= startOffset)
1196 auto self = Toolkit::TextField::DownCast(Self());
1197 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1199 if(startOffset > text.size() || endOffset > text.size())
1203 if(IsHiddenInput(self))
1205 return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
1207 return text.substr(startOffset, endOffset - startOffset);
1210 size_t TextField::AccessibleImpl::GetCharacterCount() const
1212 auto self = Toolkit::TextField::DownCast(Self());
1213 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1218 size_t TextField::AccessibleImpl::GetCursorOffset() const
1220 auto self = Toolkit::TextField::DownCast(Self());
1221 return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
1224 bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
1226 auto self = Toolkit::TextField::DownCast(Self());
1227 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1228 if(offset > text.size())
1233 auto& selfImpl = Dali::Toolkit::GetImpl(self);
1234 selfImpl.GetTextController()->ResetCursorPosition(offset);
1235 selfImpl.RequestTextRelayout();
1240 Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
1241 size_t offset, Dali::Accessibility::TextBoundary boundary) const
1243 auto self = Toolkit::TextField::DownCast(Self());
1244 auto range = Dali::Accessibility::Range{};
1246 if(IsHiddenInput(self))
1248 // Returning empty object, as there is no possibility to parse the textfield
1249 // when its content is hidden.
1253 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1254 auto textSize = text.size();
1258 case Dali::Accessibility::TextBoundary::CHARACTER:
1260 if(offset < textSize)
1262 range.content = text[offset];
1263 range.startOffset = offset;
1264 range.endOffset = offset + 1;
1268 case Dali::Accessibility::TextBoundary::WORD:
1269 case Dali::Accessibility::TextBoundary::LINE:
1271 auto textString = text.c_str();
1272 auto breaks = std::vector<char>(textSize, 0);
1274 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1276 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1280 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1285 while(index < textSize && counter <= offset)
1290 while(breaks[index])
1298 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1302 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1308 if((counter > 0) && ((counter - 1) == offset))
1310 range.content = text.substr(start, index - start + 1);
1311 range.startOffset = start;
1312 range.endOffset = index + 1;
1315 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1322 case Dali::Accessibility::TextBoundary::SENTENCE:
1324 /* not supported by default */
1327 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1329 /* Paragraph is not supported by libunibreak library */
1339 Dali::Accessibility::Range TextField::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1341 // Since DALi supports only one selection indexes higher than 0 are ignored
1342 if(selectionIndex > 0)
1347 auto self = Toolkit::TextField::DownCast(Self());
1348 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1349 auto indices = controller->GetSelectionIndexes();
1351 auto startOffset = static_cast<size_t>(indices.first);
1352 auto endOffset = static_cast<size_t>(indices.second);
1354 if(IsHiddenInput(self))
1356 return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
1359 std::string value{};
1360 controller->RetrieveSelection(value);
1361 return {startOffset, endOffset, value};
1364 bool TextField::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1366 // Since DALi supports only one selection indexes higher than 0 are ignored
1367 if(selectionIndex > 0)
1372 auto self = Toolkit::TextField::DownCast(Self());
1373 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1377 bool TextField::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1379 // Since DALi supports only one selection indexes higher than 0 are ignored
1380 if(selectionIndex > 0)
1385 auto self = Toolkit::TextField::DownCast(Self());
1386 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1390 bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1392 if(endPosition <= startPosition)
1397 auto self = Toolkit::TextField::DownCast(Self());
1398 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1399 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1404 bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1406 if(endPosition <= startPosition)
1411 auto self = Toolkit::TextField::DownCast(Self());
1412 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1413 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1415 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1420 bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1422 if(endPosition <= startPosition)
1427 auto self = Toolkit::TextField::DownCast(Self());
1428 auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1430 self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1435 Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates()
1437 using namespace Dali::Accessibility;
1439 auto states = DevelControl::ControlAccessible::CalculateStates();
1441 states[State::EDITABLE] = true;
1442 states[State::FOCUSABLE] = true;
1444 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1445 if(Self() == focusControl)
1447 states[State::FOCUSED] = true;
1453 bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1455 auto self = Toolkit::TextField::DownCast(Self());
1456 auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
1458 insertedText.insert(startPosition, text);
1460 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
1465 bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
1467 auto self = Toolkit::TextField::DownCast(Self());
1468 self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
1472 int32_t TextField::AccessibleImpl::GetLinkCount() const
1474 auto self = Toolkit::TextField::DownCast(Self());
1475 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1478 Accessibility::Hyperlink* TextField::AccessibleImpl::GetLink(int32_t linkIndex) const
1480 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1484 auto self = Toolkit::TextField::DownCast(Self());
1485 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1486 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1489 int32_t TextField::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1491 auto self = Toolkit::TextField::DownCast(Self());
1492 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1493 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1496 } // namespace Internal
1498 } // namespace Toolkit