1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
23 #include <dali/devel-api/adaptor-framework/input-method-context.h>
24 #include <dali/public-api/animation/animation.h>
27 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.h>
33 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
35 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
36 #include <dali-toolkit/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
46 * @brief A control which renders a long text string with styles.
48 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
52 * @copydoc Dali::Toollkit::TextEditor::New()
54 static Toolkit::TextEditor New();
59 * @brief Called when a property of an object of this type is set.
61 * @param[in] object The object whose property is set.
62 * @param[in] index The property index.
63 * @param[in] value The new property value.
65 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
68 * @brief Called to retrieve a property of an object of this type.
70 * @param[in] object The object whose property is to be retrieved.
71 * @param[in] index The property index.
72 * @return The current value of the property.
74 static Property::Value GetProperty(BaseObject* object, Property::Index index);
77 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
79 InputMethodContext GetInputMethodContext();
82 * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
84 DevelTextEditor::MaxLengthReachedSignalType& MaxLengthReachedSignal();
87 * Connects a callback function with the object's signals.
88 * @param[in] object The object providing the signal.
89 * @param[in] tracker Used to disconnect the signal.
90 * @param[in] signalName The signal to connect to.
91 * @param[in] functor A newly allocated FunctorDelegate.
92 * @return True if the signal was connected.
93 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
95 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
98 * @copydoc TextEditor::TextChangedSignal()
100 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
103 * @copydoc TextEditor::TextChangedSignal()
105 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
108 * @copydoc TextEditor::ScrollStateChangedSignal()
110 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
112 private: // From Control
114 * @copydoc Control::OnInitialize()
116 void OnInitialize() override;
119 * @copydoc Control::OnStyleChange()
121 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
124 * @copydoc Control::GetNaturalSize()
126 Vector3 GetNaturalSize() override;
129 * @copydoc Control::GetHeightForWidth()
131 float GetHeightForWidth(float width) override;
134 * @copydoc Control::OnInitialize()
136 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
139 * @copydoc Control::OnKeyInputFocusGained()
141 void OnKeyInputFocusGained() override;
144 * @copydoc Control::OnKeyInputFocusLost()
146 void OnKeyInputFocusLost() override;
149 * @copydoc Control::OnTap()
151 void OnTap(const TapGesture& tap) override;
154 * @copydoc Control::OnPan()
156 void OnPan(const PanGesture& gesture) override;
159 * @copydoc Control::OnLongPress()
161 void OnLongPress(const LongPressGesture& gesture) override;
164 * @copydoc Control::OnSceneConnection()
166 void OnSceneConnection(int depth) override;
169 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
171 bool OnKeyEvent(const KeyEvent& event) override;
173 // From ControlInterface
176 * @copydoc Text::ControlInterface::RequestTextRelayout()
178 void RequestTextRelayout() override;
180 // From EditableControlInterface
183 * @copydoc Text::EditableControlInterface::TextChanged()
185 void TextChanged(bool immediate) override;
188 * @copydoc Text::EditableControlInterface::MaxLengthReached()
190 void MaxLengthReached() override;
193 * @copydoc Text::EditableControlInterface::InputStyleChanged()
195 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
198 * @copydoc Text::EditableControlInterface::AddDecoration()
200 void AddDecoration(Actor& actor, bool needsClipping) override;
202 // From SelectableControlInterface
205 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
207 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
210 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
212 Uint32Pair GetTextSelectionRange() const override;
215 * @copydoc Text::SelectableControlInterface::SelectWholeText()
217 void SelectWholeText() override;
220 * @copydoc Text::SelectableControlInterface::SelectNone()
222 void SelectNone() override;
225 * @copydoc Text::SelectableControlInterface::GetSelectedText()
227 string GetSelectedText() const override;
230 * @copydoc Text::EditableControlInterface::IsEditable()
232 bool IsEditable() const override;
235 * @copydoc Text::EditableControlInterface::SetEditable()
237 void SetEditable(bool editable) override;
239 private: // Implementation
241 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
243 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
246 * @brief Callback when Clipboard signals an item should be pasted
247 * @param[in] clipboard handle to Clipboard Event Notifier
249 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
252 * @brief Get a Property Map for the image used for the required Handle Image
253 * @param[out] value the returned image property
254 * @param[in] handleType the type of handle
255 * @param[in] handleImageType the type of image for the given handleType
257 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
260 * @brief Callback when keyboard is shown/hidden.
262 * @param[in] keyboardShown True if keyboard is shown.
264 void KeyboardStatusChanged(bool keyboardShown);
267 * @brief update scroll bar position
269 * If text scroll is occurred, create or update scroll bar position
271 void UpdateScrollBar();
274 * @brief Callback when TextEditor is touched
276 * @param[in] actor TextEditor touched
277 * @param[in] touch Touch information
279 bool OnTouched(Actor actor, const TouchEvent& touch);
282 * @brief Callbacks called on idle.
284 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
289 * @brief Emits TextChanged signal.
291 void EmitTextChangedSignal();
294 * @brief set RenderActor's position with new scrollPosition
296 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
298 void ApplyScrollPosition();
301 * @brief Callback function for ScrollBar indicator animation finished signal
303 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
305 void OnScrollIndicatorAnimationFinished(Animation& animation);
308 * Construct a new TextEditor.
313 * A reference counted object may only be deleted by calling Unreference()
315 virtual ~TextEditor();
317 // Undefined copy constructor and assignment operators
318 TextEditor(const TextEditor&);
319 TextEditor& operator=(const TextEditor& rhs);
322 * @brief Render view, create and attach actor(s) to this text editor.
324 void RenderText(Text::Controller::UpdateTextType updateTextType);
326 // Connection needed to re-render text, when a text editor returns to the scene.
327 void OnSceneConnect(Dali::Actor actor);
331 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
332 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
333 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
334 Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
336 InputMethodContext mInputMethodContext;
337 Text::ControllerPtr mController;
338 Text::RendererPtr mRenderer;
339 Text::DecoratorPtr mDecorator;
340 Text::TextVerticalScrollerPtr mTextVerticalScroller;
341 Toolkit::Control mStencil;
342 Toolkit::ScrollBar mScrollBar;
343 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
344 Dali::TimePeriod mAnimationPeriod;
345 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
347 Actor mRenderableActor;
349 CallbackBase* mIdleCallback;
351 float mAlignmentOffset;
352 float mScrollAnimationDuration;
354 int mRenderingBackend;
355 bool mHasBeenStaged : 1;
356 bool mScrollAnimationEnabled : 1;
357 bool mScrollBarEnabled : 1;
358 bool mScrollStarted : 1;
359 bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
362 } // namespace Internal
364 // Helpers for public-api forwarding methods
366 inline Toolkit::Internal::TextEditor& GetImpl(Toolkit::TextEditor& textEditor)
368 DALI_ASSERT_ALWAYS(textEditor);
370 Dali::RefObject& handle = textEditor.GetImplementation();
372 return static_cast<Toolkit::Internal::TextEditor&>(handle);
375 inline const Toolkit::Internal::TextEditor& GetImpl(const Toolkit::TextEditor& textEditor)
377 DALI_ASSERT_ALWAYS(textEditor);
379 const Dali::RefObject& handle = textEditor.GetImplementation();
381 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
384 } // namespace Toolkit
388 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H