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 OHOS_OCCUPIED_AREA_CHANGE_INFO_H
17 #define OHOS_OCCUPIED_AREA_CHANGE_INFO_H
18 
19 #include <cstdint>
20 #include <parcel.h>
21 
22 #include "wm_common.h"
23 
24 namespace OHOS::Rosen {
25 class OccupiedAreaChangeInfo : public Parcelable {
26 public:
27 
28     OccupiedAreaChangeInfo() = default;
OccupiedAreaChangeInfo(OccupiedAreaType type,Rect rect)29     OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect) : type_(type), rect_(rect) {};
OccupiedAreaChangeInfo(OccupiedAreaType type,Rect rect,uint32_t safeHeight)30     OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect, uint32_t safeHeight)
31         : type_(type), rect_(rect), safeHeight_(safeHeight) {};
OccupiedAreaChangeInfo(OccupiedAreaType type,Rect rect,double textFieldPositionY,double textFieldHeight)32     OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect,
33                             double textFieldPositionY, double textFieldHeight)
34         : type_(type), rect_(rect), textFieldPositionY_(textFieldPositionY), textFieldHeight_(textFieldHeight) {};
OccupiedAreaChangeInfo(OccupiedAreaType type,Rect rect,uint32_t safeHeight,double textFieldPositionY,double textFieldHeight)35     OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect, uint32_t safeHeight,
36                            double textFieldPositionY, double textFieldHeight)
37         : type_(type), rect_(rect), safeHeight_(safeHeight),
38           textFieldPositionY_(textFieldPositionY), textFieldHeight_(textFieldHeight) {};
39     ~OccupiedAreaChangeInfo() = default;
40 
Marshalling(Parcel & parcel)41     virtual bool Marshalling(Parcel& parcel) const
42     {
43         return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) &&
44             parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) &&
45             parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
46             parcel.WriteUint32(safeHeight_) &&
47             parcel.WriteDouble(textFieldPositionY_) && parcel.WriteDouble(textFieldHeight_);
48     }
49 
Unmarshalling(Parcel & parcel)50     static OccupiedAreaChangeInfo* Unmarshalling(Parcel& parcel)
51     {
52         OccupiedAreaChangeInfo* occupiedAreaChangeInfo = new OccupiedAreaChangeInfo();
53         bool res = parcel.ReadInt32(occupiedAreaChangeInfo->rect_.posX_) &&
54             parcel.ReadInt32(occupiedAreaChangeInfo->rect_.posY_) &&
55             parcel.ReadUint32(occupiedAreaChangeInfo->rect_.width_) &&
56             parcel.ReadUint32(occupiedAreaChangeInfo->rect_.height_);
57         if (!res) {
58             delete occupiedAreaChangeInfo;
59             return nullptr;
60         }
61         occupiedAreaChangeInfo->type_ = static_cast<OccupiedAreaType>(parcel.ReadUint32());
62         occupiedAreaChangeInfo->safeHeight_ = parcel.ReadUint32();
63         occupiedAreaChangeInfo->textFieldPositionY_ = parcel.ReadDouble();
64         occupiedAreaChangeInfo->textFieldHeight_ = parcel.ReadDouble();
65         return occupiedAreaChangeInfo;
66     }
67 
68     OccupiedAreaType type_ = OccupiedAreaType::TYPE_INPUT;
69     Rect rect_ = { 0, 0, 0, 0 };
70     uint32_t safeHeight_ = 0;
71     double textFieldPositionY_ = 0.0;
72     double textFieldHeight_ = 0.0;
73 };
74 } // namespace OHOS::Rosen
75 #endif // OHOS_OCCUPIED_AREA_CHANGE_INFO_H