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_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H 18 19 #include "wm/window.h" 20 #include "adapter/ohos/entrance/platform_event_callback.h" 21 #include "base/resource/asset_manager.h" 22 #include "base/subwindow/subwindow.h" 23 #include "base/subwindow/subwindow_manager.h" 24 #include "base/thread/task_executor.h" 25 #include "core/common/ace_view.h" 26 #include "core/common/js_message_dispatcher.h" 27 #include "core/components/dialog/dialog_properties.h" 28 #include "core/components/select_popup/select_popup_component.h" 29 #include "core/components/stack/stack_element.h" 30 #include "core/components/tween/tween_component.h" 31 #include "core/components_ng/base/frame_node.h" 32 #include "core/pipeline_ng/pipeline_context.h" 33 #include "event_handler.h" 34 #include "event_runner.h" 35 #include "resource_manager.h" 36 #include "core/components_ng/pattern/overlay/overlay_manager.h" 37 38 namespace OHOS::Rosen { 39 class Window; 40 class WindowOption; 41 class RSUIDirector; 42 } // namespace OHOS::Rosen 43 44 namespace OHOS::Ace { 45 46 class SubwindowOhos : public Subwindow { 47 DECLARE_ACE_TYPE(SubwindowOhos, Subwindow) 48 49 public: 50 explicit SubwindowOhos(int32_t instanceId); 51 ~SubwindowOhos() = default; 52 53 void InitContainer() override; 54 void ResizeWindow() override; 55 void ShowMenu(const RefPtr<Component>& newComponent) override; 56 void ShowMenuNG(const RefPtr<NG::FrameNode> menuNode, int32_t targetId, const NG::OffsetF& offset) override; 57 void HideMenuNG(int32_t targetId) override; 58 void HideMenuNG() override; 59 void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true) override; 60 void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo) override; 61 void HidePopupNG(int32_t targetId) override; 62 void HidePopupNG() override; 63 bool CancelPopup(const std::string& id) override; 64 void CloseMenu() override; 65 void ClearMenu() override; 66 void ClearMenuNG() override; 67 RefPtr<NG::FrameNode> ShowDialogNG( 68 const DialogProperties& dialogProps, const RefPtr<NG::UINode>& customNode) override; 69 void HideSubWindowNG() override; 70 71 void SetHotAreas(const std::vector<Rect>& rects) override; 72 73 void ShowToast(const std::string& message, int32_t duration, const std::string& bottom) override; 74 void ShowDialog(const std::string& title, const std::string& message, 75 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 76 const std::set<std::string>& callbacks) override; 77 void ShowActionMenu(const std::string& title, 78 const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback) override; 79 void CloseDialog(int32_t instanceId) override; GetChildContainerId()80 int32_t GetChildContainerId() const 81 { 82 return childContainerId_; 83 } GetDialogWindow()84 sptr<OHOS::Rosen::Window> GetDialogWindow() const 85 { 86 return dialogWindow_; 87 } IsToastWindow()88 bool IsToastWindow() const 89 { 90 return isToastWindow_; 91 } SetIsToastWindow(bool isToastWindow)92 void SetIsToastWindow(bool isToastWindow) 93 { 94 isToastWindow_ = isToastWindow; 95 } 96 97 private: 98 RefPtr<StackElement> GetStack(); 99 void AddMenu(const RefPtr<Component>& newComponent); 100 void ShowWindow(); 101 void HideWindow(); 102 103 // Convert Rect to Rosen::Rect 104 void RectConverter(const Rect& rect, Rosen::Rect& rosenRect); 105 106 bool CreateEventRunner(); 107 void GetToastDialogWindowProperty( 108 int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const; 109 bool InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast = false); 110 bool InitToastDialogView(int32_t width, int32_t height, float density); 111 void ShowToastForAbility(const std::string& message, int32_t duration, const std::string& bottom); 112 void ShowToastForService(const std::string& message, int32_t duration, const std::string& bottom); 113 void ShowDialogForAbility(const std::string& title, const std::string& message, 114 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 115 const std::set<std::string>& callbacks); 116 void ShowDialogForService(const std::string& title, const std::string& message, 117 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 118 const std::set<std::string>& callbacks); 119 void ShowActionMenuForAbility(const std::string& title, const std::vector<ButtonInfo>& button, 120 std::function<void(int32_t, int32_t)>&& callback); 121 void ShowActionMenuForService(const std::string& title, const std::vector<ButtonInfo>& button, 122 std::function<void(int32_t, int32_t)>&& callback); 123 124 static int32_t id_; 125 int32_t windowId_ = 0; 126 int32_t parentContainerId_ = -1; 127 int32_t childContainerId_ = -1; 128 std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUiDirector; 129 sptr<OHOS::Rosen::Window> window_ = nullptr; 130 RefPtr<SelectPopupComponent> popup_; 131 132 sptr<OHOS::Rosen::Window> dialogWindow_; 133 std::shared_ptr<AppExecFwk::EventRunner> eventLoop_; 134 std::shared_ptr<AppExecFwk::EventHandler> handler_; 135 int32_t targetId_ = -1; 136 bool isToastWindow_ = false; 137 int32_t popupTargetId_ = -1; 138 bool isShowed_ = false; 139 }; 140 141 } // namespace OHOS::Ace 142 143 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H 144