• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 <list>
20 
21 #include "ability_info.h"
22 #include "display_manager.h"
23 #include "dm/display_manager.h"
24 #include "interfaces/inner_api/ace/arkui_rect.h"
25 #include "interfaces/inner_api/ace/ui_content.h"
26 #include "interfaces/inner_api/ace/viewport_config.h"
27 #include "interfaces/inner_api/ui_session/ui_content_stub_impl.h"
28 #include "key_event.h"
29 #include "native_engine/native_engine.h"
30 #include "native_engine/native_value.h"
31 #include "wm/window.h"
32 
33 #include "adapter/ohos/entrance/distributed_ui_manager.h"
34 #include "adapter/ohos/entrance/ace_viewport_config.h"
35 #include "base/thread/task_executor.h"
36 #include "base/view_data/view_data_wrap.h"
37 #include "core/common/asset_manager_impl.h"
38 #include "core/common/render_boundary_manager.h"
39 #include "core/common/update_config_manager.h"
40 #include "core/components/common/properties/animation_option.h"
41 #include "core/components/common/properties/popup_param.h"
42 #include "iremote_object.h"
43 
44 namespace OHOS::Accessibility {
45 class AccessibilityElementInfo;
46 }
47 
48 namespace OHOS::Ace {
49 class ACE_FORCE_EXPORT UIContentImpl : public UIContent {
50 public:
51     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime);
52     UIContentImpl(OHOS::AppExecFwk::Ability* ability);
53     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard);
~UIContentImpl()54     ~UIContentImpl()
55     {
56         DestroyUIDirector();
57         DestroyCallback();
58     }
59 
60     // UI content lifeCycles
61     UIContentErrorCode Initialize(OHOS::Rosen::Window* window, const std::string& url, napi_value storage) override;
62     UIContentErrorCode Initialize(
63         OHOS::Rosen::Window* window, const std::shared_ptr<std::vector<uint8_t>>& content, napi_value storage) override;
64     UIContentErrorCode Initialize(OHOS::Rosen::Window* window, const std::shared_ptr<std::vector<uint8_t>>& content,
65         napi_value storage, const std::string& contentName) override;
66     UIContentErrorCode InitializeByName(
67         OHOS::Rosen::Window* window, const std::string& name, napi_value storage) override;
68     void InitializeDynamic(const std::string& hapPath, const std::string& abcPath, const std::string& entryPoint,
69         const std::vector<std::string>& registerComponents) override;
70     void Initialize(
71         OHOS::Rosen::Window* window, const std::string& url, napi_value storage, uint32_t focusWindowId) override;
72     void Foreground() override;
73     void Background() override;
74     void Focus() override;
75     void UnFocus() override;
76     void Destroy() override;
77     void OnNewWant(const OHOS::AAFwk::Want& want) override;
78 
79     // distribute
80     UIContentErrorCode Restore(
81         OHOS::Rosen::Window* window, const std::string& contentInfo, napi_value storage) override;
82     std::string GetContentInfo() const override;
83     void DestroyUIDirector() override;
84     void SetUIContentType(UIContentType uIContentType) override;
85     void UpdateFontScale(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
86 
87     // UI content event process
88     bool ProcessBackPressed() override;
89     void UpdateDialogResourceConfiguration(RefPtr<Container>& container,
90         const std::shared_ptr<OHOS::AbilityRuntime::Context>& context);
91     bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
92     bool ProcessPointerEventWithCallback(
93         const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent, const std::function<void()>& callback) override;
94     bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override;
95     bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
96     bool ProcessVsyncEvent(uint64_t timeStampNanos) override;
97     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
98     void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
99         const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
100         const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) override;
101     void UpdateViewportConfigWithAnimation(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
102         AnimationOption animationOpt, const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
103         const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {});
104     void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override;
105     void UpdateDecorVisible(bool visible, bool hasDeco) override;
106     void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) override;
107     void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override;
108     void UpdateMaximizeMode(OHOS::Rosen::MaximizeMode mode) override;
109     void ProcessFormVisibleChange(bool isVisible) override;
110     void UpdateTitleInTargetPos(bool isShow, int32_t height) override;
111     void NotifyRotationAnimationEnd() override;
112 
113     void ChangeSensitiveNodes(bool isSensitive) override;
114 
115     // Window color
116     uint32_t GetBackgroundColor() override;
117     void SetBackgroundColor(uint32_t color) override;
118 
119     bool NeedSoftKeyboard() override;
120 
121     void SetOnWindowFocused(const std::function<void()>& callback) override;
122 
123     // Current paintSize of window
124     void GetAppPaintSize(OHOS::Rosen::Rect& paintrect) override;
125 
126     // Get paintSize of window by calculating
127     void GetWindowPaintSize(OHOS::Rosen::Rect& paintrect) override;
128 
129     void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
130 
131     // Set UIContent callback for custom window animation
132     void SetNextFrameLayoutCallback(std::function<void()>&& callback) override;
133 
134     // Set UIContent callback after layout finish
135     void SetFrameLayoutFinishCallback(std::function<void()>&& callback) override;
136 
137     // Set UIContent callback after latest layout finish
138     void SetLatestFrameLayoutFinishCallback(std::function<void()>&& callback) override;
139 
140     // Receive memory level notification
141     void NotifyMemoryLevel(int32_t level) override;
142 
143     void SetAppWindowTitle(const std::string& title) override;
144     void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) override;
145 
146     // ArkTS Form
147     void PreInitializeForm(OHOS::Rosen::Window* window, const std::string& url, napi_value storage) override;
148     void RunFormPage() override;
149     std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override;
150     void UpdateFormData(const std::string& data) override;
151     void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override;
152     void ReloadForm(const std::string& url) override;
153 
SetFormWidth(float width)154     void SetFormWidth(float width) override
155     {
156         formWidth_ = width;
157     }
SetFormHeight(float height)158     void SetFormHeight(float height) override
159     {
160         formHeight_ = height;
161     }
GetFormWidth()162     float GetFormWidth() override
163     {
164         return formWidth_;
165     }
GetFormHeight()166     float GetFormHeight() override
167     {
168         return formHeight_;
169     }
170 
171     void SetActionEventHandler(std::function<void(const std::string& action)>&& actionCallback) override;
172     void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& errorCallback) override;
173     void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& callback) override;
174 
175     void OnFormSurfaceChange(float width, float height) override;
176 
177     void SetFormBackgroundColor(const std::string& color) override;
178 
179     void RegisterAccessibilityChildTree(
180         uint32_t parentWindowId, int32_t parentTreeId, int64_t parentElementId) override;
181     void SetAccessibilityGetParentRectHandler(std::function<void(int32_t&, int32_t&)>&& callback) override;
182     void DeregisterAccessibilityChildTree() override;
183     void AccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
184 
185     void SetFontScaleFollowSystem(const bool fontScaleFollowSystem) override;
186 
DumpUITree()187     SerializeableObjectArray DumpUITree() override
188     {
189         return uiManager_->DumpUITree();
190     }
SubscribeUpdate(const std::function<void (int32_t,SerializeableObjectArray &)> & onUpdate)191     void SubscribeUpdate(const std::function<void(int32_t, SerializeableObjectArray&)>& onUpdate) override
192     {
193         return uiManager_->SubscribeUpdate(onUpdate);
194     }
UnSubscribeUpdate()195     void UnSubscribeUpdate() override
196     {
197         uiManager_->UnSubscribeUpdate();
198     }
ProcessSerializeableInputEvent(const SerializeableObjectArray & array)199     void ProcessSerializeableInputEvent(const SerializeableObjectArray& array) override
200     {
201         uiManager_->ProcessSerializeableInputEvent(array);
202     }
RestoreUITree(const SerializeableObjectArray & array)203     void RestoreUITree(const SerializeableObjectArray& array) override
204     {
205         uiManager_->RestoreUITree(array);
206     }
UpdateUITree(const SerializeableObjectArray & array)207     void UpdateUITree(const SerializeableObjectArray& array) override
208     {
209         uiManager_->UpdateUITree(array);
210     }
SubscribeInputEventProcess(const std::function<void (SerializeableObjectArray &)> & onEvent)211     void SubscribeInputEventProcess(const std::function<void(SerializeableObjectArray&)>& onEvent) override
212     {
213         uiManager_->SubscribeInputEventProcess(onEvent);
214     }
UnSubscribeInputEventProcess()215     void UnSubscribeInputEventProcess() override
216     {
217         uiManager_->UnSubscribeInputEventProcess();
218     }
219     void GetResourcePaths(std::vector<std::string>& resourcesPaths, std::string& assetRootPath,
220         std::vector<std::string>& assetBasePaths, std::string& resFolderName) override;
221     void SetResourcePaths(const std::vector<std::string>& resourcesPaths, const std::string& assetRootPath,
222         const std::vector<std::string>& assetBasePaths) override;
223 
224     napi_value GetUINapiContext() override;
225     void SetIsFocusActive(bool isFocusActive) override;
226 
227     void UpdateResource() override;
228 
229     int32_t CreateModalUIExtension(const AAFwk::Want& want,
230         const ModalUIExtensionCallbacks& callbacks, const ModalUIExtensionConfig& config) override;
231     void CloseModalUIExtension(int32_t sessionId) override;
232 
233     void SetParentToken(sptr<IRemoteObject> token) override;
234     sptr<IRemoteObject> GetParentToken() override;
235     AbilityBase::AutoFillType ViewDataToType(const AbilityBase::ViewData& viewData);
236     bool DumpViewData(AbilityBase::ViewData& viewData, AbilityBase::AutoFillType& type) override;
237     bool CheckNeedAutoSave() override;
238     bool DumpViewData(const RefPtr<NG::FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap,
239         bool skipSubAutoFillContainer = false, bool needsRecordData = false);
240 
241     void SearchElementInfoByAccessibilityId(
242         int64_t elementId, int32_t mode,
243         int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) override;
244 
245     void SearchElementInfosByText(
246         int64_t elementId, const std::string& text, int64_t baseParent,
247         std::list<Accessibility::AccessibilityElementInfo>& output) override;
248 
249     void FindFocusedElementInfo(
250         int64_t elementId, int32_t focusType,
251         int64_t baseParent, Accessibility::AccessibilityElementInfo& output) override;
252 
253     void FocusMoveSearch(
254         int64_t elementId, int32_t direction,
255         int64_t baseParent, Accessibility::AccessibilityElementInfo& output) override;
256 
257     bool NotifyExecuteAction(int64_t elementId, const std::map<std::string, std::string>& actionArguments,
258         int32_t action, int64_t offset) override;
259 
260     void HandleAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType,
261         int32_t eventType, int64_t timeMs) override;
262 
GetInstanceId()263     int32_t GetInstanceId() override
264     {
265         return instanceId_;
266     }
267 
268     std::string RecycleForm() override;
269 
270     void RecoverForm(const std::string& statusData) override;
271     Shadow GetPopupShadow();
272 
273     int32_t CreateCustomPopupUIExtension(const AAFwk::Want& want,
274         const ModalUIExtensionCallbacks& callbacks, const CustomPopupUIExtensionConfig& config) override;
275     void DestroyCustomPopupUIExtension(int32_t nodeId) override;
276     void UpdateCustomPopupUIExtension(const CustomPopupUIExtensionConfig& config) override;
277 
278     void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow) override;
279     void SetContainerModalTitleHeight(int32_t height) override;
280     int32_t GetContainerModalTitleHeight() override;
281     bool GetContainerModalButtonsRect(Rosen::Rect& containerModal, Rosen::Rect& buttons) override;
282     void SubscribeContainerModalButtonsRectChange(
283         std::function<void(Rosen::Rect& containerModal, Rosen::Rect& buttons)>&& callback) override;
284     void UpdateTransform(const OHOS::Rosen::Transform& transform) override;
285 
286     SerializedGesture GetFormSerializedGesture() override;
287 
SetUIExtensionSubWindow(bool isUIExtensionSubWindow)288     void SetUIExtensionSubWindow(bool isUIExtensionSubWindow) override
289     {
290         isUIExtensionSubWindow_ = isUIExtensionSubWindow;
291     }
292 
IsUIExtensionSubWindow()293     bool IsUIExtensionSubWindow() override
294     {
295         return isUIExtensionSubWindow_;
296     }
297 
SetUIExtensionAbilityProcess(bool isUIExtensionAbilityProcess)298     void SetUIExtensionAbilityProcess(bool isUIExtensionAbilityProcess) override
299     {
300         isUIExtensionAbilityProcess_ = isUIExtensionAbilityProcess;
301     }
302 
IsUIExtensionAbilityProcess()303     bool IsUIExtensionAbilityProcess() override
304     {
305         return isUIExtensionAbilityProcess_;
306     }
307 
SetUIExtensionAbilityHost(bool isUIExtensionAbilityHost)308     void SetUIExtensionAbilityHost(bool isUIExtensionAbilityHost) override
309     {
310         isUIExtensionAbilityHost_ = isUIExtensionAbilityHost;
311     }
312 
IsUIExtensionAbilityHost()313     bool IsUIExtensionAbilityHost() override
314     {
315         return isUIExtensionAbilityHost_;
316     }
317 
318     std::vector<Ace::RectF> GetOverlayNodePositions() const override;
319 
320     void RegisterOverlayNodePositionsUpdateCallback(
321         const std::function<void(std::vector<Ace::RectF>)>& callback) const override;
322 
323     void SetContentNodeGrayScale(float grayscale) override;
324 
325     void SetFormRenderingMode(int8_t renderMode) override;
326 
327     void PreLayout() override;
328 
329     void SetFontScaleAndWeightScale(const RefPtr<Platform::AceContainer>& container, int32_t instanceId);
330 
331     void SetStatusBarItemColor(uint32_t color) override;
332 
333     void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) override;
334 
335     void UpdateDialogContainerConfig(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
336 
GetRemoteObj()337     sptr<IRemoteObject> GetRemoteObj() override
338     {
339         return instance_;
340     }
341 
342 private:
343     UIContentErrorCode InitializeInner(
344         OHOS::Rosen::Window* window, const std::string& contentInfo, napi_value storage, bool isNamedRouter);
345     UIContentErrorCode CommonInitialize(
346         OHOS::Rosen::Window* window, const std::string& contentInfo, napi_value storage, uint32_t focusWindowId = 0);
347     UIContentErrorCode CommonInitializeForm(
348         OHOS::Rosen::Window* window, const std::string& contentInfo, napi_value storage);
349     void InitializeSubWindow(OHOS::Rosen::Window* window, bool isDialog = false);
350     void DestroyCallback() const;
351     void SetConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
352 
353     void InitializeSafeArea(const RefPtr<Platform::AceContainer>& container);
354     void InitializeDisplayAvailableRect(const RefPtr<Platform::AceContainer>& container);
355 
356     void InitDragSummaryMap(const RefPtr<Platform::AceContainer>& container);
357 
358     RefPtr<PopupParam> CreateCustomPopupParam(bool isShow, const CustomPopupUIExtensionConfig& config);
359     void OnPopupStateChange(const std::string& event, const CustomPopupUIExtensionConfig& config, int32_t nodeId);
360     void SetCustomPopupConfig(int32_t nodeId, const CustomPopupUIExtensionConfig& config, int32_t popupId);
361 
362     void RenderLayoutBoundary(bool isDebugBoundary);
363     static void EnableSystemParameterTraceLayoutCallback(const char* key, const char* value, void* context);
364     static void EnableSystemParameterSecurityDevelopermodeCallback(const char* key, const char* value, void* context);
365     static void EnableSystemParameterDebugStatemgrCallback(const char* key, const char* value, void* context);
366     static void EnableSystemParameterDebugBoundaryCallback(const char* key, const char* value, void* context);
367     static void EnableSystemParameterTraceInputEventCallback(const char* key, const char* value, void* context);
368     void AddWatchSystemParameter();
369     void StoreConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
370     void UnregisterDisplayManagerCallback();
371 
372     std::weak_ptr<OHOS::AbilityRuntime::Context> context_;
373     void* runtime_ = nullptr;
374     OHOS::Rosen::Window* window_ = nullptr;
375     std::string startUrl_;
376     int32_t instanceId_ = -1;
377     OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr;
378     OHOS::sptr<OHOS::Rosen::IOccupiedAreaChangeListener> occupiedAreaChangeListener_ = nullptr;
379     OHOS::sptr<OHOS::Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr;
380     OHOS::sptr<OHOS::Rosen::DisplayManager::IFoldStatusListener> foldStatusListener_ = nullptr;
381     OHOS::sptr<OHOS::Rosen::DisplayManager::IDisplayModeListener> foldDisplayModeListener_ = nullptr;
382     OHOS::sptr<OHOS::Rosen::DisplayManager::IAvailableAreaListener> availableAreaChangedListener_ = nullptr;
383 
384     // ITouchOutsideListener is used for touching out of hot areas of window.
385     OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr;
386 
387     // ArkTS Form
388     bool isFormRender_ = false;
389     bool isFormRenderInit_ = false;
390     std::string bundleName_;
391     std::string moduleName_;
392     std::string hapPath_;
393     bool isBundle_ = false;
394     float formWidth_ = 0.0;
395     float formHeight_ = 0.0;
396     std::string formData_;
397     bool fontScaleFollowSystem_ = true;
398     std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>> formImageDataMap_;
399     std::unordered_map<int32_t, CustomPopupUIExtensionConfig> customPopupConfigMap_;
400     std::unordered_map<int32_t, int32_t> popupUIExtensionRecords_;
401     std::unique_ptr<DistributedUIManager> uiManager_;
402 
403     bool isDynamicRender_ = false;
404     UIContentType uIContentType_ = UIContentType::UNDEFINED;
405     std::shared_ptr<TaskWrapper> taskWrapper_;
406     std::vector<std::string> registerComponents_;
407 
408     sptr<IRemoteObject> parentToken_ = nullptr;
409     sptr<IRemoteObject> instance_ = new (std::nothrow) UIContentServiceStubImpl();
410     RefPtr<RenderBoundaryManager> renderBoundaryManager_ = Referenced::MakeRefPtr<RenderBoundaryManager>();
411     bool isUIExtensionSubWindow_ = false;
412     bool isUIExtensionAbilityProcess_ = false;
413     bool isUIExtensionAbilityHost_ = false;
414     RefPtr<UpdateConfigManager<AceViewportConfig>> viewportConfigMgr_ =
415         Referenced::MakeRefPtr<UpdateConfigManager<AceViewportConfig>>();
416 
417     SingleTaskExecutor::CancelableTask updateDecorVisibleTask_;
418     std::mutex updateDecorVisibleMutex_;
419 };
420 
421 } // namespace OHOS::Ace
422 
423 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
424