• 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/layout/layout_property.h"
24 #include "core/components_ng/pattern/model/model_adapter_wrapper.h"
25 #include "core/components_ng/pattern/model/model_layout_algorithm.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, Render3D::SurfaceType surfaceType, const std::string& bundleName,
37         const std::string& moduleName);
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 
60     void OnModifyDone() override;
61     void OnRebuildFrame() override;
62 
63 private:
64     uint32_t GetKey();
65     void OnAttachToFrameNode() override;
66     void OnDetachFromFrameNode(FrameNode* node) override;
67     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
68     bool NeedsRepaint();
69     void HandleTouchEvent(const TouchEventInfo& info);
70     void MarkDirtyNode(const PropertyChangeFlag flag);
71 
72     uint32_t key_ = -1;
73 
74     RefPtr<ModelAdapterWrapper> modelAdapter_;
75     RefPtr<TouchEventImpl> touchListener_;
76 
77     ACE_DISALLOW_COPY_AND_MOVE(ModelPattern);
78 };
79 
80 } // namespace OHOS::Ace::NG
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MODEL_MODEL_PATTERN_H
83