• 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/common/dom/dom_document.h"
17 
18 #include "base/log/event_report.h"
19 #include "base/utils/linear_map.h"
20 #include "base/utils/utils.h"
21 #include "core/common/thread_checker.h"
22 #include "core/components/flex/flex_item_component.h"
23 #include "frameworks/bridge/common/dom/dom_button.h"
24 #include "frameworks/bridge/common/dom/dom_calendar.h"
25 #include "frameworks/bridge/common/dom/dom_canvas.h"
26 #include "frameworks/bridge/common/dom/dom_chart.h"
27 #include "frameworks/bridge/common/dom/dom_clock.h"
28 #include "frameworks/bridge/common/dom/dom_dialog.h"
29 #include "frameworks/bridge/common/dom/dom_div.h"
30 #include "frameworks/bridge/common/dom/dom_divider.h"
31 #include "frameworks/bridge/common/dom/dom_form.h"
32 #include "frameworks/bridge/common/dom/dom_grid_column.h"
33 #include "frameworks/bridge/common/dom/dom_grid_container.h"
34 #include "frameworks/bridge/common/dom/dom_grid_row.h"
35 #include "frameworks/bridge/common/dom/dom_image.h"
36 #include "frameworks/bridge/common/dom/dom_image_animator.h"
37 #include "frameworks/bridge/common/dom/dom_input.h"
38 #include "frameworks/bridge/common/dom/dom_label.h"
39 #include "frameworks/bridge/common/dom/dom_list.h"
40 #include "frameworks/bridge/common/dom/dom_list_item.h"
41 #include "frameworks/bridge/common/dom/dom_list_item_group.h"
42 #include "frameworks/bridge/common/dom/dom_marquee.h"
43 #include "frameworks/bridge/common/dom/dom_navigation_bar.h"
44 #include "frameworks/bridge/common/dom/dom_panel.h"
45 #include "frameworks/bridge/common/dom/dom_picker_view.h"
46 #include "frameworks/bridge/common/dom/dom_progress.h"
47 #include "frameworks/bridge/common/dom/dom_proxy.h"
48 #include "frameworks/bridge/common/dom/dom_qrcode.h"
49 #include "frameworks/bridge/common/dom/dom_refresh.h"
50 #ifdef WEB_SUPPORTED
51 #include "frameworks/bridge/common/dom/dom_rich_text.h"
52 #endif
53 #include "frameworks/bridge/common/dom/dom_search.h"
54 #include "frameworks/bridge/common/dom/dom_slider.h"
55 #include "frameworks/bridge/common/dom/dom_span.h"
56 #include "frameworks/bridge/common/dom/dom_stack.h"
57 #include "frameworks/bridge/common/dom/dom_svg.h"
58 #include "frameworks/bridge/common/dom/dom_svg_animate.h"
59 #include "frameworks/bridge/common/dom/dom_svg_animate_motion.h"
60 #include "frameworks/bridge/common/dom/dom_svg_animate_transform.h"
61 #include "frameworks/bridge/common/dom/dom_svg_circle.h"
62 #include "frameworks/bridge/common/dom/dom_svg_defs.h"
63 #include "frameworks/bridge/common/dom/dom_svg_ellipse.h"
64 #include "frameworks/bridge/common/dom/dom_svg_fe_colormatrix.h"
65 #include "frameworks/bridge/common/dom/dom_svg_fe_composite.h"
66 #include "frameworks/bridge/common/dom/dom_svg_fe_gaussianblur.h"
67 #include "frameworks/bridge/common/dom/dom_svg_fe_offset.h"
68 #include "frameworks/bridge/common/dom/dom_svg_filter.h"
69 #include "frameworks/bridge/common/dom/dom_svg_g.h"
70 #include "frameworks/bridge/common/dom/dom_svg_line.h"
71 #include "frameworks/bridge/common/dom/dom_svg_mask.h"
72 #include "frameworks/bridge/common/dom/dom_svg_path.h"
73 #include "frameworks/bridge/common/dom/dom_svg_polygon.h"
74 #include "frameworks/bridge/common/dom/dom_svg_polyline.h"
75 #include "frameworks/bridge/common/dom/dom_svg_rect.h"
76 #include "frameworks/bridge/common/dom/dom_svg_text.h"
77 #include "frameworks/bridge/common/dom/dom_svg_text_path.h"
78 #include "frameworks/bridge/common/dom/dom_svg_tspan.h"
79 #include "frameworks/bridge/common/dom/dom_svg_use.h"
80 #include "frameworks/bridge/common/dom/dom_swiper.h"
81 #include "frameworks/bridge/common/dom/dom_switch.h"
82 #include "frameworks/bridge/common/dom/dom_text.h"
83 #include "frameworks/bridge/common/dom/dom_textarea.h"
84 #include "frameworks/bridge/common/dom/dom_toggle.h"
85 #if defined(XCOMPONENT_SUPPORTED)
86 #include "frameworks/bridge/common/dom/dom_xcomponent.h"
87 #endif
88 #ifndef WEARABLE_PRODUCT
89 #include "frameworks/bridge/common/dom/dom_badge.h"
90 #include "frameworks/bridge/common/dom/dom_camera.h"
91 #include "frameworks/bridge/common/dom/dom_menu.h"
92 #include "frameworks/bridge/common/dom/dom_navigation_menu.h"
93 #include "frameworks/bridge/common/dom/dom_option.h"
94 #include "frameworks/bridge/common/dom/dom_picker_dialog.h"
95 #include "frameworks/bridge/common/dom/dom_piece.h"
96 #include "frameworks/bridge/common/dom/dom_popup.h"
97 #include "frameworks/bridge/common/dom/dom_rating.h"
98 #include "frameworks/bridge/common/dom/dom_select.h"
99 #include "frameworks/bridge/common/dom/dom_stepper.h"
100 #include "frameworks/bridge/common/dom/dom_stepper_item.h"
101 #include "frameworks/bridge/common/dom/dom_tab_bar.h"
102 #include "frameworks/bridge/common/dom/dom_tab_content.h"
103 #include "frameworks/bridge/common/dom/dom_tabs.h"
104 #include "frameworks/bridge/common/dom/dom_tool_bar.h"
105 #include "frameworks/bridge/common/dom/dom_tool_bar_item.h"
106 #include "frameworks/bridge/common/dom/dom_video.h"
107 #if !defined(PREVIEW)
108 #ifdef WEB_SUPPORTED
109 #include "frameworks/bridge/common/dom/dom_web.h"
110 #endif
111 #endif
112 #endif
113 
114 namespace OHOS::Ace::Framework {
115 RefPtr<PixelMap> DOMDocument::pixelMap_;
116 int32_t DOMDocument::pixelMapOffsetX_ = 0;
117 int32_t DOMDocument::pixelMapOffsetY_ = 0;
118 namespace {
119 
120 // avoid same with root node id
121 constexpr int32_t PROXY_ID = 10000000;
122 const char PROXY_PREFIX[] = "proxy_";
123 const int32_t ROOT_STACK_ID = -1;
124 const char ROOT_STACK_NAME[] = "ComposedStack";
125 
126 template<class T>
DOMNodeCreator(NodeId nodeId,const std::string & tag,int32_t)127 RefPtr<DOMNode> DOMNodeCreator(NodeId nodeId, const std::string& tag, int32_t)
128 {
129     return AceType::MakeRefPtr<T>(nodeId, tag);
130 }
131 
132 template<class T>
DOMListItemCreator(NodeId nodeId,const std::string & tag,int32_t itemIndex)133 RefPtr<DOMNode> DOMListItemCreator(NodeId nodeId, const std::string& tag, int32_t itemIndex)
134 {
135     return AceType::MakeRefPtr<T>(nodeId, tag, itemIndex);
136 }
137 
138 } // namespace
139 
~DOMDocument()140 DOMDocument::~DOMDocument()
141 {
142     CHECK_RUN_ON(UI);
143     LOG_DESTROY();
144 }
145 
CreateNodeWithId(const std::string & tag,NodeId nodeId,int32_t itemIndex)146 RefPtr<DOMNode> DOMDocument::CreateNodeWithId(const std::string& tag, NodeId nodeId, int32_t itemIndex)
147 {
148     LOGD("DOMDocument:created new DOMNode %{public}s, id %{public}d, itemIndex %{public}d", tag.c_str(), nodeId,
149          itemIndex);
150 
151     static const LinearMapNode<RefPtr<DOMNode>(*)(NodeId, const std::string&, int32_t)> domNodeCreators[] = {
152         { DOM_NODE_TAG_ANIMATE, &DOMNodeCreator<DOMSvgAnimate> },
153         { DOM_NODE_TAG_ANIMATE_MOTION, &DOMNodeCreator<DOMSvgAnimateMotion> },
154         { DOM_NODE_TAG_ANIMATE_TRANSFORM, &DOMNodeCreator<DOMSvgAnimateTransform> },
155         { DOM_NODE_TAG_BADGE, &DOMNodeCreator<DOMBadge> },
156         { DOM_NODE_TAG_BUTTON, &DOMNodeCreator<DOMButton> },
157         { DOM_NODE_TAG_CALENDAR, &DOMNodeCreator<DomCalendar> },
158 #ifndef WEARABLE_PRODUCT
159         { DOM_NODE_TAG_CAMERA, &DOMNodeCreator<DOMCamera> },
160 #endif
161         { DOM_NODE_TAG_CANVAS, &DOMNodeCreator<DOMCanvas> },
162         { DOM_NODE_TAG_CHART, &DOMNodeCreator<DOMChart> },
163         { DOM_NODE_TAG_CIRCLE, &DOMNodeCreator<DOMSvgCircle> },
164         { DOM_NODE_TAG_CLOCK, &DOMNodeCreator<DOMClock> },
165         { DOM_NODE_TAG_DEFS, &DOMNodeCreator<DOMSvgDefs> },
166         { DOM_NODE_TAG_DIALOG, &DOMNodeCreator<DOMDialog> },
167         { DOM_NODE_TAG_DIV, &DOMNodeCreator<DOMDiv> },
168         { DOM_NODE_TAG_DIVIDER, &DOMNodeCreator<DOMDivider> },
169         { DOM_NODE_TAG_ELLIPSE, &DOMNodeCreator<DOMSvgEllipse> },
170         { DOM_NODE_TAG_FE_COLORMATRIX, &DOMNodeCreator<DOMSvgFeColorMatrix> },
171         { DOM_NODE_TAG_FE_COMPOSITE, &DOMNodeCreator<DOMSvgFeComposite> },
172         { DOM_NODE_TAG_FE_GAUSSIANBLUR, &DOMNodeCreator<DOMSvgFeGaussianBlur> },
173         { DOM_NODE_TAG_FE_OFFSET, &DOMNodeCreator<DOMSvgFeOffset> },
174         { DOM_NODE_TAG_FILTER, &DOMNodeCreator<DOMSvgFilter> },
175         { DOM_NODE_TAG_FORM, &DOMNodeCreator<DOMForm> },
176         { DOM_NODE_TAG_G, &DOMNodeCreator<DOMSvgG> },
177         { DOM_NODE_TAG_GRID_COLUMN, &DOMNodeCreator<DomGridColumn> },
178         { DOM_NODE_TAG_GRID_CONTAINER, &DOMNodeCreator<DomGridContainer> },
179         { DOM_NODE_TAG_GRID_ROW, &DOMNodeCreator<DomGridRow> },
180         { DOM_NODE_TAG_IMAGE, &DOMNodeCreator<DOMImage> },
181         { DOM_NODE_TAG_IMAGE_ANIMATOR, &DOMNodeCreator<DOMImageAnimator> },
182         { DOM_NODE_TAG_INPUT, &DOMNodeCreator<DOMInput> },
183         { DOM_NODE_TAG_LABEL, &DOMNodeCreator<DOMLabel> },
184         { DOM_NODE_TAG_LINE, &DOMNodeCreator<DOMSvgLine> },
185         { DOM_NODE_TAG_LIST, &DOMNodeCreator<DOMList> },
186         { DOM_NODE_TAG_LIST_ITEM, &DOMListItemCreator<DOMListItem> },
187         { DOM_NODE_TAG_LIST_ITEM_GROUP, &DOMListItemCreator<DOMListItemGroup> },
188         { DOM_NODE_TAG_MARQUEE, &DOMNodeCreator<DOMMarquee> },
189         { DOM_NODE_TAG_MASK, &DOMNodeCreator<DOMSvgMask> },
190 #ifndef WEARABLE_PRODUCT
191         { DOM_NODE_TAG_MENU, &DOMNodeCreator<DOMMenu> },
192 #endif
193         { DOM_NODE_TAG_NAVIGATION_BAR, &DOMNodeCreator<DomNavigationBar> },
194 #ifndef WEARABLE_PRODUCT
195         { DOM_NODE_TAG_NAVIGATION_MENU, &DOMNodeCreator<DOMNavigationMenu> },
196         { DOM_NODE_TAG_OPTION, &DOMNodeCreator<DOMOption> },
197         { DOM_NODE_TAG_PANEL, &DOMNodeCreator<DOMPanel> },
198 #endif
199         { DOM_NODE_TAG_PATH, &DOMNodeCreator<DOMSvgPath> },
200 #ifndef WEARABLE_PRODUCT
201         { DOM_NODE_TAG_PICKER_DIALOG, &DOMNodeCreator<DOMPickerDialog> },
202 #endif
203         { DOM_NODE_TAG_PICKER_VIEW, &DOMNodeCreator<DOMPickerView> },
204         { DOM_NODE_TAG_POLYGON, &DOMNodeCreator<DOMSvgPolygon> },
205         { DOM_NODE_TAG_POLYLINE, &DOMNodeCreator<DOMSvgPolyline> },
206 #ifndef WEARABLE_PRODUCT
207         { DOM_NODE_TAG_POPUP, &DOMNodeCreator<DOMPopup> },
208 #endif
209         { DOM_NODE_TAG_PROGRESS, &DOMNodeCreator<DOMProgress> },
210         { DOM_NODE_TAG_QRCODE, &DOMNodeCreator<DOMQrcode> },
211 #ifndef WEARABLE_PRODUCT
212         { DOM_NODE_TAG_RATING, &DOMNodeCreator<DOMRating> },
213 #endif
214         { DOM_NODE_TAG_RECT, &DOMNodeCreator<DOMSvgRect> },
215         { DOM_NODE_TAG_REFRESH, &DOMNodeCreator<DOMRefresh> },
216 #ifdef WEB_SUPPORTED
217         { DOM_NODE_TAG_RICH_TEXT, &DOMNodeCreator<DOMRichText> },
218 #endif
219         { DOM_NODE_TAG_SEARCH, &DOMNodeCreator<DOMSearch> },
220 #ifndef WEARABLE_PRODUCT
221         { DOM_NODE_TAG_SELECT, &DOMNodeCreator<DOMSelect> },
222 #endif
223         { DOM_NODE_TAG_SLIDER, &DOMNodeCreator<DOMSlider> },
224         { DOM_NODE_TAG_SPAN, &DOMNodeCreator<DOMSpan> },
225         { DOM_NODE_TAG_STACK, &DOMNodeCreator<DOMStack> },
226 #ifndef WEARABLE_PRODUCT
227         { DOM_NODE_TAG_STEPPER, &DOMNodeCreator<DOMStepper> },
228         { DOM_NODE_TAG_STEPPER_ITEM, &DOMListItemCreator<DOMStepperItem> },
229 #endif
230         { DOM_NODE_TAG_SVG, &DOMNodeCreator<DOMSvg> },
231         { DOM_NODE_TAG_SVG_TEXT, &DOMNodeCreator<DOMSvgText> },
232         { DOM_NODE_TAG_SWIPER, &DOMNodeCreator<DOMSwiper> },
233         { DOM_NODE_TAG_SWITCH, &DOMNodeCreator<DOMSwitch> },
234 #ifndef WEARABLE_PRODUCT
235         { DOM_NODE_TAG_TAB_BAR, &DOMNodeCreator<DOMTabBar> },
236         { DOM_NODE_TAG_TAB_CONTENT, &DOMNodeCreator<DOMTabContent> },
237         { DOM_NODE_TAG_TABS, &DOMNodeCreator<DOMTabs> },
238 #endif
239         { DOM_NODE_TAG_TEXT, &DOMNodeCreator<DOMText> },
240         { DOM_NODE_TAG_TEXTAREA, &DOMNodeCreator<DOMTextarea> },
241         { DOM_NODE_TAG_TEXT_PATH, &DOMNodeCreator<DOMSvgTextPath> },
242         { DOM_NODE_TAG_TOGGLE, &DOMNodeCreator<DOMToggle> },
243 #ifndef WEARABLE_PRODUCT
244         { DOM_NODE_TAG_TOOL_BAR, &DOMNodeCreator<DOMToolBar> },
245         { DOM_NODE_TAG_TOOL_BAR_ITEM, &DOMNodeCreator<DOMToolBarItem> },
246 #endif
247         { DOM_NODE_TAG_TSPAN, &DOMNodeCreator<DOMSvgTspan> },
248         { DOM_NODE_TAG_USE, &DOMNodeCreator<DOMSvgUse> },
249 #ifndef WEARABLE_PRODUCT
250         { DOM_NODE_TAG_VIDEO, &DOMNodeCreator<DOMVideo> },
251 #ifdef WEB_SUPPORTED
252         { DOM_NODE_TAG_WEB, &DOMNodeCreator<DOMWeb> },
253 #endif
254 #endif
255 #ifdef XCOMPONENT_SUPPORTED
256         { DOM_NODE_TAG_XCOMPONENT, &DOMNodeCreator<DOMXComponent> },
257 #endif
258     };
259 #ifndef WEARABLE_PRODUCT
260     static const LinearMapNode<RefPtr<DOMNode>(*)(NodeId, const std::string&, int32_t)> phoneNodeCreators[] = {
261         { DOM_NODE_TAG_PIECE, &DOMNodeCreator<DOMPiece> },
262     };
263 #endif
264 
265     RefPtr<DOMNode> domNode;
266     int64_t creatorIndex = BinarySearchFindIndex(domNodeCreators, ArraySize(domNodeCreators), tag.c_str());
267     if (creatorIndex >= 0) {
268         domNode = domNodeCreators[creatorIndex].value(nodeId, tag, itemIndex);
269 #ifndef WEARABLE_PRODUCT
270     } else {
271         if (SystemProperties::GetDeviceType() == DeviceType::PHONE ||
272             SystemProperties::GetDeviceType() == DeviceType::TABLET ||
273             SystemProperties::GetDeviceType() == DeviceType::TWO_IN_ONE) {
274             creatorIndex = BinarySearchFindIndex(phoneNodeCreators, ArraySize(phoneNodeCreators), tag.c_str());
275             if (creatorIndex >= 0) {
276                 domNode = phoneNodeCreators[creatorIndex].value(nodeId, tag, itemIndex);
277             }
278         } else {
279             LOGW("node type %{public}s is invalid", tag.c_str());
280             return nullptr;
281         }
282 #endif
283     }
284     if (!domNode) {
285 #if defined(PREVIEW)
286         if (std::strcmp(tag.c_str(), DOM_NODE_TAG_WEB) == 0 || std::strcmp(tag.c_str(), DOM_NODE_TAG_XCOMPONENT) == 0 ||
287             std::strcmp(tag.c_str(), DOM_NODE_TAG_RICH_TEXT) == 0) {
288             LOGW("[Engine Log] Unable to use the %{public}s component in the Previewer. Perform this operation on the "
289                  "emulator or a real device instead.",
290                 tag.c_str());
291         }
292 #endif
293         LOGW("node type %{public}s is invalid", tag.c_str());
294         return nullptr;
295     }
296 
297     auto result = domNodes_.try_emplace(nodeId, domNode);
298     if (!result.second) {
299         LOGW("the node has already in the map");
300         return nullptr;
301     }
302     domNode->SetIsRootNode(nodeId == rootNodeId_);
303     domNode->SetPageId(rootNodeId_ - DOM_ROOT_NODE_ID_BASE);
304     return domNode;
305 }
306 
CreateProxyNodeWithId(const std::string & tag,NodeId nodeId)307 RefPtr<DOMProxy> DOMDocument::CreateProxyNodeWithId(const std::string& tag, NodeId nodeId)
308 {
309     // generate proxy tag and id, proxy id marked different from root tag id
310     std::string proxyTag = std::string(PROXY_PREFIX) + tag;
311     NodeId proxyId = PROXY_ID + nodeId;
312     auto proxy = AceType::MakeRefPtr<DOMProxy>(proxyId, proxyTag);
313     auto result = domNodes_.try_emplace(proxyId, proxy);
314     if (!result.second) {
315         LOGW("the node has already in the map");
316         return nullptr;
317     }
318     proxyRelatedNode_.emplace(nodeId);
319     return proxy;
320 }
321 
GetDOMNodeById(NodeId nodeId) const322 RefPtr<DOMNode> DOMDocument::GetDOMNodeById(NodeId nodeId) const
323 {
324     const auto itNode = domNodes_.find(nodeId);
325     if (itNode == domNodes_.end()) {
326         LOGE("the node is not in the map");
327         return nullptr;
328     }
329     return itNode->second;
330 }
331 
RemoveNodes(const RefPtr<DOMNode> & node,bool scheduleUpdate)332 void DOMDocument::RemoveNodes(const RefPtr<DOMNode>& node, bool scheduleUpdate)
333 {
334     if (!node) {
335         LOGE("remove null node");
336         return;
337     }
338     auto children = node->GetChildList();
339     for (auto it = children.begin(); it != children.end();) {
340         RemoveNodes(*it++, scheduleUpdate);
341     }
342     auto parentId = node->GetParentId();
343     RefPtr<DOMNode> parentNode;
344     if (parentId != -1) {
345         parentNode = GetDOMNodeById(parentId);
346         if (parentNode) {
347             parentNode->RemoveNode(node);
348         }
349     }
350     // Fixed positioned node and navigation bar node need to delete the relative proxy node.
351     if (node->GetPosition() == PositionType::PTFIXED && rootStackComponent_) {
352         rootStackComponent_->RemoveChild(node->GetRootComponent());
353         auto context = node->GetPipelineContext().Upgrade();
354         if (context && scheduleUpdate) {
355             context->ScheduleUpdate(rootComposedStack_);
356         }
357         auto proxyId = node->GetNodeId() + PROXY_ID;
358         auto proxy = GetDOMNodeById(proxyId);
359         if (proxy) {
360             if (parentNode) {
361                 parentNode->RemoveNode(proxy);
362             }
363             domNodes_.erase(proxyId);
364             proxyRelatedNode_.erase(node->GetNodeId());
365         }
366     }
367     if (node->GetTag() == DOM_NODE_TAG_NAVIGATION_BAR && rootStackComponent_ &&
368         rootStackComponent_->HasNavigationBar()) {
369         auto rootColumn = AceType::DynamicCast<ColumnComponent>(rootStackComponent_->GetChildren().front());
370         if (rootColumn) {
371             rootColumn->RemoveChild(node->GetRootComponent());
372             auto proxyId = node->GetNodeId() + PROXY_ID;
373             auto proxy = GetDOMNodeById(proxyId);
374             if (proxy) {
375                 if (parentNode) {
376                     parentNode->RemoveNode(proxy);
377                 }
378                 domNodes_.erase(proxyId);
379                 proxyRelatedNode_.erase(node->GetNodeId());
380             }
381         }
382     }
383     domNodes_.erase(node->GetNodeId());
384 }
385 
AddNodeWithId(const std::string & key,const RefPtr<DOMNode> & domNode)386 void DOMDocument::AddNodeWithId(const std::string& key, const RefPtr<DOMNode>& domNode)
387 {
388     nodeWithIdVec_.emplace_back(key, domNode);
389 }
390 
AddNodeWithTarget(const std::string & key,const RefPtr<DOMNode> & domNode)391 void DOMDocument::AddNodeWithTarget(const std::string& key, const RefPtr<DOMNode>& domNode)
392 {
393     // Always save only one (the last) 'target' dom node
394     for (auto iter = nodeWithTargetVec_.begin(); iter != nodeWithTargetVec_.end();) {
395         if (iter->first == key) {
396             iter = nodeWithTargetVec_.erase(iter);
397         } else {
398             ++iter;
399         }
400     }
401     nodeWithTargetVec_.emplace_back(key, domNode);
402 }
403 
HandleComponentPostBinding()404 void DOMDocument::HandleComponentPostBinding()
405 {
406     LOGD("HandleComponentPostBinding");
407     for (auto iterTarget = nodeWithTargetVec_.begin(); iterTarget != nodeWithTargetVec_.end();) {
408         auto targetNode = iterTarget->second.Upgrade();
409         if (!targetNode) {
410             LOGW("DOM:: Node with target %{public}s has been invalid", iterTarget->first.c_str());
411             iterTarget = nodeWithTargetVec_.erase(iterTarget);
412             continue;
413         }
414 
415         for (auto iterId = nodeWithIdVec_.begin(); iterId != nodeWithIdVec_.end();) {
416             auto idNode = iterId->second.Upgrade();
417             if (!idNode) {
418                 LOGW("DOM:: Node with id %{public}s has been invalid, add targetNode fail", iterId->first.c_str());
419                 iterId = nodeWithIdVec_.erase(iterId);
420                 continue;
421             }
422 
423             if (iterTarget->first != iterId->first) {
424                 ++iterId;
425                 continue;
426             }
427 
428             auto component = targetNode->GetSpecializedComponent();
429             if (AceType::InstanceOf<TouchListenerComponent>(component)) {
430                 auto labelNode = AceType::DynamicCast<DOMLabel>(targetNode);
431                 if (labelNode) {
432                     labelNode->SetTargetNode(idNode);
433                 }
434 #ifndef WEARABLE_PRODUCT
435             } else if (AceType::InstanceOf<PopupComponent>(component)) {
436                 auto popupNode = AceType::DynamicCast<DOMPopup>(targetNode);
437                 if (popupNode) {
438                     // DOMPopup bind node with ID node
439                     popupNode->BindIdNode(idNode);
440                 }
441             } else if (AceType::InstanceOf<MenuComponent>(component)) {
442                 auto menuNode = AceType::DynamicCast<DOMMenu>(targetNode);
443                 if (menuNode) {
444                     // DOMMenu bind node with ID node
445                     menuNode->BindIdNode(idNode);
446                 }
447             } else if (AceType::InstanceOf<DOMTabBar>(targetNode)) {
448                 auto tabBarNode = AceType::DynamicCast<DOMTabBar>(targetNode);
449                 // DOMTabBar in navigation bar bind tabs with ID node
450                 tabBarNode->BindToTabs(idNode);
451 #endif
452             } else {
453                 LOGW("component type not supported");
454             }
455             ++iterId;
456         }
457         ++iterTarget;
458     }
459 }
460 
HandlePageLoadFinish()461 void DOMDocument::HandlePageLoadFinish()
462 {
463     for (auto iter : domNodes_) {
464         if (iter.second) {
465             iter.second->OnPageLoadFinish();
466         }
467     }
468 }
469 
SetUpRootComponent(const RefPtr<DOMNode> & node)470 void DOMDocument::SetUpRootComponent(const RefPtr<DOMNode>& node)
471 {
472     LOGD("DOMDocument SetUpRootComponent");
473     if (!node) {
474         LOGE("fail to set up root component due to node is null");
475         EventReport::SendComponentException(ComponentExcepType::SET_ROOT_DOM_NODE_ERR);
476         return;
477     }
478     std::list<RefPtr<Component>> stackChildren { node->GetRootComponent() };
479     rootStackComponent_ = AceType::MakeRefPtr<StackComponent>(
480         Alignment::TOP_LEFT, StackFit::INHERIT, Overflow::OBSERVABLE, stackChildren);
481     auto context = pipelineContext_.Upgrade();
482     if (context && !context->IsFullScreenModal()) {
483         rootStackComponent_->SetMainStackSize(MainStackSize::MIN);
484         rootStackComponent_->SetStackFit(StackFit::FIRST_CHILD);
485     } else {
486         rootStackComponent_->SetMainStackSize(MainStackSize::MAX);
487     }
488     rootComposedStack_ =
489         AceType::MakeRefPtr<ComposedComponent>(std::to_string(ROOT_STACK_ID - rootNodeId_), ROOT_STACK_NAME);
490     rootComposedStack_->SetChild(rootStackComponent_);
491 }
492 
493 } // namespace OHOS::Ace::Framework
494