• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_PATTERNS_TOAST_TOAST_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOAST_TOAST_PATTERN_H
18 
19 #include <cstdint>
20 
21 #include "base/geometry/ng/offset_t.h"
22 #include "base/geometry/ng/size_t.h"
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "core/components/toast/toast_theme.h"
26 #include "core/components_ng/pattern/overlay/popup_base_pattern.h"
27 #include "core/components_ng/pattern/pattern.h"
28 #include "core/components_ng/pattern/text/text_layout_property.h"
29 #include "core/components_ng/pattern/toast/toast_layout_algorithm.h"
30 #include "core/components_ng/pattern/toast/toast_layout_property.h"
31 
32 namespace OHOS::Ace::NG {
33 class ToastPattern : public PopupBasePattern {
34     DECLARE_ACE_TYPE(ToastPattern, PopupBasePattern);
35 
36 public:
37     ToastPattern() = default;
38     ~ToastPattern() override = default;
39 
IsAtomicNode()40     bool IsAtomicNode() const override
41     {
42         return false;
43     }
44 
CreateLayoutProperty()45     RefPtr<LayoutProperty> CreateLayoutProperty() override
46     {
47         return AceType::MakeRefPtr<ToastLayoutProperty>();
48     }
49 
CreateLayoutAlgorithm()50     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
51     {
52         return AceType::MakeRefPtr<ToastLayoutAlgorithm>();
53     }
54 
55     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& changeConfig) override;
56 
57     void OnColorConfigurationUpdate() override;
58 
SetTextNode(RefPtr<FrameNode> textNode)59     void SetTextNode(RefPtr<FrameNode> textNode)
60     {
61         textNode_ = textNode;
62     }
63 
64 private:
65     void BeforeCreateLayoutWrapper() override;
66     void UpdateToastSize(const RefPtr<FrameNode>& toast);
67     void UpdateTextSizeConstraint(const RefPtr<FrameNode>& text);
68 
69     double GetBottomValue(const RefPtr<LayoutWrapper>& layoutWrapper);
70 
71     RefPtr<FrameNode> textNode_;
72     ACE_DISALLOW_COPY_AND_MOVE(ToastPattern);
73 };
74 } // namespace OHOS::Ace::NG
75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOAST_TOAST_PATTERN_H
76