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