1/*
2    Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3    Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4    Copyright (c) 2012, Google Inc. All rights reserved.
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public License
17    along with this library; see the file COPYING.LIB.  If not, write to
18    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.
20*/
21
22#ifndef LengthBox_h
23#define LengthBox_h
24
25#include "Length.h"
26#include "TextDirection.h"
27#include "WritingMode.h"
28
29namespace WebCore {
30
31class RenderStyle;
32
33struct LengthBox {
34    LengthBox()
35    {
36    }
37
38    LengthBox(LengthType t)
39        : m_left(t)
40        , m_right(t)
41        , m_top(t)
42        , m_bottom(t)
43    {
44    }
45
46    LengthBox(int v)
47        : m_left(Length(v, Fixed))
48        , m_right(Length(v, Fixed))
49        , m_top(Length(v, Fixed))
50        , m_bottom(Length(v, Fixed))
51    {
52    }
53
54    LengthBox(Length t, Length r, Length b, Length l)
55        : m_left(l)
56        , m_right(r)
57        , m_top(t)
58        , m_bottom(b)
59    {
60    }
61
62    LengthBox(int t, int r, int b, int l)
63        : m_left(Length(l, Fixed))
64        , m_right(Length(r, Fixed))
65        , m_top(Length(t, Fixed))
66        , m_bottom(Length(b, Fixed))
67    {
68    }
69
70    Length left() const { return m_left; }
71    Length right() const { return m_right; }
72    Length top() const { return m_top; }
73    Length bottom() const { return m_bottom; }
74
75    Length logicalLeft(WritingMode) const;
76    Length logicalRight(WritingMode) const;
77
78    Length before(WritingMode) const;
79    Length after(WritingMode) const;
80    Length start(WritingMode, TextDirection) const;
81    Length end(WritingMode, TextDirection) const;
82
83    bool operator==(const LengthBox& o) const
84    {
85        return m_left == o.m_left && m_right == o.m_right && m_top == o.m_top && m_bottom == o.m_bottom;
86    }
87
88    bool operator!=(const LengthBox& o) const
89    {
90        return !(*this == o);
91    }
92
93    bool nonZero() const
94    {
95        return !(m_left.isZero() && m_right.isZero() && m_top.isZero() && m_bottom.isZero());
96    }
97
98    Length m_left;
99    Length m_right;
100    Length m_top;
101    Length m_bottom;
102};
103
104} // namespace WebCore
105
106#endif // LengthBox_h
107