• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_SUBWINDOW_SUBWINDOW_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_SUBWINDOW_SUBWINDOW_H
18 
19 #include <set>
20 
21 #include "base/geometry/ng/rect_t.h"
22 #include "base/memory/ace_type.h"
23 #include "base/memory/referenced.h"
24 #include "core/components/dialog/dialog_properties.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/pattern/overlay/overlay_manager.h"
27 #include "core/pipeline/base/component.h"
28 
29 namespace OHOS::Ace {
30 
31 class ACE_EXPORT Subwindow : public AceType {
32     DECLARE_ACE_TYPE(Subwindow, AceType)
33 
34 public:
35     static RefPtr<Subwindow> CreateSubwindow(int32_t instanceId);
36 
37     virtual void InitContainer() = 0;
38     virtual void ResizeWindow() = 0;
39     virtual NG::RectF GetRect() = 0;
40     virtual void ShowMenu(const RefPtr<Component>& newComponent) = 0;
41     virtual void ShowMenuNG(const RefPtr<NG::FrameNode> menuNode, int32_t targetId, const NG::OffsetF& offset) = 0;
42     virtual bool ShowPreviewNG() = 0;
43     virtual void HidePreviewNG() = 0;
44     virtual void HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId) = 0;
45     virtual void HideMenuNG(bool showPreviewAnimation = true, bool startDrag = false) = 0;
46     virtual void UpdateHideMenuOffsetNG(const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f)) = 0;
47     virtual void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true) = 0;
48     virtual void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo) = 0;
49     virtual void HidePopupNG(int32_t targetId) = 0;
50     virtual void GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo) = 0;
51     virtual bool CancelPopup(const std::string& id) = 0;
52     virtual void CloseMenu() = 0;
ClearMenu()53     virtual void ClearMenu() {};
54     virtual void ClearMenuNG(bool inWindow = true, bool showAnimation = false) = 0;
55     virtual void ClearPopupNG() = 0;
56     virtual RefPtr<NG::FrameNode> ShowDialogNG(
57         const DialogProperties& dialogProps, std::function<void()>&& buildFunc) = 0;
58     virtual void CloseDialogNG(const RefPtr<NG::FrameNode>& dialogNode) = 0;
59     virtual void HideSubWindowNG() = 0;
60     virtual int32_t GetChildContainerId() const = 0;
61     virtual bool GetShown() = 0;
62 
63     // Add interface for hot regions
SetHotAreas(const std::vector<Rect> & rects,int32_t overlayId)64     virtual void SetHotAreas(const std::vector<Rect>& rects, int32_t overlayId) {};
SetDialogHotAreas(const std::vector<Rect> & rects,int32_t overlayId)65     virtual void SetDialogHotAreas(const std::vector<Rect>& rects, int32_t overlayId) {};
DeleteHotAreas(int32_t overlayId)66     virtual void DeleteHotAreas(int32_t overlayId) {};
67 
68     // Add interface to provide the size and offset of the parent window
69     virtual Rect GetParentWindowRect() const = 0;
70 
GetSubwindowId()71     int32_t GetSubwindowId() const
72     {
73         return subwindowId_;
74     }
75 
SetSubwindowId(int32_t id)76     void SetSubwindowId(int32_t id)
77     {
78         subwindowId_ = id;
79     }
80 
SetAboveApps(bool isAboveApps)81     void SetAboveApps(bool isAboveApps)
82     {
83         isAboveApps_ = isAboveApps;
84     }
85 
GetAboveApps()86     bool GetAboveApps() const
87     {
88         return isAboveApps_;
89     }
90 
91     virtual void ClearToast() = 0;
92     virtual void ShowToast(
93         const std::string& message, int32_t duration, const std::string& bottom, const NG::ToastShowMode& showMode) = 0;
94     virtual void ShowDialog(const std::string& title, const std::string& message,
95         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
96         const std::set<std::string>& callbacks) = 0;
97     virtual void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
98         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) = 0;
99     virtual void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
100         std::function<void(int32_t, int32_t)>&& callback) = 0;
101     virtual void CloseDialog(int32_t instanceId) = 0;
102     virtual void OpenCustomDialog(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) = 0;
103     virtual void CloseCustomDialog(const int32_t dialogId) = 0;
104     virtual const RefPtr<NG::OverlayManager> GetOverlayManager() = 0;
105     virtual bool IsFocused() = 0;
106     virtual void RequestFocus() = 0;
107     virtual void ResizeWindowForFoldStatus() = 0;
108 private:
109     int32_t subwindowId_ = 0;
110     bool isAboveApps_ = false;
111 };
112 
113 } // namespace OHOS::Ace
114 
115 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_SUBWINDOW_SUBWINDOW_H
116