1 /*
2 * Copyright (C) 2022 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 #include "display_resize_controller.h"
17
18 using namespace std;
19
20 namespace OHOS {
21 namespace Accessibility {
DisplayResizeController(uint32_t channelId,uint32_t displayId)22 DisplayResizeController::DisplayResizeController(uint32_t channelId, uint32_t displayId)
23 {
24 HILOG_DEBUG("start.");
25 channelId_ = channelId;
26 displayId_ = displayId;
27 }
28
AddListener(std::shared_ptr<DisplayResizeListener> & listener)29 void DisplayResizeController::AddListener(std::shared_ptr<DisplayResizeListener>& listener)
30 {
31 HILOG_DEBUG("start.");
32
33 if (!listener) {
34 return;
35 }
36
37 for (auto it = displayResizeListeners_.begin(); it != displayResizeListeners_.end(); ++it) {
38 if (*it == listener) {
39 return;
40 }
41 }
42 displayResizeListeners_.push_back(listener);
43
44 return;
45 }
46
DeleteListener(std::shared_ptr<DisplayResizeListener> & listener)47 bool DisplayResizeController::DeleteListener(std::shared_ptr<DisplayResizeListener>& listener)
48 {
49 HILOG_DEBUG("start.");
50
51 for (auto it = displayResizeListeners_.begin(); it != displayResizeListeners_.end(); ++it) {
52 if (*it == listener) {
53 displayResizeListeners_.erase(it);
54 return true;
55 }
56 }
57
58 return false;
59 }
60
GetCenterX()61 float DisplayResizeController::GetCenterX()
62 {
63 HILOG_DEBUG("start.");
64 return AccessibilityOperator::GetInstance().GetDisplayResizeCenterX(channelId_, displayId_);
65 }
66
GetCenterY()67 float DisplayResizeController::GetCenterY()
68 {
69 HILOG_DEBUG("start.");
70 return AccessibilityOperator::GetInstance().GetDisplayResizeCenterY(channelId_, displayId_);
71 }
72
GetDisplayResizeRect()73 Rect DisplayResizeController::GetDisplayResizeRect()
74 {
75 HILOG_DEBUG("start.");
76 return AccessibilityOperator::GetInstance().GetDisplayResizeRect(channelId_, displayId_);
77 }
78
GetScale()79 float DisplayResizeController::GetScale()
80 {
81 HILOG_DEBUG("start.");
82 return AccessibilityOperator::GetInstance().GetDisplayResizeScale(channelId_, displayId_);
83 }
84
Reset(bool isShouldAnimate)85 bool DisplayResizeController::Reset(bool isShouldAnimate)
86 {
87 HILOG_DEBUG("start.");
88 return AccessibilityOperator::GetInstance().ResetDisplayResize(channelId_, displayId_, isShouldAnimate);
89 }
90
SetCenter(float centerX,float centerY,bool isShouldAnimate)91 bool DisplayResizeController::SetCenter(float centerX, float centerY, bool isShouldAnimate)
92 {
93 HILOG_DEBUG("start.");
94 return AccessibilityOperator::GetInstance().SetDisplayResizeScaleAndCenter(
95 channelId_, displayId_, 1.0, centerX, centerY, isShouldAnimate);
96 }
97
SetScale(float scale,bool isShouldAnimate)98 bool DisplayResizeController::SetScale(float scale, bool isShouldAnimate)
99 {
100 HILOG_DEBUG("start.");
101
102 float invalidValue = -1;
103 return AccessibilityOperator::GetInstance().SetDisplayResizeScaleAndCenter(
104 channelId_, displayId_, scale, invalidValue, invalidValue, isShouldAnimate);
105 }
106
DispatchOnDisplayResized(const Rect & rect,const float scale,const float centerX,const float centerY)107 void DisplayResizeController::DispatchOnDisplayResized(const Rect& rect,
108 const float scale, const float centerX, const float centerY)
109 {
110 HILOG_DEBUG("start.");
111 for (auto listener : displayResizeListeners_) {
112 listener->OnDisplayResized(*this, rect, scale, centerX, centerY);
113 }
114 }
115 } // namespace Accessibility
116 } // namespace OHOS