• 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_INTERFACE_INNERKITS_FORM_RENDERER_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H
18 
19 #include "ability_context.h"
20 #include "form_js_info.h"
21 #include "form_renderer_delegate_interface.h"
22 #include "form_renderer_dispatcher_impl.h"
23 #include "js_runtime.h"
24 #include "runtime.h"
25 #include "ui_content.h"
26 #include "event_handler.h"
27 #include "form_constants.h"
28 #include "core/accessibility/accessibility_manager.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 class Configuration;
33 class EventHandler;
34 }
35 namespace Ace {
36 /**
37  * @class FormRenderer
38  */
39 class FormRenderer : public std::enable_shared_from_this<FormRenderer> {
40 public:
41     FormRenderer(const std::shared_ptr<OHOS::AbilityRuntime::Context> context,
42         const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime,
43         std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler);
44     ~FormRenderer();
45 
46     void AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
47     void PreInitAddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
48     void RunFormPage(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
49     void UpdateForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
50     void ReloadForm(const std::string& url);
51     void Destroy();
52     void ResetRenderDelegate();
53     void SetAllowUpdate(bool allowUpdate);
54     bool IsAllowUpdate();
55 
56     void OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, bool isRecoverFormToHandleClickEvent);
57     void OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
58     void OnSurfaceDetach();
59     void OnActionEvent(const std::string& action);
60     void OnError(const std::string& code, const std::string& msg);
61     void OnSurfaceChange(float width, float height, float borderWidth = 0.0);
62     void OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos);
63     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
64     void AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
65     void RecycleForm(std::string& statusData);
66     void RecoverForm(const std::string& statusData);
67     void GetRectRelativeToWindow(AccessibilityParentRectInfo& parentRectInfo) const;
68     void SetVisibleChange(bool isVisible);
69     void UpdateFormSize(float width, float height, float borderWidth);
70     void HandleTimeStampAndSetBounds(std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode);
71     void CheckWhetherNeedResizeFormAgain(float borderWidth, float width, float height);
72     void ResizeFormAgain(float borderWidth, float width, float height);
73     int64_t GetRunFormPageInnerTimeStamp();
74     void SetRunFormPageInnerTimeStamp(int64_t timeStamp);
75 
76 private:
77     void InitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
78     void ParseWant(const OHOS::AAFwk::Want& want);
79     void SetRenderDelegate(const sptr<IRemoteObject>& renderRemoteObj);
80     void AttachUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
81     void PreInitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
82     void RunFormPageInner(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
83     void RemoveFormDeathRecipient();
84 
85     bool allowUpdate_ = true;
86     bool obscurationMode_ = false;
87     float width_ = 0.0f;
88     float height_ = 0.0f;
89     float borderWidth_ = 0.0f;
90     float lastBorderWidth_ = 0.0f;
91     bool fontScaleFollowSystem_ = true;
92     std::string backgroundColor_;
93     AppExecFwk::Constants::RenderingMode renderingMode_ = AppExecFwk::Constants::RenderingMode::FULL_COLOR;
94     bool enableBlurBackground_ = false;
95     std::vector<std::string> cachedInfos_;
96     std::shared_ptr<OHOS::AbilityRuntime::Context> context_;
97     std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime_;
98     std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
99     sptr<FormRendererDispatcherImpl> formRendererDispatcherImpl_;
100     sptr<IFormRendererDelegate> formRendererDelegate_;
101     std::shared_ptr<UIContent> uiContent_;
102     sptr<IRemoteObject::DeathRecipient> renderDelegateDeathRecipient_;
103     sptr<IRemoteObject> proxy_;
104     int64_t runFormPageInnerTimeStamp_ = -1;
105 };
106 
107 /**
108  * @class FormRenderDelegateRecipient
109  * FormRenderDelegateRecipient notices IRemoteBroker died.
110  */
111 class FormRenderDelegateRecipient : public IRemoteObject::DeathRecipient {
112 public:
113     using RemoteDiedHandler = std::function<void()>;
FormRenderDelegateRecipient(RemoteDiedHandler handler)114     explicit FormRenderDelegateRecipient(RemoteDiedHandler handler) : handler_(std::move(handler)) {}
115 
116     ~FormRenderDelegateRecipient() override = default;
117 
118     void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
119 
120 private:
121     RemoteDiedHandler handler_;
122 };
123 } // namespace Ace
124 } // namespace OHOS
125 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H
126