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