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>
24 #include <dali/devel-api/adaptor-framework/autofill-item.h>
27 #include <dali-toolkit/devel-api/controls/control-devel.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
29 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
30 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
31 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
32 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
33 #include <dali-toolkit/internal/text/text-control-interface.h>
34 #include <dali-toolkit/internal/text/text-controller.h>
35 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
36 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
47 * @brief A control which renders a short text string.
49 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface, public Text::AnchorControlInterface
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();
109 * @copydoc TextField::AnchorClickedSignal()
111 DevelTextField::AnchorClickedSignalType& AnchorClickedSignal();
113 Text::ControllerPtr getController();
115 private: // From Control
117 * @copydoc Control::OnInitialize()
119 void OnInitialize() override;
122 * @copydoc Control::OnStyleChange()
124 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
127 * @copydoc Control::GetNaturalSize()
129 Vector3 GetNaturalSize() override;
132 * @copydoc Control::GetHeightForWidth()
134 float GetHeightForWidth(float width) override;
137 * @copydoc Control::OnInitialize()
139 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
142 * @copydoc Control::OnKeyInputFocusGained()
144 void OnKeyInputFocusGained() override;
147 * @copydoc Control::OnKeyInputFocusLost()
149 void OnKeyInputFocusLost() override;
152 * @copydoc Control::OnAccessibilityActivated()
154 bool OnAccessibilityActivated() override;
157 * @copydoc Control::OnTap()
159 void OnTap(const TapGesture& tap) override;
162 * @copydoc Control::OnPan()
164 void OnPan(const PanGesture& gesture) override;
167 * @copydoc Control::OnLongPress()
169 void OnLongPress(const LongPressGesture& gesture) override;
172 * @copydoc Control::OnSceneConnection()
174 void OnSceneConnection(int depth) override;
177 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
179 bool OnKeyEvent(const KeyEvent& event) override;
181 // From ControlInterface
184 * @copydoc Text::ControlInterface::RequestTextRelayout()
186 void RequestTextRelayout() override;
188 // From EditableControlInterface
191 * @copydoc Text::EditableControlInterface::TextChanged()
193 void TextInserted(unsigned int position, unsigned int length, const std::string& content) override;
196 * @copydoc Text::EditableControlInterface::TextDeleted()
198 void TextDeleted(unsigned int position, unsigned int length, const std::string& content) override;
201 * @copydoc Text::EditableControlInterface::CaretMoved()
203 void CaretMoved(unsigned int position) override;
206 * @copydoc Text::EditableControlInterface::TextChanged()
208 void TextChanged(bool immediate) override;
211 * @copydoc Text::EditableControlInterface::MaxLengthReached()
213 void MaxLengthReached() override;
216 * @copydoc Text::EditableControlInterface::InputStyleChanged()
218 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
221 * @copydoc Text::EditableControlInterface::AddDecoration()
223 void AddDecoration(Actor& actor, bool needsClipping) override;
225 // From SelectableControlInterface
228 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
230 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
233 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
235 Uint32Pair GetTextSelectionRange() const override;
238 * @copydoc Text::SelectableControlInterface::SelectWholeText()
240 void SelectWholeText() override;
243 * @copydoc Text::SelectableControlInterface::SelectNone()
245 void SelectNone() override;
248 * @copydoc Text::SelectableControlInterface::GetSelectedText()
250 string GetSelectedText() const override;
253 * @copydoc Text::EditableControlInterface::IsEditable()
255 bool IsEditable() const override;
258 * @copydoc Text::EditableControlInterface::SetEditable()
260 void SetEditable(bool editable) override;
262 // From AnchorControlInterface
265 * @copydoc Text::AnchorControlInterface::AnchorClicked()
267 void AnchorClicked(const std::string& href) override;
269 private: // Implementation
271 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
273 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
276 * @brief Callback when Clipboard signals an item should be pasted
277 * @param[in] clipboard handle to Clipboard Event Notifier
279 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
282 * @brief Get a Property Map for the image used for the required Handle Image
283 * @param[out] value the returned image property
284 * @param[in] handleType the type of handle
285 * @param[in] handleImageType the type of image for the given handleType
287 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
290 * @brief Enable or disable clipping.
292 void EnableClipping();
295 * @brief Callback when keyboard is shown/hidden.
297 * @param[in] keyboardShown True if keyboard is shown.
299 void KeyboardStatusChanged(bool keyboardShown);
302 * @brief Callback when TextField is touched
304 * @param[in] actor TextField 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::TextField::InputStyleChangedSignal() are emitted.
317 * @brief Emits TextChanged signal.
319 void EmitTextChangedSignal();
322 * Construct a new TextField.
327 * A reference counted object may only be deleted by calling Unreference()
329 virtual ~TextField();
331 // Undefined copy constructor and assignment operators
332 TextField(const TextField&);
333 TextField& operator=(const TextField& rhs);
336 * @brief Resize actor to the given size.
338 * @param[in] actor The actor to be resized.
339 * @param[in] size Size to change.
341 void ResizeActor(Actor& actor, const Vector2& size);
344 * @brief Render view, create and attach actor(s) to this Text Field.
346 void RenderText(Text::Controller::UpdateTextType updateTextType);
348 // Connection needed to re-render text, when a Text Field returns to the scene.
349 void OnSceneConnect(Dali::Actor actor);
351 public: // For UTC only
352 Text::ControllerPtr GetTextController()
359 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
360 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
361 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
362 Toolkit::DevelTextField::AnchorClickedSignalType mAnchorClickedSignal;
364 InputMethodContext mInputMethodContext;
365 Text::ControllerPtr mController;
366 Text::RendererPtr mRenderer;
367 Text::DecoratorPtr mDecorator;
368 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
369 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
370 Dali::InputMethodOptions mInputMethodOptions;
371 Dali::AutofillItem mAutofillItem;
373 Actor mRenderableActor;
375 Actor mBackgroundActor;
376 CallbackBase* mIdleCallback;
378 float mAlignmentOffset;
379 int mRenderingBackend;
381 bool mHasBeenStaged : 1;
382 bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
385 struct AccessibleImpl : public DevelControl::AccessibleImpl,
386 public virtual Dali::Accessibility::Text,
387 public virtual Dali::Accessibility::EditableText
389 using DevelControl::AccessibleImpl::AccessibleImpl;
391 std::string GetName() override;
392 std::string GetText(size_t startOffset, size_t endOffset) override;
393 size_t GetCharacterCount() override;
394 size_t GetCaretOffset() override;
395 bool SetCaretOffset(size_t offset) override;
396 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
397 Accessibility::Range GetSelection(size_t selectionNum) override;
398 bool RemoveSelection(size_t selectionNum) override;
399 bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
400 bool CopyText(size_t startPosition, size_t endPosition) override;
401 bool CutText(size_t startPosition, size_t endPosition) override;
402 Accessibility::States CalculateStates() override;
403 bool InsertText(size_t startPosition, std::string text) override;
404 bool SetTextContents(std::string newContents) override;
405 bool DeleteText(size_t startPosition, size_t endPosition) override;
409 } // namespace Internal
411 // Helpers for public-api forwarding methods
413 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
415 DALI_ASSERT_ALWAYS(textField);
417 Dali::RefObject& handle = textField.GetImplementation();
419 return static_cast<Toolkit::Internal::TextField&>(handle);
422 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
424 DALI_ASSERT_ALWAYS(textField);
426 const Dali::RefObject& handle = textField.GetImplementation();
428 return static_cast<const Toolkit::Internal::TextField&>(handle);
431 } // namespace Toolkit
435 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H