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 "LayoutUnit.h"
29
30namespace WebCore {
31
32class CollapsedBorderValue {
33public:
34 CollapsedBorderValue()
35 : m_style(static_cast<unsigned>(BorderStyle::None))
36 , m_precedence(static_cast<unsigned>(BorderPrecedence::Off))
37 , m_transparent(false)
38 {
39 }
40
41 CollapsedBorderValue(const BorderValue& border, const Color& color, BorderPrecedence precedence)
42 : m_width(LayoutUnit(border.nonZero() ? border.width() : 0))
43 , m_color(color)
44 , m_style(static_cast<unsigned>(border.style()))
45 , m_precedence(static_cast<unsigned>(precedence))
46 , m_transparent(border.isTransparent())
47 {
48 }
49
50 LayoutUnit width() const { return style() > BorderStyle::Hidden ? m_width : 0_lu; }
51 BorderStyle style() const { return static_cast<BorderStyle>(m_style); }
52 bool exists() const { return precedence() != BorderPrecedence::Off; }
53 const Color& color() const { return m_color; }
54 bool isTransparent() const { return m_transparent; }
55 BorderPrecedence precedence() const { return static_cast<BorderPrecedence>(m_precedence); }
56
57 bool isSameIgnoringColor(const CollapsedBorderValue& o) const
58 {
59 return width() == o.width() && style() == o.style() && precedence() == o.precedence();
60 }
61
62 static LayoutUnit adjustedCollapsedBorderWidth(float borderWidth, float deviceScaleFactor, bool roundUp);
63
64private:
65 LayoutUnit m_width;
66 Color m_color;
67 unsigned m_style : 4; // BorderStyle
68 unsigned m_precedence : 3; // BorderPrecedence
69 unsigned m_transparent : 1;
70};
71
72inline LayoutUnit CollapsedBorderValue::adjustedCollapsedBorderWidth(float borderWidth, float deviceScaleFactor, bool roundUp)
73{
74 float halfCollapsedBorderWidth = (borderWidth + (roundUp ? (1 / deviceScaleFactor) : 0)) / 2;
75 return floorToDevicePixel(halfCollapsedBorderWidth, deviceScaleFactor);
76}
77
78} // namespace WebCore
79