1 /* 2 * Copyright (c) 2025 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 OHOS_WEB_PICTURE_IN_PICTURE_CONTROLLER_INTERFACE_H 17 #define OHOS_WEB_PICTURE_IN_PICTURE_CONTROLLER_INTERFACE_H 18 19 #include <wm_common.h> 20 #include <window.h> 21 #include "native_pip_window_listener.h" 22 #include "web_picture_in_picture_controller.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 27 class WebPictureInPictureControllerInterface : virtual public RefBase { 28 public: 29 WebPictureInPictureControllerInterface() = default; 30 ~WebPictureInPictureControllerInterface() = default; 31 WMError Create(const PiPConfig& pipConfig); 32 WMError StartPip(uint32_t controllerId); 33 WMError StopPip(); 34 WMError UpdateContentSize(int32_t width, int32_t height); 35 WMError UpdatePiPControlStatus(PiPControlType controlType, PiPControlStatus status); 36 WMError setPiPControlEnabled(PiPControlType controlType, bool enabled); 37 WMError SetPipInitialSurfaceRect(int32_t positionX, int32_t positionY, uint32_t width, uint32_t height); 38 WMError UnsetPipInitialSurfaceRect(); 39 WMError RegisterStartPipListener(NativePipStartPipCallback); 40 WMError RegisterLifeCycleListener(NativePipLifeCycleCallback); 41 WMError RegisterControlEventListener(NativePipControlEventCallback); 42 WMError RegisterResizeListener(NativePipResizeCallback); 43 WMError UnregisterStartPipListener(NativePipStartPipCallback); 44 WMError UnregisterLifeCycleListener(NativePipLifeCycleCallback); 45 WMError UnregisterControlEventListener(NativePipControlEventCallback); 46 WMError UnregisterResizeListener(NativePipResizeCallback); 47 WMError UnregisterAllPiPStart(); 48 WMError UnregisterAllPiPLifecycle(); 49 WMError UnregisterAllPiPControlObserver(); 50 WMError UnregisterAllPiPWindowSize(); IsStarted()51 bool IsStarted() const { return isStarted_; } 52 53 private: 54 enum class ListenerType : uint32_t { 55 STATE_CHANGE_CB, 56 CONTROL_EVENT_CB, 57 SIZE_CHANGE_CB, 58 PIP_START_CB, 59 }; 60 WMError CheckRegisterParam(const sptr<NativePiPWindowListener>& listener); 61 WMError RegisterListenerWithType(ListenerType type, const sptr<NativePiPWindowListener>& listener); 62 WMError UnregisterListenerWithType(ListenerType type, const sptr<NativePiPWindowListener>& listener); 63 WMError ProcessStateChangeRegister(const sptr<NativePiPWindowListener>& listener); 64 WMError ProcessControlEventRegister(const sptr<NativePiPWindowListener>& listener); 65 WMError ProcessSizeChangeRegister(const sptr<NativePiPWindowListener>& listener); 66 WMError ProcessPipStartRegister(const sptr<NativePiPWindowListener>& listener); 67 WMError ProcessStateChangeUnregister(const sptr<NativePiPWindowListener>& listener); 68 WMError ProcessControlEventUnregister(const sptr<NativePiPWindowListener>& listener); 69 WMError ProcessSizeChangeUnregister(const sptr<NativePiPWindowListener>& listener); 70 WMError ProcessPipStartUnregister(const sptr<NativePiPWindowListener>& listener); 71 bool IsRegistered(ListenerType type, const sptr<NativePiPWindowListener>& listener); 72 WMError UnregisterAll(ListenerType type); 73 bool isPipEnabled_ = false; 74 bool isStarted_ = false; 75 sptr<WebPictureInPictureController> sptrWebPipController_; 76 std::set<sptr<NativePiPWindowListener>> lifeCycleCallbackSet_; 77 std::set<sptr<NativePiPWindowListener>> controlEventCallbackSet_; 78 std::set<sptr<NativePiPWindowListener>> resizeCallbackSet_; 79 std::set<sptr<NativePiPWindowListener>> startPipCallbackSet_; 80 }; 81 } // namespace Rosen 82 } // namespace OHOS 83 #endif // OHOS_WEB_PICTURE_IN_PICTURE_CONTROLLER_INTERFACE_H