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/devel-api/controls/text-controls/text-field-devel.h>
28 #include <dali-toolkit/internal/controls/control/control-data-impl.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-anchor-control-interface.h>
32 #include <dali-toolkit/internal/text/text-control-interface.h>
33 #include <dali-toolkit/internal/text/text-controller.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/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/controls/text-controls/text-field.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, public Text::AnchorControlInterface
52 * @copydoc Dali::Toollkit::TextField::New()
54 static Toolkit::TextField 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::TextField::GetInputMethodContext()
79 InputMethodContext GetInputMethodContext();
82 * Connects a callback function with the object's signals.
83 * @param[in] object The object providing the signal.
84 * @param[in] tracker Used to disconnect the signal.
85 * @param[in] signalName The signal to connect to.
86 * @param[in] functor A newly allocated FunctorDelegate.
87 * @return True if the signal was connected.
88 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
90 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
93 * @copydoc TextField::TextChangedSignal()
95 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
98 * @copydoc TextField::MaxLengthReachedSignal()
100 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
103 * @copydoc TextField::TextChangedSignal()
105 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
108 * @copydoc TextField::AnchorClickedSignal()
110 DevelTextField::AnchorClickedSignalType& AnchorClickedSignal();
113 * @copydoc TextField::InputFilteredSignal()
115 DevelTextField::InputFilteredSignalType& InputFilteredSignal();
117 Text::ControllerPtr getController();
119 private: // From Control
121 * @copydoc Control::OnInitialize()
123 void OnInitialize() override;
126 * @copydoc Control::OnStyleChange()
128 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
131 * @copydoc Control::GetNaturalSize()
133 Vector3 GetNaturalSize() override;
136 * @copydoc Control::GetHeightForWidth()
138 float GetHeightForWidth(float width) override;
141 * @copydoc Control::OnInitialize()
143 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
146 * @copydoc Control::OnKeyInputFocusGained()
148 void OnKeyInputFocusGained() override;
151 * @copydoc Control::OnKeyInputFocusLost()
153 void OnKeyInputFocusLost() override;
156 * @copydoc Control::OnAccessibilityActivated()
158 bool OnAccessibilityActivated() override;
161 * @copydoc Control::OnTap()
163 void OnTap(const TapGesture& tap) override;
166 * @copydoc Control::OnPan()
168 void OnPan(const PanGesture& gesture) override;
171 * @copydoc Control::OnLongPress()
173 void OnLongPress(const LongPressGesture& gesture) override;
176 * @copydoc Control::OnSceneConnection()
178 void OnSceneConnection(int depth) override;
181 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
183 bool OnKeyEvent(const KeyEvent& event) override;
185 // From ControlInterface
188 * @copydoc Text::ControlInterface::RequestTextRelayout()
190 void RequestTextRelayout() override;
192 // From EditableControlInterface
195 * @copydoc Text::EditableControlInterface::TextChanged()
197 void TextInserted(unsigned int position, unsigned int length, const std::string& content) override;
200 * @copydoc Text::EditableControlInterface::TextDeleted()
202 void TextDeleted(unsigned int position, unsigned int length, const std::string& content) override;
205 * @copydoc Text::EditableControlInterface::CaretMoved()
207 void CaretMoved(unsigned int position) override;
210 * @copydoc Text::EditableControlInterface::TextChanged()
212 void TextChanged(bool immediate) override;
215 * @copydoc Text::EditableControlInterface::MaxLengthReached()
217 void MaxLengthReached() override;
220 * @copydoc Text::EditableControlInterface::InputStyleChanged()
222 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
225 * @copydoc Text::EditableControlInterface::AddDecoration()
227 void AddDecoration(Actor& actor, bool needsClipping) override;
230 * @copydoc Text::EditableControlInterface::InputFiltered()
232 void InputFiltered(Toolkit::InputFilter::Property::Type type) override;
234 // From SelectableControlInterface
237 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
239 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
242 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
244 Uint32Pair GetTextSelectionRange() const override;
247 * @copydoc Text::SelectableControlInterface::SelectWholeText()
249 void SelectWholeText() override;
252 * @copydoc Text::SelectableControlInterface::SelectNone()
254 void SelectNone() override;
257 * @copydoc Text::SelectableControlInterface::GetSelectedText()
259 string GetSelectedText() const override;
262 * @copydoc Text::EditableControlInterface::IsEditable()
264 bool IsEditable() const override;
267 * @copydoc Text::EditableControlInterface::SetEditable()
269 void SetEditable(bool editable) override;
271 // From AnchorControlInterface
274 * @copydoc Text::AnchorControlInterface::AnchorClicked()
276 void AnchorClicked(const std::string& href) override;
278 private: // Implementation
280 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
282 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
285 * @brief Callback when Clipboard signals an item should be pasted
286 * @param[in] clipboard handle to Clipboard Event Notifier
288 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
291 * @brief Get a Property Map for the image used for the required Handle Image
292 * @param[out] value the returned image property
293 * @param[in] handleType the type of handle
294 * @param[in] handleImageType the type of image for the given handleType
296 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
299 * @brief Enable or disable clipping.
301 void EnableClipping();
304 * @brief Callback when keyboard is shown/hidden.
306 * @param[in] keyboardShown True if keyboard is shown.
308 void KeyboardStatusChanged(bool keyboardShown);
311 * @brief Callback when TextField is touched
313 * @param[in] actor TextField touched
314 * @param[in] touch Touch information
316 bool OnTouched(Actor actor, const TouchEvent& touch);
319 * @brief Callbacks called on idle.
321 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
326 * @brief Emits TextChanged signal.
328 void EmitTextChangedSignal();
331 * Construct a new TextField.
336 * A reference counted object may only be deleted by calling Unreference()
338 virtual ~TextField();
340 // Undefined copy constructor and assignment operators
341 TextField(const TextField&);
342 TextField& operator=(const TextField& rhs);
345 * @brief Resize actor to the given size.
347 * @param[in] actor The actor to be resized.
348 * @param[in] size Size to change.
350 void ResizeActor(Actor& actor, const Vector2& size);
353 * @brief Render view, create and attach actor(s) to this Text Field.
355 void RenderText(Text::Controller::UpdateTextType updateTextType);
357 // Connection needed to re-render text, when a Text Field returns to the scene.
358 void OnSceneConnect(Dali::Actor actor);
360 public: // For UTC only
361 Text::ControllerPtr GetTextController()
368 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
369 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
370 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
371 Toolkit::DevelTextField::AnchorClickedSignalType mAnchorClickedSignal;
372 Toolkit::DevelTextField::InputFilteredSignalType mInputFilteredSignal;
374 InputMethodContext mInputMethodContext;
375 Text::ControllerPtr mController;
376 Text::RendererPtr mRenderer;
377 Text::DecoratorPtr mDecorator;
378 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
379 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
380 Dali::InputMethodOptions mInputMethodOptions;
382 Actor mRenderableActor;
384 Actor mBackgroundActor;
385 CallbackBase* mIdleCallback;
387 float mAlignmentOffset;
388 int mRenderingBackend;
390 bool mHasBeenStaged : 1;
391 bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
394 struct AccessibleImpl : public DevelControl::AccessibleImpl,
395 public virtual Dali::Accessibility::Text,
396 public virtual Dali::Accessibility::EditableText
398 using DevelControl::AccessibleImpl::AccessibleImpl;
400 std::string GetName() override;
401 std::string GetText(size_t startOffset, size_t endOffset) override;
402 size_t GetCharacterCount() override;
403 size_t GetCaretOffset() override;
404 bool SetCaretOffset(size_t offset) override;
405 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
406 Accessibility::Range GetSelection(size_t selectionNum) override;
407 bool RemoveSelection(size_t selectionNum) override;
408 bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
409 bool CopyText(size_t startPosition, size_t endPosition) override;
410 bool CutText(size_t startPosition, size_t endPosition) override;
411 Accessibility::States CalculateStates() override;
412 bool InsertText(size_t startPosition, std::string text) override;
413 bool SetTextContents(std::string newContents) override;
414 bool DeleteText(size_t startPosition, size_t endPosition) override;
418 } // namespace Internal
420 // Helpers for public-api forwarding methods
422 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
424 DALI_ASSERT_ALWAYS(textField);
426 Dali::RefObject& handle = textField.GetImplementation();
428 return static_cast<Toolkit::Internal::TextField&>(handle);
431 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
433 DALI_ASSERT_ALWAYS(textField);
435 const Dali::RefObject& handle = textField.GetImplementation();
437 return static_cast<const Toolkit::Internal::TextField&>(handle);
440 } // namespace Toolkit
444 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H