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