1a3e0fd82Sopenharmony_ci/*
2a3e0fd82Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License.
5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at
6a3e0fd82Sopenharmony_ci *
7a3e0fd82Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a3e0fd82Sopenharmony_ci *
9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and
13a3e0fd82Sopenharmony_ci * limitations under the License.
14a3e0fd82Sopenharmony_ci */
15a3e0fd82Sopenharmony_ci
16a3e0fd82Sopenharmony_ci/**
17a3e0fd82Sopenharmony_ci * @addtogroup UI_Components
18a3e0fd82Sopenharmony_ci * @{
19a3e0fd82Sopenharmony_ci *
20a3e0fd82Sopenharmony_ci * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
21a3e0fd82Sopenharmony_ci *
22a3e0fd82Sopenharmony_ci */
23a3e0fd82Sopenharmony_ci
24a3e0fd82Sopenharmony_ci/**
25a3e0fd82Sopenharmony_ci * @file ui_edit_text.h
26a3e0fd82Sopenharmony_ci *
27a3e0fd82Sopenharmony_ci * @brief Declares a <b>UIEditText</b> class that represents a input edit view.
28a3e0fd82Sopenharmony_ci *
29a3e0fd82Sopenharmony_ci */
30a3e0fd82Sopenharmony_ci
31a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_EDIT_TEXT
32a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_EDIT_TEXT
33a3e0fd82Sopenharmony_ci
34a3e0fd82Sopenharmony_ci#include "animator/animator.h"
35a3e0fd82Sopenharmony_ci#include "common/text.h"
36a3e0fd82Sopenharmony_ci#include "components/ui_view.h"
37a3e0fd82Sopenharmony_ci
38a3e0fd82Sopenharmony_cinamespace OHOS {
39a3e0fd82Sopenharmony_ci/**
40a3e0fd82Sopenharmony_ci * @brief Defines the functions for presenting a edit text in a specified area, setting the style and background color,
41a3e0fd82Sopenharmony_ci *        and setting the display mode such as text and password type.
42a3e0fd82Sopenharmony_ci */
43a3e0fd82Sopenharmony_ciclass UIEditText : public UIView {
44a3e0fd82Sopenharmony_cipublic:
45a3e0fd82Sopenharmony_ci    /**
46a3e0fd82Sopenharmony_ci     * @brief Defines a value change event listener. You need to register this listener with the view to listen to
47a3e0fd82Sopenharmony_ci     *        value change events.
48a3e0fd82Sopenharmony_ci     */
49a3e0fd82Sopenharmony_ci    class OnChangeListener : public HeapBase {
50a3e0fd82Sopenharmony_ci    public:
51a3e0fd82Sopenharmony_ci        /**
52a3e0fd82Sopenharmony_ci         * @brief Called when edit text value changed.
53a3e0fd82Sopenharmony_ci         *
54a3e0fd82Sopenharmony_ci         * @param view Indicates the UIEditView.
55a3e0fd82Sopenharmony_ci         * @param value Indicates the changed value.
56a3e0fd82Sopenharmony_ci         */
57a3e0fd82Sopenharmony_ci        virtual void OnChange(UIView& view, const char* value) {}
58a3e0fd82Sopenharmony_ci
59a3e0fd82Sopenharmony_ci        /**
60a3e0fd82Sopenharmony_ci         * @brief A destructor used to delete the <b>OnChangeListener</b> instance.
61a3e0fd82Sopenharmony_ci         */
62a3e0fd82Sopenharmony_ci        virtual ~OnChangeListener() {}
63a3e0fd82Sopenharmony_ci    };
64a3e0fd82Sopenharmony_ci
65a3e0fd82Sopenharmony_ci    /**
66a3e0fd82Sopenharmony_ci     * @brief A constructor used to create a <b>UIEditText</b> instance.
67a3e0fd82Sopenharmony_ci     */
68a3e0fd82Sopenharmony_ci    UIEditText();
69a3e0fd82Sopenharmony_ci
70a3e0fd82Sopenharmony_ci    /**
71a3e0fd82Sopenharmony_ci     * @brief A destructor used to delete the <b>UIEditText</b> instance.
72a3e0fd82Sopenharmony_ci     */
73a3e0fd82Sopenharmony_ci    virtual ~UIEditText();
74a3e0fd82Sopenharmony_ci
75a3e0fd82Sopenharmony_ci    /**
76a3e0fd82Sopenharmony_ci     * @brief Obtains the view type.
77a3e0fd82Sopenharmony_ci     *
78a3e0fd82Sopenharmony_ci     * @return Returns <b>UI_EDIT_TEXT</b>, as defined in {@link UIViewType}.
79a3e0fd82Sopenharmony_ci     */
80a3e0fd82Sopenharmony_ci    UIViewType GetViewType() const override
81a3e0fd82Sopenharmony_ci    {
82a3e0fd82Sopenharmony_ci        return UI_EDIT_TEXT;
83a3e0fd82Sopenharmony_ci    }
84a3e0fd82Sopenharmony_ci
85a3e0fd82Sopenharmony_ci    /**
86a3e0fd82Sopenharmony_ci     * @brief   Executes the press event action
87a3e0fd82Sopenharmony_ci     *
88a3e0fd82Sopenharmony_ci     * @param   [in] event   The press event, contain press position.
89a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
90a3e0fd82Sopenharmony_ci     */
91a3e0fd82Sopenharmony_ci    bool OnPressEvent(const PressEvent& event) override;
92a3e0fd82Sopenharmony_ci
93a3e0fd82Sopenharmony_ci    /**
94a3e0fd82Sopenharmony_ci     * @brief   Executes the long press event action
95a3e0fd82Sopenharmony_ci     *
96a3e0fd82Sopenharmony_ci     * @param   [in] event   The long press event, contain press position.
97a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
98a3e0fd82Sopenharmony_ci     */
99a3e0fd82Sopenharmony_ci    bool OnLongPressEvent(const LongPressEvent& event) override;
100a3e0fd82Sopenharmony_ci
101a3e0fd82Sopenharmony_ci    /**
102a3e0fd82Sopenharmony_ci     * @brief Sets the view style.
103a3e0fd82Sopenharmony_ci     *
104a3e0fd82Sopenharmony_ci     * @param style Indicates the view style.
105a3e0fd82Sopenharmony_ci     */
106a3e0fd82Sopenharmony_ci    void SetStyle(Style& style) override;
107a3e0fd82Sopenharmony_ci
108a3e0fd82Sopenharmony_ci    /**
109a3e0fd82Sopenharmony_ci     * @brief Sets a style.
110a3e0fd82Sopenharmony_ci     *
111a3e0fd82Sopenharmony_ci     * @param key Indicates the key of the style to set.
112a3e0fd82Sopenharmony_ci     * @param value Indicates the value matching the key.
113a3e0fd82Sopenharmony_ci     */
114a3e0fd82Sopenharmony_ci    void SetStyle(uint8_t key, int64_t value) override;
115a3e0fd82Sopenharmony_ci
116a3e0fd82Sopenharmony_ci    /**
117a3e0fd82Sopenharmony_ci     * @brief Checks whether this view needs to be covered before drawing it.
118a3e0fd82Sopenharmony_ci     *
119a3e0fd82Sopenharmony_ci     * @param invalidatedArea Indicates the area to draw.
120a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if this view needs to be covered; returns <b> false</b> otherwise.
121a3e0fd82Sopenharmony_ci     */
122a3e0fd82Sopenharmony_ci    bool OnPreDraw(Rect& invalidatedArea) const override
123a3e0fd82Sopenharmony_ci    {
124a3e0fd82Sopenharmony_ci        return false;
125a3e0fd82Sopenharmony_ci    }
126a3e0fd82Sopenharmony_ci
127a3e0fd82Sopenharmony_ci    bool OnDragEvent(const DragEvent& event) override;
128a3e0fd82Sopenharmony_ci
129a3e0fd82Sopenharmony_ci    /**
130a3e0fd82Sopenharmony_ci     * @brief Draws this view.
131a3e0fd82Sopenharmony_ci     *
132a3e0fd82Sopenharmony_ci     * @param invalidatedArea Indicates the area to draw.
133a3e0fd82Sopenharmony_ci     */
134a3e0fd82Sopenharmony_ci    void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
135a3e0fd82Sopenharmony_ci
136a3e0fd82Sopenharmony_ci    void Focus() override;
137a3e0fd82Sopenharmony_ci
138a3e0fd82Sopenharmony_ci    void Blur() override;
139a3e0fd82Sopenharmony_ci
140a3e0fd82Sopenharmony_ci    /**
141a3e0fd82Sopenharmony_ci     * @brief Sets the text content.
142a3e0fd82Sopenharmony_ci     *
143a3e0fd82Sopenharmony_ci     * @param text Indicates the pointer to the text content.
144a3e0fd82Sopenharmony_ci     */
145a3e0fd82Sopenharmony_ci    void SetText(const char* text);
146a3e0fd82Sopenharmony_ci
147a3e0fd82Sopenharmony_ci    /**
148a3e0fd82Sopenharmony_ci     * @brief Obtains the input text of this view.
149a3e0fd82Sopenharmony_ci     *
150a3e0fd82Sopenharmony_ci     * @return Returns the text.
151a3e0fd82Sopenharmony_ci     */
152a3e0fd82Sopenharmony_ci    const char* GetText();
153a3e0fd82Sopenharmony_ci
154a3e0fd82Sopenharmony_ci    /**
155a3e0fd82Sopenharmony_ci     * @brief Sets the placeholder content.
156a3e0fd82Sopenharmony_ci     *
157a3e0fd82Sopenharmony_ci     * @param placeholder Indicates the pointer to the placeholder content.
158a3e0fd82Sopenharmony_ci     */
159a3e0fd82Sopenharmony_ci    void SetPlaceholder(const char* placeholder);
160a3e0fd82Sopenharmony_ci
161a3e0fd82Sopenharmony_ci    /**
162a3e0fd82Sopenharmony_ci     * @brief Sets the vaule listener for this view.
163a3e0fd82Sopenharmony_ci     *        The listener is triggered to invoke the callback function when the value changed.
164a3e0fd82Sopenharmony_ci     *
165a3e0fd82Sopenharmony_ci     * @param listener Indicates the listener to set. For details, see {@link OnChangeListener}.
166a3e0fd82Sopenharmony_ci     */
167a3e0fd82Sopenharmony_ci    const char* GetPlaceholder();
168a3e0fd82Sopenharmony_ci
169a3e0fd82Sopenharmony_ci    /**
170a3e0fd82Sopenharmony_ci     * @brief Set max length of the input text.
171a3e0fd82Sopenharmony_ci     *
172a3e0fd82Sopenharmony_ci     * @param maxLength max length size.
173a3e0fd82Sopenharmony_ci     */
174a3e0fd82Sopenharmony_ci    void SetMaxLength(uint16_t maxLength);
175a3e0fd82Sopenharmony_ci
176a3e0fd82Sopenharmony_ci    /**
177a3e0fd82Sopenharmony_ci     * @brief Get max length of the input text.
178a3e0fd82Sopenharmony_ci     *
179a3e0fd82Sopenharmony_ci     * @return return the length size.
180a3e0fd82Sopenharmony_ci     */
181a3e0fd82Sopenharmony_ci    uint16_t GetMaxLength();
182a3e0fd82Sopenharmony_ci
183a3e0fd82Sopenharmony_ci    /**
184a3e0fd82Sopenharmony_ci     * @brief Set the input type.
185a3e0fd82Sopenharmony_ci     *
186a3e0fd82Sopenharmony_ci     * @param type the input type, such as text or password.
187a3e0fd82Sopenharmony_ci     */
188a3e0fd82Sopenharmony_ci    void SetInputType(InputType type);
189a3e0fd82Sopenharmony_ci
190a3e0fd82Sopenharmony_ci    /**
191a3e0fd82Sopenharmony_ci     * @brief Get the input type.
192a3e0fd82Sopenharmony_ci     *
193a3e0fd82Sopenharmony_ci     * @param type the input type, such as text or password.
194a3e0fd82Sopenharmony_ci     */
195a3e0fd82Sopenharmony_ci    InputType GetInputType()
196a3e0fd82Sopenharmony_ci    {
197a3e0fd82Sopenharmony_ci        return inputType_;
198a3e0fd82Sopenharmony_ci    }
199a3e0fd82Sopenharmony_ci
200a3e0fd82Sopenharmony_ci    /**
201a3e0fd82Sopenharmony_ci     * @brief Sets the color for this text.
202a3e0fd82Sopenharmony_ci     *
203a3e0fd82Sopenharmony_ci     * @param color Indicates the text color to set.
204a3e0fd82Sopenharmony_ci     */
205a3e0fd82Sopenharmony_ci    void SetTextColor(ColorType color)
206a3e0fd82Sopenharmony_ci    {
207a3e0fd82Sopenharmony_ci        useTextColor_ = true;
208a3e0fd82Sopenharmony_ci        textColor_ = color;
209a3e0fd82Sopenharmony_ci    }
210a3e0fd82Sopenharmony_ci
211a3e0fd82Sopenharmony_ci    /**
212a3e0fd82Sopenharmony_ci     * @brief Obtains the color of this text.
213a3e0fd82Sopenharmony_ci     *
214a3e0fd82Sopenharmony_ci     * @return Returns the text color.
215a3e0fd82Sopenharmony_ci     */
216a3e0fd82Sopenharmony_ci    ColorType GetTextColor() const
217a3e0fd82Sopenharmony_ci    {
218a3e0fd82Sopenharmony_ci        return useTextColor_ ? textColor_ : GetStyleConst().textColor_;
219a3e0fd82Sopenharmony_ci    }
220a3e0fd82Sopenharmony_ci
221a3e0fd82Sopenharmony_ci    /**
222a3e0fd82Sopenharmony_ci     * @brief Sets the color of the palceholder for this text.
223a3e0fd82Sopenharmony_ci     *
224a3e0fd82Sopenharmony_ci     * @param color Indicates the palceholder color to set.
225a3e0fd82Sopenharmony_ci     */
226a3e0fd82Sopenharmony_ci    void SetPlaceholderColor(ColorType color)
227a3e0fd82Sopenharmony_ci    {
228a3e0fd82Sopenharmony_ci        placeholderColor_ = color;
229a3e0fd82Sopenharmony_ci    }
230a3e0fd82Sopenharmony_ci
231a3e0fd82Sopenharmony_ci    /**
232a3e0fd82Sopenharmony_ci     * @brief Obtains the palceholder color of this text.
233a3e0fd82Sopenharmony_ci     *
234a3e0fd82Sopenharmony_ci     * @return Returns the palceholder color.
235a3e0fd82Sopenharmony_ci     */
236a3e0fd82Sopenharmony_ci    ColorType GetPlaceholderColor() const
237a3e0fd82Sopenharmony_ci    {
238a3e0fd82Sopenharmony_ci        return placeholderColor_;
239a3e0fd82Sopenharmony_ci    }
240a3e0fd82Sopenharmony_ci
241a3e0fd82Sopenharmony_ci    /**
242a3e0fd82Sopenharmony_ci     * @brief Sets the cursor color.
243a3e0fd82Sopenharmony_ci     *
244a3e0fd82Sopenharmony_ci     * @param color Indicates the cursor color to set.
245a3e0fd82Sopenharmony_ci     */
246a3e0fd82Sopenharmony_ci    void SetCursorColor(ColorType color)
247a3e0fd82Sopenharmony_ci    {
248a3e0fd82Sopenharmony_ci        cursorColor_ = color;
249a3e0fd82Sopenharmony_ci    }
250a3e0fd82Sopenharmony_ci
251a3e0fd82Sopenharmony_ci    /**
252a3e0fd82Sopenharmony_ci     * @brief Obtains the cursor color.
253a3e0fd82Sopenharmony_ci     *
254a3e0fd82Sopenharmony_ci     * @return Returns the cursor color.
255a3e0fd82Sopenharmony_ci     */
256a3e0fd82Sopenharmony_ci    ColorType GetCursorColor() const
257a3e0fd82Sopenharmony_ci    {
258a3e0fd82Sopenharmony_ci        return cursorColor_;
259a3e0fd82Sopenharmony_ci    }
260a3e0fd82Sopenharmony_ci
261a3e0fd82Sopenharmony_ci    /**
262a3e0fd82Sopenharmony_ci     * @brief Sets the font ID for this view.
263a3e0fd82Sopenharmony_ci     *
264a3e0fd82Sopenharmony_ci     * @param fontId Indicates the font ID composed of font name and size.
265a3e0fd82Sopenharmony_ci     */
266a3e0fd82Sopenharmony_ci    void SetFontId(uint16_t fontId);
267a3e0fd82Sopenharmony_ci
268a3e0fd82Sopenharmony_ci    /**
269a3e0fd82Sopenharmony_ci     * @brief Obtains the font ID composed of font name and size.
270a3e0fd82Sopenharmony_ci     *
271a3e0fd82Sopenharmony_ci     * @return Returns the front ID of this view.
272a3e0fd82Sopenharmony_ci     */
273a3e0fd82Sopenharmony_ci    uint8_t GetFontId()
274a3e0fd82Sopenharmony_ci    {
275a3e0fd82Sopenharmony_ci        InitText();
276a3e0fd82Sopenharmony_ci        return inputText_->GetFontId();
277a3e0fd82Sopenharmony_ci    }
278a3e0fd82Sopenharmony_ci
279a3e0fd82Sopenharmony_ci    /**
280a3e0fd82Sopenharmony_ci     * @brief Sets the font for this viewview.
281a3e0fd82Sopenharmony_ci     *
282a3e0fd82Sopenharmony_ci     * @param name Indicates the pointer to the font name.
283a3e0fd82Sopenharmony_ci     * @param size Indicates the font size to set.
284a3e0fd82Sopenharmony_ci     */
285a3e0fd82Sopenharmony_ci    void SetFont(const char* name, uint8_t size);
286a3e0fd82Sopenharmony_ci
287a3e0fd82Sopenharmony_ci    /**
288a3e0fd82Sopenharmony_ci     * @brief Obtains the width of this text.
289a3e0fd82Sopenharmony_ci     *
290a3e0fd82Sopenharmony_ci     * @return Returns the text width.
291a3e0fd82Sopenharmony_ci     */
292a3e0fd82Sopenharmony_ci    uint16_t GetTextWidth();
293a3e0fd82Sopenharmony_ci
294a3e0fd82Sopenharmony_ci    /**
295a3e0fd82Sopenharmony_ci     * @brief Obtains the height of this text.
296a3e0fd82Sopenharmony_ci     *
297a3e0fd82Sopenharmony_ci     * @return Returns the text height.
298a3e0fd82Sopenharmony_ci     */
299a3e0fd82Sopenharmony_ci    uint16_t GetTextHeight();
300a3e0fd82Sopenharmony_ci
301a3e0fd82Sopenharmony_ci    void ReMeasure() override;
302a3e0fd82Sopenharmony_ci
303a3e0fd82Sopenharmony_ci    /**
304a3e0fd82Sopenharmony_ci     * @brief Insert the text passed from the input method.
305a3e0fd82Sopenharmony_ci     *
306a3e0fd82Sopenharmony_ci     * @param text the text input by the user passed form input method.
307a3e0fd82Sopenharmony_ci     */
308a3e0fd82Sopenharmony_ci    virtual void InsertText(std::string text);
309a3e0fd82Sopenharmony_ci
310a3e0fd82Sopenharmony_ci    /**
311a3e0fd82Sopenharmony_ci     * @brief Delete the input text from backward.
312a3e0fd82Sopenharmony_ci     *
313a3e0fd82Sopenharmony_ci     * @param length the length of charactor to delete.
314a3e0fd82Sopenharmony_ci     */
315a3e0fd82Sopenharmony_ci    virtual void DeleteBackward(uint32_t length);
316a3e0fd82Sopenharmony_ci
317a3e0fd82Sopenharmony_ci    /**
318a3e0fd82Sopenharmony_ci     * @brief Sets the vaule listener for this view.
319a3e0fd82Sopenharmony_ci     *        The listener is triggered to invoke the callback function when the value changed.
320a3e0fd82Sopenharmony_ci     *
321a3e0fd82Sopenharmony_ci     * @param listener Indicates the listener to set. For details, see {@link OnChangeListener}.
322a3e0fd82Sopenharmony_ci     */
323a3e0fd82Sopenharmony_ci    void SetOnChangeListener(OnChangeListener* onChangeListener)
324a3e0fd82Sopenharmony_ci    {
325a3e0fd82Sopenharmony_ci        onChangeListener_ = onChangeListener;
326a3e0fd82Sopenharmony_ci    }
327a3e0fd82Sopenharmony_ci
328a3e0fd82Sopenharmony_ci    /**
329a3e0fd82Sopenharmony_ci     * @brief Obtains the vaule change event listener for the view.
330a3e0fd82Sopenharmony_ci     *
331a3e0fd82Sopenharmony_ci     * @return Returns the vaule change event listener.
332a3e0fd82Sopenharmony_ci     */
333a3e0fd82Sopenharmony_ci    OnChangeListener*& GetOnChangeListener()
334a3e0fd82Sopenharmony_ci    {
335a3e0fd82Sopenharmony_ci        return onChangeListener_;
336a3e0fd82Sopenharmony_ci    }
337a3e0fd82Sopenharmony_ci
338a3e0fd82Sopenharmony_ci    /**
339a3e0fd82Sopenharmony_ci     * @brief set the cursor index.
340a3e0fd82Sopenharmony_ci     */
341a3e0fd82Sopenharmony_ci    void SetCursorIndex(uint16_t cursorIndex);
342a3e0fd82Sopenharmony_ci
343a3e0fd82Sopenharmony_ci    /**
344a3e0fd82Sopenharmony_ci     * @brief Is it focused or not.
345a3e0fd82Sopenharmony_ci     */
346a3e0fd82Sopenharmony_ci    bool GetIsFocus()
347a3e0fd82Sopenharmony_ci    {
348a3e0fd82Sopenharmony_ci        return isFocused_;
349a3e0fd82Sopenharmony_ci    }
350a3e0fd82Sopenharmony_ci
351a3e0fd82Sopenharmony_ci    uint16_t GetCursorIndex();
352a3e0fd82Sopenharmony_ci
353a3e0fd82Sopenharmony_ciprotected:
354a3e0fd82Sopenharmony_ci    virtual void InitText();
355a3e0fd82Sopenharmony_ci    virtual void UpdateExtraOffsetX(const uint16_t firstVisibleIndex,
356a3e0fd82Sopenharmony_ci                                    const uint16_t lastVisibleIndex);
357a3e0fd82Sopenharmony_ci    virtual uint16_t GetFirstVisibleIndex();
358a3e0fd82Sopenharmony_ci    virtual uint16_t GetLastVisibleIndex();
359a3e0fd82Sopenharmony_ci    virtual uint16_t GetTextLength();
360a3e0fd82Sopenharmony_ci    virtual void UpdateInsertDeletedOffset();
361a3e0fd82Sopenharmony_ci    virtual void UpdateOffsetX();
362a3e0fd82Sopenharmony_ci    virtual uint16_t GetTextWidthByCursorIndex(const uint16_t cursorIndex);
363a3e0fd82Sopenharmony_ci
364a3e0fd82Sopenharmony_ci    void SetText(std::string text);
365a3e0fd82Sopenharmony_ci    void InsertTextByCursorIndex(std::string text);
366a3e0fd82Sopenharmony_ci    void UpdateOffsetBySetCursorIndex();
367a3e0fd82Sopenharmony_ci    void UpdateOffsetByInputType();
368a3e0fd82Sopenharmony_ci
369a3e0fd82Sopenharmony_ci    Text* inputText_;
370a3e0fd82Sopenharmony_ci    Text* placeholderText_;
371a3e0fd82Sopenharmony_ci    int16_t offsetX_;
372a3e0fd82Sopenharmony_ci    uint16_t cursorIndex_;
373a3e0fd82Sopenharmony_ci    uint16_t deleteTextWidth_;
374a3e0fd82Sopenharmony_ci    uint16_t insertTextWidth_;
375a3e0fd82Sopenharmony_ci
376a3e0fd82Sopenharmony_ci    enum UpdateOffsetState : uint8_t {
377a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_UNKNOW = 0,
378a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_INTERFACE,
379a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_PRESS_EVENT,
380a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_DELETE,
381a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_INSERT,
382a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_SET_CURSOR,
383a3e0fd82Sopenharmony_ci        UPDATE_OFFSET_INPUT_TYPE
384a3e0fd82Sopenharmony_ci    };
385a3e0fd82Sopenharmony_ci
386a3e0fd82Sopenharmony_ci    UpdateOffsetState offsetState_;
387a3e0fd82Sopenharmony_ciprivate:
388a3e0fd82Sopenharmony_ci    friend class CursorAnimator;
389a3e0fd82Sopenharmony_ci
390a3e0fd82Sopenharmony_ci    void RemeasureForMarquee(int16_t textWidth);
391a3e0fd82Sopenharmony_ci    void UpdateInnerText();
392a3e0fd82Sopenharmony_ci    void CheckValueChange(std::string text);
393a3e0fd82Sopenharmony_ci    void RefreshText();
394a3e0fd82Sopenharmony_ci    void UpdateTextString(std::string text);
395a3e0fd82Sopenharmony_ci    void CalculatedCursorPos(bool drawPlaceholder);
396a3e0fd82Sopenharmony_ci    void DealPressEvents(bool longPressEvent, const Event &event);
397a3e0fd82Sopenharmony_ci    std::string GetInnerText();
398a3e0fd82Sopenharmony_ci    std::string GetInnerPassword();
399a3e0fd82Sopenharmony_ci    void DrawCursor(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, bool drawPlaceholder);
400a3e0fd82Sopenharmony_ci
401a3e0fd82Sopenharmony_ci    bool needRefresh_;
402a3e0fd82Sopenharmony_ci    bool useTextColor_;
403a3e0fd82Sopenharmony_ci    bool isFocused_;
404a3e0fd82Sopenharmony_ci    bool drawCursor_;
405a3e0fd82Sopenharmony_ci    uint16_t maxLength_;
406a3e0fd82Sopenharmony_ci    uint16_t placeholderEllipsisIndex_;
407a3e0fd82Sopenharmony_ci    int16_t cursorPosX_;
408a3e0fd82Sopenharmony_ci    ColorType textColor_;
409a3e0fd82Sopenharmony_ci    ColorType placeholderColor_;
410a3e0fd82Sopenharmony_ci    ColorType cursorColor_;
411a3e0fd82Sopenharmony_ci    OnChangeListener* onChangeListener_;
412a3e0fd82Sopenharmony_ci    std::string textStr_;
413a3e0fd82Sopenharmony_ci    std::string passwordStr_;
414a3e0fd82Sopenharmony_ci    Animator* cursorAnimator_;
415a3e0fd82Sopenharmony_ci    InputType inputType_ = InputType::TEXT_TYPE;
416a3e0fd82Sopenharmony_ci};
417a3e0fd82Sopenharmony_ci} // namespace OHOS
418a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_EDIT_TEXT
419