• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_PATTERN_PATTERNLOCK_PATTERNLOCK_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_PATTERN_H
18 
19 #include "base/geometry/axis.h"
20 #include "base/memory/ace_type.h"
21 #include "base/memory/referenced.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components_ng/event/event_hub.h"
24 #include "core/components_ng/pattern/pattern.h"
25 #include "core/components_ng/pattern/patternlock/patternlock_challenge.h"
26 #include "core/components_ng/pattern/patternlock/patternlock_event_hub.h"
27 #include "core/components_ng/pattern/patternlock/patternlock_layout_algorithm.h"
28 #include "core/components_ng/pattern/patternlock/patternlock_layout_property.h"
29 #include "core/components_ng/pattern/patternlock/patternlock_modifier.h"
30 #include "core/components_ng/pattern/patternlock/patternlock_paint_method.h"
31 #include "core/components_ng/pattern/patternlock/patternlock_paint_property.h"
32 #include "core/components_v2/pattern_lock/pattern_lock_controller.h"
33 #include "core/pipeline_ng/pipeline_context.h"
34 
35 namespace OHOS::Ace::NG {
36 class PatternLockPattern : public Pattern {
37     DECLARE_ACE_TYPE(PatternLockPattern, Pattern);
38 
39 public:
40     PatternLockPattern() = default;
41     ~PatternLockPattern() override = default;
42 
IsAtomicNode()43     bool IsAtomicNode() const override
44     {
45         return true;
46     }
47 
CreateLayoutProperty()48     RefPtr<LayoutProperty> CreateLayoutProperty() override
49     {
50         return MakeRefPtr<PatternLockLayoutProperty>();
51     }
52 
CreatePaintProperty()53     RefPtr<PaintProperty> CreatePaintProperty() override
54     {
55         return MakeRefPtr<PatternLockPaintProperty>();
56     }
57 
CreateLayoutAlgorithm()58     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
59     {
60         auto layoutAlgorithm = MakeRefPtr<PatternLockLayoutAlgorithm>();
61         return layoutAlgorithm;
62     }
63 
CreateNodePaintMethod()64     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
65     {
66         if (!patternLockModifier_) {
67             patternLockModifier_ = AceType::MakeRefPtr<PatternLockModifier>();
68         }
69         auto paintMethod =
70             MakeRefPtr<PatternLockPaintMethod>(cellCenter_, isMoveEventValid_, choosePoint_, patternLockModifier_);
71         return paintMethod;
72     }
73 
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,const DirtySwapConfig & config)74     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override
75     {
76         return true;
77     }
78 
CreateEventHub()79     RefPtr<EventHub> CreateEventHub() override
80     {
81         return MakeRefPtr<PatternLockEventHub>();
82     }
83 
GetPatternLockController()84     const RefPtr<V2::PatternLockController>& GetPatternLockController()
85     {
86         return patternLockController_;
87     }
88 
SetPatternLockController(const RefPtr<V2::PatternLockController> & patternLockController)89     void SetPatternLockController(const RefPtr<V2::PatternLockController>& patternLockController)
90     {
91         patternLockController_ = patternLockController;
92     }
93 
GetFocusPattern()94     FocusPattern GetFocusPattern() const override
95     {
96         FocusPaintParam focusPaintParams;
97         auto pipelineContext = PipelineBase::GetCurrentContext();
98         CHECK_NULL_RETURN(pipelineContext, FocusPattern());
99         auto patternLockTheme = pipelineContext->GetTheme<V2::PatternLockTheme>();
100         CHECK_NULL_RETURN(patternLockTheme, FocusPattern());
101         auto focusColor = patternLockTheme->GetFocusColor();
102         auto focusPaintWidth = patternLockTheme->GetFocusPaintWidth();
103         focusPaintParams.SetPaintWidth(Dimension(focusPaintWidth));
104         focusPaintParams.SetPaintColor(focusColor);
105         return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams };
106     }
107 
108 private:
109     void OnAttachToFrameNode() override;
110     void OnModifyDone() override;
111 
112     void InitTouchEvent(RefPtr<GestureEventHub>& gestureHub, RefPtr<TouchEventImpl>& touchDownListener);
113     void InitPatternLockController();
114     void HandleTouchEvent(const TouchEventInfo& info);
115     void OnTouchDown(const TouchEventInfo& info);
116     void AddPointEnd();
117     void OnTouchUp();
118     void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
119     void HandleGestureUpdate(const GestureEvent& info);
120 
121     bool CheckChoosePoint(int32_t x, int32_t y) const;
122     bool CheckInHotSpot(const OffsetF& offset, int32_t x, int32_t y);
123     bool AddChoosePoint(const OffsetF& offset, int32_t x, int32_t y);
124     void AddPassPoint(int32_t x, int32_t y);
125     void HandleReset();
126     void SetChallengeResult(V2::PatternLockChallengeResult challengeResult);
127     bool CheckAutoReset() const;
128 
129     void InitFocusEvent();
130     void HandleFocusEvent();
131     void HandleBlurEvent();
132     void GetInnerFocusPaintRect(RoundRect& paintRect);
133     void OnFocusClick();
134     void PaintFocusState();
135     void OnKeyDrapUp();
136     void OnKeyDrapDown();
137     void OnKeyDrapLeft();
138     void OnKeyDrapRight();
139     bool OnKeyEvent(const KeyEvent& event);
140     void InitMouseEvent();
141     void HandleHoverEvent(bool isHover);
142     void HandleMouseEvent(const MouseInfo& info);
143     void StartModifierConnectedAnimate(int32_t x, int32_t y);
144     void StartModifierAddPassPointAnimate(int32_t x, int32_t y);
145     void StartModifierCanceledAnimate();
146 
147     RefPtr<V2::PatternLockController> patternLockController_;
148     RefPtr<TouchEventImpl> touchDownListener_;
149     RefPtr<TouchEventImpl> touchUpListener_;
150     RefPtr<TouchEventImpl> touchMoveListener_;
151     RefPtr<PanEvent> panEvent_;
152 
153     bool isMoveEventValid_ = false;
154     std::vector<PatternLockCell> choosePoint_;
155     int32_t passPointCount_ = 0;
156     OffsetF cellCenter_;
157 
158     mutable bool autoReset_ = true;
159     Dimension circleRadius_;
160 
161     RefPtr<PatternLockModifier> patternLockModifier_;
162     std::pair<int32_t, int32_t> currentPoint_;
163 
164     ACE_DISALLOW_COPY_AND_MOVE(PatternLockPattern);
165 };
166 } // namespace OHOS::Ace::NG
167 
168 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_PATTERN_H
169