From 22b691bf06a0a5ca17428ea5aa921e6e752614b0 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Tue, 9 May 2023 18:42:16 +0800 Subject: [PATCH] brige session stage to window interface Signed-off-by: chyyy0213 Change-Id: Icbb304deba55b02a4431d641ffe4bc5d5c74c487 Signed-off-by: chyyy0213 --- interfaces/innerkits/wm/window.h | 315 +++++---- interfaces/innerkits/wm/window_option.h | 15 + interfaces/innerkits/wm/window_scene.h | 13 + interfaces/innerkits/wm/wm_common.h | 10 + interfaces/kits/napi/window_runtime/BUILD.gn | 1 - .../window_stage_napi/js_window_stage.cpp | 25 +- .../window_stage_napi/js_window_stage.h | 8 +- utils/include/window_helper.h | 5 + window_scene/common/BUILD.gn | 8 +- .../common/include/window_session_property.h | 68 ++ .../common/src/window_session_property.cpp | 146 +++++ window_scene/interfaces/include/ws_common.h | 24 +- window_scene/session/BUILD.gn | 9 +- .../session/container/include/session_stage.h | 4 +- .../container/include/window_event_channel.h | 6 +- .../include/zidl/session_stage_interface.h | 8 + .../session/container/src/session_stage.cpp | 3 +- window_scene/session/host/include/session.h | 5 +- .../host/include/zidl/session_interface.h | 4 +- .../session/host/include/zidl/session_proxy.h | 4 +- window_scene/session/host/src/session.cpp | 9 +- .../session/host/src/zidl/session_proxy.cpp | 17 +- .../session/host/src/zidl/session_stub.cpp | 11 +- .../include/session_manager_base.h | 2 +- window_scene/test/unittest/BUILD.gn | 2 + window_scene/test/unittest/session_test.cpp | 19 +- wm/BUILD.gn | 11 + wm/include/static_call.h | 5 + wm/include/window_extension_session_impl.h | 33 + wm/include/window_scene_session_impl.h | 31 + wm/include/window_session_impl.h | 117 ++++ wm/src/static_call.cpp | 7 + wm/src/window.cpp | 58 +- wm/src/window_extension_session_impl.cpp | 51 ++ wm/src/window_impl.cpp | 2 +- wm/src/window_option.cpp | 10 + wm/src/window_scene.cpp | 27 +- wm/src/window_scene_session_impl.cpp | 35 + wm/src/window_session_impl.cpp | 608 ++++++++++++++++++ 39 files changed, 1536 insertions(+), 200 deletions(-) create mode 100644 window_scene/common/include/window_session_property.h create mode 100644 window_scene/common/src/window_session_property.cpp create mode 100644 wm/include/window_extension_session_impl.h create mode 100644 wm/include/window_scene_session_impl.h create mode 100644 wm/include/window_session_impl.h create mode 100644 wm/src/window_extension_session_impl.cpp create mode 100644 wm/src/window_scene_session_impl.cpp create mode 100644 wm/src/window_session_impl.cpp diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index baf4f28d9e..6357f61a3c 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -54,6 +54,7 @@ namespace Rosen { using NotifyNativeWinDestroyFunc = std::function; class RSSurfaceNode; class RSTransaction; +class ISession; /** * @class IWindowLifeCycle @@ -180,13 +181,13 @@ public: * * @param inputEvent Means PointerEvent. */ - virtual void OnDispatchPointerEvent(std::shared_ptr& inputEvent) = 0; + virtual void OnDispatchPointerEvent(std::shared_ptr& inputEvent) {} /** * @brief Dispatch KeyEvent. * * @param inputEvent Means KeyEvent. */ - virtual void OnDispatchKeyEvent(std::shared_ptr& keyEvent) = 0; + virtual void OnDispatchKeyEvent(std::shared_ptr& keyEvent) {} }; /** @@ -261,13 +262,13 @@ public: * * @param color Color of Background. */ - virtual void SetBackgroundColor(uint32_t color) = 0; + virtual void SetBackgroundColor(uint32_t color) {} /** * @brief Get BackgroundColor. * - * @return Value of BackgroundColor. + * @return Value of BackgroundColor and default color is white. */ - virtual uint32_t GetBackgroundColor() = 0; + virtual uint32_t GetBackgroundColor() { return 0xffffffff; } }; /** @@ -290,19 +291,19 @@ public: * * @param keyEvent KeyEvent of Multi-Model Input. */ - virtual bool OnInputEvent(const std::shared_ptr& keyEvent) const = 0; + virtual bool OnInputEvent(const std::shared_ptr& keyEvent) const { return false; } /** * @brief Observe PointerEvent of Multi-Model Input. * * @param pointerEvent PointerEvent of Multi-Model Input. */ - virtual bool OnInputEvent(const std::shared_ptr& pointerEvent) const = 0; + virtual bool OnInputEvent(const std::shared_ptr& pointerEvent) const { return false; } /** * @brief Observe axisEvent of Multi-Model Input. * * @param axisEvent AxisEvent of Multi-Model Input. */ - virtual bool OnInputEvent(const std::shared_ptr& axisEvent) const = 0; + virtual bool OnInputEvent(const std::shared_ptr& axisEvent) const { return false; } }; /** @@ -328,11 +329,11 @@ public: /** * @brief Observe the event when animation show. */ - virtual void AnimationForShown() = 0; + virtual void AnimationForShown() {} /** * @brief Observe the event when animation hide. */ - virtual void AnimationForHidden() = 0; + virtual void AnimationForHidden() {} }; /** @@ -371,11 +372,11 @@ public: /** * @brief Observe event when mainwindow(bind to dialog) destroyed. */ - virtual void OnDialogDeathRecipient() const = 0; + virtual void OnDialogDeathRecipient() const {} }; static WMError DefaultCreateErrCode = WMError::WM_OK; -class Window : public RefBase { +class Window : virtual public RefBase { public: /** * @brief create window, include main_window/sub_window/system_window @@ -388,6 +389,21 @@ public: static sptr Create(const std::string& windowName, sptr& option, const std::shared_ptr& context = nullptr, WMError& errCode = DefaultCreateErrCode); + + /** + * @brief create main/uiextension window with session + * + * @param windowName window name, identify window instance + * @param option window propertion + * @param context ability context + * @param iSession session token of window session + * @param errCode error code of create window + * @return sptr If create window success, return window instance; Otherwise, return nullptr + */ + static sptr Create(const std::string& windowName, + sptr& option, const std::shared_ptr& context, + const sptr& iSession, WMError& errCode = DefaultCreateErrCode); + /** * @brief find window by windowName * @@ -428,169 +444,169 @@ public: * * @return Surface node from RS */ - virtual std::shared_ptr GetSurfaceNode() const = 0; + virtual std::shared_ptr GetSurfaceNode() const { return nullptr; } /** * @brief Get ability context * * @return Ability context from AbilityRuntime */ - virtual const std::shared_ptr GetContext() const = 0; + virtual const std::shared_ptr GetContext() const { return nullptr; } /** * @brief Get the window show rect * * @return Rect of window */ - virtual Rect GetRect() const = 0; + virtual Rect GetRect() const { return {}; } /** * @brief Get window default rect from window property. * * @return Rect of window. */ - virtual Rect GetRequestRect() const = 0; + virtual Rect GetRequestRect() const { return {}; } /** * @brief Get the window type * * @return Type of window */ - virtual WindowType GetType() const = 0; + virtual WindowType GetType() const { return WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; } /** * @brief Get the window mode. * * @return Mode of window. */ - virtual WindowMode GetMode() const = 0; + virtual WindowMode GetMode() const { return WindowMode::WINDOW_MODE_UNDEFINED; } /** * @brief Get alpha of window. * * @return Alpha of window. */ - virtual float GetAlpha() const = 0; + virtual float GetAlpha() const { return 0.0f; } /** * @brief Get the name of window. * * @return Name of window. */ - virtual const std::string& GetWindowName() const = 0; + virtual const std::string& GetWindowName() const { return std::string(); } /** * @brief Get id of window. * * @return ID of window. */ - virtual uint32_t GetWindowId() const = 0; + virtual uint32_t GetWindowId() const { return INVALID_WINDOW_ID; } /** * @brief Get flag of window. * * @return Flag of window. */ - virtual uint32_t GetWindowFlags() const = 0; + virtual uint32_t GetWindowFlags() const { return 0; } /** * @brief Get state of window. * * @return Current state of window. */ - virtual WindowState GetWindowState() const = 0; + virtual WindowState GetWindowState() const { return WindowState::STATE_INITIAL; } /** * @brief Set focusable property of window. * * @param isFocusable Window can be focused or not. * @return Errorcode of window. */ - virtual WMError SetFocusable(bool isFocusable) = 0; + virtual WMError SetFocusable(bool isFocusable) { return WMError::WM_OK; } /** * @brief Get focusable property of window. * * @return True means window can be focused, false means window cannot be focused. */ - virtual bool GetFocusable() const = 0; + virtual bool GetFocusable() const { return false; } /** * @brief Set touchable property of window. * * @param isTouchable Window can be touched or not. * @return Errorcode of window. */ - virtual WMError SetTouchable(bool isTouchable) = 0; + virtual WMError SetTouchable(bool isTouchable) { return WMError::WM_OK; } /** * @brief Get touchable property of window. * * @return True means window can be touched, false means window cannot be touched. */ - virtual bool GetTouchable() const = 0; + virtual bool GetTouchable() const { return false; } /** * @brief Get SystemBarProperty By WindowType. * * @param type Type of window. * @return Property of system bar. */ - virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const = 0; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const { return {}; } /** * @brief judge this window is full screen. * * @return true If SetFullScreen(true) is called , return true. * @return false default return false */ - virtual bool IsFullScreen() const = 0; + virtual bool IsFullScreen() const { return false; } /** * @brief judge window layout is full screen * * @return true this window layout is full screen * @return false this window layout is not full screen */ - virtual bool IsLayoutFullScreen() const = 0; + virtual bool IsLayoutFullScreen() const { return false; } /** * @brief Set the Window Type * * @param type window type * @return WMError */ - virtual WMError SetWindowType(WindowType type) = 0; + virtual WMError SetWindowType(WindowType type) { return WMError::WM_OK; } /** * @brief Set the Window Mode * * @param mode window mode * @return WMError */ - virtual WMError SetWindowMode(WindowMode mode) = 0; + virtual WMError SetWindowMode(WindowMode mode) { return WMError::WM_OK; } /** * @brief Set alpha of window. * * @param alpha Alpha of window. * @return WM_OK means success, others means set failed. */ - virtual WMError SetAlpha(float alpha) = 0; + virtual WMError SetAlpha(float alpha) { return WMError::WM_OK; } /** * @brief Set transform of window property. * * @param trans Window Transform. * @return WMError */ - virtual WMError SetTransform(const Transform& trans) = 0; + virtual WMError SetTransform(const Transform& trans) { return WMError::WM_OK; } /** * @brief Get transform of window property. * * @return Property of transform. */ - virtual const Transform& GetTransform() const = 0; + virtual const Transform& GetTransform() const { return {}; } /** * @brief Add window flag. * * @param flag Flag of window. * @return WM_OK means add success, others means failed. */ - virtual WMError AddWindowFlag(WindowFlag flag) = 0; + virtual WMError AddWindowFlag(WindowFlag flag) { return WMError::WM_OK; } /** * @brief Remove window flag. * * @param flag Flag of window * @return WM_OK means remove success, others means failed. */ - virtual WMError RemoveWindowFlag(WindowFlag flag) = 0; + virtual WMError RemoveWindowFlag(WindowFlag flag) { return WMError::WM_OK; } /** * @brief Set window flag. * * @param flags Flag of window * @return WM_OK means set success, others means failed. */ - virtual WMError SetWindowFlags(uint32_t flags) = 0; + virtual WMError SetWindowFlags(uint32_t flags) { return WMError::WM_OK; } /** * @brief Set the System Bar(include status bar and nav bar) Property * @@ -598,7 +614,7 @@ public: * @param property system bar prop,include content color, background color * @return WMError */ - virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0; + virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) { return WMError::WM_OK; } /** * @brief Get the Avoid Area By Type object * @@ -606,21 +622,21 @@ public: * @param avoidArea * @return WMError */ - virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) = 0; + virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) { return WMError::WM_OK; } /** * @brief Set this window layout full screen, with hide status bar and nav bar above on this window * * @param status * @return WMError */ - virtual WMError SetLayoutFullScreen(bool status) = 0; + virtual WMError SetLayoutFullScreen(bool status) { return WMError::WM_OK; } /** * @brief Set this window full screen, with hide status bar and nav bar * * @param status if true, hide status bar and nav bar; Otherwise, show status bar and nav bar * @return WMError */ - virtual WMError SetFullScreen(bool status) = 0; + virtual WMError SetFullScreen(bool status) { return WMError::WM_OK; } /** * @brief destroy window * @@ -651,7 +667,7 @@ public: * @param y * @return WMError */ - virtual WMError MoveTo(int32_t x, int32_t y) = 0; + virtual WMError MoveTo(int32_t x, int32_t y) { return WMError::WM_OK; } /** * @brief resize the window instance (w,h) * @@ -659,7 +675,7 @@ public: * @param height * @return WMError */ - virtual WMError Resize(uint32_t width, uint32_t height) = 0; + virtual WMError Resize(uint32_t width, uint32_t height) { return WMError::WM_OK; } /** * @brief set the window gravity * @@ -667,112 +683,112 @@ public: * @param percent * @return WMError */ - virtual WMError SetWindowGravity(WindowGravity gravity, uint32_t percent) = 0; + virtual WMError SetWindowGravity(WindowGravity gravity, uint32_t percent) { return WMError::WM_OK; } /** * @brief Set the screen always on * * @param keepScreenOn * @return WMError */ - virtual WMError SetKeepScreenOn(bool keepScreenOn) = 0; + virtual WMError SetKeepScreenOn(bool keepScreenOn) { return WMError::WM_OK; } /** * @brief Get the screen is always on or not. * * @return True means screen is always on, false means the opposite. */ - virtual bool IsKeepScreenOn() const = 0; + virtual bool IsKeepScreenOn() const { return false; } /** * @brief Set the screen on * * @param turnScreenOn True means turn screen on, false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetTurnScreenOn(bool turnScreenOn) = 0; + virtual WMError SetTurnScreenOn(bool turnScreenOn) { return WMError::WM_OK; } /** * @brief Get the screen is on or not. * * @return True means screen is on, false means screen is off. */ - virtual bool IsTurnScreenOn() const = 0; + virtual bool IsTurnScreenOn() const { return false; } /** * @brief Set Background color. * * @param color Background color. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetBackgroundColor(const std::string& color) = 0; + virtual WMError SetBackgroundColor(const std::string& color) { return WMError::WM_OK; } /** * @brief Set transparent status. * * @param isTransparent True means set window transparent, false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetTransparent(bool isTransparent) = 0; + virtual WMError SetTransparent(bool isTransparent) { return WMError::WM_OK; } /** * @brief Get transparent status. * * @return True means window is transparent, false means the opposite. */ - virtual bool IsTransparent() const = 0; + virtual bool IsTransparent() const { return false; } /** * @brief Set brightness value of window. * * @param brightness Brightness of window. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetBrightness(float brightness) = 0; + virtual WMError SetBrightness(float brightness) { return WMError::WM_OK; } /** * @brief Get brightness value of window. * * @return Brightness value of window. */ - virtual float GetBrightness() const = 0; + virtual float GetBrightness() const { return 0.0f; } /** * @brief Set calling window. * * @param windowId Window id. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetCallingWindow(uint32_t windowId) = 0; + virtual WMError SetCallingWindow(uint32_t windowId) { return WMError::WM_OK; } /** * @brief Set privacy mode of window. * * @param isPrivacyMode True means set window private, false means not set window private. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetPrivacyMode(bool isPrivacyMode) = 0; + virtual WMError SetPrivacyMode(bool isPrivacyMode) { return WMError::WM_OK; } /** * @brief Get privacy property of window. * * @return True means window is private and cannot be screenshot or recorded. */ - virtual bool IsPrivacyMode() const = 0; + virtual bool IsPrivacyMode() const { return false; } /** * @brief Set privacy mode by system. * * @param isSystemPrivacyMode True means set window private, false means not set window private. */ - virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) = 0; + virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) {} /** * @brief Bind Dialog window to target token. * * @param targetToken Window token of target. * @return WM_OK means set success, others means set failed. */ - virtual WMError BindDialogTarget(sptr targetToken) = 0; + virtual WMError BindDialogTarget(sptr targetToken) { return WMError::WM_OK; } /** * @brief Raise zorder of window to the top of APP Mainwindow. * * @return WM_OK means raise success, others means raise failed. */ - virtual WmErrorCode RaiseToAppTop() = 0; + virtual WmErrorCode RaiseToAppTop() { return WmErrorCode::WM_OK; } /** * @brief Set skip flag of snapshot. * * @param isSkip True means skip the snapshot, false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetSnapshotSkip(bool isSkip) = 0; + virtual WMError SetSnapshotSkip(bool isSkip) { return WMError::WM_OK; } // window effect /** @@ -781,268 +797,298 @@ public: * @param cornerRadius Corner radius of window * @return WM_OK means set success, others means set failed. */ - virtual WMError SetCornerRadius(float cornerRadius) = 0; + virtual WMError SetCornerRadius(float cornerRadius) { return WMError::WM_OK; } /** * @brief Set shadow radius of window. * * @param radius Shadow radius of window * @return WM_OK means set success, others means set failed. */ - virtual WMError SetShadowRadius(float radius) = 0; + virtual WMError SetShadowRadius(float radius) { return WMError::WM_OK; } /** * @brief Set shadow color of window. * * @param color Shadow color of window. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetShadowColor(std::string color) = 0; + virtual WMError SetShadowColor(std::string color) { return WMError::WM_OK; } /** * @brief Set shadow X offset. * * @param offsetX Shadow x-axis offset. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetShadowOffsetX(float offsetX) = 0; + virtual WMError SetShadowOffsetX(float offsetX) { return WMError::WM_OK; } /** * @brief Set shadow Y offset. * * @param offsetY Shadow y-axis offset. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetShadowOffsetY(float offsetY) = 0; + virtual WMError SetShadowOffsetY(float offsetY) { return WMError::WM_OK; } /** * @brief Set blur property. * * @param radius Blur value. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetBlur(float radius) = 0; + virtual WMError SetBlur(float radius) { return WMError::WM_OK; } /** * @brief Set Backdrop blur property. * * @param radius Backdrop blur value. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetBackdropBlur(float radius) = 0; + virtual WMError SetBackdropBlur(float radius) { return WMError::WM_OK; } /** * @brief Set Backdrop blur style. * * @param blurStyle Backdrop blur value. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) = 0; + virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) { return WMError::WM_OK; } /** * @brief Request to get focus. * * @return WM_OK means request success, others means request failed. */ - virtual WMError RequestFocus() const = 0; + virtual WMError RequestFocus() const { return WMError::WM_OK; } /** * @brief Check current focus status. * * @return True means window is focused, false means window is unfocused. */ - virtual bool IsFocused() const = 0; + virtual bool IsFocused() const { return false; } /** * @brief Update surfaceNode after customAnimation. * * @param isAdd True means add custom animation, false means the opposite. * @return WM_OK means update success, others means update failed. */ - virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) = 0; + virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) { return WMError::WM_OK; } /** * @brief Set InputEvent Consumer. * * @param inputEventConsumer Consume input event object. * @return WM_OK means set success, others means set failed. */ - virtual void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) = 0; + virtual void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) {} /** * @brief Consume KeyEvent from MMI. * * @param inputEvent Keyboard input event. */ - virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) = 0; + virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) {} /** * @brief Consume PointerEvent from MMI. * * @param inputEvent Pointer input event */ - virtual void ConsumePointerEvent(const std::shared_ptr& inputEvent) = 0; + virtual void ConsumePointerEvent(const std::shared_ptr& inputEvent) {} /** * @brief Request Vsync. * * @param vsyncCallback Callback of vsync. */ - virtual void RequestVsync(const std::shared_ptr& vsyncCallback) = 0; + virtual void RequestVsync(const std::shared_ptr& vsyncCallback) {} /** * @brief Update Configuration. * * @param configuration Window configuration. */ - virtual void UpdateConfiguration(const std::shared_ptr& configuration) = 0; + virtual void UpdateConfiguration(const std::shared_ptr& configuration) {} /** * @brief Register window lifecycle listener. * * @param listener WindowLifeCycle listener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterLifeCycleListener(const sptr& listener) = 0; + virtual WMError RegisterLifeCycleListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Unregister window lifecycle listener. * * @param listener WindowLifeCycle listener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterLifeCycleListener(const sptr& listener) = 0; + virtual WMError UnregisterLifeCycleListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Register window change listener. * * @param listener IWindowChangeListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterWindowChangeListener(const sptr& listener) = 0; + virtual WMError RegisterWindowChangeListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Unregister window change listener. * * @param listener IWindowChangeListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterWindowChangeListener(const sptr& listener) = 0; + virtual WMError UnregisterWindowChangeListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Register avoid area change listener. * * @param listener IAvoidAreaChangedListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterAvoidAreaChangeListener(sptr& listener) = 0; + virtual WMError RegisterAvoidAreaChangeListener(sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Unregister avoid area change listener. * * @param listener IAvoidAreaChangedListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterAvoidAreaChangeListener(sptr& listener) = 0; + virtual WMError UnregisterAvoidAreaChangeListener(sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Register window drag listener. * * @param listener IWindowDragListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterDragListener(const sptr& listener) = 0; + virtual WMError RegisterDragListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Unregister window drag listener. * * @param listener IWindowDragListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterDragListener(const sptr& listener) = 0; + virtual WMError UnregisterDragListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Register display move listener. * * @param listener IDisplayMoveListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterDisplayMoveListener(sptr& listener) = 0; + virtual WMError RegisterDisplayMoveListener(sptr& listener) { return WMError::WM_OK; } /** * @brief Unregister display move listener. * * @param listener IDisplayMoveListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterDisplayMoveListener(sptr& listener) = 0; + virtual WMError UnregisterDisplayMoveListener(sptr& listener) { return WMError::WM_OK; } /** * @brief Register window destroyed listener. * * @param func Function to notify window destroyed. */ - virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0; + virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) {} /** * @brief Register Occupied Area Change listener. * * @param listener IOccupiedAreaChangeListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterOccupiedAreaChangeListener(const sptr& listener) = 0; + virtual WMError RegisterOccupiedAreaChangeListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Unregister occupied area change listener. * * @param listener IOccupiedAreaChangeListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterOccupiedAreaChangeListener(const sptr& listener) = 0; + virtual WMError UnregisterOccupiedAreaChangeListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Register touch outside listener. * * @param listener ITouchOutsideListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterTouchOutsideListener(const sptr& listener) = 0; + virtual WMError RegisterTouchOutsideListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Unregister touch outside listener. * * @param listener ITouchOutsideListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterTouchOutsideListener(const sptr& listener) = 0; + virtual WMError UnregisterTouchOutsideListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Register Animation Transition Controller listener. * * @param listener IAnimationTransitionController. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterAnimationTransitionController(const sptr& listener) = 0; + virtual WMError RegisterAnimationTransitionController(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Register screen shot listener. * * @param listener IScreenshotListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterScreenshotListener(const sptr& listener) = 0; + virtual WMError RegisterScreenshotListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Unregister screen shot listener. * * @param listener IScreenshotListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterScreenshotListener(const sptr& listener) = 0; + virtual WMError UnregisterScreenshotListener(const sptr& listener) { return WMError::WM_OK; } /** * @brief Register dialog target touch listener. * * @param listener IDialogTargetTouchListener. * @return WM_OK means register success, others means register failed. */ - virtual WMError RegisterDialogTargetTouchListener(const sptr& listener) = 0; + virtual WMError RegisterDialogTargetTouchListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Unregister dialog target touch listener. * * @param listener IDialogTargetTouchListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnregisterDialogTargetTouchListener(const sptr& listener) = 0; + virtual WMError UnregisterDialogTargetTouchListener(const sptr& listener) + { + return WMError::WM_OK; + } /** * @brief Register dialog death Recipient listener. * * @param listener IDialogDeathRecipientListener. */ - virtual void RegisterDialogDeathRecipientListener(const sptr& listener) = 0; + virtual void RegisterDialogDeathRecipientListener(const sptr& listener) {} /** * @brief Unregister window death recipient listener. * * @param listener IDialogDeathRecipientListener. */ - virtual void UnregisterDialogDeathRecipientListener(const sptr& listener) = 0; + virtual void UnregisterDialogDeathRecipientListener(const sptr& listener) {} /** * @brief Notify touch dialog target. */ - virtual void NotifyTouchDialogTarget() = 0; + virtual void NotifyTouchDialogTarget() {} /** * @brief Set ace ability handler. * * @param handler Ace ability handler. */ - virtual void SetAceAbilityHandler(const sptr& handler) = 0; + virtual void SetAceAbilityHandler(const sptr& handler) {} /** * @brief set window ui content * @@ -1054,129 +1100,132 @@ public: * @return WMError */ virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, - NativeValue* storage, bool isDistributed = false, AppExecFwk::Ability* ability = nullptr) = 0; + NativeValue* storage, bool isDistributed = false, AppExecFwk::Ability* ability = nullptr) + { + return WMError::WM_OK; + } /** * @brief Get ui content info. * * @return UI content info. */ - virtual std::string GetContentInfo() = 0; + virtual std::string GetContentInfo() { return std::string(); } /** * @brief Get ui content object. * * @return UIContent object of ACE. */ - virtual Ace::UIContent* GetUIContent() const = 0; + virtual Ace::UIContent* GetUIContent() const { return nullptr; } /** * @brief Window handle new want. * * @param want Want object of AAFwk. */ - virtual void OnNewWant(const AAFwk::Want& want) = 0; + virtual void OnNewWant(const AAFwk::Want& want) {} /** * @brief Set requested orientation. * * @param Orientation Screen orientation. */ - virtual void SetRequestedOrientation(Orientation) = 0; + virtual void SetRequestedOrientation(Orientation) {} /** * @brief Get requested orientation. * * @return Orientation screen orientation. */ - virtual Orientation GetRequestedOrientation() = 0; + virtual Orientation GetRequestedOrientation() { return Orientation::UNSPECIFIED; } /** * @brief Set requested mode support info. * * @param modeSupportInfo Mode of window supported. */ - virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) = 0; + virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) {} /** * @brief Get requested mode support info. * * @return Enumeration values under WindowModeSupport. */ - virtual uint32_t GetRequestModeSupportInfo() const = 0; + virtual uint32_t GetRequestModeSupportInfo() const { return 0; } /** * @brief Set touch hot areas. * * @param rects Hot areas of touching. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetTouchHotAreas(const std::vector& rects) = 0; + virtual WMError SetTouchHotAreas(const std::vector& rects) { return WMError::WM_OK; } /** * @brief Get requested touch hot areas. * * @param rects Hot areas of touching. */ - virtual void GetRequestedTouchHotAreas(std::vector& rects) const = 0; + virtual void GetRequestedTouchHotAreas(std::vector& rects) const {} /** * @brief Main handler available or not. * * @return True means main handler is available, false means the opposite. */ - virtual bool IsMainHandlerAvailable() const = 0; + virtual bool IsMainHandlerAvailable() const { return false; } /** * @brief Set window label name. * * @param label Window label name. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetAPPWindowLabel(const std::string& label) = 0; + virtual WMError SetAPPWindowLabel(const std::string& label) { return WMError::WM_OK; } /** * @brief Set window icon. * * @param icon Window icon. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetAPPWindowIcon(const std::shared_ptr& icon) = 0; + virtual WMError SetAPPWindowIcon(const std::shared_ptr& icon) { return WMError::WM_OK; } /** * @brief disable main window decoration. It must be callled before loadContent. * */ - virtual WMError DisableAppWindowDecor() = 0; + virtual WMError DisableAppWindowDecor() { return WMError::WM_OK; } /** * @brief return window decoration is enabled. It is called by ACE * * @return true means window decoration is enabled. Otherwise disabled */ - virtual bool IsDecorEnable() const = 0; + virtual bool IsDecorEnable() const { return false; } /** * @brief maximize the main window. It is called by ACE when maximize button is clicked. * * @return WMError */ - virtual WMError Maximize() = 0; + virtual WMError Maximize() { return WMError::WM_OK; } /** * @brief minimize the main window. It is called by ACE when minimize button is clicked. * * @return WMError */ - virtual WMError Minimize() = 0; + virtual WMError Minimize() { return WMError::WM_OK; } /** * @brief recovery the main window. It is called by ACE when recovery button is clicked. * * @return WMError */ - virtual WMError Recover() = 0; + virtual WMError Recover() { return WMError::WM_OK; } /** * @brief close the main window. It is called by ACE when close button is clicked. * * @return WMError */ - virtual WMError Close() = 0; + virtual WMError Close() { return WMError::WM_OK; } /** * @brief start move main window. It is called by ACE when title is moved. * */ - virtual void StartMove() = 0; + virtual void StartMove() {} /** * @brief Set flag that need remove window input channel. * * @param needRemoveWindowInputChannel True means remove input channel, false means not remove. */ - virtual void SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel) = 0; + virtual void SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel) {} // colorspace, gamut /** @@ -1184,27 +1233,27 @@ public: * * @return True means support wide gamut, false means not support. */ - virtual bool IsSupportWideGamut() = 0; + virtual bool IsSupportWideGamut() { return false; } /** * @brief Set color space. * * @param colorSpace ColorSpace object. */ - virtual void SetColorSpace(ColorSpace colorSpace) = 0; + virtual void SetColorSpace(ColorSpace colorSpace) {} /** * @brief Get color space object. * * @return ColorSpace object. */ - virtual ColorSpace GetColorSpace() = 0; + virtual ColorSpace GetColorSpace() { return ColorSpace::COLOR_SPACE_DEFAULT; } - virtual void DumpInfo(const std::vector& params, std::vector& info) = 0; + virtual void DumpInfo(const std::vector& params, std::vector& info) {} /** * @brief window snapshot * * @return std::shared_ptr snapshot pixel */ - virtual std::shared_ptr Snapshot() = 0; + virtual std::shared_ptr Snapshot() { return nullptr; } /** * @brief Handle and notify memory level. @@ -1212,14 +1261,14 @@ public: * @param level memory level * @return the error code of window */ - virtual WMError NotifyMemoryLevel(int32_t level) const = 0; + virtual WMError NotifyMemoryLevel(int32_t level) const { return WMError::WM_OK; } /** * @brief Update configuration for all windows * * @param configuration configuration for app */ - virtual bool IsAllowHaveSystemSubWindow() = 0; + virtual bool IsAllowHaveSystemSubWindow() { return false; } /** * @brief Set aspect ratio of this window @@ -1227,23 +1276,23 @@ public: * @param ratio the aspect ratio of window except decoration * @return WMError */ - virtual WMError SetAspectRatio(float ratio) = 0; + virtual WMError SetAspectRatio(float ratio) { return WMError::WM_OK; } /** * @brief Unset aspect ratio * @return WMError */ - virtual WMError ResetAspectRatio() = 0; + virtual WMError ResetAspectRatio() { return WMError::WM_OK; } /** * @brief Get keyboard animation config * @return KeyboardAnimationConfig */ - virtual KeyboardAnimationConfig GetKeyboardAnimationConfig() = 0; + virtual KeyboardAnimationConfig GetKeyboardAnimationConfig() { return {}; } /** * @brief Set need default animation for window show and hide. * * @param needDefaultAnimation True means need default animation, false means not need. */ - virtual void SetNeedDefaultAnimation(bool needDefaultAnimation) = 0; + virtual void SetNeedDefaultAnimation(bool needDefaultAnimation) {} }; } } diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index d182f1027d..9bf4f8caea 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -139,6 +139,13 @@ public: */ void SetWindowTag(WindowTag windowTag); + /** + * @brief Set window session type. + * + * @param sessionType The session type of window. + */ + void SetWindowSessionType(WindowSessionType sessionType); + /** * @brief Set keep screen on. * @@ -279,6 +286,13 @@ public: */ WindowTag GetWindowTag() const; + /** + * @brief Get window session type. + * + * @return Return window session type. + */ + WindowSessionType GetWindowSessionType() const; + /** * @brief Get window brightness. * @@ -319,6 +333,7 @@ private: uint32_t flags_ { 0 }; PointInfo hitOffset_ { 0, 0 }; WindowTag windowTag_; + WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION }; bool keepScreenOn_ = false; bool turnScreenOn_ = false; bool isMainHandlerAvailable_ = true; diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h index a355b50051..8546c9f58b 100644 --- a/interfaces/innerkits/wm/window_scene.h +++ b/interfaces/innerkits/wm/window_scene.h @@ -53,6 +53,19 @@ public: WMError Init(DisplayId displayId, const std::shared_ptr& context, sptr& listener, sptr option = nullptr); + /** + * Init a WindowScene instance based on the parameters displayId, context, listener and option. + * + * @param displayId the id of current display + * @param context current ability context + * @param listener the life cycle listener of the window + * @param option the settings for window, such as WindowType, width, height, etc + * @param iSession session token of window session + * @return the error code of window + */ + WMError Init(DisplayId displayId, const std::shared_ptr& context, + sptr& listener, sptr option, const sptr& iSession); + /** * Create a window instance based on the parameters windowName and option. * diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index f18926c87e..b2f2f7cfd6 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -76,6 +76,8 @@ enum class WindowType : uint32_t { SYSTEM_SUB_WINDOW_END, SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END, + + WINDOW_TYPE_UI_EXTENSION = 3000, }; /** @@ -271,6 +273,14 @@ enum class WindowTag : uint32_t { SYSTEM_WINDOW = 2, }; +/** + * @brief Enumerates window session type. + */ +enum class WindowSessionType : uint32_t { + SCENE_SESSION = 0, + EXTENSION_SESSION = 1, +}; + /** * @brief Enumerates window gravity. */ diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index f3326169ce..8cd78e81cb 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -134,7 +134,6 @@ ohos_shared_library("windowstage_kit") { external_deps = [ "ability_runtime:runtime", - "ace_engine:ace_uicontent", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp index 66d3a959c8..6ed6453031 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp @@ -31,9 +31,8 @@ constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindo } // namespace std::unique_ptr g_listenerManager = std::make_unique(); -JsWindowStage::JsWindowStage(const std::shared_ptr& windowScene, - const std::shared_ptr& uiWindow) - : windowScene_(windowScene), uiWindow_(uiWindow) +JsWindowStage::JsWindowStage(const std::shared_ptr& windowScene) + : windowScene_(windowScene) { } @@ -145,13 +144,6 @@ NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackI return engine.CreateUndefined(); } - auto uiWindow = uiWindow_.lock(); - if (uiWindow) { - uiWindow->LoadContent(contextUrl, &engine, nullptr); - uiWindow->Connect(); - return engine.CreateUndefined(); - } - auto weakScene = windowScene_.lock(); if (weakScene == nullptr || weakScene->GetMainWindow() == nullptr) { WLOGFE("[NAPI]WindowScene is null or window is null"); @@ -345,14 +337,8 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn std::shared_ptr contentStorage = (storage == nullptr) ? nullptr : std::shared_ptr(engine.CreateReference(storage, 1)); AsyncTask::CompleteCallback complete = - [weak = windowScene_, contentStorage, contextUrl, weakUIWindow = uiWindow_]( + [weak = windowScene_, contentStorage, contextUrl]( NativeEngine& engine, AsyncTask& task, int32_t status) { - if (auto uiWindow = weakUIWindow.lock()) { - NativeValue* nativeStorage = contentStorage ? contentStorage->Get() : nullptr; - uiWindow->LoadContent(contextUrl, &engine, nativeStorage); - task.Resolve(engine, engine.CreateUndefined()); - return; - } auto weakScene = weak.lock(); sptr win = weakScene ? weakScene->GetMainWindow() : nullptr; if (win == nullptr) { @@ -553,14 +539,13 @@ NativeValue* JsWindowStage::OnDisableWindowDecor(NativeEngine& engine, NativeCal return engine.CreateUndefined(); } -NativeValue* CreateJsWindowStage(NativeEngine& engine, - std::shared_ptr windowScene, std::shared_ptr uiWindow) +NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene) { WLOGFD("[NAPI]CreateJsWindowStage"); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); - std::unique_ptr jsWindowStage = std::make_unique(windowScene, uiWindow); + std::unique_ptr jsWindowStage = std::make_unique(windowScene); object->SetNativePointer(jsWindowStage.release(), JsWindowStage::Finalizer, nullptr); const char *moduleName = "JsWindowStage"; diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h index 13358c97f6..b7fc775676 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h @@ -21,15 +21,12 @@ #include "native_engine/native_reference.h" #include "native_engine/native_value.h" #include "window_scene.h" -#include "ui_window.h" namespace OHOS { namespace Rosen { -NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene, - std::shared_ptr uiWindow = nullptr); +NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene); class JsWindowStage { public: - explicit JsWindowStage(const std::shared_ptr& windowScene, - const std::shared_ptr& uiWindow); + explicit JsWindowStage(const std::shared_ptr& windowScene); ~JsWindowStage(); static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* SetUIContent(NativeEngine* engine, NativeCallbackInfo* info); @@ -58,7 +55,6 @@ private: NativeValue* OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info); std::weak_ptr windowScene_; - std::weak_ptr uiWindow_; }; } // namespace Rosen } // namespace OHOS diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 6d3cf9abd5..b93428b359 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -73,6 +73,11 @@ public: return (IsBelowSystemWindow(type) || IsAboveSystemWindow(type) || IsSystemSubWindow(type)); } + static inline bool IsUIExtensionWindow(WindowType type) + { + return (type == WindowType::WINDOW_TYPE_UI_EXTENSION); + } + static inline bool IsMainFloatingWindow(WindowType type, WindowMode mode) { return ((IsMainWindow(type)) && (mode == WindowMode::WINDOW_MODE_FLOATING)); diff --git a/window_scene/common/BUILD.gn b/window_scene/common/BUILD.gn index bd98501564..c53def4ec4 100644 --- a/window_scene/common/BUILD.gn +++ b/window_scene/common/BUILD.gn @@ -20,18 +20,24 @@ config("window_scene_common_public_config") { # for window_manager_hilog "${window_base_path}/utils/include", + "${window_base_path}/interfaces/innerkits/wm", ] } ## Build libwindow_scene_common.so ohos_shared_library("window_scene_common") { - sources = [ "src/message_scheduler.cpp" ] + sources = [ + "src/message_scheduler.cpp", + "src/window_session_property.cpp", + ] public_configs = [ ":window_scene_common_public_config" ] external_deps = [ + "c_utils:utils", "eventhandler:libeventhandler", "hilog_native:libhilog", + "ipc:ipc_single", ] part_name = "window_manager" diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h new file mode 100644 index 0000000000..0c5a02d1d3 --- /dev/null +++ b/window_scene/common/include/window_session_property.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SESSION_PROPERTY_H +#define OHOS_ROSEN_WINDOW_SESSION_PROPERTY_H + +#include +#include +#include +#include +#include "interfaces/include/ws_common.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowSessionProperty : public Parcelable { +public: + WindowSessionProperty() = default; + ~WindowSessionProperty() = default; + + void SetWindowName(const std::string& name); + void SetSessionInfo(const SessionInfo& info); + void SetRequestRect(const struct Rect& rect); + void SetWindowRect(const struct Rect& rect); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetDisplayId(uint64_t displayId); + void SetWindowType(WindowType type); + void SetPersistentId(uint64_t persistentId); + + const std::string& GetWindowName() const; + const SessionInfo& GetSessionInfo() const; + Rect GetWindowRect() const; + Rect GetRequestRect() const; + WindowType GetWindowType() const; + bool GetFocusable() const; + bool GetTouchable() const; + uint64_t GetDisplayId() const; + uint64_t GetPersistentId() const; + + bool Marshalling(Parcel& parcel) const override; + static WindowSessionProperty* Unmarshalling(Parcel& parcel); +private: + std::string windowName_; + SessionInfo sessionInfo_; + Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size) + Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; // type main window + bool focusable_ { true }; + bool touchable_ { true }; + uint64_t displayId_ = 0; + uint64_t persistentId_ = INVALID_SESSION_ID; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_WINDOW_PROPERTY_H diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp new file mode 100644 index 0000000000..ed52995c23 --- /dev/null +++ b/window_scene/common/src/window_session_property.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common/include/window_session_property.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +void WindowSessionProperty::SetWindowName(const std::string& name) +{ + windowName_ = name; +} + +void WindowSessionProperty::SetSessionInfo(const SessionInfo& info) +{ + sessionInfo_ = info; +} + +void WindowSessionProperty::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowSessionProperty::SetRequestRect(const Rect& requestRect) +{ + requestRect_ = requestRect; +} + +void WindowSessionProperty::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowSessionProperty::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowSessionProperty::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowSessionProperty::SetDisplayId(DisplayId displayId) +{ + displayId_ = displayId; +} + +const std::string& WindowSessionProperty::GetWindowName() const +{ + return windowName_ ; +} + +const SessionInfo& WindowSessionProperty::GetSessionInfo() const +{ + return sessionInfo_ ; +} + +Rect WindowSessionProperty::GetWindowRect() const +{ + return windowRect_; +} + +Rect WindowSessionProperty::GetRequestRect() const +{ + return requestRect_; +} + +WindowType WindowSessionProperty::GetWindowType() const +{ + return type_; +} + +bool WindowSessionProperty::GetFocusable() const +{ + return focusable_; +} + +bool WindowSessionProperty::GetTouchable() const +{ + return touchable_; +} + +DisplayId WindowSessionProperty::GetDisplayId() const +{ + return displayId_; +} + +void WindowSessionProperty::SetPersistentId(uint64_t persistentId) +{ + persistentId_ = persistentId; +} + +uint64_t WindowSessionProperty::GetPersistentId() const +{ + return persistentId_; +} + +bool WindowSessionProperty::Marshalling(Parcel& parcel) const +{ + return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) && + parcel.WriteInt32(windowRect_.posY_) && parcel.WriteUint32(windowRect_.width_) && + parcel.WriteUint32(windowRect_.height_) && parcel.WriteInt32(requestRect_.posX_) && + parcel.WriteInt32(requestRect_.posY_) && parcel.WriteUint32(requestRect_.width_) && + parcel.WriteUint32(requestRect_.height_) && + parcel.WriteUint32(static_cast(type_)) && + parcel.WriteBool(focusable_) && parcel.WriteBool(touchable_) && + parcel.WriteUint64(displayId_) && parcel.WriteUint64(persistentId_) && + parcel.WriteString(sessionInfo_.bundleName_) && + parcel.WriteString(sessionInfo_.abilityName_); +} + +WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) +{ + WindowSessionProperty* property = new(std::nothrow) WindowSessionProperty(); + if (property == nullptr) { + return nullptr; + } + property->SetWindowName(parcel.ReadString()); + Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetWindowRect(rect); + Rect reqRect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetRequestRect(reqRect); + property->SetWindowType(static_cast(parcel.ReadUint32())); + property->SetFocusable(parcel.ReadBool()); + property->SetTouchable(parcel.ReadBool()); + property->SetDisplayId(parcel.ReadUint64()); + property->SetPersistentId(parcel.ReadUint64()); + SessionInfo info = { parcel.ReadString(), parcel.ReadString(), nullptr }; + property->SetSessionInfo(info); + return property; +} +} // namespace Rosen +} // namespace OHOS diff --git a/window_scene/interfaces/include/ws_common.h b/window_scene/interfaces/include/ws_common.h index a5f4783c94..79570d6624 100644 --- a/window_scene/interfaces/include/ws_common.h +++ b/window_scene/interfaces/include/ws_common.h @@ -25,7 +25,7 @@ namespace OHOS::Rosen { namespace { -constexpr uint32_t INVALID_SESSION_ID = 0; +constexpr uint64_t INVALID_SESSION_ID = 0; } enum class WSError : int32_t { @@ -50,11 +50,11 @@ enum class WSErrorCode : int32_t { }; const std::map WS_JS_TO_ERROR_CODE_MAP { - { WSError::WS_OK, WSErrorCode::WS_OK }, - { WSError::WS_DO_NOTHING, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, + { WSError::WS_OK, WSErrorCode::WS_OK }, + { WSError::WS_DO_NOTHING, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, { WSError::WS_ERROR_INVALID_SESSION, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, - { WSError::WS_ERROR_IPC_FAILED, WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY }, - { WSError::WS_ERROR_NULLPTR, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, + { WSError::WS_ERROR_IPC_FAILED, WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY }, + { WSError::WS_ERROR_NULLPTR, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, }; enum class SessionState : uint32_t { @@ -74,11 +74,21 @@ struct SessionInfo { }; enum class SizeChangeReason : uint32_t { - SHOW = 0, - HIDE, + UNDEFINED = 0, MAXIMIZE, RECOVER, ROTATION, + DRAG, + DRAG_START, + DRAG_END, + RESIZE, + MOVE, + HIDE, + TRANSFORM, + CUSTOM_ANIMATION_SHOW, + FULL_TO_SPLIT, + SPLIT_TO_FULL, + END, }; struct WSRect { diff --git a/window_scene/session/BUILD.gn b/window_scene/session/BUILD.gn index 7cba6c46e2..b5de703cb3 100644 --- a/window_scene/session/BUILD.gn +++ b/window_scene/session/BUILD.gn @@ -20,6 +20,10 @@ config("session_public_config") { # for window_manager_hilog "${window_base_path}/utils/include", + "${window_base_path}/window_scene/common/include", + + # for WMError Code + "${window_base_path}/interfaces/innerkits/wm", ] } @@ -43,7 +47,10 @@ ohos_shared_library("scene_session") { public_configs = [ ":session_public_config" ] - deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ] + deps = [ + "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "${window_base_path}/window_scene/common:window_scene_common", + ] public_deps = [ "${window_base_path}/window_scene/interfaces/innerkits:libwsutils" ] diff --git a/window_scene/session/container/include/session_stage.h b/window_scene/session/container/include/session_stage.h index c0ea43aeab..d8f24d2808 100644 --- a/window_scene/session/container/include/session_stage.h +++ b/window_scene/session/container/include/session_stage.h @@ -96,13 +96,13 @@ public: bool RegisterInputEventListener(const std::shared_ptr& listener); bool UnregisterInputEventListener(const std::shared_ptr& listener); - inline void NotifyPointerEvent(const std::shared_ptr& pointerEvent) + inline void NotifyPointerEvent(const std::shared_ptr& pointerEvent) override { auto listeners = GetListeners(); CALL_INPUT_EVENT_LISTENER(listeners, OnPointerEvent, pointerEvent); } - inline void NotifyKeyEvent(const std::shared_ptr& keyEvent) + inline void NotifyKeyEvent(const std::shared_ptr& keyEvent) override { auto listeners = GetListeners(); CALL_INPUT_EVENT_LISTENER(listeners, OnKeyEvent, keyEvent); diff --git a/window_scene/session/container/include/window_event_channel.h b/window_scene/session/container/include/window_event_channel.h index 50127c2527..70f13309f8 100644 --- a/window_scene/session/container/include/window_event_channel.h +++ b/window_scene/session/container/include/window_event_channel.h @@ -17,20 +17,20 @@ #define OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_CHANNEL_H #include "interfaces/include/ws_common.h" -#include "session/container/include/session_stage.h" +#include "session/container/include/zidl/session_stage_interface.h" #include "session/container/include/zidl/window_event_channel_stub.h" namespace OHOS::Rosen { class WindowEventChannel : public WindowEventChannelStub { public: - explicit WindowEventChannel(sptr sessionStage) : sessionStage_(sessionStage) {} + explicit WindowEventChannel(sptr iSessionStage) : sessionStage_(iSessionStage) {} ~WindowEventChannel() = default; WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; WSError TransferPointerEvent(const std::shared_ptr& pointerEvent) override; private: - sptr sessionStage_ = nullptr; + sptr sessionStage_ = nullptr; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_CHANNEL_H diff --git a/window_scene/session/container/include/zidl/session_stage_interface.h b/window_scene/session/container/include/zidl/session_stage_interface.h index 0f6123e794..8c8e737391 100644 --- a/window_scene/session/container/include/zidl/session_stage_interface.h +++ b/window_scene/session/container/include/zidl/session_stage_interface.h @@ -20,6 +20,11 @@ #include "interfaces/include/ws_common.h" +namespace OHOS::MMI { +class PointerEvent; +class KeyEvent; +class AxisEvent; +} // namespace MMI namespace OHOS::Rosen { class ISessionStage : public IRemoteBroker { public: @@ -30,6 +35,9 @@ public: TRANS_ID_NOTIFY_SIZE_CHANGE, }; + virtual void NotifyPointerEvent(const std::shared_ptr& pointerEvent) {} + virtual void NotifyKeyEvent(const std::shared_ptr& keyEvent) {} + virtual WSError SetActive(bool active) = 0; virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) = 0; }; diff --git a/window_scene/session/container/src/session_stage.cpp b/window_scene/session/container/src/session_stage.cpp index 1205352a16..c4258fdff9 100644 --- a/window_scene/session/container/src/session_stage.cpp +++ b/window_scene/session/container/src/session_stage.cpp @@ -93,7 +93,8 @@ WSError SessionStage::Connect(const std::shared_ptr& surfaceNode) } sptr sessionStage(this); sptr eventChannel(new WindowEventChannel(sessionStage)); - return session_->Connect(sessionStage, eventChannel, surfaceNode); + uint64_t persistentId = INVALID_SESSION_ID; + return session_->Connect(sessionStage, eventChannel, surfaceNode, persistentId); } WSError SessionStage::Foreground() diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 0c85a67f94..7662f3e48d 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -62,7 +62,8 @@ public: virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason); WSError Connect(const sptr& sessionStage, const sptr& eventChannel, - const std::shared_ptr& surfaceNode) override; + const std::shared_ptr& surfaceNode, uint64_t& persistentId, + sptr property = nullptr) override; WSError Foreground() override; WSError Background() override; WSError Disconnect() override; @@ -92,7 +93,7 @@ protected: sptr sessionStage_; SessionInfo sessionInfo_; NotifyPendingSessionActivationFunc pendingSessionActivationFunc_; - + sptr property_ = nullptr; private: template bool RegisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener); diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index 6f2e0ddbd9..b4f77a4aef 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -18,6 +18,7 @@ #include #include "interfaces/include/ws_common.h" +#include "common/include/window_session_property.h" #include "session/container/include/zidl/session_stage_interface.h" #include "session/container/include/zidl/window_event_channel_interface.h" @@ -40,7 +41,8 @@ public: TRANS_ID_MAXIMIZE, }; virtual WSError Connect(const sptr& sessionStage, const sptr& eventChannel, - const std::shared_ptr& surfaceNode) = 0; + const std::shared_ptr& surfaceNode, uint64_t& persistentId, + sptr property = nullptr) = 0; virtual WSError Foreground() = 0; virtual WSError Background() = 0; virtual WSError Disconnect() = 0; diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index 7f780893e6..8714c786c1 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -24,14 +24,14 @@ namespace OHOS::Rosen { class SessionProxy : public IRemoteProxy { public: explicit SessionProxy(const sptr& impl) : IRemoteProxy(impl) {}; - ~SessionProxy() {}; WSError Foreground() override; WSError Background() override; WSError Disconnect() override; WSError Connect(const sptr& sessionStage, const sptr& eventChannel, - const std::shared_ptr& surfaceNode) override; + const std::shared_ptr& surfaceNode, uint64_t& persistentId, + sptr property = nullptr) override; WSError PendingSessionActivation(const SessionInfo& info) override; WSError Recover() override; diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 0fe492498d..e21aa85f21 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -152,9 +152,10 @@ WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason) } WSError Session::Connect(const sptr& sessionStage, const sptr& eventChannel, - const std::shared_ptr& surfaceNode) + const std::shared_ptr& surfaceNode, uint64_t& persistentId, sptr property) { - WLOGFI("Connect session, id: %{public}" PRIu64 ", state: %{public}u", GetPersistentId(), + persistentId = GetPersistentId(); + WLOGFI("Connect session, id: %{public}" PRIu64 ", state: %{public}u", persistentId, static_cast(GetSessionState())); if (GetSessionState() != SessionState::STATE_DISCONNECT) { WLOGFE("state is not disconnect!"); @@ -167,10 +168,10 @@ WSError Session::Connect(const sptr& sessionStage, const sptr& sessionStage, const sptr& eventChannel, - const std::shared_ptr& surfaceNode) + const std::shared_ptr& surfaceNode, uint64_t& persistentId, sptr property) { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; @@ -106,11 +106,24 @@ WSError SessionProxy::Connect(const sptr& sessionStage, const spt WLOGFE("Write surfaceNode failed"); return WSError::WS_ERROR_IPC_FAILED; } + + if (property) { + if (!data.WriteBool(true) || !property->Marshalling(data)) { + WLOGFE("Write property failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + } else { + if (!data.WriteBool(false)) { + WLOGFE("Write property failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + } if (Remote()->SendRequest(static_cast(SessionMessage::TRANS_ID_CONNECT), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } + persistentId = reply.ReadUint64(); int32_t ret = reply.ReadUint32(); return static_cast(ret); } diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 22cddde45d..f85d5e0964 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -90,7 +90,16 @@ int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply) WLOGFE("Failed to read scene session stage object or event channel object!"); return ERR_INVALID_DATA; } - WSError errCode = Connect(sessionStage, eventChannel, surfaceNode); + + sptr property = nullptr; + if (data.ReadBool()) { + property = data.ReadStrongParcelable(); + } else { + WLOGFW("Property not exist!"); + } + uint64_t persistentId = INVALID_SESSION_ID; + WSError errCode = Connect(sessionStage, eventChannel, surfaceNode, persistentId, property); + reply.WriteUint64(persistentId); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } diff --git a/window_scene/session_manager/include/session_manager_base.h b/window_scene/session_manager/include/session_manager_base.h index 993231a76a..7e60b37128 100644 --- a/window_scene/session_manager/include/session_manager_base.h +++ b/window_scene/session_manager/include/session_manager_base.h @@ -35,7 +35,7 @@ protected: private: int pid_ = getpid(); // shared by scene session and extension session once in same process - std::atomic sessionId_ = INVALID_SESSION_ID; + std::atomic sessionId_ = 0; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_BASE_H diff --git a/window_scene/test/unittest/BUILD.gn b/window_scene/test/unittest/BUILD.gn index 862ba349da..6180dd2276 100644 --- a/window_scene/test/unittest/BUILD.gn +++ b/window_scene/test/unittest/BUILD.gn @@ -32,6 +32,8 @@ ohos_unittest("ws_session_test") { ## Build ws_unittest_common.a {{{ config("ws_unittest_common_public_config") { include_dirs = [ + # for WMError Code + "${window_base_path}/interfaces/innerkits/wm", "${window_base_path}/window_scene", "${window_base_path}/window_scene/test", "//third_party/googletest/googlemock/include", diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 38d2694dbc..7d57d3be53 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -112,7 +112,8 @@ HWTEST_F(WindowSessionTest, SetActive01, Function | SmallTest | Level2) sptr mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage); EXPECT_NE(nullptr, mockEventChannel); auto surfaceNode = CreateRSSurfaceNode(); - ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, surfaceNode)); + uint64_t persistentId; + ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, surfaceNode, persistentId)); ASSERT_EQ(WSError::WS_OK, session_->SetActive(true)); ASSERT_EQ(false, session_->isActive_); @@ -136,14 +137,15 @@ HWTEST_F(WindowSessionTest, UpdateRect01, Function | SmallTest | Level2) EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK)); WSRect rect = {0, 0, 0, 0}; - ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->UpdateRect(rect, SizeChangeReason::SHOW)); + ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED)); sptr mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage); EXPECT_NE(nullptr, mockEventChannel); - ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, nullptr)); + uint64_t persistentId = 0; + ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, nullptr, persistentId)); rect = {0, 0, 100, 100}; EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK)); - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::SHOW)); + ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED)); ASSERT_EQ(rect, session_->winRect_); } @@ -169,22 +171,23 @@ HWTEST_F(WindowSessionTest, Connect01, Function | SmallTest | Level2) { auto surfaceNode = CreateRSSurfaceNode(); session_->state_ = SessionState::STATE_CONNECT; - auto result = session_->Connect(nullptr, nullptr, nullptr); + uint64_t persistentId = 0; + auto result = session_->Connect(nullptr, nullptr, nullptr, persistentId); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); session_->state_ = SessionState::STATE_DISCONNECT; - result = session_->Connect(nullptr, nullptr, nullptr); + result = session_->Connect(nullptr, nullptr, nullptr, persistentId); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); sptr sessionToken = nullptr; sptr sessionStage = new(std::nothrow) SessionStage(sessionToken); EXPECT_NE(nullptr, sessionStage); - result = session_->Connect(sessionStage, nullptr, surfaceNode); + result = session_->Connect(sessionStage, nullptr, surfaceNode, persistentId); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); sptr testWindowEventChannel = new(std::nothrow) TestWindowEventChannel(); EXPECT_NE(nullptr, testWindowEventChannel); - result = session_->Connect(sessionStage, testWindowEventChannel, surfaceNode); + result = session_->Connect(sessionStage, testWindowEventChannel, surfaceNode, persistentId); ASSERT_EQ(result, WSError::WS_OK); } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index a7414421d2..ebf5b98f40 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -29,6 +29,7 @@ config("libwm_public_config") { include_dirs = [ "../interfaces/innerkits/wm", "../utils/include", + "../window_scene", ] } @@ -46,6 +47,7 @@ ohos_static_library("libwm_static") { "src/window_accessibility_controller.cpp", "src/window_adapter.cpp", "src/window_agent.cpp", + "src/window_extension_session_impl.cpp", "src/window_frame_trace_impl.cpp", "src/window_impl.cpp", "src/window_input_channel.cpp", @@ -53,6 +55,8 @@ ohos_static_library("libwm_static") { "src/window_manager_agent.cpp", "src/window_option.cpp", "src/window_scene.cpp", + "src/window_scene_session_impl.cpp", + "src/window_session_impl.cpp", "src/zidl/window_manager_agent_stub.cpp", "src/zidl/window_stub.cpp", ] @@ -68,6 +72,8 @@ ohos_static_library("libwm_static") { "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client", "${window_base_path}/dm:libdm", "${window_base_path}/utils:libwmutil", + "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/session:scene_session", ] external_deps = [ @@ -141,6 +147,7 @@ ohos_shared_library("libwm") { "src/window_accessibility_controller.cpp", "src/window_adapter.cpp", "src/window_agent.cpp", + "src/window_extension_session_impl.cpp", "src/window_frame_trace_impl.cpp", "src/window_impl.cpp", "src/window_input_channel.cpp", @@ -148,6 +155,8 @@ ohos_shared_library("libwm") { "src/window_manager_agent.cpp", "src/window_option.cpp", "src/window_scene.cpp", + "src/window_scene_session_impl.cpp", + "src/window_session_impl.cpp", "src/zidl/window_manager_agent_stub.cpp", "src/zidl/window_stub.cpp", ] @@ -160,6 +169,8 @@ ohos_shared_library("libwm") { public_configs = [ ":libwm_public_config" ] deps = [ + "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/session:scene_session", "../dm:libdm", "../utils:libwmutil", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", diff --git a/wm/include/static_call.h b/wm/include/static_call.h index 47a3ee5f80..fad5cd1691 100644 --- a/wm/include/static_call.h +++ b/wm/include/static_call.h @@ -21,13 +21,18 @@ #include "wm_single_instance.h" #include "window.h" #include "window_option.h" + namespace OHOS { namespace Rosen { +class ISession; class StaticCall { WM_DECLARE_SINGLE_INSTANCE_BASE(StaticCall); public: virtual sptr CreateWindow(const std::string& windowName, sptr& option, std::shared_ptr context = nullptr); + virtual sptr CreateWindow(const std::string& windowName, + sptr& option, std::shared_ptr context, + const sptr& iSession); virtual std::vector> GetSubWindow(uint32_t parentId); protected: StaticCall() = default; diff --git a/wm/include/window_extension_session_impl.h b/wm/include/window_extension_session_impl.h new file mode 100644 index 0000000000..0805519d66 --- /dev/null +++ b/wm/include/window_extension_session_impl.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_EXTENSION_SESSION_IMPL_H +#define OHOS_ROSEN_WINDOW_EXTENSION_SESSION_IMPL_H + +#include "window_session_impl.h" + +namespace OHOS { +namespace Rosen { + +class WindowExtensionSessionImpl : public WindowSessionImpl { +public: + explicit WindowExtensionSessionImpl(const sptr& option); + ~WindowExtensionSessionImpl(); + WMError Create(const std::shared_ptr& context, + const sptr& iSession) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_WINDOW_EXTENSION_SESSION_IMPL_H \ No newline at end of file diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h new file mode 100644 index 0000000000..0ee9541abd --- /dev/null +++ b/wm/include/window_scene_session_impl.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H +#define OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H + +#include "window_session_impl.h" + +namespace OHOS { +namespace Rosen { + +class WindowSceneSessionImpl : public WindowSessionImpl { +public: + explicit WindowSceneSessionImpl(const sptr& option); + ~WindowSceneSessionImpl(); +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H \ No newline at end of file diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h new file mode 100644 index 0000000000..2b6fa04641 --- /dev/null +++ b/wm/include/window_session_impl.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SESSION_IMPL_H +#define OHOS_ROSEN_WINDOW_SESSION_IMPL_H + +#include +#include +#include +#include + +#include "common/include/window_session_property.h" +#include "session/container/include/zidl/session_stage_stub.h" +#include "session/host/include/zidl/session_interface.h" +#include "window.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +namespace { +template +using EnableIfSame = typename std::enable_if, Ret>::type; +} +class WindowSessionImpl : public Window, virtual public SessionStageStub { +public: + explicit WindowSessionImpl(const sptr& option); + ~WindowSessionImpl(); + // inherits from window + virtual WMError Create(const std::shared_ptr& context, + const sptr& iSession); + WMError Show(uint32_t reason = 0, bool withAnimation = false) override; + WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; + WMError Destroy() override; + WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, + NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override; + std::shared_ptr GetSurfaceNode() const override; + const std::shared_ptr GetContext() const override; + Rect GetRequestRect() const override; + WindowType GetType() const override; + const std::string& GetWindowName() const override; + WindowState GetWindowState() const override; + WMError SetFocusable(bool isFocusable) override; + WMError SetTouchable(bool isTouchable) override; + WMError SetWindowType(WindowType type) override; + bool GetTouchable() const override; + uint32_t GetWindowId() const override; + Rect GetRect() const override; + bool GetFocusable() const override; + std::string GetContentInfo() override; + Ace::UIContent* GetUIContent() const override; + void OnNewWant(const AAFwk::Want& want) override; + void RequestVsync(const std::shared_ptr& vsyncCallback) override; + // inherits from session stage + WSError SetActive(bool active) override; + WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) override; + void NotifyPointerEvent(const std::shared_ptr& pointerEvent) override; + void NotifyKeyEvent(const std::shared_ptr& keyEvent) override; + // callback + WMError RegisterLifeCycleListener(const sptr& listener) override; + WMError UnregisterLifeCycleListener(const sptr& listener) override; + WMError RegisterWindowChangeListener(const sptr& listener) override; + WMError UnregisterWindowChangeListener(const sptr& listener) override; + uint64_t GetPersistentId() const; + +protected: + WMError Connect(); + + std::unique_ptr uiContent_ = nullptr; + sptr hostSession_ = nullptr; + std::shared_ptr context_ = nullptr; + std::shared_ptr surfaceNode_ = nullptr; + sptr property_ = nullptr; + WindowState state_ { WindowState::STATE_INITIAL }; + +private: + template WMError RegisterListener(std::vector>& holder, const sptr& listener); + template WMError UnregisterListener(std::vector>& holder, const sptr& listener); + template EnableIfSame>> GetListeners(); + template + EnableIfSame>> GetListeners(); + template void ClearUselessListeners(std::map& listeners, uint64_t persistentId); + + WMError Destroy(bool needClearListener); + RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name, WindowType type); + bool IsWindowSessionInvalid() const; + void NotifyAfterForeground(bool needNotifyListeners = true, bool needNotifyUiContent = true); + void NotifyAfterBackground(bool needNotifyListeners = true, bool needNotifyUiContent = true); + void NotifyAfterFocused(); + void NotifyAfterUnfocused(bool needNotifyUiContent = true); + void NotifyBeforeDestroy(std::string windowName); + void NotifyAfterActive(); + void NotifyAfterInactive(); + void NotifyForegroundFailed(WMError ret); + void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason); + void ClearListenersById(uint64_t persistentId); + void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); + static std::map>> lifecycleListeners_; + static std::map>> windowChangeListeners_; + static std::recursive_mutex globalMutex_; + std::recursive_mutex mutex_; + NotifyNativeWinDestroyFunc notifyNativefunc_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_WINDOW_SESSION_IMPL_H \ No newline at end of file diff --git a/wm/src/static_call.cpp b/wm/src/static_call.cpp index b92fe6d36d..7b927a08cc 100644 --- a/wm/src/static_call.cpp +++ b/wm/src/static_call.cpp @@ -14,6 +14,7 @@ */ #include "static_call.h" +#include "session/host/include/zidl/session_interface.h" namespace OHOS { namespace Rosen { @@ -25,6 +26,12 @@ sptr StaticCall::CreateWindow(const std::string& windowName, return Window::Create(windowName, option, context); } +sptr StaticCall::CreateWindow(const std::string& windowName, + sptr& option, std::shared_ptr context, const sptr& iSession) +{ + return Window::Create(windowName, option, context, iSession); +} + std::vector> StaticCall::GetSubWindow(uint32_t parentId) { return Window::GetSubWindow(parentId); diff --git a/wm/src/window.cpp b/wm/src/window.cpp index 0ab65bfb8b..a14028b9ce 100644 --- a/wm/src/window.cpp +++ b/wm/src/window.cpp @@ -14,16 +14,47 @@ */ #include "window.h" + +#include "scene_board_judgement.h" +#include "session/host/include/zidl/session_interface.h" #include "window_helper.h" #include "window_impl.h" +#include "window_session_impl.h" +#include "window_scene_session_impl.h" +#include "window_extension_session_impl.h" #include "window_manager_hilog.h" #include "wm_common.h" namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Window"}; +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Window"}; } + +static sptr CreateWindowWithSession(sptr& option, + const std::shared_ptr& context, WMError& errCode, + sptr iSession = nullptr) +{ + sptr windowSessionImpl = nullptr; + auto sessionType = option->GetWindowSessionType(); + if (sessionType == WindowSessionType::SCENE_SESSION) { + windowSessionImpl = new(std::nothrow) WindowSceneSessionImpl(option); + } else if (sessionType == WindowSessionType::EXTENSION_SESSION) { + windowSessionImpl = new(std::nothrow) WindowExtensionSessionImpl(option); + } + + if (windowSessionImpl == nullptr) { + WLOGFE("malloc windowSessionImpl failed"); + return nullptr; + } + WMError error = windowSessionImpl->Create(context, iSession); + if (error != WMError::WM_OK) { + errCode = error; + return nullptr; + } + return windowSessionImpl; +} + sptr Window::Create(const std::string& windowName, sptr& option, const std::shared_ptr& context, WMError& errCode) { @@ -52,6 +83,9 @@ sptr Window::Create(const std::string& windowName, sptr& o return nullptr; } option->SetWindowName(windowName); + if (SceneBoardJudgement::IsSceneBoardEnabled()) { + return CreateWindowWithSession(option, context, errCode); + } sptr windowImpl = new(std::nothrow) WindowImpl(option); if (windowImpl == nullptr) { WLOGFE("malloc windowImpl failed"); @@ -65,6 +99,28 @@ sptr Window::Create(const std::string& windowName, sptr& o return windowImpl; } +sptr Window::Create(const std::string& windowName, sptr& option, + const std::shared_ptr& context, const sptr& iSession, WMError& errCode) +{ + // create from ability mgr service + if (!iSession || !option) { + WLOGFE("host window session is nullptr: %{public}u or option is null: %{public}u", + iSession == nullptr, option == nullptr); + return nullptr; + } + if (windowName.empty()) { + WLOGFE("window name is empty"); + return nullptr; + } + WindowType type = option->GetWindowType(); + if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsUIExtensionWindow(type))) { + WLOGFE("window type is invalid %{public}d", type); + return nullptr; + } + option->SetWindowName(windowName); + return CreateWindowWithSession(option, context, errCode, iSession); +} + sptr Window::Find(const std::string& windowName) { return WindowImpl::Find(windowName); diff --git a/wm/src/window_extension_session_impl.cpp b/wm/src/window_extension_session_impl.cpp new file mode 100644 index 0000000000..678686c379 --- /dev/null +++ b/wm/src/window_extension_session_impl.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_extension_session_impl.h" + +#include "window_manager_hilog.h" +#include "window_session_impl.h" + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionSessionImpl"}; +} + +WindowExtensionSessionImpl::WindowExtensionSessionImpl(const sptr& option) : WindowSessionImpl(option) +{ +} + +WindowExtensionSessionImpl::~WindowExtensionSessionImpl() +{ +} + +WMError WindowExtensionSessionImpl::Create(const std::shared_ptr& context, + const sptr& iSession) +{ + if (!context || !iSession) { + WLOGFE("context is nullptr: %{public}u or sessionToken is nullptr: %{public}u", + context == nullptr, iSession == nullptr); + return WMError::WM_ERROR_NULLPTR; + } + hostSession_ = iSession; + context_ = context; + Connect(); + state_ = WindowState::STATE_CREATED; + return WMError::WM_OK; +} +} // namespace Rosen +} // namespace OHOS + diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index a5fdfed1fa..f6843f155e 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1918,7 +1918,7 @@ WMError WindowImpl::RegisterWindowChangeListener(const sptr& listener) { - WLOGFD("Start register"); + WLOGFD("Start unregister"); std::lock_guard lock(globalMutex_); return UnregisterListener(windowChangeListeners_[GetWindowId()], listener); } diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index a738d745ed..4569003829 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -150,6 +150,16 @@ WindowTag WindowOption::GetWindowTag() const return windowTag_; } +void WindowOption::SetWindowSessionType(WindowSessionType sessionType) +{ + sessionType_ = sessionType; +} + +WindowSessionType WindowOption::GetWindowSessionType() const +{ + return sessionType_; +} + void WindowOption::SetMainHandlerAvailable(bool isMainHandlerAvailable) { isMainHandlerAvailable_ = isMainHandlerAvailable; diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index 24155045e5..8546010322 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -41,6 +41,7 @@ WindowScene::~WindowScene() WMError WindowScene::Init(DisplayId displayId, const std::shared_ptr& context, sptr& listener, sptr option) { + WLOGFI("WindowScene init with normal option!"); displayId_ = displayId; if (option == nullptr) { option = new(std::nothrow) WindowOption(); @@ -62,6 +63,28 @@ WMError WindowScene::Init(DisplayId displayId, const std::shared_ptr& context, + sptr& listener, sptr option, const sptr& iSession) +{ + WLOGFI("WindowScene with window session!"); + displayId_ = displayId; + if (option == nullptr || iSession == nullptr) { + WLOGFE("Cannot init scene with option or iSession null!"); + return WMError::WM_ERROR_NULLPTR; + } + option->SetDisplayId(displayId); + + mainWindow_ = SingletonContainer::Get().CreateWindow( + GenerateMainWindowName(context), option, context, iSession); + if (mainWindow_ == nullptr) { + WLOGFE("mainWindow is null after creat Window!"); + return WMError::WM_ERROR_NULLPTR; + } + mainWindow_->RegisterLifeCycleListener(listener); + + return WMError::WM_OK; +} + std::string WindowScene::GenerateMainWindowName(const std::shared_ptr& context) const { if (context == nullptr) { @@ -101,7 +124,7 @@ std::vector> WindowScene::GetSubWindow() WMError WindowScene::GoForeground(uint32_t reason) { - WLOGI("reason:%{public}u", reason); + WLOGFI("reason:%{public}u", reason); if (mainWindow_ == nullptr) { WLOGFE("Go foreground failed, because main window is null"); return WMError::WM_ERROR_NULLPTR; @@ -111,7 +134,7 @@ WMError WindowScene::GoForeground(uint32_t reason) WMError WindowScene::GoBackground(uint32_t reason) { - WLOGI("reason:%{public}u", reason); + WLOGFI("reason:%{public}u", reason); if (mainWindow_ == nullptr) { WLOGFE("Go background failed, because main window is null"); return WMError::WM_ERROR_NULLPTR; diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp new file mode 100644 index 0000000000..824ce37d50 --- /dev/null +++ b/wm/src/window_scene_session_impl.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_scene_session_impl.h" + +#include "window_manager_hilog.h" +#include "window_session_impl.h" + +namespace OHOS { +namespace Rosen { +namespace { +} + +WindowSceneSessionImpl::WindowSceneSessionImpl(const sptr& option) : WindowSessionImpl(option) +{ +} + +WindowSceneSessionImpl::~WindowSceneSessionImpl() +{ +} +} // namespace Rosen +} // namespace OHOS + diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp new file mode 100644 index 0000000000..7f8d564691 --- /dev/null +++ b/wm/src/window_session_impl.cpp @@ -0,0 +1,608 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_session_impl.h" + +#include +#include +#include +#include +#include "window_manager_hilog.h" +#include "window_helper.h" +#include "session/container/include/window_event_channel.h" +#include "vsync_station.h" + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSessionImpl"}; +} + +std::map>> WindowSessionImpl::lifecycleListeners_; +std::map>> WindowSessionImpl::windowChangeListeners_; +std::recursive_mutex WindowSessionImpl::globalMutex_; + +#define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, listeners) \ + do { \ + for (auto& listener : (listeners)) { \ + if (listener.GetRefPtr() != nullptr) { \ + listener.GetRefPtr()->windowLifecycleCb(); \ + } \ + } \ + } while (0) + +#define CALL_LIFECYCLE_LISTENER_WITH_PARAM(windowLifecycleCb, listeners, param) \ + do { \ + for (auto& listener : (listeners)) { \ + if (listener.GetRefPtr()) { \ + listener.GetRefPtr()->windowLifecycleCb(param); \ + } \ + } \ + } while (0) + +#define CALL_UI_CONTENT(uiContentCb) \ + do { \ + if (uiContent_ != nullptr) { \ + uiContent_->uiContentCb(); \ + } \ + } while (0) + +WindowSessionImpl::WindowSessionImpl(const sptr& option) +{ + property_ = new (std::nothrow) WindowSessionProperty(); + if (property_ == nullptr) { + WLOGFE("Property is null"); + return; + } + property_->SetWindowName(option->GetWindowName()); + property_->SetRequestRect(option->GetWindowRect()); + property_->SetWindowType(option->GetWindowType()); + property_->SetFocusable(option->GetFocusable()); + property_->SetTouchable(option->GetTouchable()); + property_->SetDisplayId(option->GetDisplayId()); + property_->SetWindowName(option->GetWindowName()); + surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), option->GetWindowType()); +} + +RSSurfaceNode::SharedPtr WindowSessionImpl::CreateSurfaceNode(std::string name, WindowType type) +{ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + rsSurfaceNodeConfig.SurfaceNodeName = name; + RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT; + switch (type) { + case WindowType::WINDOW_TYPE_BOOT_ANIMATION: + case WindowType::WINDOW_TYPE_POINTER: + rsSurfaceNodeType = RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; + break; + case WindowType::WINDOW_TYPE_APP_MAIN_WINDOW: + rsSurfaceNodeType = RSSurfaceNodeType::APP_WINDOW_NODE; + break; + default: + rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT; + break; + } + return RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType); +} + +WindowSessionImpl::~WindowSessionImpl() +{ + Destroy(false); +} + +uint32_t WindowSessionImpl::GetWindowId() const +{ + // for get window property + return static_cast((property_->GetPersistentId()) & 0xffffffff); // 0xffffffff: to get lower 32 bits +} + +bool WindowSessionImpl::IsWindowSessionInvalid() const +{ + bool res = ((hostSession_ == nullptr) || (GetPersistentId() == INVALID_SESSION_ID) || + (state_ == WindowState::STATE_DESTROYED)); + if (res) { + WLOGW("already destroyed or not created! id: %{public}" PRIu64 "", GetPersistentId()); + } + return res; +} + +uint64_t WindowSessionImpl::GetPersistentId() const +{ + return property_->GetPersistentId(); +} + +WMError WindowSessionImpl::Create(const std::shared_ptr& context, + const sptr& iSession) +{ + // allow iSession is nullptr when create from window manager + if (!context) { + WLOGFE("context is nullptr: %{public}u", context == nullptr); + return WMError::WM_ERROR_INVALID_PARAM; + } + hostSession_ = iSession; + context_ = context; + WMError ret = WMError::WM_OK; + if (hostSession_) { + ret = Connect(); + state_ = WindowState::STATE_CREATED; + } + return ret; +} + +WMError WindowSessionImpl::Connect() +{ + if (hostSession_ == nullptr) { + WLOGFE("session is invalid"); + return WMError::WM_ERROR_NULLPTR; + } + sptr iSessionStage(this); + sptr eventChannel(new WindowEventChannel(iSessionStage)); + uint64_t persistentId = INVALID_SESSION_ID; + WSError ret = hostSession_->Connect(iSessionStage, eventChannel, surfaceNode_, persistentId, property_); + property_->SetPersistentId(persistentId); + // replace WSError with WMError + WMError res = static_cast(ret); + WLOGFI("Window Connect [name:%{public}s, id:%{public}" PRIu64 ", type: %{public}u], ret:%{public}u", + property_->GetWindowName().c_str(), property_->GetPersistentId(), property_->GetWindowType(), res); + return res; +} + +WMError WindowSessionImpl::Show(uint32_t reason, bool withAnimation) +{ + WLOGFI("Window Show [name:%{public}s, id:%{public}" PRIu64 ", type: %{public}u], reason:%{public}u", + property_->GetWindowName().c_str(), property_->GetPersistentId(), property_->GetWindowType(), reason); + if (IsWindowSessionInvalid()) { + WLOGFE("session is invalid"); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == WindowState::STATE_SHOWN) { + WLOGFD("window session is alreay shown [name:%{public}s, id:%{public}" PRIu64 ", type: %{public}u]", + property_->GetWindowName().c_str(), property_->GetPersistentId(), property_->GetWindowType()); + return WMError::WM_OK; + } + + WSError ret = hostSession_->Foreground(); + // delete after replace WSError with WMError + WMError res = static_cast(ret); + if (res == WMError::WM_OK) { + NotifyAfterForeground(); + state_ = WindowState::STATE_SHOWN; + } else { + NotifyForegroundFailed(res); + } + return res; +} + +WMError WindowSessionImpl::Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) +{ + WLOGFI("id:%{public}" PRIu64 " Hide, reason:%{public}u, state:%{public}u", + property_->GetPersistentId(), reason, state_); + if (IsWindowSessionInvalid()) { + WLOGFE("session is invalid"); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) { + WLOGFD("window session is alreay hidden [name:%{public}s, id:%{public}" PRIu64 ", type: %{public}u]", + property_->GetWindowName().c_str(), property_->GetPersistentId(), property_->GetWindowType()); + return WMError::WM_OK; + } + WSError ret = WSError::WS_OK; + if (!WindowHelper::IsMainWindow(GetType())) { + // main window no need to notify host, since host knows hide first + // need to set host session SetActive(false) + ret = hostSession_->Background(); + } + + // delete after replace WSError with WMError + WMError res = static_cast(ret); + if (res == WMError::WM_OK) { + NotifyAfterBackground(); + state_ = WindowState::STATE_HIDDEN; + } + return res; +} + +WMError WindowSessionImpl::Destroy(bool needClearListener) +{ + WLOGFI("id:%{public}" PRIu64 " Destroy", property_->GetPersistentId()); + if (IsWindowSessionInvalid()) { + WLOGFE("session is invalid"); + return WMError::WM_OK; + } + WSError ret = WSError::WS_OK; + if (!WindowHelper::IsMainWindow(GetType())) { + // main window no need to notify host, since host knows hide first + ret = hostSession_->Disconnect(); + } + // delete after replace WSError with WMError + WMError res = static_cast(ret); + if (res == WMError::WM_OK) { + NotifyBeforeDestroy(GetWindowName()); + state_ = WindowState::STATE_DESTROYED; + } + if (needClearListener) { + ClearListenersById(GetPersistentId()); + } + return res; +} + +WMError WindowSessionImpl::Destroy() +{ + return Destroy(true); +} + +WSError WindowSessionImpl::SetActive(bool active) +{ + WLOGFD("active status: %{public}d", active); + if (active) { + NotifyAfterActive(); + } else { + NotifyAfterInactive(); + } + return WSError::WS_OK; +} + +WSError WindowSessionImpl::UpdateRect(const WSRect& rect, SizeChangeReason reason) +{ + WLOGFI("update rect [%{public}d, %{public}d, %{public}u, %{public}u], reason:%{public}u", rect.posX_, rect.posY_, + rect.width_, rect.height_, reason); + + // delete after replace ws_common.h with wm_common.h + auto wmReason = static_cast(reason); + Rect wmRect = { rect.posX_, rect.posY_, rect.width_, rect.height_ }; + property_->SetWindowRect(wmRect); + NotifySizeChange(wmRect, wmReason); + UpdateViewportConfig(wmRect, wmReason); + return WSError::WS_OK; +} + +void WindowSessionImpl::UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason) +{ + std::lock_guard lock(mutex_); + if (uiContent_ == nullptr) { + return; + } + Ace::ViewportConfig config; + config.SetSize(rect.width_, rect.height_); + config.SetPosition(rect.posX_, rect.posY_); + float density = rect.height_ > 2700 ? 3.5f : 1.5f; // 2700: phone height; 3.5f/1.5f: normal desity + config.SetDensity(density); + uiContent_->UpdateViewportConfig(config, reason); + WLOGFD("Id:%{public}" PRIu64 ", windowRect:[%{public}d, %{public}d, %{public}u, %{public}u]", + property_->GetPersistentId(), rect.posX_, rect.posY_, rect.width_, rect.height_); +} + +Rect WindowSessionImpl::GetRect() const +{ + return property_->GetWindowRect(); +} + +WMError WindowSessionImpl::SetUIContent(const std::string& contentInfo, + NativeEngine* engine, NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) +{ + WLOGFD("SetUIContent: %{public}s state:%{public}u", contentInfo.c_str(), state_); + if (uiContent_) { + uiContent_->Destroy(); + } + std::unique_ptr uiContent; + if (ability != nullptr) { + uiContent = Ace::UIContent::Create(ability); + } else { + uiContent = Ace::UIContent::Create(context_.get(), engine); + } + if (uiContent == nullptr) { + WLOGFE("fail to SetUIContent id: %{public}" PRIu64 "", property_->GetPersistentId()); + return WMError::WM_ERROR_NULLPTR; + } + if (isdistributed) { + uiContent->Restore(this, contentInfo, storage); + } else { + uiContent->Initialize(this, contentInfo, storage); + } + // make uiContent available after Initialize/Restore + uiContent_ = std::move(uiContent); + if (state_ == WindowState::STATE_SHOWN) { + // UIContent may be nullptr when show window, need to notify again when window is shown + uiContent_->Foreground(); + } + UpdateViewportConfig(GetRect(), WindowSizeChangeReason::UNDEFINED); + WLOGFD("notify uiContent window size change end"); + return WMError::WM_OK; +} + +std::shared_ptr WindowSessionImpl::GetSurfaceNode() const +{ + return surfaceNode_; +} + +const std::shared_ptr WindowSessionImpl::GetContext() const +{ + return context_; +} + +Rect WindowSessionImpl::GetRequestRect() const +{ + return property_->GetRequestRect(); +} + +WindowType WindowSessionImpl::GetType() const +{ + return property_->GetWindowType(); +} + +const std::string& WindowSessionImpl::GetWindowName() const +{ + return property_->GetWindowName(); +} + +WindowState WindowSessionImpl::GetWindowState() const +{ + return state_; +} + +WMError WindowSessionImpl::SetFocusable(bool isFocusable) +{ + property_->SetFocusable(isFocusable); + return WMError::WM_OK; +} + +bool WindowSessionImpl::GetFocusable() const +{ + return property_->GetFocusable(); +} + +WMError WindowSessionImpl::SetTouchable(bool isTouchable) +{ + property_->SetTouchable(isTouchable); + return WMError::WM_OK; +} + +bool WindowSessionImpl::GetTouchable() const +{ + return property_->GetTouchable(); +} + +WMError WindowSessionImpl::SetWindowType(WindowType type) +{ + property_->SetWindowType(type); + return WMError::WM_OK; +} + +std::string WindowSessionImpl::GetContentInfo() +{ + WLOGFD("GetContentInfo"); + if (uiContent_ == nullptr) { + WLOGFE("fail to GetContentInfo id: %{public}" PRIu64 "", property_->GetPersistentId()); + return ""; + } + return uiContent_->GetContentInfo(); +} + +Ace::UIContent* WindowSessionImpl::GetUIContent() const +{ + return uiContent_.get(); +} + +void WindowSessionImpl::OnNewWant(const AAFwk::Want& want) +{ + WLOGFI("Window [name:%{public}s, id:%{public}" PRIu64 "]", + property_->GetWindowName().c_str(), property_->GetPersistentId()); + if (uiContent_ != nullptr) { + uiContent_->OnNewWant(want); + } +} + +WMError WindowSessionImpl::RegisterLifeCycleListener(const sptr& listener) +{ + WLOGFD("Start register"); + std::lock_guard lock(globalMutex_); + return RegisterListener(lifecycleListeners_[GetPersistentId()], listener); +} + +WMError WindowSessionImpl::UnregisterLifeCycleListener(const sptr& listener) +{ + WLOGFD("Start unregister"); + std::lock_guard lock(globalMutex_); + return UnregisterListener(lifecycleListeners_[GetPersistentId()], listener); +} + +WMError WindowSessionImpl::RegisterWindowChangeListener(const sptr& listener) +{ + WLOGFD("Start register"); + std::lock_guard lock(globalMutex_); + return RegisterListener(windowChangeListeners_[GetPersistentId()], listener); +} + +WMError WindowSessionImpl::UnregisterWindowChangeListener(const sptr& listener) +{ + WLOGFD("Start register"); + std::lock_guard lock(globalMutex_); + return UnregisterListener(windowChangeListeners_[GetPersistentId()], listener); +} + +template +EnableIfSame>> WindowSessionImpl::GetListeners() +{ + std::vector> lifecycleListeners; + { + std::lock_guard lock(globalMutex_); + for (auto& listener : lifecycleListeners_[GetPersistentId()]) { + lifecycleListeners.push_back(listener); + } + } + return lifecycleListeners; +} + +template +EnableIfSame>> WindowSessionImpl::GetListeners() +{ + std::vector> windowChangeListeners; + { + std::lock_guard lock(globalMutex_); + for (auto& listener : windowChangeListeners_[GetPersistentId()]) { + windowChangeListeners.push_back(listener); + } + } + return windowChangeListeners; +} + +template +WMError WindowSessionImpl::RegisterListener(std::vector>& holder, const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + if (std::find(holder.begin(), holder.end(), listener) != holder.end()) { + WLOGFE("Listener already registered"); + return WMError::WM_OK; + } + holder.emplace_back(listener); + return WMError::WM_OK; +} + +template +WMError WindowSessionImpl::UnregisterListener(std::vector>& holder, const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return WMError::WM_ERROR_NULLPTR; + } + holder.erase(std::remove_if(holder.begin(), holder.end(), + [listener](sptr registeredListener) { + return registeredListener == listener; + }), holder.end()); + return WMError::WM_OK; +} + +template +void WindowSessionImpl::ClearUselessListeners(std::map& listeners, uint64_t persistentId) +{ + listeners.erase(persistentId); +} + +void WindowSessionImpl::ClearListenersById(uint64_t persistentId) +{ + std::lock_guard lock(globalMutex_); + ClearUselessListeners(lifecycleListeners_, persistentId); + ClearUselessListeners(windowChangeListeners_, persistentId); +} + +void WindowSessionImpl::NotifyAfterForeground(bool needNotifyListeners, bool needNotifyUiContent) +{ + if (needNotifyListeners) { + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterForeground, lifecycleListeners); + } + if (needNotifyUiContent) { + CALL_UI_CONTENT(Foreground); + } +} + +void WindowSessionImpl::NotifyAfterBackground(bool needNotifyListeners, bool needNotifyUiContent) +{ + if (needNotifyListeners) { + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterBackground, lifecycleListeners); + } + if (needNotifyUiContent) { + CALL_UI_CONTENT(Background); + } +} + +void WindowSessionImpl::NotifyAfterFocused() +{ + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterFocused, lifecycleListeners); + CALL_UI_CONTENT(Focus); +} + +void WindowSessionImpl::NotifyAfterUnfocused(bool needNotifyUiContent) +{ + auto lifecycleListeners = GetListeners(); + // use needNotifyUinContent to separate ui content callbacks + CALL_LIFECYCLE_LISTENER(AfterUnfocused, lifecycleListeners); + if (needNotifyUiContent) { + CALL_UI_CONTENT(UnFocus); + } +} + +void WindowSessionImpl::NotifyBeforeDestroy(std::string windowName) +{ + std::lock_guard lock(mutex_); + if (uiContent_ != nullptr) { + auto uiContent = std::move(uiContent_); + uiContent_ = nullptr; + uiContent->Destroy(); + } + if (notifyNativefunc_) { + notifyNativefunc_(windowName); + } +} + +void WindowSessionImpl::NotifyAfterActive() +{ + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterActive, lifecycleListeners); +} + +void WindowSessionImpl::NotifyAfterInactive() +{ + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER(AfterInactive, lifecycleListeners); +} + +void WindowSessionImpl::NotifyForegroundFailed(WMError ret) +{ + auto lifecycleListeners = GetListeners(); + CALL_LIFECYCLE_LISTENER_WITH_PARAM(ForegroundFailed, lifecycleListeners, static_cast(ret)); +} + +void WindowSessionImpl::NotifySizeChange(Rect rect, WindowSizeChangeReason reason) +{ + auto windowChangeListeners = GetListeners(); + for (auto& listener : windowChangeListeners) { + if (listener.GetRefPtr() != nullptr) { + listener.GetRefPtr()->OnSizeChange(rect, reason); + } + } +} + +void WindowSessionImpl::NotifyPointerEvent(const std::shared_ptr& pointerEvent) +{ + if (uiContent_) { + uiContent_->ProcessPointerEvent(pointerEvent); + } +} + +void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& keyEvent) +{ + if (uiContent_) { + uiContent_->ProcessKeyEvent(keyEvent); + } +} + +void WindowSessionImpl::RequestVsync(const std::shared_ptr& vsyncCallback) +{ + std::lock_guard lock(mutex_); + if (state_ == WindowState::STATE_DESTROYED) { + WLOGFE("Receive vsync request failed, window is destroyed"); + return; + } + VsyncStation::GetInstance().RequestVsync(vsyncCallback); + return; +} +} // namespace Rosen +} // namespace OHOS + -- Gitee