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 "magnification_menu_manager.h"
18 #include "accessibility_def.h"
19 #include "accessibility_display_manager.h"
20 #include "accessible_ability_manager_service.h"
21
22 namespace OHOS {
23 namespace Accessibility {
24 namespace {
25 const std::string FULL_SCREEN_PATH = "/system/etc/accessibility/fullScreen.png";
26 const std::string WINDOW_PATH = "/system/etc/accessibility/window.png";
27 }
MagnificationMenuManager(std::shared_ptr<MagnificationWindowProxy> proxy)28 MagnificationMenuManager::MagnificationMenuManager(std::shared_ptr<MagnificationWindowProxy> proxy)
29 : windowProxy_(proxy)
30 {
31 }
32
ShowMenuWindow(uint32_t mode)33 void MagnificationMenuManager::ShowMenuWindow(uint32_t mode)
34 {
35 HILOG_INFO();
36 CHECK_PROXY_PTR_VOID()
37 if (windowProxy_->IsMenuShown()) {
38 HILOG_INFO("no need show menu.");
39 return;
40 }
41 uint32_t currentType = Singleton<AccessibleAbilityManagerService>::GetInstance().GetMagnificationType();
42 if (currentType != SWITCH_MAGNIFICATION) {
43 HILOG_INFO("no need show menu.");
44 return;
45 }
46 windowProxy_->SetCurrentType(currentType);
47 windowProxy_->ShowMenuWindow(mode);
48 }
49
DisableMenuWindow()50 void MagnificationMenuManager::DisableMenuWindow()
51 {
52 HILOG_INFO();
53 CHECK_PROXY_PTR_VOID()
54 std::lock_guard<ffrt::mutex> lock(mutex_);
55 windowProxy_->DisableMenuWindow();
56 }
57
MoveMenuWindow(int32_t deltaX,int32_t deltaY)58 void MagnificationMenuManager::MoveMenuWindow(int32_t deltaX, int32_t deltaY)
59 {
60 HILOG_DEBUG();
61 CHECK_PROXY_PTR_VOID()
62 windowProxy_->MoveMenuWindow(deltaX, deltaY);
63 }
64
AttachToEdge()65 void MagnificationMenuManager::AttachToEdge()
66 {
67 HILOG_DEBUG();
68 CHECK_PROXY_PTR_VOID()
69 windowProxy_->AttachToEdge();
70 }
71
SetCurrentType(uint32_t type)72 void MagnificationMenuManager::SetCurrentType(uint32_t type)
73 {
74 HILOG_DEBUG();
75 CHECK_PROXY_PTR_VOID()
76 windowProxy_->SetCurrentType(type);
77 }
78
IsTapOnMenu(int32_t posX,int32_t posY)79 bool MagnificationMenuManager::IsTapOnMenu(int32_t posX, int32_t posY)
80 {
81 HILOG_DEBUG();
82 if (windowProxy_ == nullptr) {
83 HILOG_ERROR("windowProxy_ is nullptr.");
84 return false;
85 }
86 return windowProxy_->IsTapOnMenu(posX, posY);
87 }
88
OnMenuTap()89 void MagnificationMenuManager::OnMenuTap()
90 {
91 HILOG_DEBUG();
92 CHECK_PROXY_PTR_VOID()
93 windowProxy_->DisableMenuWindow();
94 uint32_t mode = windowProxy_->ChangeMode();
95 Singleton<AccessibleAbilityManagerService>::GetInstance().OnModeChanged(mode);
96 ShowMenuWindow(mode);
97 }
98
RefreshWindowParam()99 void MagnificationMenuManager::RefreshWindowParam()
100 {
101 HILOG_DEBUG();
102 CHECK_PROXY_PTR_VOID()
103 windowProxy_->RefreshWindowParamMenu();
104 }
105 } // namespace Accessibility
106 } // namespace OHOS
107 // LCOV_EXCL_STOP