1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef OHOS_PICTURE_IN_PICTURE_CONTROLLER_H 17e0dac50fSopenharmony_ci#define OHOS_PICTURE_IN_PICTURE_CONTROLLER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#define PIP_WINDOW_NAME "pip_window" 20e0dac50fSopenharmony_ci 21e0dac50fSopenharmony_ci#include <event_handler.h> 22e0dac50fSopenharmony_ci#include <refbase.h> 23e0dac50fSopenharmony_ci#include <ability_context.h> 24e0dac50fSopenharmony_ci#include "picture_in_picture_option.h" 25e0dac50fSopenharmony_ci#include "window.h" 26e0dac50fSopenharmony_ci#include "wm_common.h" 27e0dac50fSopenharmony_ci#include "picture_in_picture_interface.h" 28e0dac50fSopenharmony_ci#include "xcomponent_controller.h" 29e0dac50fSopenharmony_ci#include "pip_report.h" 30e0dac50fSopenharmony_ci#include "navigation_controller.h" 31e0dac50fSopenharmony_ci#include "display_manager.h" 32e0dac50fSopenharmony_ci#include "errors.h" 33e0dac50fSopenharmony_ci 34e0dac50fSopenharmony_cinamespace OHOS { 35e0dac50fSopenharmony_cinamespace Rosen { 36e0dac50fSopenharmony_ci 37e0dac50fSopenharmony_cienum class StartPipType : uint32_t { 38e0dac50fSopenharmony_ci NULL_START = 0, 39e0dac50fSopenharmony_ci USER_START = 1, 40e0dac50fSopenharmony_ci AUTO_START = 2, 41e0dac50fSopenharmony_ci ONE_STEP_START = 3, 42e0dac50fSopenharmony_ci}; 43e0dac50fSopenharmony_ci 44e0dac50fSopenharmony_cienum class StopPipType : uint32_t { 45e0dac50fSopenharmony_ci NULL_STOP = 0, 46e0dac50fSopenharmony_ci USER_STOP = 1, 47e0dac50fSopenharmony_ci OTHER_PACKAGE_STOP = 2, 48e0dac50fSopenharmony_ci PACKAGE_STOP = 3, 49e0dac50fSopenharmony_ci}; 50e0dac50fSopenharmony_ci 51e0dac50fSopenharmony_cistatic std::map<std::string, PiPControlType> CONTROL_TYPE_MAP = { 52e0dac50fSopenharmony_ci {"playbackStateChanged", PiPControlType::VIDEO_PLAY_PAUSE}, 53e0dac50fSopenharmony_ci {"nextVideo", PiPControlType::VIDEO_NEXT}, 54e0dac50fSopenharmony_ci {"previousVideo", PiPControlType::VIDEO_PREVIOUS}, 55e0dac50fSopenharmony_ci {"hangUp", PiPControlType::HANG_UP_BUTTON}, 56e0dac50fSopenharmony_ci {"micStateChanged", PiPControlType::MICROPHONE_SWITCH}, 57e0dac50fSopenharmony_ci {"videoStateChanged", PiPControlType::CAMERA_SWITCH}, 58e0dac50fSopenharmony_ci {"voiceStateChanged", PiPControlType::MUTE_SWITCH}, 59e0dac50fSopenharmony_ci {"fastForward", PiPControlType::FAST_FORWARD}, 60e0dac50fSopenharmony_ci {"fastBackward", PiPControlType::FAST_BACKWARD} 61e0dac50fSopenharmony_ci}; 62e0dac50fSopenharmony_ci 63e0dac50fSopenharmony_ciusing namespace Ace; 64e0dac50fSopenharmony_ciclass PictureInPictureController : virtual public RefBase { 65e0dac50fSopenharmony_cipublic: 66e0dac50fSopenharmony_ci PictureInPictureController(sptr<PipOption> pipOption, sptr<Window> mainWindow, uint32_t mainWindowId, napi_env env); 67e0dac50fSopenharmony_ci ~PictureInPictureController(); 68e0dac50fSopenharmony_ci WMError StartPictureInPicture(StartPipType startType); 69e0dac50fSopenharmony_ci WMError StopPictureInPicture(bool destroyWindow, StopPipType stopPipType, bool withAnim = true); 70e0dac50fSopenharmony_ci WMError StopPictureInPictureFromClient(); 71e0dac50fSopenharmony_ci WMError DestroyPictureInPictureWindow(); 72e0dac50fSopenharmony_ci sptr<Window> GetPipWindow() const; 73e0dac50fSopenharmony_ci uint32_t GetMainWindowId(); 74e0dac50fSopenharmony_ci void SetPipWindow(sptr<Window> window); 75e0dac50fSopenharmony_ci void SetAutoStartEnabled(bool enable); 76e0dac50fSopenharmony_ci void IsAutoStartEnabled(bool& enable) const; 77e0dac50fSopenharmony_ci void UpdateContentSize(int32_t width, int32_t height); 78e0dac50fSopenharmony_ci void UpdatePiPControlStatus(PiPControlType controlType, PiPControlStatus status); 79e0dac50fSopenharmony_ci bool IsContentSizeChanged(float width, float height, float posX, float posY); 80e0dac50fSopenharmony_ci void DoActionEvent(const std::string& actionName, int32_t status); 81e0dac50fSopenharmony_ci void DoControlEvent(PiPControlType controlType, PiPControlStatus status); 82e0dac50fSopenharmony_ci void PreRestorePictureInPicture(); 83e0dac50fSopenharmony_ci void RestorePictureInPictureWindow(); 84e0dac50fSopenharmony_ci void PrepareSource(); 85e0dac50fSopenharmony_ci void LocateSource(); 86e0dac50fSopenharmony_ci WMError RegisterPiPLifecycle(const sptr<IPiPLifeCycle>& listener); 87e0dac50fSopenharmony_ci WMError RegisterPiPActionObserver(const sptr<IPiPActionObserver>& listener); 88e0dac50fSopenharmony_ci WMError RegisterPiPControlObserver(const sptr<IPiPControlObserver>& listener); 89e0dac50fSopenharmony_ci WMError UnregisterPiPLifecycle(const sptr<IPiPLifeCycle>& listener); 90e0dac50fSopenharmony_ci WMError UnregisterPiPActionObserver(const sptr<IPiPActionObserver>& listener); 91e0dac50fSopenharmony_ci WMError UnregisterPiPControlObserver(const sptr<IPiPControlObserver>& listener); 92e0dac50fSopenharmony_ci sptr<IPiPLifeCycle> GetPictureInPictureLifecycle() const; 93e0dac50fSopenharmony_ci sptr<IPiPActionObserver> GetPictureInPictureActionObserver() const; 94e0dac50fSopenharmony_ci sptr<IPiPControlObserver> GetPictureInPictureControlObserver() const; 95e0dac50fSopenharmony_ci WMError SetXComponentController(std::shared_ptr<XComponentController> xComponentController); 96e0dac50fSopenharmony_ci PiPWindowState GetControllerState(); 97e0dac50fSopenharmony_ci std::string GetPiPNavigationId(); 98e0dac50fSopenharmony_ci napi_ref GetCustomNodeController(); 99e0dac50fSopenharmony_ci napi_ref GetTypeNode() const; 100e0dac50fSopenharmony_ci void OnPictureInPictureStart(); 101e0dac50fSopenharmony_ci bool IsTypeNodeEnabled() const; 102e0dac50fSopenharmony_ci 103e0dac50fSopenharmony_ciprivate: 104e0dac50fSopenharmony_ci class WindowLifeCycleListener : public IWindowLifeCycle { 105e0dac50fSopenharmony_ci public: 106e0dac50fSopenharmony_ci void AfterDestroyed() override; 107e0dac50fSopenharmony_ci }; 108e0dac50fSopenharmony_ci 109e0dac50fSopenharmony_ciprivate: 110e0dac50fSopenharmony_ci uint32_t GetPipPriority(uint32_t pipTemplateType); 111e0dac50fSopenharmony_ci WMError CreatePictureInPictureWindow(StartPipType startType); 112e0dac50fSopenharmony_ci WMError ShowPictureInPictureWindow(StartPipType startType); 113e0dac50fSopenharmony_ci WMError StartPictureInPictureInner(StartPipType startType); 114e0dac50fSopenharmony_ci WMError StopPictureInPictureInner(StopPipType stopType, bool withAnim); 115e0dac50fSopenharmony_ci void UpdateWinRectByComponent(); 116e0dac50fSopenharmony_ci void UpdatePiPSourceRect() const; 117e0dac50fSopenharmony_ci void ResetExtController(); 118e0dac50fSopenharmony_ci bool IsPullPiPAndHandleNavigation(); 119e0dac50fSopenharmony_ci template<typename T> WMError RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener); 120e0dac50fSopenharmony_ci template<typename T> WMError UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener); 121e0dac50fSopenharmony_ci wptr<PictureInPictureController> weakRef_ = nullptr; 122e0dac50fSopenharmony_ci sptr<PipOption> pipOption_ = nullptr; 123e0dac50fSopenharmony_ci std::vector<sptr<IPiPLifeCycle>> pipLifeCycleListeners_; 124e0dac50fSopenharmony_ci std::vector<sptr<IPiPActionObserver>> pipActionObservers_; 125e0dac50fSopenharmony_ci std::vector<sptr<IPiPControlObserver>> pipControlObservers_; 126e0dac50fSopenharmony_ci sptr<Window> window_ = nullptr; 127e0dac50fSopenharmony_ci sptr<Window> mainWindow_ = nullptr; 128e0dac50fSopenharmony_ci sptr<IWindowLifeCycle> mainWindowLifeCycleListener_ = nullptr; 129e0dac50fSopenharmony_ci uint32_t mainWindowId_ = 0; 130e0dac50fSopenharmony_ci Rect windowRect_ = {0, 0, 0, 0}; 131e0dac50fSopenharmony_ci bool isAutoStartEnabled_ = false; 132e0dac50fSopenharmony_ci PiPWindowState curState_ = PiPWindowState::STATE_UNDEFINED; 133e0dac50fSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 134e0dac50fSopenharmony_ci std::shared_ptr<XComponentController> pipXComponentController_ = nullptr; 135e0dac50fSopenharmony_ci std::shared_ptr<XComponentController> mainWindowXComponentController_ = nullptr; 136e0dac50fSopenharmony_ci napi_env env_ = nullptr; 137e0dac50fSopenharmony_ci int32_t handleId_ = -1; 138e0dac50fSopenharmony_ci bool isStoppedFromClient_ = false; 139e0dac50fSopenharmony_ci}; 140e0dac50fSopenharmony_ci} // namespace Rosen 141e0dac50fSopenharmony_ci} // namespace OHOS 142e0dac50fSopenharmony_ci#endif // OHOS_PICTURE_IN_PICTURE_CONTROLLER_H 143