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_FULL_SCREEN_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_FULL_SCREEN_PATTERN_H
18 
19 #include "core/components/video/video_controller_v2.h"
20 #include "core/components_ng/manager/focus/focus_view.h"
21 #include "core/components_ng/pattern/video/video_node.h"
22 #include "core/components_ng/pattern/video/video_pattern.h"
23 
24 namespace OHOS::Ace::NG {
25 class VideoFullScreenPattern : public VideoPattern, public FocusView {
26     DECLARE_ACE_TYPE(VideoFullScreenPattern, VideoPattern);
27 
28 public:
29     VideoFullScreenPattern() = delete;
VideoFullScreenPattern(const RefPtr<VideoControllerV2> & videoController)30     explicit VideoFullScreenPattern(const RefPtr<VideoControllerV2>& videoController) : VideoPattern(videoController) {}
31     ~VideoFullScreenPattern() override = default;
32     void InitFullScreenParam(const RefPtr<VideoPattern>& video, const RefPtr<RenderSurface>& renderSurface,
33         const RefPtr<MediaPlayer>& mediaPlayer, const RefPtr<RenderContext>& context);
34     void RequestFullScreen(const RefPtr<VideoNode>& videoNode);
35 
36     bool ExitFullScreen();
37 
OnBackPressed()38     bool OnBackPressed() override
39     {
40         ExitFullScreen();
41         return true;
42     }
43 
GetRouteOfFirstScope()44     std::list<int32_t> GetRouteOfFirstScope() override
45     {
46         return {};
47     }
48 
GetOriginVideoPattern()49     const RefPtr<VideoPattern> GetOriginVideoPattern()
50     {
51         return videoPattern_.Upgrade();
52     }
53 
GetVideoPattern()54     const RefPtr<VideoPattern> GetVideoPattern()
55     {
56         return videoPattern_.Upgrade();
57     }
58 
CreateEventHub()59     RefPtr<EventHub> CreateEventHub() override
60     {
61         return eventHub_;
62     }
63 
64     void SetEventHub(const RefPtr<EventHub>& eventHub);
65 
66     void UpdateState();
67 
CreateLayoutProperty()68     RefPtr<LayoutProperty> CreateLayoutProperty() override
69     {
70         auto videoPattern = videoPattern_.Upgrade();
71         if (!videoPattern) {
72             return MakeRefPtr<VideoLayoutProperty>();
73         }
74         auto layoutProperty = videoPattern->GetLayoutProperty<VideoLayoutProperty>()->Clone();
75         DynamicCast<VideoLayoutProperty>(layoutProperty)->fullScreenReset();
76         return layoutProperty;
77     }
78 
IsFullScreen()79     bool IsFullScreen() const override
80     {
81         // full screen state check from origin video fullScreenNodeId_
82         auto videoPattern = videoPattern_.Upgrade();
83         CHECK_NULL_RETURN(videoPattern, false);
84         return videoPattern->IsFullScreen();
85     }
86 
87 private:
88     WeakPtr<VideoPattern> videoPattern_;
89     RefPtr<EventHub> eventHub_;
90     RefPtr<GestureEventHub> originGestureEventHub_;
91 };
92 } // namespace OHOS::Ace::NG
93 #endif