1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/rendering/style/BorderEdge.h"
10 BorderEdge::BorderEdge(int edgeWidth, const Color& edgeColor, EBorderStyle edgeStyle, bool edgeIsTransparent, bool edgeIsPresent)
13 , isTransparent(edgeIsTransparent)
14 , isPresent(edgeIsPresent)
17 if (style == DOUBLE && edgeWidth < 3)
21 BorderEdge::BorderEdge()
23 , isTransparent(false)
29 bool BorderEdge::hasVisibleColorAndStyle() const
31 return style > BHIDDEN && !isTransparent;
34 bool BorderEdge::shouldRender() const { return isPresent && width && hasVisibleColorAndStyle(); }
35 bool BorderEdge::presentButInvisible() const { return usedWidth() && !hasVisibleColorAndStyle(); }
36 bool BorderEdge::obscuresBackgroundEdge(float scale) const
38 if (!isPresent || isTransparent || (width * scale) < 2 || color.hasAlpha() || style == BHIDDEN)
41 if (style == DOTTED || style == DASHED)
45 return width >= 5 * scale; // The outer band needs to be >= 2px wide at unit scale.
49 bool BorderEdge::obscuresBackground() const
51 if (!isPresent || isTransparent || color.hasAlpha() || style == BHIDDEN)
54 if (style == DOTTED || style == DASHED || style == DOUBLE)
60 int BorderEdge::usedWidth() const
62 return isPresent ? width : 0;
65 void BorderEdge::getDoubleBorderStripeWidths(int& outerWidth, int& innerWidth) const
67 int fullWidth = usedWidth();
68 outerWidth = fullWidth / 3;
69 innerWidth = fullWidth * 2 / 3;
71 // We need certain integer rounding results
72 if (fullWidth % 3 == 2)
75 if (fullWidth % 3 == 1)
79 bool BorderEdge::sharesColorWith(const BorderEdge& other) const
81 return color == other.color;