2 * Copyright (c) 2024 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/math/math-utils.h>
31 #include <dali/public-api/object/type-registry-helper.h>
36 #include <dali-toolkit/devel-api/controls/control-devel.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/focus-manager/keyboard-focus-manager-impl.h>
42 #include <dali-toolkit/internal/styling/style-manager-impl.h>
43 #include <dali-toolkit/internal/text/rendering/text-backend.h>
44 #include <dali-toolkit/internal/text/text-effects-style.h>
45 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
46 #include <dali-toolkit/internal/text/text-font-style.h>
47 #include <dali-toolkit/internal/text/text-view.h>
48 #include <dali-toolkit/public-api/text/text-enumerations.h>
49 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
50 #include <dali-toolkit/public-api/visuals/visual-properties.h>
52 using namespace Dali::Toolkit::Text;
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gTextEditorLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
64 namespace // unnamed namespace
66 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
67 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
68 } // unnamed namespace
72 const char* const SCROLL_BAR_POSITION("sourcePosition");
73 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
74 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
75 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
80 return Toolkit::TextEditor::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextEditor, Toolkit::Control, Create);
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "text", STRING, TEXT )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "underline", MAP, UNDERLINE )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
130 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
131 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE )
132 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT )
133 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION )
134 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER )
135 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalScrollPosition", FLOAT, HORIZONTAL_SCROLL_POSITION )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION )
147 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING )
148 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT )
149 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
150 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
151 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
152 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
153 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
154 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
155 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFilter", MAP, INPUT_FILTER )
156 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsis", BOOLEAN, ELLIPSIS )
157 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
158 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "minLineSize", FLOAT, MIN_LINE_SIZE )
159 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", MAP, STRIKETHROUGH )
160 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
161 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "characterSpacing", FLOAT, CHARACTER_SPACING )
162 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE )
163 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
164 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionPopupStyle", MAP, SELECTION_POPUP_STYLE )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
167 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
168 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
169 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
170 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
171 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
172 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
173 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
174 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionStarted", SIGNAL_SELECTION_STARTED )
176 DALI_TYPE_REGISTRATION_END()
179 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
181 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
183 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
185 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
187 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
189 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
191 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
193 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
195 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
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_FONT_WIDTH))
201 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
203 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
205 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
207 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
209 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
211 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
213 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
215 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
217 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
219 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
221 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
223 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
225 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
227 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
229 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
232 return editorInputStyleMask;
237 Toolkit::TextEditor TextEditor::New(ControlBehaviour additionalBehaviour)
239 // Create the implementation, temporarily owned by this handle on stack
240 IntrusivePtr<TextEditor> impl = new TextEditor(additionalBehaviour);
242 // Pass ownership to CustomActor handle
243 Toolkit::TextEditor handle(*impl);
245 // Second-phase init of the implementation
246 // This can only be done after the CustomActor connection has been made...
252 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
254 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
256 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
260 PropertyHandler::SetProperty(textEditor, index, value);
264 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
266 Property::Value value;
268 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
272 value = PropertyHandler::GetProperty(textEditor, index);
277 void TextEditor::SelectWholeText()
279 if(mController && mController->IsShowingRealText())
281 mController->SelectWholeText();
286 void TextEditor::SelectNone()
288 if(mController && mController->IsShowingRealText())
290 mController->SelectNone();
294 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
296 if(mController && mController->IsShowingRealText())
298 mController->SelectText(start, end);
303 string TextEditor::CopyText()
305 string copiedText = "";
306 if(mController && mController->IsShowingRealText())
308 copiedText = mController->CopyText();
313 string TextEditor::CutText()
316 if(mController && mController->IsShowingRealText())
318 cutText = mController->CutText();
323 void TextEditor::PasteText()
327 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
328 mController->PasteText();
332 void TextEditor::ScrollBy(Vector2 scroll)
334 if(mController && mController->IsShowingRealText())
336 mController->ScrollBy(scroll);
340 float TextEditor::GetHorizontalScrollPosition()
342 if(mController && mController->IsShowingRealText())
344 return mController->GetHorizontalScrollPosition();
349 float TextEditor::GetVerticalScrollPosition()
351 if(mController && mController->IsShowingRealText())
353 return mController->GetVerticalScrollPosition();
358 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
360 return mController->GetTextSize(startIndex, endIndex);
363 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
365 return mController->GetTextPosition(startIndex, endIndex);
368 Rect<float> TextEditor::GetLineBoundingRectangle(const uint32_t lineIndex) const
370 return mController->GetLineBoundingRectangle(lineIndex);
373 Rect<float> TextEditor::GetCharacterBoundingRectangle(const uint32_t charIndex) const
375 return mController->GetCharacterBoundingRectangle(charIndex);
378 int TextEditor::GetCharacterIndexAtPosition(float visualX, float visualY) const
380 return mController->GetCharacterIndexAtPosition(visualX, visualY);
383 Rect<> TextEditor::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
385 return mController->GetTextBoundingRectangle(startIndex, endIndex);
388 void TextEditor::SetSpannedText(const Text::Spanned& spannedText)
390 mController->SetSpannedText(spannedText);
393 string TextEditor::GetSelectedText() const
395 string selectedText = "";
396 if(mController && mController->IsShowingRealText())
398 selectedText = mController->GetSelectedText();
403 InputMethodContext TextEditor::GetInputMethodContext()
405 return mInputMethodContext;
408 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
410 return mMaxLengthReachedSignal;
413 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
415 return mAnchorClickedSignal;
418 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
420 return mCursorPositionChangedSignal;
423 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
425 return mInputFilteredSignal;
428 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
430 return mSelectionChangedSignal;
433 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
435 return mSelectionClearedSignal;
438 DevelTextEditor::SelectionStartedSignalType& TextEditor::SelectionStartedSignal()
440 return mSelectionStartedSignal;
443 Text::ControllerPtr TextEditor::GetTextController()
448 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
450 Dali::BaseHandle handle(object);
452 bool connected(true);
453 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
455 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
457 editor.TextChangedSignal().Connect(tracker, functor);
459 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
461 editor.InputStyleChangedSignal().Connect(tracker, functor);
463 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
467 Internal::TextEditor& editorImpl(GetImpl(editor));
468 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
471 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
475 Internal::TextEditor& editorImpl(GetImpl(editor));
476 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
479 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
483 Internal::TextEditor& editorImpl(GetImpl(editor));
484 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
487 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
491 Internal::TextEditor& editorImpl(GetImpl(editor));
492 editorImpl.InputFilteredSignal().Connect(tracker, functor);
495 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
499 Internal::TextEditor& editorImpl(GetImpl(editor));
500 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
503 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
507 Internal::TextEditor& editorImpl(GetImpl(editor));
508 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
511 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
515 Internal::TextEditor& editorImpl(GetImpl(editor));
516 editorImpl.SelectionStartedSignal().Connect(tracker, functor);
521 // signalName does not match any signal
528 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
530 return mTextChangedSignal;
533 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
535 return mInputStyleChangedSignal;
538 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
540 return mScrollStateChangedSignal;
543 void TextEditor::OnAccessibilityStatusChanged()
545 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
548 void TextEditor::OnInitialize()
552 mController = Text::Controller::New(this, this, this, this);
554 mDecorator = Text::Decorator::New(*mController,
557 mInputMethodContext = InputMethodContext::New(self);
559 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
561 // Enables the text input.
562 mController->EnableTextInput(mDecorator, mInputMethodContext);
564 // Enables the vertical scrolling after the text input has been enabled.
565 mController->SetVerticalScrollEnabled(true);
567 // Disables the horizontal scrolling.
568 mController->SetHorizontalScrollEnabled(false);
570 // Sets the maximum number of characters.
571 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
573 // Enable the smooth handle panning.
574 mController->SetSmoothHandlePanEnabled(true);
576 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
577 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
579 // Sets layoutDirection value
580 Dali::Stage stage = Dali::Stage::GetCurrent();
581 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
582 mController->SetLayoutDirection(layoutDirection);
584 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
586 // Forward input events to controller
587 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
588 GetTapGestureDetector().SetMaximumTapsRequired(2);
589 GetTapGestureDetector().ReceiveAllTapEvents(true);
591 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
593 // Set BoundingBox to stage size if not already set.
594 Rect<int> boundingBox;
595 mDecorator->GetBoundingBox(boundingBox);
597 if(boundingBox.IsEmpty())
599 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
600 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
603 // Whether to flip the selection handles as soon as they cross.
604 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
606 // Set the default scroll speed.
607 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
609 // Fill-parent area by default
610 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
611 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
612 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
614 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
616 // Creates an extra control to be used as stencil buffer.
617 mStencil = Control::New();
618 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
619 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
620 mStencil.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
622 // Creates a background visual. Even if the color is transparent it updates the stencil.
623 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
624 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
626 // Enable the clipping property.
627 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
628 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
633 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY);
634 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
636 Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
637 Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
640 DevelControl::ControlAccessible* TextEditor::CreateAccessibleObject()
642 return new TextEditorAccessible(Self());
645 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
647 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
651 case StyleChange::DEFAULT_FONT_CHANGE:
653 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
654 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
655 // Property system did not set the font so should update it.
656 mController->UpdateAfterFontChange(newFont);
661 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
663 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
667 case StyleChange::THEME_CHANGE:
669 // Nothing to do, let control base class handle this
674 // Up call to Control
675 Control::OnStyleChange(styleManager, change);
678 Vector3 TextEditor::GetNaturalSize()
681 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
683 Vector3 naturalSize = mController->GetNaturalSize();
684 naturalSize.width += (padding.start + padding.end);
685 naturalSize.height += (padding.top + padding.bottom);
690 float TextEditor::GetHeightForWidth(float width)
693 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
694 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
697 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
699 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
701 actor.SetProperty(Actor::Property::SIZE, size);
705 void TextEditor::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
707 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnPropertySet index[%d]\n", index);
711 case DevelActor::Property::USER_INTERACTION_ENABLED:
713 const bool enabled = propertyValue.Get<bool>();
714 mController->SetUserInteractionEnabled(enabled);
717 float opacity = enabled ? 1.0f : mController->GetDisabledColorOpacity();
718 mStencil.SetProperty(Actor::Property::OPACITY, opacity);
724 Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
730 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
732 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
737 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
739 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
741 // Support Right-To-Left of padding
742 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
744 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
746 std::swap(padding.start, padding.end);
751 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
752 ResizeActor(mStencil, contentSize);
756 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
757 ResizeActor(mActiveLayer, contentSize);
761 // The cursor layer is added to the stencil in RenderText.
762 // Do not calculate the position because the stencil has already been resized excluding the padding size.
763 // There is no case where the text editor does not have a stencil.
764 ResizeActor(mCursorLayer, contentSize);
767 // If there is text changed, callback is called.
770 EmitTextChangedSignal();
773 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
775 if((Text::Controller::NONE_UPDATED != updateTextType) ||
778 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
781 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
783 mDecorator->Relayout(contentSize);
788 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
791 RenderText(updateTextType);
794 if(mCursorPositionChanged)
796 EmitCursorPositionChangedSignal();
799 if(mSelectionStarted)
801 EmitSelectionStartedSignal();
804 if(mSelectionChanged)
806 EmitSelectionChangedSignal();
809 if(mSelectionCleared)
811 EmitSelectionClearedSignal();
814 // The text-editor emits signals when the input style changes. These changes of style are
815 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
816 // can't be emitted during the size negotiation as the callbacks may update the UI.
817 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
818 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
820 if(Adaptor::IsAvailable())
822 Adaptor& adaptor = Adaptor::Get();
824 if(NULL == mIdleCallback)
826 // @note: The callback manager takes the ownership of the callback object.
827 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
828 if(DALI_UNLIKELY(!adaptor.AddIdle(mIdleCallback, false)))
830 DALI_LOG_ERROR("Fail to add idle callback for text editor queue. Skip these callbacks\n");
832 // Set the pointer to null as the callback manager deletes the callback even AddIdle failed.
833 mIdleCallback = NULL;
840 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
842 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mCursorLayer, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
845 ApplyScrollPosition();
850 void TextEditor::OnKeyInputFocusGained()
852 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
853 if(mInputMethodContext && IsEditable())
855 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
856 mInputMethodContext.ApplyOptions(mInputMethodOptions);
857 mInputMethodContext.NotifyTextInputMultiLine(true);
859 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
861 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
863 // Notify that the text editing start.
864 mInputMethodContext.Activate();
866 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
867 mInputMethodContext.SetRestoreAfterFocusLost(true);
870 if(IsEditable() && mController->IsUserInteractionEnabled())
872 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
875 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
878 void TextEditor::OnKeyInputFocusLost()
880 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
881 if(mInputMethodContext)
883 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
885 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
886 mInputMethodContext.SetRestoreAfterFocusLost(false);
888 // Notify that the text editing finish.
889 mInputMethodContext.Deactivate();
891 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
894 mController->KeyboardFocusLostEvent();
896 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
899 bool TextEditor::OnAccessibilityActivated()
905 void TextEditor::OnTap(const TapGesture& gesture)
907 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
908 if(mInputMethodContext && IsEditable())
910 mInputMethodContext.Activate();
912 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
914 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
915 const Vector2& localPoint = gesture.GetLocalPoint();
916 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
917 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
919 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
920 if(keyboardFocusManager)
922 keyboardFocusManager.SetCurrentFocusActor(Self());
927 void TextEditor::OnPan(const PanGesture& gesture)
929 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
930 if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement()))
932 Dali::DevelActor::SetNeedGesturePropagation(Self(), true);
936 void TextEditor::OnLongPress(const LongPressGesture& gesture)
938 if(mInputMethodContext && IsEditable())
940 mInputMethodContext.Activate();
943 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
944 const Vector2& localPoint = gesture.GetLocalPoint();
945 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
950 bool TextEditor::OnKeyEvent(const KeyEvent& event)
952 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
954 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
956 // Make sure ClearKeyInputFocus when only key is up
957 if(event.GetState() == KeyEvent::UP)
959 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
960 if(keyboardFocusManager)
962 keyboardFocusManager.ClearFocus();
964 ClearKeyInputFocus();
970 return mController->KeyEvent(event);
973 void TextEditor::RequestTextRelayout()
978 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
980 auto accessible = GetAccessibleObject();
981 if(DALI_LIKELY(accessible))
983 accessible->EmitTextInserted(position, length, content);
987 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
989 auto accessible = GetAccessibleObject();
990 if(DALI_LIKELY(accessible))
992 accessible->EmitTextDeleted(position, length, content);
996 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
998 auto accessible = GetAccessibleObject();
999 if(DALI_LIKELY(accessible))
1001 accessible->EmitTextCursorMoved(newPosition);
1004 if((oldPosition != newPosition) && !mCursorPositionChanged)
1006 mCursorPositionChanged = true;
1007 mOldPosition = oldPosition;
1011 void TextEditor::TextChanged(bool immediate)
1013 if(immediate) // Emits TextChangedSignal immediately
1015 EmitTextChangedSignal();
1019 mTextChanged = true;
1023 void TextEditor::EmitTextChangedSignal()
1025 Dali::Toolkit::TextEditor handle(GetOwner());
1026 mTextChangedSignal.Emit(handle);
1027 mTextChanged = false;
1030 void TextEditor::MaxLengthReached()
1032 Dali::Toolkit::TextEditor handle(GetOwner());
1033 mMaxLengthReachedSignal.Emit(handle);
1036 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
1038 Dali::Toolkit::TextEditor handle(GetOwner());
1039 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
1042 void TextEditor::AnchorClicked(const std::string& href)
1044 Dali::Toolkit::TextEditor handle(GetOwner());
1045 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
1048 void TextEditor::EmitCursorPositionChangedSignal()
1050 Dali::Toolkit::TextEditor handle(GetOwner());
1051 mCursorPositionChanged = false;
1052 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
1055 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
1057 Dali::Toolkit::TextEditor handle(GetOwner());
1058 mInputFilteredSignal.Emit(handle, type);
1061 void TextEditor::EmitSelectionChangedSignal()
1063 Dali::Toolkit::TextEditor handle(GetOwner());
1064 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
1065 mSelectionChanged = false;
1068 void TextEditor::EmitSelectionClearedSignal()
1070 Dali::Toolkit::TextEditor handle(GetOwner());
1071 mSelectionClearedSignal.Emit(handle);
1072 mSelectionCleared = false;
1075 void TextEditor::EmitSelectionStartedSignal()
1077 Dali::Toolkit::TextEditor handle(GetOwner());
1078 mSelectionStartedSignal.Emit(handle);
1079 mSelectionStarted = false;
1082 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
1084 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
1086 if(newStart == newEnd)
1088 mSelectionCleared = true;
1092 if(oldStart == oldEnd)
1094 mSelectionStarted = true;
1098 mSelectionChanged = true;
1099 mOldSelectionStart = oldStart;
1100 mOldSelectionEnd = oldEnd;
1102 if(mOldSelectionStart > mOldSelectionEnd)
1105 uint32_t temp = mOldSelectionStart;
1106 mOldSelectionStart = mOldSelectionEnd;
1107 mOldSelectionEnd = temp;
1112 void TextEditor::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1118 mClippingDecorationActors.push_back(actor);
1121 // If the actor is a layer type, add it.
1122 if(type == DecorationType::ACTIVE_LAYER)
1124 AddLayer(mActiveLayer, actor);
1126 else if(type == DecorationType::CURSOR_LAYER)
1128 AddLayer(mCursorLayer, actor);
1133 void TextEditor::AddLayer(Actor& layer, Actor& actor)
1135 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1136 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1141 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1143 if(mController && mController->IsShowingRealText())
1145 mController->SetTextSelectionRange(start, end);
1150 Uint32Pair TextEditor::GetTextSelectionRange() const
1152 Uint32Pair range(0, 0);
1153 if(mController && mController->IsShowingRealText())
1155 range = mController->GetTextSelectionRange();
1160 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1162 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1163 Property::Map* resultMap = propValue.GetMap();
1165 Property::Value* colorValue = nullptr;
1166 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1168 colorValue->Get(color);
1172 void TextEditor::UpdateScrollBar()
1174 using namespace Dali;
1176 float scrollPosition;
1179 bool latestScrolled;
1181 if(!mScrollBarEnabled)
1185 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1186 if(!latestScrolled || controlSize > layoutSize)
1191 CustomActor self = Self();
1194 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1195 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1196 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1197 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1198 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1199 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1201 // Register the scroll position property
1202 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1203 // Register the minimum scroll position property
1204 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1205 // Register the maximum scroll position property
1206 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1207 // Register the scroll content size property
1208 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1210 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1212 // Set style name of ScrollBar for styling
1213 mScrollBar.SetStyleName("TextEditorScrollBar");
1214 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1217 // Set style name of ScrollBarIndicator for styling
1218 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1221 self.Add(mScrollBar);
1225 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1226 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1227 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1229 self.SetProperty(propertyScrollPosition, scrollPosition);
1230 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1231 self.SetProperty(propertyScrollContentSize, layoutSize);
1234 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1237 mScrollStarted = true;
1238 Dali::Toolkit::TextEditor handle(GetOwner());
1239 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1242 Actor indicator = mScrollBar.GetScrollIndicator();
1245 mAnimation.Stop(); // Cancel any animation
1249 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1251 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1252 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1254 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1257 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1259 // If animation is successfully ended, then emit ScrollStateChangedSignal
1260 if(Dali::EqualsZero(animation.GetCurrentProgress()))
1262 mScrollStarted = false;
1263 Dali::Toolkit::TextEditor handle(GetOwner());
1264 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1268 void TextEditor::OnSceneConnect(Dali::Actor actor)
1272 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1276 mHasBeenStaged = true;
1280 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1282 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1283 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1286 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1291 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1297 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1299 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1301 // Just hide the grab handle when keyboard is hidden.
1304 mController->KeyboardFocusLostEvent();
1308 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1312 void TextEditor::OnSceneConnection(int depth)
1314 // Sets the depth to the visuals inside the text's decorator.
1315 mDecorator->SetTextDepth(depth);
1317 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1319 // Call the Control::OnSceneConnection() to set the depth of the background.
1320 Control::OnSceneConnection(depth);
1323 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1328 void TextEditor::OnIdleSignal()
1330 // Emits the change of input style signals.
1331 mController->ProcessInputStyleChangedSignals();
1333 // Set the pointer to null as the callback manager deletes the callback after execute it.
1334 mIdleCallback = NULL;
1337 void TextEditor::ApplyScrollPosition()
1339 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1340 float scrollAmount = 0.0f;
1342 if(mScrollAnimationEnabled)
1344 scrollAmount = mController->GetScrollAmountByUserInput();
1346 if(mTextVerticalScroller)
1348 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1350 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1352 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1356 mTextVerticalScroller = Text::TextVerticalScroller::New();
1357 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1359 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1361 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1365 bool TextEditor::IsEditable() const
1367 return mController->IsEditable();
1370 void TextEditor::SetEditable(bool editable)
1372 mController->SetEditable(editable);
1373 if(mInputMethodContext && !editable)
1375 mInputMethodContext.Deactivate();
1379 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1381 mController->ChangedLayoutDirection();
1384 TextEditor::TextEditor(ControlBehaviour additionalBehaviour)
1385 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
1386 mAnimationPeriod(0.0f, 0.0f),
1387 mIdleCallback(NULL),
1388 mAlignmentOffset(0.f),
1389 mScrollAnimationDuration(0.f),
1391 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1392 mHasBeenStaged(false),
1393 mScrollAnimationEnabled(false),
1394 mScrollBarEnabled(false),
1395 mScrollStarted(false),
1396 mTextChanged(false),
1397 mCursorPositionChanged(false),
1398 mSelectionChanged(false),
1399 mSelectionCleared(false),
1401 mOldSelectionStart(0u),
1402 mOldSelectionEnd(0u),
1403 mSelectionStarted(false)
1407 TextEditor::~TextEditor()
1409 UnparentAndReset(mStencil);
1411 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1413 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1414 Adaptor::Get().RemoveIdle(mIdleCallback);
1418 std::string TextEditor::TextEditorAccessible::GetName() const
1420 return GetWholeText();
1423 const std::vector<Toolkit::TextAnchor>& TextEditor::TextEditorAccessible::GetTextAnchors() const
1425 auto self = Toolkit::TextEditor::DownCast(Self());
1427 return Toolkit::GetImpl(self).mAnchorActors;
1430 Toolkit::Text::ControllerPtr TextEditor::TextEditorAccessible::GetTextController() const
1432 auto self = Toolkit::TextEditor::DownCast(Self());
1434 return Toolkit::GetImpl(self).GetTextController();
1437 void TextEditor::TextEditorAccessible::RequestTextRelayout()
1439 auto self = Toolkit::TextEditor::DownCast(Self());
1440 auto& selfImpl = Toolkit::GetImpl(self);
1442 selfImpl.RequestTextRelayout();
1445 } // namespace Internal
1447 } // namespace Toolkit