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/base/inspector_filter.h"
23 #include "core/components_ng/event/touch_event.h"
24 #include "core/components_ng/layout/layout_property.h"
25 #include "core/components_ng/pattern/model/model_adapter_wrapper.h"
26 #include "core/components_ng/pattern/model/model_layout_algorithm.h"
27 #include "core/components_ng/pattern/model/model_paint_method.h"
28 #include "core/components_ng/pattern/model/model_paint_property.h"
29 #include "core/components_ng/pattern/pattern.h"
30 #include "core/components_ng/property/property.h"
31 
32 namespace OHOS::Ace::NG {
33 class ACE_EXPORT ModelPattern : public Pattern {
34     DECLARE_ACE_TYPE(ModelPattern, Pattern);
35 
36 public:
37     ModelPattern(uint32_t key, const ModelViewContext& context);
38     ~ModelPattern() override;
39 
CreatePaintProperty()40     RefPtr<PaintProperty> CreatePaintProperty() override
41     {
42         return MakeRefPtr<ModelPaintProperty>();
43     }
44 
CreateNodePaintMethod()45     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
46     {
47         return MakeRefPtr<ModelPaintMethod>(WeakClaim(RawPtr(modelAdapter_)));
48     }
49 
CreateLayoutProperty()50     RefPtr<LayoutProperty> CreateLayoutProperty() override
51     {
52         return MakeRefPtr<LayoutProperty>();
53     }
54 
CreateLayoutAlgorithm()55     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
56     {
57         return MakeRefPtr<ModelLayoutAlgorithm>(WeakClaim(RawPtr(modelAdapter_)));
58     }
59 
UpdateTransformHintChangedCallbackId(std::optional<int32_t> id)60     void UpdateTransformHintChangedCallbackId(std::optional<int32_t> id)
61     {
62         transformHintChangedCallbackId_ = id;
63     }
64 
HasTransformHintChangedCallbackId()65     bool HasTransformHintChangedCallbackId() const
66     {
67         return transformHintChangedCallbackId_.has_value();
68     }
69 
70     void OnModifyDone() override;
71     void OnRebuildFrame() override;
72     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
73 
74 private:
75     uint32_t GetKey();
76     void OnAttachToFrameNode() override;
77     void OnDetachFromFrameNode(FrameNode* node) override;
78     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
79     bool NeedsRepaint();
80     void HandleTouchEvent(const TouchEventInfo& info);
81     void MarkDirtyNode(const PropertyChangeFlag flag);
82 
83     uint32_t key_ = -1;
84 
85     RefPtr<ModelAdapterWrapper> modelAdapter_;
86     RefPtr<TouchEventImpl> touchListener_;
87 
88     std::optional<int32_t> transformHintChangedCallbackId_;
89     uint32_t rotation_ = 0; // Transform
90 
91     ACE_DISALLOW_COPY_AND_MOVE(ModelPattern);
92 };
93 
94 } // namespace OHOS::Ace::NG
95 
96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MODEL_MODEL_PATTERN_H
97