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() 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 * Construct a new TextField.
307 * A reference counted object may only be deleted by calling Unreference()
309 virtual ~TextField();
311 // Undefined copy constructor and assignment operators
312 TextField(const TextField&);
313 TextField& operator=(const TextField& rhs);
316 * @brief Resize actor to the given size.
318 * @param[in] actor The actor to be resized.
319 * @param[in] size Size to change.
321 void ResizeActor( Actor& actor, const Vector2& size );
324 * @brief Render view, create and attach actor(s) to this Text Field.
326 void RenderText(Text::Controller::UpdateTextType updateTextType);
328 // Connection needed to re-render text, when a Text Field returns to the scene.
329 void OnSceneConnect(Dali::Actor actor);
331 public: // For UTC only
332 Text::ControllerPtr GetTextController()
339 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
340 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
341 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
343 InputMethodContext mInputMethodContext;
344 Text::ControllerPtr mController;
345 Text::RendererPtr mRenderer;
346 Text::DecoratorPtr mDecorator;
347 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
348 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
349 Dali::InputMethodOptions mInputMethodOptions;
351 Actor mRenderableActor;
353 Actor mBackgroundActor;
354 CallbackBase* mIdleCallback;
356 float mAlignmentOffset;
357 int mRenderingBackend;
359 bool mHasBeenStaged : 1;
362 struct AccessibleImpl : public DevelControl::AccessibleImpl,
363 public virtual Dali::Accessibility::Text,
364 public virtual Dali::Accessibility::EditableText
366 using DevelControl::AccessibleImpl::AccessibleImpl;
368 std::string GetName() override;
369 std::string GetText(size_t startOffset, size_t endOffset) override;
370 size_t GetCharacterCount() override;
371 size_t GetCaretOffset() override;
372 bool SetCaretOffset(size_t offset) override;
373 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
374 Accessibility::Range GetSelection(size_t selectionNum) override;
375 bool RemoveSelection(size_t selectionNum) override;
376 bool SetSelection(size_t selectionNum, size_t startOffset, 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 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