1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
5 * Copyright (c) 2017 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/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/public-api/controls/scroll-bar/scroll-bar.h>
30 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
31 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
32 #include <dali-toolkit/internal/text/text-control-interface.h>
33 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #include <dali-toolkit/internal/text/text-controller.h>
35 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
36 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
37 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
48 * @brief A control which renders a long text string with styles.
50 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface
55 * @copydoc Dali::Toollkit::TextEditor::New()
57 static Toolkit::TextEditor New();
62 * @brief Called when a property of an object of this type is set.
64 * @param[in] object The object whose property is set.
65 * @param[in] index The property index.
66 * @param[in] value The new property value.
68 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
71 * @brief Called to retrieve a property of an object of this type.
73 * @param[in] object The object whose property is to be retrieved.
74 * @param[in] index The property index.
75 * @return The current value of the property.
77 static Property::Value GetProperty( BaseObject* object, Property::Index index );
80 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
82 InputMethodContext GetInputMethodContext();
85 * Connects a callback function with the object's signals.
86 * @param[in] object The object providing the signal.
87 * @param[in] tracker Used to disconnect the signal.
88 * @param[in] signalName The signal to connect to.
89 * @param[in] functor A newly allocated FunctorDelegate.
90 * @return True if the signal was connected.
91 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
93 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
96 * @copydoc TextEditor::TextChangedSignal()
98 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
101 * @copydoc TextEditor::TextChangedSignal()
103 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
106 * @copydoc TextEditor::ScrollStateChangedSignal()
108 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
110 private: // From Control
113 * @copydoc Control::OnInitialize()
115 virtual void OnInitialize();
118 * @copydoc Control::OnStyleChange()
120 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
123 * @copydoc Control::GetNaturalSize()
125 virtual Vector3 GetNaturalSize();
128 * @copydoc Control::GetHeightForWidth()
130 virtual float GetHeightForWidth( float width );
133 * @copydoc Control::OnInitialize()
135 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
138 * @copydoc Control::OnKeyInputFocusGained()
140 virtual void OnKeyInputFocusGained();
143 * @copydoc Control::OnKeyInputFocusLost()
145 virtual void OnKeyInputFocusLost();
148 * @copydoc Control::OnTap()
150 virtual void OnTap( const TapGesture& tap );
153 * @copydoc Control::OnPan()
155 virtual void OnPan( const PanGesture& gesture );
158 * @copydoc Control::OnLongPress()
160 virtual void OnLongPress( const LongPressGesture& gesture );
163 * @copydoc Control::OnStageConnection()
165 virtual void OnStageConnection( int depth );
168 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
170 virtual bool OnKeyEvent(const KeyEvent& event);
172 // From ControlInterface
175 * @copydoc Text::ControlInterface::RequestTextRelayout()
177 virtual void RequestTextRelayout();
179 // From EditableControlInterface
182 * @copydoc Text::ControlInterface::TextInserted()
184 virtual void TextInserted( unsigned int position, unsigned int length, const std::string &content );
187 * @copydoc Text::ControlInterface::TextDeleted()
189 virtual void TextDeleted( unsigned int position, unsigned int length, const std::string &content );
192 * @copydoc Text::ControlInterface::CaretMoved()
194 virtual void CaretMoved( unsigned int position );
197 * @copydoc Text::ControlInterface::TextChanged()
199 virtual void TextChanged();
202 * @copydoc Text::ControlInterface::MaxLengthReached()
204 virtual void MaxLengthReached();
207 * @copydoc Text::ControlInterface::InputStyleChanged()
209 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
212 * @copydoc Text::ControlInterface::AddDecoration()
214 virtual void AddDecoration( Actor& actor, bool needsClipping );
216 Text::ControllerPtr getController();
218 private: // Implementation
221 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
223 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
226 * @brief Callback when Clipboard signals an item should be pasted
227 * @param[in] clipboard handle to Clipboard Event Notifier
229 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
232 * @brief Get a Property Map for the image used for the required Handle Image
233 * @param[out] value the returned image property
234 * @param[in] handleType the type of handle
235 * @param[in] handleImageType the type of image for the given handleType
237 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
240 * @brief Callback when keyboard is shown/hidden.
242 * @param[in] keyboardShown True if keyboard is shown.
244 void KeyboardStatusChanged( bool keyboardShown );
247 * @brief update scroll bar position
249 * If text scroll is occurred, create or update scroll bar position
251 void UpdateScrollBar();
254 * @brief Callback when TextEditor is touched
256 * @param[in] actor TextEditor touched
257 * @param[in] touch Touch information
259 bool OnTouched( Actor actor, const TouchData& touch );
262 * @brief Callbacks called on idle.
264 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
269 * @brief set RenderActor's position with new scrollPosition
271 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
273 void ApplyScrollPosition();
276 * @brief Callback function for ScrollBar indicator animation finished signal
278 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
280 void OnScrollIndicatorAnimationFinished( Animation& animation );
283 * Construct a new TextEditor.
288 * A reference counted object may only be deleted by calling Unreference()
290 virtual ~TextEditor();
292 // Undefined copy constructor and assignment operators
293 TextEditor(const TextEditor&);
294 TextEditor& operator=(const TextEditor& rhs);
297 * @brief Render view, create and attach actor(s) to this text editor.
299 void RenderText( Text::Controller::UpdateTextType updateTextType );
301 // Connection needed to re-render text, when a text editor returns to the stage.
302 void OnStageConnect( Dali::Actor actor );
306 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
307 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
308 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
310 InputMethodContext mInputMethodContext;
311 Text::ControllerPtr mController;
312 Text::RendererPtr mRenderer;
313 Text::DecoratorPtr mDecorator;
314 Text::TextVerticalScrollerPtr mTextVerticalScroller;
315 Toolkit::Control mStencil;
316 Toolkit::ScrollBar mScrollBar;
317 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
318 Dali::TimePeriod mAnimationPeriod;
319 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
321 Actor mRenderableActor;
323 CallbackBase* mIdleCallback;
325 float mAlignmentOffset;
326 float mScrollAnimationDuration;
328 int mRenderingBackend;
329 bool mHasBeenStaged:1;
330 bool mScrollAnimationEnabled:1;
331 bool mScrollBarEnabled:1;
332 bool mScrollStarted:1;
334 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
335 public virtual Dali::Accessibility::Text,
336 public virtual Dali::Accessibility::EditableText
338 using Control::Impl::AccessibleImpl::AccessibleImpl;
340 std::string GetName() override;
341 std::string GetText( size_t startOffset, size_t endOffset ) override;
342 size_t GetCharacterCount() override;
343 size_t GetCaretOffset() override;
344 bool SetCaretOffset(size_t offset) override;
345 Dali::Accessibility::Range
346 GetTextAtOffset( size_t offset,
347 Dali::Accessibility::TextBoundary boundary ) override;
348 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
349 bool RemoveSelection( size_t selectionNum ) override;
350 bool SetSelection( size_t selectionNum, size_t startOffset,
351 size_t endOffset ) override;
352 bool CopyText( size_t startPosition, size_t endPosition ) override;
353 bool CutText( size_t startPosition, size_t endPosition ) override;
354 Dali::Accessibility::States CalculateStates() override;
358 } // namespace Internal
360 // Helpers for public-api forwarding methods
362 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
364 DALI_ASSERT_ALWAYS(textEditor);
366 Dali::RefObject& handle = textEditor.GetImplementation();
368 return static_cast<Toolkit::Internal::TextEditor&>(handle);
371 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
373 DALI_ASSERT_ALWAYS(textEditor);
375 const Dali::RefObject& handle = textEditor.GetImplementation();
377 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
380 } // namespace Toolkit
384 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H