• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "base/utils/noncopyable.h"
21 #include "base/thread/cancelable_callback.h"
22 #include "core/components/slider/render_slider.h"
23 #include "core/components_ng/base/view_abstract.h"
24 #include "core/components_ng/event/long_press_event.h"
25 #include "core/components_ng/pattern/menu/menu_item/custom_menu_item_layout_algorithm.h"
26 #include "core/components_ng/pattern/menu/menu_item/menu_item_accessibility_property.h"
27 #include "core/components_ng/pattern/menu/menu_item/menu_item_event_hub.h"
28 #include "core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.h"
29 #include "core/components_ng/pattern/menu/menu_item/menu_item_layout_property.h"
30 #include "core/components_ng/pattern/menu/menu_item/menu_item_paint_method.h"
31 #include "core/components_ng/pattern/menu/menu_item/menu_item_paint_property.h"
32 #include "core/components_ng/pattern/menu/menu_pattern.h"
33 #include "core/components_ng/pattern/menu/menu_theme.h"
34 #include "core/components_ng/pattern/pattern.h"
35 
36 namespace OHOS::Ace::NG {
37 enum class ShowSubMenuType : int32_t {
38     DEFAULT = 0,
39     HOVER = 1,
40     CLICK = 2,
41     LONG_PRESS = 3,
42     KEY_DPAD_RIGHT = 4,
43     ACTION = 5
44 };
45 class ACE_EXPORT MenuItemPattern : public Pattern {
46     DECLARE_ACE_TYPE(MenuItemPattern, Pattern);
47 
48 public:
index_(index)49     MenuItemPattern(bool isOptionPattern = false, int index = -1) : index_(index), isOptionPattern_(isOptionPattern) {}
50     ~MenuItemPattern() override = default;
51 
HasHideTask()52     bool HasHideTask()
53     {
54         return hideTask_;
55     }
56 
IsAtomicNode()57     inline bool IsAtomicNode() const override
58     {
59         return false;
60     }
61 
GetFocusPattern()62     inline FocusPattern GetFocusPattern() const override
63     {
64         FocusPattern focusPattern = { FocusType::NODE, true, FocusStyleType::INNER_BORDER };
65         auto host = GetHost();
66         CHECK_NULL_RETURN(host, focusPattern);
67         auto pipelineContext = host->GetContext();
68         CHECK_NULL_RETURN(pipelineContext, focusPattern);
69         if (isOptionPattern_) {
70             auto selectTheme = pipelineContext->GetTheme<SelectTheme>();
71             CHECK_NULL_RETURN(selectTheme, focusPattern);
72             auto focusStyleType =
73                 static_cast<FocusStyleType>(static_cast<int32_t>(selectTheme->GetOptionFocusStyleType_()));
74             focusPattern.SetStyleType(focusStyleType);
75             return focusPattern;
76         } else {
77             auto menuTheme = pipelineContext->GetTheme<MenuTheme>();
78             CHECK_NULL_RETURN(menuTheme, focusPattern);
79             auto focusStyleType =
80                 static_cast<FocusStyleType>(static_cast<int32_t>(menuTheme->GetFocusStyleType()));
81             focusPattern.SetStyleType(focusStyleType);
82             return focusPattern;
83         }
84     }
85 
IsEnableMatchParent()86     bool IsEnableMatchParent() override
87     {
88         return true;
89     }
90 
IsEnableChildrenMatchParent()91     bool IsEnableChildrenMatchParent() override
92     {
93         return true;
94     }
95 
IsEnableFix()96     bool IsEnableFix() override
97     {
98         return true;
99     }
100 
CreateEventHub()101     inline RefPtr<EventHub> CreateEventHub() override
102     {
103         return MakeRefPtr<MenuItemEventHub>();
104     }
105 
CreateLayoutProperty()106     inline RefPtr<LayoutProperty> CreateLayoutProperty() override
107     {
108         return MakeRefPtr<MenuItemLayoutProperty>();
109     }
110 
CreateAccessibilityProperty()111     inline RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
112     {
113         return MakeRefPtr<MenuItemAccessibilityProperty>(isOptionPattern_);
114     }
115 
CreateLayoutAlgorithm()116     inline RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
117     {
118         return MakeRefPtr<MenuItemLayoutAlgorithm>(isOptionPattern_, showDefaultSelectedIcon_);
119     }
120 
CreateNodePaintMethod()121     inline RefPtr<NodePaintMethod> CreateNodePaintMethod() override
122     {
123         return MakeRefPtr<MenuItemPaintMethod>(isOptionPattern_);
124     }
125 
CreatePaintProperty()126     inline RefPtr<PaintProperty> CreatePaintProperty() override
127     {
128         return MakeRefPtr<MenuItemPaintProperty>(isOptionPattern_);
129     }
130 
131     void MarkIsSelected(bool isSelected);
SetSelected(bool isSelected)132     void SetSelected(bool isSelected)
133     {
134         isSelected_ = isSelected;
135         if (!isOptionPattern_) {
136             GetHost()->MarkModifyDone();
137         }
138         UpdateDividerSelectedStatus(isSelected_);
139     }
140 
IsSelected()141     bool IsSelected() const
142     {
143         return isSelected_;
144     }
145 
SetSubBuilder(const std::function<void ()> & subBuilderFunc)146     void SetSubBuilder(const std::function<void()>& subBuilderFunc)
147     {
148         subBuilderFunc_ = subBuilderFunc;
149     }
150 
GetSubBuilder()151     std::function<void()>& GetSubBuilder()
152     {
153         return subBuilderFunc_;
154     }
155 
IsSubMenuShowed()156     bool IsSubMenuShowed() const
157     {
158         return isSubMenuShowed_;
159     }
160 
SetIsSubMenuShowed(bool isSubMenuShowed)161     void SetIsSubMenuShowed(bool isSubMenuShowed)
162     {
163         isSubMenuShowed_ = isSubMenuShowed;
164     }
165 
IsSubMenuHovered()166     bool IsSubMenuHovered() const
167     {
168         return isSubMenuHovered_;
169     }
170 
SetIsSubMenuHovered(bool isSubMenuHovered)171     void SetIsSubMenuHovered(bool isSubMenuHovered)
172     {
173         isSubMenuHovered_ = isSubMenuHovered;
174     }
175 
176     void AddHoverRegions(const OffsetF& topLeftPoint, const OffsetF& bottomRightPoint);
177 
178     bool IsInHoverRegions(double x, double y);
179 
ClearHoverRegions()180     void ClearHoverRegions()
181     {
182         hoverRegions_.clear();
183     }
184 
ResetWrapperMouseEvent()185     void ResetWrapperMouseEvent()
186     {
187         wrapperMouseEvent_.Reset();
188     }
189 
SetChange()190     void SetChange()
191     {
192         isSelected_ = !isSelected_;
193     }
194 
IsChange()195     bool IsChange() const
196     {
197         return isChanged_;
198     }
199 
200     void CloseMenu();
201 
GetContentNode()202     RefPtr<FrameNode> GetContentNode()
203     {
204         return content_;
205     }
206 
GetLabelNode()207     RefPtr<FrameNode> GetLabelNode()
208     {
209         return label_;
210     }
211 
GetBottomDivider()212     RefPtr<FrameNode> GetBottomDivider()
213     {
214         CreateBottomDivider();
215         return bottomDivider_;
216     }
217 
SetTopDivider(WeakPtr<FrameNode> topDivider)218     void SetTopDivider(WeakPtr<FrameNode> topDivider)
219     {
220         topDivider_ = topDivider;
221     }
222 
GetTopDivider()223     RefPtr<FrameNode> GetTopDivider()
224     {
225         return topDivider_.Upgrade();
226     }
227 
228     void PlayBgColorAnimation(bool isHoverChange = true);
SetBgBlendColor(const Color & color)229     void SetBgBlendColor(const Color& color)
230     {
231         bgBlendColor_ = color;
232     }
GetBgBlendColor()233     Color GetBgBlendColor() const
234     {
235         return bgBlendColor_;
236     }
237     bool IsDisabled();
238 
239     RefPtr<FrameNode> GetMenu(bool needTopMenu = false);
240     RefPtr<MenuPattern> GetMenuPattern(bool needTopMenu = false);
241     void UpdateTextNodes();
242 
243     void OnAttachToFrameNode() override;
244     void OnModifyDone() override;
245     void OnMountToParentDone() override;
246 
HasSelectIcon()247     bool HasSelectIcon() const
248     {
249         return selectIcon_ != nullptr;
250     }
HasStartIcon()251     bool HasStartIcon() const
252     {
253         return startIcon_ != nullptr;
254     }
255 
SetClickMenuItemId(int32_t id)256     void SetClickMenuItemId(int32_t id)
257     {
258         clickMenuItemId_ = id;
259     }
260 
GetClickMenuItemId()261     int32_t GetClickMenuItemId() const
262     {
263         return clickMenuItemId_;
264     }
265 
SetOnClickAIMenuItem(std::function<void ()> onClickAIMenuItem)266     void SetOnClickAIMenuItem(std::function<void()> onClickAIMenuItem)
267     {
268         onClickAIMenuItem_ = onClickAIMenuItem;
269     }
270 
271     void OnVisibleChange(bool isVisible) override;
272     void InitLongPressEvent();
273     void UpdateNeedDivider(bool need);
274     void CheckHideSubMenu(std::function<void()> callback, const PointF& mousePoint, const RectF& menuZone);
275     bool NeedPerformHideSubMenuImmediately(const PointF& mousePoint, const RectF& menuZone);
276     bool NeedStartHideMenuTask(const PointF& mousePoint, const RectF& menuZone);
277     bool NeedStartHideRightSubMenuTask(const PointF& lastInnerPoint, const PointF& mousePoint, const RectF& menuZone);
278     bool NeedStartHideLeftSubMenuTask(const PointF& lastInnerPoint, const PointF& mousePoint, const RectF& menuZone);
279     void CancelHideSubMenuTask(const PointF& mousePoint);
SetIndex(int32_t index)280     void SetIndex(int32_t index)
281     {
282         index_ = index;
283     }
284     float GetDividerStroke();
285 
GetExpandingMode()286     SubMenuExpandingMode GetExpandingMode()
287     {
288         return expandingMode_;
289     }
290     bool IsSubMenu();
291     bool IsEmbedded();
SetIsStackSubmenuHeader()292     void SetIsStackSubmenuHeader()
293     {
294         isStackSubmenuHeader_ = true;
295     }
IsStackSubmenuHeader()296     bool IsStackSubmenuHeader()
297     {
298         return isStackSubmenuHeader_;
299     }
300     RefPtr<FrameNode> FindTouchedEmbeddedMenuItem(const PointF& position);
GetEmbeddedMenu()301     RefPtr<FrameNode> GetEmbeddedMenu() const
302     {
303         return embeddedMenu_;
304     }
305     void HideEmbedded(bool isNeedAnimation = true);
306     void OnHover(bool isHover);
307     void NotifyPressStatus(bool isPress);
308     void SetBgColor(const Color& color);
309     void SetFontColor(const Color& color, bool isNeedRecord = true);
310     void SetFontFamily(const std::vector<std::string>& value);
311     void SetFontSize(const Dimension& value);
312     void SetFontWeight(const FontWeight& value);
313     void SetItalicFontStyle(const Ace::FontStyle& value);
314     void SetSelected(int32_t selected);
315     void SetBorderColor(const Color& color);
316     Color GetBorderColor() const;
317     void SetBorderWidth(const Dimension& value);
318     Dimension GetBorderWidth() const;
319     void UpdateIcon(const std::string& src, const std::function<void(WeakPtr<NG::FrameNode>)> symbolIcon);
320     void UpdateNextNodeDivider(bool needDivider);
321     void UpdateText(const std::string& content);
322     Color GetBgColor();
323     Color GetFontColor();
324     Dimension GetFontSize();
325     Ace::FontStyle GetItalicFontStyle();
326     FontWeight GetFontWeight();
327     std::vector<std::string> GetFontFamily();
328     std::string GetText();
329     // XTS inspector functions
330     std::string InspectorGetFont();
331     float GetSelectOptionWidth();
332 
SetIcon(const std::string & src)333     inline void SetIcon(const std::string& src)
334     {
335         iconSrc_ = src;
336     }
GetIcon()337     inline const std::string& GetIcon()
338     {
339         return iconSrc_;
340     }
SetIsHover(bool isHover)341     inline void SetIsHover(bool isHover)
342     {
343         isHover_ = isHover;
344     }
IsHover()345     inline bool IsHover() const
346     {
347         return isHover_;
348     }
SetMenu(const WeakPtr<FrameNode> & menuWeak)349     inline void SetMenu(const WeakPtr<FrameNode>& menuWeak)
350     {
351         menuWeak_ = menuWeak;
352     }
GetMenuWeak()353     inline const WeakPtr<FrameNode>& GetMenuWeak() const
354     {
355         return menuWeak_;
356     }
SetIsWidthModifiedBySelect(bool isModified)357     inline void SetIsWidthModifiedBySelect(bool isModified)
358     {
359         isWidthModifiedBySelect_ = isModified;
360     }
IsWidthModifiedBySelect()361     inline bool IsWidthModifiedBySelect() const
362     {
363         return isWidthModifiedBySelect_;
364     }
SetIsSelectOption(bool isSelect)365     inline void SetIsSelectOption(bool isSelect)
366     {
367         isSelectOption_ = isSelect;
368     }
IsSelectOption()369     inline bool IsSelectOption() const
370     {
371         return isSelectOption_;
372     }
GetShowDefaultSelectedIcon()373     inline bool GetShowDefaultSelectedIcon() const
374     {
375         return showDefaultSelectedIcon_;
376     }
SetHasOptionWidth(bool hasOptionWidth)377     inline void SetHasOptionWidth(bool hasOptionWidth)
378     {
379         hasOptionWidth_ = hasOptionWidth;
380     }
GetHasOptionWidth()381     inline bool GetHasOptionWidth()
382     {
383         return hasOptionWidth_;
384     }
GetSelectTheme()385     inline const RefPtr<SelectTheme>& GetSelectTheme() const
386     {
387         return selectTheme_;
388     }
SetBlockClick(bool blockClick)389     inline void SetBlockClick(bool blockClick)
390     {
391         blockClick_ = blockClick;
392     }
SetTextNode(const RefPtr<FrameNode> & text)393     inline void SetTextNode(const RefPtr<FrameNode>& text)
394     {
395         text_ = text;
396     }
GetTextNode()397     inline RefPtr<FrameNode> GetTextNode() const
398     {
399         return text_;
400     }
SetIconNode(const RefPtr<FrameNode> & icon)401     inline void SetIconNode(const RefPtr<FrameNode>& icon)
402     {
403         icon_ = icon;
404     }
SetPasteButton(const RefPtr<FrameNode> & pasteButton)405     inline void SetPasteButton(const RefPtr<FrameNode>& pasteButton)
406     {
407         pasteButton_ = pasteButton;
408     }
SetOptionFontColor(const Color & color)409     inline void SetOptionFontColor(const Color& color)
410     {
411         optionFontColor_ = color;
412     }
IsExpanded()413     inline bool IsExpanded() const
414     {
415         return isExpanded_;
416     }
417     void AttachBottomDivider();
IsOptionPattern()418     inline bool IsOptionPattern()
419     {
420         return isOptionPattern_;
421     }
422     void RemoveBottomDivider();
423     void SetOptionTextModifier(const std::function<void(WeakPtr<NG::FrameNode>)>& optionApply);
424     void SetSelectedOptionTextModifier(const std::function<void(WeakPtr<NG::FrameNode>)>& optionSelectedApply);
425     std::function<void(WeakPtr<NG::FrameNode>)>& GetOptionTextModifier();
426     std::function<void(WeakPtr<NG::FrameNode>)>& GetSelectedOptionTextModifier();
427     void ApplyTextModifier(const std::function<void(WeakPtr<NG::FrameNode>)>& optionApply);
428     void ResetSelectTextProps();
429     void ApplyOptionThemeStyles();
430     void ApplySelectedThemeStyles();
431     void UpdateCheckMarkColor(const Color& color);
432     void SetShowDefaultSelectedIcon(bool show);
433     void SetCheckMarkVisibleType(VisibleType type);
434     void OnColorConfigurationUpdate() override;
435 
436 protected:
437     void RegisterOnKeyEvent();
438     void RegisterOnTouch();
439     void CreateBottomDivider();
440     void RegisterOnPress();
441     void OnAfterModifyDone() override;
442     RefPtr<FrameNode> GetMenuWrapper();
443     void InitFocusPadding();
444     Dimension focusPadding_ = 0.0_vp;
445     double menuFocusType_ = 0.0;
446 
447 private:
448     friend class ServiceCollaborationMenuAceHelper;
449     // register menu item's callback
450     void RegisterOnClick();
451     void RegisterOnHover();
452     void CleanParentMenuItemBgColor();
453     void SendSubMenuOpenToAccessibility(RefPtr<FrameNode>& subMenu, ShowSubMenuType type);
454     virtual void OnTouch(const TouchEventInfo& info);
455     virtual bool OnKeyEvent(const KeyEvent& event);
IsCustomMenuItem()456     virtual bool IsCustomMenuItem()
457     {
458         return false;
459     }
460     bool OnClick();
461 
462     void RegisterWrapperMouseEvent();
463 
464     void AddSelectIcon(RefPtr<FrameNode>& row);
465     void UpdateIcon(RefPtr<FrameNode>& row, bool isStart);
466     void AddExpandIcon(RefPtr<FrameNode>& row);
467     bool ISNeedAddExpandIcon(RefPtr<FrameNode>& row);
468     void AddClickableArea();
469     void SetRowAccessibilityLevel();
470     void UpdateText(RefPtr<FrameNode>& row, RefPtr<MenuLayoutProperty>& menuProperty, bool isLabel);
471     void UpdateTextMarquee(bool isMarqueeStart);
472     void UpdateTextOverflow(RefPtr<TextLayoutProperty>& textProperty, RefPtr<SelectTheme>& theme);
473     void InitTextFadeOut();
474     void UpdateFont(RefPtr<MenuLayoutProperty>& menuProperty, RefPtr<SelectTheme>& theme, bool isLabel);
475     void SetThemeProps(const RefPtr<FrameNode>& host);
476     void UpdateMaxLinesFromTheme(RefPtr<TextLayoutProperty>& textProperty);
477     void AddStackSubMenuHeader(RefPtr<FrameNode>& menuNode);
478     RefPtr<FrameNode> GetClickableArea();
479     void UpdateDisabledStyle();
480 
481     void ShowSubMenu(ShowSubMenuType type = ShowSubMenuType::DEFAULT);
482     RefPtr<UINode> BuildSubMenuCustomNode();
483     RefPtr<FrameNode> GetSubMenu(RefPtr<UINode>& customNode);
484     void UpdateSubmenuExpandingMode(RefPtr<UINode>& customNode);
485     void ShowSubMenuHelper(const RefPtr<FrameNode>& subMenu);
486     void HideSubMenu();
487     void OnExpandChanged(const RefPtr<FrameNode>& expandableNode);
488     void HideEmbeddedExpandMenu(const RefPtr<FrameNode>& expandableNode, bool isNeedAnimation = true);
489     void ShowEmbeddedExpandMenu(const RefPtr<FrameNode>& expandableNode);
490     void SetShowEmbeddedMenuParams(const RefPtr<FrameNode>& expandableNode);
491     void UpdatePreviewPosition(SizeF oldMenuSize, SizeF menuSize);
492     void MenuRemoveChild(const RefPtr<FrameNode>& expandableNode, bool isOutFocus);
493 
494     OffsetF GetSubMenuPosition(const RefPtr<FrameNode>& targetNode);
495 
496     void AddSelfHoverRegion(const RefPtr<FrameNode>& targetNode);
497     void SetAccessibilityAction();
498     bool IsSelectOverlayMenu();
499     void RecordChangeEvent() const;
500     bool ParseMenuBlurStyleEffect(MenuParam& param, const RefPtr<RenderContext>& parseMenuBlurStyleEffect);
501     void ParseMenuRadius(MenuParam& param);
502     void ModifyDivider();
503 
504     void NeedFocusEvent();
505     void InitFocusEvent();
506     void HandleFocusEvent();
507     void HandleBlurEvent();
508     bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow);
509 
510     void UpdateSymbolNode(RefPtr<FrameNode>& row, RefPtr<FrameNode>& selectIcon);
511     void UpdateImageNode(RefPtr<FrameNode>& row, RefPtr<FrameNode>& selectIcon);
512     void UpdateSymbolIcon(RefPtr<FrameNode>& row, RefPtr<FrameNode>& iconNode, ImageSourceInfo& iconSrc,
513         std::function<void(WeakPtr<NG::FrameNode>)>& symbol, bool isStart);
514     void UpdateImageIcon(RefPtr<FrameNode>& row, RefPtr<FrameNode>& iconNode, ImageSourceInfo& iconSrc,
515         std::function<void(WeakPtr<NG::FrameNode>)>& symbol, bool isStart);
516     bool UseDefaultThemeIcon(const ImageSourceInfo& imageSourceInfo);
517 
518     void OnPress(const UIState& state);
519     bool OnSelectProcess();
520     void OptionOnModifyDone(const RefPtr<FrameNode>& host);
521     void UpdateIconSrc();
522     bool UpdateOptionFocus(KeyCode code);
523     void UpdatePasteFontColor(const Color& fontColor);
524     void UpdatePasteDisabledOpacity(const double disabledColorAlpha);
525     void OptionHandleFocusEvent();
526     void OptionHandleBlurEvent();
527     void SetFocusStyle();
528     void ClearFocusStyle();
529     void PostHoverSubMenuTask();
530     void PerformHideSubMenu(std::function<void()> callback);
531     void UpdateDividerSelectedStatus(bool isSelected);
532     void UpdateDividerHoverStatus(bool isHover);
533     void UpdateDividerPressStatus(bool isPress);
534     void ShowSubMenuWithAnimation(const RefPtr<FrameNode>& subMenu);
535 
536     RefPtr<FrameNode> CreateCheckMarkNode(const RefPtr<FrameNode>& parent, uint32_t index);
537     // make render after measure and layout
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,const DirtySwapConfig & config)538     inline bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override
539     {
540         return !(config.skipMeasure && config.skipLayout);
541     }
542 
543     void HandleOptionBackgroundColor();
544     void HandleOptionFontColor();
545     RefPtr<SelectTheme> GetCurrentSelectTheme();
546 
547     std::list<TouchRegion> hoverRegions_;
548 
549     RefPtr<InputEvent> wrapperMouseEvent_;
550 
551     bool isSelected_ = false;
552     bool isSubMenuShowed_ = false;
553     bool isSubMenuHovered_ = false;
554 
555     bool isChanged_ = false;
556     bool isHovered_ = false;
557     bool isExpanded_ = false;
558     int32_t clickMenuItemId_ = -1;
559     std::function<void()> onClickAIMenuItem_ = nullptr;
560     int32_t index_ = 0;
561 
562     std::function<void()> subBuilderFunc_ = nullptr;
563     std::function<void(WeakPtr<NG::FrameNode>)> optionApply_ = nullptr;
564     std::function<void(WeakPtr<NG::FrameNode>)> optionSelectedApply_ = nullptr;
565 
566     int32_t subMenuId_ = -1;
567     RefPtr<FrameNode> subMenu_;
568     RefPtr<FrameNode> content_ = nullptr;
569     RefPtr<FrameNode> label_ = nullptr;
570     RefPtr<FrameNode> startIcon_ = nullptr;
571     RefPtr<FrameNode> endIcon_ = nullptr;
572     RefPtr<FrameNode> checkMarkNode_ = nullptr;
573     RefPtr<FrameNode> selectIcon_ = nullptr;
574     RefPtr<FrameNode> expandIcon_ = nullptr;
575     RefPtr<FrameNode> embeddedMenu_ = nullptr;
576     RefPtr<FrameNode> clickableArea_ = nullptr;
577     RefPtr<FrameNode> bottomDivider_ = nullptr;
578     WeakPtr<FrameNode> topDivider_ = nullptr;
579     RefPtr<LongPressEvent> longPressEvent_;
580     RefPtr<TouchEventImpl> onTouchEvent_;
581     std::function<void(UIState)> onPressEvent_;
582     RefPtr<InputEvent> onHoverEvent_;
583     RefPtr<ClickEvent> onClickEvent_;
584     RefPtr<FrameNode> endRowNode_ = nullptr;
585     bool onTouchEventSet_ = false;
586     bool onPressEventSet_ = false;
587     bool onHoverEventSet_ = false;
588     bool onKeyEventSet_ = false;
589     bool onClickEventSet_ = false;
590     SubMenuExpandingMode expandingMode_ = SubMenuExpandingMode::SIDE;
591     bool isStackSubmenuHeader_ = false;
592     bool expandingModeSet_ = false;
593 
594     Color bgBlendColor_ = Color::TRANSPARENT;
595     std::optional<Color> bgColor_;
596     std::optional<Color> fontColor_;
597     std::optional<Color> optionFontColor_;
598     std::function<void(bool)> isFocusActiveUpdateEvent_;
599     // src of icon image, used in XTS inspector
600     std::string iconSrc_;
601     WeakPtr<FrameNode> menuWeak_;
602     RefPtr<FrameNode> text_;
603     RefPtr<FrameNode> icon_;
604     RefPtr<FrameNode> pasteButton_;
605     RefPtr<TextTheme> textTheme_;
606     RefPtr<SelectTheme> selectTheme_;
607 
608     bool blockClick_ = false;
609     bool hasOptionWidth_ = false;
610     bool isHover_ = false;
611     bool isOptionPattern_ = false;  // if it is OptionPattern
612     bool showDefaultSelectedIcon_ = false;
613     bool isSelectOption_ = false;
614     bool isWidthModifiedBySelect_ = false;
615 
616     bool isFocused_ = false;
617     bool isFocusShadowSet_ = false;
618     bool isFocusBGColorSet_ = false;
619     bool isTextFadeOut_ = false;
620     int32_t rowSelected_ = -1;
621     CancelableCallback<void()> showTask_;
622     CancelableCallback<void()> hideTask_;
623     std::optional<PointF> lastInnerPosition_ = std::nullopt;
624     std::optional<PointF> lastOutterPosition_ = std::nullopt;
625     bool leaveFromBottom_ = false;
626 
627     ACE_DISALLOW_COPY_AND_MOVE(MenuItemPattern);
628 };
629 
630 class CustomMenuItemPattern : public MenuItemPattern {
631     DECLARE_ACE_TYPE(CustomMenuItemPattern, MenuItemPattern);
632 
633 public:
CreateLayoutAlgorithm()634     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
635     {
636         return MakeRefPtr<CustomMenuItemLayoutAlgorithm>();
637     }
638     void OnAttachToFrameNode() override;
639 
640 private:
641     void OnTouch(const TouchEventInfo& info) override;
642     void HandleOnChange();
643     bool OnKeyEvent(const KeyEvent& event) override;
IsCustomMenuItem()644     bool IsCustomMenuItem() override
645     {
646         return true;
647     }
648     std::unique_ptr<Offset> lastTouchOffset_;
649 };
650 } // namespace OHOS::Ace::NG
651 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_PATTERN_H
652