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