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/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-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.h>
33 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
35 #include <dali-toolkit/public-api/controls/control-impl.h>
36 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
45 * @brief A control which renders a short text string.
47 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
51 * @copydoc Dali::Toollkit::TextField::New()
53 static Toolkit::TextField New();
58 * @brief Called when a property of an object of this type is set.
60 * @param[in] object The object whose property is set.
61 * @param[in] index The property index.
62 * @param[in] value The new property value.
64 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
67 * @brief Called to retrieve a property of an object of this type.
69 * @param[in] object The object whose property is to be retrieved.
70 * @param[in] index The property index.
71 * @return The current value of the property.
73 static Property::Value GetProperty(BaseObject* object, Property::Index index);
76 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
78 InputMethodContext GetInputMethodContext();
81 * Connects a callback function with the object's signals.
82 * @param[in] object The object providing the signal.
83 * @param[in] tracker Used to disconnect the signal.
84 * @param[in] signalName The signal to connect to.
85 * @param[in] functor A newly allocated FunctorDelegate.
86 * @return True if the signal was connected.
87 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
89 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
92 * @copydoc TextField::TextChangedSignal()
94 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
97 * @copydoc TextField::MaxLengthReachedSignal()
99 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
102 * @copydoc TextField::TextChangedSignal()
104 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
106 Text::ControllerPtr getController();
108 private: // From Control
110 * @copydoc Control::OnInitialize()
112 void OnInitialize() override;
115 * @copydoc Control::OnStyleChange()
117 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
120 * @copydoc Control::GetNaturalSize()
122 Vector3 GetNaturalSize() override;
125 * @copydoc Control::GetHeightForWidth()
127 float GetHeightForWidth(float width) override;
130 * @copydoc Control::OnInitialize()
132 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
135 * @copydoc Control::OnKeyInputFocusGained()
137 void OnKeyInputFocusGained() override;
140 * @copydoc Control::OnKeyInputFocusLost()
142 void OnKeyInputFocusLost() override;
145 * @copydoc Control::OnAccessibilityActivated()
147 bool OnAccessibilityActivated() override;
150 * @copydoc Control::OnTap()
152 void OnTap(const TapGesture& tap) override;
155 * @copydoc Control::OnPan()
157 void OnPan(const PanGesture& gesture) override;
160 * @copydoc Control::OnLongPress()
162 void OnLongPress(const LongPressGesture& gesture) override;
165 * @copydoc Control::OnSceneConnection()
167 void OnSceneConnection(int depth) override;
170 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
172 bool OnKeyEvent(const KeyEvent& event) override;
174 // From ControlInterface
177 * @copydoc Text::ControlInterface::RequestTextRelayout()
179 void RequestTextRelayout() override;
181 // From EditableControlInterface
184 * @copydoc Text::EditableControlInterface::TextChanged()
186 void TextInserted(unsigned int position, unsigned int length, const std::string& content) override;
189 * @copydoc Text::EditableControlInterface::TextDeleted()
191 void TextDeleted(unsigned int position, unsigned int length, const std::string& content) override;
194 * @copydoc Text::EditableControlInterface::CaretMoved()
196 void CaretMoved(unsigned int position) override;
199 * @copydoc Text::EditableControlInterface::TextChanged()
201 void TextChanged() override;
204 * @copydoc Text::EditableControlInterface::MaxLengthReached()
206 void MaxLengthReached() override;
209 * @copydoc Text::EditableControlInterface::InputStyleChanged()
211 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
214 * @copydoc Text::EditableControlInterface::AddDecoration()
216 void AddDecoration(Actor& actor, bool needsClipping) override;
218 // From SelectableControlInterface
221 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
223 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
226 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
228 Uint32Pair GetTextSelectionRange() const override;
231 * @copydoc Text::SelectableControlInterface::SelectWholeText()
233 void SelectWholeText() override;
236 * @copydoc Text::SelectableControlInterface::SelectNone()
238 void SelectNone() override;
241 * @copydoc Text::SelectableControlInterface::GetSelectedText()
243 string GetSelectedText() const override;
246 * @copydoc Text::EditableControlInterface::IsEditable()
248 bool IsEditable() const override;
251 * @copydoc Text::EditableControlInterface::SetEditable()
253 void SetEditable(bool editable) override;
255 private: // Implementation
257 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
259 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
262 * @brief Callback when Clipboard signals an item should be pasted
263 * @param[in] clipboard handle to Clipboard Event Notifier
265 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
268 * @brief Get a Property Map for the image used for the required Handle Image
269 * @param[out] value the returned image property
270 * @param[in] handleType the type of handle
271 * @param[in] handleImageType the type of image for the given handleType
273 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
276 * @brief Enable or disable clipping.
278 void EnableClipping();
281 * @brief Callback when keyboard is shown/hidden.
283 * @param[in] keyboardShown True if keyboard is shown.
285 void KeyboardStatusChanged(bool keyboardShown);
288 * @brief Callback when TextField is touched
290 * @param[in] actor TextField touched
291 * @param[in] touch Touch information
293 bool OnTouched(Actor actor, const TouchEvent& touch);
296 * @brief Callbacks called on idle.
298 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
303 * Construct a new TextField.
308 * A reference counted object may only be deleted by calling Unreference()
310 virtual ~TextField();
312 // Undefined copy constructor and assignment operators
313 TextField(const TextField&);
314 TextField& operator=(const TextField& rhs);
317 * @brief Resize actor to the given size.
319 * @param[in] actor The actor to be resized.
320 * @param[in] size Size to change.
322 void ResizeActor( Actor& actor, const Vector2& size );
325 * @brief Render view, create and attach actor(s) to this Text Field.
327 void RenderText(Text::Controller::UpdateTextType updateTextType);
329 // Connection needed to re-render text, when a Text Field returns to the scene.
330 void OnSceneConnect(Dali::Actor actor);
332 public: // For UTC only
333 Text::ControllerPtr GetTextController()
340 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
341 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
342 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
344 InputMethodContext mInputMethodContext;
345 Text::ControllerPtr mController;
346 Text::RendererPtr mRenderer;
347 Text::DecoratorPtr mDecorator;
348 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
349 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
350 Dali::InputMethodOptions mInputMethodOptions;
351 Dali::AutofillItem mAutofillItem;
353 Actor mRenderableActor;
355 Actor mBackgroundActor;
356 CallbackBase* mIdleCallback;
358 float mAlignmentOffset;
359 int mRenderingBackend;
361 bool mHasBeenStaged : 1;
364 struct AccessibleImpl : public DevelControl::AccessibleImpl,
365 public virtual Dali::Accessibility::Text,
366 public virtual Dali::Accessibility::EditableText
368 using DevelControl::AccessibleImpl::AccessibleImpl;
370 std::string GetName() override;
371 std::string GetText(size_t startOffset, size_t endOffset) override;
372 size_t GetCharacterCount() override;
373 size_t GetCaretOffset() override;
374 bool SetCaretOffset(size_t offset) override;
375 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
376 Accessibility::Range GetSelection(size_t selectionNum) override;
377 bool RemoveSelection(size_t selectionNum) override;
378 bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
379 bool CopyText(size_t startPosition, size_t endPosition) override;
380 bool CutText(size_t startPosition, size_t endPosition) override;
381 Accessibility::States CalculateStates() override;
385 } // namespace Internal
387 // Helpers for public-api forwarding methods
389 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
391 DALI_ASSERT_ALWAYS(textField);
393 Dali::RefObject& handle = textField.GetImplementation();
395 return static_cast<Toolkit::Internal::TextField&>(handle);
398 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
400 DALI_ASSERT_ALWAYS(textField);
402 const Dali::RefObject& handle = textField.GetImplementation();
404 return static_cast<const Toolkit::Internal::TextField&>(handle);
407 } // namespace Toolkit
411 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H