1 /* 2 * Copyright (c) 2024 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_TEXT_FIELD_PATTERN_MAGNIFIER_CONTROLLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_MAGNIFIER_CONTROLLER_H 18 19 #include "base/memory/type_info_base.h" 20 #include "base/geometry/ng/offset_t.h" 21 #include "base/geometry/ng/size_t.h" 22 #include "base/memory/ace_type.h" 23 #include "base/memory/referenced.h" 24 #include "core/components_ng/pattern/pattern.h" 25 #include "core/components_ng/render/drawing_forward.h" 26 #include "frameworks/base/memory/referenced.h" 27 28 namespace OHOS::Ace::NG { 29 30 class MagnifierController : public virtual AceType { 31 DECLARE_ACE_TYPE(MagnifierController, AceType); 32 33 public: MagnifierController(const WeakPtr<Pattern> & pattern)34 explicit MagnifierController(const WeakPtr<Pattern>& pattern) : pattern_(pattern) {} 35 ~MagnifierController() override = default; 36 37 void OpenMagnifier(); 38 void CloseMagnifier(); 39 40 bool UpdateMagnifierOffsetX(OffsetF& magnifierPaintOffset, VectorF& magnifierOffset, const OffsetF& basePaintOffset, 41 const RefPtr<FrameNode>& host); 42 bool UpdateMagnifierOffsetY(OffsetF& magnifierPaintOffset, VectorF& magnifierOffset, const OffsetF& basePaintOffset, 43 const RefPtr<FrameNode>& host); 44 bool UpdateMagnifierOffset(); 45 46 void UpdateShowMagnifier(bool isShowMagnifier = false); 47 GetShowMagnifier()48 bool GetShowMagnifier() const 49 { 50 return isShowMagnifier_; 51 } 52 SetLocalOffset(OffsetF localOffset)53 void SetLocalOffset(OffsetF localOffset) 54 { 55 localOffset_.SetX(localOffset.GetX()); 56 localOffset_.SetY(localOffset.GetY()); 57 magnifierNodeExist_ = true; 58 UpdateShowMagnifier(true); 59 } 60 GetLocalOffset()61 OffsetF GetLocalOffset() const 62 { 63 return localOffset_; 64 } 65 GetMagnifierNode()66 RefPtr<FrameNode> GetMagnifierNode() const 67 { 68 return magnifierFrameNode_; 69 } 70 void ChangeMagnifierVisibility(const bool& visible); 71 72 void InitMagnifierParams(); 73 74 uint32_t ArgbToRgba(const uint32_t& color); 75 76 void RemoveMagnifierFrameNode(); 77 SetColorModeChange(const bool & colorModeChange)78 void SetColorModeChange(const bool& colorModeChange) 79 { 80 colorModeChange_ = colorModeChange; 81 } 82 RefPtr<FrameNode> GetRootNode(); 83 84 RefPtr<UINode> FindWindowScene(const RefPtr<FrameNode>& targetNode); 85 GetMagnifierNodeExist()86 bool GetMagnifierNodeExist() const 87 { 88 return magnifierNodeExist_; 89 } 90 private: 91 MagnifierParams params_; 92 bool visible_ = false; 93 void CreateMagnifierChildNode(); 94 95 RefPtr<FrameNode> magnifierFrameNode_ = nullptr; 96 bool isShowMagnifier_ = false; 97 OffsetF localOffset_; 98 WeakPtr<Pattern> pattern_; 99 bool removeFrameNode_ = false; 100 bool colorModeChange_ = false; 101 bool magnifierNodeExist_ = false; 102 Dimension magnifierNodeWidth_; 103 Dimension magnifierNodeHeight_; 104 }; 105 } // namespace OHOS::Ace::NG 106 107 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_MAGNIFIER_CONTROLLER_H 108