• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_VIDEO_VIDEO_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_NODE_H
18 
19 #include <optional>
20 
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/pattern/video/video_pattern.h"
23 
24 namespace OHOS::Ace::NG {
25 namespace {
26 constexpr int32_t PREVIEW_IMAGE_INDEX = 1;
27 constexpr int32_t CONTROLLER_ROW_INDEX = 2;
28 constexpr int32_t MEDIA_COLUMN_INDEX = 0;
29 } // namespace
30 
31 class ACE_EXPORT VideoNode : public FrameNode {
32     DECLARE_ACE_TYPE(VideoNode, FrameNode);
33 
34 public:
35     VideoNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false)
FrameNode(tag,nodeId,pattern,isRoot)36         : FrameNode(tag, nodeId, pattern, isRoot)
37     {}
38     ~VideoNode() override = default;
39 
HasControllerRowNode()40     bool HasControllerRowNode() const
41     {
42         return controllerRowId_.has_value();
43     }
44 
HasPreviewImageNode()45     bool HasPreviewImageNode() const
46     {
47         return previewImageId_.has_value();
48     }
49 
HasMediaColumnNode()50     bool HasMediaColumnNode() const
51     {
52         return mediaColumnId_.has_value();
53     }
54 
GetControllerRowId()55     int32_t GetControllerRowId()
56     {
57         if (!controllerRowId_.has_value()) {
58             controllerRowId_ = ElementRegister::GetInstance()->MakeUniqueId();
59         }
60         return controllerRowId_.value();
61     }
62 
GetPreviewImageId()63     int32_t GetPreviewImageId()
64     {
65         if (!previewImageId_.has_value()) {
66             previewImageId_ = ElementRegister::GetInstance()->MakeUniqueId();
67         }
68         return previewImageId_.value();
69     }
70 
GetMediaColumnId()71     int32_t GetMediaColumnId()
72     {
73         if (!mediaColumnId_.has_value()) {
74             mediaColumnId_ = ElementRegister::GetInstance()->MakeUniqueId();
75         }
76         return mediaColumnId_.value();
77     }
78 
79     // Get the preview image node, please check null first.
GetPreviewImage()80     RefPtr<UINode> GetPreviewImage()
81     {
82         // If the index >= size, it will return null.
83         return GetChildAtIndex(PREVIEW_IMAGE_INDEX);
84     }
85 
86     // Get the controller row node, please check null first.
GetControllerRow()87     RefPtr<UINode> GetControllerRow()
88     {
89         // If the index >= size, it will return null.
90         return GetChildAtIndex(CONTROLLER_ROW_INDEX);
91     }
92 
GetMediaColumn()93     RefPtr<UINode> GetMediaColumn()
94     {
95         return GetChildAtIndex(MEDIA_COLUMN_INDEX);
96     }
97 
98     static RefPtr<VideoNode> GetOrCreateVideoNode(
99         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
100 
101 private:
102     std::optional<int32_t> previewImageId_;
103     std::optional<int32_t> controllerRowId_;
104     std::optional<int32_t> mediaColumnId_;
105 };
106 } // namespace OHOS::Ace::NG
107 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_NODE_H
108