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_PATTERNS_CUSTOM_FRAME_NODE_CUSTOM_FRAME_NODE_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CUSTOM_FRAME_NODE_CUSTOM_FRAME_NODE_PATTERN_H 18 19 #include <functional> 20 21 #include "core/components_ng/pattern/custom_frame_node/custom_frame_node_layout_algorithm.h" 22 #include "core/components_ng/pattern/pattern.h" 23 #include "core/components_ng/pattern/render_node/render_node_modifier.h" 24 #include "core/components_ng/pattern/render_node/render_node_paint_method.h" 25 #include "core/components_ng/pattern/stack/stack_layout_algorithm.h" 26 #include "core/components_ng/pattern/stack/stack_layout_property.h" 27 28 namespace OHOS::Ace::NG { 29 30 class ACE_EXPORT CustomFrameNodePattern : public Pattern { 31 DECLARE_ACE_TYPE(CustomFrameNodePattern, Pattern); 32 33 public: 34 CustomFrameNodePattern() = default; 35 ~CustomFrameNodePattern() override = default; 36 CreateLayoutAlgorithm()37 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 38 { 39 return MakeRefPtr<CustomFrameNodeLayoutAlgorithm>(); 40 } 41 CreateLayoutProperty()42 RefPtr<LayoutProperty> CreateLayoutProperty() override 43 { 44 auto layoutProperty = MakeRefPtr<StackLayoutProperty>(); 45 layoutProperty->UpdateAlignment(Alignment::TOP_LEFT); 46 return layoutProperty; 47 } 48 IsAtomicNode()49 bool IsAtomicNode() const override 50 { 51 return false; 52 } 53 GetFocusPattern()54 FocusPattern GetFocusPattern() const override 55 { 56 return { FocusType::SCOPE, true }; 57 } 58 IsNeedInitClickEventRecorder()59 bool IsNeedInitClickEventRecorder() const override 60 { 61 return true; 62 } 63 CreatePaintProperty()64 RefPtr<PaintProperty> CreatePaintProperty() override 65 { 66 auto renderNodePaintProperty = MakeRefPtr<RenderNodePaintProperty>(); 67 renderNodePaintProperty->UpdateRenderNodeFlag(0); 68 return renderNodePaintProperty; 69 } 70 CreateNodePaintMethod()71 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 72 { 73 auto host = GetHost(); 74 CHECK_NULL_RETURN(host, nullptr); 75 76 if (!renderNodeModifier_) { 77 renderNodeModifier_ = AceType::MakeRefPtr<RenderNodeModifier>(drawCallback_); 78 } 79 auto paintMethod = AceType::MakeRefPtr<RenderNodePaintMethod>(renderNodeModifier_); 80 return paintMethod; 81 } 82 SetDrawCallback(std::function<void (DrawingContext & context)> && drawCallback)83 void SetDrawCallback(std::function<void(DrawingContext& context)>&& drawCallback) 84 { 85 drawCallback_ = drawCallback; 86 renderNodeModifier_ = AceType::MakeRefPtr<RenderNodeModifier>(drawCallback_); 87 } 88 Invalidate()89 void Invalidate() 90 { 91 CHECK_NULL_VOID(renderNodeModifier_); 92 renderNodeModifier_->Modify(); 93 } 94 95 private: 96 std::function<void(DrawingContext& context)> drawCallback_; 97 RefPtr<RenderNodeModifier> renderNodeModifier_; 98 }; 99 } // namespace OHOS::Ace::NG 100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CUSTOM_FRAME_NODE_CUSTOM_FRAME_NODE_PATTERN_H 101