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 #include "frameworks/bridge/js_frontend/js_command.h"
17
18 #include "base/log/event_report.h"
19 #include "frameworks/bridge/common/dom/dom_search.h"
20 #include "frameworks/bridge/common/dom/dom_textarea.h"
21 #include "frameworks/bridge/js_frontend/engine/common/js_engine_loader.h"
22 #include "frameworks/bridge/js_frontend/js_ace_page.h"
23
24 namespace OHOS::Ace::Framework {
25 namespace {
26
GetNodeFromPage(const RefPtr<JsAcePage> & page,NodeId nodeId)27 inline RefPtr<DOMNode> GetNodeFromPage(const RefPtr<JsAcePage>& page, NodeId nodeId)
28 {
29 auto domDocument = page ? page->GetDomDocument() : nullptr;
30 if (domDocument) {
31 return domDocument->GetDOMNodeById(nodeId);
32 }
33 LOGE("Failed to get DOM document");
34 EventReport::SendJsException(JsExcepType::GET_NODE_ERR);
35 return nullptr;
36 }
37
GetAccessibilityManager(const RefPtr<JsAcePage> & page)38 inline RefPtr<AccessibilityManager> GetAccessibilityManager(const RefPtr<JsAcePage>& page)
39 {
40 if (!page) {
41 return nullptr;
42 }
43 auto pipelineContext = page->GetPipelineContext().Upgrade();
44 if (!pipelineContext) {
45 return nullptr;
46 }
47 return pipelineContext->GetAccessibilityManager();
48 }
49
TrySaveTargetAndIdNode(const std::string & id,const std::string & target,const RefPtr<DOMDocument> & domDocument,const RefPtr<DOMNode> & node)50 inline void TrySaveTargetAndIdNode(const std::string& id, const std::string& target,
51 const RefPtr<DOMDocument>& domDocument, const RefPtr<DOMNode>& node)
52 {
53 if (!id.empty()) {
54 domDocument->AddNodeWithId(id, node);
55 }
56 if (!target.empty()) {
57 domDocument->AddNodeWithTarget(target, node);
58 }
59 }
60
61 std::vector<std::string> g_declarationNodes = {
62 DOM_NODE_TAG_BADGE,
63 DOM_NODE_TAG_BUTTON,
64 DOM_NODE_TAG_LABEL,
65 DOM_NODE_TAG_PIECE,
66 DOM_NODE_TAG_QRCODE,
67 DOM_NODE_TAG_SPAN,
68 DOM_NODE_TAG_SWIPER,
69 DOM_NODE_TAG_TEXT,
70 DOM_NODE_TAG_WEB,
71 DOM_NODE_TAG_CLOCK,
72 DOM_NODE_TAG_XCOMPONENT
73 };
74
75 } // namespace
76
UpdateForChart(const RefPtr<DOMNode> & node) const77 void JsCommandDomElementOperator::UpdateForChart(const RefPtr<DOMNode>& node) const
78 {
79 if (chartDatasets_ || chartOptions_ || segments_) {
80 auto chart = AceType::DynamicCast<DOMChart>(node);
81 if (chart) {
82 if (chartDatasets_) {
83 chart->SetChartAttrDatasets(*chartDatasets_);
84 }
85 if (chartOptions_) {
86 chart->SetChartAttrOptions(*chartOptions_);
87 }
88 if (segments_) {
89 chart->SetChartAttrSegments(*segments_);
90 }
91 }
92 }
93 }
94
UpdateForImageAnimator(const RefPtr<DOMNode> & node) const95 void JsCommandDomElementOperator::UpdateForImageAnimator(const RefPtr<DOMNode>& node) const
96 {
97 if (images_) {
98 auto imageAnimator = AceType::DynamicCast<DOMImageAnimator>(node);
99 if (imageAnimator) {
100 imageAnimator->SetImagesAttr(*images_);
101 }
102 }
103 }
104
UpdateForClock(const RefPtr<DOMNode> & node) const105 void JsCommandDomElementOperator::UpdateForClock(const RefPtr<DOMNode>& node) const
106 {
107 if (clockConfig_) {
108 auto domClock = AceType::DynamicCast<DOMClock>(node);
109 if (domClock) {
110 domClock->SetClockConfig(*clockConfig_);
111 }
112 }
113 }
114
UpdateForBadge(const RefPtr<DOMNode> & node) const115 void JsCommandDomElementOperator::UpdateForBadge(const RefPtr<DOMNode>& node) const
116 {
117 if (badgeConfig_) {
118 auto domBadge = AceType::DynamicCast<DOMBadge>(node);
119 if (domBadge) {
120 domBadge->SetBadgeConfig(*badgeConfig_);
121 }
122 }
123 }
124
UpdateForStepperLabel(const RefPtr<DOMNode> & node) const125 void JsCommandDomElementOperator::UpdateForStepperLabel(const RefPtr<DOMNode>& node) const
126 {
127 if (stepperLabel_) {
128 auto domStepperItem = AceType::DynamicCast<DOMStepperItem>(node);
129 if (domStepperItem) {
130 domStepperItem->SetLabel(*stepperLabel_);
131 }
132 }
133 }
134
UpdateForInput(const RefPtr<DOMNode> & node) const135 void JsCommandDomElementOperator::UpdateForInput(const RefPtr<DOMNode>& node) const
136 {
137 if (!node || !inputOptions_) {
138 return;
139 }
140
141 auto input = AceType::DynamicCast<DOMInput>(node);
142 if (input) {
143 input->SetInputOptions(*inputOptions_);
144 return;
145 }
146 auto textarea = AceType::DynamicCast<DOMTextarea>(node);
147 if (textarea) {
148 textarea->SetInputOptions(*inputOptions_);
149 return;
150 }
151 auto search = AceType::DynamicCast<DOMSearch>(node);
152 if (search) {
153 search->SetInputOptions(*inputOptions_);
154 }
155 }
156
CreateDomNode(const RefPtr<JsAcePage> & page,NodeId parentNodeId) const157 RefPtr<DOMNode> JsCommandDomElementCreator::CreateDomNode(const RefPtr<JsAcePage>& page, NodeId parentNodeId) const
158 {
159 if (!page) {
160 return nullptr;
161 }
162 auto pageId = page->GetPageId();
163 auto domDocument = page->GetDomDocument();
164 ACE_DCHECK(domDocument);
165 RefPtr<DOMNode> parentNode;
166 if (parentNodeId != -1) {
167 parentNode = domDocument->GetDOMNodeById(parentNodeId);
168 if (!parentNode) {
169 LOGE("Parent node %{private}d not exists", nodeId_);
170 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
171 return nullptr;
172 }
173 }
174
175 std::string tagName = tagName_;
176 if (parentNode && parentNode->HasSvgTag() && tagName_ == DOM_NODE_TAG_TEXT) {
177 // the input tag of ace text and svg text is same.
178 tagName = std::string(DOM_NODE_TAG_SVG_TEXT);
179 }
180 auto node = domDocument->CreateNodeWithId(tagName, nodeId_, itemIndex_);
181 if (!node) {
182 LOGE("Failed to create DOM node %{public}s", tagName.c_str());
183 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
184 return nullptr;
185 }
186 if (page->IsLiteStyle()) {
187 node->AdjustParamInLiteMode();
188 }
189
190 // supplement: set svg tag by parentNode.hasSvgTag_ or tagName_
191 node->SetParentNode(parentNode);
192
193 TrySaveTargetAndIdNode(id_, target_, domDocument, node);
194 node->SetShareId(shareId_);
195 node->SetPipelineContext(pipelineContext_);
196 node->SetIsCustomComponent(isCustomComponent_);
197 node->SetBoxWrap(page->IsUseBoxWrap());
198 node->InitializeStyle();
199 auto declaration = node->GetDeclaration();
200 if (declaration) {
201 declaration->BindPipelineContext(pipelineContext_);
202 declaration->InitializeStyle();
203 }
204 node->SetAttr(attrs_);
205
206 if (animationStyles_) {
207 node->SetAnimationStyle(*animationStyles_);
208 }
209 if (transitionEnter_) {
210 node->SetIsTransition(true);
211 node->SetIsEnter(true);
212 node->SetAnimationStyle(*transitionEnter_);
213 }
214 if (transitionExit_) {
215 node->SetIsTransition(true);
216 node->SetIsEnter(false);
217 node->SetAnimationStyle(*transitionExit_);
218 }
219 if (sharedTransitionName_) {
220 node->SetSharedTransitionStyle(*sharedTransitionName_);
221 }
222
223 UpdateForChart(node);
224 UpdateForImageAnimator(node);
225 UpdateForClock(node);
226 UpdateForBadge(node);
227 UpdateForStepperLabel(node);
228 UpdateForInput(node);
229 node->SetStyle(styles_);
230 node->AddEvent(pageId, events_);
231 return node;
232 }
233
CreateDomElement(const RefPtr<JsAcePage> & page) const234 RefPtr<DOMNode> JsCommandDomElementCreator::CreateDomElement(const RefPtr<JsAcePage>& page) const
235 {
236 if (!page) {
237 return nullptr;
238 }
239 auto pageId = page->GetPageId();
240 auto domDocument = page->GetDomDocument();
241 ACE_DCHECK(domDocument);
242
243 std::string tagName = tagName_;
244 auto node = domDocument->CreateNodeWithId(tagName, nodeId_, -1);
245 if (!node) {
246 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
247 return nullptr;
248 }
249 if (page->IsLiteStyle()) {
250 node->AdjustParamInLiteMode();
251 }
252 node->SetBoxWrap(page->IsUseBoxWrap());
253
254 TrySaveTargetAndIdNode(id_, target_, domDocument, node);
255 node->SetShareId(shareId_);
256 node->SetPipelineContext(pipelineContext_);
257 node->SetIsCustomComponent(isCustomComponent_);
258 node->InitializeStyle();
259 node->SetAttr(attrs_);
260 if (animationStyles_) {
261 node->SetAnimationStyle(*animationStyles_);
262 }
263 if (transitionEnter_) {
264 node->SetIsTransition(true);
265 node->SetIsEnter(true);
266 node->SetAnimationStyle(*transitionEnter_);
267 }
268 if (transitionExit_) {
269 node->SetIsTransition(true);
270 node->SetIsEnter(false);
271 node->SetAnimationStyle(*transitionExit_);
272 }
273 if (sharedTransitionName_) {
274 node->SetSharedTransitionStyle(*sharedTransitionName_);
275 }
276
277 UpdateForChart(node);
278 UpdateForImageAnimator(node);
279 UpdateForClock(node);
280 UpdateForBadge(node);
281 UpdateForStepperLabel(node);
282 UpdateForInput(node);
283 node->SetStyle(styles_);
284 node->AddEvent(pageId, events_);
285 return node;
286 }
287
288
MountDomNode(const RefPtr<DOMNode> & node,const RefPtr<DOMDocument> & domDocument,NodeId parentNodeId) const289 void JsCommandDomElementCreator::MountDomNode(
290 const RefPtr<DOMNode>& node, const RefPtr<DOMDocument>& domDocument, NodeId parentNodeId) const
291 {
292 if (!node || !domDocument) {
293 return;
294 }
295 // useProxyNode flag is used for the dom node which is out of its previous order.
296 // For example, navigation bar is used to set outside the root div, thus there should be a proxy node in
297 // its previous order.
298 bool useProxyNode = false;
299 bool isIgnored = false;
300 if (tagName_ == DOM_NODE_TAG_NAVIGATION_BAR) {
301 auto rootStack = domDocument->GetRootStackComponent();
302 if (rootStack && !rootStack->HasNavigationBar()) {
303 node->GenerateComponentNode();
304 rootStack->SetNavigationBar(node->GetRootComponent());
305 useProxyNode = true;
306 isIgnored = true;
307 }
308 } else if (node->GetPosition() == PositionType::PTFIXED) {
309 const auto& rootStack = domDocument->GetRootStackComponent();
310 if (rootStack) {
311 rootStack->AppendChild(node->GetRootComponent());
312 // mount node to root
313 node->Mount(-1);
314 ScheduleUpdateForFixedNode(domDocument);
315 useProxyNode = true;
316 }
317 }
318 if (useProxyNode) {
319 // mount proxy dom node to replace the position of original node
320 auto proxy = CreateDomProxy(domDocument, parentNodeId);
321 if (proxy) {
322 proxy->ConnectWith(node);
323 proxy->SetIsIgnored(isIgnored);
324 proxy->Mount(itemIndex_);
325 }
326 } else {
327 node->Mount(itemIndex_);
328 }
329 }
330
CreateDomProxy(const RefPtr<DOMDocument> & domDocument,NodeId parentNodeId) const331 RefPtr<DOMProxy> JsCommandDomElementCreator::CreateDomProxy(
332 const RefPtr<DOMDocument>& domDocument, NodeId parentNodeId) const
333 {
334 RefPtr<DOMNode> parentNode;
335 if (parentNodeId != -1) {
336 parentNode = domDocument->GetDOMNodeById(parentNodeId);
337 if (!parentNode) {
338 return nullptr;
339 }
340 }
341 // generate proxy id in DomDocument
342 auto proxy = domDocument->CreateProxyNodeWithId(tagName_, nodeId_);
343 if (!proxy) {
344 return nullptr;
345 }
346
347 proxy->SetParentNode(parentNode);
348 proxy->SetPipelineContext(pipelineContext_);
349 proxy->SetProxyNode(true);
350 return proxy;
351 }
352
ScheduleUpdateForFixedNode(const RefPtr<DOMDocument> & domDocument) const353 void JsCommandDomElementCreator::ScheduleUpdateForFixedNode(const RefPtr<DOMDocument>& domDocument) const
354 {
355 const auto& rootComposedStack = domDocument->GetRootComposedStack();
356 if (rootComposedStack) {
357 rootComposedStack->MarkNeedUpdate();
358 auto context = pipelineContext_.Upgrade();
359 if (context) {
360 context->ScheduleUpdate(rootComposedStack);
361 }
362 }
363 }
364
Execute(const RefPtr<JsAcePage> & page) const365 void JsCommandCreateDomBody::Execute(const RefPtr<JsAcePage>& page) const
366 {
367 auto domDocument = page ? page->GetDomDocument() : nullptr;
368 if (!domDocument) {
369 LOGE("Failed to get DOM document");
370 EventReport::SendJsException(JsExcepType::CREATE_DOM_BODY_ERR);
371 return;
372 }
373
374 auto node = CreateDomNode(page);
375 if (!node) {
376 return;
377 }
378
379 auto transition = node->BuildTransitionComponent();
380 page->SetPageTransition(transition);
381 node->GenerateComponentNode();
382 domDocument->SetPipelineContext(pipelineContext_);
383 domDocument->SetUpRootComponent(node);
384
385 if (tagName_ == DOM_NODE_TAG_OPTION) {
386 return; // option of menu and select for popup do not need auto creating
387 }
388
389 // create root accessibility node
390 auto accessibilityManager = GetAccessibilityManager(page);
391 if (!accessibilityManager) {
392 LOGW("accessibilityManager not exists");
393 return;
394 }
395
396 accessibilityManager->SetRootNodeId(domDocument->GetRootNodeId());
397 auto accessibilityNode = accessibilityManager->CreateAccessibilityNode(tagName_, nodeId_, -1, itemIndex_);
398 if (!accessibilityNode) {
399 return;
400 }
401 accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
402 accessibilityNode->SetAttr(attrs_);
403 #if defined(PREVIEW)
404 accessibilityNode->SetStyle(styles_);
405 #endif
406 accessibilityNode->AddEvent(page->GetPageId(), events_);
407 }
408
Execute(const RefPtr<JsAcePage> & page) const409 void JsCommandCreateDomElement::Execute(const RefPtr<JsAcePage>& page) const
410 {
411 auto domDocument = page ? page->GetDomDocument() : nullptr;
412 if (!domDocument) {
413 LOGE("Failed to get DOM document");
414 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
415 return;
416 }
417 auto node = CreateDomElement(page);
418 if (!node) {
419 LOGE("node is nullptr");
420 return;
421 }
422 }
Execute(const RefPtr<JsAcePage> & page) const423 void JsCommandAddDomElement::Execute(const RefPtr<JsAcePage>& page) const
424 {
425 auto domDocument = page ? page->GetDomDocument() : nullptr;
426 if (!domDocument) {
427 LOGE("Failed to get DOM document");
428 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
429 return;
430 }
431
432 auto node = CreateDomNode(page, parentNodeId_);
433 if (!node) {
434 return;
435 }
436 MountDomNode(node, domDocument, parentNodeId_);
437
438 if (tagName_ == DOM_NODE_TAG_CANVAS) {
439 auto bridge = JsEngineLoader::Get().CreateCanvasBridge();
440 page->PushCanvasBridge(nodeId_, bridge);
441 }
442
443 if (tagName_ == DOM_NODE_TAG_XCOMPONENT) {
444 auto bridge = JsEngineLoader::Get().CreateXComponentBridge();
445 page->PushXComponentBridge(nodeId_, bridge);
446 }
447
448 page->PushNewNode(nodeId_, parentNodeId_);
449
450 // create other accessibility node
451 auto accessibilityManager = GetAccessibilityManager(page);
452 if (!accessibilityManager) {
453 LOGW("accessibilityManager not exists");
454 return;
455 }
456 if (tagName_ == DOM_NODE_TAG_OPTION) {
457 return; // option of menu and select for popup do not need auto creating
458 }
459 auto accessibilityNode =
460 accessibilityManager->CreateAccessibilityNode(tagName_, nodeId_, parentNodeId_, itemIndex_);
461 if (!accessibilityNode) {
462 return;
463 }
464 accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
465 accessibilityNode->SetAttr(attrs_);
466 #if defined(PREVIEW)
467 accessibilityNode->SetStyle(styles_);
468 if (!animationStyles_) {
469 return;
470 }
471 for (const auto& animationNameKeyframe : *animationStyles_.get()) {
472 auto animationName = animationNameKeyframe.find(DOM_ANIMATION_NAME);
473 if (animationName != animationNameKeyframe.end()) {
474 std::vector<std::pair<std::string, std::string>> vector;
475 vector.emplace_back(DOM_ANIMATION_NAME, animationName->second);
476 accessibilityNode->SetStyle(vector);
477 }
478 }
479 #endif
480 accessibilityNode->AddEvent(page->GetPageId(), events_);
481 }
482
Execute(const RefPtr<JsAcePage> & page) const483 void JsCommandRemoveDomElement::Execute(const RefPtr<JsAcePage>& page) const
484 {
485 auto domDocument = page ? page->GetDomDocument() : nullptr;
486 if (!domDocument) {
487 LOGE("Failed to get DOM document");
488 EventReport::SendJsException(JsExcepType::REMOVE_DOM_ELEMENT_ERR);
489 return;
490 }
491
492 auto node = domDocument->GetDOMNodeById(nodeId_);
493 if (!node) {
494 LOGE("Node %{private}d not exists", nodeId_);
495 EventReport::SendJsException(JsExcepType::REMOVE_DOM_ELEMENT_ERR);
496 return;
497 }
498
499 auto parentNodeId = node->GetParentId();
500 domDocument->RemoveNodes(node, true);
501 page->PushDirtyNode(parentNodeId);
502
503 // remove accessibility node and it's children
504 auto accessibilityManager = GetAccessibilityManager(page);
505 if (!accessibilityManager) {
506 LOGW("accessibilityManager not exists");
507 return;
508 }
509 auto accessibilityNode = accessibilityManager->GetAccessibilityNodeById(nodeId_);
510 if (!accessibilityNode) {
511 LOGE("Accessibility Node %{private}d not exists", nodeId_);
512 return;
513 }
514 accessibilityManager->RemoveAccessibilityNodes(accessibilityNode);
515 }
516
Execute(const RefPtr<JsAcePage> & page) const517 void JsCommandAppendElement::Execute(const RefPtr<JsAcePage>& page) const
518 {
519 auto domDocument = page ? page->GetDomDocument() : nullptr;
520 if (!domDocument) {
521 LOGE("Failed to get DOM document");
522 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
523 return;
524 }
525 auto node = GetNodeFromPage(page, nodeId_);
526 if (!node) {
527 LOGE("node is nullptr");
528 return;
529 }
530 RefPtr<DOMNode> parentNode;
531 int32_t parentNodeId = parentNodeId_;
532 if (parentNodeId != -1) {
533 parentNode = domDocument->GetDOMNodeById(parentNodeId);
534 if (!parentNode) {
535 LOGE("Parent node %{private}d not exists", nodeId_);
536 EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
537 }
538 }
539 node->SetParentNode(parentNode);
540
541 MountDomNode(node, domDocument, parentNodeId_);
542 page->PushNewNode(nodeId_, parentNodeId_);
543 }
544
Execute(const RefPtr<JsAcePage> & page) const545 void JsCommandUpdateDomElementAttrs::Execute(const RefPtr<JsAcePage>& page) const
546 {
547 auto node = GetNodeFromPage(page, nodeId_);
548 if (!node) {
549 LOGE("Node %{private}d not exists", nodeId_);
550 EventReport::SendJsException(JsExcepType::UPDATE_DOM_ELEMENT_ERR);
551 return;
552 }
553 if (page->IsLiteStyle()) {
554 node->AdjustParamInLiteMode();
555 }
556 if (page->CheckShowCommandConsumed()) {
557 auto showAttr = std::find_if(std::begin(attrs_), std::end(attrs_),
558 [](const std::pair<std::string, std::string>& attr) { return attr.first == DOM_SHOW; });
559 if (showAttr != std::end(attrs_)) {
560 return;
561 }
562 }
563 TrySaveTargetAndIdNode(id_, target_, page->GetDomDocument(), node);
564 node->SetBoxWrap(page->IsUseBoxWrap());
565 node->SetAttr(attrs_);
566 node->SetShareId(shareId_);
567 UpdateForChart(node);
568 UpdateForImageAnimator(node);
569 UpdateForClock(node);
570 UpdateForBadge(node);
571 UpdateForStepperLabel(node);
572 UpdateForInput(node);
573
574 node->GenerateComponentNode();
575 page->PushDirtyNode(node->GetDirtyNodeId());
576
577 // update accessibility node
578 auto accessibilityManager = GetAccessibilityManager(page);
579 if (!accessibilityManager) {
580 LOGW("accessibilityManager not exists");
581 return;
582 }
583 auto accessibilityNode = accessibilityManager->GetAccessibilityNodeById(nodeId_);
584 if (!accessibilityNode) {
585 LOGE("Accessibility Node %{private}d not exists", nodeId_);
586 return;
587 }
588 accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
589 accessibilityNode->SetAttr(attrs_);
590 }
591
Execute(const RefPtr<JsAcePage> & page) const592 void JsCommandUpdateDomElementStyles::Execute(const RefPtr<JsAcePage>& page) const
593 {
594 auto node = GetNodeFromPage(page, nodeId_);
595 if (!node) {
596 LOGE("Node %{private}d not exists", nodeId_);
597 EventReport::SendJsException(JsExcepType::UPDATE_DOM_ELEMENT_ERR);
598 return;
599 }
600 if (animationStyles_) {
601 node->SetAnimationStyle(*animationStyles_);
602 }
603 DisplayType displayType = node->GetDisplay();
604 if (displayType == DisplayType::INLINE) {
605 std::vector < std::pair < std::string, std::string >> stylesTemp;
606 for (int32_t i = 0; i < static_cast<int32_t>(styles_.size()); i++) {
607 std::string key = styles_[i].first;
608 std::string value = styles_[i].second;
609 if (key == "width" || key == "height" || key.find("margin") != std::string::npos ||
610 key.find("padding") != std::string::npos) {
611 continue;
612 }
613 stylesTemp.emplace_back(key, value);
614 }
615 node->SetStyle(stylesTemp);
616 } else {
617 node->SetStyle(styles_);
618 }
619
620 node->GenerateComponentNode();
621 page->PushDirtyNode(nodeId_);
622
623 #if defined(PREVIEW)
624 // update accessibility node
625 auto accessibilityManager = GetAccessibilityManager(page);
626 if (!accessibilityManager) {
627 LOGE("accessibilityManager not exists");
628 return;
629 }
630 auto accessibilityNode = accessibilityManager->GetAccessibilityNodeById(nodeId_);
631 if (!accessibilityNode) {
632 LOGE("Accessibility Node %{private}d not exists", nodeId_);
633 return;
634 }
635 accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
636 accessibilityNode->SetStyle(styles_);
637 #endif
638 }
639
Execute(const RefPtr<JsAcePage> & page) const640 void JsCommandCallDomElementMethod::Execute(const RefPtr<JsAcePage>& page) const
641 {
642 auto node = GetNodeFromPage(page, nodeId_);
643 if (!node) {
644 LOGE("Node %{private}d not exists", nodeId_);
645 return;
646 }
647 if (method_ == DOM_FOCUS) {
648 page->UpdateShowAttr();
649 }
650 auto declaration = node->GetDeclaration();
651 if (declaration &&
652 std::find(g_declarationNodes.begin(), g_declarationNodes.end(), node->GetTag()) != g_declarationNodes.end()) {
653 declaration->CallMethod(method_, param_);
654 } else {
655 node->CallMethod(method_, param_);
656 }
657 }
658
Execute(const RefPtr<JsAcePage> & page) const659 void JsCommandContextOperation::Execute(const RefPtr<JsAcePage>& page) const
660 {
661 if (!task_) {
662 return;
663 }
664 auto canvas = AceType::DynamicCast<DOMCanvas>(GetNodeFromPage(page, nodeId_));
665 if (!canvas) {
666 LOGE("Node %{private}d not exists or not a canvas", nodeId_);
667 return;
668 }
669 auto paintChild = AceType::DynamicCast<CustomPaintComponent>(canvas->GetSpecializedComponent());
670 ACE_DCHECK(paintChild);
671 auto pool = paintChild->GetTaskPool();
672 if (!pool) {
673 LOGE("canvas get pool failed");
674 return;
675 }
676 task_(pool);
677 }
678
Execute(const RefPtr<JsAcePage> & page) const679 void JsCommandXComponentOperation::Execute(const RefPtr<JsAcePage>& page) const
680 {
681 if (!task_) {
682 return;
683 }
684 auto xcomponent = AceType::DynamicCast<DOMXComponent>(GetNodeFromPage(page, nodeId_));
685 if (!xcomponent) {
686 LOGE("Node %{private}d not exists or not a xcomponent", nodeId_);
687 return;
688 }
689 auto child = AceType::DynamicCast<XComponentComponent>(xcomponent->GetSpecializedComponent());
690 ACE_DCHECK(child);
691 auto pool = child->GetTaskPool();
692 if (!pool) {
693 LOGE("xcomponent get pool failed");
694 return;
695 }
696 task_(pool);
697 }
698
Execute(const RefPtr<JsAcePage> & page) const699 void JsCommandAnimation::Execute(const RefPtr<JsAcePage>& page) const
700 {
701 if (!page) {
702 LOGE("execute animation command failed. page is null.");
703 return;
704 }
705 if (task_) {
706 task_->AnimationBridgeTaskFunc(page, nodeId_);
707 }
708 }
709
Execute(const RefPtr<JsAcePage> & page) const710 void JsCommandAnimator::Execute(const RefPtr<JsAcePage>& page) const
711 {
712 if (!page) {
713 LOGE("execute animation command failed. page is null.");
714 return;
715 }
716 if (task_) {
717 task_->AnimatorBridgeTaskFunc(page, bridgeId_);
718 }
719 }
720
721 } // namespace OHOS::Ace::Framework
722