• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 SECURITY_COMPONENT_INFO_H
17 #define SECURITY_COMPONENT_INFO_H
18 
19 #include <cstdint>
20 
21 namespace OHOS {
22 namespace Security {
23 namespace SecurityComponent {
24 static constexpr int32_t INVALID_SC_ID = -1;
25 using DimensionT = double; // unit is vp
26 static constexpr DimensionT DEFAULT_DIMENSION = 0.0;
27 static constexpr DimensionT MIN_FONT_SIZE = 12.0;
28 static constexpr DimensionT MIN_ICON_SIZE = 12.0;
29 static constexpr DimensionT MIN_PADDING_SIZE = 0.0;
30 static constexpr DimensionT MIN_PADDING_WITHOUT_BG = 4.0;
31 static constexpr uint32_t MAX_EXTRA_SIZE = 0x1000;
32 
33 static constexpr int32_t KEY_SPACE = 2050;
34 static constexpr int32_t KEY_ENTER = 2054;
35 
36 struct PaddingSize {
37     DimensionT top = DEFAULT_DIMENSION;
38     DimensionT right = DEFAULT_DIMENSION;
39     DimensionT bottom = DEFAULT_DIMENSION;
40     DimensionT left = DEFAULT_DIMENSION;
41 };
42 
43 enum SecCompType {
44     UNKNOWN_SC_TYPE = 0,
45     LOCATION_COMPONENT,
46     PASTE_COMPONENT,
47     SAVE_COMPONENT,
48     MAX_SC_TYPE
49 };
50 
51 union SecCompColor {
52     struct {
53         uint8_t blue;
54         uint8_t green;
55         uint8_t red;
56         uint8_t alpha;
57     } argb;
58     uint32_t value;
59 };
60 
IsComponentTypeValid(int32_t type)61 inline bool IsComponentTypeValid(int32_t type)
62 {
63     return (type > UNKNOWN_SC_TYPE && type < MAX_SC_TYPE);
64 }
65 
GreatOrEqual(double left,double right)66 inline bool GreatOrEqual(double left, double right)
67 {
68     constexpr double epsilon = -0.001;
69     return (left - right) > epsilon;
70 }
71 
GreatNotEqual(double left,double right)72 inline bool GreatNotEqual(double left, double right)
73 {
74     constexpr double epsilon = 0.001;
75     return (left - right) > epsilon;
76 }
77 
IsEqual(double left,double right)78 inline bool IsEqual(double left, double right)
79 {
80     constexpr double epsilon = 0.001;
81     if (left > right) {
82         return (left - right) < epsilon;
83     } else if (right > left) {
84         return (right - left) < epsilon;
85     } else {
86         return true;
87     }
88 }
89 
90 class SecCompRect {
91 public:
92     SecCompRect() = default;
93     ~SecCompRect() = default;
94 
IsInRect(double x,double y)95     bool IsInRect(double x, double y) const
96     {
97         return (GreatOrEqual(x, x_) && GreatOrEqual((x_ + width_), x) &&
98             GreatOrEqual(y, y_) && GreatOrEqual((y_ + height_), y));
99     };
100 
101     bool operator==(const SecCompRect& other) const
102     {
103         return (IsEqual(x_, other.x_)) && (IsEqual(y_, other.y_)) &&
104             (IsEqual(width_, other.width_)) && (IsEqual(height_, other.height_));
105     }
106 
107     DimensionT x_ = 0.0;
108     DimensionT y_ = 0.0;
109     DimensionT width_ = 0.0;
110     DimensionT height_ = 0.0;
111 };
112 
113 struct ExtraInfo {
114     uint32_t dataSize;
115     uint8_t* data;
116 };
117 
118 enum class ClickEventType : int32_t {
119     UNKNOWN_EVENT_TYPE,
120     POINT_EVENT_TYPE,
121     KEY_EVENT_TYPE
122 };
123 
124 struct SecCompPointEvent {
125     double touchX;
126     double touchY;
127     uint64_t timestamp;
128 };
129 
130 struct SecCompKeyEvent {
131     uint64_t timestamp;
132     int32_t keyCode;
133 };
134 
135 struct SecCompClickEvent {
136     ClickEventType type;
137     union {
138         SecCompPointEvent point;
139         SecCompKeyEvent key;
140     };
141     ExtraInfo extraInfo;
142 };
143 }  // namespace SecurityComponent
144 }  // namespace Security
145 }  // namespace OHOS
146 #endif  // SECURITY_COMPONENT_INFO_H
147