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, 41 const OffsetF& basePaintOffset); 42 bool UpdateMagnifierOffsetY(OffsetF& magnifierPaintOffset, VectorF& magnifierOffset, 43 const OffsetF& basePaintOffset); 44 bool UpdateMagnifierOffset(); 45 46 void UpdateShowMagnifier(bool isShowMagnifier = false); 47 GetShowMagnifier()48 bool GetShowMagnifier() const 49 { 50 return isShowMagnifier_; 51 } 52 53 void SetLocalOffset(OffsetF localOffset, std::optional<OffsetF> localOffsetWithoutTrans = std::nullopt) 54 { 55 localOffsetChanged_ = localOffset != localOffset_; 56 localOffset_.SetX(localOffset.GetX()); 57 localOffset_.SetY(localOffset.GetY()); 58 localOffsetWithoutTrans_ = localOffsetWithoutTrans; 59 magnifierNodeExist_ = true; 60 UpdateShowMagnifier(true); 61 } 62 GetLocalOffset()63 OffsetF GetLocalOffset() const 64 { 65 return localOffset_; 66 } 67 GetLocalOffsetWithoutTrans()68 std::optional<OffsetF> GetLocalOffsetWithoutTrans() const 69 { 70 return localOffsetWithoutTrans_; 71 } 72 GetMagnifierNode()73 RefPtr<FrameNode> GetMagnifierNode() const 74 { 75 return magnifierFrameNode_; 76 } 77 void ChangeMagnifierVisibility(const bool& visible); 78 79 void InitMagnifierParams(); 80 81 uint32_t ArgbToRgba(const uint32_t& color); 82 83 void RemoveMagnifierFrameNode(); 84 SetColorModeChange(const bool & colorModeChange)85 void SetColorModeChange(const bool& colorModeChange) 86 { 87 colorModeChange_ = colorModeChange; 88 } 89 RefPtr<FrameNode> GetRootNode(); 90 91 RefPtr<UINode> FindWindowScene(const RefPtr<FrameNode>& targetNode); 92 GetMagnifierNodeExist()93 bool GetMagnifierNodeExist() const 94 { 95 return magnifierNodeExist_; 96 } 97 SetHostViewPort(const RectF & viewPort)98 void SetHostViewPort(const RectF& viewPort) 99 { 100 hostViewPort_ = viewPort; 101 } 102 103 RectF GetViewPort(const RefPtr<FrameNode>& host); 104 private: 105 bool IsLocalOffsetInHostRange(const RefPtr<FrameNode>& host); 106 107 MagnifierParams params_; 108 bool visible_ = false; 109 void CreateMagnifierChildNode(); 110 RefPtr<FrameNode> magnifierFrameNode_ = nullptr; 111 bool isShowMagnifier_ = false; 112 OffsetF localOffset_; 113 std::optional<OffsetF> localOffsetWithoutTrans_; 114 WeakPtr<Pattern> pattern_; 115 bool localOffsetChanged_ = false; 116 bool removeFrameNode_ = false; 117 bool colorModeChange_ = false; 118 bool magnifierNodeExist_ = false; 119 Dimension magnifierNodeWidth_; 120 Dimension magnifierNodeHeight_; 121 std::optional<RectF> hostViewPort_; 122 }; 123 } // namespace OHOS::Ace::NG 124 125 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_PATTERN_MAGNIFIER_CONTROLLER_H 126