1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_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/autofill-item.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/text-control-interface.h>
31 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
32 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
33 #include <dali-toolkit/internal/text/text-controller.h>
34 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
35 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
46 * @brief A control which renders a short text string.
48 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
53 * @copydoc Dali::Toollkit::TextField::New()
55 static Toolkit::TextField New();
60 * @brief Called when a property of an object of this type is set.
62 * @param[in] object The object whose property is set.
63 * @param[in] index The property index.
64 * @param[in] value The new property value.
66 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
69 * @brief Called to retrieve a property of an object of this type.
71 * @param[in] object The object whose property is to be retrieved.
72 * @param[in] index The property index.
73 * @return The current value of the property.
75 static Property::Value GetProperty( BaseObject* object, Property::Index index );
78 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
80 InputMethodContext GetInputMethodContext();
83 * Connects a callback function with the object's signals.
84 * @param[in] object The object providing the signal.
85 * @param[in] tracker Used to disconnect the signal.
86 * @param[in] signalName The signal to connect to.
87 * @param[in] functor A newly allocated FunctorDelegate.
88 * @return True if the signal was connected.
89 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
91 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
94 * @copydoc TextField::TextChangedSignal()
96 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
99 * @copydoc TextField::MaxLengthReachedSignal()
101 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
104 * @copydoc TextField::TextChangedSignal()
106 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
108 Text::ControllerPtr getController();
110 private: // From Control
113 * @copydoc Control::OnInitialize()
115 void OnInitialize() override;
118 * @copydoc Control::OnStyleChange()
120 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
123 * @copydoc Control::GetNaturalSize()
125 Vector3 GetNaturalSize() override;
128 * @copydoc Control::GetHeightForWidth()
130 float GetHeightForWidth( float width ) override;
133 * @copydoc Control::OnInitialize()
135 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
138 * @copydoc Control::OnKeyInputFocusGained()
140 void OnKeyInputFocusGained() override;
143 * @copydoc Control::OnKeyInputFocusLost()
145 void OnKeyInputFocusLost() override;
148 * @copydoc Control::OnAccessibilityActivated()
150 bool OnAccessibilityActivated() override;
153 * @copydoc Control::OnTap()
155 void OnTap( const TapGesture& tap ) override;
158 * @copydoc Control::OnPan()
160 void OnPan( const PanGesture& gesture ) override;
163 * @copydoc Control::OnLongPress()
165 void OnLongPress( const LongPressGesture& gesture ) override;
168 * @copydoc Control::OnSceneConnection()
170 void OnSceneConnection( int depth ) override;
173 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
175 bool OnKeyEvent(const KeyEvent& event) override;
177 // From ControlInterface
180 * @copydoc Text::ControlInterface::RequestTextRelayout()
182 void RequestTextRelayout() override;
184 // From EditableControlInterface
187 * @copydoc Text::EditableControlInterface::TextChanged()
189 void TextInserted( unsigned int position, unsigned int length, const std::string &content ) override;
192 * @copydoc Text::EditableControlInterface::TextDeleted()
194 void TextDeleted( unsigned int position, unsigned int length, const std::string &content ) override;
197 * @copydoc Text::EditableControlInterface::CaretMoved()
199 void CaretMoved( unsigned int position ) override;
202 * @copydoc Text::EditableControlInterface::TextChanged()
204 void TextChanged() override;
207 * @copydoc Text::EditableControlInterface::MaxLengthReached()
209 void MaxLengthReached() override;
212 * @copydoc Text::EditableControlInterface::InputStyleChanged()
214 void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
217 * @copydoc Text::EditableControlInterface::AddDecoration()
219 void AddDecoration( Actor& actor, bool needsClipping ) override;
221 // From SelectableControlInterface
224 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
226 void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
229 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
231 Uint32Pair GetTextSelectionRange() const override;
234 * @copydoc Text::SelectableControlInterface::SelectWholeText()
236 void SelectWholeText() override;
239 * @copydoc Text::SelectableControlInterface::SelectNone()
241 void SelectNone() override;
244 * @copydoc Text::SelectableControlInterface::GetSelectedText()
246 string GetSelectedText() const override;
249 * @copydoc Text::EditableControlInterface::IsEditable()
251 bool IsEditable() const override;
254 * @copydoc Text::EditableControlInterface::SetEditable()
256 void SetEditable( bool editable ) override;
258 private: // Implementation
261 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
263 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
266 * @brief Callback when Clipboard signals an item should be pasted
267 * @param[in] clipboard handle to Clipboard Event Notifier
269 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
272 * @brief Get a Property Map for the image used for the required Handle Image
273 * @param[out] value the returned image property
274 * @param[in] handleType the type of handle
275 * @param[in] handleImageType the type of image for the given handleType
277 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
280 * @brief Enable or disable clipping.
282 void EnableClipping();
285 * @brief Callback when keyboard is shown/hidden.
287 * @param[in] keyboardShown True if keyboard is shown.
289 void KeyboardStatusChanged( bool keyboardShown );
292 * @brief Callback when TextField is touched
294 * @param[in] actor TextField touched
295 * @param[in] touch Touch information
297 bool OnTouched( Actor actor, const TouchEvent& touch );
300 * @brief Callbacks called on idle.
302 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
307 * Construct a new TextField.
312 * A reference counted object may only be deleted by calling Unreference()
314 virtual ~TextField();
316 // Undefined copy constructor and assignment operators
317 TextField(const TextField&);
318 TextField& operator=(const TextField& rhs);
321 * @brief Render view, create and attach actor(s) to this Text Field.
323 void RenderText( Text::Controller::UpdateTextType updateTextType );
325 // Connection needed to re-render text, when a Text Field returns to the scene.
326 void OnSceneConnect( Dali::Actor actor );
328 public: // For UTC only
330 Text::ControllerPtr GetTextController() { return mController; }
335 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
336 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
337 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
339 InputMethodContext mInputMethodContext;
340 Text::ControllerPtr mController;
341 Text::RendererPtr mRenderer;
342 Text::DecoratorPtr mDecorator;
343 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
344 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
345 Dali::InputMethodOptions mInputMethodOptions;
346 Dali::AutofillItem mAutofillItem;
348 Actor mRenderableActor;
350 Actor mBackgroundActor;
351 CallbackBase* mIdleCallback;
353 float mAlignmentOffset;
354 int mRenderingBackend;
356 bool mHasBeenStaged:1;
359 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
360 public virtual Dali::Accessibility::Text,
361 public virtual Dali::Accessibility::EditableText
363 using Control::Impl::AccessibleImpl::AccessibleImpl;
365 std::string GetName() override;
366 std::string GetText( size_t startOffset, size_t endOffset ) override;
367 size_t GetCharacterCount() override;
368 size_t GetCaretOffset() override;
369 bool SetCaretOffset(size_t offset) override;
370 Dali::Accessibility::Range
371 GetTextAtOffset( size_t offset,
372 Dali::Accessibility::TextBoundary boundary ) override;
373 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
374 bool RemoveSelection( size_t selectionNum ) override;
375 bool SetSelection( size_t selectionNum, size_t startOffset,
376 size_t endOffset ) override;
377 bool CopyText( size_t startPosition, size_t endPosition ) override;
378 bool CutText( size_t startPosition, size_t endPosition ) override;
379 Dali::Accessibility::States CalculateStates() override;
383 } // namespace Internal
385 // Helpers for public-api forwarding methods
387 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
389 DALI_ASSERT_ALWAYS(textField);
391 Dali::RefObject& handle = textField.GetImplementation();
393 return static_cast<Toolkit::Internal::TextField&>(handle);
396 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
398 DALI_ASSERT_ALWAYS(textField);
400 const Dali::RefObject& handle = textField.GetImplementation();
402 return static_cast<const Toolkit::Internal::TextField&>(handle);
405 } // namespace Toolkit
409 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H