| 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 | #pragma once |
| 26 | |
| 27 | #include "BorderValue.h" |
| 28 | #include "LengthSize.h" |
| 29 | #include "NinePieceImage.h" |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | class BorderData { |
| 34 | friend class RenderStyle; |
| 35 | public: |
| 36 | BorderData() |
| 37 | : m_topLeft { { 0, Fixed }, { 0, Fixed } } |
| 38 | , m_topRight { { 0, Fixed }, { 0, Fixed } } |
| 39 | , m_bottomLeft { { 0, Fixed }, { 0, Fixed } } |
| 40 | , m_bottomRight { { 0, Fixed }, { 0, Fixed } } |
| 41 | { |
| 42 | } |
| 43 | bool hasBorder() const |
| 44 | { |
| 45 | bool haveImage = m_image.hasImage(); |
| 46 | return m_left.nonZero(!haveImage) || m_right.nonZero(!haveImage) || m_top.nonZero(!haveImage) || m_bottom.nonZero(!haveImage); |
| 47 | } |
| 48 | |
| 49 | bool hasVisibleBorder() const |
| 50 | { |
| 51 | bool haveImage = m_image.hasImage(); |
| 52 | return m_left.isVisible(!haveImage) || m_right.isVisible(!haveImage) || m_top.isVisible(!haveImage) || m_bottom.isVisible(!haveImage); |
| 53 | } |
| 54 | |
| 55 | bool hasFill() const |
| 56 | { |
| 57 | return m_image.hasImage() && m_image.fill(); |
| 58 | } |
| 59 | |
| 60 | bool hasBorderRadius() const |
| 61 | { |
| 62 | return !m_topLeft.width.isZero() |
| 63 | || !m_topRight.width.isZero() |
| 64 | || !m_bottomLeft.width.isZero() |
| 65 | || !m_bottomRight.width.isZero(); |
| 66 | } |
| 67 | |
| 68 | float borderLeftWidth() const |
| 69 | { |
| 70 | if (!m_image.hasImage() && (m_left.style() == BorderStyle::None || m_left.style() == BorderStyle::Hidden)) |
| 71 | return 0; |
| 72 | return m_left.width(); |
| 73 | } |
| 74 | |
| 75 | float borderRightWidth() const |
| 76 | { |
| 77 | if (!m_image.hasImage() && (m_right.style() == BorderStyle::None || m_right.style() == BorderStyle::Hidden)) |
| 78 | return 0; |
| 79 | return m_right.width(); |
| 80 | } |
| 81 | |
| 82 | float borderTopWidth() const |
| 83 | { |
| 84 | if (!m_image.hasImage() && (m_top.style() == BorderStyle::None || m_top.style() == BorderStyle::Hidden)) |
| 85 | return 0; |
| 86 | return m_top.width(); |
| 87 | } |
| 88 | |
| 89 | float borderBottomWidth() const |
| 90 | { |
| 91 | if (!m_image.hasImage() && (m_bottom.style() == BorderStyle::None || m_bottom.style() == BorderStyle::Hidden)) |
| 92 | return 0; |
| 93 | return m_bottom.width(); |
| 94 | } |
| 95 | |
| 96 | FloatBoxExtent borderWidth() const |
| 97 | { |
| 98 | return FloatBoxExtent(borderTopWidth(), borderRightWidth(), borderBottomWidth(), borderLeftWidth()); |
| 99 | } |
| 100 | |
| 101 | bool operator==(const BorderData& o) const |
| 102 | { |
| 103 | return m_left == o.m_left && m_right == o.m_right && m_top == o.m_top && m_bottom == o.m_bottom && m_image == o.m_image |
| 104 | && m_topLeft == o.m_topLeft && m_topRight == o.m_topRight && m_bottomLeft == o.m_bottomLeft && m_bottomRight == o.m_bottomRight; |
| 105 | } |
| 106 | |
| 107 | bool operator!=(const BorderData& o) const |
| 108 | { |
| 109 | return !(*this == o); |
| 110 | } |
| 111 | |
| 112 | const BorderValue& left() const { return m_left; } |
| 113 | const BorderValue& right() const { return m_right; } |
| 114 | const BorderValue& top() const { return m_top; } |
| 115 | const BorderValue& bottom() const { return m_bottom; } |
| 116 | |
| 117 | const NinePieceImage& image() const { return m_image; } |
| 118 | |
| 119 | const LengthSize& topLeft() const { return m_topLeft; } |
| 120 | const LengthSize& topRight() const { return m_topRight; } |
| 121 | const LengthSize& bottomLeft() const { return m_bottomLeft; } |
| 122 | const LengthSize& bottomRight() const { return m_bottomRight; } |
| 123 | |
| 124 | private: |
| 125 | BorderValue m_left; |
| 126 | BorderValue m_right; |
| 127 | BorderValue m_top; |
| 128 | BorderValue m_bottom; |
| 129 | |
| 130 | NinePieceImage m_image; |
| 131 | |
| 132 | LengthSize m_topLeft; |
| 133 | LengthSize m_topRight; |
| 134 | LengthSize m_bottomLeft; |
| 135 | LengthSize m_bottomRight; |
| 136 | }; |
| 137 | |
| 138 | } // namespace WebCore |
| 139 | |