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