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/internal/controls/control/control-data-impl.h>
27 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29 #include <dali-toolkit/internal/text/text-control-interface.h>
30 #include <dali-toolkit/internal/text/text-controller.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/public-api/controls/control-impl.h>
34 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
43 * @brief A control which renders a short text string.
45 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
49 * @copydoc Dali::Toollkit::TextField::New()
51 static Toolkit::TextField New();
56 * @brief Called when a property of an object of this type is set.
58 * @param[in] object The object whose property is set.
59 * @param[in] index The property index.
60 * @param[in] value The new property value.
62 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
65 * @brief Called to retrieve a property of an object of this type.
67 * @param[in] object The object whose property is to be retrieved.
68 * @param[in] index The property index.
69 * @return The current value of the property.
71 static Property::Value GetProperty(BaseObject* object, Property::Index index);
74 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
76 InputMethodContext GetInputMethodContext();
79 * Connects a callback function with the object's signals.
80 * @param[in] object The object providing the signal.
81 * @param[in] tracker Used to disconnect the signal.
82 * @param[in] signalName The signal to connect to.
83 * @param[in] functor A newly allocated FunctorDelegate.
84 * @return True if the signal was connected.
85 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
87 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
90 * @copydoc TextField::TextChangedSignal()
92 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
95 * @copydoc TextField::MaxLengthReachedSignal()
97 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
100 * @copydoc TextField::TextChangedSignal()
102 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
104 Text::ControllerPtr getController();
106 private: // From Control
108 * @copydoc Control::OnInitialize()
110 void OnInitialize() override;
113 * @copydoc Control::OnStyleChange()
115 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
118 * @copydoc Control::GetNaturalSize()
120 Vector3 GetNaturalSize() override;
123 * @copydoc Control::GetHeightForWidth()
125 float GetHeightForWidth(float width) override;
128 * @copydoc Control::OnInitialize()
130 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
133 * @copydoc Control::OnKeyInputFocusGained()
135 void OnKeyInputFocusGained() override;
138 * @copydoc Control::OnKeyInputFocusLost()
140 void OnKeyInputFocusLost() override;
143 * @copydoc Control::OnAccessibilityActivated()
145 bool OnAccessibilityActivated() override;
148 * @copydoc Control::OnTap()
150 void OnTap(const TapGesture& tap) override;
153 * @copydoc Control::OnPan()
155 void OnPan(const PanGesture& gesture) override;
158 * @copydoc Control::OnLongPress()
160 void OnLongPress(const LongPressGesture& gesture) override;
163 * @copydoc Control::OnSceneConnection()
165 void OnSceneConnection(int depth) override;
168 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
170 bool OnKeyEvent(const KeyEvent& event) override;
172 // From ControlInterface
175 * @copydoc Text::ControlInterface::RequestTextRelayout()
177 void RequestTextRelayout() override;
179 // From EditableControlInterface
182 * @copydoc Text::EditableControlInterface::TextChanged()
184 void TextInserted(unsigned int position, unsigned int length, const std::string& content) override;
187 * @copydoc Text::EditableControlInterface::TextDeleted()
189 void TextDeleted(unsigned int position, unsigned int length, const std::string& content) override;
192 * @copydoc Text::EditableControlInterface::CaretMoved()
194 void CaretMoved(unsigned int position) override;
197 * @copydoc Text::EditableControlInterface::TextChanged()
199 void TextChanged() override;
202 * @copydoc Text::EditableControlInterface::MaxLengthReached()
204 void MaxLengthReached() override;
207 * @copydoc Text::EditableControlInterface::InputStyleChanged()
209 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
212 * @copydoc Text::EditableControlInterface::AddDecoration()
214 void AddDecoration(Actor& actor, bool needsClipping) override;
216 // From SelectableControlInterface
219 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
221 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
224 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
226 Uint32Pair GetTextSelectionRange() const override;
229 * @copydoc Text::SelectableControlInterface::SelectWholeText()
231 void SelectWholeText() override;
234 * @copydoc Text::SelectableControlInterface::SelectNone()
236 void SelectNone() override;
239 * @copydoc Text::SelectableControlInterface::GetSelectedText()
241 string GetSelectedText() const override;
244 * @copydoc Text::EditableControlInterface::IsEditable()
246 bool IsEditable() const override;
249 * @copydoc Text::EditableControlInterface::SetEditable()
251 void SetEditable(bool editable) override;
253 private: // Implementation
255 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
257 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
260 * @brief Callback when Clipboard signals an item should be pasted
261 * @param[in] clipboard handle to Clipboard Event Notifier
263 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
266 * @brief Get a Property Map for the image used for the required Handle Image
267 * @param[out] value the returned image property
268 * @param[in] handleType the type of handle
269 * @param[in] handleImageType the type of image for the given handleType
271 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
274 * @brief Enable or disable clipping.
276 void EnableClipping();
279 * @brief Callback when keyboard is shown/hidden.
281 * @param[in] keyboardShown True if keyboard is shown.
283 void KeyboardStatusChanged(bool keyboardShown);
286 * @brief Callback when TextField is touched
288 * @param[in] actor TextField touched
289 * @param[in] touch Touch information
291 bool OnTouched(Actor actor, const TouchEvent& touch);
294 * @brief Callbacks called on idle.
296 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
301 * Construct a new TextField.
306 * A reference counted object may only be deleted by calling Unreference()
308 virtual ~TextField();
310 // Undefined copy constructor and assignment operators
311 TextField(const TextField&);
312 TextField& operator=(const TextField& rhs);
315 * @brief Render view, create and attach actor(s) to this Text Field.
317 void RenderText(Text::Controller::UpdateTextType updateTextType);
319 // Connection needed to re-render text, when a Text Field returns to the scene.
320 void OnSceneConnect(Dali::Actor actor);
322 public: // For UTC only
323 Text::ControllerPtr GetTextController()
330 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
331 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
332 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
334 InputMethodContext mInputMethodContext;
335 Text::ControllerPtr mController;
336 Text::RendererPtr mRenderer;
337 Text::DecoratorPtr mDecorator;
338 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
339 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
340 Dali::InputMethodOptions mInputMethodOptions;
342 Actor mRenderableActor;
344 Actor mBackgroundActor;
345 CallbackBase* mIdleCallback;
347 float mAlignmentOffset;
348 int mRenderingBackend;
350 bool mHasBeenStaged : 1;
353 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
354 public virtual Dali::Accessibility::Text,
355 public virtual Dali::Accessibility::EditableText
357 using Control::Impl::AccessibleImpl::AccessibleImpl;
359 std::string GetName() override;
360 std::string GetText(size_t startOffset, size_t endOffset) override;
361 size_t GetCharacterCount() override;
362 size_t GetCaretOffset() override;
363 bool SetCaretOffset(size_t offset) override;
364 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
365 Accessibility::Range GetSelection(size_t selectionNum) override;
366 bool RemoveSelection(size_t selectionNum) override;
367 bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
368 bool CopyText(size_t startPosition, size_t endPosition) override;
369 bool CutText(size_t startPosition, size_t endPosition) override;
370 Accessibility::States CalculateStates() override;
374 } // namespace Internal
376 // Helpers for public-api forwarding methods
378 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
380 DALI_ASSERT_ALWAYS(textField);
382 Dali::RefObject& handle = textField.GetImplementation();
384 return static_cast<Toolkit::Internal::TextField&>(handle);
387 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
389 DALI_ASSERT_ALWAYS(textField);
391 const Dali::RefObject& handle = textField.GetImplementation();
393 return static_cast<const Toolkit::Internal::TextField&>(handle);
396 } // namespace Toolkit
400 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H