1 /* 2 * Copyright (c) 2022 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_FRAMEWORKS_CORE_COMPONENTS_CORE_PROPERTIES_BORDER_IMAGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CORE_PROPERTIES_BORDER_IMAGE_H 18 19 #include <cstdint> 20 21 #include "base/geometry/dimension.h" 22 #include "base/geometry/offset.h" 23 #include "base/geometry/size.h" 24 #include "base/utils/utils.h" 25 #include "core/components/common/layout/constants.h" 26 #include "core/components/common/properties/border_image_edge.h" 27 #include "core/components/common/properties/color.h" 28 #include "core/components/common/properties/radius.h" 29 30 namespace OHOS::Ace { 31 32 class ACE_EXPORT BorderImage final : public AceType { 33 DECLARE_ACE_TYPE(BorderImage, AceType); 34 35 public: 36 const static uint8_t OUTSET_BIT = 1 << 0; 37 const static uint8_t REPEAT_BIT = 1 << 1; 38 const static uint8_t SLICE_BIT = 1 << 2; 39 const static uint8_t SOURCE_BIT = 1 << 3; 40 const static uint8_t WIDTH_BIT = 1 << 4; 41 const static uint8_t GRADIENT_BIT = 1 << 5; 42 43 BorderImage() = default; BorderImage(const std::string & src)44 explicit BorderImage(const std::string& src) 45 { 46 src_ = src; 47 } 48 49 ~BorderImage() override = default; 50 GetSrc()51 const std::string& GetSrc() const 52 { 53 return src_; 54 } 55 SetSrc(const std::string & src)56 void SetSrc(const std::string& src) 57 { 58 src_ = src; 59 } 60 61 struct BorderImageOption { 62 std::optional<Dimension> leftDimension; 63 std::optional<Dimension> rightDimension; 64 std::optional<Dimension> topDimension; 65 std::optional<Dimension> bottomDimension; 66 }; 67 68 void SetEdgeSlice(BorderImageDirection direction, const Dimension& sliceDimension); 69 70 void SetEdgeOutset(BorderImageDirection direction, const Dimension& outsetDimension); 71 72 void SetEdgeWidth(BorderImageDirection direction, const Dimension& widthDimension); 73 SetRepeatMode(BorderImageRepeat repeatMode)74 void SetRepeatMode(BorderImageRepeat repeatMode) 75 { 76 repeatMode_ = repeatMode; 77 } 78 GetRepeatMode()79 BorderImageRepeat GetRepeatMode() 80 { 81 return repeatMode_; 82 } 83 SetNeedFillCenter(bool needFillCenter)84 void SetNeedFillCenter(bool needFillCenter) 85 { 86 needFillCenter_ = needFillCenter; 87 } 88 GetNeedFillCenter()89 bool GetNeedFillCenter() const 90 { 91 return needFillCenter_; 92 } 93 94 BorderImageEdge& GetBorderImageEdge(BorderImageDirection direction); 95 HasBorderImageWidth()96 bool HasBorderImageWidth() const 97 { 98 return hasBorderImageWidth_; 99 } 100 101 private: 102 std::string src_; 103 BorderImageEdge borderImageLeft_; 104 BorderImageEdge borderImageTop_; 105 BorderImageEdge borderImageRight_; 106 BorderImageEdge borderImageBottom_; 107 BorderImageRepeat repeatMode_ = BorderImageRepeat::STRETCH; 108 bool needFillCenter_ = false; 109 bool hasBorderImageWidth_ = false; 110 }; 111 112 } // namespace OHOS::Ace 113 114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CORE_PROPERTIES_BORDER_IMAGE_H 115