• 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             LOGD("added navigation bar node");
309             useProxyNode = true;
310             isIgnored = true;
311         }
312     } else if (node->GetPosition() == PositionType::PTFIXED) {
313         const auto& rootStack = domDocument->GetRootStackComponent();
314         if (rootStack) {
315             rootStack->AppendChild(node->GetRootComponent());
316             // mount node to root
317             node->Mount(-1);
318             ScheduleUpdateForFixedNode(domDocument);
319             useProxyNode = true;
320         }
321     }
322     LOGD("parent(=%{private}d) add child(=%{private}d) in slot(=%{private}d)", parentNodeId, nodeId_, itemIndex_);
323     if (useProxyNode) {
324         // mount proxy dom node to replace the position of original node
325         auto proxy = CreateDomProxy(domDocument, parentNodeId);
326         if (proxy) {
327             proxy->ConnectWith(node);
328             proxy->SetIsIgnored(isIgnored);
329             proxy->Mount(itemIndex_);
330         }
331     } else {
332         node->Mount(itemIndex_);
333     }
334 }
335 
CreateDomProxy(const RefPtr<DOMDocument> & domDocument,NodeId parentNodeId) const336 RefPtr<DOMProxy> JsCommandDomElementCreator::CreateDomProxy(
337     const RefPtr<DOMDocument>& domDocument, NodeId parentNodeId) const
338 {
339     RefPtr<DOMNode> parentNode;
340     if (parentNodeId != -1) {
341         parentNode = domDocument->GetDOMNodeById(parentNodeId);
342         if (!parentNode) {
343             return nullptr;
344         }
345     }
346     // generate proxy id in DomDocument
347     auto proxy = domDocument->CreateProxyNodeWithId(tagName_, nodeId_);
348     if (!proxy) {
349         return nullptr;
350     }
351 
352     proxy->SetParentNode(parentNode);
353     proxy->SetPipelineContext(pipelineContext_);
354     proxy->SetProxyNode(true);
355     return proxy;
356 }
357 
ScheduleUpdateForFixedNode(const RefPtr<DOMDocument> & domDocument) const358 void JsCommandDomElementCreator::ScheduleUpdateForFixedNode(const RefPtr<DOMDocument>& domDocument) const
359 {
360     const auto& rootComposedStack = domDocument->GetRootComposedStack();
361     if (rootComposedStack) {
362         rootComposedStack->MarkNeedUpdate();
363         auto context = pipelineContext_.Upgrade();
364         if (context) {
365             context->ScheduleUpdate(rootComposedStack);
366         }
367     }
368 }
369 
Execute(const RefPtr<JsAcePage> & page) const370 void JsCommandCreateDomBody::Execute(const RefPtr<JsAcePage>& page) const
371 {
372     auto domDocument = page ? page->GetDomDocument() : nullptr;
373     if (!domDocument) {
374         LOGE("Failed to get DOM document");
375         EventReport::SendJsException(JsExcepType::CREATE_DOM_BODY_ERR);
376         return;
377     }
378 
379     auto node = CreateDomNode(page);
380     if (!node) {
381         return;
382     }
383 
384     auto transition = node->BuildTransitionComponent();
385     page->SetPageTransition(transition);
386     node->GenerateComponentNode();
387     domDocument->SetPipelineContext(pipelineContext_);
388     domDocument->SetUpRootComponent(node);
389 
390     if (tagName_ == DOM_NODE_TAG_OPTION) {
391         return; // option of menu and select for popup do not need auto creating
392     }
393 
394     // create root accessibility node
395     auto accessibilityManager = GetAccessibilityManager(page);
396     if (!accessibilityManager) {
397         LOGW("accessibilityManager not exists");
398         return;
399     }
400 
401     accessibilityManager->SetRootNodeId(domDocument->GetRootNodeId());
402     auto accessibilityNode = accessibilityManager->CreateAccessibilityNode(tagName_, nodeId_, -1, itemIndex_);
403     if (!accessibilityNode) {
404         LOGD("Failed to create accessibility node %{public}s", tagName_.c_str());
405         return;
406     }
407     accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
408     accessibilityNode->SetAttr(attrs_);
409 #if defined(PREVIEW)
410     accessibilityNode->SetStyle(styles_);
411 #endif
412     accessibilityNode->AddEvent(page->GetPageId(), events_);
413 }
414 
Execute(const RefPtr<JsAcePage> & page) const415 void JsCommandCreateDomElement::Execute(const RefPtr<JsAcePage>& page) const
416 {
417     auto domDocument = page ? page->GetDomDocument() : nullptr;
418     if (!domDocument) {
419         LOGE("Failed to get DOM document");
420         EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
421         return;
422     }
423     auto node = CreateDomElement(page);
424     if (!node) {
425         LOGE("node is nullptr");
426         return;
427     }
428 }
Execute(const RefPtr<JsAcePage> & page) const429 void JsCommandAddDomElement::Execute(const RefPtr<JsAcePage>& page) const
430 {
431     auto domDocument = page ? page->GetDomDocument() : nullptr;
432     if (!domDocument) {
433         LOGE("Failed to get DOM document");
434         EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
435         return;
436     }
437 
438     auto node = CreateDomNode(page, parentNodeId_);
439     if (!node) {
440         return;
441     }
442     MountDomNode(node, domDocument, parentNodeId_);
443 
444     if (tagName_ == DOM_NODE_TAG_CANVAS) {
445         auto bridge = JsEngineLoader::Get().CreateCanvasBridge();
446         page->PushCanvasBridge(nodeId_, bridge);
447     }
448 
449     if (tagName_ == DOM_NODE_TAG_XCOMPONENT) {
450         auto bridge = JsEngineLoader::Get().CreateXComponentBridge();
451         page->PushXComponentBridge(nodeId_, bridge);
452     }
453 
454     page->PushNewNode(nodeId_, parentNodeId_);
455 
456     // create other accessibility node
457     auto accessibilityManager = GetAccessibilityManager(page);
458     if (!accessibilityManager) {
459         LOGW("accessibilityManager not exists");
460         return;
461     }
462     if (tagName_ == DOM_NODE_TAG_OPTION) {
463         return; // option of menu and select for popup do not need auto creating
464     }
465     auto accessibilityNode =
466         accessibilityManager->CreateAccessibilityNode(tagName_, nodeId_, parentNodeId_, itemIndex_);
467     if (!accessibilityNode) {
468         LOGD("Failed to create accessibility node %{public}s", tagName_.c_str());
469         return;
470     }
471     accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
472     accessibilityNode->SetAttr(attrs_);
473 #if defined(PREVIEW)
474     accessibilityNode->SetStyle(styles_);
475     if (!animationStyles_) {
476         return;
477     }
478     for (const auto& animationNameKeyframe : *animationStyles_.get()) {
479         auto animationName = animationNameKeyframe.find(DOM_ANIMATION_NAME);
480         if (animationName != animationNameKeyframe.end()) {
481             std::vector<std::pair<std::string, std::string>> vector;
482             vector.emplace_back(DOM_ANIMATION_NAME, animationName->second);
483             accessibilityNode->SetStyle(vector);
484         }
485     }
486 #endif
487     accessibilityNode->AddEvent(page->GetPageId(), events_);
488 }
489 
Execute(const RefPtr<JsAcePage> & page) const490 void JsCommandRemoveDomElement::Execute(const RefPtr<JsAcePage>& page) const
491 {
492     auto domDocument = page ? page->GetDomDocument() : nullptr;
493     if (!domDocument) {
494         LOGE("Failed to get DOM document");
495         EventReport::SendJsException(JsExcepType::REMOVE_DOM_ELEMENT_ERR);
496         return;
497     }
498 
499     auto node = domDocument->GetDOMNodeById(nodeId_);
500     if (!node) {
501         LOGE("Node %{private}d not exists", nodeId_);
502         EventReport::SendJsException(JsExcepType::REMOVE_DOM_ELEMENT_ERR);
503         return;
504     }
505 
506     auto parentNodeId = node->GetParentId();
507     domDocument->RemoveNodes(node, true);
508     page->PushDirtyNode(parentNodeId);
509 
510     // remove accessibility node and it's children
511     auto accessibilityManager = GetAccessibilityManager(page);
512     if (!accessibilityManager) {
513         LOGW("accessibilityManager not exists");
514         return;
515     }
516     auto accessibilityNode = accessibilityManager->GetAccessibilityNodeById(nodeId_);
517     if (!accessibilityNode) {
518         LOGE("Accessibility Node %{private}d not exists", nodeId_);
519         return;
520     }
521     accessibilityManager->RemoveAccessibilityNodes(accessibilityNode);
522 }
523 
Execute(const RefPtr<JsAcePage> & page) const524 void JsCommandAppendElement::Execute(const RefPtr<JsAcePage>& page) const
525 {
526     auto domDocument = page ? page->GetDomDocument() : nullptr;
527     if (!domDocument) {
528         LOGE("Failed to get DOM document");
529         EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
530         return;
531     }
532     auto node = GetNodeFromPage(page, nodeId_);
533     if (!node) {
534         LOGE("node is nullptr");
535         return;
536     }
537     RefPtr<DOMNode> parentNode;
538     int32_t parentNodeId = parentNodeId_;
539     if (parentNodeId != -1) {
540         parentNode = domDocument->GetDOMNodeById(parentNodeId);
541         if (!parentNode) {
542             LOGE("Parent node %{private}d not exists", nodeId_);
543             EventReport::SendJsException(JsExcepType::CREATE_NODE_ERR);
544         }
545     }
546     node->SetParentNode(parentNode);
547 
548     MountDomNode(node, domDocument, parentNodeId_);
549     page->PushNewNode(nodeId_, parentNodeId_);
550 }
551 
Execute(const RefPtr<JsAcePage> & page) const552 void JsCommandUpdateDomElementAttrs::Execute(const RefPtr<JsAcePage>& page) const
553 {
554     auto node = GetNodeFromPage(page, nodeId_);
555     if (!node) {
556         LOGE("Node %{private}d not exists", nodeId_);
557         EventReport::SendJsException(JsExcepType::UPDATE_DOM_ELEMENT_ERR);
558         return;
559     }
560     if (page->IsLiteStyle()) {
561         node->AdjustParamInLiteMode();
562     }
563     if (page->CheckShowCommandConsumed()) {
564         auto showAttr = std::find_if(std::begin(attrs_), std::end(attrs_),
565             [](const std::pair<std::string, std::string>& attr) { return attr.first == DOM_SHOW; });
566         if (showAttr != std::end(attrs_)) {
567             return;
568         }
569     }
570     TrySaveTargetAndIdNode(id_, target_, page->GetDomDocument(), node);
571     node->SetBoxWrap(page->IsUseBoxWrap());
572     node->SetAttr(attrs_);
573     node->SetShareId(shareId_);
574     UpdateForChart(node);
575     UpdateForImageAnimator(node);
576     UpdateForClock(node);
577     UpdateForBadge(node);
578     UpdateForStepperLabel(node);
579     UpdateForInput(node);
580 
581     node->GenerateComponentNode();
582     page->PushDirtyNode(node->GetDirtyNodeId());
583 
584     // update accessibility node
585     auto accessibilityManager = GetAccessibilityManager(page);
586     if (!accessibilityManager) {
587         LOGW("accessibilityManager not exists");
588         return;
589     }
590     auto accessibilityNode = accessibilityManager->GetAccessibilityNodeById(nodeId_);
591     if (!accessibilityNode) {
592         LOGE("Accessibility Node %{private}d not exists", nodeId_);
593         return;
594     }
595     accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
596     accessibilityNode->SetAttr(attrs_);
597 }
598 
Execute(const RefPtr<JsAcePage> & page) const599 void JsCommandUpdateDomElementStyles::Execute(const RefPtr<JsAcePage>& page) const
600 {
601     auto node = GetNodeFromPage(page, nodeId_);
602     if (!node) {
603         LOGE("Node %{private}d not exists", nodeId_);
604         EventReport::SendJsException(JsExcepType::UPDATE_DOM_ELEMENT_ERR);
605         return;
606     }
607     if (animationStyles_) {
608         node->SetAnimationStyle(*animationStyles_);
609     }
610     DisplayType displayType = node->GetDisplay();
611     if (displayType == DisplayType::INLINE) {
612         std::vector < std::pair < std::string, std::string >> stylesTemp;
613         for (int32_t i = 0; i < static_cast<int32_t>(styles_.size()); i++) {
614             std::string key = styles_[i].first;
615             std::string value = styles_[i].second;
616             if (key == "width" || key == "height" || key.find("margin") != std::string::npos ||
617                 key.find("padding") != std::string::npos) {
618                 continue;
619             }
620             stylesTemp.emplace_back(key, value);
621         }
622         node->SetStyle(stylesTemp);
623     } else {
624         node->SetStyle(styles_);
625     }
626 
627     node->GenerateComponentNode();
628     page->PushDirtyNode(nodeId_);
629 
630 #if defined(PREVIEW)
631     // update accessibility node
632     auto accessibilityManager = GetAccessibilityManager(page);
633     if (!accessibilityManager) {
634         LOGE("accessibilityManager not exists");
635         return;
636     }
637     auto accessibilityNode = accessibilityManager->GetAccessibilityNodeById(nodeId_);
638     if (!accessibilityNode) {
639         LOGE("Accessibility Node %{private}d not exists", nodeId_);
640         return;
641     }
642     accessibilityManager->TrySaveTargetAndIdNode(id_, target_, accessibilityNode);
643     accessibilityNode->SetStyle(styles_);
644 #endif
645 }
646 
Execute(const RefPtr<JsAcePage> & page) const647 void JsCommandCallDomElementMethod::Execute(const RefPtr<JsAcePage>& page) const
648 {
649     auto node = GetNodeFromPage(page, nodeId_);
650     if (!node) {
651         LOGE("Node %{private}d not exists", nodeId_);
652         return;
653     }
654     if (method_ == DOM_FOCUS) {
655         page->UpdateShowAttr();
656     }
657     auto declaration = node->GetDeclaration();
658     if (declaration &&
659         std::find(g_declarationNodes.begin(), g_declarationNodes.end(), node->GetTag()) != g_declarationNodes.end()) {
660         declaration->CallMethod(method_, param_);
661     } else {
662         node->CallMethod(method_, param_);
663     }
664 }
665 
Execute(const RefPtr<JsAcePage> & page) const666 void JsCommandContextOperation::Execute(const RefPtr<JsAcePage>& page) const
667 {
668     if (!task_) {
669         return;
670     }
671     auto canvas = AceType::DynamicCast<DOMCanvas>(GetNodeFromPage(page, nodeId_));
672     if (!canvas) {
673         LOGE("Node %{private}d not exists or not a canvas", nodeId_);
674         return;
675     }
676     auto paintChild = AceType::DynamicCast<CustomPaintComponent>(canvas->GetSpecializedComponent());
677     ACE_DCHECK(paintChild);
678     auto pool = paintChild->GetTaskPool();
679     if (!pool) {
680         LOGE("canvas get pool failed");
681         return;
682     }
683     task_(pool);
684 }
685 
Execute(const RefPtr<JsAcePage> & page) const686 void JsCommandXComponentOperation::Execute(const RefPtr<JsAcePage>& page) const
687 {
688     if (!task_) {
689         return;
690     }
691     auto xcomponent = AceType::DynamicCast<DOMXComponent>(GetNodeFromPage(page, nodeId_));
692     if (!xcomponent) {
693         LOGE("Node %{private}d not exists or not a xcomponent", nodeId_);
694         return;
695     }
696     auto child = AceType::DynamicCast<XComponentComponent>(xcomponent->GetSpecializedComponent());
697     ACE_DCHECK(child);
698     auto pool = child->GetTaskPool();
699     if (!pool) {
700         LOGE("xcomponent get pool failed");
701         return;
702     }
703     task_(pool);
704 }
705 
Execute(const RefPtr<JsAcePage> & page) const706 void JsCommandAnimation::Execute(const RefPtr<JsAcePage>& page) const
707 {
708     if (!page) {
709         LOGE("execute animation command failed. page is null.");
710         return;
711     }
712     if (task_) {
713         task_->AnimationBridgeTaskFunc(page, nodeId_);
714     }
715 }
716 
Execute(const RefPtr<JsAcePage> & page) const717 void JsCommandAnimator::Execute(const RefPtr<JsAcePage>& page) const
718 {
719     if (!page) {
720         LOGE("execute animation command failed. page is null.");
721         return;
722     }
723     if (task_) {
724         task_->AnimatorBridgeTaskFunc(page, bridgeId_);
725     }
726 }
727 
728 } // namespace OHOS::Ace::Framework
729