• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_MODEL_MODEL_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MODEL_MODEL_PATTERN_H
18 
19 #include <memory>
20 
21 #include "base/memory/referenced.h"
22 #include "core/components_ng/event/touch_event.h"
23 #include "core/components_ng/pattern/model/model_adapter_wrapper.h"
24 #include "core/components_ng/pattern/model/model_layout_algorithm.h"
25 #include "core/components_ng/pattern/model/model_layout_property.h"
26 #include "core/components_ng/pattern/model/model_paint_method.h"
27 #include "core/components_ng/pattern/model/model_paint_property.h"
28 #include "core/components_ng/pattern/pattern.h"
29 #include "core/components_ng/property/property.h"
30 
31 namespace OHOS::Ace::NG {
32 class ACE_EXPORT ModelPattern : public Pattern {
33     DECLARE_ACE_TYPE(ModelPattern, Pattern);
34 
35 public:
36     ModelPattern(uint32_t key);
37     ~ModelPattern() override = default;
38 
CreatePaintProperty()39     RefPtr<PaintProperty> CreatePaintProperty() override
40     {
41         return MakeRefPtr<ModelPaintProperty>();
42     }
43 
CreateNodePaintMethod()44     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
45     {
46         return MakeRefPtr<ModelPaintMethod>(WeakClaim(RawPtr(modelAdapter_)));
47     }
48 
CreateLayoutProperty()49     RefPtr<LayoutProperty> CreateLayoutProperty() override
50     {
51         return MakeRefPtr<ModelLayoutProperty>();
52     }
53 
CreateLayoutAlgorithm()54     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
55     {
56         return MakeRefPtr<ModelLayoutAlgorithm>(WeakClaim(RawPtr(modelAdapter_)));
57     }
58 
59     void OnModifyDone() override;
60 
61 private:
62     uint32_t GetKey();
63     void OnAttachToFrameNode() override;
64     void OnDetachFromFrameNode(FrameNode* node) override;
65     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
66     bool NeedsRepaint();
67     void HandleTouchEvent(const TouchEventInfo& info);
68     void MarkDirtyNode(const PropertyChangeFlag flag);
69 
70     uint32_t key_ = -1;
71 
72     RefPtr<ModelAdapterWrapper> modelAdapter_;
73     RefPtr<TouchEventImpl> touchListener_;
74 
75     ACE_DISALLOW_COPY_AND_MOVE(ModelPattern);
76 };
77 
78 } // namespace OHOS::Ace::NG
79 
80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MODEL_MODEL_PATTERN_H
81