1 /*
2  * Copyright (c) 2023-2024 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 FOUNDATION_ACE_ADAPTER_OHOS_OSAL_VIEW_DATA_WRAP_OHOS_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_VIEW_DATA_WRAP_OHOS_H
18 
19 #include "base/view_data/view_data_wrap.h"
20 
21 #include <string>
22 #include <vector>
23 
24 #include "view_data.h"
25 
26 namespace OHOS::Ace {
27 class PageNodeInfoWrapOhos : public PageNodeInfoWrap {
DECLARE_ACE_TYPE(PageNodeInfoWrapOhos,PageNodeInfoWrap)28     DECLARE_ACE_TYPE(PageNodeInfoWrapOhos, PageNodeInfoWrap)
29 
30 public:
31     PageNodeInfoWrapOhos() {}
PageNodeInfoWrapOhos(const AbilityBase::PageNodeInfo & pageNodeInfo)32     PageNodeInfoWrapOhos(const AbilityBase::PageNodeInfo& pageNodeInfo): pageNodeInfo_(pageNodeInfo) {}
33     ~PageNodeInfoWrapOhos() = default;
34 
35     const AbilityBase::PageNodeInfo& GetPageNodeInfo() const;
36 
SetId(int32_t id)37     void SetId(int32_t id) override
38     {
39         pageNodeInfo_.id = id;
40     }
41 
GetId()42     int32_t GetId() const override
43     {
44         return pageNodeInfo_.id;
45     }
46 
SetDepth(int32_t depth)47     void SetDepth(int32_t depth) override
48     {
49         pageNodeInfo_.depth = depth;
50     }
51 
GetDepth()52     int32_t GetDepth() const override
53     {
54         return pageNodeInfo_.depth;
55     }
56 
SetAutoFillType(AceAutoFillType autoFillType)57     void SetAutoFillType(AceAutoFillType autoFillType) override
58     {
59         pageNodeInfo_.autoFillType = static_cast<AbilityBase::AutoFillType>(autoFillType);
60     }
61 
GetAutoFillType()62     AceAutoFillType GetAutoFillType() const override
63     {
64         return static_cast<AceAutoFillType>(pageNodeInfo_.autoFillType);
65     }
66 
SetTag(const std::string & tag)67     void SetTag(const std::string& tag) override
68     {
69         pageNodeInfo_.tag = tag;
70     }
71 
GetTag()72     const std::string& GetTag() const override
73     {
74         return pageNodeInfo_.tag;
75     }
76 
SetValue(const std::string & value)77     void SetValue(const std::string& value) override
78     {
79         pageNodeInfo_.value = value;
80     }
81 
GetValue()82     const std::string& GetValue() const override
83     {
84         return pageNodeInfo_.value;
85     }
86 
SetPlaceholder(const std::string & placeholder)87     void SetPlaceholder(const std::string& placeholder) override
88     {
89         pageNodeInfo_.placeholder = placeholder;
90     }
91 
GetPlaceholder()92     const std::string& GetPlaceholder() const override
93     {
94         return pageNodeInfo_.placeholder;
95     }
96 
SetMetadata(const std::string & metadata)97     void SetMetadata(const std::string& metadata) override
98     {
99         pageNodeInfo_.metadata = metadata;
100     }
101 
GetMetadata()102     const std::string& GetMetadata() const override
103     {
104         return pageNodeInfo_.metadata;
105     }
106 
SetPasswordRules(const std::string & passwordRules)107     void SetPasswordRules(const std::string& passwordRules) override
108     {
109         pageNodeInfo_.passwordRules = passwordRules;
110     }
111 
GetPasswordRules()112     const std::string& GetPasswordRules() const override
113     {
114         return pageNodeInfo_.passwordRules;
115     }
116 
SetEnableAutoFill(bool enableAutoFill)117     void SetEnableAutoFill(bool enableAutoFill) override
118     {
119         pageNodeInfo_.enableAutoFill = enableAutoFill;
120     }
121 
GetEnableAutoFill()122     bool GetEnableAutoFill() const override
123     {
124         return pageNodeInfo_.enableAutoFill;
125     }
126 
SetIsFocus(bool isFocus)127     void SetIsFocus(bool isFocus) override
128     {
129         pageNodeInfo_.isFocus = isFocus;
130     }
131 
GetIsFocus()132     bool GetIsFocus() const override
133     {
134         return pageNodeInfo_.isFocus;
135     }
136 
SetPageNodeRect(const NG::RectF & rect)137     void SetPageNodeRect(const NG::RectF& rect) override
138     {
139         pageNodeInfo_.rect.left = rect.GetX();
140         pageNodeInfo_.rect.top = rect.GetY();
141         pageNodeInfo_.rect.width = rect.Width();
142         pageNodeInfo_.rect.height = rect.Height();
143         pageNodeRect_ = rect;
144     }
145 
GetPageNodeRect()146     const NG::RectF& GetPageNodeRect() const override
147     {
148         return pageNodeRect_;
149     }
150 
151 private:
152     AbilityBase::PageNodeInfo pageNodeInfo_;
153     NG::RectF pageNodeRect_;
154 };
155 
156 class ViewDataWrapOhos : public ViewDataWrap {
DECLARE_ACE_TYPE(ViewDataWrapOhos,ViewDataWrap)157     DECLARE_ACE_TYPE(ViewDataWrapOhos, ViewDataWrap)
158 
159 public:
160     ViewDataWrapOhos() {}
161     ViewDataWrapOhos(const AbilityBase::ViewData& viewData);
162     ~ViewDataWrapOhos() = default;
163 
164     const AbilityBase::ViewData& GetViewData();
165 
SetBundleName(const std::string & bundleName)166     void SetBundleName(const std::string& bundleName) override
167     {
168         viewData_.bundleName = bundleName;
169     }
170 
GetBundleName()171     const std::string& GetBundleName() const override
172     {
173         return viewData_.bundleName;
174     }
175 
SetModuleName(const std::string & moduleName)176     void SetModuleName(const std::string& moduleName) override
177     {
178         viewData_.moduleName = moduleName;
179     }
180 
GetModuleName()181     const std::string& GetModuleName() const override
182     {
183         return viewData_.moduleName;
184     }
185 
SetAbilityName(const std::string & abilityName)186     void SetAbilityName(const std::string& abilityName) override
187     {
188         viewData_.abilityName = abilityName;
189     }
190 
GetAbilityName()191     const std::string& GetAbilityName() const override
192     {
193         return viewData_.abilityName;
194     }
195 
SetPageUrl(const std::string & pageUrl)196     void SetPageUrl(const std::string& pageUrl) override
197     {
198         viewData_.pageUrl = pageUrl;
199     }
200 
GetPageUrl()201     const std::string& GetPageUrl() const override
202     {
203         return viewData_.pageUrl;
204     }
205 
AddPageNodeInfoWrap(RefPtr<PageNodeInfoWrap> pageNodeInfoWrap)206     void AddPageNodeInfoWrap(RefPtr<PageNodeInfoWrap> pageNodeInfoWrap) override
207     {
208         pageNodeInfoWraps_.emplace_back(pageNodeInfoWrap);
209     }
210 
GetPageNodeInfoWraps()211     const std::vector<RefPtr<PageNodeInfoWrap>>& GetPageNodeInfoWraps() override
212     {
213         return pageNodeInfoWraps_;
214     }
215 
SetPageRect(const NG::RectF & rect)216     void SetPageRect(const NG::RectF& rect) override
217     {
218         viewData_.pageRect.left = rect.GetX();
219         viewData_.pageRect.top = rect.GetY();
220         viewData_.pageRect.width = rect.Width();
221         viewData_.pageRect.height = rect.Height();
222         pageRect_ = rect;
223     }
224 
GetPageRect()225     const NG::RectF& GetPageRect() const override
226     {
227         return pageRect_;
228     }
229 
SetUserSelected(bool isUserSelected)230     void SetUserSelected(bool isUserSelected) override
231     {
232         viewData_.isUserSelected = isUserSelected;
233     }
234 
GetUserSelected()235     bool GetUserSelected() const override
236     {
237         return viewData_.isUserSelected;
238     }
239 
SetOtherAccount(bool isOtherAccount)240     void SetOtherAccount(bool isOtherAccount) override
241     {
242         viewData_.isOtherAccount = isOtherAccount;
243     }
244 
GetOtherAccount()245     bool GetOtherAccount() const override
246     {
247         return viewData_.isOtherAccount;
248     }
249 
250 private:
251     std::vector<RefPtr<PageNodeInfoWrap>> pageNodeInfoWraps_;
252     AbilityBase::ViewData viewData_;
253     NG::RectF pageRect_;
254 };
255 } // namespace OHOS::Ace
256 #endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_VIEW_DATA_WRAP_OHOS_H
257