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/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/public-api/text/text-enumerations.h>
47 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
48 #include <dali-toolkit/public-api/visuals/visual-properties.h>
50 using namespace Dali::Toolkit::Text;
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gTextEditorLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
62 namespace // unnamed namespace
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
65 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
66 } // unnamed namespace
70 const char* const SCROLL_BAR_POSITION("sourcePosition");
71 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
72 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
73 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
78 return Toolkit::TextEditor::New();
82 // Setup properties, signals and actions using the type-registry.
83 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextEditor, Toolkit::Control, Create);
85 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "text", STRING, TEXT )
86 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
87 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
88 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
89 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
90 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
92 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
93 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
96 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
97 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
98 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
99 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
100 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
101 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
102 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
103 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "underline", MAP, UNDERLINE )
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "emboss", MAP, EMBOSS )
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT )
131 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION )
132 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER )
133 DALI_PROPERTY_REGISTRATION(Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
134 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "horizontalScrollPosition", FLOAT, HORIZONTAL_SCROLL_POSITION )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING )
146 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT )
147 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
148 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableFontSizeScale", BOOLEAN, ENABLE_FONT_SIZE_SCALE )
149 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
150 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
151 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
152 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
153 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputFilter", MAP, INPUT_FILTER )
154 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsis", BOOLEAN, ELLIPSIS )
155 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
156 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "minLineSize", FLOAT, MIN_LINE_SIZE )
157 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", MAP, STRIKETHROUGH )
158 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
159 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "characterSpacing", FLOAT, CHARACTER_SPACING )
160 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE )
162 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
163 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
164 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
165 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked", SIGNAL_ANCHOR_CLICKED )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered", SIGNAL_INPUT_FILTERED )
167 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
168 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged", SIGNAL_SELECTION_CHANGED )
169 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared", SIGNAL_SELECTION_CLEARED )
170 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionStarted", SIGNAL_SELECTION_STARTED )
172 DALI_TYPE_REGISTRATION_END()
175 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
177 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
179 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
181 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
183 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
185 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
187 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
189 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
191 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
193 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
195 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
197 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
199 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
201 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
203 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
205 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
207 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
209 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
211 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
213 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
215 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
217 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
219 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
221 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
223 if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
225 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
228 return editorInputStyleMask;
233 Toolkit::TextEditor TextEditor::New()
235 // Create the implementation, temporarily owned by this handle on stack
236 IntrusivePtr<TextEditor> impl = new TextEditor();
238 // Pass ownership to CustomActor handle
239 Toolkit::TextEditor handle(*impl);
241 // Second-phase init of the implementation
242 // This can only be done after the CustomActor connection has been made...
248 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
250 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
252 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
256 PropertyHandler::SetProperty(textEditor, index, value);
260 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
262 Property::Value value;
264 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
268 value = PropertyHandler::GetProperty(textEditor, index);
273 void TextEditor::SelectWholeText()
275 if(mController && mController->IsShowingRealText())
277 mController->SelectWholeText();
282 void TextEditor::SelectNone()
284 if(mController && mController->IsShowingRealText())
286 mController->SelectNone();
290 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
292 if(mController && mController->IsShowingRealText())
294 mController->SelectText(start, end);
299 string TextEditor::CopyText()
301 string copiedText = "";
302 if(mController && mController->IsShowingRealText())
304 copiedText = mController->CopyText();
309 string TextEditor::CutText()
312 if(mController && mController->IsShowingRealText())
314 cutText = mController->CutText();
319 void TextEditor::PasteText()
323 SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
324 mController->PasteText();
328 void TextEditor::ScrollBy(Vector2 scroll)
330 if(mController && mController->IsShowingRealText())
332 mController->ScrollBy(scroll);
336 float TextEditor::GetHorizontalScrollPosition()
338 if(mController && mController->IsShowingRealText())
340 return mController->GetHorizontalScrollPosition();
345 float TextEditor::GetVerticalScrollPosition()
347 if(mController && mController->IsShowingRealText())
349 return mController->GetVerticalScrollPosition();
354 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
356 return mController->GetTextSize(startIndex, endIndex);
359 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
361 return mController->GetTextPosition(startIndex, endIndex);
364 string TextEditor::GetSelectedText() const
366 string selectedText = "";
367 if(mController && mController->IsShowingRealText())
369 selectedText = mController->GetSelectedText();
374 InputMethodContext TextEditor::GetInputMethodContext()
376 return mInputMethodContext;
379 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
381 return mMaxLengthReachedSignal;
384 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
386 return mAnchorClickedSignal;
389 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
391 return mCursorPositionChangedSignal;
394 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
396 return mInputFilteredSignal;
399 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
401 return mSelectionChangedSignal;
404 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
406 return mSelectionClearedSignal;
409 DevelTextEditor::SelectionStartedSignalType& TextEditor::SelectionStartedSignal()
411 return mSelectionStartedSignal;
414 Text::ControllerPtr TextEditor::GetTextController()
419 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
421 Dali::BaseHandle handle(object);
423 bool connected(true);
424 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
426 if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
428 editor.TextChangedSignal().Connect(tracker, functor);
430 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
432 editor.InputStyleChangedSignal().Connect(tracker, functor);
434 else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
438 Internal::TextEditor& editorImpl(GetImpl(editor));
439 editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
442 else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
446 Internal::TextEditor& editorImpl(GetImpl(editor));
447 editorImpl.AnchorClickedSignal().Connect(tracker, functor);
450 else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
454 Internal::TextEditor& editorImpl(GetImpl(editor));
455 editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
458 else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
462 Internal::TextEditor& editorImpl(GetImpl(editor));
463 editorImpl.InputFilteredSignal().Connect(tracker, functor);
466 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
470 Internal::TextEditor& editorImpl(GetImpl(editor));
471 editorImpl.SelectionChangedSignal().Connect(tracker, functor);
474 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
478 Internal::TextEditor& editorImpl(GetImpl(editor));
479 editorImpl.SelectionClearedSignal().Connect(tracker, functor);
482 else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
486 Internal::TextEditor& editorImpl(GetImpl(editor));
487 editorImpl.SelectionStartedSignal().Connect(tracker, functor);
492 // signalName does not match any signal
499 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
501 return mTextChangedSignal;
504 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
506 return mInputStyleChangedSignal;
509 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
511 return mScrollStateChangedSignal;
514 void TextEditor::OnAccessibilityStatusChanged()
516 CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
519 void TextEditor::OnInitialize()
523 mController = Text::Controller::New(this, this, this, this);
525 mDecorator = Text::Decorator::New(*mController,
528 mInputMethodContext = InputMethodContext::New(self);
530 mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
532 // Enables the text input.
533 mController->EnableTextInput(mDecorator, mInputMethodContext);
535 // Enables the vertical scrolling after the text input has been enabled.
536 mController->SetVerticalScrollEnabled(true);
538 // Disables the horizontal scrolling.
539 mController->SetHorizontalScrollEnabled(false);
541 // Sets the maximum number of characters.
542 mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
544 // Enable the smooth handle panning.
545 mController->SetSmoothHandlePanEnabled(true);
547 mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
548 mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
550 // Sets layoutDirection value
551 Dali::Stage stage = Dali::Stage::GetCurrent();
552 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
553 mController->SetLayoutDirection(layoutDirection);
555 self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
557 // Forward input events to controller
558 EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
559 GetTapGestureDetector().SetMaximumTapsRequired(2);
560 GetTapGestureDetector().ReceiveAllTapEvents(true);
562 self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
564 // Set BoundingBox to stage size if not already set.
565 Rect<int> boundingBox;
566 mDecorator->GetBoundingBox(boundingBox);
568 if(boundingBox.IsEmpty())
570 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
571 mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
574 // Whether to flip the selection handles as soon as they cross.
575 mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
577 // Set the default scroll speed.
578 mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
580 // Fill-parent area by default
581 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
582 self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
583 self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
585 DevelControl::SetInputMethodContext(*this, mInputMethodContext);
587 // Creates an extra control to be used as stencil buffer.
588 mStencil = Control::New();
589 mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
590 mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
592 // Creates a background visual. Even if the color is transparent it updates the stencil.
593 mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
594 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
596 // Enable the clipping property.
597 mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
598 mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
603 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY);
604 self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
606 Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
607 Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
610 DevelControl::ControlAccessible* TextEditor::CreateAccessibleObject()
612 return new TextEditorAccessible(Self());
615 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
617 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
621 case StyleChange::DEFAULT_FONT_CHANGE:
623 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
624 const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
625 // Property system did not set the font so should update it.
626 mController->UpdateAfterFontChange(newFont);
631 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
633 GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
637 case StyleChange::THEME_CHANGE:
639 // Nothing to do, let control base class handle this
644 // Up call to Control
645 Control::OnStyleChange(styleManager, change);
648 Vector3 TextEditor::GetNaturalSize()
651 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
653 Vector3 naturalSize = mController->GetNaturalSize();
654 naturalSize.width += (padding.start + padding.end);
655 naturalSize.height += (padding.top + padding.bottom);
660 float TextEditor::GetHeightForWidth(float width)
663 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
664 return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
667 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
669 if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
671 actor.SetProperty(Actor::Property::SIZE, size);
675 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
677 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
682 padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
684 Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
686 // Support Right-To-Left of padding
687 Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
689 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
691 std::swap(padding.start, padding.end);
696 mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
697 ResizeActor(mStencil, contentSize);
701 mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
702 ResizeActor(mActiveLayer, contentSize);
706 mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
707 ResizeActor(mCursorLayer, contentSize);
710 // If there is text changed, callback is called.
713 EmitTextChangedSignal();
716 const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
718 if((Text::Controller::NONE_UPDATED != updateTextType) ||
721 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
724 (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
726 mDecorator->Relayout(contentSize);
731 mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
734 RenderText(updateTextType);
737 if(mCursorPositionChanged)
739 EmitCursorPositionChangedSignal();
742 if(mSelectionStarted)
744 EmitSelectionStartedSignal();
747 if(mSelectionChanged)
749 EmitSelectionChangedSignal();
752 if(mSelectionCleared)
754 EmitSelectionClearedSignal();
757 // The text-editor emits signals when the input style changes. These changes of style are
758 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
759 // can't be emitted during the size negotiation as the callbacks may update the UI.
760 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
761 if(!mController->IsInputStyleChangedSignalsQueueEmpty())
763 if(Adaptor::IsAvailable())
765 Adaptor& adaptor = Adaptor::Get();
767 if(NULL == mIdleCallback)
769 // @note: The callback manager takes the ownership of the callback object.
770 mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
771 adaptor.AddIdle(mIdleCallback, false);
777 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
779 CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mCursorLayer, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
782 ApplyScrollPosition();
787 void TextEditor::OnKeyInputFocusGained()
789 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
790 if(mInputMethodContext && IsEditable())
792 // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
793 mInputMethodContext.ApplyOptions(mInputMethodOptions);
794 mInputMethodContext.NotifyTextInputMultiLine(true);
796 mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
798 mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
800 // Notify that the text editing start.
801 mInputMethodContext.Activate();
803 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
804 mInputMethodContext.SetRestoreAfterFocusLost(true);
806 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
810 notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
813 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
815 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
818 void TextEditor::OnKeyInputFocusLost()
820 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
821 if(mInputMethodContext)
823 mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
825 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
826 mInputMethodContext.SetRestoreAfterFocusLost(false);
828 // Notify that the text editing finish.
829 mInputMethodContext.Deactivate();
831 mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
833 ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
837 notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
840 mController->KeyboardFocusLostEvent();
842 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
845 bool TextEditor::OnAccessibilityActivated()
851 void TextEditor::OnTap(const TapGesture& gesture)
853 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
854 if(mInputMethodContext && IsEditable())
856 mInputMethodContext.Activate();
858 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
860 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
861 const Vector2& localPoint = gesture.GetLocalPoint();
862 mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
863 mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
868 void TextEditor::OnPan(const PanGesture& gesture)
870 mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
873 void TextEditor::OnLongPress(const LongPressGesture& gesture)
875 if(mInputMethodContext && IsEditable())
877 mInputMethodContext.Activate();
880 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
881 const Vector2& localPoint = gesture.GetLocalPoint();
882 mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
887 bool TextEditor::OnKeyEvent(const KeyEvent& event)
889 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
891 if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
893 // Make sure ClearKeyInputFocus when only key is up
894 if(event.GetState() == KeyEvent::UP)
896 ClearKeyInputFocus();
902 return mController->KeyEvent(event);
905 void TextEditor::RequestTextRelayout()
910 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
912 GetAccessibleObject()->EmitTextInserted(position, length, content);
915 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
917 GetAccessibleObject()->EmitTextDeleted(position, length, content);
920 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
922 GetAccessibleObject()->EmitTextCursorMoved(newPosition);
924 if((oldPosition != newPosition) && !mCursorPositionChanged)
926 mCursorPositionChanged = true;
927 mOldPosition = oldPosition;
931 void TextEditor::TextChanged(bool immediate)
933 if(immediate) // Emits TextChangedSignal immediately
935 EmitTextChangedSignal();
943 void TextEditor::EmitTextChangedSignal()
945 Dali::Toolkit::TextEditor handle(GetOwner());
946 mTextChangedSignal.Emit(handle);
947 mTextChanged = false;
950 void TextEditor::MaxLengthReached()
952 Dali::Toolkit::TextEditor handle(GetOwner());
953 mMaxLengthReachedSignal.Emit(handle);
956 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
958 Dali::Toolkit::TextEditor handle(GetOwner());
959 mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
962 void TextEditor::AnchorClicked(const std::string& href)
964 Dali::Toolkit::TextEditor handle(GetOwner());
965 mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
968 void TextEditor::EmitCursorPositionChangedSignal()
970 Dali::Toolkit::TextEditor handle(GetOwner());
971 mCursorPositionChanged = false;
972 mCursorPositionChangedSignal.Emit(handle, mOldPosition);
975 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
977 Dali::Toolkit::TextEditor handle(GetOwner());
978 mInputFilteredSignal.Emit(handle, type);
981 void TextEditor::EmitSelectionChangedSignal()
983 Dali::Toolkit::TextEditor handle(GetOwner());
984 mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
985 mSelectionChanged = false;
988 void TextEditor::EmitSelectionClearedSignal()
990 Dali::Toolkit::TextEditor handle(GetOwner());
991 mSelectionClearedSignal.Emit(handle);
992 mSelectionCleared = false;
995 void TextEditor::EmitSelectionStartedSignal()
997 Dali::Toolkit::TextEditor handle(GetOwner());
998 mSelectionStartedSignal.Emit(handle);
999 mSelectionStarted = false;
1002 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
1004 if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
1006 if(newStart == newEnd)
1008 mSelectionCleared = true;
1012 if(oldStart == oldEnd)
1014 mSelectionStarted = true;
1018 mSelectionChanged = true;
1019 mOldSelectionStart = oldStart;
1020 mOldSelectionEnd = oldEnd;
1022 if(mOldSelectionStart > mOldSelectionEnd)
1025 uint32_t temp = mOldSelectionStart;
1026 mOldSelectionStart = mOldSelectionEnd;
1027 mOldSelectionEnd = temp;
1032 void TextEditor::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1038 mClippingDecorationActors.push_back(actor);
1041 // If the actor is a layer type, add it.
1042 if(type == DecorationType::ACTIVE_LAYER)
1044 AddLayer(mActiveLayer, actor);
1046 else if(type == DecorationType::CURSOR_LAYER)
1048 AddLayer(mCursorLayer, actor);
1053 void TextEditor::AddLayer(Actor& layer, Actor& actor)
1055 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1056 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1061 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1063 if(mController && mController->IsShowingRealText())
1065 mController->SetTextSelectionRange(start, end);
1070 Uint32Pair TextEditor::GetTextSelectionRange() const
1072 Uint32Pair range(0, 0);
1073 if(mController && mController->IsShowingRealText())
1075 range = mController->GetTextSelectionRange();
1080 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1082 Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1083 Property::Map* resultMap = propValue.GetMap();
1085 Property::Value* colorValue = nullptr;
1086 if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1088 colorValue->Get(color);
1092 void TextEditor::UpdateScrollBar()
1094 using namespace Dali;
1096 float scrollPosition;
1099 bool latestScrolled;
1101 if(!mScrollBarEnabled)
1105 latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1106 if(!latestScrolled || controlSize > layoutSize)
1111 CustomActor self = Self();
1114 mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1115 mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1116 mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1117 mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1118 mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1119 mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1121 // Register the scroll position property
1122 Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1123 // Register the minimum scroll position property
1124 Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1125 // Register the maximum scroll position property
1126 Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1127 // Register the scroll content size property
1128 Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1130 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1132 // Set style name of ScrollBar for styling
1133 mScrollBar.SetStyleName("TextEditorScrollBar");
1134 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1137 // Set style name of ScrollBarIndicator for styling
1138 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1141 self.Add(mScrollBar);
1145 Property::Index propertyScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1146 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1147 Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1149 self.SetProperty(propertyScrollPosition, scrollPosition);
1150 self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1151 self.SetProperty(propertyScrollContentSize, layoutSize);
1154 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1157 mScrollStarted = true;
1158 Dali::Toolkit::TextEditor handle(GetOwner());
1159 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1162 Actor indicator = mScrollBar.GetScrollIndicator();
1165 mAnimation.Stop(); // Cancel any animation
1169 mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1171 indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1172 mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1174 mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1177 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1179 // If animation is successfully ended, then emit ScrollStateChangedSignal
1180 if(animation.GetCurrentProgress() == 0.0f)
1182 mScrollStarted = false;
1183 Dali::Toolkit::TextEditor handle(GetOwner());
1184 mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1188 void TextEditor::OnSceneConnect(Dali::Actor actor)
1192 RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1196 mHasBeenStaged = true;
1200 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1202 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1203 return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1206 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1211 map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1217 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1219 mController->PasteClipboardItemEvent();
1222 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1224 DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1226 // Just hide the grab handle when keyboard is hidden.
1229 mController->KeyboardFocusLostEvent();
1233 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1237 void TextEditor::OnSceneConnection(int depth)
1239 // Sets the depth to the visuals inside the text's decorator.
1240 mDecorator->SetTextDepth(depth);
1242 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1244 // Call the Control::OnSceneConnection() to set the depth of the background.
1245 Control::OnSceneConnection(depth);
1248 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1253 void TextEditor::OnIdleSignal()
1255 // Emits the change of input style signals.
1256 mController->ProcessInputStyleChangedSignals();
1258 // Set the pointer to null as the callback manager deletes the callback after execute it.
1259 mIdleCallback = NULL;
1262 void TextEditor::ApplyScrollPosition()
1264 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1265 float scrollAmount = 0.0f;
1267 if(mScrollAnimationEnabled)
1269 scrollAmount = mController->GetScrollAmountByUserInput();
1271 if(mTextVerticalScroller)
1273 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1275 else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1277 mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1281 mTextVerticalScroller = Text::TextVerticalScroller::New();
1282 if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1284 mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1286 mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1290 bool TextEditor::IsEditable() const
1292 return mController->IsEditable();
1295 void TextEditor::SetEditable(bool editable)
1297 mController->SetEditable(editable);
1298 if(mInputMethodContext && !editable)
1300 mInputMethodContext.Deactivate();
1304 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1306 mController->ChangedLayoutDirection();
1309 TextEditor::TextEditor()
1310 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1311 mAnimationPeriod(0.0f, 0.0f),
1312 mIdleCallback(NULL),
1313 mAlignmentOffset(0.f),
1314 mScrollAnimationDuration(0.f),
1316 mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1317 mHasBeenStaged(false),
1318 mScrollAnimationEnabled(false),
1319 mScrollBarEnabled(false),
1320 mScrollStarted(false),
1321 mTextChanged(false),
1322 mCursorPositionChanged(false),
1323 mSelectionChanged(false),
1324 mSelectionCleared(false),
1326 mOldSelectionStart(0u),
1327 mOldSelectionEnd(0u),
1328 mSelectionStarted(false)
1332 TextEditor::~TextEditor()
1334 UnparentAndReset(mStencil);
1336 if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1338 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1339 Adaptor::Get().RemoveIdle(mIdleCallback);
1343 std::string TextEditor::TextEditorAccessible::GetName() const
1345 return GetWholeText();
1348 const std::vector<Toolkit::TextAnchor>& TextEditor::TextEditorAccessible::GetTextAnchors() const
1350 auto self = Toolkit::TextEditor::DownCast(Self());
1352 return Toolkit::GetImpl(self).mAnchorActors;
1355 Toolkit::Text::ControllerPtr TextEditor::TextEditorAccessible::GetTextController() const
1357 auto self = Toolkit::TextEditor::DownCast(Self());
1359 return Toolkit::GetImpl(self).GetTextController();
1362 void TextEditor::TextEditorAccessible::RequestTextRelayout()
1364 auto self = Toolkit::TextEditor::DownCast(Self());
1365 auto& selfImpl = Toolkit::GetImpl(self);
1367 selfImpl.RequestTextRelayout();
1370 } // namespace Internal
1372 } // namespace Toolkit