• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025-2025 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 // LCOV_EXCL_START
17 #include "full_screen_magnification_manager.h"
18 #include "accessible_ability_manager_service.h"
19 #include "magnification_menu_manager.h"
20 #include "utils.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 namespace {
25 }
26 
FullScreenMagnificationManager(std::shared_ptr<MagnificationWindowProxy> proxy)27 FullScreenMagnificationManager::FullScreenMagnificationManager(
28     std::shared_ptr<MagnificationWindowProxy> proxy) : windowProxy_(proxy)
29 {
30 }
31 
EnableMagnification(int32_t centerX,int32_t centerY)32 void FullScreenMagnificationManager::EnableMagnification(int32_t centerX, int32_t centerY)
33 {
34     HILOG_INFO("centerX = %{public}d, centerY = %{public}d.", centerX, centerY);
35     CHECK_PROXY_PTR_VOID()
36     float scale = Singleton<AccessibleAbilityManagerService>::GetInstance().GetMagnificationScale();
37     windowProxy_->InitMagnificationParam(scale);
38     windowProxy_->EnableMagnification(FULL_SCREEN_MAGNIFICATION, centerX, centerY);
39 }
40 
ShowMagnification()41 void FullScreenMagnificationManager::ShowMagnification()
42 {
43     CHECK_PROXY_PTR_VOID()
44     windowProxy_->ShowMagnification(FULL_SCREEN_MAGNIFICATION);
45 }
46 
ShowMagnificationWithPosition(PointerPos pos)47 void FullScreenMagnificationManager::ShowMagnificationWithPosition(PointerPos pos)
48 {
49     if (pos.posX == 0 && pos.posY == 0) {
50         ShowMagnification();
51     } else {
52         EnableMagnification(pos.posX, pos.posY);
53     }
54 }
55 
DisableMagnification(bool needClear)56 void FullScreenMagnificationManager::DisableMagnification(bool needClear)
57 {
58     HILOG_INFO();
59     CHECK_PROXY_PTR_VOID()
60     std::lock_guard<ffrt::mutex> lock(mutex_);
61     windowProxy_->DisableMagnification(FULL_SCREEN_MAGNIFICATION, needClear);
62 }
63 
SetScale(float scaleSpan)64 void FullScreenMagnificationManager::SetScale(float scaleSpan)
65 {
66     HILOG_DEBUG();
67     CHECK_PROXY_PTR_VOID()
68     windowProxy_->SetScale(FULL_SCREEN_MAGNIFICATION, scaleSpan);
69 }
70 
MoveMagnification(int32_t deltaX,int32_t deltaY)71 void FullScreenMagnificationManager::MoveMagnification(int32_t deltaX, int32_t deltaY)
72 {
73     CHECK_PROXY_PTR_VOID()
74     windowProxy_->MoveMagnification(FULL_SCREEN_MAGNIFICATION, deltaX, deltaY);
75 }
76 
PersistScale()77 void FullScreenMagnificationManager::PersistScale()
78 {
79     CHECK_PROXY_PTR_VOID()
80     float scale = windowProxy_->GetScale();
81     HILOG_DEBUG("scale = %{public}f", scale);
82     Singleton<AccessibleAbilityManagerService>::GetInstance().SetMagnificationScale(scale);
83     Singleton<AccessibleAbilityManagerService>::GetInstance().AnnouncedForMagnification(
84         AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE);
85 }
86 
RefreshWindowParam(RotationType type)87 void FullScreenMagnificationManager::RefreshWindowParam(RotationType type)
88 {
89     HILOG_DEBUG();
90     CHECK_PROXY_PTR_VOID()
91     windowProxy_->RefreshWindowParam(FULL_SCREEN_MAGNIFICATION, type);
92 }
93 
ConvertCoordinates(int32_t posX,int32_t posY)94 PointerPos FullScreenMagnificationManager::ConvertCoordinates(int32_t posX, int32_t posY)
95 {
96     PointerPos pos = {posX, posY};
97     if (windowProxy_ == nullptr) {
98         HILOG_ERROR("windowProxy_ is nullptr.");
99         return pos;
100     }
101     return windowProxy_->ConvertCoordinates(posX, posY);
102 }
103 
ConvertGesture(uint32_t type,PointerPos coordinates)104 PointerPos FullScreenMagnificationManager::ConvertGesture(uint32_t type, PointerPos coordinates)
105 {
106     if (windowProxy_ == nullptr) {
107         HILOG_ERROR("windowProxy_ is nullptr.");
108         return coordinates;
109     }
110     return windowProxy_->ConvertGesture(type, coordinates);
111 }
112 
CheckTapOnHotArea(int32_t posX,int32_t posY)113 uint32_t FullScreenMagnificationManager::CheckTapOnHotArea(int32_t posX, int32_t posY)
114 {
115     if (windowProxy_ == nullptr) {
116         HILOG_ERROR("windowProxy_ is nullptr.");
117         return INVALID_GESTURE_TYPE;
118     }
119     return windowProxy_->CheckTapOnHotArea(posX, posY);
120 }
121 
GetSourceCenter()122 PointerPos FullScreenMagnificationManager::GetSourceCenter()
123 {
124     PointerPos pos = {0, 0};
125     if (windowProxy_ == nullptr) {
126         HILOG_ERROR("windowProxy_ is nullptr.");
127         return pos;
128     }
129     return windowProxy_->GetSourceCenter();
130 }
131 
FollowFocuseElement(int32_t centerX,int32_t centerY)132 void FullScreenMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY)
133 {
134     HILOG_DEBUG();
135     CHECK_PROXY_PTR_VOID()
136     windowProxy_->FollowFocuseElement(FULL_SCREEN_MAGNIFICATION, centerX, centerY);
137 }
138 
IsMagnificationWindowShow()139 bool FullScreenMagnificationManager::IsMagnificationWindowShow()
140 {
141     if (windowProxy_ == nullptr) {
142         HILOG_ERROR("windowProxy_ is nullptr.");
143         return false;
144     }
145     return windowProxy_->IsMagnificationWindowShow(FULL_SCREEN_MAGNIFICATION);
146 }
147 
GetScale()148 float FullScreenMagnificationManager::GetScale()
149 {
150     if (windowProxy_ == nullptr) {
151         HILOG_ERROR("windowProxy_ is nullptr.");
152         return DEFAULT_SCALE;
153     }
154     return windowProxy_->GetScale();
155 }
156 } // namespace Accessibility
157 } // namespace OHOS
158 // LCOV_EXCL_STOP