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 std::shared_ptr<EventHandler> eventHandler = eventHandler_.lock();
290 rsSurfaceNode->SetBounds(borderWidth_, borderWidth_, resizedWidth, resizedHeight);
291 if (!eventHandler) {
292 HILOG_ERROR("eventHandler is null");
293 return;
294 }
295 eventHandler->PostTask([uiContent = uiContent_, resizedWidth, resizedHeight]() {
296 if (!uiContent) {
297 HILOG_ERROR("uiContent is null");
298 return;
299 }
300 uiContent->OnFormSurfaceChange(resizedWidth, resizedHeight);
301 });
302 }
303 }
304
OnSurfaceChange(float width,float height,float borderWidth)305 void FormRenderer::OnSurfaceChange(float width, float height, float borderWidth)
306 {
307 if (!formRendererDelegate_) {
308 HILOG_ERROR("form renderer delegate is null!");
309 return;
310 }
311 HILOG_INFO("Form OnSurfaceChange!");
312 formRendererDelegate_->OnSurfaceChange(width, height, borderWidth);
313 width_ = width;
314 height_ = height;
315 borderWidth_ = borderWidth;
316 }
317
OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo & formJsInfo,bool isRecoverFormToHandleClickEvent)318 void FormRenderer::OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo& formJsInfo,
319 bool isRecoverFormToHandleClickEvent)
320 {
321 if (!formRendererDispatcherImpl_) {
322 HILOG_ERROR("form renderer dispatcher is null!");
323 return;
324 }
325 if (!formRendererDelegate_) {
326 HILOG_ERROR("form renderer delegate is null!");
327 return;
328 }
329 OHOS::AAFwk::Want newWant;
330 newWant.SetParam(FORM_RENDERER_DISPATCHER, formRendererDispatcherImpl_->AsObject());
331 newWant.SetParam(OHOS::AppExecFwk::Constants::FORM_IS_RECOVER_FORM_TO_HANDLE_CLICK_EVENT,
332 isRecoverFormToHandleClickEvent);
333 auto rsSurfaceNode = uiContent_->GetFormRootNode();
334 HILOG_INFO("Form OnSurfaceCreate!");
335 formRendererDelegate_->OnSurfaceCreate(rsSurfaceNode, formJsInfo, newWant);
336 }
337
OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo & formJsInfo)338 void FormRenderer::OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
339 {
340 if (!formRendererDispatcherImpl_) {
341 HILOG_ERROR("form renderer dispatcher is null!");
342 return;
343 }
344 if (!formRendererDelegate_) {
345 HILOG_ERROR("form renderer delegate is null!");
346 return;
347 }
348 auto rsSurfaceNode = uiContent_->GetFormRootNode();
349 if (rsSurfaceNode == nullptr) {
350 HILOG_ERROR("form renderer rsSurfaceNode is null!");
351 return;
352 }
353 OHOS::AAFwk::Want newWant;
354 newWant.SetParam(FORM_RENDERER_DISPATCHER, formRendererDispatcherImpl_->AsObject());
355 HILOG_INFO("Form OnSurfaceReuse.");
356 formRendererDelegate_->OnSurfaceReuse(rsSurfaceNode->GetId(), formJsInfo, newWant);
357 formRendererDelegate_->OnFormLinkInfoUpdate(cachedInfos_);
358 }
359
OnSurfaceDetach()360 void FormRenderer::OnSurfaceDetach()
361 {
362 if (!formRendererDelegate_) {
363 HILOG_ERROR("form renderer delegate is null!");
364 return;
365 }
366 auto rsSurfaceNode = uiContent_->GetFormRootNode();
367 if (rsSurfaceNode == nullptr) {
368 HILOG_ERROR("form renderer rsSurfaceNode is null!");
369 return;
370 }
371 HILOG_INFO("Form OnSurfaceDetach.");
372 formRendererDelegate_->OnSurfaceDetach(rsSurfaceNode->GetId());
373 }
374
OnActionEvent(const std::string & action)375 void FormRenderer::OnActionEvent(const std::string& action)
376 {
377 if (!formRendererDelegate_) {
378 HILOG_ERROR("formRendererDelegate is null!");
379 return;
380 }
381
382 formRendererDelegate_->OnActionEvent(action);
383 }
384
OnError(const std::string & code,const std::string & msg)385 void FormRenderer::OnError(const std::string& code, const std::string& msg)
386 {
387 if (!formRendererDelegate_) {
388 HILOG_ERROR("formRendererDelegate is null!");
389 return;
390 }
391
392 formRendererDelegate_->OnError(code, msg);
393 }
394
OnFormLinkInfoUpdate(const std::vector<std::string> & formLinkInfos)395 void FormRenderer::OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos)
396 {
397 if (!formRendererDelegate_) {
398 HILOG_ERROR("formRendererDelegate is null!");
399 return;
400 }
401 cachedInfos_ = formLinkInfos;
402 formRendererDelegate_->OnFormLinkInfoUpdate(formLinkInfos);
403 }
404
SetRenderDelegate(const sptr<IRemoteObject> & remoteObj)405 void FormRenderer::SetRenderDelegate(const sptr<IRemoteObject>& remoteObj)
406 {
407 HILOG_INFO("Get renderRemoteObj, add death recipient.");
408 auto renderRemoteObj = iface_cast<IFormRendererDelegate>(remoteObj);
409 if (renderRemoteObj == nullptr) {
410 HILOG_ERROR("renderRemoteObj is nullptr.");
411 return;
412 }
413
414 if (!formRendererDelegate_) {
415 formRendererDelegate_ = renderRemoteObj;
416 } else {
417 auto formRendererDelegate = renderRemoteObj;
418 bool checkFlag = true;
419 formRendererDelegate->OnCheckManagerDelegate(checkFlag);
420 if (checkFlag) {
421 formRendererDelegate_ = renderRemoteObj;
422 } else {
423 HILOG_ERROR("EventHandle - SetRenderDelegate error checkFlag is false");
424 }
425 }
426
427 if (renderDelegateDeathRecipient_ == nullptr) {
428 renderDelegateDeathRecipient_ = new FormRenderDelegateRecipient(
429 [eventHandler = eventHandler_, renderer = weak_from_this()]() {
430 auto handler = eventHandler.lock();
431 if (!handler) {
432 HILOG_ERROR("eventHandler is nullptr");
433 return;
434 }
435
436 handler->PostTask([weak = renderer]() {
437 auto formRender = weak.lock();
438 if (!formRender) {
439 HILOG_ERROR("formRender is nullptr");
440 return;
441 }
442 formRender->ResetRenderDelegate();
443 });
444 });
445 }
446 auto renderDelegate = formRendererDelegate_->AsObject();
447 if (renderDelegate == nullptr) {
448 HILOG_ERROR("renderDelegate is nullptr, can not get obj from renderRemoteObj.");
449 return;
450 }
451 renderDelegate->AddDeathRecipient(renderDelegateDeathRecipient_);
452 }
453
ResetRenderDelegate()454 void FormRenderer::ResetRenderDelegate()
455 {
456 HILOG_INFO("ResetRenderDelegate.");
457 formRendererDelegate_ = nullptr;
458 }
459
UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration> & config)460 void FormRenderer::UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config)
461 {
462 if (!uiContent_) {
463 HILOG_ERROR("uiContent_ is null");
464 return;
465 }
466
467 uiContent_->UpdateConfiguration(config);
468 }
469
OnRemoteDied(const wptr<IRemoteObject> & remote)470 void FormRenderDelegateRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
471 {
472 HILOG_ERROR("Recv FormRenderDelegate death notice");
473 if (remote == nullptr) {
474 HILOG_ERROR("weak remote is null");
475 return;
476 }
477 if (handler_) {
478 handler_();
479 }
480 }
481
AttachForm(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)482 void FormRenderer::AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
483 {
484 if (uiContent_ == nullptr) {
485 HILOG_ERROR("uiContent is null!");
486 return;
487 }
488 ParseWant(want);
489 OnSurfaceDetach();
490 AttachUIContent(want, formJsInfo);
491 SetRenderDelegate(proxy_);
492 OnSurfaceReuse(formJsInfo);
493 }
494
AttachUIContent(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::FormJsInfo & formJsInfo)495 void FormRenderer::AttachUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo)
496 {
497 HILOG_INFO("AttachUIContent width = %{public}f , height = %{public}f, borderWidth_ = %{public}f.",
498 width_, height_, borderWidth_);
499 SetAllowUpdate(allowUpdate_);
500 auto rsSurfaceNode = uiContent_->GetFormRootNode();
501 if (rsSurfaceNode == nullptr) {
502 HILOG_ERROR("rsSurfaceNode is nullptr.");
503 return;
504 }
505 float width = width_ - borderWidth_ * DOUBLE;
506 float height = height_ - borderWidth_ * DOUBLE;
507 if (!NearEqual(width, uiContent_->GetFormWidth()) || !NearEqual(height, uiContent_->GetFormHeight())
508 || !NearEqual(borderWidth_, lastBorderWidth_)) {
509 uiContent_->SetFormWidth(width);
510 uiContent_->SetFormHeight(height);
511 lastBorderWidth_ = borderWidth_;
512 uiContent_->OnFormSurfaceChange(width, height);
513 rsSurfaceNode->SetBounds(borderWidth_, borderWidth_, width, height);
514 }
515 auto backgroundColor = want.GetStringParam(OHOS::AppExecFwk::Constants::PARAM_FORM_TRANSPARENCY_KEY);
516 if (backgroundColor_ != backgroundColor) {
517 backgroundColor_ = backgroundColor;
518 uiContent_->SetFormBackgroundColor(backgroundColor_);
519 }
520 if (renderingMode_ == AppExecFwk::Constants::RenderingMode::SINGLE_COLOR) {
521 HILOG_INFO("AttachUIContent SetFormBackgroundColor #00FFFFFF");
522 uiContent_->SetFormBackgroundColor(TRANSPARENT_COLOR);
523 }
524
525 uiContent_->Foreground();
526 }
527
GetRectRelativeToWindow(int32_t & top,int32_t & left) const528 void FormRenderer::GetRectRelativeToWindow(int32_t &top, int32_t &left) const
529 {
530 if (!formRendererDelegate_) {
531 HILOG_ERROR("form renderer delegate is null!");
532 return;
533 }
534 formRendererDelegate_->OnGetRectRelativeToWindow(top, left);
535 }
536
RecycleForm(std::string & statusData)537 void FormRenderer::RecycleForm(std::string& statusData)
538 {
539 if (uiContent_ == nullptr) {
540 HILOG_ERROR("RecycleForm, uiContent_ is null!");
541 return;
542 }
543 statusData = uiContent_->RecycleForm();
544 }
545
RecoverForm(const std::string & statusData)546 void FormRenderer::RecoverForm(const std::string& statusData)
547 {
548 if (uiContent_ == nullptr) {
549 HILOG_ERROR("RecoverForm, uiContent_ is null!");
550 return;
551 }
552 uiContent_->RecoverForm(statusData);
553 }
554
SetVisibleChange(bool isVisible)555 void FormRenderer::SetVisibleChange(bool isVisible)
556 {
557 if (formRendererDispatcherImpl_ != nullptr) {
558 formRendererDispatcherImpl_->SetVisible(isVisible);
559 } else {
560 HILOG_WARN("formRendererDispatcherImpl_ is null!");
561 }
562
563 if (uiContent_ == nullptr) {
564 HILOG_ERROR("SetVisibleChange error, uiContent_ is null!");
565 return;
566 }
567 uiContent_->ProcessFormVisibleChange(isVisible);
568 }
569 } // namespace Ace
570 } // namespace OHOS
571