• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_AUTO_FILL_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_AUTO_FILL_CONTROLLER_H
18 
19 #include <string>
20 #include <utility>
21 
22 #include "base/memory/ace_type.h"
23 #include "base/memory/referenced.h"
24 #include "base/utils/string_utils.h"
25 #include "base/utils/utf_helper.h"
26 #include "core/components_ng/pattern/pattern.h"
27 #include "core/components_ng/render/paragraph.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 enum class AutoFillAnimationStatus { INIT, SHOW_ICON, TRANSLATION, HIDE_ICON };
32 
33 enum class AutoFillContentLengthMode { INVALID, SHORT, MEDIUM, LONG, EXTRA_LONG };
34 
35 class AutoFillController : public virtual AceType {
36     DECLARE_ACE_TYPE(AutoFillController, AceType);
37 
38 public:
AutoFillController(const WeakPtr<Pattern> & pattern)39     explicit AutoFillController(const WeakPtr<Pattern>& pattern) : pattern_(pattern) {}
40     ~AutoFillController() override = default;
41     void StartAutoFillAnimation(const std::function<void()>& onFinishCallback, const std::u16string& content);
42     void ResetAutoFillAnimationStatus();
43 
GetAutoFillParagraph()44     const RefPtr<Paragraph>& GetAutoFillParagraph() const
45     {
46         return autoFillParagraph_;
47     }
48 
GetAutoFillAnimationStatus()49     AutoFillAnimationStatus GetAutoFillAnimationStatus() const
50     {
51         return autoFillAnimationStatus_;
52     }
53 
SetAutoFillAnimationStatus(AutoFillAnimationStatus status)54     void SetAutoFillAnimationStatus(AutoFillAnimationStatus status)
55     {
56         autoFillAnimationStatus_ = status;
57     }
58 
GetAutoFillIconNode()59     const WeakPtr<FrameNode>& GetAutoFillIconNode() const
60     {
61         return autoFillIconNode_;
62     }
63 
SetAutoFillOriginTextColor(const Color & value)64     void SetAutoFillOriginTextColor(const Color& value)
65     {
66         autoFillOriginTextColor_ = value;
67     }
68 
SetAutoFillTextUtf16Value(const std::u16string & value)69     void SetAutoFillTextUtf16Value(const std::u16string& value)
70     {
71         autofillTextUtf16Value_ = value;
72     }
73 
GetAutoFillTextUtf16Value()74     const std::u16string& GetAutoFillTextUtf16Value() const
75     {
76         return autofillTextUtf16Value_;
77     }
78 
GetAnimationTextRect()79     const RectF& GetAnimationTextRect() const
80     {
81         return animationTextRect_;
82     }
83 
84 private:
85     void PlayAutoFillIconShowAnimation(const AutoFillContentLengthMode& mode);
86     void PlayAutoFillDefaultCharAnimation(const AutoFillContentLengthMode& mode);
87     void PlayAutoFillTranslationAnimation(const AutoFillContentLengthMode& mode);
88     void PlayAutoFillIconHideAnimation(
89         const std::function<void()>& onFinishCallback, const AutoFillContentLengthMode& mode);
90     void PlayAutoFillTextScrollAnimation();
91     bool InitAutoFillParagraph(const std::u16string& textContent);
92     bool CreateAutoFillIcon();
93     void ResetAutoFillIcon();
94     AutoFillContentLengthMode GetAutoFillContentLengthMode();
95     float GetSpringAnimationResponse(const AutoFillContentLengthMode& mode);
96     float GetSpringAnimationDamping(const AutoFillContentLengthMode& mode);
97     void UpdateAnimationTextRect();
98 
99     WeakPtr<Pattern> pattern_;
100     RefPtr<Paragraph> autoFillParagraph_;
101     AutoFillAnimationStatus autoFillAnimationStatus_ = AutoFillAnimationStatus::INIT;
102     WeakPtr<FrameNode> autoFillIconNode_;
103     std::u16string autofillTextUtf16Value_;
104     float autoFillFirstCharOffset_ = 0.0f;
105     Color autoFillOriginTextColor_;
106     RectF animationTextRect_;
107 };
108 } // namespace OHOS::Ace::NG
109 
110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_AUTO_FILL_CONTROLLER_H