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 creatorIndex = BinarySearchFindIndex(phoneNodeCreators, ArraySize(phoneNodeCreators), tag.c_str());
274 if (creatorIndex >= 0) {
275 domNode = phoneNodeCreators[creatorIndex].value(nodeId, tag, itemIndex);
276 }
277 } else {
278 LOGW("node type %{public}s is invalid", tag.c_str());
279 return nullptr;
280 }
281 #endif
282 }
283 if (!domNode) {
284 #if defined(PREVIEW)
285 if (std::strcmp(tag.c_str(), DOM_NODE_TAG_WEB) == 0 || std::strcmp(tag.c_str(), DOM_NODE_TAG_XCOMPONENT) == 0 ||
286 std::strcmp(tag.c_str(), DOM_NODE_TAG_RICH_TEXT) == 0) {
287 LOGW("[Engine Log] Unable to use the %{public}s component in the Previewer. Perform this operation on the "
288 "emulator or a real device instead.",
289 tag.c_str());
290 }
291 #endif
292 LOGW("node type %{public}s is invalid", tag.c_str());
293 return nullptr;
294 }
295
296 auto result = domNodes_.try_emplace(nodeId, domNode);
297 if (!result.second) {
298 LOGW("the node has already in the map");
299 return nullptr;
300 }
301 domNode->SetIsRootNode(nodeId == rootNodeId_);
302 domNode->SetPageId(rootNodeId_ - DOM_ROOT_NODE_ID_BASE);
303 return domNode;
304 }
305
CreateProxyNodeWithId(const std::string & tag,NodeId nodeId)306 RefPtr<DOMProxy> DOMDocument::CreateProxyNodeWithId(const std::string& tag, NodeId nodeId)
307 {
308 // generate proxy tag and id, proxy id marked different from root tag id
309 std::string proxyTag = std::string(PROXY_PREFIX) + tag;
310 NodeId proxyId = PROXY_ID + nodeId;
311 auto proxy = AceType::MakeRefPtr<DOMProxy>(proxyId, proxyTag);
312 auto result = domNodes_.try_emplace(proxyId, proxy);
313 if (!result.second) {
314 LOGW("the node has already in the map");
315 return nullptr;
316 }
317 proxyRelatedNode_.emplace(nodeId);
318 return proxy;
319 }
320
GetDOMNodeById(NodeId nodeId) const321 RefPtr<DOMNode> DOMDocument::GetDOMNodeById(NodeId nodeId) const
322 {
323 const auto itNode = domNodes_.find(nodeId);
324 if (itNode == domNodes_.end()) {
325 LOGE("the node is not in the map");
326 return nullptr;
327 }
328 return itNode->second;
329 }
330
RemoveNodes(const RefPtr<DOMNode> & node,bool scheduleUpdate)331 void DOMDocument::RemoveNodes(const RefPtr<DOMNode>& node, bool scheduleUpdate)
332 {
333 if (!node) {
334 LOGE("remove null node");
335 return;
336 }
337 auto children = node->GetChildList();
338 for (auto it = children.begin(); it != children.end();) {
339 RemoveNodes(*it++, scheduleUpdate);
340 }
341 auto parentId = node->GetParentId();
342 RefPtr<DOMNode> parentNode;
343 if (parentId != -1) {
344 parentNode = GetDOMNodeById(parentId);
345 if (parentNode) {
346 parentNode->RemoveNode(node);
347 }
348 }
349 // Fixed positioned node and navigation bar node need to delete the relative proxy node.
350 if (node->GetPosition() == PositionType::PTFIXED && rootStackComponent_) {
351 rootStackComponent_->RemoveChild(node->GetRootComponent());
352 auto context = node->GetPipelineContext().Upgrade();
353 if (context && scheduleUpdate) {
354 context->ScheduleUpdate(rootComposedStack_);
355 }
356 auto proxyId = node->GetNodeId() + PROXY_ID;
357 auto proxy = GetDOMNodeById(proxyId);
358 if (proxy) {
359 if (parentNode) {
360 parentNode->RemoveNode(proxy);
361 }
362 domNodes_.erase(proxyId);
363 proxyRelatedNode_.erase(node->GetNodeId());
364 }
365 }
366 if (node->GetTag() == DOM_NODE_TAG_NAVIGATION_BAR && rootStackComponent_ &&
367 rootStackComponent_->HasNavigationBar()) {
368 auto rootColumn = AceType::DynamicCast<ColumnComponent>(rootStackComponent_->GetChildren().front());
369 if (rootColumn) {
370 rootColumn->RemoveChild(node->GetRootComponent());
371 auto proxyId = node->GetNodeId() + PROXY_ID;
372 auto proxy = GetDOMNodeById(proxyId);
373 if (proxy) {
374 if (parentNode) {
375 parentNode->RemoveNode(proxy);
376 }
377 domNodes_.erase(proxyId);
378 proxyRelatedNode_.erase(node->GetNodeId());
379 }
380 }
381 }
382 domNodes_.erase(node->GetNodeId());
383 }
384
AddNodeWithId(const std::string & key,const RefPtr<DOMNode> & domNode)385 void DOMDocument::AddNodeWithId(const std::string& key, const RefPtr<DOMNode>& domNode)
386 {
387 nodeWithIdVec_.emplace_back(key, domNode);
388 }
389
AddNodeWithTarget(const std::string & key,const RefPtr<DOMNode> & domNode)390 void DOMDocument::AddNodeWithTarget(const std::string& key, const RefPtr<DOMNode>& domNode)
391 {
392 // Always save only one (the last) 'target' dom node
393 for (auto iter = nodeWithTargetVec_.begin(); iter != nodeWithTargetVec_.end();) {
394 if (iter->first == key) {
395 iter = nodeWithTargetVec_.erase(iter);
396 } else {
397 ++iter;
398 }
399 }
400 nodeWithTargetVec_.emplace_back(key, domNode);
401 }
402
HandleComponentPostBinding()403 void DOMDocument::HandleComponentPostBinding()
404 {
405 LOGD("HandleComponentPostBinding");
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 } else {
452 LOGW("component type not supported");
453 }
454 ++iterId;
455 }
456 ++iterTarget;
457 }
458 }
459
HandlePageLoadFinish()460 void DOMDocument::HandlePageLoadFinish()
461 {
462 for (auto iter : domNodes_) {
463 if (iter.second) {
464 iter.second->OnPageLoadFinish();
465 }
466 }
467 }
468
SetUpRootComponent(const RefPtr<DOMNode> & node)469 void DOMDocument::SetUpRootComponent(const RefPtr<DOMNode>& node)
470 {
471 LOGD("DOMDocument SetUpRootComponent");
472 if (!node) {
473 LOGE("fail to set up root component due to node is null");
474 EventReport::SendComponentException(ComponentExcepType::SET_ROOT_DOM_NODE_ERR);
475 return;
476 }
477 std::list<RefPtr<Component>> stackChildren { node->GetRootComponent() };
478 rootStackComponent_ = AceType::MakeRefPtr<StackComponent>(
479 Alignment::TOP_LEFT, StackFit::INHERIT, Overflow::OBSERVABLE, stackChildren);
480 auto context = pipelineContext_.Upgrade();
481 if (context && !context->IsFullScreenModal()) {
482 rootStackComponent_->SetMainStackSize(MainStackSize::MIN);
483 rootStackComponent_->SetStackFit(StackFit::FIRST_CHILD);
484 } else {
485 rootStackComponent_->SetMainStackSize(MainStackSize::MAX);
486 }
487 rootComposedStack_ =
488 AceType::MakeRefPtr<ComposedComponent>(std::to_string(ROOT_STACK_ID - rootNodeId_), ROOT_STACK_NAME);
489 rootComposedStack_->SetChild(rootStackComponent_);
490 }
491
492 } // namespace OHOS::Ace::Framework
493