• 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_PREVIEW_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_PREVIEW_PATTERN_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/memory/referenced.h"
21 #include "base/utils/string_utils.h"
22 #include "base/utils/utils.h"
23 #include "core/components/common/properties/color.h"
24 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
25 #include "core/components_ng/pattern/menu/menu_pattern.h"
26 #include "core/components_ng/pattern/menu/menu_theme.h"
27 #include "core/components_ng/pattern/menu/preview/menu_preview_layout_algorithm.h"
28 #include "core/components_ng/pattern/pattern.h"
29 #include "core/components_v2/inspector/inspector_constants.h"
30 #include "core/pipeline_ng/ui_task_scheduler.h"
31 
32 namespace OHOS::Ace::NG {
33 class MenuPreviewPattern : public LinearLayoutPattern {
34     DECLARE_ACE_TYPE(MenuPreviewPattern, Pattern);
35 
36 public:
MenuPreviewPattern()37     MenuPreviewPattern() : LinearLayoutPattern(true) {}
38     ~MenuPreviewPattern() override = default;
39 
CreateLayoutAlgorithm()40     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
41     {
42         return MakeRefPtr<MenuPreviewLayoutAlgorithm>();
43     }
44 
SetFirstShow()45     void SetFirstShow()
46     {
47         isFirstShow_ = true;
48     }
49 
SetHasPreviewTransitionEffect(bool hasPreviewTransitionEffect)50     void SetHasPreviewTransitionEffect(bool hasPreviewTransitionEffect)
51     {
52         hasPreviewTransitionEffect_ = hasPreviewTransitionEffect;
53     }
54 
SetIsShowHoverImage(bool isShow)55     void SetIsShowHoverImage(bool isShow)
56     {
57         isShowHoverImage_ = isShow;
58     }
59 
GetIsShowHoverImage()60     bool GetIsShowHoverImage() const
61     {
62         return isShowHoverImage_;
63     }
64 
SetHoverImageAfterScaleWidth(float width)65     void SetHoverImageAfterScaleWidth(float width)
66     {
67         hoverImageAfterScaleWidth_ = width;
68     }
69 
GetHoverImageAfterScaleWidth()70     float GetHoverImageAfterScaleWidth() const
71     {
72         return hoverImageAfterScaleWidth_;
73     }
74 
SetHoverImageAfterScaleHeight(float height)75     void SetHoverImageAfterScaleHeight(float height)
76     {
77         hoverImageAfterScaleHeight_ = height;
78     }
79 
GetHoverImageAfterScaleHeight()80     float GetHoverImageAfterScaleHeight() const
81     {
82         return hoverImageAfterScaleHeight_;
83     }
84 
SetClipStartWidth(float width)85     void SetClipStartWidth(float width)
86     {
87         clipStartWidth_ = width;
88     }
89 
GetClipStartWidth()90     float GetClipStartWidth() const
91     {
92         return clipStartWidth_;
93     }
94 
SetClipStartHeight(float height)95     void SetClipStartHeight(float height)
96     {
97         clipStartHeight_ = height;
98     }
99 
GetClipStartHeight()100     float GetClipStartHeight() const
101     {
102         return clipStartHeight_;
103     }
104 
SetClipStartValue(float value)105     void SetClipStartValue(float value)
106     {
107         clipStartVal_ = value;
108     }
109 
GetClipStartValue()110     float GetClipStartValue() const
111     {
112         return clipStartVal_;
113     }
114 
SetClipEndValue(float value)115     void SetClipEndValue(float value)
116     {
117         clipEndVal_ = value;
118     }
119 
GetClipEndValue()120     float GetClipEndValue() const
121     {
122         return clipEndVal_;
123     }
124 
SetHoverImageAfterScaleOffset(const OffsetF & offset)125     void SetHoverImageAfterScaleOffset(const OffsetF& offset)
126     {
127         hoverImageAfterScaleOffset_ = offset;
128     }
129 
GetHoverImageAfterScaleOffset()130     OffsetF GetHoverImageAfterScaleOffset() const
131     {
132         return hoverImageAfterScaleOffset_;
133     }
134 
SetCustomPreviewWidth(float width)135     void SetCustomPreviewWidth(float width)
136     {
137         customPreviewWidth_ = width;
138     }
139 
GetCustomPreviewWidth()140     float GetCustomPreviewWidth() const
141     {
142         return customPreviewWidth_;
143     }
144 
SetCustomPreviewHeight(float height)145     void SetCustomPreviewHeight(float height)
146     {
147         customPreviewHeight_ = height;
148     }
149 
GetCustomPreviewHeight()150     float GetCustomPreviewHeight() const
151     {
152         return customPreviewHeight_;
153     }
154 
SetStackAfterScaleActualWidth(float width)155     void SetStackAfterScaleActualWidth(float width)
156     {
157         stackAfterScaleActualWidth_ = width;
158     }
159 
GetStackAfterScaleActualWidth()160     float GetStackAfterScaleActualWidth() const
161     {
162         return stackAfterScaleActualWidth_;
163     }
164 
SetStackAfterScaleActualHeight(float height)165     void SetStackAfterScaleActualHeight(float height)
166     {
167         stackAfterScaleActualHeight_ = height;
168     }
169 
GetStackAfterScaleActualHeight()170     float GetStackAfterScaleActualHeight() const
171     {
172         return stackAfterScaleActualHeight_;
173     }
174 
SetIsWidthDistLarger(bool widthDistLarger)175     void SetIsWidthDistLarger(bool widthDistLarger)
176     {
177         isWidthDistLarge_ = widthDistLarger;
178     }
179 
GetIsWidthDistLarger()180     bool GetIsWidthDistLarger() const
181     {
182         return isWidthDistLarge_;
183     }
184 
SetHoverImageScaleFrom(float scaleFrom)185     void SetHoverImageScaleFrom(float scaleFrom)
186     {
187         hoverImageScaleFrom_ = scaleFrom;
188     }
189 
GetHoverImageScaleFrom()190     float GetHoverImageScaleFrom() const
191     {
192         return hoverImageScaleFrom_;
193     }
194 
SetHoverImageScaleTo(float scaleTo)195     void SetHoverImageScaleTo(float scaleTo)
196     {
197         hoverImageScaleTo_ = scaleTo;
198     }
199 
GetHoverImageScaleTo()200     float GetHoverImageScaleTo() const
201     {
202         return hoverImageScaleTo_;
203     }
204 
SetCustomPreviewScaleTo(float scaleTo)205     void SetCustomPreviewScaleTo(float scaleTo)
206     {
207         customPreviewScaleTo_ = scaleTo;
208     }
209 
GetCustomPreviewScaleTo()210     float GetCustomPreviewScaleTo() const
211     {
212         return customPreviewScaleTo_;
213     }
214     RefPtr<FrameNode> GetMenuWrapper() const;
215 
SetIsHoverImageScalePlaying(bool isPlay)216     void SetIsHoverImageScalePlaying(bool isPlay)
217     {
218         isHoverImageScalePlaying_ = isPlay;
219     }
220 
IsHoverImageScalePlaying()221     bool IsHoverImageScalePlaying()
222     {
223         return isHoverImageScalePlaying_;
224     }
225 
SetIsHoverImagePreviewScalePlaying(bool isPlay)226     void SetIsHoverImagePreviewScalePlaying(bool isPlay)
227     {
228         isHoverImagePreviewScalePlaying_ = isPlay;
229     }
230 
IsHoverImagePreviewScalePlaying()231     bool IsHoverImagePreviewScalePlaying()
232     {
233         return isHoverImagePreviewScalePlaying_;
234     }
235 
236 private:
237     void OnModifyDone() override;
238     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
239     void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
240     void HandleDragEnd(float offsetX, float offsetY, float velocity);
241     void UpdateShowScale(const RefPtr<RenderContext>& context, const RefPtr<MenuTheme>& menuTheme,
242         const RefPtr<MenuPattern>& menuPattern);
243     bool isFirstShow_ = false;
244     bool hasPreviewTransitionEffect_ = false;
245 
246     bool isShowHoverImage_ = false;
247     bool isWidthDistLarge_ = false;
248     bool isHoverImageScalePlaying_ = false;
249     bool isHoverImagePreviewScalePlaying_ = false;
250     OffsetF hoverImageAfterScaleOffset_;
251     float hoverImageAfterScaleWidth_ = 0.0f;
252     float hoverImageAfterScaleHeight_ = 0.0f;
253     float clipStartWidth_ = 0.0f;
254     float clipStartHeight_ = 0.0f;
255     float clipStartVal_ = 0.0f;
256     float clipEndVal_ = 0.0f;
257     float customPreviewWidth_ = 0.0f;
258     float customPreviewHeight_ = 0.0f;
259     float stackAfterScaleActualWidth_ = 0.0f;
260     float stackAfterScaleActualHeight_ = 0.0f;
261     float hoverImageScaleFrom_ = 1.0f;
262     float hoverImageScaleTo_ = 1.0f;
263     float customPreviewScaleTo_ = 1.0f;
264     ACE_DISALLOW_COPY_AND_MOVE(MenuPreviewPattern);
265 };
266 } // namespace OHOS::Ace::NG
267 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_PREVIEW_PATTERN_H
268