1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
5 * Copyright (c) 2020 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/devel-api/adaptor-framework/accessibility.h>
25 #include <dali/public-api/animation/animation.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
30 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
31 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
32 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
33 #include <dali-toolkit/internal/text/text-control-interface.h>
34 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
35 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
36 #include <dali-toolkit/internal/text/text-controller.h>
37 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
38 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
39 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
50 * @brief A control which renders a long text string with styles.
52 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
57 * @copydoc Dali::Toollkit::TextEditor::New()
59 static Toolkit::TextEditor New();
64 * @brief Called when a property of an object of this type is set.
66 * @param[in] object The object whose property is set.
67 * @param[in] index The property index.
68 * @param[in] value The new property value.
70 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
73 * @brief Called to retrieve a property of an object of this type.
75 * @param[in] object The object whose property is to be retrieved.
76 * @param[in] index The property index.
77 * @return The current value of the property.
79 static Property::Value GetProperty( BaseObject* object, Property::Index index );
82 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
84 InputMethodContext GetInputMethodContext();
87 * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
89 DevelTextEditor::MaxLengthReachedSignalType& MaxLengthReachedSignal();
92 * Connects a callback function with the object's signals.
93 * @param[in] object The object providing the signal.
94 * @param[in] tracker Used to disconnect the signal.
95 * @param[in] signalName The signal to connect to.
96 * @param[in] functor A newly allocated FunctorDelegate.
97 * @return True if the signal was connected.
98 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
100 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
103 * @copydoc TextEditor::TextChangedSignal()
105 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
108 * @copydoc TextEditor::TextChangedSignal()
110 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
113 * @copydoc TextEditor::ScrollStateChangedSignal()
115 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
117 private: // From Control
120 * @copydoc Control::OnInitialize()
122 void OnInitialize() override;
125 * @copydoc Control::OnStyleChange()
127 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
130 * @copydoc Control::GetNaturalSize()
132 Vector3 GetNaturalSize() override;
135 * @copydoc Control::GetHeightForWidth()
137 float GetHeightForWidth( float width ) override;
140 * @copydoc Control::OnInitialize()
142 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
145 * @copydoc Control::OnKeyInputFocusGained()
147 void OnKeyInputFocusGained() override;
150 * @copydoc Control::OnKeyInputFocusLost()
152 void OnKeyInputFocusLost() override;
155 * @copydoc Control::OnAccessibilityActivated()
157 bool OnAccessibilityActivated() override;
160 * @copydoc Control::OnTap()
162 void OnTap( const TapGesture& tap ) override;
165 * @copydoc Control::OnPan()
167 void OnPan( const PanGesture& gesture ) override;
170 * @copydoc Control::OnLongPress()
172 void OnLongPress( const LongPressGesture& gesture ) override;
175 * @copydoc Control::OnSceneConnection()
177 void OnSceneConnection( int depth ) override;
180 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
182 bool OnKeyEvent(const KeyEvent& event) override;
184 // From ControlInterface
187 * @copydoc Text::ControlInterface::RequestTextRelayout()
189 void RequestTextRelayout() override;
191 // From EditableControlInterface
194 * @copydoc Text::EditableControlInterface::TextChanged()
196 void TextInserted( unsigned int position, unsigned int length, const std::string &content ) override;
199 * @copydoc Text::EditableControlInterface::TextDeleted()
201 void TextDeleted( unsigned int position, unsigned int length, const std::string &content ) override;
204 * @copydoc Text::EditableControlInterface::CaretMoved()
206 void CaretMoved( unsigned int position ) override;
209 * @copydoc Text::EditableControlInterface::TextChanged()
211 void TextChanged() override;
214 * @copydoc Text::EditableControlInterface::MaxLengthReached()
216 void MaxLengthReached() override;
219 * @copydoc Text::EditableControlInterface::InputStyleChanged()
221 void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
224 * @copydoc Text::EditableControlInterface::AddDecoration()
226 void AddDecoration( Actor& actor, bool needsClipping ) override;
228 // From SelectableControlInterface
231 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
233 void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
236 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
238 Uint32Pair GetTextSelectionRange() const override;
241 * @copydoc Text::SelectableControlInterface::SelectWholeText()
243 void SelectWholeText() override;
246 * @copydoc Text::SelectableControlInterface::SelectNone()
248 void SelectNone() override;
251 * @copydoc Text::SelectableControlInterface::GetSelectedText()
253 string GetSelectedText() const override;
256 * @copydoc Text::EditableControlInterface::IsEditable()
258 bool IsEditable() const override;
261 * @copydoc Text::EditableControlInterface::SetEditable()
263 void SetEditable( bool editable ) override;
264 Text::ControllerPtr getController();
266 private: // Implementation
269 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
271 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
274 * @brief Callback when Clipboard signals an item should be pasted
275 * @param[in] clipboard handle to Clipboard Event Notifier
277 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
280 * @brief Get a Property Map for the image used for the required Handle Image
281 * @param[out] value the returned image property
282 * @param[in] handleType the type of handle
283 * @param[in] handleImageType the type of image for the given handleType
285 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
288 * @brief Callback when keyboard is shown/hidden.
290 * @param[in] keyboardShown True if keyboard is shown.
292 void KeyboardStatusChanged( bool keyboardShown );
295 * @brief update scroll bar position
297 * If text scroll is occurred, create or update scroll bar position
299 void UpdateScrollBar();
302 * @brief Callback when TextEditor is touched
304 * @param[in] actor TextEditor touched
305 * @param[in] touch Touch information
307 bool OnTouched( Actor actor, const TouchEvent& touch );
310 * @brief Callbacks called on idle.
312 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
317 * @brief set RenderActor's position with new scrollPosition
319 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
321 void ApplyScrollPosition();
324 * @brief Callback function for ScrollBar indicator animation finished signal
326 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
328 void OnScrollIndicatorAnimationFinished( Animation& animation );
331 * Construct a new TextEditor.
336 * A reference counted object may only be deleted by calling Unreference()
338 virtual ~TextEditor();
340 // Undefined copy constructor and assignment operators
341 TextEditor(const TextEditor&);
342 TextEditor& operator=(const TextEditor& rhs);
345 * @brief Render view, create and attach actor(s) to this text editor.
347 void RenderText( Text::Controller::UpdateTextType updateTextType );
349 // Connection needed to re-render text, when a text editor returns to the scene.
350 void OnSceneConnect( Dali::Actor actor );
354 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
355 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
356 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
357 Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
359 InputMethodContext mInputMethodContext;
360 Text::ControllerPtr mController;
361 Text::RendererPtr mRenderer;
362 Text::DecoratorPtr mDecorator;
363 Text::TextVerticalScrollerPtr mTextVerticalScroller;
364 Toolkit::Control mStencil;
365 Toolkit::ScrollBar mScrollBar;
366 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
367 Dali::TimePeriod mAnimationPeriod;
368 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
370 Actor mRenderableActor;
372 CallbackBase* mIdleCallback;
374 float mAlignmentOffset;
375 float mScrollAnimationDuration;
377 int mRenderingBackend;
378 bool mHasBeenStaged:1;
379 bool mScrollAnimationEnabled:1;
380 bool mScrollBarEnabled:1;
381 bool mScrollStarted:1;
383 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
384 public virtual Dali::Accessibility::Text,
385 public virtual Dali::Accessibility::EditableText
387 using Control::Impl::AccessibleImpl::AccessibleImpl;
389 std::string GetName() override;
390 std::string GetText( size_t startOffset, size_t endOffset ) override;
391 size_t GetCharacterCount() override;
392 size_t GetCaretOffset() override;
393 bool SetCaretOffset(size_t offset) override;
394 Dali::Accessibility::Range
395 GetTextAtOffset( size_t offset,
396 Dali::Accessibility::TextBoundary boundary ) override;
397 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
398 bool RemoveSelection( size_t selectionNum ) override;
399 bool SetSelection( size_t selectionNum, size_t startOffset,
400 size_t endOffset ) override;
401 bool CopyText( size_t startPosition, size_t endPosition ) override;
402 bool CutText( size_t startPosition, size_t endPosition ) override;
403 Dali::Accessibility::States CalculateStates() override;
407 } // namespace Internal
409 // Helpers for public-api forwarding methods
411 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
413 DALI_ASSERT_ALWAYS(textEditor);
415 Dali::RefObject& handle = textEditor.GetImplementation();
417 return static_cast<Toolkit::Internal::TextEditor&>(handle);
420 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
422 DALI_ASSERT_ALWAYS(textEditor);
424 const Dali::RefObject& handle = textEditor.GetImplementation();
426 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
429 } // namespace Toolkit
433 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H