2 * Copyright (c) 2021 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/adaptor-framework/key.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/object/type-registry-helper.h>
34 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.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/text-editor-property-handler.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/public-api/text/text-enumerations.h>
47 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
48 #include <dali-toolkit/public-api/visuals/visual-properties.h>
50 using namespace Dali::Toolkit::Text;
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gTextEditorLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
62 namespace // unnamed namespace
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
65 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
66 } // unnamed namespace
70 const char* const SCROLL_BAR_POSITION("sourcePosition");
71 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
72 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
73 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
78 return Toolkit::TextEditor::New();
82 // Setup properties, signals and actions using the type-registry.
83 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextEditor, Toolkit::Control, Create);
85 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "text", STRING, TEXT )
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "underline", MAP, UNDERLINE )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "emboss", MAP, EMBOSS )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT )
131 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION )
132 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER )
133 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
134 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalScrollPosition", FLOAT, HORIZONTAL_SCROLL_POSITION )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING )
146 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT )
147 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
148 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
149 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
150 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
151 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
152 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFilter", MAP, INPUT_FILTER )
153 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsis", BOOLEAN, ELLIPSIS )
154 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
155 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "minLineSize", FLOAT, MIN_LINE_SIZE )
157 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
158 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
159 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
160 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
161 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
162 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
163 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
164 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
166 DALI_TYPE_REGISTRATION_END()
171 Toolkit::TextEditor TextEditor::New()
173 // Create the implementation, temporarily owned by this handle on stack
174 IntrusivePtr<TextEditor> impl = new TextEditor();
176 // Pass ownership to CustomActor handle
177 Toolkit::TextEditor handle(*impl);
179 // Second-phase init of the implementation
180 // This can only be done after the CustomActor connection has been made...
186 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
188 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
190 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
194 PropertyHandler::SetProperty(textEditor, index, value);
198 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
200 Property::Value value;
202 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
206 value = PropertyHandler::GetProperty(textEditor, index);
211 void TextEditor::SelectWholeText()
213 if(mController && mController->IsShowingRealText())
215 mController->SelectWholeText();
220 void TextEditor::SelectNone()
222 if(mController && mController->IsShowingRealText())
224 mController->SelectNone();
228 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
230 if(mController && mController->IsShowingRealText())
232 mController->SelectText(start, end);
237 string TextEditor::CopyText()
239 string copiedText = "";
240 if(mController && mController->IsShowingRealText())
242 copiedText = mController->CopyText();
247 string TextEditor::CutText()
250 if(mController && mController->IsShowingRealText())
252 cutText = mController->CutText();
257 void TextEditor::PasteText()
261 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
262 mController->PasteText();
266 void TextEditor::ScrollBy(Vector2 scroll)
268 if(mController && mController->IsShowingRealText())
270 mController->ScrollBy(scroll);
274 float TextEditor::GetHorizontalScrollPosition()
276 if(mController && mController->IsShowingRealText())
278 return mController->GetHorizontalScrollPosition();
283 float TextEditor::GetVerticalScrollPosition()
285 if(mController && mController->IsShowingRealText())
287 return mController->GetVerticalScrollPosition();
292 string TextEditor::GetSelectedText() const
294 string selectedText = "";
295 if(mController && mController->IsShowingRealText())
297 selectedText = mController->GetSelectedText();
302 InputMethodContext TextEditor::GetInputMethodContext()
304 return mInputMethodContext;
307 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
309 return mMaxLengthReachedSignal;
312 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
314 return mAnchorClickedSignal;
317 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
319 return mCursorPositionChangedSignal;
322 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
324 return mInputFilteredSignal;
327 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
329 return mSelectionChangedSignal;
332 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
334 return mSelectionClearedSignal;
337 Text::ControllerPtr TextEditor::GetTextController()
342 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
344 Dali::BaseHandle handle(object);
346 bool connected(true);
347 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
349 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
351 editor.TextChangedSignal().Connect(tracker, functor);
353 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
355 editor.InputStyleChangedSignal().Connect(tracker, functor);
357 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
361 Internal::TextEditor& editorImpl(GetImpl(editor));
362 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
365 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
369 Internal::TextEditor& editorImpl(GetImpl(editor));
370 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
373 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
377 Internal::TextEditor& editorImpl(GetImpl(editor));
378 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
381 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
385 Internal::TextEditor& editorImpl(GetImpl(editor));
386 editorImpl.InputFilteredSignal().Connect(tracker, functor);
389 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
393 Internal::TextEditor& editorImpl(GetImpl(editor));
394 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
397 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
401 Internal::TextEditor& editorImpl(GetImpl(editor));
402 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
407 // signalName does not match any signal
414 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
416 return mTextChangedSignal;
419 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
421 return mInputStyleChangedSignal;
424 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
426 return mScrollStateChangedSignal;
429 void TextEditor::OnInitialize()
433 mController = Text::Controller::New(this, this, this, this);
435 mDecorator = Text::Decorator::New(*mController,
438 mInputMethodContext = InputMethodContext::New(self);
440 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
442 // Enables the text input.
443 mController->EnableTextInput(mDecorator, mInputMethodContext);
445 // Enables the vertical scrolling after the text input has been enabled.
446 mController->SetVerticalScrollEnabled(true);
448 // Disables the horizontal scrolling.
449 mController->SetHorizontalScrollEnabled(false);
451 // Sets the maximum number of characters.
452 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
454 // Enable the smooth handle panning.
455 mController->SetSmoothHandlePanEnabled(true);
457 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
458 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
460 // Sets layoutDirection value
461 Dali::Stage stage = Dali::Stage::GetCurrent();
462 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
463 mController->SetLayoutDirection(layoutDirection);
465 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
467 // Forward input events to controller
468 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
469 GetTapGestureDetector().SetMaximumTapsRequired(2);
470 GetTapGestureDetector().ReceiveAllTapEvents(true);
472 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
474 // Set BoundingBox to stage size if not already set.
475 Rect<int> boundingBox;
476 mDecorator->GetBoundingBox(boundingBox);
478 if(boundingBox.IsEmpty())
480 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
481 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
484 // Whether to flip the selection handles as soon as they cross.
485 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
487 // Set the default scroll speed.
488 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
490 // Fill-parent area by default
491 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
492 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
493 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
495 //Enable highightability
496 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
498 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
500 // Creates an extra control to be used as stencil buffer.
501 mStencil = Control::New();
502 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
503 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
505 // Creates a background visual. Even if the color is transparent it updates the stencil.
506 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
507 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
509 // Enable the clipping property.
510 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
511 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
515 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
516 return std::unique_ptr<Dali::Accessibility::Accessible>(
517 new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
521 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
523 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
527 case StyleChange::DEFAULT_FONT_CHANGE:
529 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
530 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
531 // Property system did not set the font so should update it.
532 mController->UpdateAfterFontChange(newFont);
537 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
539 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
543 case StyleChange::THEME_CHANGE:
545 // Nothing to do, let control base class handle this
550 // Up call to Control
551 Control::OnStyleChange(styleManager, change);
554 Vector3 TextEditor::GetNaturalSize()
557 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
559 Vector3 naturalSize = mController->GetNaturalSize();
560 naturalSize.width += (padding.start + padding.end);
561 naturalSize.height += (padding.top + padding.bottom);
566 float TextEditor::GetHeightForWidth(float width)
569 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
570 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
573 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
575 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
577 actor.SetProperty(Actor::Property::SIZE, size);
581 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
583 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
588 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
590 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
592 // Support Right-To-Left of padding
593 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
595 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
597 std::swap(padding.start, padding.end);
602 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
603 ResizeActor(mStencil, contentSize);
607 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
608 ResizeActor(mActiveLayer, contentSize);
611 // If there is text changed, callback is called.
614 EmitTextChangedSignal();
617 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
619 if((Text::Controller::NONE_UPDATED != updateTextType) ||
622 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
625 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
627 mDecorator->Relayout(contentSize);
632 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
635 RenderText(updateTextType);
638 if(mCursorPositionChanged)
640 EmitCursorPositionChangedSignal();
643 if(mSelectionChanged)
645 EmitSelectionChangedSignal();
648 if(mSelectionCleared)
650 EmitSelectionClearedSignal();
653 // The text-editor emits signals when the input style changes. These changes of style are
654 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
655 // can't be emitted during the size negotiation as the callbacks may update the UI.
656 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
657 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
659 if(Adaptor::IsAvailable())
661 Adaptor& adaptor = Adaptor::Get();
663 if(NULL == mIdleCallback)
665 // @note: The callback manager takes the ownership of the callback object.
666 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
667 adaptor.AddIdle(mIdleCallback, false);
673 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
675 Actor renderableActor;
677 if(Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType))
681 Dali::Toolkit::TextEditor handle = Dali::Toolkit::TextEditor(GetOwner());
683 renderableActor = mRenderer->Render(mController->GetView(),
685 Property::INVALID_INDEX, // Animatable property not supported
687 DepthIndex::CONTENT);
690 if(renderableActor != mRenderableActor)
692 UnparentAndReset(mBackgroundActor);
693 UnparentAndReset(mRenderableActor);
694 mRenderableActor = renderableActor;
698 mBackgroundActor = mController->CreateBackgroundActor();
705 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
707 float renderableActorPositionX, renderableActorPositionY;
711 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
712 renderableActorPositionY = scrollOffset.y;
717 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
719 // Support Right-To-Left of padding
720 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
721 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
723 std::swap(padding.start, padding.end);
726 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
727 renderableActorPositionY = scrollOffset.y + padding.top;
730 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(renderableActorPositionX, renderableActorPositionY));
731 // Make sure the actors are parented correctly with/without clipping
732 Actor self = mStencil ? mStencil : Self();
734 Actor highlightActor;
736 for(std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
737 endIt = mClippingDecorationActors.end();
744 if(it->GetProperty<std::string>(Dali::Actor::Property::NAME) == "HighlightActor")
746 highlightActor = *it;
749 mClippingDecorationActors.clear();
751 self.Add(mRenderableActor);
755 if(mDecorator && mDecorator->IsHighlightVisible())
757 self.Add(mBackgroundActor);
758 mBackgroundActor.SetProperty(Actor::Property::POSITION, Vector2(renderableActorPositionX, renderableActorPositionY)); // In text field's coords.
759 mBackgroundActor.LowerBelow(highlightActor);
763 mRenderableActor.Add(mBackgroundActor);
764 mBackgroundActor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); // In renderable actor's coords.
765 mBackgroundActor.LowerToBottom();
769 ApplyScrollPosition();
774 void TextEditor::OnKeyInputFocusGained()
776 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
777 if(mInputMethodContext && IsEditable())
779 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
780 mInputMethodContext.ApplyOptions(mInputMethodOptions);
781 mInputMethodContext.NotifyTextInputMultiLine(true);
783 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
785 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
787 // Notify that the text editing start.
788 mInputMethodContext.Activate();
790 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
791 mInputMethodContext.SetRestoreAfterFocusLost(true);
793 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
797 notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
800 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
802 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
805 void TextEditor::OnKeyInputFocusLost()
807 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
808 if(mInputMethodContext)
810 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
812 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
813 mInputMethodContext.SetRestoreAfterFocusLost(false);
815 // Notify that the text editing finish.
816 mInputMethodContext.Deactivate();
818 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
820 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
824 notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
827 mController->KeyboardFocusLostEvent();
829 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
832 bool TextEditor::OnAccessibilityActivated()
838 void TextEditor::OnTap(const TapGesture& gesture)
840 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
841 if(mInputMethodContext && IsEditable())
843 mInputMethodContext.Activate();
845 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
847 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
848 const Vector2& localPoint = gesture.GetLocalPoint();
849 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
850 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
855 void TextEditor::OnPan(const PanGesture& gesture)
857 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
860 void TextEditor::OnLongPress(const LongPressGesture& gesture)
862 if(mInputMethodContext && IsEditable())
864 mInputMethodContext.Activate();
867 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
868 const Vector2& localPoint = gesture.GetLocalPoint();
869 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
874 bool TextEditor::OnKeyEvent(const KeyEvent& event)
876 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
878 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
880 // Make sure ClearKeyInputFocus when only key is up
881 if(event.GetState() == KeyEvent::UP)
883 ClearKeyInputFocus();
889 return mController->KeyEvent(event);
892 void TextEditor::RequestTextRelayout()
897 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
899 if(Accessibility::IsUp())
901 Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
905 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
907 if(Accessibility::IsUp())
909 Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
913 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
915 if(Accessibility::IsUp())
917 Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
920 if((oldPosition != newPosition) && !mCursorPositionChanged)
922 mCursorPositionChanged = true;
923 mOldPosition = oldPosition;
927 void TextEditor::TextChanged(bool immediate)
929 if(immediate) // Emits TextChangedSignal immediately
931 EmitTextChangedSignal();
939 void TextEditor::EmitTextChangedSignal()
941 Dali::Toolkit::TextEditor handle(GetOwner());
942 mTextChangedSignal.Emit(handle);
943 mTextChanged = false;
946 void TextEditor::MaxLengthReached()
948 Dali::Toolkit::TextEditor handle(GetOwner());
949 mMaxLengthReachedSignal.Emit(handle);
952 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
954 Dali::Toolkit::TextEditor handle(GetOwner());
956 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
958 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
960 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
962 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
964 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
966 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
968 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
970 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
972 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
974 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
976 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
978 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
980 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
982 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
984 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
986 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
988 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
990 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
992 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
994 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
996 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
998 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
1000 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
1003 mInputStyleChangedSignal.Emit(handle, editorInputStyleMask);
1006 void TextEditor::AnchorClicked(const std::string& href)
1008 Dali::Toolkit::TextEditor handle(GetOwner());
1009 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
1012 void TextEditor::EmitCursorPositionChangedSignal()
1014 Dali::Toolkit::TextEditor handle(GetOwner());
1015 mCursorPositionChanged = false;
1016 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
1019 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
1021 Dali::Toolkit::TextEditor handle(GetOwner());
1022 mInputFilteredSignal.Emit(handle, type);
1025 void TextEditor::EmitSelectionChangedSignal()
1027 Dali::Toolkit::TextEditor handle(GetOwner());
1028 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
1029 mSelectionChanged = false;
1032 void TextEditor::EmitSelectionClearedSignal()
1034 Dali::Toolkit::TextEditor handle(GetOwner());
1035 mSelectionClearedSignal.Emit(handle);
1036 mSelectionCleared = false;
1039 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
1041 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
1043 if(newStart == newEnd)
1045 mSelectionCleared = true;
1048 mSelectionChanged = true;
1049 mOldSelectionStart = oldStart;
1050 mOldSelectionEnd = oldEnd;
1052 if(mOldSelectionStart > mOldSelectionEnd)
1055 uint32_t temp = mOldSelectionStart;
1056 mOldSelectionStart = mOldSelectionEnd;
1057 mOldSelectionEnd = temp;
1062 void TextEditor::AddDecoration(Actor& actor, bool needsClipping)
1068 mClippingDecorationActors.push_back(actor);
1072 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1073 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1075 mActiveLayer = actor;
1080 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1082 if(mController && mController->IsShowingRealText())
1084 mController->SetTextSelectionRange(start, end);
1089 Uint32Pair TextEditor::GetTextSelectionRange() const
1091 Uint32Pair range(0, 0);
1092 if(mController && mController->IsShowingRealText())
1094 range = mController->GetTextSelectionRange();
1099 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1101 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1102 Property::Map* resultMap = propValue.GetMap();
1104 Property::Value* colorValue = nullptr;
1105 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1107 colorValue->Get(color);
1111 void TextEditor::UpdateScrollBar()
1113 using namespace Dali;
1115 float scrollPosition;
1118 bool latestScrolled;
1120 if(!mScrollBarEnabled)
1124 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1125 if(!latestScrolled || controlSize > layoutSize)
1130 CustomActor self = Self();
1133 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1134 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1135 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1136 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1137 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1138 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1140 // Register the scroll position property
1141 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1142 // Register the minimum scroll position property
1143 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1144 // Register the maximum scroll position property
1145 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1146 // Register the scroll content size property
1147 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1149 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1151 // Set style name of ScrollBar for styling
1152 mScrollBar.SetStyleName("TextEditorScrollBar");
1153 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1156 // Set style name of ScrollBarIndicator for styling
1157 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1160 self.Add(mScrollBar);
1164 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1165 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1166 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1168 self.SetProperty(propertyScrollPosition, scrollPosition);
1169 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1170 self.SetProperty(propertyScrollContentSize, layoutSize);
1173 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1176 mScrollStarted = true;
1177 Dali::Toolkit::TextEditor handle(GetOwner());
1178 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1181 Actor indicator = mScrollBar.GetScrollIndicator();
1184 mAnimation.Stop(); // Cancel any animation
1188 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1190 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1191 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1193 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1196 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1198 // If animation is successfully ended, then emit ScrollStateChangedSignal
1199 if(animation.GetCurrentProgress() == 0.0f)
1201 mScrollStarted = false;
1202 Dali::Toolkit::TextEditor handle(GetOwner());
1203 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1207 void TextEditor::OnSceneConnect(Dali::Actor actor)
1211 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1215 mHasBeenStaged = true;
1219 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1221 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1222 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1225 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1230 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1236 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1238 mController->PasteClipboardItemEvent();
1241 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1243 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1245 // Just hide the grab handle when keyboard is hidden.
1248 mController->KeyboardFocusLostEvent();
1252 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1256 void TextEditor::OnSceneConnection(int depth)
1258 // Sets the depth to the visuals inside the text's decorator.
1259 mDecorator->SetTextDepth(depth);
1261 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1263 // Call the Control::OnSceneConnection() to set the depth of the background.
1264 Control::OnSceneConnection(depth);
1267 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1272 void TextEditor::OnIdleSignal()
1274 // Emits the change of input style signals.
1275 mController->ProcessInputStyleChangedSignals();
1277 // Set the pointer to null as the callback manager deletes the callback after execute it.
1278 mIdleCallback = NULL;
1281 void TextEditor::ApplyScrollPosition()
1283 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1284 float scrollAmount = 0.0f;
1286 if(mScrollAnimationEnabled)
1288 scrollAmount = mController->GetScrollAmountByUserInput();
1290 if(mTextVerticalScroller)
1292 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1294 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1296 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1300 mTextVerticalScroller = Text::TextVerticalScroller::New();
1301 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1303 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1305 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1309 bool TextEditor::IsEditable() const
1311 return mController->IsEditable();
1314 void TextEditor::SetEditable(bool editable)
1316 mController->SetEditable(editable);
1317 if(mInputMethodContext && !editable)
1319 mInputMethodContext.Deactivate();
1323 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1325 mController->ChangedLayoutDirection();
1328 TextEditor::TextEditor()
1329 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1330 mAnimationPeriod(0.0f, 0.0f),
1331 mIdleCallback(NULL),
1332 mAlignmentOffset(0.f),
1333 mScrollAnimationDuration(0.f),
1335 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1336 mHasBeenStaged(false),
1337 mScrollAnimationEnabled(false),
1338 mScrollBarEnabled(false),
1339 mScrollStarted(false),
1340 mTextChanged(false),
1341 mCursorPositionChanged(false),
1342 mSelectionChanged(false),
1343 mSelectionCleared(false),
1345 mOldSelectionStart(0u),
1346 mOldSelectionEnd(0u)
1350 TextEditor::~TextEditor()
1352 UnparentAndReset(mStencil);
1354 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1356 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1357 Adaptor::Get().RemoveIdle(mIdleCallback);
1361 std::string TextEditor::AccessibleImpl::GetName()
1363 auto self = Toolkit::TextEditor::DownCast(Self());
1364 return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1367 std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset)
1369 if(endOffset <= startOffset)
1374 auto self = Toolkit::TextEditor::DownCast(Self());
1375 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1377 if(startOffset > text.size() || endOffset > text.size())
1382 return text.substr(startOffset, endOffset - startOffset);
1385 size_t TextEditor::AccessibleImpl::GetCharacterCount()
1387 auto self = Toolkit::TextEditor::DownCast(Self());
1388 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1393 size_t TextEditor::AccessibleImpl::GetCursorOffset()
1395 auto slf = Toolkit::TextEditor::DownCast(Self());
1396 return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition();
1399 bool TextEditor::AccessibleImpl::SetCursorOffset(size_t offset)
1401 auto slf = Toolkit::TextEditor::DownCast(Self());
1402 auto txt = slf.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1403 if(offset > txt.size())
1408 auto& slfImpl = Dali::Toolkit::GetImpl(slf);
1409 slfImpl.GetTextController()->ResetCursorPosition(offset);
1410 slfImpl.RequestTextRelayout();
1415 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary)
1417 auto self = Toolkit::TextEditor::DownCast(Self());
1418 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1419 auto textSize = text.size();
1421 auto range = Dali::Accessibility::Range{};
1425 case Dali::Accessibility::TextBoundary::CHARACTER:
1427 if(offset < textSize)
1429 range.content = text[offset];
1430 range.startOffset = offset;
1431 range.endOffset = offset + 1;
1435 case Dali::Accessibility::TextBoundary::WORD:
1436 case Dali::Accessibility::TextBoundary::LINE:
1438 auto textString = text.c_str();
1439 auto breaks = std::vector<char>(textSize, 0);
1441 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1443 Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1447 Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1452 while(index < textSize && counter <= offset)
1457 while(breaks[index])
1465 if(boundary == Dali::Accessibility::TextBoundary::WORD)
1469 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1475 if((counter > 0) && ((counter - 1) == offset))
1477 range.content = text.substr(start, index - start + 1);
1478 range.startOffset = start;
1479 range.endOffset = index + 1;
1482 if(boundary == Dali::Accessibility::TextBoundary::LINE)
1489 case Dali::Accessibility::TextBoundary::SENTENCE:
1491 /* not supported by default */
1494 case Dali::Accessibility::TextBoundary::PARAGRAPH:
1496 /* Paragraph is not supported by libunibreak library */
1506 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex)
1508 // Since DALi supports only one selection indexes higher than 0 are ignored
1509 if(selectionIndex > 0)
1514 auto self = Toolkit::TextEditor::DownCast(Self());
1515 auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1516 std::string value{};
1517 controller->RetrieveSelection(value);
1518 auto indices = controller->GetSelectionIndexes();
1520 return {static_cast<size_t>(indices.first), static_cast<size_t>(indices.second), value};
1523 bool TextEditor::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1525 // Since DALi supports only one selection indexes higher than 0 are ignored
1526 if(selectionIndex > 0)
1531 auto self = Toolkit::TextEditor::DownCast(Self());
1532 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1536 bool TextEditor::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1538 // Since DALi supports only one selection indexes higher than 0 are ignored
1539 if(selectionIndex > 0)
1544 auto self = Toolkit::TextEditor::DownCast(Self());
1545 Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1549 bool TextEditor::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1551 if(endPosition <= startPosition)
1556 auto self = Toolkit::TextEditor::DownCast(Self());
1557 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1558 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1563 bool TextEditor::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1565 if(endPosition <= startPosition)
1570 auto self = Toolkit::TextEditor::DownCast(Self());
1571 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1572 Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1574 self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1579 bool TextEditor::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1581 if(endPosition <= startPosition)
1586 auto self = Toolkit::TextEditor::DownCast(Self());
1587 auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1589 self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1594 Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates()
1596 using namespace Dali::Accessibility;
1598 auto states = DevelControl::AccessibleImpl::CalculateStates();
1599 states[State::EDITABLE] = true;
1600 states[State::FOCUSABLE] = true;
1602 Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1603 if(mSelf == focusControl)
1605 states[State::FOCUSED] = true;
1611 bool TextEditor::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1613 auto self = Toolkit::TextEditor::DownCast(Self());
1614 auto insertedText = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1616 insertedText.insert(startPosition, text);
1618 self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(insertedText));
1623 bool TextEditor::AccessibleImpl::SetTextContents(std::string newContents)
1625 auto self = Toolkit::TextEditor::DownCast(Self());
1626 self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents));
1630 } // namespace Internal
1632 } // namespace Toolkit