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 { 28 DECLARE_ACE_TYPE(PageNodeInfoWrapOhos, PageNodeInfoWrap) 29 30 public: PageNodeInfoWrapOhos()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 37 void SetId(int32_t id) override 38 { 39 pageNodeInfo_.id = id; 40 } 41 42 int32_t GetId() const override 43 { 44 return pageNodeInfo_.id; 45 } 46 47 void SetDepth(int32_t depth) override 48 { 49 pageNodeInfo_.depth = depth; 50 } 51 52 int32_t GetDepth() const override 53 { 54 return pageNodeInfo_.depth; 55 } 56 57 void SetAutoFillType(AceAutoFillType autoFillType) override 58 { 59 pageNodeInfo_.autoFillType = static_cast<AbilityBase::AutoFillType>(autoFillType); 60 } 61 62 AceAutoFillType GetAutoFillType() const override 63 { 64 return static_cast<AceAutoFillType>(pageNodeInfo_.autoFillType); 65 } 66 67 void SetTag(const std::string& tag) override 68 { 69 pageNodeInfo_.tag = tag; 70 } 71 72 const std::string& GetTag() const override 73 { 74 return pageNodeInfo_.tag; 75 } 76 77 void SetValue(const std::string& value) override 78 { 79 pageNodeInfo_.value = value; 80 } 81 82 const std::string& GetValue() const override 83 { 84 return pageNodeInfo_.value; 85 } 86 87 void SetPlaceholder(const std::string& placeholder) override 88 { 89 pageNodeInfo_.placeholder = placeholder; 90 } 91 92 const std::string& GetPlaceholder() const override 93 { 94 return pageNodeInfo_.placeholder; 95 } 96 97 void SetMetadata(const std::string& metadata) override 98 { 99 pageNodeInfo_.metadata = metadata; 100 } 101 102 const std::string& GetMetadata() const override 103 { 104 return pageNodeInfo_.metadata; 105 } 106 107 void SetPasswordRules(const std::string& passwordRules) override 108 { 109 pageNodeInfo_.passwordRules = passwordRules; 110 } 111 112 const std::string& GetPasswordRules() const override 113 { 114 return pageNodeInfo_.passwordRules; 115 } 116 117 void SetEnableAutoFill(bool enableAutoFill) override 118 { 119 pageNodeInfo_.enableAutoFill = enableAutoFill; 120 } 121 122 bool GetEnableAutoFill() const override 123 { 124 return pageNodeInfo_.enableAutoFill; 125 } 126 127 void SetIsFocus(bool isFocus) override 128 { 129 pageNodeInfo_.isFocus = isFocus; 130 } 131 132 bool GetIsFocus() const override 133 { 134 return pageNodeInfo_.isFocus; 135 } 136 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 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 { 157 DECLARE_ACE_TYPE(ViewDataWrapOhos, ViewDataWrap) 158 159 public: ViewDataWrapOhos()160 ViewDataWrapOhos() {} 161 ViewDataWrapOhos(const AbilityBase::ViewData& viewData); 162 ~ViewDataWrapOhos() = default; 163 164 const AbilityBase::ViewData& GetViewData(); 165 166 void SetBundleName(const std::string& bundleName) override 167 { 168 viewData_.bundleName = bundleName; 169 } 170 171 const std::string& GetBundleName() const override 172 { 173 return viewData_.bundleName; 174 } 175 176 void SetModuleName(const std::string& moduleName) override 177 { 178 viewData_.moduleName = moduleName; 179 } 180 181 const std::string& GetModuleName() const override 182 { 183 return viewData_.moduleName; 184 } 185 186 void SetAbilityName(const std::string& abilityName) override 187 { 188 viewData_.abilityName = abilityName; 189 } 190 191 const std::string& GetAbilityName() const override 192 { 193 return viewData_.abilityName; 194 } 195 196 void SetPageUrl(const std::string& pageUrl) override 197 { 198 viewData_.pageUrl = pageUrl; 199 } 200 201 const std::string& GetPageUrl() const override 202 { 203 return viewData_.pageUrl; 204 } 205 206 void AddPageNodeInfoWrap(RefPtr<PageNodeInfoWrap> pageNodeInfoWrap) override 207 { 208 pageNodeInfoWraps_.emplace_back(pageNodeInfoWrap); 209 } 210 211 const std::vector<RefPtr<PageNodeInfoWrap>>& GetPageNodeInfoWraps() override 212 { 213 return pageNodeInfoWraps_; 214 } 215 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 225 const NG::RectF& GetPageRect() const override 226 { 227 return pageRect_; 228 } 229 230 void SetUserSelected(bool isUserSelected) override 231 { 232 viewData_.isUserSelected = isUserSelected; 233 } 234 235 bool GetUserSelected() const override 236 { 237 return viewData_.isUserSelected; 238 } 239 240 void SetOtherAccount(bool isOtherAccount) override 241 { 242 viewData_.isOtherAccount = isOtherAccount; 243 } 244 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