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>(WeakClaim(this)); 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 IsEnableMatchParent()112 bool IsEnableMatchParent() override 113 { 114 return true; 115 } 116 117 void UpdateSelectedColor(const Color& color, bool isFristLoad = false); 118 void UpdatePathColor(const Color& color, bool isFristLoad = false); 119 void UpdateActiveColor(const Color& color, bool isFristLoad = false); 120 void UpdateRegularColor(const Color& color, bool isFristLoad = false); 121 void UpdateCircleRadius(const CalcDimension& radius, bool isFristLoad = false); 122 void UpdateSideLength(const CalcDimension& sideLength, bool isFristLoad = false); 123 void UpdateActiveCircleColor(const Color& color, bool isFristLoad = false); 124 private: 125 void OnAttachToFrameNode() override; 126 void OnModifyDone() override; 127 128 void InitTouchEvent(RefPtr<GestureEventHub>& gestureHub, RefPtr<TouchEventImpl>& touchDownListener); 129 void InitPatternLockController(); 130 void InitAccessibilityHoverEvent(); 131 void HandleAccessibilityHoverEvent(bool state, AccessibilityHoverInfo& info); 132 bool InitVirtualNode(); 133 RefPtr<FrameNode> AddTextNodeIntoVirtual(int32_t x, int32_t y, float handleCircleRadius); 134 void HandleTextOnAccessibilityFocusCallback(int32_t x, int32_t y); 135 void ModifyAccessibilityVirtualNode(); 136 bool GetHandleCircleRadius(float& handleCircleRadius); 137 std::string ReplacePlaceHolder(const std::string& str, int32_t number); 138 void UpdateAccessibilityTextNode(RefPtr<FrameNode> frameNode, float handleCircleRadius, int32_t x, int32_t y); 139 void HandleTouchEvent(const TouchEventInfo& info); 140 void OnTouchDown(const TouchLocationInfo& info); 141 void OnTouchMove(const TouchLocationInfo& info); 142 void AddPointEnd(); 143 void OnTouchUp(); 144 void HandleGestureUpdate(const GestureEvent& info); 145 146 bool CheckChoosePoint(int32_t x, int32_t y) const; 147 bool CheckInHotSpot(const OffsetF& offset, int32_t x, int32_t y); 148 void UpdateDotConnectEvent(); 149 void AddPassPointToChoosePoint(int32_t lastCode, int32_t nowCode, std::vector<PatternLockCell> passPointVec); 150 bool AddChoosePoint(const OffsetF& offset, int32_t x, int32_t y); 151 void AddPassPoint(int32_t x, int32_t y); 152 void HandleReset(); 153 void SetChallengeResult(V2::PatternLockChallengeResult challengeResult); 154 bool CheckAutoReset() const; 155 156 void InitFocusEvent(); 157 void HandleFocusEvent(); 158 void HandleBlurEvent(); 159 void GetInnerFocusPaintRect(RoundRect& paintRect); 160 void OnFocusClick(); 161 void PaintFocusState(); 162 void OnKeyDrapUp(); 163 void OnKeyDrapDown(); 164 void OnKeyDrapLeft(); 165 void OnKeyDrapRight(); 166 bool OnKeyEvent(const KeyEvent& event); 167 void InitMouseEvent(); 168 void HandleHoverEvent(bool isHover); 169 void HandleMouseEvent(const MouseInfo& info); 170 void StartModifierConnectedAnimate(int32_t x, int32_t y); 171 void StartModifierAddPassPointAnimate(int32_t x, int32_t y); 172 void StartModifierCanceledAnimate(); 173 OffsetF GetLastChoosePointOffset(); 174 void CalculateCellCenter(); 175 OffsetF GetTouchOffsetToNode(); 176 void InitSkipUnselectedPoint(); 177 void OnColorConfigurationUpdate() override; 178 RefPtr<V2::PatternLockController> patternLockController_; 179 RefPtr<TouchEventImpl> touchDownListener_; 180 RefPtr<TouchEventImpl> touchUpListener_; 181 RefPtr<TouchEventImpl> touchMoveListener_; 182 RefPtr<PanEvent> panEvent_; 183 OffsetF screenTouchPoint_; 184 std::vector<RefPtr<AccessibilityProperty>> accessibilityPropertyVec_; 185 std::vector<RefPtr<FrameNode>> textAccessibilityNodeVec_; 186 bool isInitVirtualNode_ = false; 187 188 bool isMoveEventValid_ = false; 189 bool isOnKeyEventState_ = false; 190 std::vector<PatternLockCell> choosePoint_; 191 int32_t passPointCount_ = 0; 192 OffsetF cellCenter_; 193 int32_t fingerId_ = -1; 194 195 mutable bool autoReset_ = true; 196 bool skipUnselectedPoint_ = false; 197 Dimension circleRadius_; 198 199 RefPtr<PatternLockModifier> patternLockModifier_; 200 std::pair<int32_t, int32_t> currentPoint_; 201 202 ACE_DISALLOW_COPY_AND_MOVE(PatternLockPattern); 203 }; 204 } // namespace OHOS::Ace::NG 205 206 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_PATTERN_H 207