1 /* 2 * Copyright (c) 2023 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_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H 17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H 18 19 #include "interfaces/inner_api/ace/ui_content.h" 20 #include "interfaces/inner_api/ace/viewport_config.h" 21 #include "native_engine/native_engine.h" 22 #include "native_engine/native_value.h" 23 #include "previewer/include/window.h" 24 25 #include "adapter/preview/entrance/ace_run_args.h" 26 #include "adapter/preview/external/ability/context.h" 27 #include "adapter/preview/external/ability/fa/fa_context.h" 28 #include "adapter/preview/external/ability/stage/stage_context.h" 29 30 namespace OHOS::Ace { 31 class ACE_FORCE_EXPORT UIContentImpl : public UIContent { 32 public: 33 UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime); 34 UIContentImpl(OHOS::AppExecFwk::Ability* ability); 35 UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard); ~UIContentImpl()36 ~UIContentImpl() 37 { 38 DestroyUIDirector(); 39 DestroyCallback(); 40 } 41 42 // UI content lifeCycles 43 UIContentErrorCode Initialize(OHOS::Rosen::Window* window, const std::string& url, napi_value storage) override; Initialize(OHOS::Rosen::Window * window,const std::shared_ptr<std::vector<uint8_t>> & content,napi_value storage)44 UIContentErrorCode Initialize(OHOS::Rosen::Window* window, 45 const std::shared_ptr<std::vector<uint8_t>>& content, napi_value storage) override { 46 return UIContentErrorCode::NO_ERRORS; 47 } 48 UIContentErrorCode InitializeByName(OHOS::Rosen::Window *window, const std::string &name, 49 napi_value storage) override; InitializeDynamic(int32_t hostInstanceId,const std::string & hapPath,const std::string & abcPath,const std::string & entryPoint,const std::vector<std::string> & registerComponents)50 void InitializeDynamic(int32_t hostInstanceId, const std::string& hapPath, const std::string& abcPath, 51 const std::string& entryPoint, const std::vector<std::string>& registerComponents) override {} Initialize(OHOS::Rosen::Window * window,const std::string & url,napi_value storage,uint32_t focusWindowId)52 void Initialize( 53 OHOS::Rosen::Window* window, const std::string& url, napi_value storage, uint32_t focusWindowId) override {} Foreground()54 void Foreground() override {} Background()55 void Background() override {} Focus()56 void Focus() override {} UnFocus()57 void UnFocus() override {} 58 void Destroy() override; OnNewWant(const OHOS::AAFwk::Want & want)59 void OnNewWant(const OHOS::AAFwk::Want& want) override {} 60 61 // restore Restore(OHOS::Rosen::Window * window,const std::string & contentInfo,napi_value storage,ContentInfoType type)62 UIContentErrorCode Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, 63 napi_value storage, ContentInfoType type) override { 64 return UIContentErrorCode::NO_ERRORS; 65 } 66 std::string GetContentInfo(ContentInfoType type) const override; 67 void DestroyUIDirector() override; 68 69 // UI content event process 70 bool ProcessBackPressed() override; 71 bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 72 bool ProcessPointerEventWithCallback( 73 const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent, const std::function<void()>& callback) override; 74 bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override; 75 bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 76 bool ProcessVsyncEvent(uint64_t timeStampNanos) override; SetIsFocusActive(bool isFocusActive)77 void SetIsFocusActive(bool isFocusActive) override {} 78 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override; 79 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config, 80 const std::shared_ptr<Global::Resource::ResourceManager>& resourceManager) override; 81 void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason, 82 const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr, 83 const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) override; 84 void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override {} 85 void UpdateDecorVisible(bool visible, bool hasDeco = true) override {}; HideWindowTitleButton(bool hideSplit,bool hideMaximize,bool hideMinimize,bool hideClose)86 void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) override {} SetIgnoreViewSafeArea(bool ignoreViewSafeArea)87 void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override {} UpdateTitleInTargetPos(bool isShow,int32_t height)88 void UpdateTitleInTargetPos(bool isShow, int32_t height) override {} 89 90 // Window color 91 uint32_t GetBackgroundColor() override; 92 void SetBackgroundColor(uint32_t color) override; 93 void SetWindowContainerColor(uint32_t activeColor, uint32_t inactiveColor) override; 94 95 void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override; 96 97 // Set UIContent callback for custom window animation 98 void SetNextFrameLayoutCallback(std::function<void()>&& callback) override; 99 100 // Receive memory level notification 101 void NotifyMemoryLevel(int32_t level) override; 102 SetAppWindowTitle(const std::string & title)103 void SetAppWindowTitle(const std::string& title) override {} SetAppWindowIcon(const std::shared_ptr<Media::PixelMap> & pixelMap)104 void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) override {} SetActionEventHandler(std::function<void (const std::string & action)> && actionCallback)105 void SetActionEventHandler(std::function<void(const std::string& action)>&& actionCallback) override {} SetErrorEventHandler(std::function<void (const std::string &,const std::string &)> && errorCallback)106 void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& errorCallback) override {} SetFormLinkInfoUpdateHandler(std::function<void (const std::vector<std::string> &)> && callback)107 void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& callback) override {} 108 109 // ArkTS Form PreInitializeForm(OHOS::Rosen::Window * window,const std::string & url,napi_value storage)110 void PreInitializeForm(OHOS::Rosen::Window* window, const std::string& url, napi_value storage) override {} RunFormPage()111 void RunFormPage() override {} 112 void OnFormSurfaceChange(float width, float height, 113 OHOS::Rosen::WindowSizeChangeReason type = static_cast<OHOS::Rosen::WindowSizeChangeReason>(0), 114 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override {} UpdateFormData(const std::string & data)115 void UpdateFormData(const std::string& data) override {} UpdateFormSharedImage(const std::map<std::string,sptr<OHOS::AppExecFwk::FormAshmem>> & imageDataMap)116 void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override 117 {} SetFormWidth(float width)118 void SetFormWidth(float width) override {} SetFormHeight(float height)119 void SetFormHeight(float height) override {} GetFormWidth()120 float GetFormWidth() override 121 { 122 return 0.0; 123 } GetFormHeight()124 float GetFormHeight() override 125 { 126 return 0.0; 127 } GetFormRootNode()128 std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override 129 { 130 return nullptr; 131 } 132 133 int32_t CreateModalUIExtension(const AAFwk::Want& want, 134 const ModalUIExtensionCallbacks& callbacks, const ModalUIExtensionConfig& config) override; 135 void CloseModalUIExtension(int32_t sessionId) override; 136 SetParentToken(sptr<IRemoteObject> token)137 void SetParentToken(sptr<IRemoteObject> token) override {} GetParentToken()138 sptr<IRemoteObject> GetParentToken() override 139 { 140 return nullptr; 141 } 142 GetFormSerializedGesture()143 SerializedGesture GetFormSerializedGesture() override 144 { 145 return SerializedGesture(); 146 } 147 UpdateTransform(const OHOS::Rosen::Transform & transform)148 void UpdateTransform(const OHOS::Rosen::Transform& transform) override {}; 149 SetContentNodeGrayScale(float grayscale)150 void SetContentNodeGrayScale(float grayscale) override {}; 151 PreLayout()152 void PreLayout() override {}; 153 154 void SetStatusBarItemColor(uint32_t color) override; 155 SetForceSplitEnable(bool isForceSplit,const std::string & homePage)156 void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) override {}; 157 EnableContainerModalGesture(bool isEnable)158 void EnableContainerModalGesture(bool isEnable) override {}; 159 GetContainerFloatingTitleVisible()160 bool GetContainerFloatingTitleVisible() override 161 { 162 return false; 163 } 164 GetContainerCustomTitleVisible()165 bool GetContainerCustomTitleVisible() override 166 { 167 return false; 168 } 169 GetContainerControlButtonVisible()170 bool GetContainerControlButtonVisible() override 171 { 172 return false; 173 } 174 UpdateSingleHandTransform(const OHOS::Rosen::SingleHandTransform & transform)175 void UpdateSingleHandTransform(const OHOS::Rosen::SingleHandTransform& transform) override {}; 176 private: 177 UIContentErrorCode InitializeInner( 178 OHOS::Rosen::Window* window, const std::string& contentInfo, napi_value storage, bool isNamedRouter); 179 UIContentErrorCode CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, 180 napi_value storage); 181 void DestroyCallback() const; 182 183 private: 184 int32_t instanceId_ = -1; 185 void* runtime_ = nullptr; 186 // All parameters that need to be passed. 187 std::string startUrl_; 188 std::string assetPath_; 189 std::string systemResourcesPath_; 190 std::string appResourcesPath_; 191 std::string containerSdkPath_; 192 std::string language_; 193 std::string region_; 194 std::string script_; 195 uint32_t themeId_ = 0; 196 int32_t deviceWidth_ = 0; 197 int32_t deviceHeight_ = 0; 198 bool isRound_ = false; 199 Platform::SendCurrentRouterCallback onRouterChange_; 200 DeviceConfig deviceConfig_; 201 202 std::string bundleName_; 203 std::string moduleName_; 204 std::string compileMode_; 205 std::string pageProfile_; 206 int32_t compatibleVersion_ = 0; 207 int32_t targetVersion_ = 0; 208 bool installationFree_ = false; 209 uint32_t labelId_ = 0; 210 bool useNewPipeline_ = true; 211 212 sptr<OHOS::Rosen::Window> rsWindow_; 213 // ITouchOutsideListener is used for touching out of hot areas of window. 214 OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr; 215 OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr; 216 OHOS::sptr<OHOS::Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr; 217 OHOS::sptr<OHOS::Rosen::IIgnoreViewSafeAreaListener> ignoreViewSafeAreaListener_ = nullptr; 218 // ArkTS Form 219 bool isFormRender_ = false; 220 }; 221 } // namespace OHOS::Ace 222 223 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H 224