1 /* 2 * Copyright (c) 2021-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_ACE_UI_CONTENT_IMPL_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H 18 19 #include "ability_info.h" 20 #include "core/common/flutter/flutter_asset_manager.h" 21 #include "interfaces/inner_api/ace/ui_content.h" 22 #include "interfaces/inner_api/ace/viewport_config.h" 23 #include "key_event.h" 24 #include "native_engine/native_value.h" 25 #include "native_engine/native_engine.h" 26 27 #include "base/utils/macros.h" 28 #include "wm/window.h" 29 30 namespace OHOS { 31 32 class Window; 33 34 } // namespace OHOS 35 36 namespace OHOS::Ace { 37 38 class ACE_FORCE_EXPORT UIContentImpl : public UIContent { 39 public: 40 UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime); 41 UIContentImpl(OHOS::AppExecFwk::Ability* ability); 42 UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard); ~UIContentImpl()43 ~UIContentImpl() 44 { 45 DestroyUIDirector(); 46 DestroyCallback(); 47 } 48 49 // UI content lifecycles 50 void Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) override; 51 void Foreground() override; 52 void Background() override; 53 void Focus() override; 54 void UnFocus() override; 55 void Destroy() override; 56 void OnNewWant(const OHOS::AAFwk::Want& want) override; 57 58 // distribute 59 void Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) override; 60 std::string GetContentInfo() const override; 61 void DestroyUIDirector() override; 62 63 // UI content event process 64 bool ProcessBackPressed() override; 65 bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 66 bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override; 67 bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 68 bool ProcessVsyncEvent(uint64_t timeStampNanos) override; 69 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override; 70 void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason) override; 71 void UpdateWindowMode(OHOS::Rosen::WindowMode mode) override; 72 void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) override; 73 74 // Window color 75 uint32_t GetBackgroundColor() override; 76 void SetBackgroundColor(uint32_t color) override; 77 78 void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override; 79 80 // Set UIContent callback for custom window animation 81 void SetNextFrameLayoutCallback(std::function<void()>&& callback) override; 82 83 // Receive memory level notification 84 void NotifyMemoryLevel(int32_t level) override; 85 86 void SetAppWindowTitle(const std::string& title) override; 87 void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) override; 88 89 // ArkTS Form 90 std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override; 91 void UpdateFormData(const std::string& data) override; 92 void UpdateFormSharedImage( 93 const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override; 94 void ReloadForm() override; 95 SetFormWidth(float width)96 void SetFormWidth(float width) override 97 { 98 formWidth_ = width; 99 } SetFormHeight(float height)100 void SetFormHeight(float height) override 101 { 102 formHeight_ = height; 103 } GetFormWidth()104 float GetFormWidth() override 105 { 106 return formWidth_; 107 } GetFormHeight()108 float GetFormHeight() override 109 { 110 return formHeight_; 111 } 112 113 void SetActionEventHandler( 114 std::function<void(const std::string& action)>&& actionCallback) override; 115 void SetErrorEventHandler( 116 std::function<void(const std::string&, const std::string&)>&& errorCallback) override; 117 118 void OnFormSurfaceChange(float width, float height) override; 119 120 private: 121 void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage); 122 void CommonInitializeForm(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage); 123 void InitializeSubWindow(OHOS::Rosen::Window* window, bool isDialog = false); 124 void DestroyCallback() const; 125 void SetConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config); 126 127 std::weak_ptr<OHOS::AbilityRuntime::Context> context_; 128 void* runtime_ = nullptr; 129 OHOS::Rosen::Window* window_ = nullptr; 130 std::string startUrl_; 131 int32_t instanceId_ = -1; 132 OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr; 133 OHOS::sptr<OHOS::Rosen::IOccupiedAreaChangeListener> occupiedAreaChangeListener_ = nullptr; 134 135 // ITouchOutsideListener is used for touching out of hot areas of window. 136 OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr; 137 138 // ArkTS Form 139 bool isFormRender_ = false; 140 bool isFormRenderInit_ = false; 141 std::string bundleName_; 142 std::string moduleName_; 143 bool isBundle_ = false; 144 int32_t minCompatibleVersionCode_ = 0; 145 float formWidth_ = 0.0; 146 float formHeight_ = 0.0; 147 std::string formData_; 148 std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>> formImageDataMap_; 149 }; 150 151 } // namespace OHOS::Ace 152 153 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H 154