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 )
159 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
160 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
161 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
162 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
163 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
164 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
165 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
168 DALI_TYPE_REGISTRATION_END()
171 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
173 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
175 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
177 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
179 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
181 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
183 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
185 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
187 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
189 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
191 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
193 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
195 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
197 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
199 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
201 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
203 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
205 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
207 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
209 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
211 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
213 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
215 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
217 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
219 return editorInputStyleMask;
224 Toolkit::TextEditor TextEditor::New()
226 // Create the implementation, temporarily owned by this handle on stack
227 IntrusivePtr<TextEditor> impl = new TextEditor();
229 // Pass ownership to CustomActor handle
230 Toolkit::TextEditor handle(*impl);
232 // Second-phase init of the implementation
233 // This can only be done after the CustomActor connection has been made...
239 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
241 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
243 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
247 PropertyHandler::SetProperty(textEditor, index, value);
251 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
253 Property::Value value;
255 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
259 value = PropertyHandler::GetProperty(textEditor, index);
264 void TextEditor::SelectWholeText()
266 if(mController && mController->IsShowingRealText())
268 mController->SelectWholeText();
273 void TextEditor::SelectNone()
275 if(mController && mController->IsShowingRealText())
277 mController->SelectNone();
281 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
283 if(mController && mController->IsShowingRealText())
285 mController->SelectText(start, end);
290 string TextEditor::CopyText()
292 string copiedText = "";
293 if(mController && mController->IsShowingRealText())
295 copiedText = mController->CopyText();
300 string TextEditor::CutText()
303 if(mController && mController->IsShowingRealText())
305 cutText = mController->CutText();
310 void TextEditor::PasteText()
314 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
315 mController->PasteText();
319 void TextEditor::ScrollBy(Vector2 scroll)
321 if(mController && mController->IsShowingRealText())
323 mController->ScrollBy(scroll);
327 float TextEditor::GetHorizontalScrollPosition()
329 if(mController && mController->IsShowingRealText())
331 return mController->GetHorizontalScrollPosition();
336 float TextEditor::GetVerticalScrollPosition()
338 if(mController && mController->IsShowingRealText())
340 return mController->GetVerticalScrollPosition();
345 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
347 return mController->GetTextSize(startIndex, endIndex);
350 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
352 return mController->GetTextPosition(startIndex, endIndex);
355 string TextEditor::GetSelectedText() const
357 string selectedText = "";
358 if(mController && mController->IsShowingRealText())
360 selectedText = mController->GetSelectedText();
365 InputMethodContext TextEditor::GetInputMethodContext()
367 return mInputMethodContext;
370 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
372 return mMaxLengthReachedSignal;
375 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
377 return mAnchorClickedSignal;
380 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
382 return mCursorPositionChangedSignal;
385 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
387 return mInputFilteredSignal;
390 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
392 return mSelectionChangedSignal;
395 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
397 return mSelectionClearedSignal;
400 Text::ControllerPtr TextEditor::GetTextController()
405 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
407 Dali::BaseHandle handle(object);
409 bool connected(true);
410 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
412 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
414 editor.TextChangedSignal().Connect(tracker, functor);
416 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
418 editor.InputStyleChangedSignal().Connect(tracker, functor);
420 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
424 Internal::TextEditor& editorImpl(GetImpl(editor));
425 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
428 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
432 Internal::TextEditor& editorImpl(GetImpl(editor));
433 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
436 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
440 Internal::TextEditor& editorImpl(GetImpl(editor));
441 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
444 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
448 Internal::TextEditor& editorImpl(GetImpl(editor));
449 editorImpl.InputFilteredSignal().Connect(tracker, functor);
452 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
456 Internal::TextEditor& editorImpl(GetImpl(editor));
457 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
460 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
464 Internal::TextEditor& editorImpl(GetImpl(editor));
465 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
470 // signalName does not match any signal
477 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
479 return mTextChangedSignal;
482 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
484 return mInputStyleChangedSignal;
487 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
489 return mScrollStateChangedSignal;
492 void TextEditor::OnAccessibilityStatusChanged()
494 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
497 void TextEditor::OnInitialize()
501 mController = Text::Controller::New(this, this, this, this);
503 mDecorator = Text::Decorator::New(*mController,
506 mInputMethodContext = InputMethodContext::New(self);
508 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
510 // Enables the text input.
511 mController->EnableTextInput(mDecorator, mInputMethodContext);
513 // Enables the vertical scrolling after the text input has been enabled.
514 mController->SetVerticalScrollEnabled(true);
516 // Disables the horizontal scrolling.
517 mController->SetHorizontalScrollEnabled(false);
519 // Sets the maximum number of characters.
520 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
522 // Enable the smooth handle panning.
523 mController->SetSmoothHandlePanEnabled(true);
525 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
526 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
528 // Sets layoutDirection value
529 Dali::Stage stage = Dali::Stage::GetCurrent();
530 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
531 mController->SetLayoutDirection(layoutDirection);
533 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
535 // Forward input events to controller
536 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
537 GetTapGestureDetector().SetMaximumTapsRequired(2);
538 GetTapGestureDetector().ReceiveAllTapEvents(true);
540 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
542 // Set BoundingBox to stage size if not already set.
543 Rect<int> boundingBox;
544 mDecorator->GetBoundingBox(boundingBox);
546 if(boundingBox.IsEmpty())
548 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
549 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
552 // Whether to flip the selection handles as soon as they cross.
553 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
555 // Set the default scroll speed.
556 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
558 // Fill-parent area by default
559 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
560 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
561 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
563 //Enable highightability
564 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
566 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
568 // Creates an extra control to be used as stencil buffer.
569 mStencil = Control::New();
570 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
571 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
573 // Creates a background visual. Even if the color is transparent it updates the stencil.
574 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
575 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
577 // Enable the clipping property.
578 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
579 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
583 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
584 return std::unique_ptr<Dali::Accessibility::Accessible>(
585 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
588 Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
589 Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
592 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
594 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
598 case StyleChange::DEFAULT_FONT_CHANGE:
600 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
601 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
602 // Property system did not set the font so should update it.
603 mController->UpdateAfterFontChange(newFont);
608 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
610 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
614 case StyleChange::THEME_CHANGE:
616 // Nothing to do, let control base class handle this
621 // Up call to Control
622 Control::OnStyleChange(styleManager, change);
625 Vector3 TextEditor::GetNaturalSize()
628 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
630 Vector3 naturalSize = mController->GetNaturalSize();
631 naturalSize.width += (padding.start + padding.end);
632 naturalSize.height += (padding.top + padding.bottom);
637 float TextEditor::GetHeightForWidth(float width)
640 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
641 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
644 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
646 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
648 actor.SetProperty(Actor::Property::SIZE, size);
652 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
654 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
659 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
661 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
663 // Support Right-To-Left of padding
664 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
666 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
668 std::swap(padding.start, padding.end);
673 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
674 ResizeActor(mStencil, contentSize);
678 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
679 ResizeActor(mActiveLayer, contentSize);
682 // If there is text changed, callback is called.
685 EmitTextChangedSignal();
688 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
690 if((Text::Controller::NONE_UPDATED != updateTextType) ||
693 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
696 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
698 mDecorator->Relayout(contentSize);
703 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
706 RenderText(updateTextType);
709 if(mCursorPositionChanged)
711 EmitCursorPositionChangedSignal();
714 if(mSelectionChanged)
716 EmitSelectionChangedSignal();
719 if(mSelectionCleared)
721 EmitSelectionClearedSignal();
724 // The text-editor emits signals when the input style changes. These changes of style are
725 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
726 // can't be emitted during the size negotiation as the callbacks may update the UI.
727 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
728 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
730 if(Adaptor::IsAvailable())
732 Adaptor& adaptor = Adaptor::Get();
734 if(NULL == mIdleCallback)
736 // @note: The callback manager takes the ownership of the callback object.
737 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
738 adaptor.AddIdle(mIdleCallback, false);
744 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
746 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
749 ApplyScrollPosition();
754 void TextEditor::OnKeyInputFocusGained()
756 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
757 if(mInputMethodContext && IsEditable())
759 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
760 mInputMethodContext.ApplyOptions(mInputMethodOptions);
761 mInputMethodContext.NotifyTextInputMultiLine(true);
763 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
765 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
767 // Notify that the text editing start.
768 mInputMethodContext.Activate();
770 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
771 mInputMethodContext.SetRestoreAfterFocusLost(true);
773 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
777 notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
780 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
782 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
785 void TextEditor::OnKeyInputFocusLost()
787 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
788 if(mInputMethodContext)
790 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
792 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
793 mInputMethodContext.SetRestoreAfterFocusLost(false);
795 // Notify that the text editing finish.
796 mInputMethodContext.Deactivate();
798 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
800 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
804 notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
807 mController->KeyboardFocusLostEvent();
809 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
812 bool TextEditor::OnAccessibilityActivated()
818 void TextEditor::OnTap(const TapGesture& gesture)
820 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
821 if(mInputMethodContext && IsEditable())
823 mInputMethodContext.Activate();
825 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
827 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
828 const Vector2& localPoint = gesture.GetLocalPoint();
829 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
830 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
835 void TextEditor::OnPan(const PanGesture& gesture)
837 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
840 void TextEditor::OnLongPress(const LongPressGesture& gesture)
842 if(mInputMethodContext && IsEditable())
844 mInputMethodContext.Activate();
847 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
848 const Vector2& localPoint = gesture.GetLocalPoint();
849 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
854 bool TextEditor::OnKeyEvent(const KeyEvent& event)
856 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
858 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
860 // Make sure ClearKeyInputFocus when only key is up
861 if(event.GetState() == KeyEvent::UP)
863 ClearKeyInputFocus();
869 return mController->KeyEvent(event);
872 void TextEditor::RequestTextRelayout()
877 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
879 if(Accessibility::IsUp())
881 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
885 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
887 if(Accessibility::IsUp())
889 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
893 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
895 if(Accessibility::IsUp())
897 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
900 if((oldPosition != newPosition) && !mCursorPositionChanged)
902 mCursorPositionChanged = true;
903 mOldPosition = oldPosition;
907 void TextEditor::TextChanged(bool immediate)
909 if(immediate) // Emits TextChangedSignal immediately
911 EmitTextChangedSignal();
919 void TextEditor::EmitTextChangedSignal()
921 Dali::Toolkit::TextEditor handle(GetOwner());
922 mTextChangedSignal.Emit(handle);
923 mTextChanged = false;
926 void TextEditor::MaxLengthReached()
928 Dali::Toolkit::TextEditor handle(GetOwner());
929 mMaxLengthReachedSignal.Emit(handle);
932 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
934 Dali::Toolkit::TextEditor handle(GetOwner());
935 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
938 void TextEditor::AnchorClicked(const std::string& href)
940 Dali::Toolkit::TextEditor handle(GetOwner());
941 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
944 void TextEditor::EmitCursorPositionChangedSignal()
946 Dali::Toolkit::TextEditor handle(GetOwner());
947 mCursorPositionChanged = false;
948 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
951 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
953 Dali::Toolkit::TextEditor handle(GetOwner());
954 mInputFilteredSignal.Emit(handle, type);
957 void TextEditor::EmitSelectionChangedSignal()
959 Dali::Toolkit::TextEditor handle(GetOwner());
960 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
961 mSelectionChanged = false;
964 void TextEditor::EmitSelectionClearedSignal()
966 Dali::Toolkit::TextEditor handle(GetOwner());
967 mSelectionClearedSignal.Emit(handle);
968 mSelectionCleared = false;
971 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
973 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
975 if(newStart == newEnd)
977 mSelectionCleared = true;
980 mSelectionChanged = true;
981 mOldSelectionStart = oldStart;
982 mOldSelectionEnd = oldEnd;
984 if(mOldSelectionStart > mOldSelectionEnd)
987 uint32_t temp = mOldSelectionStart;
988 mOldSelectionStart = mOldSelectionEnd;
989 mOldSelectionEnd = temp;
994 void TextEditor::AddDecoration(Actor& actor, bool needsClipping)
1000 mClippingDecorationActors.push_back(actor);
1004 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1005 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1007 mActiveLayer = actor;
1012 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1014 if(mController && mController->IsShowingRealText())
1016 mController->SetTextSelectionRange(start, end);
1021 Uint32Pair TextEditor::GetTextSelectionRange() const
1023 Uint32Pair range(0, 0);
1024 if(mController && mController->IsShowingRealText())
1026 range = mController->GetTextSelectionRange();
1031 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1033 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1034 Property::Map* resultMap = propValue.GetMap();
1036 Property::Value* colorValue = nullptr;
1037 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1039 colorValue->Get(color);
1043 void TextEditor::UpdateScrollBar()
1045 using namespace Dali;
1047 float scrollPosition;
1050 bool latestScrolled;
1052 if(!mScrollBarEnabled)
1056 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1057 if(!latestScrolled || controlSize > layoutSize)
1062 CustomActor self = Self();
1065 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1066 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1067 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1068 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1069 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1070 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1072 // Register the scroll position property
1073 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1074 // Register the minimum scroll position property
1075 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1076 // Register the maximum scroll position property
1077 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1078 // Register the scroll content size property
1079 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1081 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1083 // Set style name of ScrollBar for styling
1084 mScrollBar.SetStyleName("TextEditorScrollBar");
1085 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1088 // Set style name of ScrollBarIndicator for styling
1089 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1092 self.Add(mScrollBar);
1096 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1097 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1098 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1100 self.SetProperty(propertyScrollPosition, scrollPosition);
1101 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1102 self.SetProperty(propertyScrollContentSize, layoutSize);
1105 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1108 mScrollStarted = true;
1109 Dali::Toolkit::TextEditor handle(GetOwner());
1110 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1113 Actor indicator = mScrollBar.GetScrollIndicator();
1116 mAnimation.Stop(); // Cancel any animation
1120 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1122 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1123 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1125 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1128 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1130 // If animation is successfully ended, then emit ScrollStateChangedSignal
1131 if(animation.GetCurrentProgress() == 0.0f)
1133 mScrollStarted = false;
1134 Dali::Toolkit::TextEditor handle(GetOwner());
1135 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1139 void TextEditor::OnSceneConnect(Dali::Actor actor)
1143 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1147 mHasBeenStaged = true;
1151 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1153 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1154 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1157 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1162 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1168 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1170 mController->PasteClipboardItemEvent();
1173 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1175 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1177 // Just hide the grab handle when keyboard is hidden.
1180 mController->KeyboardFocusLostEvent();
1184 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1188 void TextEditor::OnSceneConnection(int depth)
1190 // Sets the depth to the visuals inside the text's decorator.
1191 mDecorator->SetTextDepth(depth);
1193 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1195 // Call the Control::OnSceneConnection() to set the depth of the background.
1196 Control::OnSceneConnection(depth);
1199 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1204 void TextEditor::OnIdleSignal()
1206 // Emits the change of input style signals.
1207 mController->ProcessInputStyleChangedSignals();
1209 // Set the pointer to null as the callback manager deletes the callback after execute it.
1210 mIdleCallback = NULL;
1213 void TextEditor::ApplyScrollPosition()
1215 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1216 float scrollAmount = 0.0f;
1218 if(mScrollAnimationEnabled)
1220 scrollAmount = mController->GetScrollAmountByUserInput();
1222 if(mTextVerticalScroller)
1224 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1226 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1228 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1232 mTextVerticalScroller = Text::TextVerticalScroller::New();
1233 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1235 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1237 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1241 bool TextEditor::IsEditable() const
1243 return mController->IsEditable();
1246 void TextEditor::SetEditable(bool editable)
1248 mController->SetEditable(editable);
1249 if(mInputMethodContext && !editable)
1251 mInputMethodContext.Deactivate();
1255 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1257 mController->ChangedLayoutDirection();
1260 TextEditor::TextEditor()
1261 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1262 mAnimationPeriod(0.0f, 0.0f),
1263 mIdleCallback(NULL),
1264 mAlignmentOffset(0.f),
1265 mScrollAnimationDuration(0.f),
1267 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1268 mHasBeenStaged(false),
1269 mScrollAnimationEnabled(false),
1270 mScrollBarEnabled(false),
1271 mScrollStarted(false),
1272 mTextChanged(false),
1273 mCursorPositionChanged(false),
1274 mSelectionChanged(false),
1275 mSelectionCleared(false),
1277 mOldSelectionStart(0u),
1278 mOldSelectionEnd(0u)
1282 TextEditor::~TextEditor()
1284 UnparentAndReset(mStencil);
1286 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1288 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1289 Adaptor::Get().RemoveIdle(mIdleCallback);
1293 std::string TextEditor::AccessibleImpl::GetName() const
1295 auto self = Toolkit::TextEditor::DownCast(Self());
1296 return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1299 std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1301 if(endOffset <= startOffset)
1306 auto self = Toolkit::TextEditor::DownCast(Self());
1307 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1309 if(startOffset > text.size() || endOffset > text.size())
1314 return text.substr(startOffset, endOffset - startOffset);
1317 size_t TextEditor::AccessibleImpl::GetCharacterCount() const
1319 auto self = Toolkit::TextEditor::DownCast(Self());
1320 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1325 size_t TextEditor::AccessibleImpl::GetCursorOffset() const
1327 auto slf = Toolkit::TextEditor::DownCast(Self());
1328 return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition();
1331 bool TextEditor::AccessibleImpl::SetCursorOffset(size_t offset)
1333 auto slf = Toolkit::TextEditor::DownCast(Self());
1334 auto txt = slf.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1335 if(offset > txt.size())
1340 auto& slfImpl = Dali::Toolkit::GetImpl(slf);
1341 slfImpl.GetTextController()->ResetCursorPosition(offset);
1342 slfImpl.RequestTextRelayout();
1347 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const
1349 auto self = Toolkit::TextEditor::DownCast(Self());
1350 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1351 auto textSize = text.size();
1353 auto range = Dali::Accessibility::Range{};
1357 case Dali::Accessibility::TextBoundary::CHARACTER:
1359 if(offset < textSize)
1361 range.content = text[offset];
1362 range.startOffset = offset;
1363 range.endOffset = offset + 1;
1367 case Dali::Accessibility::TextBoundary::WORD:
1368 case Dali::Accessibility::TextBoundary::LINE:
1370 auto textString = text.c_str();
1371 auto breaks = std::vector<char>(textSize, 0);
1373 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1375 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1379 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1384 while(index < textSize && counter <= offset)
1389 while(breaks[index])
1397 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1401 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1407 if((counter > 0) && ((counter - 1) == offset))
1409 range.content = text.substr(start, index - start + 1);
1410 range.startOffset = start;
1411 range.endOffset = index + 1;
1414 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1421 case Dali::Accessibility::TextBoundary::SENTENCE:
1423 /* not supported by default */
1426 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1428 /* Paragraph is not supported by libunibreak library */
1438 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1440 // Since DALi supports only one selection indexes higher than 0 are ignored
1441 if(selectionIndex > 0)
1446 auto self = Toolkit::TextEditor::DownCast(Self());
1447 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1448 std::string value{};
1449 controller->RetrieveSelection(value);
1450 auto indices = controller->GetSelectionIndexes();
1452 return {static_cast<size_t>(indices.first), static_cast<size_t>(indices.second), value};
1455 bool TextEditor::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1457 // Since DALi supports only one selection indexes higher than 0 are ignored
1458 if(selectionIndex > 0)
1463 auto self = Toolkit::TextEditor::DownCast(Self());
1464 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1468 bool TextEditor::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1470 // Since DALi supports only one selection indexes higher than 0 are ignored
1471 if(selectionIndex > 0)
1476 auto self = Toolkit::TextEditor::DownCast(Self());
1477 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1481 bool TextEditor::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1483 if(endPosition <= startPosition)
1488 auto self = Toolkit::TextEditor::DownCast(Self());
1489 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1490 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1495 bool TextEditor::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1497 if(endPosition <= startPosition)
1502 auto self = Toolkit::TextEditor::DownCast(Self());
1503 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1504 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1506 self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1511 bool TextEditor::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1513 if(endPosition <= startPosition)
1518 auto self = Toolkit::TextEditor::DownCast(Self());
1519 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1521 self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1526 Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates()
1528 using namespace Dali::Accessibility;
1530 auto states = DevelControl::ControlAccessible::CalculateStates();
1531 states[State::EDITABLE] = true;
1532 states[State::FOCUSABLE] = true;
1534 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1535 if(Self() == focusControl)
1537 states[State::FOCUSED] = true;
1543 bool TextEditor::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1545 auto self = Toolkit::TextEditor::DownCast(Self());
1546 auto insertedText = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1548 insertedText.insert(startPosition, text);
1550 self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(insertedText));
1555 bool TextEditor::AccessibleImpl::SetTextContents(std::string newContents)
1557 auto self = Toolkit::TextEditor::DownCast(Self());
1558 self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents));
1562 int32_t TextEditor::AccessibleImpl::GetLinkCount() const
1564 auto self = Toolkit::TextEditor::DownCast(Self());
1565 return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1568 Accessibility::Hyperlink* TextEditor::AccessibleImpl::GetLink(int32_t linkIndex) const
1570 if(linkIndex < 0 || linkIndex >= GetLinkCount())
1574 auto self = Toolkit::TextEditor::DownCast(Self());
1575 auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1576 return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1579 int32_t TextEditor::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1581 auto self = Toolkit::TextEditor::DownCast(Self());
1582 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1583 return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1586 } // namespace Internal
1588 } // namespace Toolkit