1/*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 *           (C) 2000 Antti Koivisto (koivisto@kde.org)
4 *           (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB.  If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#ifndef BorderData_h
26#define BorderData_h
27
28#include "BorderValue.h"
29#include "IntSize.h"
30#include "NinePieceImage.h"
31
32namespace WebCore {
33
34class BorderData {
35public:
36    BorderValue left;
37    BorderValue right;
38    BorderValue top;
39    BorderValue bottom;
40
41    NinePieceImage image;
42
43    IntSize topLeft;
44    IntSize topRight;
45    IntSize bottomLeft;
46    IntSize bottomRight;
47
48    bool hasBorder() const
49    {
50        bool haveImage = image.hasImage();
51        return left.nonZero(!haveImage) || right.nonZero(!haveImage) || top.nonZero(!haveImage) || bottom.nonZero(!haveImage);
52    }
53
54    bool hasBorderRadius() const
55    {
56        if (topLeft.width() > 0)
57            return true;
58        if (topRight.width() > 0)
59            return true;
60        if (bottomLeft.width() > 0)
61            return true;
62        if (bottomRight.width() > 0)
63            return true;
64        return false;
65    }
66
67    unsigned short borderLeftWidth() const
68    {
69        if (!image.hasImage() && (left.style() == BNONE || left.style() == BHIDDEN))
70            return 0;
71        return left.width;
72    }
73
74    unsigned short borderRightWidth() const
75    {
76        if (!image.hasImage() && (right.style() == BNONE || right.style() == BHIDDEN))
77            return 0;
78        return right.width;
79    }
80
81    unsigned short borderTopWidth() const
82    {
83        if (!image.hasImage() && (top.style() == BNONE || top.style() == BHIDDEN))
84            return 0;
85        return top.width;
86    }
87
88    unsigned short borderBottomWidth() const
89    {
90        if (!image.hasImage() && (bottom.style() == BNONE || bottom.style() == BHIDDEN))
91            return 0;
92        return bottom.width;
93    }
94
95    bool operator==(const BorderData& o) const
96    {
97        return left == o.left && right == o.right && top == o.top && bottom == o.bottom && image == o.image &&
98               topLeft == o.topLeft && topRight == o.topRight && bottomLeft == o.bottomLeft && bottomRight == o.bottomRight;
99    }
100
101    bool operator!=(const BorderData& o) const
102    {
103        return !(*this == o);
104    }
105};
106
107} // namespace WebCore
108
109#endif // BorderData_h
110