123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci#include <unordered_map>
2023b3eb3cSopenharmony_ci
2123b3eb3cSopenharmony_ci#include "event_handler.h"
2223b3eb3cSopenharmony_ci#include "event_runner.h"
2323b3eb3cSopenharmony_ci#include "resource_manager.h"
2423b3eb3cSopenharmony_ci#include "wm/window.h"
2523b3eb3cSopenharmony_ci
2623b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/platform_event_callback.h"
2723b3eb3cSopenharmony_ci#include "base/resource/asset_manager.h"
2823b3eb3cSopenharmony_ci#include "base/subwindow/subwindow.h"
2923b3eb3cSopenharmony_ci#include "base/subwindow/subwindow_manager.h"
3023b3eb3cSopenharmony_ci#include "base/thread/task_executor.h"
3123b3eb3cSopenharmony_ci#include "core/common/ace_view.h"
3223b3eb3cSopenharmony_ci#include "core/common/js_message_dispatcher.h"
3323b3eb3cSopenharmony_ci#include "core/components/dialog/dialog_properties.h"
3423b3eb3cSopenharmony_ci#include "core/components/select_popup/select_popup_component.h"
3523b3eb3cSopenharmony_ci#include "core/components/stack/stack_element.h"
3623b3eb3cSopenharmony_ci#include "core/components/tween/tween_component.h"
3723b3eb3cSopenharmony_ci#include "core/components_ng/base/frame_node.h"
3823b3eb3cSopenharmony_ci#include "core/components_ng/pattern/overlay/overlay_manager.h"
3923b3eb3cSopenharmony_ci#include "core/pipeline/pipeline_base.h"
4023b3eb3cSopenharmony_ci#include "core/pipeline_ng/pipeline_context.h"
4123b3eb3cSopenharmony_ci
4223b3eb3cSopenharmony_cinamespace OHOS::Rosen {
4323b3eb3cSopenharmony_ciclass Window;
4423b3eb3cSopenharmony_ciclass WindowOption;
4523b3eb3cSopenharmony_ciclass RSUIDirector;
4623b3eb3cSopenharmony_ci} // namespace OHOS::Rosen
4723b3eb3cSopenharmony_ci
4823b3eb3cSopenharmony_cinamespace OHOS::Ace {
4923b3eb3cSopenharmony_ci
5023b3eb3cSopenharmony_ciclass SubwindowOhos : public Subwindow {
5123b3eb3cSopenharmony_ci    DECLARE_ACE_TYPE(SubwindowOhos, Subwindow)
5223b3eb3cSopenharmony_ci
5323b3eb3cSopenharmony_cipublic:
5423b3eb3cSopenharmony_ci    explicit SubwindowOhos(int32_t instanceId);
5523b3eb3cSopenharmony_ci    ~SubwindowOhos() = default;
5623b3eb3cSopenharmony_ci
5723b3eb3cSopenharmony_ci    bool InitContainer() override;
5823b3eb3cSopenharmony_ci    void ResizeWindow() override;
5923b3eb3cSopenharmony_ci    NG::RectF GetRect() override;
6023b3eb3cSopenharmony_ci    void SetRect(const NG::RectF& rect) override;
6123b3eb3cSopenharmony_ci    void ShowMenu(const RefPtr<Component>& newComponent) override;
6223b3eb3cSopenharmony_ci    void ShowMenuNG(const RefPtr<NG::FrameNode> customNode, const NG::MenuParam& menuParam,
6323b3eb3cSopenharmony_ci        const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) override;
6423b3eb3cSopenharmony_ci    void ShowMenuNG(std::function<void()>&& buildFunc, std::function<void()>&& previewBuildFunc,
6523b3eb3cSopenharmony_ci        const NG::MenuParam& menuParam, const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) override;
6623b3eb3cSopenharmony_ci    bool ShowPreviewNG(bool isStartDraggingFromSubWindow = false) override;
6723b3eb3cSopenharmony_ci    void HidePreviewNG() override;
6823b3eb3cSopenharmony_ci    void HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId) override;
6923b3eb3cSopenharmony_ci    void HideMenuNG(bool showPreviewAnimation, bool startDrag) override;
7023b3eb3cSopenharmony_ci    void UpdateHideMenuOffsetNG(
7123b3eb3cSopenharmony_ci        const NG::OffsetF& offset, float menuScale, bool isRedragStart, int32_t menuWrapperId = -1) override;
7223b3eb3cSopenharmony_ci    void ContextMenuSwitchDragPreviewAnimationtNG(const RefPtr<NG::FrameNode>& dragPreviewNode,
7323b3eb3cSopenharmony_ci        const NG::OffsetF& offset) override;
7423b3eb3cSopenharmony_ci    void UpdatePreviewPosition() override;
7523b3eb3cSopenharmony_ci    bool GetMenuPreviewCenter(NG::OffsetF& offset) override;
7623b3eb3cSopenharmony_ci    void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true) override;
7723b3eb3cSopenharmony_ci    void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo,
7823b3eb3cSopenharmony_ci        const std::function<void(int32_t)>&& onWillDismiss = nullptr, bool interactiveDismiss = true) override;
7923b3eb3cSopenharmony_ci    void HidePopupNG(int32_t targetId) override;
8023b3eb3cSopenharmony_ci    void GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo) override;
8123b3eb3cSopenharmony_ci    bool CancelPopup(const std::string& id) override;
8223b3eb3cSopenharmony_ci    void CloseMenu() override;
8323b3eb3cSopenharmony_ci    void ClearMenu() override;
8423b3eb3cSopenharmony_ci    void ClearMenuNG(int32_t targetId, bool inWindow, bool showAnimation = false) override;
8523b3eb3cSopenharmony_ci    void ClearPopupNG() override;
8623b3eb3cSopenharmony_ci    RefPtr<NG::FrameNode> ShowDialogNG(const DialogProperties& dialogProps, std::function<void()>&& buildFunc) override;
8723b3eb3cSopenharmony_ci    RefPtr<NG::FrameNode> ShowDialogNGWithNode(const DialogProperties& dialogProps,
8823b3eb3cSopenharmony_ci        const RefPtr<NG::UINode>& customNode) override;
8923b3eb3cSopenharmony_ci    void CloseDialogNG(const RefPtr<NG::FrameNode>& dialogNode) override;
9023b3eb3cSopenharmony_ci    void OpenCustomDialogNG(const DialogProperties& dialogProps, std::function<void(int32_t)>&& callback) override;
9123b3eb3cSopenharmony_ci    void CloseCustomDialogNG(int32_t dialogId) override;
9223b3eb3cSopenharmony_ci    void CloseCustomDialogNG(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) override;
9323b3eb3cSopenharmony_ci    void UpdateCustomDialogNG(const WeakPtr<NG::UINode>& node, const DialogProperties& dialogProps,
9423b3eb3cSopenharmony_ci        std::function<void(int32_t)>&& callback) override;
9523b3eb3cSopenharmony_ci    void HideSubWindowNG() override;
9623b3eb3cSopenharmony_ci    bool GetShown() override
9723b3eb3cSopenharmony_ci    {
9823b3eb3cSopenharmony_ci        return isShowed_;
9923b3eb3cSopenharmony_ci    }
10023b3eb3cSopenharmony_ci
10123b3eb3cSopenharmony_ci    void SetHotAreas(const std::vector<Rect>& rects, int32_t nodeId) override;
10223b3eb3cSopenharmony_ci    void DeleteHotAreas(int32_t nodeId) override;
10323b3eb3cSopenharmony_ci    void ClearToast() override;
10423b3eb3cSopenharmony_ci    void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) override;
10523b3eb3cSopenharmony_ci    void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback) override;
10623b3eb3cSopenharmony_ci    void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
10723b3eb3cSopenharmony_ci        bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
10823b3eb3cSopenharmony_ci        const std::set<std::string>& callbacks) override;
10923b3eb3cSopenharmony_ci    void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
11023b3eb3cSopenharmony_ci        std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) override;
11123b3eb3cSopenharmony_ci    void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
11223b3eb3cSopenharmony_ci        std::function<void(int32_t, int32_t)>&& callback) override;
11323b3eb3cSopenharmony_ci    void CloseDialog(int32_t instanceId) override;
11423b3eb3cSopenharmony_ci    void OpenCustomDialog(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) override;
11523b3eb3cSopenharmony_ci    void CloseCustomDialog(const int32_t dialogId) override;
11623b3eb3cSopenharmony_ci    void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) override;
11723b3eb3cSopenharmony_ci    const RefPtr<NG::OverlayManager> GetOverlayManager() override;
11823b3eb3cSopenharmony_ci
11923b3eb3cSopenharmony_ci    int32_t GetChildContainerId() const override
12023b3eb3cSopenharmony_ci    {
12123b3eb3cSopenharmony_ci        return childContainerId_;
12223b3eb3cSopenharmony_ci    }
12323b3eb3cSopenharmony_ci    sptr<OHOS::Rosen::Window> GetDialogWindow() const
12423b3eb3cSopenharmony_ci    {
12523b3eb3cSopenharmony_ci        return dialogWindow_;
12623b3eb3cSopenharmony_ci    }
12723b3eb3cSopenharmony_ci    bool IsToastWindow() const
12823b3eb3cSopenharmony_ci    {
12923b3eb3cSopenharmony_ci        return isToastWindow_;
13023b3eb3cSopenharmony_ci    }
13123b3eb3cSopenharmony_ci    void SetIsToastWindow(bool isToastWindow)
13223b3eb3cSopenharmony_ci    {
13323b3eb3cSopenharmony_ci        isToastWindow_ = isToastWindow;
13423b3eb3cSopenharmony_ci    }
13523b3eb3cSopenharmony_ci
13623b3eb3cSopenharmony_ci    void UpdateAceView(int32_t width, int32_t height, float density, int32_t containerId);
13723b3eb3cSopenharmony_ci
13823b3eb3cSopenharmony_ci    // Gets parent window's size and offset
13923b3eb3cSopenharmony_ci    Rect GetParentWindowRect() const override;
14023b3eb3cSopenharmony_ci    Rect GetUIExtensionHostWindowRect() const override;
14123b3eb3cSopenharmony_ci    NG::RectF GetWindowRect() const override;
14223b3eb3cSopenharmony_ci    bool IsFreeMultiWindow() const override;
14323b3eb3cSopenharmony_ci    void OnFreeMultiWindowSwitch(bool enable) override;
14423b3eb3cSopenharmony_ci    int32_t RegisterFreeMultiWindowSwitchCallback(std::function<void(bool)>&& callback) override;
14523b3eb3cSopenharmony_ci    void UnRegisterFreeMultiWindowSwitchCallback(int32_t callbackId) override;
14623b3eb3cSopenharmony_ci
14723b3eb3cSopenharmony_ci    bool IsFocused() override;
14823b3eb3cSopenharmony_ci    void RequestFocus() override;
14923b3eb3cSopenharmony_ci    const sptr<OHOS::Rosen::Window>& GetSubWindow() const
15023b3eb3cSopenharmony_ci    {
15123b3eb3cSopenharmony_ci        return window_;
15223b3eb3cSopenharmony_ci    }
15323b3eb3cSopenharmony_ci    void ResizeWindowForFoldStatus() override;
15423b3eb3cSopenharmony_ci    void ResizeWindowForFoldStatus(int32_t parentContainerId) override;
15523b3eb3cSopenharmony_ci    void MarkDirtyDialogSafeArea() override;
15623b3eb3cSopenharmony_ci
15723b3eb3cSopenharmony_ci    bool Close() override;
15823b3eb3cSopenharmony_ci    bool IsToastSubWindow() override;
15923b3eb3cSopenharmony_ci    void DestroyWindow() override;
16023b3eb3cSopenharmony_ci
16123b3eb3cSopenharmony_ciprivate:
16223b3eb3cSopenharmony_ci    RefPtr<StackElement> GetStack();
16323b3eb3cSopenharmony_ci    void AddMenu(const RefPtr<Component>& newComponent);
16423b3eb3cSopenharmony_ci    void ShowWindow(bool needFocus = true);
16523b3eb3cSopenharmony_ci    void HideWindow();
16623b3eb3cSopenharmony_ci
16723b3eb3cSopenharmony_ci    // Convert Rect to Rosen::Rect
16823b3eb3cSopenharmony_ci    void RectConverter(const Rect& rect, Rosen::Rect& rosenRect);
16923b3eb3cSopenharmony_ci
17023b3eb3cSopenharmony_ci    bool CreateEventRunner();
17123b3eb3cSopenharmony_ci    void GetToastDialogWindowProperty(
17223b3eb3cSopenharmony_ci        int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const;
17323b3eb3cSopenharmony_ci    bool InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast = false);
17423b3eb3cSopenharmony_ci    bool InitToastDialogView(int32_t width, int32_t height, float density);
17523b3eb3cSopenharmony_ci    bool InitToastServiceConfig();
17623b3eb3cSopenharmony_ci    void ShowToastForAbility(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback);
17723b3eb3cSopenharmony_ci    void ShowToastForService(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback);
17823b3eb3cSopenharmony_ci    void ShowDialogForAbility(const std::string& title, const std::string& message,
17923b3eb3cSopenharmony_ci        const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
18023b3eb3cSopenharmony_ci        const std::set<std::string>& callbacks);
18123b3eb3cSopenharmony_ci    void ShowDialogForService(const std::string& title, const std::string& message,
18223b3eb3cSopenharmony_ci        const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
18323b3eb3cSopenharmony_ci        const std::set<std::string>& callbacks);
18423b3eb3cSopenharmony_ci    void ShowDialogForAbility(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
18523b3eb3cSopenharmony_ci        std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks);
18623b3eb3cSopenharmony_ci    void ShowDialogForService(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
18723b3eb3cSopenharmony_ci        std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks);
18823b3eb3cSopenharmony_ci    void OpenCustomDialogForAbility(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback);
18923b3eb3cSopenharmony_ci    void OpenCustomDialogForService(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback);
19023b3eb3cSopenharmony_ci    void ShowActionMenuForAbility(const std::string& title, const std::vector<ButtonInfo>& button,
19123b3eb3cSopenharmony_ci        std::function<void(int32_t, int32_t)>&& callback);
19223b3eb3cSopenharmony_ci    void ShowActionMenuForService(const std::string& title, const std::vector<ButtonInfo>& button,
19323b3eb3cSopenharmony_ci        std::function<void(int32_t, int32_t)>&& callback);
19423b3eb3cSopenharmony_ci    RefPtr<PipelineBase> GetChildPipelineContext() const;
19523b3eb3cSopenharmony_ci    std::function<void()> GetInitToastDelayTask(const NG::ToastInfo& toastInfo,
19623b3eb3cSopenharmony_ci        std::function<void(int32_t)>&& callback);
19723b3eb3cSopenharmony_ci    void ContainerModalUnFocus();
19823b3eb3cSopenharmony_ci
19923b3eb3cSopenharmony_ci    void HideFilter(bool isInSubWindow);
20023b3eb3cSopenharmony_ci    void HidePixelMap(bool startDrag = false, double x = 0, double y = 0, bool showAnimation = true);
20123b3eb3cSopenharmony_ci    void HideEventColumn();
20223b3eb3cSopenharmony_ci    Rosen::WindowType GetToastRosenType(bool IsSceneBoardEnabled);
20323b3eb3cSopenharmony_ci
20423b3eb3cSopenharmony_ci    static int32_t id_;
20523b3eb3cSopenharmony_ci    int32_t windowId_ = 0;
20623b3eb3cSopenharmony_ci    int32_t parentContainerId_ = -1;
20723b3eb3cSopenharmony_ci    int32_t childContainerId_ = -1;
20823b3eb3cSopenharmony_ci    std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUiDirector;
20923b3eb3cSopenharmony_ci    sptr<OHOS::Rosen::Window> window_ = nullptr;
21023b3eb3cSopenharmony_ci    RefPtr<SelectPopupComponent> popup_;
21123b3eb3cSopenharmony_ci    std::unordered_map<int32_t, std::vector<Rosen::Rect>> hotAreasMap_;
21223b3eb3cSopenharmony_ci
21323b3eb3cSopenharmony_ci    sptr<OHOS::Rosen::Window> dialogWindow_;
21423b3eb3cSopenharmony_ci    std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
21523b3eb3cSopenharmony_ci    std::shared_ptr<AppExecFwk::EventHandler> handler_;
21623b3eb3cSopenharmony_ci    int32_t targetId_ = -1;
21723b3eb3cSopenharmony_ci    bool isToastWindow_ = false;
21823b3eb3cSopenharmony_ci    int32_t popupTargetId_ = -1;
21923b3eb3cSopenharmony_ci    bool haveDialog_ = false;
22023b3eb3cSopenharmony_ci    bool isShowed_ = false;
22123b3eb3cSopenharmony_ci    sptr<OHOS::Rosen::Window> parentWindow_ = nullptr;
22223b3eb3cSopenharmony_ci    int32_t callbackId_ = 0;
22323b3eb3cSopenharmony_ci    sptr<OHOS::Rosen::ISwitchFreeMultiWindowListener> freeMultiWindowListener_ = nullptr;
22423b3eb3cSopenharmony_ci    std::unordered_map<int32_t, std::function<void(bool)>> freeMultiWindowSwitchCallbackMap_;
22523b3eb3cSopenharmony_ci    NG::RectF windowRect_;
22623b3eb3cSopenharmony_ci};
22723b3eb3cSopenharmony_ci
22823b3eb3cSopenharmony_ci} // namespace OHOS::Ace
22923b3eb3cSopenharmony_ci
23023b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
231