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
31struct LengthBox {
32    LengthBox()
33    {
34    }
35
36    explicit LengthBox(LengthType type)
37        : m_left(type)
38        , m_right(type)
39        , m_top(type)
40        , m_bottom(type)
41    {
42    }
43
44    explicit LengthBox(int v)
45        : m_left(Length(v, Fixed))
46        , m_right(Length(v, Fixed))
47        , m_top(Length(v, Fixed))
48        , m_bottom(Length(v, Fixed))
49    {
50    }
51
52    LengthBox(Length top, Length right, Length bottom, Length left)
53        : m_left(WTF::move(left))
54        , m_right(WTF::move(right))
55        , m_top(WTF::move(top))
56        , m_bottom(WTF::move(bottom))
57    {
58    }
59
60    LengthBox(int top, int right, int bottom, int left)
61        : m_left(Length(left, Fixed))
62        , m_right(Length(right, Fixed))
63        , m_top(Length(top, Fixed))
64        , m_bottom(Length(bottom, Fixed))
65    {
66    }
67
68    const Length& left() const { return m_left; }
69    const Length& right() const { return m_right; }
70    const Length& top() const { return m_top; }
71    const Length& bottom() const { return m_bottom; }
72
73    const Length& logicalLeft(WritingMode) const;
74    const Length& logicalRight(WritingMode) const;
75
76    const Length& before(WritingMode) const;
77    const Length& after(WritingMode) const;
78    const Length& start(WritingMode, TextDirection) const;
79    const Length& end(WritingMode, TextDirection) const;
80
81    bool operator==(const LengthBox& other) const
82    {
83        return m_left == other.m_left && m_right == other.m_right && m_top == other.m_top && m_bottom == other.m_bottom;
84    }
85
86    bool operator!=(const LengthBox& other) const
87    {
88        return !(*this == other);
89    }
90
91    bool nonZero() const
92    {
93        return !(m_left.isZero() && m_right.isZero() && m_top.isZero() && m_bottom.isZero());
94    }
95
96    Length m_left;
97    Length m_right;
98    Length m_top;
99    Length m_bottom;
100};
101
102} // namespace WebCore
103
104#endif // LengthBox_h
105