• 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 #if defined(CAMERA_FRAMEWORK_EXISTS) && defined(PLAYER_FRAMEWORK_EXISTS)
91 #include "frameworks/bridge/common/dom/dom_camera.h"
92 #endif
93 #include "frameworks/bridge/common/dom/dom_menu.h"
94 #include "frameworks/bridge/common/dom/dom_navigation_menu.h"
95 #include "frameworks/bridge/common/dom/dom_option.h"
96 #include "frameworks/bridge/common/dom/dom_picker_dialog.h"
97 #include "frameworks/bridge/common/dom/dom_piece.h"
98 #include "frameworks/bridge/common/dom/dom_popup.h"
99 #include "frameworks/bridge/common/dom/dom_rating.h"
100 #include "frameworks/bridge/common/dom/dom_select.h"
101 #include "frameworks/bridge/common/dom/dom_stepper.h"
102 #include "frameworks/bridge/common/dom/dom_stepper_item.h"
103 #include "frameworks/bridge/common/dom/dom_tab_bar.h"
104 #include "frameworks/bridge/common/dom/dom_tab_content.h"
105 #include "frameworks/bridge/common/dom/dom_tabs.h"
106 #include "frameworks/bridge/common/dom/dom_tool_bar.h"
107 #include "frameworks/bridge/common/dom/dom_tool_bar_item.h"
108 #if defined(PLAYER_FRAMEWORK_EXISTS)
109 #include "frameworks/bridge/common/dom/dom_video.h"
110 #endif
111 #if !defined(PREVIEW)
112 #ifdef WEB_SUPPORTED
113 #include "frameworks/bridge/common/dom/dom_web.h"
114 #endif
115 #endif
116 #endif
117 
118 namespace OHOS::Ace::Framework {
119 RefPtr<PixelMap> DOMDocument::pixelMap_;
120 int32_t DOMDocument::pixelMapOffsetX_ = 0;
121 int32_t DOMDocument::pixelMapOffsetY_ = 0;
122 namespace {
123 
124 // avoid same with root node id
125 constexpr int32_t PROXY_ID = 10000000;
126 const char PROXY_PREFIX[] = "proxy_";
127 const int32_t ROOT_STACK_ID = -1;
128 const char ROOT_STACK_NAME[] = "ComposedStack";
129 
130 template<class T>
DOMNodeCreator(NodeId nodeId,const std::string & tag,int32_t)131 RefPtr<DOMNode> DOMNodeCreator(NodeId nodeId, const std::string& tag, int32_t)
132 {
133     return AceType::MakeRefPtr<T>(nodeId, tag);
134 }
135 
136 template<class T>
DOMListItemCreator(NodeId nodeId,const std::string & tag,int32_t itemIndex)137 RefPtr<DOMNode> DOMListItemCreator(NodeId nodeId, const std::string& tag, int32_t itemIndex)
138 {
139     return AceType::MakeRefPtr<T>(nodeId, tag, itemIndex);
140 }
141 
142 } // namespace
143 
~DOMDocument()144 DOMDocument::~DOMDocument()
145 {
146     CHECK_RUN_ON(UI);
147     LOG_DESTROY();
148 }
149 
CreateNodeWithId(const std::string & tag,NodeId nodeId,int32_t itemIndex)150 RefPtr<DOMNode> DOMDocument::CreateNodeWithId(const std::string& tag, NodeId nodeId, int32_t itemIndex)
151 {
152     static const LinearMapNode<RefPtr<DOMNode> (*)(NodeId, const std::string&, int32_t)> domNodeCreators[] = {
153         { DOM_NODE_TAG_ANIMATE, &DOMNodeCreator<DOMSvgAnimate> },
154         { DOM_NODE_TAG_ANIMATE_MOTION, &DOMNodeCreator<DOMSvgAnimateMotion> },
155         { DOM_NODE_TAG_ANIMATE_TRANSFORM, &DOMNodeCreator<DOMSvgAnimateTransform> },
156         { DOM_NODE_TAG_BADGE, &DOMNodeCreator<DOMBadge> },
157         { DOM_NODE_TAG_BUTTON, &DOMNodeCreator<DOMButton> },
158         { DOM_NODE_TAG_CALENDAR, &DOMNodeCreator<DomCalendar> },
159 #ifndef WEARABLE_PRODUCT
160 #if defined(CAMERA_FRAMEWORK_EXISTS) && defined(PLAYER_FRAMEWORK_EXISTS)
161         { DOM_NODE_TAG_CAMERA, &DOMNodeCreator<DOMCamera> },
162 #endif
163 #endif
164         { DOM_NODE_TAG_CANVAS, &DOMNodeCreator<DOMCanvas> },
165         { DOM_NODE_TAG_CHART, &DOMNodeCreator<DOMChart> },
166         { DOM_NODE_TAG_CIRCLE, &DOMNodeCreator<DOMSvgCircle> },
167         { DOM_NODE_TAG_CLOCK, &DOMNodeCreator<DOMClock> },
168         { DOM_NODE_TAG_DEFS, &DOMNodeCreator<DOMSvgDefs> },
169         { DOM_NODE_TAG_DIALOG, &DOMNodeCreator<DOMDialog> },
170         { DOM_NODE_TAG_DIV, &DOMNodeCreator<DOMDiv> },
171         { DOM_NODE_TAG_DIVIDER, &DOMNodeCreator<DOMDivider> },
172         { DOM_NODE_TAG_ELLIPSE, &DOMNodeCreator<DOMSvgEllipse> },
173         { DOM_NODE_TAG_FE_COLORMATRIX, &DOMNodeCreator<DOMSvgFeColorMatrix> },
174         { DOM_NODE_TAG_FE_COMPOSITE, &DOMNodeCreator<DOMSvgFeComposite> },
175         { DOM_NODE_TAG_FE_GAUSSIANBLUR, &DOMNodeCreator<DOMSvgFeGaussianBlur> },
176         { DOM_NODE_TAG_FE_OFFSET, &DOMNodeCreator<DOMSvgFeOffset> },
177         { DOM_NODE_TAG_FILTER, &DOMNodeCreator<DOMSvgFilter> },
178         { DOM_NODE_TAG_FORM, &DOMNodeCreator<DOMForm> },
179         { DOM_NODE_TAG_G, &DOMNodeCreator<DOMSvgG> },
180         { DOM_NODE_TAG_GRID_COLUMN, &DOMNodeCreator<DomGridColumn> },
181         { DOM_NODE_TAG_GRID_CONTAINER, &DOMNodeCreator<DomGridContainer> },
182         { DOM_NODE_TAG_GRID_ROW, &DOMNodeCreator<DomGridRow> },
183         { DOM_NODE_TAG_IMAGE, &DOMNodeCreator<DOMImage> },
184         { DOM_NODE_TAG_IMAGE_ANIMATOR, &DOMNodeCreator<DOMImageAnimator> },
185         { DOM_NODE_TAG_INPUT, &DOMNodeCreator<DOMInput> },
186         { DOM_NODE_TAG_LABEL, &DOMNodeCreator<DOMLabel> },
187         { DOM_NODE_TAG_LINE, &DOMNodeCreator<DOMSvgLine> },
188         { DOM_NODE_TAG_LIST, &DOMNodeCreator<DOMList> },
189         { DOM_NODE_TAG_LIST_ITEM, &DOMListItemCreator<DOMListItem> },
190         { DOM_NODE_TAG_LIST_ITEM_GROUP, &DOMListItemCreator<DOMListItemGroup> },
191         { DOM_NODE_TAG_MARQUEE, &DOMNodeCreator<DOMMarquee> },
192         { DOM_NODE_TAG_MASK, &DOMNodeCreator<DOMSvgMask> },
193 #ifndef WEARABLE_PRODUCT
194         { DOM_NODE_TAG_MENU, &DOMNodeCreator<DOMMenu> },
195 #endif
196         { DOM_NODE_TAG_NAVIGATION_BAR, &DOMNodeCreator<DomNavigationBar> },
197 #ifndef WEARABLE_PRODUCT
198         { DOM_NODE_TAG_NAVIGATION_MENU, &DOMNodeCreator<DOMNavigationMenu> },
199         { DOM_NODE_TAG_OPTION, &DOMNodeCreator<DOMOption> },
200         { DOM_NODE_TAG_PANEL, &DOMNodeCreator<DOMPanel> },
201 #endif
202         { DOM_NODE_TAG_PATH, &DOMNodeCreator<DOMSvgPath> },
203 #ifndef WEARABLE_PRODUCT
204         { DOM_NODE_TAG_PICKER_DIALOG, &DOMNodeCreator<DOMPickerDialog> },
205 #endif
206         { DOM_NODE_TAG_PICKER_VIEW, &DOMNodeCreator<DOMPickerView> },
207         { DOM_NODE_TAG_POLYGON, &DOMNodeCreator<DOMSvgPolygon> },
208         { DOM_NODE_TAG_POLYLINE, &DOMNodeCreator<DOMSvgPolyline> },
209 #ifndef WEARABLE_PRODUCT
210         { DOM_NODE_TAG_POPUP, &DOMNodeCreator<DOMPopup> },
211 #endif
212         { DOM_NODE_TAG_PROGRESS, &DOMNodeCreator<DOMProgress> },
213         { DOM_NODE_TAG_QRCODE, &DOMNodeCreator<DOMQrcode> },
214 #ifndef WEARABLE_PRODUCT
215         { DOM_NODE_TAG_RATING, &DOMNodeCreator<DOMRating> },
216 #endif
217         { DOM_NODE_TAG_RECT, &DOMNodeCreator<DOMSvgRect> },
218         { DOM_NODE_TAG_REFRESH, &DOMNodeCreator<DOMRefresh> },
219 #ifdef WEB_SUPPORTED
220         { DOM_NODE_TAG_RICH_TEXT, &DOMNodeCreator<DOMRichText> },
221 #endif
222         { DOM_NODE_TAG_SEARCH, &DOMNodeCreator<DOMSearch> },
223 #ifndef WEARABLE_PRODUCT
224         { DOM_NODE_TAG_SELECT, &DOMNodeCreator<DOMSelect> },
225 #endif
226         { DOM_NODE_TAG_SLIDER, &DOMNodeCreator<DOMSlider> },
227         { DOM_NODE_TAG_SPAN, &DOMNodeCreator<DOMSpan> },
228         { DOM_NODE_TAG_STACK, &DOMNodeCreator<DOMStack> },
229 #ifndef WEARABLE_PRODUCT
230         { DOM_NODE_TAG_STEPPER, &DOMNodeCreator<DOMStepper> },
231         { DOM_NODE_TAG_STEPPER_ITEM, &DOMListItemCreator<DOMStepperItem> },
232 #endif
233         { DOM_NODE_TAG_SVG, &DOMNodeCreator<DOMSvg> },
234         { DOM_NODE_TAG_SVG_TEXT, &DOMNodeCreator<DOMSvgText> },
235         { DOM_NODE_TAG_SWIPER, &DOMNodeCreator<DOMSwiper> },
236         { DOM_NODE_TAG_SWITCH, &DOMNodeCreator<DOMSwitch> },
237 #ifndef WEARABLE_PRODUCT
238         { DOM_NODE_TAG_TAB_BAR, &DOMNodeCreator<DOMTabBar> },
239         { DOM_NODE_TAG_TAB_CONTENT, &DOMNodeCreator<DOMTabContent> },
240         { DOM_NODE_TAG_TABS, &DOMNodeCreator<DOMTabs> },
241 #endif
242         { DOM_NODE_TAG_TEXT, &DOMNodeCreator<DOMText> },
243         { DOM_NODE_TAG_TEXTAREA, &DOMNodeCreator<DOMTextarea> },
244         { DOM_NODE_TAG_TEXT_PATH, &DOMNodeCreator<DOMSvgTextPath> },
245         { DOM_NODE_TAG_TOGGLE, &DOMNodeCreator<DOMToggle> },
246 #ifndef WEARABLE_PRODUCT
247         { DOM_NODE_TAG_TOOL_BAR, &DOMNodeCreator<DOMToolBar> },
248         { DOM_NODE_TAG_TOOL_BAR_ITEM, &DOMNodeCreator<DOMToolBarItem> },
249 #endif
250         { DOM_NODE_TAG_TSPAN, &DOMNodeCreator<DOMSvgTspan> },
251         { DOM_NODE_TAG_USE, &DOMNodeCreator<DOMSvgUse> },
252 #ifndef WEARABLE_PRODUCT
253 #if defined(PLAYER_FRAMEWORK_EXISTS)
254         { DOM_NODE_TAG_VIDEO, &DOMNodeCreator<DOMVideo> },
255 #endif
256 #ifdef WEB_SUPPORTED
257         { DOM_NODE_TAG_WEB, &DOMNodeCreator<DOMWeb> },
258 #endif
259 #endif
260 #ifdef XCOMPONENT_SUPPORTED
261         { DOM_NODE_TAG_XCOMPONENT, &DOMNodeCreator<DOMXComponent> },
262 #endif
263     };
264 #ifndef WEARABLE_PRODUCT
265     static const LinearMapNode<RefPtr<DOMNode> (*)(NodeId, const std::string&, int32_t)> phoneNodeCreators[] = {
266         { DOM_NODE_TAG_PIECE, &DOMNodeCreator<DOMPiece> },
267     };
268 #endif
269 
270     RefPtr<DOMNode> domNode;
271     int64_t creatorIndex = BinarySearchFindIndex(domNodeCreators, ArraySize(domNodeCreators), tag.c_str());
272     if (creatorIndex >= 0) {
273         domNode = domNodeCreators[creatorIndex].value(nodeId, tag, itemIndex);
274 #ifndef WEARABLE_PRODUCT
275     } else {
276         if (SystemProperties::GetDeviceType() == DeviceType::PHONE ||
277             SystemProperties::GetDeviceType() == DeviceType::TABLET ||
278             SystemProperties::GetDeviceType() == DeviceType::TWO_IN_ONE) {
279             creatorIndex = BinarySearchFindIndex(phoneNodeCreators, ArraySize(phoneNodeCreators), tag.c_str());
280             if (creatorIndex >= 0) {
281                 domNode = phoneNodeCreators[creatorIndex].value(nodeId, tag, itemIndex);
282             }
283         } else {
284             return nullptr;
285         }
286 #endif
287     }
288     if (!domNode) {
289 #if defined(PREVIEW)
290         if (std::strcmp(tag.c_str(), DOM_NODE_TAG_WEB) == 0 || std::strcmp(tag.c_str(), DOM_NODE_TAG_XCOMPONENT) == 0 ||
291             std::strcmp(tag.c_str(), DOM_NODE_TAG_RICH_TEXT) == 0) {
292             LOGW("[Engine Log] Unable to use the %{public}s component in the Previewer. Perform this operation on the "
293                  "emulator or a real device instead.",
294                 tag.c_str());
295         }
296 #endif
297         return nullptr;
298     }
299 
300     auto result = domNodes_.try_emplace(nodeId, domNode);
301     if (!result.second) {
302         return nullptr;
303     }
304     domNode->SetIsRootNode(nodeId == rootNodeId_);
305     domNode->SetPageId(rootNodeId_ - DOM_ROOT_NODE_ID_BASE);
306     return domNode;
307 }
308 
CreateProxyNodeWithId(const std::string & tag,NodeId nodeId)309 RefPtr<DOMProxy> DOMDocument::CreateProxyNodeWithId(const std::string& tag, NodeId nodeId)
310 {
311     // generate proxy tag and id, proxy id marked different from root tag id
312     std::string proxyTag = std::string(PROXY_PREFIX) + tag;
313     NodeId proxyId = PROXY_ID + nodeId;
314     auto proxy = AceType::MakeRefPtr<DOMProxy>(proxyId, proxyTag);
315     auto result = domNodes_.try_emplace(proxyId, proxy);
316     if (!result.second) {
317         return nullptr;
318     }
319     proxyRelatedNode_.emplace(nodeId);
320     return proxy;
321 }
322 
GetDOMNodeById(NodeId nodeId) const323 RefPtr<DOMNode> DOMDocument::GetDOMNodeById(NodeId nodeId) const
324 {
325     const auto itNode = domNodes_.find(nodeId);
326     if (itNode == domNodes_.end()) {
327         LOGI("the node is not in the map");
328         return nullptr;
329     }
330     return itNode->second;
331 }
332 
RemoveNodes(const RefPtr<DOMNode> & node,bool scheduleUpdate)333 void DOMDocument::RemoveNodes(const RefPtr<DOMNode>& node, bool scheduleUpdate)
334 {
335     if (!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     for (auto iterTarget = nodeWithTargetVec_.begin(); iterTarget != nodeWithTargetVec_.end();) {
407         auto targetNode = iterTarget->second.Upgrade();
408         if (!targetNode) {
409             LOGW("DOM Node with target %{public}s has been invalid", iterTarget->first.c_str());
410             iterTarget = nodeWithTargetVec_.erase(iterTarget);
411             continue;
412         }
413 
414         for (auto iterId = nodeWithIdVec_.begin(); iterId != nodeWithIdVec_.end();) {
415             auto idNode = iterId->second.Upgrade();
416             if (!idNode) {
417                 LOGW("DOM Node with id %{public}s has been invalid, add targetNode fail", iterId->first.c_str());
418                 iterId = nodeWithIdVec_.erase(iterId);
419                 continue;
420             }
421 
422             if (iterTarget->first != iterId->first) {
423                 ++iterId;
424                 continue;
425             }
426 
427             auto component = targetNode->GetSpecializedComponent();
428             if (AceType::InstanceOf<TouchListenerComponent>(component)) {
429                 auto labelNode = AceType::DynamicCast<DOMLabel>(targetNode);
430                 if (labelNode) {
431                     labelNode->SetTargetNode(idNode);
432                 }
433 #ifndef WEARABLE_PRODUCT
434             } else if (AceType::InstanceOf<PopupComponent>(component)) {
435                 auto popupNode = AceType::DynamicCast<DOMPopup>(targetNode);
436                 if (popupNode) {
437                     // DOMPopup bind node with ID node
438                     popupNode->BindIdNode(idNode);
439                 }
440             } else if (AceType::InstanceOf<MenuComponent>(component)) {
441                 auto menuNode = AceType::DynamicCast<DOMMenu>(targetNode);
442                 if (menuNode) {
443                     // DOMMenu bind node with ID node
444                     menuNode->BindIdNode(idNode);
445                 }
446             } else if (AceType::InstanceOf<DOMTabBar>(targetNode)) {
447                 auto tabBarNode = AceType::DynamicCast<DOMTabBar>(targetNode);
448                 // DOMTabBar in navigation bar bind tabs with ID node
449                 tabBarNode->BindToTabs(idNode);
450 #endif
451             }
452             ++iterId;
453         }
454         ++iterTarget;
455     }
456 }
457 
HandlePageLoadFinish()458 void DOMDocument::HandlePageLoadFinish()
459 {
460     for (auto iter : domNodes_) {
461         if (iter.second) {
462             iter.second->OnPageLoadFinish();
463         }
464     }
465 }
466 
SetUpRootComponent(const RefPtr<DOMNode> & node)467 void DOMDocument::SetUpRootComponent(const RefPtr<DOMNode>& node)
468 {
469     if (!node) {
470         EventReport::SendComponentException(ComponentExcepType::SET_ROOT_DOM_NODE_ERR);
471         return;
472     }
473     std::list<RefPtr<Component>> stackChildren { node->GetRootComponent() };
474     rootStackComponent_ = AceType::MakeRefPtr<StackComponent>(
475         Alignment::TOP_LEFT, StackFit::INHERIT, Overflow::OBSERVABLE, stackChildren);
476     auto context = pipelineContext_.Upgrade();
477     if (context && !context->IsFullScreenModal()) {
478         rootStackComponent_->SetMainStackSize(MainStackSize::MIN);
479         rootStackComponent_->SetStackFit(StackFit::FIRST_CHILD);
480     } else {
481         rootStackComponent_->SetMainStackSize(MainStackSize::MAX);
482     }
483     rootComposedStack_ =
484         AceType::MakeRefPtr<ComposedComponent>(std::to_string(ROOT_STACK_ID - rootNodeId_), ROOT_STACK_NAME);
485     rootComposedStack_->SetChild(rootStackComponent_);
486 }
487 
488 } // namespace OHOS::Ace::Framework
489