• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
32 class ACE_FORCE_EXPORT UIContentImpl : public UIContent {
33 public:
34     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime);
35     UIContentImpl(OHOS::AppExecFwk::Ability* ability);
36     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard);
~UIContentImpl()37     ~UIContentImpl()
38     {
39         DestroyUIDirector();
40         DestroyCallback();
41     }
42 
43     // UI content lifeCycles
44     void Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) override;
Initialize(OHOS::Rosen::Window * window,const std::string & url,NativeValue * storage,uint32_t focusWindowId)45     void Initialize(
46         OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage, uint32_t focusWindowId) override {}
Foreground()47     void Foreground() override {}
Background()48     void Background() override {}
Focus()49     void Focus() override {}
UnFocus()50     void UnFocus() override {}
51     void Destroy() override;
OnNewWant(const OHOS::AAFwk::Want & want)52     void OnNewWant(const OHOS::AAFwk::Want& want) override {}
53 
54     // distribute
Restore(OHOS::Rosen::Window * window,const std::string & contentInfo,NativeValue * storage)55     void Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) override {}
56     std::string GetContentInfo() const override;
57     void DestroyUIDirector() override;
58 
59     // UI content event process
60     bool ProcessBackPressed() override;
61     bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
62     bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override;
63     bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
64     bool ProcessVsyncEvent(uint64_t timeStampNanos) override;
SetIsFocusActive(bool isFocusActive)65     void SetIsFocusActive(bool isFocusActive) override {}
66     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
67     void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
68         const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) override;
69     void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override {}
HideWindowTitleButton(bool hideSplit,bool hideMaximize,bool hideMinimize)70     void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) override {}
SetIgnoreViewSafeArea(bool ignoreViewSafeArea)71     void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override {}
72 
73     // Window color
74     uint32_t GetBackgroundColor() override;
75     void SetBackgroundColor(uint32_t color) override;
76 
77     void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
78 
79     // Set UIContent callback for custom window animation
80     void SetNextFrameLayoutCallback(std::function<void()>&& callback) override;
81 
82     // Receive memory level notification
83     void NotifyMemoryLevel(int32_t level) override;
84 
SetAppWindowTitle(const std::string & title)85     void SetAppWindowTitle(const std::string& title) override {}
SetAppWindowIcon(const std::shared_ptr<Media::PixelMap> & pixelMap)86     void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) override {}
SetActionEventHandler(std::function<void (const std::string & action)> && actionCallback)87     void SetActionEventHandler(std::function<void(const std::string& action)>&& actionCallback) override {}
SetErrorEventHandler(std::function<void (const std::string &,const std::string &)> && errorCallback)88     void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& errorCallback) override {}
SetFormLinkInfoUpdateHandler(std::function<void (const std::vector<std::string> &)> && callback)89     void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& callback) override {}
90 
91     // ArkTS Form
OnFormSurfaceChange(float width,float height)92     void OnFormSurfaceChange(float width, float height) override {}
UpdateFormData(const std::string & data)93     void UpdateFormData(const std::string& data) override {}
UpdateFormSharedImage(const std::map<std::string,sptr<OHOS::AppExecFwk::FormAshmem>> & imageDataMap)94     void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override
95     {}
SetFormWidth(float width)96     void SetFormWidth(float width) override {}
SetFormHeight(float height)97     void SetFormHeight(float height) override {}
GetFormWidth()98     float GetFormWidth() override
99     {
100         return 0.0;
101     }
GetFormHeight()102     float GetFormHeight() override
103     {
104         return 0.0;
105     }
GetFormRootNode()106     std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override
107     {
108         return nullptr;
109     }
110 
111     int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks) override;
112     void CloseModalUIExtension(int32_t sessionId) override;
113 
114 private:
115     void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
116     void DestroyCallback() const;
117 
118 private:
119     int32_t instanceId_ = -1;
120     void* runtime_ = nullptr;
121     // All parameters that need to be passed.
122     std::string assetPath_;
123     std::string systemResourcesPath_;
124     std::string appResourcesPath_;
125     std::string containerSdkPath_;
126     std::string language_;
127     std::string region_;
128     std::string script_;
129     uint32_t themeId_ = 0;
130     int32_t deviceWidth_ = 0;
131     int32_t deviceHeight_ = 0;
132     bool isRound_ = false;
133     Platform::SendCurrentRouterCallback onRouterChange_;
134     DeviceConfig deviceConfig_;
135 
136     std::string bundleName_;
137     std::string moduleName_;
138     std::string compileMode_;
139     std::string pageProfile_;
140     int32_t compatibleVersion_ = 0;
141     bool installationFree_ = false;
142     uint32_t labelId_ = 0;
143     bool useNewPipeline_ = true;
144 
145     sptr<OHOS::Rosen::Window> rsWindow_;
146     // ITouchOutsideListener is used for touching out of hot areas of window.
147     OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr;
148     OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr;
149     // ArkTS Form
150     bool isFormRender_ = false;
151 };
152 
153 } // namespace OHOS::Ace
154 
155 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H
156