• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_COMPONENT_DECORATOR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_COMPONENT_DECORATOR_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/memory/referenced.h"
21 #include "core/components_ng/base/frame_node.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 class ACE_EXPORT TextComponentDecorator : public AceType {
26     DECLARE_ACE_TYPE(TextComponentDecorator, AceType);
27 public:
28     TextComponentDecorator(const RefPtr<FrameNode>& decoratedNode);
29     ~TextComponentDecorator();
30     void BuildDecorator();
31     void CleanDecorator();
32     virtual void UpdateTextFieldMargin() = 0;
33     virtual float MeasureDecorator(float contentWidth, const std::u16string& textContent, bool showPlaceHolder) = 0;
34     virtual void LayoutDecorator() = 0;
35     virtual float GetBoundHeight() const = 0;
36     virtual float GetDecoratorHeight() const;
37     virtual float GetContentWidth() const;
38 
39 protected:
40     WeakPtr<FrameNode> decoratedNode_;
41     WeakPtr<FrameNode> textNode_;
42 };
43 
44 class ACE_EXPORT CounterDecorator : public TextComponentDecorator {
45     DECLARE_ACE_TYPE(CounterDecorator, TextComponentDecorator);
46 public:
CounterDecorator(const RefPtr<FrameNode> & decoratedNode)47     explicit CounterDecorator(const RefPtr<FrameNode>& decoratedNode): TextComponentDecorator(decoratedNode) {}
48     ~CounterDecorator() override = default;
49     void UpdateTextFieldMargin() override;
50     float MeasureDecorator(float contentWidth, const std::u16string& textContent, bool showPlaceHolder) override;
51     void LayoutDecorator() override;
52     float GetBoundHeight() const override;
53     bool HasContent() const;
54 private:
55     void UpdateCounterContentAndStyle(uint32_t textLength, uint32_t maxLength, bool isVisible = true);
56     float MeasureTextNodeHeight();
57     void UpdateTextNodeAndMeasure(uint32_t textLength, uint32_t maxLength, const LayoutConstraintF& contentConstraint);
58     TextAlign GetCounterNodeAlignment();
59     void HandleNonTextArea();
60     void HandleTextArea();
61     std::string GetAccessibilityText(uint32_t textLength, uint32_t maxLength);
62 };
63 
64 class ACE_EXPORT ErrorDecorator : public TextComponentDecorator {
65     DECLARE_ACE_TYPE(ErrorDecorator, TextComponentDecorator);
66 public:
ErrorDecorator(const RefPtr<FrameNode> & decoratedNode)67     explicit ErrorDecorator(const RefPtr<FrameNode>& decoratedNode): TextComponentDecorator(decoratedNode) {}
68     ~ErrorDecorator() override = default;
69     void UpdateTextFieldMargin() override;
70     float MeasureDecorator(float contentWidth, const std::u16string& textContent, bool showPlaceHolder) override;
71     void LayoutDecorator() override;
72     float GetBoundHeight() const override;
73 private:
74     void BeforeLayout();
75     void UpdateLayoutProperty();
76     void UpdateErrorStyle();
77 
78 };
79 
80 }
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_COMPONENT_DECORATOR_H