• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_NODE_H
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include "base/geometry/transform_util.h"
23 #include "base/json/json_util.h"
24 #include "base/memory/ace_type.h"
25 #include "base/utils/macros.h"
26 #include "core/animation/animation_util.h"
27 #include "core/animation/keyframe_animation.h"
28 #include "core/animation/property_animation.h"
29 #include "core/components/box/box_component.h"
30 #include "core/components/common/properties/shadow.h"
31 #include "core/components/declaration/common/declaration_creator_manager.h"
32 #include "core/components/display/display_component.h"
33 #include "core/components/flex/flex_component.h"
34 #include "core/components/flex/flex_item_component.h"
35 #include "core/components/focusable/focusable_component.h"
36 #include "core/components/gesture_listener/gesture_listener_component.h"
37 #include "core/components/list/list_component.h"
38 #include "core/components/mouse_listener/mouse_listener_component.h"
39 #include "core/components/page_transition/page_transition_component.h"
40 #include "core/components/positioned/positioned_component.h"
41 #include "core/components/shared_transition/shared_transition_component.h"
42 #include "core/components/stack/stack_component.h"
43 #include "core/components/swiper/swiper_component.h"
44 #include "core/components/theme/theme_utils.h"
45 #include "core/components/touch_listener/touch_listener_component.h"
46 #include "core/components/transform/transform_component.h"
47 #include "core/components/transition/transition_component.h"
48 #include "core/components/tween/tween_component.h"
49 #include "core/pipeline/pipeline_context.h"
50 #include "frameworks/bridge/common/dom/dom_type.h"
51 #include "frameworks/bridge/common/utils/transform_convertor.h"
52 #include "frameworks/core/animation/animatable_data.h"
53 
54 #ifndef WEARABLE_PRODUCT
55 #include "core/components/multimodal/multimodal_component.h"
56 #endif
57 
58 namespace OHOS::Ace::Framework {
59 
60 // If no insertion location is specified, new child will be added to the end of children list by default.
61 inline constexpr int32_t DEFAULT_ITEM_INDEX = -1;
62 
63 class ACE_EXPORT DOMNode : public virtual AceType {
64     DECLARE_ACE_TYPE(DOMNode, AceType);
65 
66 public:
67     DOMNode(NodeId nodeId, const std::string& nodeName);
68     ~DOMNode() override;
69 
70     void SetAnimationStyle(const std::vector<std::unordered_map<std::string, std::string>>& animationKeyframes);
71     bool ParseAnimationStyle(const std::vector<std::unordered_map<std::string, std::string>>& animationKeyframes);
72     void SetSharedTransitionStyle(const std::vector<std::unordered_map<std::string, std::string>>& animationKeyframes);
73     bool ParseTransitionPropertyStyle(const std::string& transitionProperty);
74     bool ParseTransitionNameStyle(const std::string& transitionName);
75     void CreateDeclaration(const std::string& tag);
76     void TweenOptionSetKeyframes(TweenOption& tweenOption);
77     void SetCustomAnimationStyleUpdate(bool enable);
78     void AddNode(const RefPtr<DOMNode>& node, int32_t slot = DEFAULT_ITEM_INDEX);
79     void RemoveNode(const RefPtr<DOMNode>& node);
80     virtual void Mount(int32_t slot);
81     void GenerateComponentNode();
OnPageLoadFinish()82     virtual void OnPageLoadFinish() {};
83 
84     virtual void SetShowAttr(const std::string& showValue);
85 
GetScrollComponent()86     virtual const RefPtr<ScrollComponent>& GetScrollComponent() const
87     {
88         return scrollComponent_;
89     }
90 
91     void MarkNeedUpdate();
92 
SetTweenComponent(const RefPtr<TweenComponent> & tweenComponent)93     void SetTweenComponent(const RefPtr<TweenComponent>& tweenComponent)
94     {
95         tweenComponent_ = tweenComponent;
96         if (!displayComponent_) {
97             displayComponent_ = AceType::MakeRefPtr<DisplayComponent>(rootComponent_->GetChild());
98         }
99         if (!transformComponent_) {
100             transformComponent_ = AceType::MakeRefPtr<TransformComponent>();
101         }
102     }
103 
GetTweenComponent()104     RefPtr<TweenComponent> GetTweenComponent() const
105     {
106         return tweenComponent_;
107     }
108 
GetChildList()109     const std::list<RefPtr<DOMNode>>& GetChildList() const
110     {
111         return children_;
112     }
113 
GetDeclaration()114     const RefPtr<Declaration>& GetDeclaration() const
115     {
116         return declaration_;
117     }
118 
GetRootComponent()119     const RefPtr<ComposedComponent>& GetRootComponent() const
120     {
121         return rootComponent_;
122     }
123 
GetBoxComponent()124     const RefPtr<BoxComponent>& GetBoxComponent() const
125     {
126         return boxComponent_;
127     }
128 
GetDisplayComponent()129     const RefPtr<DisplayComponent>& GetDisplayComponent() const
130     {
131         return displayComponent_;
132     }
133 
GetTouchListenerComponent()134     const RefPtr<TouchListenerComponent>& GetTouchListenerComponent() const
135     {
136         return touchEventComponent_;
137     }
138 
GetMouseListenerComponent()139     const RefPtr<MouseListenerComponent>& GetMouseListenerComponent() const
140     {
141         return mouseEventComponent_;
142     }
143 
GetGestureListenerComponent()144     const RefPtr<GestureListenerComponent>& GetGestureListenerComponent() const
145     {
146         return gestureEventComponent_;
147     }
148 
GetFocusableComponent()149     const RefPtr<FocusableComponent>& GetFocusableComponent() const
150     {
151         return focusableEventComponent_;
152     }
153 
GetTransformComponent()154     const RefPtr<TransformComponent>& GetTransformComponent() const
155     {
156         return transformComponent_;
157     }
158 
SetShareId(const std::string & shareId)159     void SetShareId(const std::string& shareId)
160     {
161         shareId_ = shareId;
162         if (declaration_) {
163             declaration_->SetShareId(shareId);
164         }
165     }
166 
GetShareId()167     const std::string& GetShareId() const
168     {
169         return shareId_;
170     }
171 
172     const RefPtr<PageTransitionComponent>& BuildTransitionComponent();
173 
174     // Ensure DOMPopup can response onClick event even without defining it.
SetOnClick(const EventMarker & eventMarker)175     void SetOnClick(const EventMarker& eventMarker)
176     {
177         ACE_DCHECK(gestureEventComponent_);
178         gestureEventComponent_->SetOnClickId(eventMarker);
179     }
180 
SetOnDoubleClick(const EventMarker & eventMarker)181     void SetOnDoubleClick(const EventMarker& eventMarker)
182     {
183         gestureEventComponent_->SetOnDoubleClickId(eventMarker);
184     }
185 
SetOnDragStart(const EventMarker & eventMarker)186     void SetOnDragStart(const EventMarker& eventMarker)
187     {
188         gestureEventComponent_->SetOnFreeDragStartId(eventMarker);
189     }
190 
SetOnDrag(const EventMarker & eventMarker)191     void SetOnDrag(const EventMarker& eventMarker)
192     {
193         gestureEventComponent_->SetOnFreeDragUpdateId(eventMarker);
194     }
195 
SetOnDragEnd(const EventMarker & eventMarker)196     void SetOnDragEnd(const EventMarker& eventMarker)
197     {
198         gestureEventComponent_->SetOnFreeDragEndId(eventMarker);
199     }
200 
SetOnLongPress(const EventMarker & eventMarker)201     void SetOnLongPress(const EventMarker& eventMarker)
202     {
203         gestureEventComponent_->SetOnLongPressId(eventMarker);
204     }
205 
SetOnPinchStart(const EventMarker & eventMarker)206     void SetOnPinchStart(const EventMarker& eventMarker)
207     {
208         gestureEventComponent_->SetOnPinchStartId(eventMarker);
209     }
210 
SetOnPinchUpdate(const EventMarker & eventMarker)211     void SetOnPinchUpdate(const EventMarker& eventMarker)
212     {
213         gestureEventComponent_->SetOnPinchUpdateId(eventMarker);
214     }
215 
SetOnPinchEnd(const EventMarker & eventMarker)216     void SetOnPinchEnd(const EventMarker& eventMarker)
217     {
218         gestureEventComponent_->SetOnPinchEndId(eventMarker);
219     }
220 
SetOnPinchCancel(const EventMarker & eventMarker)221     void SetOnPinchCancel(const EventMarker& eventMarker)
222     {
223         gestureEventComponent_->SetOnPinchCancelId(eventMarker);
224     }
225 
SetIsRootNode(bool isRootNode)226     void SetIsRootNode(bool isRootNode)
227     {
228         isRootNode_ = isRootNode;
229     }
230 
IsRootNode()231     bool IsRootNode() const
232     {
233         return isRootNode_;
234     }
235 
SetIsTransition(bool isTransition)236     void SetIsTransition(bool isTransition)
237     {
238         isTransition_ = isTransition;
239     }
240 
GetIsTransition()241     bool GetIsTransition() const
242     {
243         return isTransition_;
244     }
245 
246     void SetOnFocusClick(const EventMarker& eventMarker);
247 
248     bool IsNodeDisabled() const;
249 
SetIsEnter(bool isEnter)250     void SetIsEnter(bool isEnter)
251     {
252         isEnter_ = isEnter;
253     }
254 
GetIsEnter()255     bool GetIsEnter() const
256     {
257         return isEnter_;
258     }
259 
GetNodeId()260     NodeId GetNodeId() const
261     {
262         return nodeId_;
263     }
264 
GetNodeIdForEvent()265     std::string GetNodeIdForEvent() const
266     {
267         return isRootNode_ ? DOM_DEFAULT_ROOT_NODE_ID : std::to_string(GetNodeId());
268     }
269 
GetTag()270     const std::string& GetTag() const
271     {
272         return tag_;
273     }
274 
SetProxyNode(bool isProxy)275     void SetProxyNode(bool isProxy)
276     {
277         isProxy_ = isProxy;
278     }
279 
IsProxy()280     bool IsProxy() const
281     {
282         return isProxy_;
283     }
284 
IsShow()285     bool IsShow() const
286     {
287         double opacity = 1.0;
288         if (declaration_) {
289             auto& opacityStyle =
290                 static_cast<CommonOpacityStyle&>(declaration_->GetStyle(StyleTag::COMMON_OPACITY_STYLE));
291             if (opacityStyle.IsValid()) {
292                 opacity = opacityStyle.opacity;
293             }
294         }
295         return visible_ == VisibleType::VISIBLE && !NearZero(opacity);
296     }
297 
GetBackGroundColor()298     Color GetBackGroundColor() const
299     {
300         Color color = Color::TRANSPARENT;
301         if (declaration_ && isTransitionColor_) {
302             auto& style =
303                 static_cast<CommonBackgroundStyle&>(declaration_->GetStyle(StyleTag::COMMON_BACKGROUND_STYLE));
304             if (style.IsValid()) {
305                 color = style.backgroundColor;
306             }
307         }
308         return color;
309     }
310 
GetOpacity()311     double GetOpacity() const
312     {
313         double opacity = 1.0;
314         if (declaration_) {
315             auto& style = static_cast<CommonOpacityStyle&>(declaration_->GetStyle(StyleTag::COMMON_OPACITY_STYLE));
316             if (style.IsValid()) {
317                 opacity = style.opacity;
318             }
319         }
320         return opacity;
321     }
322 
GetParentId()323     NodeId GetParentId() const
324     {
325         return parentId_;
326     }
327 
GetParentNode()328     RefPtr<DOMNode> GetParentNode() const
329     {
330         return parentNode_.Upgrade();
331     }
332 
333     bool IsTabbarSubNode() const;
334 
SetParentNode(const RefPtr<DOMNode> & parentNode)335     void SetParentNode(const RefPtr<DOMNode>& parentNode)
336     {
337         if (!parentNode) {
338             return;
339         }
340         parentNode_ = parentNode;
341         parentId_ = parentNode->GetNodeId();
342         parentTag_ = parentNode->GetTag();
343 
344         if (tag_ == DOM_NODE_TAG_SVG || parentNode->HasSvgTag()) {
345             hasSvgTag_ = true;
346         }
347     }
348 
GetPageId()349     int32_t GetPageId() const
350     {
351         return pageId_;
352     }
SetPageId(int32_t pageId)353     void SetPageId(int32_t pageId)
354     {
355         pageId_ = pageId;
356     }
357 
358     // Subclasses need to implement this interface to return their specialized components, which will be added to the
359     // last node of the component tree.
360     virtual RefPtr<Component> GetSpecializedComponent() = 0;
361 
SetPipelineContext(const WeakPtr<PipelineContext> & pipelineContext)362     void SetPipelineContext(const WeakPtr<PipelineContext>& pipelineContext)
363     {
364         pipelineContext_ = pipelineContext;
365     }
366 
GetPipelineContext()367     const WeakPtr<PipelineContext>& GetPipelineContext() const
368     {
369         return pipelineContext_;
370     }
371 
372     // Initialize node theme style when created.
InitializeStyle()373     virtual void InitializeStyle() {};
374 
375     void OnActive(bool isActive);
376 
HasPseudo()377     bool HasPseudo() const
378     {
379         return (cachedPseudoType_ != STATE_NORMAL);
380     }
381 
HasDisabledPseudo()382     bool HasDisabledPseudo() const
383     {
384         return ((cachedPseudoType_ & STATE_DISABLED) > 0);
385     }
386 
HasCheckedPseudo()387     bool HasCheckedPseudo() const
388     {
389         return ((cachedPseudoType_ & STATE_CHECKED) > 0);
390     }
391 
HasFocusPseudo()392     bool HasFocusPseudo() const
393     {
394         return ((cachedPseudoType_ & STATE_FOCUS) > 0);
395     }
396 
HasActivePseudo()397     bool HasActivePseudo() const
398     {
399         return ((cachedPseudoType_ & STATE_ACTIVE) > 0);
400     }
401 
HasSvgTag()402     bool HasSvgTag()
403     {
404         return hasSvgTag_;
405     }
406 
407     /*
408      * Parse color from string content and reference for id/attr, including format:
409      * #rrggbb, #aarrggbb, "@id001", "@attr_sys_color".
410      */
411     Color ParseColor(const std::string& value, uint32_t maskAlpha = COLOR_ALPHA_MASK) const;
412 
413     /*
414      * Parse double from string content and reference for id/attr, including format:
415      * 100.01, "@id001", "@attr_sys_alpha".
416      */
417     double ParseDouble(const std::string& value) const;
418 
419     /*
420      * Parse dimension from string content and reference for id/attr, including format:
421      * 10px, "@id001", "@attr_sys_dimension, expression".
422      */
423     CalcDimension ParseDimension(const std::string& value) const;
424 
425     /*
426      * Parse line height from string content and reference for id/attr, including format:
427      * 1.5, "@id001", "@attr_sys_line_height".
428      */
429     Dimension ParseLineHeight(const std::string& value) const;
430 
431     /*
432      * Parse font family list from string content and reference for id/attr, including format:
433      * sans-serif, "@id001", "@attr_sys_font_family".
434      */
435     std::vector<std::string> ParseFontFamilies(const std::string& value) const;
436 
437     /*
438      * Parse dimension list from string content and reference for id/attr, including format:
439      * 10px, "@id001", "@attr_sys_dimension".
440      */
441     std::vector<Dimension> ParsePreferFontSizes(const std::string& value) const;
442 
443     /*
444      * Parse image src from string content and reference for id/attr, including format:
445      * "@app.media.customized_image", "@sys.media.123".
446      */
447     std::string ParseImageSrc(const std::string& imgSrc) const;
448 
GetThemeManager()449     RefPtr<ThemeManager> GetThemeManager() const
450     {
451         auto context = pipelineContext_.Upgrade();
452         if (!context) {
453             return nullptr;
454         }
455         return context->GetThemeManager();
456     }
457 
458     template<typename T>
GetTheme()459     RefPtr<T> GetTheme() const
460     {
461         auto context = pipelineContext_.Upgrade();
462         if (!context) {
463             return nullptr;
464         }
465         auto themeManager = context->GetThemeManager();
466         if (!themeManager) {
467             return nullptr;
468         }
469         return themeManager->GetTheme<T>();
470     }
471 
472     virtual void UpdateStyleWithChildren();
473 
IsCustomComponent()474     bool IsCustomComponent() const
475     {
476         return isCustomComponent_;
477     }
478 
SetIsCustomComponent(bool isCustomComponent)479     void SetIsCustomComponent(bool isCustomComponent)
480     {
481         isCustomComponent_ = isCustomComponent;
482     }
483 
HasBorderRadiusStyle()484     bool HasBorderRadiusStyle() const
485     {
486         return declaration_ ? declaration_->HasBorderRadiusStyle() : false;
487     }
488 
HasOverflowStyle()489     bool HasOverflowStyle() const
490     {
491         return declaration_ ? declaration_->HasOverflowStyle() : false;
492     }
493 
IsBoxWrap()494     bool IsBoxWrap() const
495     {
496         return boxWrap_;
497     }
498 
SetBoxWrap(bool boxWrap)499     void SetBoxWrap(bool boxWrap)
500     {
501         boxWrap_ = boxWrap;
502     }
503 
504     void AdjustParamInLiteMode();
505 
AdjustSpecialParamInLiteMode()506     virtual void AdjustSpecialParamInLiteMode() {}
507 
508     // TODO delete those method form dom node, use declaration.
509     virtual void SetAttr(const std::vector<std::pair<std::string, std::string>>& attrs);
510     virtual void SetStyle(const std::vector<std::pair<std::string, std::string>>& styles);
511     virtual void AddEvent(int32_t pageId, const std::vector<std::string>& events);
512     virtual void CallMethod(const std::string& method, const std::string& args);
513     virtual void OnRequestFocus(bool shouldFocus);
514     virtual void OnScrollBy(double dx, double dy, bool isSmooth);
515 
516     bool SetCurrentStyle(const std::pair<std::string, std::string>& style);
517 
IsRightToLeft()518     bool IsRightToLeft() const
519     {
520         return declaration_ ? declaration_->IsRightToLeft() : false;
521     }
522 
SetHeight(const CalcDimension & height)523     void SetHeight(const CalcDimension& height)
524     {
525         if (declaration_) {
526             auto& sizeStyle = declaration_->MaybeResetStyle<CommonSizeStyle>(StyleTag::COMMON_SIZE_STYLE);
527             if (sizeStyle.IsValid()) {
528                 sizeStyle.height = height;
529             }
530         }
531     }
532 
SetWidth(const CalcDimension & width)533     void SetWidth(const CalcDimension& width)
534     {
535         if (declaration_) {
536             auto& sizeStyle = declaration_->MaybeResetStyle<CommonSizeStyle>(StyleTag::COMMON_SIZE_STYLE);
537             if (sizeStyle.IsValid()) {
538                 sizeStyle.width = width;
539             }
540         }
541     }
542 
GetHeight()543     virtual Dimension GetHeight() const
544     {
545         Dimension height = Dimension(-1.0, DimensionUnit::PX);
546         if (declaration_) {
547             auto& sizeStyle = static_cast<CommonSizeStyle&>(declaration_->GetStyle(StyleTag::COMMON_SIZE_STYLE));
548             if (sizeStyle.IsValid()) {
549                 height = sizeStyle.height;
550             }
551         }
552         return height;
553     }
554 
GetCalcHeight()555     virtual CalcDimension GetCalcHeight() const
556     {
557         CalcDimension height = Dimension(-1.0, DimensionUnit::PX);
558         if (declaration_) {
559             auto& sizeStyle = static_cast<CommonSizeStyle&>(declaration_->GetStyle(StyleTag::COMMON_SIZE_STYLE));
560             if (sizeStyle.IsValid()) {
561                 height = sizeStyle.height;
562             }
563         }
564         return height;
565     }
566 
GetWidth()567     virtual Dimension GetWidth() const
568     {
569         Dimension width = Dimension(-1.0, DimensionUnit::PX);
570         if (declaration_) {
571             auto& sizeStyle = static_cast<CommonSizeStyle&>(declaration_->GetStyle(StyleTag::COMMON_SIZE_STYLE));
572             if (sizeStyle.IsValid()) {
573                 width = sizeStyle.width;
574             }
575         }
576         return width;
577     }
578 
GetCalcWidth()579     virtual CalcDimension GetCalcWidth() const
580     {
581         CalcDimension width = Dimension(-1.0, DimensionUnit::PX);
582         if (declaration_) {
583             auto& sizeStyle = static_cast<CommonSizeStyle&>(declaration_->GetStyle(StyleTag::COMMON_SIZE_STYLE));
584             if (sizeStyle.IsValid()) {
585                 width = sizeStyle.width;
586             }
587         }
588         return width;
589     }
590 
GetDisplay()591     DisplayType GetDisplay() const
592     {
593         DisplayType display = DisplayType::NO_SETTING;
594         if (declaration_) {
595             auto& displayStyle =
596                 static_cast<CommonDisplayStyle&>(declaration_->GetStyle(StyleTag::COMMON_DISPLAY_STYLE));
597             if (displayStyle.IsValid()) {
598                 display = displayStyle.display;
599             }
600         }
601         return display;
602     }
603 
SetDisplay(DisplayType type)604     void SetDisplay(DisplayType type)
605     {
606         if (declaration_) {
607             auto& displayStyle = declaration_->MaybeResetStyle<CommonDisplayStyle>(StyleTag::COMMON_DISPLAY_STYLE);
608             if (displayStyle.IsValid()) {
609                 displayStyle.display = type;
610             }
611         }
612     }
613 
GetPosition()614     PositionType GetPosition() const
615     {
616         PositionType position = PositionType::RELATIVE;
617         if (declaration_) {
618             auto& positionStyle =
619                 static_cast<CommonPositionStyle&>(declaration_->GetStyle(StyleTag::COMMON_POSITION_STYLE));
620             if (positionStyle.IsValid()) {
621                 position = positionStyle.position;
622             }
623         }
624         return position;
625     }
626 
GetImageFill()627     std::optional<Color> GetImageFill() const
628     {
629         std::optional<Color> imageFill = std::nullopt;
630         if (declaration_) {
631             auto& imageStyle = static_cast<CommonImageStyle&>(declaration_->GetStyle(StyleTag::COMMON_IMAGE_STYLE));
632             if (imageStyle.IsValid()) {
633                 imageFill = imageStyle.imageFill;
634             }
635         }
636         return imageFill;
637     }
638 
GetDirtyNodeId()639     virtual NodeId GetDirtyNodeId() const
640     {
641         return nodeId_;
642     }
643 
644 protected:
OnMounted(const RefPtr<DOMNode> & parentNode)645     virtual void OnMounted(const RefPtr<DOMNode>& parentNode) {};
OnChildNodeAdded(const RefPtr<DOMNode> & child,int32_t slot)646     virtual void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) {};
OnChildNodeRemoved(const RefPtr<DOMNode> & child)647     virtual void OnChildNodeRemoved(const RefPtr<DOMNode>& child) {};
OnSetStyleFinished()648     virtual void OnSetStyleFinished() {};
649     // Confirm declaration is exist before call GetClickId and GetLongPressId.
GetClickId()650     virtual const EventMarker& GetClickId()
651     {
652         static EventMarker defaultMarker;
653         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
654         return gestureEvent.IsValid() ? gestureEvent.click.eventMarker : defaultMarker;
655     };
GetDoubleClickId()656     const EventMarker& GetDoubleClickId()
657     {
658         static EventMarker defaultMarker;
659         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
660         return gestureEvent.IsValid() ? gestureEvent.doubleClick.eventMarker : defaultMarker;
661     };
GetDragStartId()662     const EventMarker& GetDragStartId()
663     {
664         static EventMarker defaultMarker;
665         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
666         return gestureEvent.IsValid() ? gestureEvent.dragStart.eventMarker : defaultMarker;
667     };
GetDragId()668     const EventMarker& GetDragId()
669     {
670         static EventMarker defaultMarker;
671         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
672         return gestureEvent.IsValid() ? gestureEvent.drag.eventMarker : defaultMarker;
673     };
GetDragEndId()674     const EventMarker& GetDragEndId()
675     {
676         static EventMarker defaultMarker;
677         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
678         return gestureEvent.IsValid() ? gestureEvent.dragEnd.eventMarker : defaultMarker;
679     };
GetDragEnterId()680     const EventMarker& GetDragEnterId()
681     {
682         static EventMarker defaultMarker;
683         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
684         return gestureEvent.IsValid() ? gestureEvent.dragEnter.eventMarker : defaultMarker;
685     };
GetDragOverId()686     const EventMarker& GetDragOverId()
687     {
688         static EventMarker defaultMarker;
689         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
690         return gestureEvent.IsValid() ? gestureEvent.dragOver.eventMarker : defaultMarker;
691     };
GetDragLeaveId()692     const EventMarker& GetDragLeaveId()
693     {
694         static EventMarker defaultMarker;
695         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
696         return gestureEvent.IsValid() ? gestureEvent.dragLeave.eventMarker : defaultMarker;
697     };
GetDragDropId()698     const EventMarker& GetDragDropId()
699     {
700         static EventMarker defaultMarker;
701         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
702         return gestureEvent.IsValid() ? gestureEvent.dragDrop.eventMarker : defaultMarker;
703     };
GetLongPressId()704     const EventMarker& GetLongPressId()
705     {
706         static EventMarker defaultMarker;
707         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
708         return gestureEvent.IsValid() ? gestureEvent.longPress.eventMarker : defaultMarker;
709     };
GetPinchStartId()710         const EventMarker& GetPinchStartId()
711     {
712         static EventMarker defaultMarker;
713         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
714         return gestureEvent.IsValid() ? gestureEvent.pinchStart.eventMarker : defaultMarker;
715     };
GetPinchUpdateId()716     const EventMarker& GetPinchUpdateId()
717     {
718         static EventMarker defaultMarker;
719         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
720         return gestureEvent.IsValid() ? gestureEvent.pinchUpdate.eventMarker : defaultMarker;
721     };
GetPinchEndId()722     const EventMarker& GetPinchEndId()
723     {
724         static EventMarker defaultMarker;
725         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
726         return gestureEvent.IsValid() ? gestureEvent.pinchEnd.eventMarker : defaultMarker;
727     };
GetPinchCancelId()728     const EventMarker& GetPinchCancelId()
729     {
730         static EventMarker defaultMarker;
731         auto& gestureEvent = static_cast<CommonGestureEvent&>(declaration_->GetEvent(EventTag::COMMON_GESTURE_EVENT));
732         return gestureEvent.IsValid() ? gestureEvent.pinchCancel.eventMarker : defaultMarker;
733     };
734 
735     // Confirm declaration exist and support raw event before call GetTouchId.
GetTouchId(uint32_t action,uint32_t stage,uint32_t type)736     EventMarker& GetTouchId(uint32_t action, uint32_t stage, uint32_t type)
737     {
738         static EventMarker defaultMarker;
739         if (!declaration_) {
740             return defaultMarker;
741         }
742 
743         auto& rawEvent = declaration_->MaybeResetEvent<CommonRawEvent>(EventTag::COMMON_RAW_EVENT);
744         if (!rawEvent.IsValid()) {
745             return defaultMarker;
746         }
747         if (action == EventAction::ON && stage == EventStage::CAPTURE && type == EventType::TOUCH_CANCEL) {
748             return rawEvent.captureTouchCancel.eventMarker;
749         } else if (action == EventAction::ON && stage == EventStage::CAPTURE && type == EventType::TOUCH_UP) {
750             return rawEvent.captureTouchEnd.eventMarker;
751         } else if (action == EventAction::ON && stage == EventStage::CAPTURE && type == EventType::TOUCH_MOVE) {
752             return rawEvent.captureTouchMove.eventMarker;
753         } else if (action == EventAction::ON && stage == EventStage::CAPTURE && type == EventType::TOUCH_DOWN) {
754             return rawEvent.captureTouchStart.eventMarker;
755         } else if (action == EventAction::CATCH && stage == EventStage::BUBBLE && type == EventType::TOUCH_CANCEL) {
756             return rawEvent.catchBubbleTouchCancel.eventMarker;
757         } else if (action == EventAction::CATCH && stage == EventStage::BUBBLE && type == EventType::TOUCH_UP) {
758             return rawEvent.catchBubbleTouchEnd.eventMarker;
759         } else if (action == EventAction::CATCH && stage == EventStage::BUBBLE && type == EventType::TOUCH_MOVE) {
760             return rawEvent.catchBubbleTouchMove.eventMarker;
761         } else if (action == EventAction::CATCH && stage == EventStage::BUBBLE && type == EventType::TOUCH_DOWN) {
762             return rawEvent.catchBubbleTouchStart.eventMarker;
763         } else if (action == EventAction::CATCH && stage == EventStage::CAPTURE && type == EventType::TOUCH_CANCEL) {
764             return rawEvent.catchCaptureTouchCancel.eventMarker;
765         } else if (action == EventAction::CATCH && stage == EventStage::CAPTURE && type == EventType::TOUCH_UP) {
766             return rawEvent.catchCaptureTouchEnd.eventMarker;
767         } else if (action == EventAction::CATCH && stage == EventStage::CAPTURE && type == EventType::TOUCH_MOVE) {
768             return rawEvent.catchCaptureTouchMove.eventMarker;
769         } else if (action == EventAction::CATCH && stage == EventStage::CAPTURE && type == EventType::TOUCH_DOWN) {
770             return rawEvent.catchCaptureTouchStart.eventMarker;
771         } else if (action == EventAction::ON && stage == EventStage::BUBBLE && type == EventType::TOUCH_CANCEL) {
772             return rawEvent.touchCancel.eventMarker;
773         } else if (action == EventAction::ON && stage == EventStage::BUBBLE && type == EventType::TOUCH_UP) {
774             return rawEvent.touchEnd.eventMarker;
775         } else if (action == EventAction::ON && stage == EventStage::BUBBLE && type == EventType::TOUCH_MOVE) {
776             return rawEvent.touchMove.eventMarker;
777         } else if (action == EventAction::ON && stage == EventStage::BUBBLE && type == EventType::TOUCH_DOWN) {
778             return rawEvent.touchStart.eventMarker;
779         }
780         return defaultMarker;
781     }
782 
783     // Subclasses need to implement this interface to composit specialized component into common components.
784     virtual RefPtr<Component> CompositeSpecializedComponent(const std::vector<RefPtr<SingleChild>>& components);
785 
786     // Subclasses need to override this interface to update component with declaration.
UpdateSpecializedComponentWithDeclaration()787     virtual void UpdateSpecializedComponentWithDeclaration() {};
788 
789     // Subclasses need to override this interface to implement the dynamic creation of subclass specialized components.
PrepareSpecializedComponent()790     virtual void PrepareSpecializedComponent() {};
791 
792     virtual void CompositeComponents();
793 
794     virtual void UpdateBoxSize(const CalcDimension& width, const CalcDimension& height);
795     virtual void UpdateBoxPadding(const Edge& padding);
796     virtual void UpdateBoxBorder(const Border& border);
797     virtual void UpdatePropAnimations(const PropAnimationMap& animations);
798     virtual void UpdatePositionAnimations(const RefPtr<Component> componet);
799 
800     // Subclasses need to override this interface to implement reset initialization style before any frontend style set.
ResetInitializedStyle()801     virtual void ResetInitializedStyle() {};
802 
IsLeafNode()803     virtual bool IsLeafNode() const
804     {
805         return false;
806     }
807 
808     void PrepareScrollComponent();
809 
GetLastCommonParent()810     RefPtr<SingleChild> GetLastCommonParent()
811     {
812         if (sharedTransitionComponent_) {
813             return sharedTransitionComponent_;
814         }
815         return boxComponent_;
816     }
817 
SetAlignment(const Alignment & align)818     void SetAlignment(const Alignment& align)
819     {
820         ACE_DCHECK(boxComponent_);
821         boxComponent_->SetAlignment(align);
822     }
823 
824     void OnChecked(bool isChecked);
825 
826     // TODO delete those method from dom node.
827     // Each subclass needs to override this function to obtain the properties. If it returns true, it means that the
828     // property has been consumed. If it returns false, it means it is handed over to the parent class.
SetSpecializedAttr(const std::pair<std::string,std::string> & attr)829     virtual bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr)
830     {
831         return false;
832     }
833 
834     // Each subclass needs to override this function to obtain the style. If it returns true, it means that the
835     // style has been consumed. If it returns false, it means it is handed over to the parent class.
SetSpecializedStyle(const std::pair<std::string,std::string> & style)836     virtual bool SetSpecializedStyle(const std::pair<std::string, std::string>& style)
837     {
838         return false;
839     }
840 
841     // Each subclass needs to override this function to obtain the event. If it returns true, it means that the
842     // event has been consumed. If it returns false, it means it is handed over to the parent class.
AddSpecializedEvent(int32_t pageId,const std::string & event)843     virtual bool AddSpecializedEvent(int32_t pageId, const std::string& event)
844     {
845         return false;
846     }
847 
CallSpecializedMethod(const std::string & method,const std::string & args)848     virtual void CallSpecializedMethod(const std::string& method, const std::string& args) {};
849 
850     // When the multi-mode input subscript is set to auto, need to determine whether the current component has the
851     // ability to support the subscript.
IsSubscriptEnable()852     virtual bool IsSubscriptEnable() const
853     {
854         if (declaration_) {
855             declaration_->SetIsSubscriptEnable(false);
856         }
857         return false;
858     }
859 
860     WeakPtr<DOMNode> parentNode_;
861     NodeId parentId_ = -1;
862     bool isRootNode_ = false;
863     std::string parentTag_;
864     std::list<RefPtr<DOMNode>> children_;
865     // for pseudo class
866     std::vector<std::pair<std::string, std::string>> attributesCache_;
867     std::unordered_map<int32_t, std::unordered_map<std::string, std::string>> pseudoClassStyleMap_;
868     RefPtr<ComposedComponent> rootComponent_;
869     RefPtr<BoxComponent> boxComponent_;
870     RefPtr<ScrollComponent> scrollComponent_;
871     RefPtr<FlexItemComponent> flexItemComponent_;
872     RefPtr<TransformComponent> transformComponent_;
873     WeakPtr<PipelineContext> pipelineContext_;
874     RefPtr<Declaration> declaration_;
875     bool isCustomComponent_ = false;
876     bool boxWrap_ = false;
877 
878 private:
879     static void SetTransform(const std::string& value, DOMNode& node);
880     static void AddKeyframe(
881         double time, const std::string& typeValue, RefPtr<KeyframeAnimation<float>>& transformKeyframes);
882     static void AddKeyframe(double time, double typeValue, RefPtr<KeyframeAnimation<float>>& transformKeyframes);
883     std::string GetTransformJsonValue(const std::string& value);
884     std::string GetTransformType(const std::unique_ptr<JsonValue>& transformJson);
885     std::string GetTransformTypeValue(const std::unique_ptr<JsonValue>& transformJson);
886 
887     void CreatePropertyAnimation(const std::string& property);
888     RefPtr<KeyframeAnimation<float>> SetPropertyFloatAnimationKeyframe(float begin, float end);
889     RefPtr<KeyframeAnimation<Color>> SetPropertyColorAnimationKeyframe(const Color& begin, const Color& end);
890     void TransitionOptionSetKeyframes(TweenOption& tweenOption);
891     void SetDisplayStyle();
892 
893     void UpdateFlexItemComponent();
894     void UpdateUiComponents();
895     void UpdateBoxComponent();
896     void UpdateDisplayComponent();
897     void UpdateTweenComponent();
898     void UpdateTouchEventComponent();
899     void UpdateGestureEventComponent();
900     void UpdateMouseEventComponent();
901     void UpdateFocusableEventComponents();
902     void UpdatePositionComponent();
903     void UpdatePositionProps();
904     void UpdateTweenPosition(const RefPtr<TweenComponent> tweenComponent);
905 #ifndef WEARABLE_PRODUCT
906     void UpdateMultimodalComponent();
907 #endif
908 
909     void CachePseudoClassStyle(const std::pair<std::string, std::string>& pseudoClassStyle);
910     void UpdatePseudoStyle(bool isBackendChange);
911     void PrepareTouchEvent(EventMarker& eventMarker, uint32_t type);
912     void PrepareFocusableEventId();
913     void PrepareMouseHoverEvent();
914     void UpdatePseudoStyleByStatus(int32_t status, bool isBackendChange);
915     void ResetDefaultStyles();
916     uint32_t CalculatePseudoStatus() const;
917     void SetAttrInternal(const std::vector<std::pair<std::string, std::string>>& attrs);
918 
919     // for state update callbacks
920     void OnFocus(bool isFocus);
921     void OnHover(bool isHover);
922 
923     RefPtr<ThemeConstants> GetThemeConstants() const;
924 
925     template<typename T>
ParseThemeReference(const std::string & value,std::function<T ()> && noRefFunc,std::function<T (uint32_t refId)> && idRefFunc,const T & errorValue)926     T ParseThemeReference(const std::string& value, std::function<T()>&& noRefFunc,
927         std::function<T(uint32_t refId)>&& idRefFunc, const T& errorValue) const
928     {
929         const auto& parseResult = ThemeUtils::ParseThemeIdReference(value, GetThemeConstants());
930         if (!parseResult.parseSuccess) {
931             return noRefFunc();
932         }
933         auto themeConstants = GetThemeConstants();
934         if (!themeConstants) {
935             return errorValue;
936         }
937         // Refer to a theme id resource.
938         if (parseResult.isIdRef) {
939             return idRefFunc(parseResult.id);
940         }
941         // Refer to a theme attribute.
942         auto themeStyle = themeConstants->GetThemeStyle();
943         if (!themeStyle) {
944             return errorValue;
945         }
946         return themeStyle->GetAttr<T>(parseResult.refAttr, errorValue);
947     }
948 
949     bool isTransition_ = false;
950     bool isEnter_ = false;
951     bool isProxy_ = false;
952     bool animationStyleUpdated_ = false;
953     bool customAnimationStyleUpdated_ = false;
954     bool hasSvgTag_ = false;
955     VisibleType visible_ = VisibleType::VISIBLE;
956 
957     int32_t pageId_ = -1;
958     NodeId nodeId_ = -1;
959     std::string tag_;
960 
961     RefPtr<DisplayComponent> displayComponent_;
962     RefPtr<TouchListenerComponent> touchEventComponent_;
963     RefPtr<GestureListenerComponent> gestureEventComponent_;
964     RefPtr<FocusableComponent> focusableEventComponent_;
965     RefPtr<MouseListenerComponent> mouseEventComponent_;
966     RefPtr<PositionedComponent> positionComponent_;
967     RefPtr<SharedTransitionComponent> sharedTransitionComponent_;
968     RefPtr<TweenComponent> tweenComponent_;
969     RefPtr<TransitionComponent> propTransitionComponent_;
970     RefPtr<PageTransitionComponent> transitionComponent_;
971 
972     PropAnimationMap propAnimations_;
973     AnimationUtil animationUtil_;
974     RefPtr<KeyframeAnimation<float>> propertyWidthAnimation_;
975     RefPtr<KeyframeAnimation<float>> propertyHeightAnimation_;
976     RefPtr<KeyframeAnimation<Color>> propertyColorAnimation_;
977     std::string animationName_;
978     bool isActive_ = false;
979     bool isFocus_ = false;
980     uint32_t cachedPseudoType_ = STATE_NORMAL;
981 
982     TweenOption propTransitionOption_;
983     std::string transitionPropertyName_ = "all";
984     std::string transitionTimeFunction_ = "ease";
985     int32_t transitionDuration_ = 0;
986     int32_t transitionDelay_ = 0;
987     bool isTransitionNameUpdateFirst_ = true;
988     bool isTransitionDurationUpdateFirst_ = true;
989     bool transitionStyleUpdated_ = false;
990     bool isTransitionColor_ = false;
991 
992     // for shared transition
993     std::string shareId_;
994 #ifndef WEARABLE_PRODUCT
995     // for multi modal input.
996     RefPtr<MultimodalComponent> multimodalComponent_;
997 #endif
998 };
999 
1000 } // namespace OHOS::Ace::Framework
1001 
1002 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_NODE_H