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-editor-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/object/property-helper-devel.h>
25 #include <dali/integration-api/adaptor-framework/adaptor.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>
35 #include <dali-toolkit/devel-api/controls/control-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/control/control-data-impl.h>
39 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
40 #include <dali-toolkit/internal/controls/text-controls/text-editor-property-handler.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
45 #include <dali-toolkit/internal/text/text-font-style.h>
46 #include <dali-toolkit/internal/text/text-view.h>
47 #include <dali-toolkit/public-api/text/text-enumerations.h>
48 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
49 #include <dali-toolkit/public-api/visuals/visual-properties.h>
51 using namespace Dali::Toolkit::Text;
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextEditorLogFilter = 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 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
67 } // unnamed namespace
71 const char* const SCROLL_BAR_POSITION("sourcePosition");
72 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
73 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
74 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
79 return Toolkit::TextEditor::New();
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextEditor, Toolkit::Control, Create);
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "text", STRING, TEXT )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "underline", MAP, UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "shadow", MAP, SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "emboss", MAP, EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "outline", MAP, OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
130 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE )
131 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT )
132 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION )
133 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER )
134 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalScrollPosition", FLOAT, HORIZONTAL_SCROLL_POSITION )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING )
147 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT )
148 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
149 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
150 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
151 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
152 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
153 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
154 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFilter", MAP, INPUT_FILTER )
155 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsis", BOOLEAN, ELLIPSIS )
156 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
157 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "minLineSize", FLOAT, MIN_LINE_SIZE )
158 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", MAP, STRIKETHROUGH )
159 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
161 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
162 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
163 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
164 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
165 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
167 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
168 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
170 DALI_TYPE_REGISTRATION_END()
173 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
175 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
177 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
179 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
181 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
183 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
185 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
187 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
189 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
191 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
193 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
195 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
197 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
199 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
201 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
203 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
205 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
207 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
209 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
211 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
213 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
215 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
217 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
219 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
221 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
223 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
226 return editorInputStyleMask;
231 Toolkit::TextEditor TextEditor::New()
233 // Create the implementation, temporarily owned by this handle on stack
234 IntrusivePtr<TextEditor> impl = new TextEditor();
236 // Pass ownership to CustomActor handle
237 Toolkit::TextEditor handle(*impl);
239 // Second-phase init of the implementation
240 // This can only be done after the CustomActor connection has been made...
246 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
248 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
250 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
254 PropertyHandler::SetProperty(textEditor, index, value);
258 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
260 Property::Value value;
262 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
266 value = PropertyHandler::GetProperty(textEditor, index);
271 void TextEditor::SelectWholeText()
273 if(mController && mController->IsShowingRealText())
275 mController->SelectWholeText();
280 void TextEditor::SelectNone()
282 if(mController && mController->IsShowingRealText())
284 mController->SelectNone();
288 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
290 if(mController && mController->IsShowingRealText())
292 mController->SelectText(start, end);
297 string TextEditor::CopyText()
299 string copiedText = "";
300 if(mController && mController->IsShowingRealText())
302 copiedText = mController->CopyText();
307 string TextEditor::CutText()
310 if(mController && mController->IsShowingRealText())
312 cutText = mController->CutText();
317 void TextEditor::PasteText()
321 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
322 mController->PasteText();
326 void TextEditor::ScrollBy(Vector2 scroll)
328 if(mController && mController->IsShowingRealText())
330 mController->ScrollBy(scroll);
334 float TextEditor::GetHorizontalScrollPosition()
336 if(mController && mController->IsShowingRealText())
338 return mController->GetHorizontalScrollPosition();
343 float TextEditor::GetVerticalScrollPosition()
345 if(mController && mController->IsShowingRealText())
347 return mController->GetVerticalScrollPosition();
352 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
354 return mController->GetTextSize(startIndex, endIndex);
357 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
359 return mController->GetTextPosition(startIndex, endIndex);
362 string TextEditor::GetSelectedText() const
364 string selectedText = "";
365 if(mController && mController->IsShowingRealText())
367 selectedText = mController->GetSelectedText();
372 InputMethodContext TextEditor::GetInputMethodContext()
374 return mInputMethodContext;
377 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
379 return mMaxLengthReachedSignal;
382 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
384 return mAnchorClickedSignal;
387 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
389 return mCursorPositionChangedSignal;
392 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
394 return mInputFilteredSignal;
397 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
399 return mSelectionChangedSignal;
402 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
404 return mSelectionClearedSignal;
407 Text::ControllerPtr TextEditor::GetTextController()
412 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
414 Dali::BaseHandle handle(object);
416 bool connected(true);
417 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
419 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
421 editor.TextChangedSignal().Connect(tracker, functor);
423 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
425 editor.InputStyleChangedSignal().Connect(tracker, functor);
427 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
431 Internal::TextEditor& editorImpl(GetImpl(editor));
432 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
435 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
439 Internal::TextEditor& editorImpl(GetImpl(editor));
440 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
443 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
447 Internal::TextEditor& editorImpl(GetImpl(editor));
448 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
451 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
455 Internal::TextEditor& editorImpl(GetImpl(editor));
456 editorImpl.InputFilteredSignal().Connect(tracker, functor);
459 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
463 Internal::TextEditor& editorImpl(GetImpl(editor));
464 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
467 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
471 Internal::TextEditor& editorImpl(GetImpl(editor));
472 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
477 // signalName does not match any signal
484 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
486 return mTextChangedSignal;
489 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
491 return mInputStyleChangedSignal;
494 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
496 return mScrollStateChangedSignal;
499 void TextEditor::OnAccessibilityStatusChanged()
501 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
504 void TextEditor::OnInitialize()
508 mController = Text::Controller::New(this, this, this, this);
510 mDecorator = Text::Decorator::New(*mController,
513 mInputMethodContext = InputMethodContext::New(self);
515 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
517 // Enables the text input.
518 mController->EnableTextInput(mDecorator, mInputMethodContext);
520 // Enables the vertical scrolling after the text input has been enabled.
521 mController->SetVerticalScrollEnabled(true);
523 // Disables the horizontal scrolling.
524 mController->SetHorizontalScrollEnabled(false);
526 // Sets the maximum number of characters.
527 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
529 // Enable the smooth handle panning.
530 mController->SetSmoothHandlePanEnabled(true);
532 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
533 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
535 // Sets layoutDirection value
536 Dali::Stage stage = Dali::Stage::GetCurrent();
537 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
538 mController->SetLayoutDirection(layoutDirection);
540 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
542 // Forward input events to controller
543 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
544 GetTapGestureDetector().SetMaximumTapsRequired(2);
545 GetTapGestureDetector().ReceiveAllTapEvents(true);
547 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
549 // Set BoundingBox to stage size if not already set.
550 Rect<int> boundingBox;
551 mDecorator->GetBoundingBox(boundingBox);
553 if(boundingBox.IsEmpty())
555 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
556 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
559 // Whether to flip the selection handles as soon as they cross.
560 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
562 // Set the default scroll speed.
563 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
565 // Fill-parent area by default
566 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
567 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
568 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
570 //Enable highightability
571 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
573 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
575 // Creates an extra control to be used as stencil buffer.
576 mStencil = Control::New();
577 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
578 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
580 // Creates a background visual. Even if the color is transparent it updates the stencil.
581 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
582 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
584 // Enable the clipping property.
585 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
586 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
590 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
591 return std::unique_ptr<Dali::Accessibility::Accessible>(
592 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
595 Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
596 Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
599 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
601 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
605 case StyleChange::DEFAULT_FONT_CHANGE:
607 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
608 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
609 // Property system did not set the font so should update it.
610 mController->UpdateAfterFontChange(newFont);
615 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
617 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
621 case StyleChange::THEME_CHANGE:
623 // Nothing to do, let control base class handle this
628 // Up call to Control
629 Control::OnStyleChange(styleManager, change);
632 Vector3 TextEditor::GetNaturalSize()
635 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
637 Vector3 naturalSize = mController->GetNaturalSize();
638 naturalSize.width += (padding.start + padding.end);
639 naturalSize.height += (padding.top + padding.bottom);
644 float TextEditor::GetHeightForWidth(float width)
647 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
648 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
651 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
653 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
655 actor.SetProperty(Actor::Property::SIZE, size);
659 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
661 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
666 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
668 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
670 // Support Right-To-Left of padding
671 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
673 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
675 std::swap(padding.start, padding.end);
680 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
681 ResizeActor(mStencil, contentSize);
685 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
686 ResizeActor(mActiveLayer, contentSize);
689 // If there is text changed, callback is called.
692 EmitTextChangedSignal();
695 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
697 if((Text::Controller::NONE_UPDATED != updateTextType) ||
700 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
703 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
705 mDecorator->Relayout(contentSize);
710 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
713 RenderText(updateTextType);
716 if(mCursorPositionChanged)
718 EmitCursorPositionChangedSignal();
721 if(mSelectionChanged)
723 EmitSelectionChangedSignal();
726 if(mSelectionCleared)
728 EmitSelectionClearedSignal();
731 // The text-editor emits signals when the input style changes. These changes of style are
732 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
733 // can't be emitted during the size negotiation as the callbacks may update the UI.
734 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
735 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
737 if(Adaptor::IsAvailable())
739 Adaptor& adaptor = Adaptor::Get();
741 if(NULL == mIdleCallback)
743 // @note: The callback manager takes the ownership of the callback object.
744 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
745 adaptor.AddIdle(mIdleCallback, false);
751 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
753 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
756 ApplyScrollPosition();
761 void TextEditor::OnKeyInputFocusGained()
763 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
764 if(mInputMethodContext && IsEditable())
766 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
767 mInputMethodContext.ApplyOptions(mInputMethodOptions);
768 mInputMethodContext.NotifyTextInputMultiLine(true);
770 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
772 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
774 // Notify that the text editing start.
775 mInputMethodContext.Activate();
777 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
778 mInputMethodContext.SetRestoreAfterFocusLost(true);
780 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
784 notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
787 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
789 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
792 void TextEditor::OnKeyInputFocusLost()
794 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
795 if(mInputMethodContext)
797 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
799 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
800 mInputMethodContext.SetRestoreAfterFocusLost(false);
802 // Notify that the text editing finish.
803 mInputMethodContext.Deactivate();
805 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
807 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
811 notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
814 mController->KeyboardFocusLostEvent();
816 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
819 bool TextEditor::OnAccessibilityActivated()
825 void TextEditor::OnTap(const TapGesture& gesture)
827 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
828 if(mInputMethodContext && IsEditable())
830 mInputMethodContext.Activate();
832 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
834 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
835 const Vector2& localPoint = gesture.GetLocalPoint();
836 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
837 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
842 void TextEditor::OnPan(const PanGesture& gesture)
844 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
847 void TextEditor::OnLongPress(const LongPressGesture& gesture)
849 if(mInputMethodContext && IsEditable())
851 mInputMethodContext.Activate();
854 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
855 const Vector2& localPoint = gesture.GetLocalPoint();
856 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
861 bool TextEditor::OnKeyEvent(const KeyEvent& event)
863 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
865 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
867 // Make sure ClearKeyInputFocus when only key is up
868 if(event.GetState() == KeyEvent::UP)
870 ClearKeyInputFocus();
876 return mController->KeyEvent(event);
879 void TextEditor::RequestTextRelayout()
884 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
886 if(Accessibility::IsUp())
888 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
892 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
894 if(Accessibility::IsUp())
896 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
900 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
902 if(Accessibility::IsUp())
904 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
907 if((oldPosition != newPosition) && !mCursorPositionChanged)
909 mCursorPositionChanged = true;
910 mOldPosition = oldPosition;
914 void TextEditor::TextChanged(bool immediate)
916 if(immediate) // Emits TextChangedSignal immediately
918 EmitTextChangedSignal();
926 void TextEditor::EmitTextChangedSignal()
928 Dali::Toolkit::TextEditor handle(GetOwner());
929 mTextChangedSignal.Emit(handle);
930 mTextChanged = false;
933 void TextEditor::MaxLengthReached()
935 Dali::Toolkit::TextEditor handle(GetOwner());
936 mMaxLengthReachedSignal.Emit(handle);
939 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
941 Dali::Toolkit::TextEditor handle(GetOwner());
942 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
945 void TextEditor::AnchorClicked(const std::string& href)
947 Dali::Toolkit::TextEditor handle(GetOwner());
948 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
951 void TextEditor::EmitCursorPositionChangedSignal()
953 Dali::Toolkit::TextEditor handle(GetOwner());
954 mCursorPositionChanged = false;
955 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
958 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
960 Dali::Toolkit::TextEditor handle(GetOwner());
961 mInputFilteredSignal.Emit(handle, type);
964 void TextEditor::EmitSelectionChangedSignal()
966 Dali::Toolkit::TextEditor handle(GetOwner());
967 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
968 mSelectionChanged = false;
971 void TextEditor::EmitSelectionClearedSignal()
973 Dali::Toolkit::TextEditor handle(GetOwner());
974 mSelectionClearedSignal.Emit(handle);
975 mSelectionCleared = false;
978 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
980 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
982 if(newStart == newEnd)
984 mSelectionCleared = true;
987 mSelectionChanged = true;
988 mOldSelectionStart = oldStart;
989 mOldSelectionEnd = oldEnd;
991 if(mOldSelectionStart > mOldSelectionEnd)
994 uint32_t temp = mOldSelectionStart;
995 mOldSelectionStart = mOldSelectionEnd;
996 mOldSelectionEnd = temp;
1001 void TextEditor::AddDecoration(Actor& actor, bool needsClipping)
1007 mClippingDecorationActors.push_back(actor);
1011 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1012 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1014 mActiveLayer = actor;
1019 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1021 if(mController && mController->IsShowingRealText())
1023 mController->SetTextSelectionRange(start, end);
1028 Uint32Pair TextEditor::GetTextSelectionRange() const
1030 Uint32Pair range(0, 0);
1031 if(mController && mController->IsShowingRealText())
1033 range = mController->GetTextSelectionRange();
1038 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1040 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1041 Property::Map* resultMap = propValue.GetMap();
1043 Property::Value* colorValue = nullptr;
1044 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1046 colorValue->Get(color);
1050 void TextEditor::UpdateScrollBar()
1052 using namespace Dali;
1054 float scrollPosition;
1057 bool latestScrolled;
1059 if(!mScrollBarEnabled)
1063 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1064 if(!latestScrolled || controlSize > layoutSize)
1069 CustomActor self = Self();
1072 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1073 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1074 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1075 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1076 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1077 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1079 // Register the scroll position property
1080 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1081 // Register the minimum scroll position property
1082 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1083 // Register the maximum scroll position property
1084 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1085 // Register the scroll content size property
1086 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1088 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1090 // Set style name of ScrollBar for styling
1091 mScrollBar.SetStyleName("TextEditorScrollBar");
1092 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1095 // Set style name of ScrollBarIndicator for styling
1096 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1099 self.Add(mScrollBar);
1103 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1104 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1105 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1107 self.SetProperty(propertyScrollPosition, scrollPosition);
1108 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1109 self.SetProperty(propertyScrollContentSize, layoutSize);
1112 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1115 mScrollStarted = true;
1116 Dali::Toolkit::TextEditor handle(GetOwner());
1117 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1120 Actor indicator = mScrollBar.GetScrollIndicator();
1123 mAnimation.Stop(); // Cancel any animation
1127 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1129 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1130 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1132 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1135 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1137 // If animation is successfully ended, then emit ScrollStateChangedSignal
1138 if(animation.GetCurrentProgress() == 0.0f)
1140 mScrollStarted = false;
1141 Dali::Toolkit::TextEditor handle(GetOwner());
1142 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1146 void TextEditor::OnSceneConnect(Dali::Actor actor)
1150 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1154 mHasBeenStaged = true;
1158 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1160 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1161 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1164 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1169 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1175 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1177 mController->PasteClipboardItemEvent();
1180 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1182 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1184 // Just hide the grab handle when keyboard is hidden.
1187 mController->KeyboardFocusLostEvent();
1191 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1195 void TextEditor::OnSceneConnection(int depth)
1197 // Sets the depth to the visuals inside the text's decorator.
1198 mDecorator->SetTextDepth(depth);
1200 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1202 // Call the Control::OnSceneConnection() to set the depth of the background.
1203 Control::OnSceneConnection(depth);
1206 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1211 void TextEditor::OnIdleSignal()
1213 // Emits the change of input style signals.
1214 mController->ProcessInputStyleChangedSignals();
1216 // Set the pointer to null as the callback manager deletes the callback after execute it.
1217 mIdleCallback = NULL;
1220 void TextEditor::ApplyScrollPosition()
1222 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1223 float scrollAmount = 0.0f;
1225 if(mScrollAnimationEnabled)
1227 scrollAmount = mController->GetScrollAmountByUserInput();
1229 if(mTextVerticalScroller)
1231 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1233 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1235 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1239 mTextVerticalScroller = Text::TextVerticalScroller::New();
1240 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1242 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1244 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1248 bool TextEditor::IsEditable() const
1250 return mController->IsEditable();
1253 void TextEditor::SetEditable(bool editable)
1255 mController->SetEditable(editable);
1256 if(mInputMethodContext && !editable)
1258 mInputMethodContext.Deactivate();
1262 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1264 mController->ChangedLayoutDirection();
1267 TextEditor::TextEditor()
1268 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1269 mAnimationPeriod(0.0f, 0.0f),
1270 mIdleCallback(NULL),
1271 mAlignmentOffset(0.f),
1272 mScrollAnimationDuration(0.f),
1274 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1275 mHasBeenStaged(false),
1276 mScrollAnimationEnabled(false),
1277 mScrollBarEnabled(false),
1278 mScrollStarted(false),
1279 mTextChanged(false),
1280 mCursorPositionChanged(false),
1281 mSelectionChanged(false),
1282 mSelectionCleared(false),
1284 mOldSelectionStart(0u),
1285 mOldSelectionEnd(0u)
1289 TextEditor::~TextEditor()
1291 UnparentAndReset(mStencil);
1293 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1295 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1296 Adaptor::Get().RemoveIdle(mIdleCallback);
1300 std::string TextEditor::AccessibleImpl::GetName() const
1302 auto self = Toolkit::TextEditor::DownCast(Self());
1303 return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1306 std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1308 if(endOffset <= startOffset)
1313 auto self = Toolkit::TextEditor::DownCast(Self());
1314 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1316 if(startOffset > text.size() || endOffset > text.size())
1321 return text.substr(startOffset, endOffset - startOffset);
1324 size_t TextEditor::AccessibleImpl::GetCharacterCount() const
1326 auto self = Toolkit::TextEditor::DownCast(Self());
1327 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1332 size_t TextEditor::AccessibleImpl::GetCursorOffset() const
1334 auto slf = Toolkit::TextEditor::DownCast(Self());
1335 return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition();
1338 bool TextEditor::AccessibleImpl::SetCursorOffset(size_t offset)
1340 auto slf = Toolkit::TextEditor::DownCast(Self());
1341 auto txt = slf.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1342 if(offset > txt.size())
1347 auto& slfImpl = Dali::Toolkit::GetImpl(slf);
1348 slfImpl.GetTextController()->ResetCursorPosition(offset);
1349 slfImpl.RequestTextRelayout();
1354 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const
1356 auto self = Toolkit::TextEditor::DownCast(Self());
1357 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1358 auto textSize = text.size();
1360 auto range = Dali::Accessibility::Range{};
1364 case Dali::Accessibility::TextBoundary::CHARACTER:
1366 if(offset < textSize)
1368 range.content = text[offset];
1369 range.startOffset = offset;
1370 range.endOffset = offset + 1;
1374 case Dali::Accessibility::TextBoundary::WORD:
1375 case Dali::Accessibility::TextBoundary::LINE:
1377 auto textString = text.c_str();
1378 auto breaks = std::vector<char>(textSize, 0);
1380 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1382 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1386 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1391 while(index < textSize && counter <= offset)
1396 while(breaks[index])
1404 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1408 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1414 if((counter > 0) && ((counter - 1) == offset))
1416 range.content = text.substr(start, index - start + 1);
1417 range.startOffset = start;
1418 range.endOffset = index + 1;
1421 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1428 case Dali::Accessibility::TextBoundary::SENTENCE:
1430 /* not supported by default */
1433 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1435 /* Paragraph is not supported by libunibreak library */
1445 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1447 // Since DALi supports only one selection indexes higher than 0 are ignored
1448 if(selectionIndex > 0)
1453 auto self = Toolkit::TextEditor::DownCast(Self());
1454 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1455 std::string value{};
1456 controller->RetrieveSelection(value);
1457 auto indices = controller->GetSelectionIndexes();
1459 return {static_cast<size_t>(indices.first), static_cast<size_t>(indices.second), value};
1462 bool TextEditor::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1464 // Since DALi supports only one selection indexes higher than 0 are ignored
1465 if(selectionIndex > 0)
1470 auto self = Toolkit::TextEditor::DownCast(Self());
1471 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1475 bool TextEditor::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1477 // Since DALi supports only one selection indexes higher than 0 are ignored
1478 if(selectionIndex > 0)
1483 auto self = Toolkit::TextEditor::DownCast(Self());
1484 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1488 bool TextEditor::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1490 if(endPosition <= startPosition)
1495 auto self = Toolkit::TextEditor::DownCast(Self());
1496 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1497 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1502 bool TextEditor::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1504 if(endPosition <= startPosition)
1509 auto self = Toolkit::TextEditor::DownCast(Self());
1510 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1511 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1513 self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1518 bool TextEditor::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1520 if(endPosition <= startPosition)
1525 auto self = Toolkit::TextEditor::DownCast(Self());
1526 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1528 self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1533 Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates()
1535 using namespace Dali::Accessibility;
1537 auto states = DevelControl::ControlAccessible::CalculateStates();
1538 states[State::EDITABLE] = true;
1539 states[State::FOCUSABLE] = true;
1541 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1542 if(Self() == focusControl)
1544 states[State::FOCUSED] = true;
1550 bool TextEditor::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1552 auto self = Toolkit::TextEditor::DownCast(Self());
1553 auto insertedText = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1555 insertedText.insert(startPosition, text);
1557 self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(insertedText));
1562 bool TextEditor::AccessibleImpl::SetTextContents(std::string newContents)
1564 auto self = Toolkit::TextEditor::DownCast(Self());
1565 self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents));
1569 int32_t TextEditor::AccessibleImpl::GetLinkCount() const
1571 auto self = Toolkit::TextEditor::DownCast(Self());
1572 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1575 Accessibility::Hyperlink* TextEditor::AccessibleImpl::GetLink(int32_t linkIndex) const
1577 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1581 auto self = Toolkit::TextEditor::DownCast(Self());
1582 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1583 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1586 int32_t TextEditor::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1588 auto self = Toolkit::TextEditor::DownCast(Self());
1589 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1590 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1593 } // namespace Internal
1595 } // namespace Toolkit