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 #include "core/components_ng/pattern/video/video_full_screen_node.h"
17 
18 #include "core/components_ng/pattern/image/image_pattern.h"
19 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
20 #include "core/components_ng/pattern/video/video_full_screen_pattern.h"
21 
22 namespace OHOS::Ace::NG {
InitVideoFullScreenNode(const RefPtr<VideoNode> & video)23 void VideoFullScreenNode::InitVideoFullScreenNode(const RefPtr<VideoNode>& video)
24 {
25     if (video->HasMediaColumnNode()) {
26         auto mediaColumnId = GetMediaColumnId();
27         auto mediaColumNode = FrameNode::GetOrCreateFrameNode(
28             V2::COLUMN_ETS_TAG, mediaColumnId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
29         CHECK_NULL_VOID(mediaColumNode);
30         AddChild(mediaColumNode);
31     }
32     if (video->HasPreviewImageNode()) {
33         int32_t imageId = ElementRegister::GetInstance()->MakeUniqueId();
34         auto previewNode = FrameNode::GetOrCreateFrameNode(
35             V2::IMAGE_ETS_TAG, imageId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
36         CHECK_NULL_VOID(previewNode);
37         AddChild(previewNode);
38     }
39     if (video->HasControllerRowNode()) {
40         int32_t controlRowId = GetControllerRowId();
41         auto fullScreenPattern = AceType::DynamicCast<VideoFullScreenPattern>(GetPattern());
42         auto controlRowNode = fullScreenPattern->CreateControlBar(controlRowId);
43         CHECK_NULL_VOID(controlRowNode);
44         AddChild(controlRowNode);
45     }
46 }
47 
CreateFullScreenNode(const std::string & tag,int32_t nodeId,const RefPtr<Pattern> & pattern)48 RefPtr<VideoFullScreenNode> VideoFullScreenNode::CreateFullScreenNode(
49     const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
50 {
51     auto fullScreenNode = AceType::MakeRefPtr<VideoFullScreenNode>(tag, nodeId, pattern, false);
52     ElementRegister::GetInstance()->AddUINode(fullScreenNode);
53     fullScreenNode->InitializePatternAndContext();
54     return fullScreenNode;
55 }
56 } // namespace OHOS::Ace::NG