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 )
163 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
164 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
165 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
167 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
168 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
169 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
170 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
171 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionStarted", SIGNAL_SELECTION_STARTED )
173 DALI_TYPE_REGISTRATION_END()
176 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
178 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
180 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
182 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
184 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
186 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
188 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
190 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
192 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
194 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
196 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
198 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
200 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
202 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
204 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
206 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
208 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
210 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
212 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
214 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
216 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
218 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
220 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
222 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
224 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
226 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
229 return editorInputStyleMask;
234 Toolkit::TextEditor TextEditor::New()
236 // Create the implementation, temporarily owned by this handle on stack
237 IntrusivePtr<TextEditor> impl = new TextEditor();
239 // Pass ownership to CustomActor handle
240 Toolkit::TextEditor handle(*impl);
242 // Second-phase init of the implementation
243 // This can only be done after the CustomActor connection has been made...
249 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
251 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
253 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
257 PropertyHandler::SetProperty(textEditor, index, value);
261 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
263 Property::Value value;
265 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
269 value = PropertyHandler::GetProperty(textEditor, index);
274 void TextEditor::SelectWholeText()
276 if(mController && mController->IsShowingRealText())
278 mController->SelectWholeText();
283 void TextEditor::SelectNone()
285 if(mController && mController->IsShowingRealText())
287 mController->SelectNone();
291 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
293 if(mController && mController->IsShowingRealText())
295 mController->SelectText(start, end);
300 string TextEditor::CopyText()
302 string copiedText = "";
303 if(mController && mController->IsShowingRealText())
305 copiedText = mController->CopyText();
310 string TextEditor::CutText()
313 if(mController && mController->IsShowingRealText())
315 cutText = mController->CutText();
320 void TextEditor::PasteText()
324 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
325 mController->PasteText();
329 void TextEditor::ScrollBy(Vector2 scroll)
331 if(mController && mController->IsShowingRealText())
333 mController->ScrollBy(scroll);
337 float TextEditor::GetHorizontalScrollPosition()
339 if(mController && mController->IsShowingRealText())
341 return mController->GetHorizontalScrollPosition();
346 float TextEditor::GetVerticalScrollPosition()
348 if(mController && mController->IsShowingRealText())
350 return mController->GetVerticalScrollPosition();
355 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
357 return mController->GetTextSize(startIndex, endIndex);
360 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
362 return mController->GetTextPosition(startIndex, endIndex);
365 string TextEditor::GetSelectedText() const
367 string selectedText = "";
368 if(mController && mController->IsShowingRealText())
370 selectedText = mController->GetSelectedText();
375 InputMethodContext TextEditor::GetInputMethodContext()
377 return mInputMethodContext;
380 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
382 return mMaxLengthReachedSignal;
385 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
387 return mAnchorClickedSignal;
390 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
392 return mCursorPositionChangedSignal;
395 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
397 return mInputFilteredSignal;
400 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
402 return mSelectionChangedSignal;
405 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
407 return mSelectionClearedSignal;
410 DevelTextEditor::SelectionStartedSignalType& TextEditor::SelectionStartedSignal()
412 return mSelectionStartedSignal;
415 Text::ControllerPtr TextEditor::GetTextController()
420 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
422 Dali::BaseHandle handle(object);
424 bool connected(true);
425 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
427 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
429 editor.TextChangedSignal().Connect(tracker, functor);
431 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
433 editor.InputStyleChangedSignal().Connect(tracker, functor);
435 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
439 Internal::TextEditor& editorImpl(GetImpl(editor));
440 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
443 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
447 Internal::TextEditor& editorImpl(GetImpl(editor));
448 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
451 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
455 Internal::TextEditor& editorImpl(GetImpl(editor));
456 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
459 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
463 Internal::TextEditor& editorImpl(GetImpl(editor));
464 editorImpl.InputFilteredSignal().Connect(tracker, functor);
467 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
471 Internal::TextEditor& editorImpl(GetImpl(editor));
472 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
475 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
479 Internal::TextEditor& editorImpl(GetImpl(editor));
480 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
483 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
487 Internal::TextEditor& editorImpl(GetImpl(editor));
488 editorImpl.SelectionStartedSignal().Connect(tracker, functor);
493 // signalName does not match any signal
500 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
502 return mTextChangedSignal;
505 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
507 return mInputStyleChangedSignal;
510 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
512 return mScrollStateChangedSignal;
515 void TextEditor::OnAccessibilityStatusChanged()
517 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
520 void TextEditor::OnInitialize()
524 mController = Text::Controller::New(this, this, this, this);
526 mDecorator = Text::Decorator::New(*mController,
529 mInputMethodContext = InputMethodContext::New(self);
531 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
533 // Enables the text input.
534 mController->EnableTextInput(mDecorator, mInputMethodContext);
536 // Enables the vertical scrolling after the text input has been enabled.
537 mController->SetVerticalScrollEnabled(true);
539 // Disables the horizontal scrolling.
540 mController->SetHorizontalScrollEnabled(false);
542 // Sets the maximum number of characters.
543 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
545 // Enable the smooth handle panning.
546 mController->SetSmoothHandlePanEnabled(true);
548 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
549 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
551 // Sets layoutDirection value
552 Dali::Stage stage = Dali::Stage::GetCurrent();
553 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
554 mController->SetLayoutDirection(layoutDirection);
556 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
558 // Forward input events to controller
559 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
560 GetTapGestureDetector().SetMaximumTapsRequired(2);
561 GetTapGestureDetector().ReceiveAllTapEvents(true);
563 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
565 // Set BoundingBox to stage size if not already set.
566 Rect<int> boundingBox;
567 mDecorator->GetBoundingBox(boundingBox);
569 if(boundingBox.IsEmpty())
571 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
572 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
575 // Whether to flip the selection handles as soon as they cross.
576 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
578 // Set the default scroll speed.
579 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
581 // Fill-parent area by default
582 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
583 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
584 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
586 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
588 // Creates an extra control to be used as stencil buffer.
589 mStencil = Control::New();
590 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
591 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
593 // Creates a background visual. Even if the color is transparent it updates the stencil.
594 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
595 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
597 // Enable the clipping property.
598 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
599 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
604 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY);
605 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
607 Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
608 Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
611 DevelControl::ControlAccessible* TextEditor::CreateAccessibleObject()
613 return new TextEditorAccessible(Self());
616 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
618 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
622 case StyleChange::DEFAULT_FONT_CHANGE:
624 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
625 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
626 // Property system did not set the font so should update it.
627 mController->UpdateAfterFontChange(newFont);
632 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
634 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
638 case StyleChange::THEME_CHANGE:
640 // Nothing to do, let control base class handle this
645 // Up call to Control
646 Control::OnStyleChange(styleManager, change);
649 Vector3 TextEditor::GetNaturalSize()
652 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
654 Vector3 naturalSize = mController->GetNaturalSize();
655 naturalSize.width += (padding.start + padding.end);
656 naturalSize.height += (padding.top + padding.bottom);
661 float TextEditor::GetHeightForWidth(float width)
664 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
665 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
668 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
670 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
672 actor.SetProperty(Actor::Property::SIZE, size);
676 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
678 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
683 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
685 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
687 // Support Right-To-Left of padding
688 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
690 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
692 std::swap(padding.start, padding.end);
697 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
698 ResizeActor(mStencil, contentSize);
702 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
703 ResizeActor(mActiveLayer, contentSize);
707 mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
708 ResizeActor(mCursorLayer, contentSize);
711 // If there is text changed, callback is called.
714 EmitTextChangedSignal();
717 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
719 if((Text::Controller::NONE_UPDATED != updateTextType) ||
722 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
725 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
727 mDecorator->Relayout(contentSize);
732 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
735 RenderText(updateTextType);
738 if(mCursorPositionChanged)
740 EmitCursorPositionChangedSignal();
743 if(mSelectionStarted)
745 EmitSelectionStartedSignal();
748 if(mSelectionChanged)
750 EmitSelectionChangedSignal();
753 if(mSelectionCleared)
755 EmitSelectionClearedSignal();
758 // The text-editor emits signals when the input style changes. These changes of style are
759 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
760 // can't be emitted during the size negotiation as the callbacks may update the UI.
761 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
762 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
764 if(Adaptor::IsAvailable())
766 Adaptor& adaptor = Adaptor::Get();
768 if(NULL == mIdleCallback)
770 // @note: The callback manager takes the ownership of the callback object.
771 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
772 adaptor.AddIdle(mIdleCallback, false);
778 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
780 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mCursorLayer, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
783 ApplyScrollPosition();
788 void TextEditor::OnKeyInputFocusGained()
790 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
791 if(mInputMethodContext && IsEditable())
793 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
794 mInputMethodContext.ApplyOptions(mInputMethodOptions);
795 mInputMethodContext.NotifyTextInputMultiLine(true);
797 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
799 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
801 // Notify that the text editing start.
802 mInputMethodContext.Activate();
804 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
805 mInputMethodContext.SetRestoreAfterFocusLost(true);
807 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
811 notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
814 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
816 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
819 void TextEditor::OnKeyInputFocusLost()
821 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
822 if(mInputMethodContext)
824 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
826 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
827 mInputMethodContext.SetRestoreAfterFocusLost(false);
829 // Notify that the text editing finish.
830 mInputMethodContext.Deactivate();
832 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
834 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
838 notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
841 mController->KeyboardFocusLostEvent();
843 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
846 bool TextEditor::OnAccessibilityActivated()
852 void TextEditor::OnTap(const TapGesture& gesture)
854 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
855 if(mInputMethodContext && IsEditable())
857 mInputMethodContext.Activate();
859 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
861 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
862 const Vector2& localPoint = gesture.GetLocalPoint();
863 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
864 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
866 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
867 if (keyboardFocusManager)
869 keyboardFocusManager.SetCurrentFocusActor(Self());
874 void TextEditor::OnPan(const PanGesture& gesture)
876 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
879 void TextEditor::OnLongPress(const LongPressGesture& gesture)
881 if(mInputMethodContext && IsEditable())
883 mInputMethodContext.Activate();
886 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
887 const Vector2& localPoint = gesture.GetLocalPoint();
888 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
893 bool TextEditor::OnKeyEvent(const KeyEvent& event)
895 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
897 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
899 // Make sure ClearKeyInputFocus when only key is up
900 if(event.GetState() == KeyEvent::UP)
902 Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
903 if (keyboardFocusManager)
905 keyboardFocusManager.ClearFocus();
907 ClearKeyInputFocus();
913 return mController->KeyEvent(event);
916 void TextEditor::RequestTextRelayout()
921 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
923 GetAccessibleObject()->EmitTextInserted(position, length, content);
926 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
928 GetAccessibleObject()->EmitTextDeleted(position, length, content);
931 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
933 GetAccessibleObject()->EmitTextCursorMoved(newPosition);
935 if((oldPosition != newPosition) && !mCursorPositionChanged)
937 mCursorPositionChanged = true;
938 mOldPosition = oldPosition;
942 void TextEditor::TextChanged(bool immediate)
944 if(immediate) // Emits TextChangedSignal immediately
946 EmitTextChangedSignal();
954 void TextEditor::EmitTextChangedSignal()
956 Dali::Toolkit::TextEditor handle(GetOwner());
957 mTextChangedSignal.Emit(handle);
958 mTextChanged = false;
961 void TextEditor::MaxLengthReached()
963 Dali::Toolkit::TextEditor handle(GetOwner());
964 mMaxLengthReachedSignal.Emit(handle);
967 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
969 Dali::Toolkit::TextEditor handle(GetOwner());
970 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
973 void TextEditor::AnchorClicked(const std::string& href)
975 Dali::Toolkit::TextEditor handle(GetOwner());
976 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
979 void TextEditor::EmitCursorPositionChangedSignal()
981 Dali::Toolkit::TextEditor handle(GetOwner());
982 mCursorPositionChanged = false;
983 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
986 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
988 Dali::Toolkit::TextEditor handle(GetOwner());
989 mInputFilteredSignal.Emit(handle, type);
992 void TextEditor::EmitSelectionChangedSignal()
994 Dali::Toolkit::TextEditor handle(GetOwner());
995 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
996 mSelectionChanged = false;
999 void TextEditor::EmitSelectionClearedSignal()
1001 Dali::Toolkit::TextEditor handle(GetOwner());
1002 mSelectionClearedSignal.Emit(handle);
1003 mSelectionCleared = false;
1006 void TextEditor::EmitSelectionStartedSignal()
1008 Dali::Toolkit::TextEditor handle(GetOwner());
1009 mSelectionStartedSignal.Emit(handle);
1010 mSelectionStarted = false;
1013 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
1015 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
1017 if(newStart == newEnd)
1019 mSelectionCleared = true;
1023 if(oldStart == oldEnd)
1025 mSelectionStarted = true;
1029 mSelectionChanged = true;
1030 mOldSelectionStart = oldStart;
1031 mOldSelectionEnd = oldEnd;
1033 if(mOldSelectionStart > mOldSelectionEnd)
1036 uint32_t temp = mOldSelectionStart;
1037 mOldSelectionStart = mOldSelectionEnd;
1038 mOldSelectionEnd = temp;
1043 void TextEditor::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1049 mClippingDecorationActors.push_back(actor);
1052 // If the actor is a layer type, add it.
1053 if(type == DecorationType::ACTIVE_LAYER)
1055 AddLayer(mActiveLayer, actor);
1057 else if(type == DecorationType::CURSOR_LAYER)
1059 AddLayer(mCursorLayer, actor);
1064 void TextEditor::AddLayer(Actor& layer, Actor& actor)
1066 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1067 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1072 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1074 if(mController && mController->IsShowingRealText())
1076 mController->SetTextSelectionRange(start, end);
1081 Uint32Pair TextEditor::GetTextSelectionRange() const
1083 Uint32Pair range(0, 0);
1084 if(mController && mController->IsShowingRealText())
1086 range = mController->GetTextSelectionRange();
1091 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1093 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1094 Property::Map* resultMap = propValue.GetMap();
1096 Property::Value* colorValue = nullptr;
1097 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1099 colorValue->Get(color);
1103 void TextEditor::UpdateScrollBar()
1105 using namespace Dali;
1107 float scrollPosition;
1110 bool latestScrolled;
1112 if(!mScrollBarEnabled)
1116 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1117 if(!latestScrolled || controlSize > layoutSize)
1122 CustomActor self = Self();
1125 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1126 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1127 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1128 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1129 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1130 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1132 // Register the scroll position property
1133 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1134 // Register the minimum scroll position property
1135 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1136 // Register the maximum scroll position property
1137 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1138 // Register the scroll content size property
1139 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1141 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1143 // Set style name of ScrollBar for styling
1144 mScrollBar.SetStyleName("TextEditorScrollBar");
1145 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1148 // Set style name of ScrollBarIndicator for styling
1149 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1152 self.Add(mScrollBar);
1156 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1157 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1158 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1160 self.SetProperty(propertyScrollPosition, scrollPosition);
1161 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1162 self.SetProperty(propertyScrollContentSize, layoutSize);
1165 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1168 mScrollStarted = true;
1169 Dali::Toolkit::TextEditor handle(GetOwner());
1170 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1173 Actor indicator = mScrollBar.GetScrollIndicator();
1176 mAnimation.Stop(); // Cancel any animation
1180 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1182 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1183 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1185 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1188 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1190 // If animation is successfully ended, then emit ScrollStateChangedSignal
1191 if(animation.GetCurrentProgress() == 0.0f)
1193 mScrollStarted = false;
1194 Dali::Toolkit::TextEditor handle(GetOwner());
1195 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1199 void TextEditor::OnSceneConnect(Dali::Actor actor)
1203 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1207 mHasBeenStaged = true;
1211 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1213 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1214 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1217 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1222 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1228 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1230 mController->PasteClipboardItemEvent();
1233 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1235 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1237 // Just hide the grab handle when keyboard is hidden.
1240 mController->KeyboardFocusLostEvent();
1244 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1248 void TextEditor::OnSceneConnection(int depth)
1250 // Sets the depth to the visuals inside the text's decorator.
1251 mDecorator->SetTextDepth(depth);
1253 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1255 // Call the Control::OnSceneConnection() to set the depth of the background.
1256 Control::OnSceneConnection(depth);
1259 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1264 void TextEditor::OnIdleSignal()
1266 // Emits the change of input style signals.
1267 mController->ProcessInputStyleChangedSignals();
1269 // Set the pointer to null as the callback manager deletes the callback after execute it.
1270 mIdleCallback = NULL;
1273 void TextEditor::ApplyScrollPosition()
1275 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1276 float scrollAmount = 0.0f;
1278 if(mScrollAnimationEnabled)
1280 scrollAmount = mController->GetScrollAmountByUserInput();
1282 if(mTextVerticalScroller)
1284 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1286 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1288 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1292 mTextVerticalScroller = Text::TextVerticalScroller::New();
1293 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1295 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1297 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1301 bool TextEditor::IsEditable() const
1303 return mController->IsEditable();
1306 void TextEditor::SetEditable(bool editable)
1308 mController->SetEditable(editable);
1309 if(mInputMethodContext && !editable)
1311 mInputMethodContext.Deactivate();
1315 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1317 mController->ChangedLayoutDirection();
1320 TextEditor::TextEditor()
1321 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1322 mAnimationPeriod(0.0f, 0.0f),
1323 mIdleCallback(NULL),
1324 mAlignmentOffset(0.f),
1325 mScrollAnimationDuration(0.f),
1327 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1328 mHasBeenStaged(false),
1329 mScrollAnimationEnabled(false),
1330 mScrollBarEnabled(false),
1331 mScrollStarted(false),
1332 mTextChanged(false),
1333 mCursorPositionChanged(false),
1334 mSelectionChanged(false),
1335 mSelectionCleared(false),
1337 mOldSelectionStart(0u),
1338 mOldSelectionEnd(0u),
1339 mSelectionStarted(false)
1343 TextEditor::~TextEditor()
1345 UnparentAndReset(mStencil);
1347 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1349 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1350 Adaptor::Get().RemoveIdle(mIdleCallback);
1354 std::string TextEditor::TextEditorAccessible::GetName() const
1356 return GetWholeText();
1359 const std::vector<Toolkit::TextAnchor>& TextEditor::TextEditorAccessible::GetTextAnchors() const
1361 auto self = Toolkit::TextEditor::DownCast(Self());
1363 return Toolkit::GetImpl(self).mAnchorActors;
1366 Toolkit::Text::ControllerPtr TextEditor::TextEditorAccessible::GetTextController() const
1368 auto self = Toolkit::TextEditor::DownCast(Self());
1370 return Toolkit::GetImpl(self).GetTextController();
1373 void TextEditor::TextEditorAccessible::RequestTextRelayout()
1375 auto self = Toolkit::TextEditor::DownCast(Self());
1376 auto& selfImpl = Toolkit::GetImpl(self);
1378 selfImpl.RequestTextRelayout();
1381 } // namespace Internal
1383 } // namespace Toolkit