• 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 FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_WINDOW_INFO_H
17 #define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_WINDOW_INFO_H
18 
19 #include <cstdint>
20 #include <string>
21 #include "parcel.h"
22 
23 #include "panel_info.h"
24 namespace OHOS {
25 namespace MiscServices {
26 enum class InputWindowStatus : uint32_t {
27     SHOW,
28     HIDE,
29     NONE
30 };
31 
32 struct InputWindowInfo : public Parcelable {
33     std::string name;      // the name of inputWindow
34     int32_t left { 0 };    // the abscissa of the upper-left vertex of inputWindow
35     int32_t top { 0 };     // the ordinate of the upper-left vertex of inputWindow
36     uint32_t width { 0 };  // the width of inputWindow
37     uint32_t height { 0 }; // the height of inputWindow
38 
ReadFromParcelInputWindowInfo39     bool ReadFromParcel(Parcel &in)
40     {
41         name = in.ReadString();
42         left = in.ReadInt32();
43         top = in.ReadInt32();
44         width = in.ReadUint32();
45         height = in.ReadUint32();
46         return true;
47     }
48 
MarshallingInputWindowInfo49     bool Marshalling(Parcel &out) const
50     {
51         if (!out.WriteString(name)) {
52             return false;
53         }
54         if (!out.WriteInt32(left)) {
55             return false;
56         }
57         if (!out.WriteInt32(top)) {
58             return false;
59         }
60         if (!out.WriteUint32(width)) {
61             return false;
62         }
63         if (!out.WriteUint32(height)) {
64             return false;
65         }
66         return true;
67     }
68 
UnmarshallingInputWindowInfo69     static InputWindowInfo *Unmarshalling(Parcel &in)
70     {
71         InputWindowInfo *data = new (std::nothrow) InputWindowInfo();
72         if (data && !data->ReadFromParcel(in)) {
73             delete data;
74             data = nullptr;
75         }
76         return data;
77     }
78 };
79 
80 struct ImeWindowInfo : public Parcelable {
81     PanelInfo panelInfo;
82     InputWindowInfo windowInfo;
83 
ReadFromParcelImeWindowInfo84     bool ReadFromParcel(Parcel &in)
85     {
86         std::unique_ptr<PanelInfo> pInfo(in.ReadParcelable<PanelInfo>());
87         if (pInfo == nullptr) {
88             return false;
89         }
90         panelInfo = *pInfo;
91 
92         std::unique_ptr<InputWindowInfo> wInfo(in.ReadParcelable<InputWindowInfo>());
93         if (wInfo == nullptr) {
94             return false;
95         }
96         windowInfo = *wInfo;
97         return true;
98     }
99 
MarshallingImeWindowInfo100     bool Marshalling(Parcel &out) const
101     {
102         if (!out.WriteParcelable(&panelInfo)) {
103             return false;
104         }
105         if (!out.WriteParcelable(&windowInfo)) {
106             return false;
107         }
108         return true;
109     }
UnmarshallingImeWindowInfo110     static ImeWindowInfo *Unmarshalling(Parcel &in)
111     {
112         ImeWindowInfo *data = new (std::nothrow) ImeWindowInfo();
113         if (data && !data->ReadFromParcel(in)) {
114             delete data;
115             data = nullptr;
116         }
117     return data;
118     }
119 };
120 } // namespace MiscServices
121 } // namespace OHOS
122 
123 #endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_WINDOW_INFO_H
124