1 /* 2 * Copyright (c) 2021 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_CORE_COMMON_CONTAINER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_H 18 19 #include "base/memory/ace_type.h" 20 #include "base/resource/asset_manager.h" 21 #include "base/resource/shared_image_manager.h" 22 #include "base/thread/task_executor.h" 23 #include "base/utils/macros.h" 24 #include "base/utils/noncopyable.h" 25 #include "core/common/frontend.h" 26 #include "core/common/platform_res_register.h" 27 #include "core/common/settings.h" 28 #include "core/common/window.h" 29 #include "core/pipeline/pipeline_context.h" 30 31 namespace OHOS::Ace { 32 33 using PageTask = std::function<void()>; 34 using TouchEventCallback = std::function<void(const TouchEvent&)>; 35 using KeyEventCallback = std::function<bool(const KeyEvent&)>; 36 using MouseEventCallback = std::function<void(const MouseEvent&)>; 37 using AxisEventCallback = std::function<void(const AxisEvent&)>; 38 using RotationEventCallBack = std::function<bool(const RotationEvent&)>; 39 using CardViewPositionCallBack = std::function<void(int id, float offsetX, float offsetY)>; 40 using DragEventCallBack = std::function<void(int32_t x, int32_t y, const DragEventAction& action)>; 41 42 constexpr int32_t INSTANCE_ID_UNDEFINED = -1; 43 constexpr int32_t INSTANCE_ID_PLATFORM = -2; 44 45 class ACE_FORCE_EXPORT_WITH_PREVIEW Container : public virtual AceType { 46 DECLARE_ACE_TYPE(Container, AceType); 47 48 public: 49 Container() = default; 50 ~Container() override = default; 51 52 virtual void Initialize() = 0; 53 54 virtual void Destroy() = 0; 55 DestroyView()56 virtual void DestroyView() {} 57 58 // Get the instance id of this container 59 virtual int32_t GetInstanceId() const = 0; 60 61 // Get the ability name of this container 62 virtual std::string GetHostClassName() const = 0; 63 64 // Get the frontend of container 65 virtual RefPtr<Frontend> GetFrontend() const = 0; 66 67 // Get task executor. 68 virtual RefPtr<TaskExecutor> GetTaskExecutor() const = 0; 69 70 // Get assert manager. 71 virtual RefPtr<AssetManager> GetAssetManager() const = 0; 72 73 // Get platform resource register. 74 virtual RefPtr<PlatformResRegister> GetPlatformResRegister() const = 0; 75 76 // Get the pipelineContext of container. 77 virtual RefPtr<PipelineContext> GetPipelineContext() const = 0; 78 79 // Dump container. 80 virtual bool Dump(const std::vector<std::string>& params) = 0; 81 82 // Get the width/height of the view 83 virtual int32_t GetViewWidth() const = 0; 84 virtual int32_t GetViewHeight() const = 0; 85 virtual void* GetView() const = 0; 86 87 // Trigger garbage collection TriggerGarbageCollection()88 virtual void TriggerGarbageCollection() {} 89 NotifyFontNodes()90 virtual void NotifyFontNodes() {} 91 NotifyAppStorage(const std::string & key,const std::string & value)92 virtual void NotifyAppStorage(const std::string& key, const std::string& value) {} 93 94 // Get MutilModal ptr. GetMutilModalPtr()95 virtual uintptr_t GetMutilModalPtr() const 96 { 97 return 0; 98 } 99 ProcessScreenOnEvents()100 virtual void ProcessScreenOnEvents() {} 101 ProcessScreenOffEvents()102 virtual void ProcessScreenOffEvents() {} 103 SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)104 void SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time) 105 { 106 createTime_ = time; 107 } 108 IsFirstUpdate()109 bool IsFirstUpdate() 110 { 111 return firstUpdateData_; 112 } 113 AlreadyFirstUpdate()114 void AlreadyFirstUpdate() 115 { 116 firstUpdateData_ = false; 117 } 118 SetModuleName(const std::string & moduleName)119 void SetModuleName(const std::string& moduleName) 120 { 121 moduleName_ = moduleName; 122 } 123 GetModuleName()124 std::string GetModuleName() const 125 { 126 return moduleName_; 127 } 128 IsMainWindow()129 virtual bool IsMainWindow() const 130 { 131 return false; 132 } 133 IsSubContainer()134 virtual bool IsSubContainer() const 135 { 136 return false; 137 } 138 GetCardHapPath()139 const std::string& GetCardHapPath() const 140 { 141 return cardHapPath_; 142 } 143 GetSettings()144 Settings& GetSettings() 145 { 146 return settings_; 147 } 148 SetBundlePath(const std::string & path)149 void SetBundlePath(const std::string& path) { 150 bundlePath_ = path; 151 } 152 GetBundlePath()153 const std::string& GetBundlePath() const { 154 return bundlePath_; 155 } 156 SetFilesDataPath(const std::string & path)157 void SetFilesDataPath(const std::string& path) { 158 filesDataPath_ = path; 159 } 160 GetFilesDataPath()161 const std::string& GetFilesDataPath() const { 162 return filesDataPath_; 163 } 164 SetViewFirstUpdating(std::chrono::time_point<std::chrono::high_resolution_clock> time)165 virtual void SetViewFirstUpdating(std::chrono::time_point<std::chrono::high_resolution_clock> time) {} 166 UpdateResourceConfiguration(const std::string & jsonStr)167 virtual void UpdateResourceConfiguration(const std::string& jsonStr) {} 168 169 static int32_t CurrentId(); 170 static RefPtr<Container> Current(); 171 static RefPtr<TaskExecutor> CurrentTaskExecutor(); 172 static void UpdateCurrent(int32_t id); 173 174 protected: 175 std::chrono::time_point<std::chrono::high_resolution_clock> createTime_; 176 bool firstUpdateData_ = true; 177 std::string cardHapPath_; 178 179 private: 180 std::string moduleName_; 181 std::string bundlePath_; 182 std::string filesDataPath_; 183 Settings settings_; 184 ACE_DISALLOW_COPY_AND_MOVE(Container); 185 }; 186 187 } // namespace OHOS::Ace 188 189 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_H 190