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 #include "form_renderer.h"
17 
18 #include "configuration.h"
19 #include "form_constants.h"
20 #include "form_renderer_hilog.h"
21 #include "event_handler.h"
22 #include "refbase.h"
23 
24 #include "base/utils/utils.h"
25 
26 namespace OHOS {
27 namespace Ace {
28 namespace {
29 constexpr char FORM_RENDERER_ALLOW_UPDATE[] = "allowUpdate";
30 constexpr char FORM_RENDERER_DISPATCHER[] = "ohos.extra.param.key.process_on_form_renderer_dispatcher";
31 constexpr char FORM_RENDERER_PROCESS_ON_ADD_SURFACE[] = "ohos.extra.param.key.process_on_add_surface";
32 constexpr char TRANSPARENT_COLOR[] = "#00FFFFFF";
33 constexpr int32_t DOUBLE = 2;
34 } // namespace
35 
36 using EventHandler = OHOS::AppExecFwk::EventHandler;
37 
FormRenderer(const std::shared_ptr<OHOS::AbilityRuntime::Context> context,const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime,std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler)38 FormRenderer::FormRenderer(const std::shared_ptr<OHOS::AbilityRuntime::Context> context,
39     const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime,
40     std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler)
41     : context_(context), runtime_(runtime), eventHandler_(eventHandler)
42 {
43     HILOG_INFO("FormRenderer created.");
44     if (!context_ || !runtime_) {
45         return;
46     }
47     auto& nativeEngine = (static_cast<AbilityRuntime::JsRuntime&>(*runtime_.get())).GetNativeEngine();
48     uiContent_ = UIContent::Create(context_.get(), &nativeEngine, true);
49 }
50 
~FormRenderer()51 FormRenderer::~FormRenderer()
52 {
53     HILOG_DEBUG("called");
54 }
55 
PreInitUIContent(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)56 void FormRenderer::PreInitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
57 {
58     HILOG_INFO("InitUIContent width = %{public}f , height = %{public}f, borderWidth = %{public}f. \
59         formJsInfo.formData.size = %{public}zu. formJsInfo.imageDataMap.size = %{public}zu.",
60         width_, height_, borderWidth_,
61         formJsInfo.formData.size(),
62         formJsInfo.imageDataMap.size());
63     SetAllowUpdate(allowUpdate_);
64     uiContent_->SetFormWidth(width_ - borderWidth_ * DOUBLE);
65     uiContent_->SetFormHeight(height_ - borderWidth_ * DOUBLE);
66     lastBorderWidth_ = borderWidth_;
67     uiContent_->SetFontScaleFollowSystem(fontScaleFollowSystem_);
68     uiContent_->UpdateFormSharedImage(formJsInfo.imageDataMap);
69     uiContent_->UpdateFormData(formJsInfo.formData);
70     uiContent_->PreInitializeForm(nullptr, formJsInfo.formSrc, nullptr);
71     backgroundColor_ = want.GetStringParam(OHOS::AppExecFwk::Constants::PARAM_FORM_TRANSPARENCY_KEY);
72     if (!backgroundColor_.empty()) {
73         uiContent_->SetFormBackgroundColor(backgroundColor_);
74     }
75 }
76 
RunFormPageInner(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)77 void FormRenderer::RunFormPageInner(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
78 {
79     if (renderingMode_ == AppExecFwk::Constants::RenderingMode::SINGLE_COLOR) {
80         uiContent_->SetFormRenderingMode(static_cast<int8_t>(renderingMode_));
81     }
82     uiContent_->RunFormPage();
83     backgroundColor_ = want.GetStringParam(OHOS::AppExecFwk::Constants::PARAM_FORM_TRANSPARENCY_KEY);
84     if (!backgroundColor_.empty()) {
85         uiContent_->SetFormBackgroundColor(backgroundColor_);
86     }
87 
88     auto actionEventHandler = [weak = weak_from_this()](const std::string& action) {
89         auto formRenderer = weak.lock();
90         if (formRenderer) {
91             formRenderer->OnActionEvent(action);
92         }
93     };
94     uiContent_->SetActionEventHandler(actionEventHandler);
95 
96     auto errorEventHandler = [weak = weak_from_this()](const std::string& code, const std::string& msg) {
97         auto formRenderer = weak.lock();
98         if (formRenderer) {
99             formRenderer->OnError(code, msg);
100         }
101     };
102     uiContent_->SetErrorEventHandler(errorEventHandler);
103 
104     if (!formJsInfo.isDynamic) {
105         auto formLinkInfoUpdateHandler = [weak = weak_from_this()](const std::vector<std::string>& formLinkInfos) {
106             auto formRenderer = weak.lock();
107             if (formRenderer) {
108                 formRenderer->OnFormLinkInfoUpdate(formLinkInfos);
109             }
110         };
111         uiContent_->SetFormLinkInfoUpdateHandler(formLinkInfoUpdateHandler);
112     }
113 
114     auto rsSurfaceNode = uiContent_->GetFormRootNode();
115     if (rsSurfaceNode == nullptr) {
116         return;
117     }
118     rsSurfaceNode->SetBounds(round(borderWidth_), round(borderWidth_), round(width_ - borderWidth_ * DOUBLE),
119         round(height_ - borderWidth_ * DOUBLE));
120     if (renderingMode_ == AppExecFwk::Constants::RenderingMode::SINGLE_COLOR) {
121         HILOG_INFO("InitUIContent SetFormBackgroundColor #00FFFFFF");
122         uiContent_->SetFormBackgroundColor(TRANSPARENT_COLOR);
123     }
124     HILOG_INFO("ChangeSensitiveNodes: %{public}s", obscurationMode_ ? "true" : "false");
125     uiContent_->ChangeSensitiveNodes(obscurationMode_);
126     uiContent_->Foreground();
127 }
128 
InitUIContent(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)129 void FormRenderer::InitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
130 {
131     PreInitUIContent(want, formJsInfo);
132     RunFormPageInner(want, formJsInfo);
133 }
134 
ParseWant(const OHOS::AAFwk::Want & want)135 void FormRenderer::ParseWant(const OHOS::AAFwk::Want& want)
136 {
137     allowUpdate_ = want.GetBoolParam(FORM_RENDERER_ALLOW_UPDATE, true);
138     width_ = want.GetDoubleParam(OHOS::AppExecFwk::Constants::PARAM_FORM_WIDTH_KEY, 0.0f);
139     height_ = want.GetDoubleParam(OHOS::AppExecFwk::Constants::PARAM_FORM_HEIGHT_KEY, 0.0f);
140     proxy_ = want.GetRemoteObject(FORM_RENDERER_PROCESS_ON_ADD_SURFACE);
141     renderingMode_ = (AppExecFwk::Constants::RenderingMode)want.GetIntParam(
142         OHOS::AppExecFwk::Constants::PARAM_FORM_RENDERINGMODE_KEY, 0);
143     borderWidth_ = want.GetFloatParam(OHOS::AppExecFwk::Constants::PARAM_FORM_BORDER_WIDTH_KEY, 0.0f);
144     fontScaleFollowSystem_ = want.GetBoolParam(OHOS::AppExecFwk::Constants::PARAM_FONT_FOLLOW_SYSTEM_KEY, true);
145     obscurationMode_ = want.GetBoolParam(OHOS::AppExecFwk::Constants::PARAM_FORM_OBSCURED_KEY, false);
146 }
147 
AddForm(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)148 void FormRenderer::AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
149 {
150     if (uiContent_ == nullptr) {
151         HILOG_ERROR("uiContent is null!");
152         return;
153     }
154     formRendererDispatcherImpl_ = new FormRendererDispatcherImpl(uiContent_, shared_from_this(), eventHandler_);
155     ParseWant(want);
156     InitUIContent(want, formJsInfo);
157     SetRenderDelegate(proxy_);
158     if (want.HasParameter(OHOS::AppExecFwk::Constants::FORM_STATUS_DATA)) {
159         std::string statusData = want.GetStringParam(OHOS::AppExecFwk::Constants::FORM_STATUS_DATA);
160         RecoverForm(statusData);
161     }
162     OnSurfaceCreate(formJsInfo, want.GetBoolParam(
163         OHOS::AppExecFwk::Constants::FORM_IS_RECOVER_FORM_TO_HANDLE_CLICK_EVENT, false));
164 }
165 
PreInitAddForm(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)166 void FormRenderer::PreInitAddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
167 {
168     if (uiContent_ == nullptr) {
169         HILOG_ERROR("uiContent is null!");
170         return;
171     }
172     formRendererDispatcherImpl_ = new FormRendererDispatcherImpl(uiContent_, shared_from_this(), eventHandler_);
173     ParseWant(want);
174     PreInitUIContent(want, formJsInfo);
175 }
176 
RunFormPage(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)177 void FormRenderer::RunFormPage(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
178 {
179     if (uiContent_ == nullptr) {
180         HILOG_ERROR("uiContent is null!");
181         return;
182     }
183     ParseWant(want);
184     RunFormPageInner(want, formJsInfo);
185     SetRenderDelegate(proxy_);
186     if (want.HasParameter(OHOS::AppExecFwk::Constants::FORM_STATUS_DATA)) {
187         std::string statusData = want.GetStringParam(OHOS::AppExecFwk::Constants::FORM_STATUS_DATA);
188         RecoverForm(statusData);
189     }
190     OnSurfaceCreate(formJsInfo, want.GetBoolParam(
191         OHOS::AppExecFwk::Constants::FORM_IS_RECOVER_FORM_TO_HANDLE_CLICK_EVENT, false));
192 }
193 
ReloadForm(const std::string & url)194 void FormRenderer::ReloadForm(const std::string& url)
195 {
196     if (!uiContent_) {
197         HILOG_ERROR("uiContent_ is null");
198         return;
199     }
200     uiContent_->ReloadForm(url);
201 }
202 
IsAllowUpdate()203 bool FormRenderer::IsAllowUpdate()
204 {
205     if (formRendererDispatcherImpl_ == nullptr) {
206         HILOG_ERROR("formRendererDispatcherImpl is null");
207         return true;
208     }
209 
210     return formRendererDispatcherImpl_->IsAllowUpdate();
211 }
212 
SetAllowUpdate(bool allowUpdate)213 void FormRenderer::SetAllowUpdate(bool allowUpdate)
214 {
215     if (formRendererDispatcherImpl_ == nullptr) {
216         HILOG_ERROR("formRendererDispatcherImpl is null");
217         return;
218     }
219 
220     formRendererDispatcherImpl_->SetAllowUpdate(allowUpdate);
221 }
222 
UpdateForm(const OHOS::AppExecFwk::FormJsInfo & formJsInfo)223 void FormRenderer::UpdateForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
224 {
225     HILOG_INFO("FormRender UpdateForm start.");
226     if (!IsAllowUpdate()) {
227         HILOG_ERROR("Not allow update");
228         return;
229     }
230     if (!uiContent_) {
231         HILOG_ERROR("uiContent_ is null");
232         return;
233     }
234     uiContent_->SetFontScaleFollowSystem(fontScaleFollowSystem_);
235     uiContent_->UpdateFormSharedImage(formJsInfo.imageDataMap);
236     uiContent_->UpdateFormData(formJsInfo.formData);
237     HILOG_INFO("FormRender UpdateForm end. formJsInfo.formData.size = %{public}zu. \
238         formJsInfo.imageDataMap.size = %{public}zu.",
239         formJsInfo.formData.size(),
240         formJsInfo.imageDataMap.size());
241 }
242 
Destroy()243 void FormRenderer::Destroy()
244 {
245     HILOG_INFO("Destroy FormRenderer start.");
246     if (formRendererDelegate_ != nullptr) {
247         auto rsSurfaceNode = uiContent_->GetFormRootNode();
248         if (rsSurfaceNode != nullptr) {
249             HILOG_INFO("Form OnSurfaceRelease!");
250             formRendererDelegate_->OnSurfaceRelease(rsSurfaceNode->GetId());
251         }
252     }
253 
254     if (formRendererDelegate_ != nullptr && formRendererDelegate_->AsObject() != nullptr) {
255         formRendererDelegate_->AsObject()->RemoveDeathRecipient(renderDelegateDeathRecipient_);
256     }
257     renderDelegateDeathRecipient_ = nullptr;
258     formRendererDelegate_ = nullptr;
259     formRendererDispatcherImpl_ = nullptr;
260     if (uiContent_) {
261         uiContent_->Destroy();
262         uiContent_ = nullptr;
263     }
264     context_ = nullptr;
265     runtime_ = nullptr;
266     HILOG_INFO("Destroy FormRenderer finish.");
267 }
268 
UpdateFormSize(float width,float height,float borderWidth)269 void FormRenderer::UpdateFormSize(float width, float height, float borderWidth)
270 {
271     if (!uiContent_) {
272         HILOG_ERROR("uiContent_ is null");
273         return;
274     }
275     auto rsSurfaceNode = uiContent_->GetFormRootNode();
276     if (rsSurfaceNode == nullptr) {
277         HILOG_ERROR("rsSurfaceNode is nullptr.");
278         return;
279     }
280     float resizedWidth = width - borderWidth * DOUBLE;
281     float resizedHeight = height - borderWidth * DOUBLE;
282     if (!NearEqual(width, width_) || !NearEqual(height, height_) || !NearEqual(borderWidth, lastBorderWidth_)) {
283         width_ = width;
284         height_ = height;
285         borderWidth_ = borderWidth;
286         uiContent_->SetFormWidth(resizedWidth);
287         uiContent_->SetFormHeight(resizedHeight);
288         lastBorderWidth_ = borderWidth_;
289         uiContent_->OnFormSurfaceChange(resizedWidth, resizedHeight);
290         rsSurfaceNode->SetBounds(borderWidth_, borderWidth_, resizedWidth, resizedHeight);
291     }
292 }
293 
OnSurfaceChange(float width,float height,float borderWidth)294 void FormRenderer::OnSurfaceChange(float width, float height, float borderWidth)
295 {
296     if (!formRendererDelegate_) {
297         HILOG_ERROR("form renderer delegate is null!");
298         return;
299     }
300     HILOG_INFO("Form OnSurfaceChange!");
301     formRendererDelegate_->OnSurfaceChange(width, height, borderWidth);
302     width_ = width;
303     height_ = height;
304     borderWidth_ = borderWidth;
305 }
306 
OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo & formJsInfo,bool isRecoverFormToHandleClickEvent)307 void FormRenderer::OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo& formJsInfo,
308     bool isRecoverFormToHandleClickEvent)
309 {
310     if (!formRendererDispatcherImpl_) {
311         HILOG_ERROR("form renderer dispatcher is null!");
312         return;
313     }
314     if (!formRendererDelegate_) {
315         HILOG_ERROR("form renderer delegate is null!");
316         return;
317     }
318     OHOS::AAFwk::Want newWant;
319     newWant.SetParam(FORM_RENDERER_DISPATCHER, formRendererDispatcherImpl_->AsObject());
320     newWant.SetParam(OHOS::AppExecFwk::Constants::FORM_IS_RECOVER_FORM_TO_HANDLE_CLICK_EVENT,
321         isRecoverFormToHandleClickEvent);
322     auto rsSurfaceNode = uiContent_->GetFormRootNode();
323     HILOG_INFO("Form OnSurfaceCreate!");
324     formRendererDelegate_->OnSurfaceCreate(rsSurfaceNode, formJsInfo, newWant);
325 }
326 
OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo & formJsInfo)327 void FormRenderer::OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
328 {
329     if (!formRendererDispatcherImpl_) {
330         HILOG_ERROR("form renderer dispatcher is null!");
331         return;
332     }
333     if (!formRendererDelegate_) {
334         HILOG_ERROR("form renderer delegate is null!");
335         return;
336     }
337     auto rsSurfaceNode = uiContent_->GetFormRootNode();
338     if (rsSurfaceNode == nullptr) {
339         HILOG_ERROR("form renderer rsSurfaceNode is null!");
340         return;
341     }
342     OHOS::AAFwk::Want newWant;
343     newWant.SetParam(FORM_RENDERER_DISPATCHER, formRendererDispatcherImpl_->AsObject());
344     HILOG_INFO("Form OnSurfaceReuse.");
345     formRendererDelegate_->OnSurfaceReuse(rsSurfaceNode->GetId(), formJsInfo, newWant);
346     formRendererDelegate_->OnFormLinkInfoUpdate(cachedInfos_);
347 }
348 
OnSurfaceDetach()349 void FormRenderer::OnSurfaceDetach()
350 {
351     if (!formRendererDelegate_) {
352         HILOG_ERROR("form renderer delegate is null!");
353         return;
354     }
355     auto rsSurfaceNode = uiContent_->GetFormRootNode();
356     if (rsSurfaceNode == nullptr) {
357         HILOG_ERROR("form renderer rsSurfaceNode is null!");
358         return;
359     }
360     HILOG_INFO("Form OnSurfaceDetach.");
361     formRendererDelegate_->OnSurfaceDetach(rsSurfaceNode->GetId());
362 }
363 
OnActionEvent(const std::string & action)364 void FormRenderer::OnActionEvent(const std::string& action)
365 {
366     if (!formRendererDelegate_) {
367         HILOG_ERROR("formRendererDelegate is null!");
368         return;
369     }
370 
371     formRendererDelegate_->OnActionEvent(action);
372 }
373 
OnError(const std::string & code,const std::string & msg)374 void FormRenderer::OnError(const std::string& code, const std::string& msg)
375 {
376     if (!formRendererDelegate_) {
377         HILOG_ERROR("formRendererDelegate is null!");
378         return;
379     }
380 
381     formRendererDelegate_->OnError(code, msg);
382 }
383 
OnFormLinkInfoUpdate(const std::vector<std::string> & formLinkInfos)384 void FormRenderer::OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos)
385 {
386     if (!formRendererDelegate_) {
387         HILOG_ERROR("formRendererDelegate is null!");
388         return;
389     }
390     cachedInfos_ = formLinkInfos;
391     formRendererDelegate_->OnFormLinkInfoUpdate(formLinkInfos);
392 }
393 
SetRenderDelegate(const sptr<IRemoteObject> & remoteObj)394 void FormRenderer::SetRenderDelegate(const sptr<IRemoteObject>& remoteObj)
395 {
396     HILOG_INFO("Get renderRemoteObj, add death recipient.");
397     auto renderRemoteObj = iface_cast<IFormRendererDelegate>(remoteObj);
398     if (renderRemoteObj == nullptr) {
399         HILOG_ERROR("renderRemoteObj is nullptr.");
400         return;
401     }
402 
403     formRendererDelegate_ = renderRemoteObj;
404 
405     if (renderDelegateDeathRecipient_ == nullptr) {
406         renderDelegateDeathRecipient_ = new FormRenderDelegateRecipient(
407             [eventHandler = eventHandler_, renderer = weak_from_this()]() {
408                 auto handler = eventHandler.lock();
409                 if (!handler) {
410                     HILOG_ERROR("eventHandler is nullptr");
411                     return;
412                 }
413 
414                 handler->PostTask([weak = renderer]() {
415                     auto formRender = weak.lock();
416                     if (!formRender) {
417                         HILOG_ERROR("formRender is nullptr");
418                         return;
419                     }
420                     formRender->ResetRenderDelegate();
421                 });
422             });
423     }
424     auto renderDelegate = formRendererDelegate_->AsObject();
425     if (renderDelegate == nullptr) {
426         HILOG_ERROR("renderDelegate is nullptr, can not get obj from renderRemoteObj.");
427         return;
428     }
429     renderDelegate->AddDeathRecipient(renderDelegateDeathRecipient_);
430 }
431 
ResetRenderDelegate()432 void FormRenderer::ResetRenderDelegate()
433 {
434     HILOG_INFO("ResetRenderDelegate.");
435     formRendererDelegate_ = nullptr;
436 }
437 
UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration> & config)438 void FormRenderer::UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config)
439 {
440     if (!uiContent_) {
441         HILOG_ERROR("uiContent_ is null");
442         return;
443     }
444 
445     uiContent_->UpdateConfiguration(config);
446 }
447 
OnRemoteDied(const wptr<IRemoteObject> & remote)448 void FormRenderDelegateRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
449 {
450     HILOG_ERROR("Recv FormRenderDelegate death notice");
451     if (remote == nullptr) {
452         HILOG_ERROR("weak remote is null");
453         return;
454     }
455     if (handler_) {
456         handler_();
457     }
458 }
459 
AttachForm(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)460 void FormRenderer::AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
461 {
462     if (uiContent_ == nullptr) {
463         HILOG_ERROR("uiContent is null!");
464         return;
465     }
466     ParseWant(want);
467     OnSurfaceDetach();
468     AttachUIContent(want, formJsInfo);
469     SetRenderDelegate(proxy_);
470     OnSurfaceReuse(formJsInfo);
471 }
472 
AttachUIContent(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)473 void FormRenderer::AttachUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
474 {
475     HILOG_INFO("AttachUIContent width = %{public}f , height = %{public}f, borderWidth_ = %{public}f.",
476         width_, height_, borderWidth_);
477     SetAllowUpdate(allowUpdate_);
478     auto rsSurfaceNode = uiContent_->GetFormRootNode();
479     if (rsSurfaceNode == nullptr) {
480         HILOG_ERROR("rsSurfaceNode is nullptr.");
481         return;
482     }
483     float width = width_ - borderWidth_ * DOUBLE;
484     float height = height_ - borderWidth_ * DOUBLE;
485     if (!NearEqual(width, uiContent_->GetFormWidth()) || !NearEqual(height, uiContent_->GetFormHeight())
486         || !NearEqual(borderWidth_, lastBorderWidth_)) {
487         uiContent_->SetFormWidth(width);
488         uiContent_->SetFormHeight(height);
489         lastBorderWidth_ = borderWidth_;
490         uiContent_->OnFormSurfaceChange(width, height);
491         rsSurfaceNode->SetBounds(borderWidth_, borderWidth_, width, height);
492     }
493     auto backgroundColor = want.GetStringParam(OHOS::AppExecFwk::Constants::PARAM_FORM_TRANSPARENCY_KEY);
494     if (backgroundColor_ != backgroundColor) {
495         backgroundColor_ = backgroundColor;
496         uiContent_->SetFormBackgroundColor(backgroundColor_);
497     }
498     if (renderingMode_ == AppExecFwk::Constants::RenderingMode::SINGLE_COLOR) {
499         HILOG_INFO("AttachUIContent SetFormBackgroundColor #00FFFFFF");
500         uiContent_->SetFormBackgroundColor(TRANSPARENT_COLOR);
501     }
502 
503     uiContent_->Foreground();
504 }
505 
GetRectRelativeToWindow(int32_t & top,int32_t & left) const506 void FormRenderer::GetRectRelativeToWindow(int32_t &top, int32_t &left) const
507 {
508     if (!formRendererDelegate_) {
509         HILOG_ERROR("form renderer delegate is null!");
510         return;
511     }
512     formRendererDelegate_->OnGetRectRelativeToWindow(top, left);
513 }
514 
RecycleForm(std::string & statusData)515 void FormRenderer::RecycleForm(std::string& statusData)
516 {
517     if (uiContent_ == nullptr) {
518         HILOG_ERROR("RecycleForm, uiContent_ is null!");
519         return;
520     }
521     statusData = uiContent_->RecycleForm();
522 }
523 
RecoverForm(const std::string & statusData)524 void FormRenderer::RecoverForm(const std::string& statusData)
525 {
526     if (uiContent_ == nullptr) {
527         HILOG_ERROR("RecoverForm, uiContent_ is null!");
528         return;
529     }
530     uiContent_->RecoverForm(statusData);
531 }
532 
SetVisibleChange(bool isVisible)533 void FormRenderer::SetVisibleChange(bool isVisible)
534 {
535     if (formRendererDispatcherImpl_ != nullptr) {
536         formRendererDispatcherImpl_->SetVisible(isVisible);
537     } else {
538         HILOG_WARN("formRendererDispatcherImpl_ is null!");
539     }
540 
541     if (uiContent_ == nullptr) {
542         HILOG_ERROR("SetVisibleChange error, uiContent_ is null!");
543         return;
544     }
545     uiContent_->ProcessFormVisibleChange(isVisible);
546 }
547 } // namespace Ace
548 } // namespace OHOS
549