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 if (!isInitVirtualNode_ && AceApplicationInfo::GetInstance().IsAccessibilityEnabled()) { 70 isInitVirtualNode_ = InitVirtualNode(); 71 } 72 CalculateCellCenter(); 73 auto paintMethod = 74 MakeRefPtr<PatternLockPaintMethod>(cellCenter_, isMoveEventValid_, choosePoint_, patternLockModifier_); 75 return paintMethod; 76 } 77 OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,const DirtySwapConfig & config)78 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override 79 { 80 return true; 81 } 82 CreateEventHub()83 RefPtr<EventHub> CreateEventHub() override 84 { 85 return MakeRefPtr<PatternLockEventHub>(); 86 } 87 GetPatternLockController()88 const RefPtr<V2::PatternLockController>& GetPatternLockController() 89 { 90 return patternLockController_; 91 } 92 SetPatternLockController(const RefPtr<V2::PatternLockController> & patternLockController)93 void SetPatternLockController(const RefPtr<V2::PatternLockController>& patternLockController) 94 { 95 patternLockController_ = patternLockController; 96 } 97 GetFocusPattern()98 FocusPattern GetFocusPattern() const override 99 { 100 FocusPaintParam focusPaintParams; 101 auto pipelineContext = PipelineBase::GetCurrentContext(); 102 CHECK_NULL_RETURN(pipelineContext, FocusPattern()); 103 auto patternLockTheme = pipelineContext->GetTheme<V2::PatternLockTheme>(); 104 CHECK_NULL_RETURN(patternLockTheme, FocusPattern()); 105 auto focusColor = patternLockTheme->GetFocusColor(); 106 auto focusPaintWidth = patternLockTheme->GetFocusPaintWidth(); 107 focusPaintParams.SetPaintWidth(Dimension(focusPaintWidth)); 108 focusPaintParams.SetPaintColor(focusColor); 109 return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams }; 110 } 111 112 private: 113 void OnAttachToFrameNode() override; 114 void OnModifyDone() override; 115 116 void InitTouchEvent(RefPtr<GestureEventHub>& gestureHub, RefPtr<TouchEventImpl>& touchDownListener); 117 void InitPatternLockController(); 118 void InitAccessibilityHoverEvent(); 119 void HandleAccessibilityHoverEvent(bool state, AccessibilityHoverInfo& info); 120 bool InitVirtualNode(); 121 RefPtr<FrameNode> AddTextNodeIntoVirtual(int32_t x, int32_t y, float handleCircleRadius); 122 void HandleTextOnAccessibilityFocusCallback(int32_t x, int32_t y); 123 void ModifyAccessibilityVirtualNode(); 124 bool GetHandleCircleRadius(float& handleCircleRadius); 125 std::string ReplacePlaceHolder(const std::string& str, int32_t number); 126 void UpdateAccessibilityTextNode(RefPtr<FrameNode> frameNode, float handleCircleRadius, int32_t x, int32_t y); 127 void HandleTouchEvent(const TouchEventInfo& info); 128 void OnTouchDown(const TouchLocationInfo& info); 129 void OnTouchMove(const TouchLocationInfo& info); 130 void AddPointEnd(); 131 void OnTouchUp(); 132 void HandleGestureUpdate(const GestureEvent& info); 133 134 bool CheckChoosePoint(int32_t x, int32_t y) const; 135 bool CheckInHotSpot(const OffsetF& offset, int32_t x, int32_t y); 136 void UpdateDotConnectEvent(); 137 void AddPassPointToChoosePoint(int32_t lastCode, int32_t nowCode, std::vector<PatternLockCell> passPointVec); 138 bool AddChoosePoint(const OffsetF& offset, int32_t x, int32_t y); 139 void AddPassPoint(int32_t x, int32_t y); 140 void HandleReset(); 141 void SetChallengeResult(V2::PatternLockChallengeResult challengeResult); 142 bool CheckAutoReset() const; 143 144 void InitFocusEvent(); 145 void HandleFocusEvent(); 146 void HandleBlurEvent(); 147 void GetInnerFocusPaintRect(RoundRect& paintRect); 148 void OnFocusClick(); 149 void PaintFocusState(); 150 void OnKeyDrapUp(); 151 void OnKeyDrapDown(); 152 void OnKeyDrapLeft(); 153 void OnKeyDrapRight(); 154 bool OnKeyEvent(const KeyEvent& event); 155 void InitMouseEvent(); 156 void HandleHoverEvent(bool isHover); 157 void HandleMouseEvent(const MouseInfo& info); 158 void StartModifierConnectedAnimate(int32_t x, int32_t y); 159 void StartModifierAddPassPointAnimate(int32_t x, int32_t y); 160 void StartModifierCanceledAnimate(); 161 OffsetF GetLastChoosePointOffset(); 162 void CalculateCellCenter(); 163 OffsetF GetTouchOffsetToNode(); 164 void InitSkipUnselectedPoint(); 165 166 RefPtr<V2::PatternLockController> patternLockController_; 167 RefPtr<TouchEventImpl> touchDownListener_; 168 RefPtr<TouchEventImpl> touchUpListener_; 169 RefPtr<TouchEventImpl> touchMoveListener_; 170 RefPtr<PanEvent> panEvent_; 171 OffsetF screenTouchPoint_; 172 std::vector<RefPtr<AccessibilityProperty>> accessibilityPropertyVec_; 173 std::vector<RefPtr<FrameNode>> textAccessibilityNodeVec_; 174 bool isInitVirtualNode_ = false; 175 176 bool isMoveEventValid_ = false; 177 bool isOnKeyEventState_ = false; 178 std::vector<PatternLockCell> choosePoint_; 179 int32_t passPointCount_ = 0; 180 OffsetF cellCenter_; 181 int32_t fingerId_ = -1; 182 183 mutable bool autoReset_ = true; 184 bool skipUnselectedPoint_ = false; 185 Dimension circleRadius_; 186 187 RefPtr<PatternLockModifier> patternLockModifier_; 188 std::pair<int32_t, int32_t> currentPoint_; 189 190 ACE_DISALLOW_COPY_AND_MOVE(PatternLockPattern); 191 }; 192 } // namespace OHOS::Ace::NG 193 194 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_PATTERN_H 195