• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_NODE_H
17 #define COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_NODE_H
18 
19 #include "movingphoto_pattern.h"
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/pipeline/base/element_register.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 constexpr int32_t VIDEO_NODE_INDEX = 0;
26 constexpr int32_t IMAGE_NODE_INDEX = 0;
27 
28 class ACE_EXPORT MovingPhotoNode : public FrameNode {
29     DECLARE_ACE_TYPE(MovingPhotoNode, FrameNode);
30 
31 public:
32     MovingPhotoNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false)
FrameNode(tag,nodeId,pattern,isRoot)33         : FrameNode(tag, nodeId, pattern, isRoot)
34     {}
35     ~MovingPhotoNode() override = default;
36 
37     static RefPtr<MovingPhotoNode> GetOrCreateMovingPhotoNode(
38         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
39 
GetImageId()40     int32_t GetImageId()
41     {
42         if (!imageId_.has_value()) {
43             imageId_ = ElementRegister::GetInstance()->MakeUniqueId();
44         }
45         return imageId_.value();
46     }
47 
GetImage()48     RefPtr<UINode> GetImage()
49     {
50         return GetChildAtIndex(IMAGE_NODE_INDEX);
51     }
52 
HasImageNode()53     bool HasImageNode()
54     {
55         return imageId_.has_value();
56     }
57 
GetVideoId()58     int32_t GetVideoId()
59     {
60         if (!videoId_.has_value()) {
61             videoId_ = ElementRegister::GetInstance()->MakeUniqueId();
62         }
63         return videoId_.value();
64     }
65 
GetVideo(int32_t index)66     RefPtr<UINode> GetVideo(int32_t index)
67     {
68         return GetChildAtIndex(index)->GetChildAtIndex(VIDEO_NODE_INDEX);
69     }
70 
HasVideoNode()71     bool HasVideoNode()
72     {
73         return videoId_.has_value();
74     }
75 
GetColumnId()76     int32_t GetColumnId()
77     {
78         if (!columnId_.has_value()) {
79             columnId_ = ElementRegister::GetInstance()->MakeUniqueId();
80         }
81         return columnId_.value();
82     }
83 
GetColumn(int32_t index)84     RefPtr<UINode> GetColumn(int32_t index)
85     {
86         return GetChildAtIndex(index);
87     }
88 
HasColumnNode()89     bool HasColumnNode()
90     {
91         return columnId_.has_value();
92     }
93 
94 private:
95     std::optional<int32_t> imageId_;
96     std::optional<int32_t> videoId_;
97     std::optional<int32_t> columnId_;
98 };
99 } // namespace OHOS::Ace::NG
100 #endif // COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_NODE_H