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