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 } InitializeByName(OHOS::Rosen::Window * window,const std::string & name,napi_value storage)48 UIContentErrorCode InitializeByName(OHOS::Rosen::Window *window, const std::string &name, 49 napi_value storage) override { 50 return UIContentErrorCode::NO_ERRORS; 51 } InitializeDynamic(const std::string & hapPath,const std::string & abcPath,const std::string & entryPoint,const std::vector<std::string> & registerComponents)52 void InitializeDynamic(const std::string& hapPath, const std::string& abcPath, const std::string& entryPoint, 53 const std::vector<std::string>& registerComponents) override {} Initialize(OHOS::Rosen::Window * window,const std::string & url,napi_value storage,uint32_t focusWindowId)54 void Initialize( 55 OHOS::Rosen::Window* window, const std::string& url, napi_value storage, uint32_t focusWindowId) override {} Foreground()56 void Foreground() override {} Background()57 void Background() override {} Focus()58 void Focus() override {} UnFocus()59 void UnFocus() override {} 60 void Destroy() override; OnNewWant(const OHOS::AAFwk::Want & want)61 void OnNewWant(const OHOS::AAFwk::Want& want) override {} 62 63 // distribute 64 Restore(OHOS::Rosen::Window * window,const std::string & contentInfo,napi_value storage)65 UIContentErrorCode Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, 66 napi_value storage) override { 67 return UIContentErrorCode::NO_ERRORS; 68 } 69 std::string GetContentInfo() const override; 70 void DestroyUIDirector() override; 71 72 // UI content event process 73 bool ProcessBackPressed() override; 74 bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 75 bool ProcessPointerEventWithCallback( 76 const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent, const std::function<void()>& callback) override; 77 bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override; 78 bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 79 bool ProcessVsyncEvent(uint64_t timeStampNanos) override; SetIsFocusActive(bool isFocusActive)80 void SetIsFocusActive(bool isFocusActive) override {} 81 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override; 82 void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason, 83 const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr, 84 const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) override; 85 void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override {} 86 void UpdateDecorVisible(bool visible, bool hasDeco = true) override {}; HideWindowTitleButton(bool hideSplit,bool hideMaximize,bool hideMinimize)87 void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) override {} SetIgnoreViewSafeArea(bool ignoreViewSafeArea)88 void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override {} UpdateTitleInTargetPos(bool isShow,int32_t height)89 void UpdateTitleInTargetPos(bool isShow, int32_t height) override {} 90 91 // Window color 92 uint32_t GetBackgroundColor() override; 93 void SetBackgroundColor(uint32_t color) 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 {} OnFormSurfaceChange(float width,float height)112 void OnFormSurfaceChange(float width, float height) override {} UpdateFormData(const std::string & data)113 void UpdateFormData(const std::string& data) override {} UpdateFormSharedImage(const std::map<std::string,sptr<OHOS::AppExecFwk::FormAshmem>> & imageDataMap)114 void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override 115 {} SetFormWidth(float width)116 void SetFormWidth(float width) override {} SetFormHeight(float height)117 void SetFormHeight(float height) override {} GetFormWidth()118 float GetFormWidth() override 119 { 120 return 0.0; 121 } GetFormHeight()122 float GetFormHeight() override 123 { 124 return 0.0; 125 } GetFormRootNode()126 std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override 127 { 128 return nullptr; 129 } 130 131 int32_t CreateModalUIExtension(const AAFwk::Want& want, 132 const ModalUIExtensionCallbacks& callbacks, const ModalUIExtensionConfig& config) override; 133 void CloseModalUIExtension(int32_t sessionId) override; 134 SetParentToken(sptr<IRemoteObject> token)135 void SetParentToken(sptr<IRemoteObject> token) override {} GetParentToken()136 sptr<IRemoteObject> GetParentToken() override 137 { 138 return nullptr; 139 } 140 GetFormSerializedGesture()141 SerializedGesture GetFormSerializedGesture() override 142 { 143 return SerializedGesture(); 144 } 145 UpdateTransform(const OHOS::Rosen::Transform & transform)146 void UpdateTransform(const OHOS::Rosen::Transform& transform) override {}; 147 SetContentNodeGrayScale(float grayscale)148 void SetContentNodeGrayScale(float grayscale) override {}; 149 PreLayout()150 void PreLayout() override {}; 151 152 void SetStatusBarItemColor(uint32_t color) override; 153 SetForceSplitEnable(bool isForceSplit,const std::string & homePage)154 void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) override {}; 155 156 private: 157 UIContentErrorCode CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, 158 napi_value storage); 159 void DestroyCallback() const; 160 161 private: 162 int32_t instanceId_ = -1; 163 void* runtime_ = nullptr; 164 // All parameters that need to be passed. 165 std::string assetPath_; 166 std::string systemResourcesPath_; 167 std::string appResourcesPath_; 168 std::string containerSdkPath_; 169 std::string language_; 170 std::string region_; 171 std::string script_; 172 uint32_t themeId_ = 0; 173 int32_t deviceWidth_ = 0; 174 int32_t deviceHeight_ = 0; 175 bool isRound_ = false; 176 Platform::SendCurrentRouterCallback onRouterChange_; 177 DeviceConfig deviceConfig_; 178 179 std::string bundleName_; 180 std::string moduleName_; 181 std::string compileMode_; 182 std::string pageProfile_; 183 int32_t compatibleVersion_ = 0; 184 int32_t targetVersion_ = 0; 185 bool installationFree_ = false; 186 uint32_t labelId_ = 0; 187 bool useNewPipeline_ = true; 188 189 sptr<OHOS::Rosen::Window> rsWindow_; 190 // ITouchOutsideListener is used for touching out of hot areas of window. 191 OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr; 192 OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr; 193 OHOS::sptr<OHOS::Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr; 194 OHOS::sptr<OHOS::Rosen::IIgnoreViewSafeAreaListener> ignoreViewSafeAreaListener_ = nullptr; 195 // ArkTS Form 196 bool isFormRender_ = false; 197 }; 198 } // namespace OHOS::Ace 199 200 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H 201