• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DISPLAY_RESIZE_CONTROLLER_H
17 #define DISPLAY_RESIZE_CONTROLLER_H
18 
19 #include <cstdint>
20 #include <vector>
21 #include "accessible_ability_client_stub_impl.h"
22 #include "accessibility_element_info.h"
23 
24 namespace OHOS {
25 namespace Accessibility {
26 class DisplayResizeListener;
27 
28 class DisplayResizeController {
29 public:
30     /**
31      * @brief The constructor of DisplayResizeController.
32      * @param channelId The id of channel.
33      * @param displayId The id of display.
34      */
35     DisplayResizeController(uint32_t channelId, uint32_t displayId);
36 
37     /**
38      * @brief Adds a displayresize listener to observe display resizing operations.
39      * @param listener Indicates the listener to add.
40      * @return
41      */
42     void AddListener(std::shared_ptr<DisplayResizeListener>& listener);
43 
44     /**
45      * @brief Removes the specified displayresize listener.
46      * @param listener Indicates the listener to remove.
47      * @return Return true if removing listener successfully, else return false.
48      */
49     bool DeleteListener(std::shared_ptr<DisplayResizeListener>& listener);
50 
51     /**
52      * @brief Obtains the X coordinate of the center in this display resizing rectangle.
53      * @param
54      * @return Returns the X coordinate of the center.
55      */
56     float GetCenterX();
57 
58     /**
59      * @brief Obtains the Y coordinate of the center in this display resizing rectangle.
60      * @param
61      * @return Returns the Y coordinate of the center.
62      */
63     float GetCenterY();
64 
65     /**
66      * @brief Obtains the display resizing rectangle.
67      * @param
68      * @return Returns the display resizing rectangle.
69      */
70     Rect GetDisplayResizeRect();
71 
72     /**
73      * @brief Obtains the resizing scale of this display resizing rectangle.
74      * @param
75      * @return Returns the resizing scale.
76      */
77     float GetScale();
78 
79     /**
80      * @brief Resets the display to its initial size.
81      * @param isShouldAnimate Specifies whether animation is required.
82      * @return Returns true if the display is successfully reset; returns false otherwise.
83      */
84     bool Reset(bool isShouldAnimate);
85 
86     /**
87      * @brief Sets the center coordinates for the display resizing rectangle.
88      * @param centerX Indicates the X coordinate of the center for resizing the display.
89      * @param centerY Indicates the Y coordinate of the center for resizing the display.
90      * @param isShouldAnimate Specifies whether animation is required.
91      * @return Returns true if the center coordinates are successfully set; returns false otherwise.
92      */
93     bool SetCenter(float centerX, float centerY, bool isShouldAnimate);
94 
95     /**
96      * @brief Sets the display resizing scale.
97      * @param scale Indicates the scale for resizing the display
98      * @param isShouldAnimate Specifies whether animation is required.
99      * @return Returns true if the resizing scale is successfully set; returns false otherwise.
100      */
101     bool SetScale(float scale, bool isShouldAnimate);
102 
103     /**
104      * @brief Dispatch displayresize changes to listeners who has been registered.
105      * @param rect The rectangle of displayresize which needs to dispatch.
106      * @param scale The scale of displayresize which needs to dispatch.
107      * @param centerX The centerX of displayresize which needs to dispatch.
108      * @param centerY The centerY of displayresize which needs to dispatch.
109      * @return
110      */
111     void DispatchOnDisplayResized(const Rect& rect, const float scale, const float centerX, const float centerY);
112 
113 private:
114     std::vector<std::shared_ptr<DisplayResizeListener>> displayResizeListeners_ {};
115     uint32_t channelId_ = AccessibleAbilityClientStubImpl::INVALID_CHANNEL_ID;
116     uint32_t displayId_;
117 };
118 
119 class DisplayResizeListener {
120 public:
121     /**
122      * @brief Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed.
123      * @param controller Indicates the controller for display resizing operations.
124      * @param rect Indicates the rectangle for resizing the display.
125      * @param scale Indicates the scale for resizing the display.
126      * @param centerX Indicates the X coordinate of the center for resizing the display.
127      * @param centerY Indicates the Y coordinate of the center for resizing the display.
128      * @return
129      */
130     virtual void OnDisplayResized(const DisplayResizeController& controller, const Rect& rect, const float scale,
131                                             const float centerX, const float centerY) = 0;
132 };
133 } // namespace Accessibility
134 } // namespace OHOS
135 #endif // DISPLAY_RESIZE_CONTROLLER_H