• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::weak_ptr<OHOS::AbilityRuntime::Context> context_;
126     void* runtime_ = nullptr;
127     OHOS::Rosen::Window* window_ = nullptr;
128     std::string startUrl_;
129     int32_t instanceId_ = -1;
130     OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr;
131     OHOS::sptr<OHOS::Rosen::IOccupiedAreaChangeListener> occupiedAreaChangeListener_ = nullptr;
132 
133     // ITouchOutsideListener is used for touching out of hot areas of window.
134     OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr;
135 
136     // ArkTS Form
137     bool isFormRender_ = false;
138     bool isFormRenderInit_ = false;
139     std::string bundleName_;
140     std::string moduleName_;
141     bool isBundle_ = false;
142     int32_t minCompatibleVersionCode_ = 0;
143     float formWidth_ = 0.0;
144     float formHeight_ = 0.0;
145     std::string formData_;
146     std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>> formImageDataMap_;
147 };
148 
149 } // namespace OHOS::Ace
150 
151 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
152