• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_WRAPPER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_WRAPPER_PATTERN_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/memory/referenced.h"
21 #include "base/subwindow/subwindow_manager.h"
22 #include "base/utils/string_utils.h"
23 #include "base/utils/utils.h"
24 #include "core/components/common/properties/color.h"
25 #include "core/components_ng/pattern/menu/menu_item/menu_item_pattern.h"
26 #include "core/components_ng/pattern/menu/menu_layout_algorithm.h"
27 #include "core/components_ng/pattern/menu/menu_layout_property.h"
28 #include "core/components_ng/pattern/menu/menu_paint_method.h"
29 #include "core/components_ng/pattern/menu/menu_pattern.h"
30 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_layout_algorithm.h"
31 #include "core/components_ng/pattern/pattern.h"
32 #include "core/components_v2/inspector/inspector_constants.h"
33 #include "core/pipeline_ng/ui_task_scheduler.h"
34 
35 namespace OHOS::Ace::NG {
36 
37 // has full screen size
38 // used for detecting clicks outside Menu area
39 class MenuWrapperPattern : public Pattern {
40     DECLARE_ACE_TYPE(MenuWrapperPattern, Pattern);
41 
42 public:
MenuWrapperPattern(int32_t Id)43     explicit MenuWrapperPattern(int32_t Id) : targetId_(Id) {}
44     ~MenuWrapperPattern() override = default;
45 
IsAtomicNode()46     bool IsAtomicNode() const override
47     {
48         return false;
49     }
50 
GetFocusPattern()51     FocusPattern GetFocusPattern() const override
52     {
53         return { FocusType::SCOPE, true };
54     }
55 
CreateLayoutAlgorithm()56     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
57     {
58         return MakeRefPtr<MenuWrapperLayoutAlgorithm>();
59     }
60 
61     void HandleMouseEvent(const MouseInfo& info, RefPtr<MenuItemPattern>& menuItem);
62 
GetTargetId()63     int32_t GetTargetId() const
64     {
65         return targetId_;
66     }
67 
68     void HideMenu();
69 
AddSubMenuId(int32_t subMenuId)70     void AddSubMenuId(int32_t subMenuId)
71     {
72         subMenuIds_.emplace_back(subMenuId);
73     }
74 
IsHided()75     bool IsHided() const
76     {
77         return isHided_;
78     }
79 
IsContextMenu()80     bool IsContextMenu() const
81     {
82         auto menu = GetMenu();
83         CHECK_NULL_RETURN(menu, false);
84         auto menuPattern = menu->GetPattern<MenuPattern>();
85         CHECK_NULL_RETURN(menuPattern, false);
86         return menuPattern->IsContextMenu();
87     }
88 
IsSelectMenu()89     bool IsSelectMenu() const
90     {
91         auto menu = GetMenu();
92         CHECK_NULL_RETURN(menu, false);
93         auto menuPattern = menu->GetPattern<MenuPattern>();
94         CHECK_NULL_RETURN(menuPattern, false);
95         return menuPattern->IsSelectMenu();
96     }
97 
98     void HideSubMenu();
99 
100 private:
101     void OnModifyDone() override;
102 
103     void HideMenu(const RefPtr<FrameNode>& menu);
104 
GetMenu()105     RefPtr<FrameNode> GetMenu() const
106     {
107         auto host = GetHost();
108         CHECK_NULL_RETURN(host, nullptr);
109         auto menu = AceType::DynamicCast<FrameNode>(host->GetChildAtIndex(0));
110         CHECK_NULL_RETURN(menu, nullptr);
111         return menu;
112     }
113 
114     RefPtr<TouchEventImpl> onTouch_;
115     // menuId in OverlayManager's map
116     int32_t targetId_ = -1;
117 
118     bool isHided_ = false;
119 
120     std::list<int32_t> subMenuIds_;
121 
122     ACE_DISALLOW_COPY_AND_MOVE(MenuWrapperPattern);
123 };
124 } // namespace OHOS::Ace::NG
125 
126 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_WRAPPER_PATTERN_H
127