2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/object/property-helper-devel.h>
25 #include <dali/integration-api/adaptor-framework/adaptor.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/key.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/object/type-registry-helper.h>
35 #include <dali-toolkit/devel-api/controls/control-devel.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
38 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
39 #include <dali-toolkit/internal/controls/text-controls/text-editor-property-handler.h>
40 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
45 #include <dali-toolkit/internal/text/text-font-style.h>
46 #include <dali-toolkit/internal/text/text-view.h>
47 #include <dali-toolkit/public-api/text/text-enumerations.h>
48 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
49 #include <dali-toolkit/public-api/visuals/visual-properties.h>
51 using namespace Dali::Toolkit::Text;
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextEditorLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
63 namespace // unnamed namespace
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
66 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
67 } // unnamed namespace
71 const char* const SCROLL_BAR_POSITION("sourcePosition");
72 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
73 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
74 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
79 return Toolkit::TextEditor::New();
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextEditor, Toolkit::Control, Create);
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "text", STRING, TEXT )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "underline", MAP, UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "shadow", MAP, SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "emboss", MAP, EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "outline", MAP, OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
130 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE )
131 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT )
132 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION )
133 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER )
134 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalScrollPosition", FLOAT, HORIZONTAL_SCROLL_POSITION )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING )
147 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT )
148 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
149 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
150 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
151 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
152 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
153 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
154 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFilter", MAP, INPUT_FILTER )
155 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsis", BOOLEAN, ELLIPSIS )
156 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
157 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "minLineSize", FLOAT, MIN_LINE_SIZE )
158 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", MAP, STRIKETHROUGH )
159 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
160 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "characterSpacing", FLOAT, CHARACTER_SPACING )
161 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE )
162 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
163 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionPopupStyle", MAP, SELECTION_POPUP_STYLE )
165 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
167 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
168 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
169 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
170 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
171 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
172 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
173 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionStarted", SIGNAL_SELECTION_STARTED )
175 DALI_TYPE_REGISTRATION_END()
178 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
180 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
182 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
184 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
186 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
188 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
190 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
192 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
194 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
196 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
198 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
200 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
202 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
204 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
206 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
208 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
210 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
212 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
214 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
216 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
218 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
220 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
222 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
224 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
226 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
228 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
231 return editorInputStyleMask;
236 Toolkit::TextEditor TextEditor::New(ControlBehaviour additionalBehaviour)
238 // Create the implementation, temporarily owned by this handle on stack
239 IntrusivePtr<TextEditor> impl = new TextEditor(additionalBehaviour);
241 // Pass ownership to CustomActor handle
242 Toolkit::TextEditor handle(*impl);
244 // Second-phase init of the implementation
245 // This can only be done after the CustomActor connection has been made...
251 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
253 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
255 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
259 PropertyHandler::SetProperty(textEditor, index, value);
263 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
265 Property::Value value;
267 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
271 value = PropertyHandler::GetProperty(textEditor, index);
276 void TextEditor::SelectWholeText()
278 if(mController && mController->IsShowingRealText())
280 mController->SelectWholeText();
285 void TextEditor::SelectNone()
287 if(mController && mController->IsShowingRealText())
289 mController->SelectNone();
293 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
295 if(mController && mController->IsShowingRealText())
297 mController->SelectText(start, end);
302 string TextEditor::CopyText()
304 string copiedText = "";
305 if(mController && mController->IsShowingRealText())
307 copiedText = mController->CopyText();
312 string TextEditor::CutText()
315 if(mController && mController->IsShowingRealText())
317 cutText = mController->CutText();
322 void TextEditor::PasteText()
326 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
327 mController->PasteText();
331 void TextEditor::ScrollBy(Vector2 scroll)
333 if(mController && mController->IsShowingRealText())
335 mController->ScrollBy(scroll);
339 float TextEditor::GetHorizontalScrollPosition()
341 if(mController && mController->IsShowingRealText())
343 return mController->GetHorizontalScrollPosition();
348 float TextEditor::GetVerticalScrollPosition()
350 if(mController && mController->IsShowingRealText())
352 return mController->GetVerticalScrollPosition();
357 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
359 return mController->GetTextSize(startIndex, endIndex);
362 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
364 return mController->GetTextPosition(startIndex, endIndex);
367 Rect<float> TextEditor::GetLineBoundingRectangle(const uint32_t lineIndex) const
369 return mController->GetLineBoundingRectangle(lineIndex);
372 Rect<float> TextEditor::GetCharacterBoundingRectangle(const uint32_t charIndex) const
374 return mController->GetCharacterBoundingRectangle(charIndex);
377 void TextEditor::SetSpannedText(const Text::Spanned& spannedText)
379 mController->SetSpannedText(spannedText);
382 string TextEditor::GetSelectedText() const
384 string selectedText = "";
385 if(mController && mController->IsShowingRealText())
387 selectedText = mController->GetSelectedText();
392 InputMethodContext TextEditor::GetInputMethodContext()
394 return mInputMethodContext;
397 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
399 return mMaxLengthReachedSignal;
402 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
404 return mAnchorClickedSignal;
407 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
409 return mCursorPositionChangedSignal;
412 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
414 return mInputFilteredSignal;
417 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
419 return mSelectionChangedSignal;
422 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
424 return mSelectionClearedSignal;
427 DevelTextEditor::SelectionStartedSignalType& TextEditor::SelectionStartedSignal()
429 return mSelectionStartedSignal;
432 Text::ControllerPtr TextEditor::GetTextController()
437 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
439 Dali::BaseHandle handle(object);
441 bool connected(true);
442 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
444 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
446 editor.TextChangedSignal().Connect(tracker, functor);
448 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
450 editor.InputStyleChangedSignal().Connect(tracker, functor);
452 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
456 Internal::TextEditor& editorImpl(GetImpl(editor));
457 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
460 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
464 Internal::TextEditor& editorImpl(GetImpl(editor));
465 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
468 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
472 Internal::TextEditor& editorImpl(GetImpl(editor));
473 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
476 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
480 Internal::TextEditor& editorImpl(GetImpl(editor));
481 editorImpl.InputFilteredSignal().Connect(tracker, functor);
484 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
488 Internal::TextEditor& editorImpl(GetImpl(editor));
489 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
492 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
496 Internal::TextEditor& editorImpl(GetImpl(editor));
497 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
500 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
504 Internal::TextEditor& editorImpl(GetImpl(editor));
505 editorImpl.SelectionStartedSignal().Connect(tracker, functor);
510 // signalName does not match any signal
517 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
519 return mTextChangedSignal;
522 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
524 return mInputStyleChangedSignal;
527 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
529 return mScrollStateChangedSignal;
532 void TextEditor::OnAccessibilityStatusChanged()
534 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
537 void TextEditor::OnInitialize()
541 mController = Text::Controller::New(this, this, this, this);
543 mDecorator = Text::Decorator::New(*mController,
546 mInputMethodContext = InputMethodContext::New(self);
548 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
550 // Enables the text input.
551 mController->EnableTextInput(mDecorator, mInputMethodContext);
553 // Enables the vertical scrolling after the text input has been enabled.
554 mController->SetVerticalScrollEnabled(true);
556 // Disables the horizontal scrolling.
557 mController->SetHorizontalScrollEnabled(false);
559 // Sets the maximum number of characters.
560 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
562 // Enable the smooth handle panning.
563 mController->SetSmoothHandlePanEnabled(true);
565 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
566 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
568 // Sets layoutDirection value
569 Dali::Stage stage = Dali::Stage::GetCurrent();
570 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
571 mController->SetLayoutDirection(layoutDirection);
573 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
575 // Forward input events to controller
576 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
577 GetTapGestureDetector().SetMaximumTapsRequired(2);
578 GetTapGestureDetector().ReceiveAllTapEvents(true);
580 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
582 // Set BoundingBox to stage size if not already set.
583 Rect<int> boundingBox;
584 mDecorator->GetBoundingBox(boundingBox);
586 if(boundingBox.IsEmpty())
588 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
589 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
592 // Whether to flip the selection handles as soon as they cross.
593 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
595 // Set the default scroll speed.
596 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
598 // Fill-parent area by default
599 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
600 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
601 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
603 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
605 // Creates an extra control to be used as stencil buffer.
606 mStencil = Control::New();
607 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
608 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
610 // Creates a background visual. Even if the color is transparent it updates the stencil.
611 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
612 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
614 // Enable the clipping property.
615 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
616 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
621 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY);
622 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
624 Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
625 Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
628 DevelControl::ControlAccessible* TextEditor::CreateAccessibleObject()
630 return new TextEditorAccessible(Self());
633 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
635 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
639 case StyleChange::DEFAULT_FONT_CHANGE:
641 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
642 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
643 // Property system did not set the font so should update it.
644 mController->UpdateAfterFontChange(newFont);
649 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
651 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
655 case StyleChange::THEME_CHANGE:
657 // Nothing to do, let control base class handle this
662 // Up call to Control
663 Control::OnStyleChange(styleManager, change);
666 Vector3 TextEditor::GetNaturalSize()
669 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
671 Vector3 naturalSize = mController->GetNaturalSize();
672 naturalSize.width += (padding.start + padding.end);
673 naturalSize.height += (padding.top + padding.bottom);
678 float TextEditor::GetHeightForWidth(float width)
681 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
682 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
685 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
687 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
689 actor.SetProperty(Actor::Property::SIZE, size);
693 void TextEditor::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
695 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnPropertySet index[%d]\n", index);
699 case DevelActor::Property::USER_INTERACTION_ENABLED:
701 const bool enabled = propertyValue.Get<bool>();
702 mController->SetUserInteractionEnabled(enabled);
705 float opacity = enabled ? 1.0f : mController->GetDisabledColorOpacity();
706 mStencil.SetProperty(Actor::Property::OPACITY, opacity);
712 Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
718 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
720 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
725 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
727 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
729 // Support Right-To-Left of padding
730 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
732 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
734 std::swap(padding.start, padding.end);
739 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
740 ResizeActor(mStencil, contentSize);
744 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
745 ResizeActor(mActiveLayer, contentSize);
749 mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
750 ResizeActor(mCursorLayer, contentSize);
753 // If there is text changed, callback is called.
756 EmitTextChangedSignal();
759 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
761 if((Text::Controller::NONE_UPDATED != updateTextType) ||
764 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
767 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
769 mDecorator->Relayout(contentSize);
774 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
777 RenderText(updateTextType);
780 if(mCursorPositionChanged)
782 EmitCursorPositionChangedSignal();
785 if(mSelectionStarted)
787 EmitSelectionStartedSignal();
790 if(mSelectionChanged)
792 EmitSelectionChangedSignal();
795 if(mSelectionCleared)
797 EmitSelectionClearedSignal();
800 // The text-editor emits signals when the input style changes. These changes of style are
801 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
802 // can't be emitted during the size negotiation as the callbacks may update the UI.
803 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
804 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
806 if(Adaptor::IsAvailable())
808 Adaptor& adaptor = Adaptor::Get();
810 if(NULL == mIdleCallback)
812 // @note: The callback manager takes the ownership of the callback object.
813 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
814 adaptor.AddIdle(mIdleCallback, false);
820 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
822 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mCursorLayer, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
825 ApplyScrollPosition();
830 void TextEditor::OnKeyInputFocusGained()
832 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
833 if(mInputMethodContext && IsEditable())
835 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
836 mInputMethodContext.ApplyOptions(mInputMethodOptions);
837 mInputMethodContext.NotifyTextInputMultiLine(true);
839 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
841 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
843 // Notify that the text editing start.
844 mInputMethodContext.Activate();
846 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
847 mInputMethodContext.SetRestoreAfterFocusLost(true);
849 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
853 notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
856 if(IsEditable() && mController->IsUserInteractionEnabled())
858 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
861 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
864 void TextEditor::OnKeyInputFocusLost()
866 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
867 if(mInputMethodContext)
869 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
871 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
872 mInputMethodContext.SetRestoreAfterFocusLost(false);
874 // Notify that the text editing finish.
875 mInputMethodContext.Deactivate();
877 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
879 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
883 notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
886 mController->KeyboardFocusLostEvent();
888 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
891 bool TextEditor::OnAccessibilityActivated()
897 void TextEditor::OnTap(const TapGesture& gesture)
899 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
900 if(mInputMethodContext && IsEditable())
902 mInputMethodContext.Activate();
904 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
906 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
907 const Vector2& localPoint = gesture.GetLocalPoint();
908 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
909 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
911 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
912 if(keyboardFocusManager)
914 keyboardFocusManager.SetCurrentFocusActor(Self());
919 void TextEditor::OnPan(const PanGesture& gesture)
921 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
922 if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement()))
924 Dali::DevelActor::SetNeedGesturePropagation(Self(), true);
928 void TextEditor::OnLongPress(const LongPressGesture& gesture)
930 if(mInputMethodContext && IsEditable())
932 mInputMethodContext.Activate();
935 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
936 const Vector2& localPoint = gesture.GetLocalPoint();
937 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
942 bool TextEditor::OnKeyEvent(const KeyEvent& event)
944 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
946 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
948 // Make sure ClearKeyInputFocus when only key is up
949 if(event.GetState() == KeyEvent::UP)
951 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
952 if(keyboardFocusManager)
954 keyboardFocusManager.ClearFocus();
956 ClearKeyInputFocus();
962 return mController->KeyEvent(event);
965 void TextEditor::RequestTextRelayout()
970 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
972 GetAccessibleObject()->EmitTextInserted(position, length, content);
975 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
977 GetAccessibleObject()->EmitTextDeleted(position, length, content);
980 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
982 GetAccessibleObject()->EmitTextCursorMoved(newPosition);
984 if((oldPosition != newPosition) && !mCursorPositionChanged)
986 mCursorPositionChanged = true;
987 mOldPosition = oldPosition;
991 void TextEditor::TextChanged(bool immediate)
993 if(immediate) // Emits TextChangedSignal immediately
995 EmitTextChangedSignal();
1003 void TextEditor::EmitTextChangedSignal()
1005 Dali::Toolkit::TextEditor handle(GetOwner());
1006 mTextChangedSignal.Emit(handle);
1007 mTextChanged = false;
1010 void TextEditor::MaxLengthReached()
1012 Dali::Toolkit::TextEditor handle(GetOwner());
1013 mMaxLengthReachedSignal.Emit(handle);
1016 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
1018 Dali::Toolkit::TextEditor handle(GetOwner());
1019 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
1022 void TextEditor::AnchorClicked(const std::string& href)
1024 Dali::Toolkit::TextEditor handle(GetOwner());
1025 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
1028 void TextEditor::EmitCursorPositionChangedSignal()
1030 Dali::Toolkit::TextEditor handle(GetOwner());
1031 mCursorPositionChanged = false;
1032 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
1035 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
1037 Dali::Toolkit::TextEditor handle(GetOwner());
1038 mInputFilteredSignal.Emit(handle, type);
1041 void TextEditor::EmitSelectionChangedSignal()
1043 Dali::Toolkit::TextEditor handle(GetOwner());
1044 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
1045 mSelectionChanged = false;
1048 void TextEditor::EmitSelectionClearedSignal()
1050 Dali::Toolkit::TextEditor handle(GetOwner());
1051 mSelectionClearedSignal.Emit(handle);
1052 mSelectionCleared = false;
1055 void TextEditor::EmitSelectionStartedSignal()
1057 Dali::Toolkit::TextEditor handle(GetOwner());
1058 mSelectionStartedSignal.Emit(handle);
1059 mSelectionStarted = false;
1062 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
1064 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
1066 if(newStart == newEnd)
1068 mSelectionCleared = true;
1072 if(oldStart == oldEnd)
1074 mSelectionStarted = true;
1078 mSelectionChanged = true;
1079 mOldSelectionStart = oldStart;
1080 mOldSelectionEnd = oldEnd;
1082 if(mOldSelectionStart > mOldSelectionEnd)
1085 uint32_t temp = mOldSelectionStart;
1086 mOldSelectionStart = mOldSelectionEnd;
1087 mOldSelectionEnd = temp;
1092 void TextEditor::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1098 mClippingDecorationActors.push_back(actor);
1101 // If the actor is a layer type, add it.
1102 if(type == DecorationType::ACTIVE_LAYER)
1104 AddLayer(mActiveLayer, actor);
1106 else if(type == DecorationType::CURSOR_LAYER)
1108 AddLayer(mCursorLayer, actor);
1113 void TextEditor::AddLayer(Actor& layer, Actor& actor)
1115 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1116 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1121 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1123 if(mController && mController->IsShowingRealText())
1125 mController->SetTextSelectionRange(start, end);
1130 Uint32Pair TextEditor::GetTextSelectionRange() const
1132 Uint32Pair range(0, 0);
1133 if(mController && mController->IsShowingRealText())
1135 range = mController->GetTextSelectionRange();
1140 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1142 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1143 Property::Map* resultMap = propValue.GetMap();
1145 Property::Value* colorValue = nullptr;
1146 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1148 colorValue->Get(color);
1152 void TextEditor::UpdateScrollBar()
1154 using namespace Dali;
1156 float scrollPosition;
1159 bool latestScrolled;
1161 if(!mScrollBarEnabled)
1165 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1166 if(!latestScrolled || controlSize > layoutSize)
1171 CustomActor self = Self();
1174 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1175 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1176 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1177 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1178 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1179 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1181 // Register the scroll position property
1182 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1183 // Register the minimum scroll position property
1184 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1185 // Register the maximum scroll position property
1186 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1187 // Register the scroll content size property
1188 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1190 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1192 // Set style name of ScrollBar for styling
1193 mScrollBar.SetStyleName("TextEditorScrollBar");
1194 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1197 // Set style name of ScrollBarIndicator for styling
1198 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1201 self.Add(mScrollBar);
1205 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1206 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1207 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1209 self.SetProperty(propertyScrollPosition, scrollPosition);
1210 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1211 self.SetProperty(propertyScrollContentSize, layoutSize);
1214 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1217 mScrollStarted = true;
1218 Dali::Toolkit::TextEditor handle(GetOwner());
1219 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1222 Actor indicator = mScrollBar.GetScrollIndicator();
1225 mAnimation.Stop(); // Cancel any animation
1229 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1231 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1232 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1234 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1237 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1239 // If animation is successfully ended, then emit ScrollStateChangedSignal
1240 if(animation.GetCurrentProgress() == 0.0f)
1242 mScrollStarted = false;
1243 Dali::Toolkit::TextEditor handle(GetOwner());
1244 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1248 void TextEditor::OnSceneConnect(Dali::Actor actor)
1252 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1256 mHasBeenStaged = true;
1260 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1262 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1263 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1266 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1271 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1277 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1279 mController->PasteClipboardItemEvent();
1282 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1284 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1286 // Just hide the grab handle when keyboard is hidden.
1289 mController->KeyboardFocusLostEvent();
1293 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1297 void TextEditor::OnSceneConnection(int depth)
1299 // Sets the depth to the visuals inside the text's decorator.
1300 mDecorator->SetTextDepth(depth);
1302 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1304 // Call the Control::OnSceneConnection() to set the depth of the background.
1305 Control::OnSceneConnection(depth);
1308 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1313 void TextEditor::OnIdleSignal()
1315 // Emits the change of input style signals.
1316 mController->ProcessInputStyleChangedSignals();
1318 // Set the pointer to null as the callback manager deletes the callback after execute it.
1319 mIdleCallback = NULL;
1322 void TextEditor::ApplyScrollPosition()
1324 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1325 float scrollAmount = 0.0f;
1327 if(mScrollAnimationEnabled)
1329 scrollAmount = mController->GetScrollAmountByUserInput();
1331 if(mTextVerticalScroller)
1333 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1335 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1337 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1341 mTextVerticalScroller = Text::TextVerticalScroller::New();
1342 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1344 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1346 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1350 bool TextEditor::IsEditable() const
1352 return mController->IsEditable();
1355 void TextEditor::SetEditable(bool editable)
1357 mController->SetEditable(editable);
1358 if(mInputMethodContext && !editable)
1360 mInputMethodContext.Deactivate();
1364 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1366 mController->ChangedLayoutDirection();
1369 TextEditor::TextEditor(ControlBehaviour additionalBehaviour)
1370 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
1371 mAnimationPeriod(0.0f, 0.0f),
1372 mIdleCallback(NULL),
1373 mAlignmentOffset(0.f),
1374 mScrollAnimationDuration(0.f),
1376 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1377 mHasBeenStaged(false),
1378 mScrollAnimationEnabled(false),
1379 mScrollBarEnabled(false),
1380 mScrollStarted(false),
1381 mTextChanged(false),
1382 mCursorPositionChanged(false),
1383 mSelectionChanged(false),
1384 mSelectionCleared(false),
1386 mOldSelectionStart(0u),
1387 mOldSelectionEnd(0u),
1388 mSelectionStarted(false)
1392 TextEditor::~TextEditor()
1394 UnparentAndReset(mStencil);
1396 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1398 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1399 Adaptor::Get().RemoveIdle(mIdleCallback);
1403 std::string TextEditor::TextEditorAccessible::GetName() const
1405 return GetWholeText();
1408 const std::vector<Toolkit::TextAnchor>& TextEditor::TextEditorAccessible::GetTextAnchors() const
1410 auto self = Toolkit::TextEditor::DownCast(Self());
1412 return Toolkit::GetImpl(self).mAnchorActors;
1415 Toolkit::Text::ControllerPtr TextEditor::TextEditorAccessible::GetTextController() const
1417 auto self = Toolkit::TextEditor::DownCast(Self());
1419 return Toolkit::GetImpl(self).GetTextController();
1422 void TextEditor::TextEditorAccessible::RequestTextRelayout()
1424 auto self = Toolkit::TextEditor::DownCast(Self());
1425 auto& selfImpl = Toolkit::GetImpl(self);
1427 selfImpl.RequestTextRelayout();
1430 } // namespace Internal
1432 } // namespace Toolkit