1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_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>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
28 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
29 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
30 #include <dali-toolkit/internal/text/text-control-interface.h>
31 #include <dali-toolkit/internal/text/text-controller.h>
32 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
33 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
44 * @brief A control which renders a short text string.
46 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
50 * @copydoc Dali::Toollkit::TextField::New()
52 static Toolkit::TextField New();
57 * @brief Called when a property of an object of this type is set.
59 * @param[in] object The object whose property is set.
60 * @param[in] index The property index.
61 * @param[in] value The new property value.
63 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
66 * @brief Called to retrieve a property of an object of this type.
68 * @param[in] object The object whose property is to be retrieved.
69 * @param[in] index The property index.
70 * @return The current value of the property.
72 static Property::Value GetProperty(BaseObject* object, Property::Index index);
75 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
77 InputMethodContext GetInputMethodContext();
80 * Connects a callback function with the object's signals.
81 * @param[in] object The object providing the signal.
82 * @param[in] tracker Used to disconnect the signal.
83 * @param[in] signalName The signal to connect to.
84 * @param[in] functor A newly allocated FunctorDelegate.
85 * @return True if the signal was connected.
86 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
88 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
91 * @copydoc TextField::TextChangedSignal()
93 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
96 * @copydoc TextField::MaxLengthReachedSignal()
98 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
101 * @copydoc TextField::TextChangedSignal()
103 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
105 Text::ControllerPtr getController();
107 private: // From Control
109 * @copydoc Control::OnInitialize()
111 void OnInitialize() override;
114 * @copydoc Control::OnStyleChange()
116 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
119 * @copydoc Control::GetNaturalSize()
121 Vector3 GetNaturalSize() override;
124 * @copydoc Control::GetHeightForWidth()
126 float GetHeightForWidth(float width) override;
129 * @copydoc Control::OnInitialize()
131 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
134 * @copydoc Control::OnKeyInputFocusGained()
136 void OnKeyInputFocusGained() override;
139 * @copydoc Control::OnKeyInputFocusLost()
141 void OnKeyInputFocusLost() override;
144 * @copydoc Control::OnAccessibilityActivated()
146 bool OnAccessibilityActivated() 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 TextInserted(unsigned int position, unsigned int length, const std::string& content) override;
188 * @copydoc Text::EditableControlInterface::TextDeleted()
190 void TextDeleted(unsigned int position, unsigned int length, const std::string& content) override;
193 * @copydoc Text::EditableControlInterface::CaretMoved()
195 void CaretMoved(unsigned int position) override;
198 * @copydoc Text::EditableControlInterface::TextChanged()
200 void TextChanged(bool immediate) override;
203 * @copydoc Text::EditableControlInterface::MaxLengthReached()
205 void MaxLengthReached() override;
208 * @copydoc Text::EditableControlInterface::InputStyleChanged()
210 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
213 * @copydoc Text::EditableControlInterface::AddDecoration()
215 void AddDecoration(Actor& actor, bool needsClipping) override;
217 // From SelectableControlInterface
220 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
222 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
225 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
227 Uint32Pair GetTextSelectionRange() const override;
230 * @copydoc Text::SelectableControlInterface::SelectWholeText()
232 void SelectWholeText() override;
235 * @copydoc Text::SelectableControlInterface::SelectNone()
237 void SelectNone() override;
240 * @copydoc Text::SelectableControlInterface::GetSelectedText()
242 string GetSelectedText() const override;
245 * @copydoc Text::EditableControlInterface::IsEditable()
247 bool IsEditable() const override;
250 * @copydoc Text::EditableControlInterface::SetEditable()
252 void SetEditable(bool editable) override;
254 private: // Implementation
256 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
258 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
261 * @brief Callback when Clipboard signals an item should be pasted
262 * @param[in] clipboard handle to Clipboard Event Notifier
264 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
267 * @brief Get a Property Map for the image used for the required Handle Image
268 * @param[out] value the returned image property
269 * @param[in] handleType the type of handle
270 * @param[in] handleImageType the type of image for the given handleType
272 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
275 * @brief Enable or disable clipping.
277 void EnableClipping();
280 * @brief Callback when keyboard is shown/hidden.
282 * @param[in] keyboardShown True if keyboard is shown.
284 void KeyboardStatusChanged(bool keyboardShown);
287 * @brief Callback when TextField is touched
289 * @param[in] actor TextField touched
290 * @param[in] touch Touch information
292 bool OnTouched(Actor actor, const TouchEvent& touch);
295 * @brief Callbacks called on idle.
297 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
302 * @brief Emits TextChanged signal.
304 void EmitTextChangedSignal();
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 Resize actor to the given size.
323 * @param[in] actor The actor to be resized.
324 * @param[in] size Size to change.
326 void ResizeActor(Actor& actor, const Vector2& size);
329 * @brief Render view, create and attach actor(s) to this Text Field.
331 void RenderText(Text::Controller::UpdateTextType updateTextType);
333 // Connection needed to re-render text, when a Text Field returns to the scene.
334 void OnSceneConnect(Dali::Actor actor);
336 public: // For UTC only
337 Text::ControllerPtr GetTextController()
344 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
345 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
346 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
348 InputMethodContext mInputMethodContext;
349 Text::ControllerPtr mController;
350 Text::RendererPtr mRenderer;
351 Text::DecoratorPtr mDecorator;
352 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
353 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
354 Dali::InputMethodOptions mInputMethodOptions;
356 Actor mRenderableActor;
358 Actor mBackgroundActor;
359 CallbackBase* mIdleCallback;
361 float mAlignmentOffset;
362 int mRenderingBackend;
364 bool mHasBeenStaged : 1;
365 bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
368 struct AccessibleImpl : public DevelControl::AccessibleImpl,
369 public virtual Dali::Accessibility::Text,
370 public virtual Dali::Accessibility::EditableText
372 using DevelControl::AccessibleImpl::AccessibleImpl;
374 std::string GetName() override;
375 std::string GetText(size_t startOffset, size_t endOffset) override;
376 size_t GetCharacterCount() override;
377 size_t GetCaretOffset() override;
378 bool SetCaretOffset(size_t offset) override;
379 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
380 Accessibility::Range GetSelection(size_t selectionNum) override;
381 bool RemoveSelection(size_t selectionNum) override;
382 bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
383 bool CopyText(size_t startPosition, size_t endPosition) override;
384 bool CutText(size_t startPosition, size_t endPosition) override;
385 Accessibility::States CalculateStates() override;
389 } // namespace Internal
391 // Helpers for public-api forwarding methods
393 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
395 DALI_ASSERT_ALWAYS(textField);
397 Dali::RefObject& handle = textField.GetImplementation();
399 return static_cast<Toolkit::Internal::TextField&>(handle);
402 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
404 DALI_ASSERT_ALWAYS(textField);
406 const Dali::RefObject& handle = textField.GetImplementation();
408 return static_cast<const Toolkit::Internal::TextField&>(handle);
411 } // namespace Toolkit
415 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H