• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "core/components/common/properties/border.h"
17 
18 #include "core/pipeline/pipeline_context.h"
19 
20 namespace OHOS::Ace {
21 
Border(const BorderEdge & left,const BorderEdge & top,const BorderEdge & right,const BorderEdge & bottom)22 Border::Border(const BorderEdge& left, const BorderEdge& top, const BorderEdge& right, const BorderEdge& bottom)
23     : left_(left), top_(top), right_(right), bottom_(bottom)
24 {}
25 
Border(const BorderImageEdge & leftImage,const BorderImageEdge & topImage,const BorderImageEdge & rightImage,const BorderImageEdge & bottomImage)26 Border::Border(const BorderImageEdge& leftImage, const BorderImageEdge& topImage,
27     const BorderImageEdge& rightImage, const BorderImageEdge& bottomImage)
28     : borderImageLeft_(leftImage), borderImageTop_(topImage),
29     borderImageRight_(rightImage), borderImageBottom_(bottomImage)
30 {}
31 
IsAllEqual() const32 bool Border::IsAllEqual() const
33 {
34     return (left_ == top_) && (top_ == right_) && (right_ == bottom_);
35 }
36 
HasValue() const37 bool Border::HasValue() const
38 {
39     return left_.HasValue() || top_.HasValue() || right_.HasValue() || bottom_.HasValue();
40 }
41 
HasRadius() const42 bool Border::HasRadius() const
43 {
44     return topLeftRadius_.HasValue() || topRightRadius_.HasValue() ||
45         bottomLeftRadius_.HasValue() || bottomRightRadius_.HasValue();
46 }
47 
GetOffset(double dipScale) const48 Offset Border::GetOffset(double dipScale) const
49 {
50     return Offset(left_.GetWidthInPx(dipScale), top_.GetWidthInPx(dipScale));
51 }
52 
HorizontalWidth(double dipScale) const53 double Border::HorizontalWidth(double dipScale) const
54 {
55     return left_.GetWidthInPx(dipScale) + right_.GetWidthInPx(dipScale);
56 }
57 
VerticalWidth(double dipScale) const58 double Border::VerticalWidth(double dipScale) const
59 {
60     return top_.GetWidthInPx(dipScale) + bottom_.GetWidthInPx(dipScale);
61 }
62 
GetLayoutSize(double dipScale) const63 Size Border::GetLayoutSize(double dipScale) const
64 {
65     return Size(HorizontalWidth(dipScale), VerticalWidth(dipScale));
66 }
67 
GetValidEdge() const68 BorderEdge Border::GetValidEdge() const
69 {
70     if (left_.HasValue()) {
71         return left_;
72     }
73     if (top_.HasValue()) {
74         return top_;
75     }
76     if (right_.HasValue()) {
77         return right_;
78     }
79     if (bottom_.HasValue()) {
80         return bottom_;
81     }
82     return BorderEdge();
83 }
84 
SetContextAndCallback(const WeakPtr<PipelineContext> & context,const RenderNodeAnimationCallback & callback)85 void Border::SetContextAndCallback(const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback)
86 {
87     left_.SetContextAndCallback(context, callback);
88     top_.SetContextAndCallback(context, callback);
89     right_.SetContextAndCallback(context, callback);
90     bottom_.SetContextAndCallback(context, callback);
91 
92     topLeftRadius_.SetContextAndCallback(context, callback);
93     topRightRadius_.SetContextAndCallback(context, callback);
94     bottomLeftRadius_.SetContextAndCallback(context, callback);
95     bottomRightRadius_.SetContextAndCallback(context, callback);
96 }
97 } // namespace OHOS::Ace
98