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