- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / LengthBox.h
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 "platform/Length.h"
26 #include "platform/PlatformExport.h"
27 #include "platform/text/TextDirection.h"
28 #include "platform/text/WritingMode.h"
29
30 namespace WebCore {
31
32 class RenderStyle;
33
34 class PLATFORM_EXPORT LengthBox {
35 public:
36     LengthBox()
37     {
38     }
39
40     LengthBox(LengthType t)
41         : m_left(t)
42         , m_right(t)
43         , m_top(t)
44         , m_bottom(t)
45     {
46     }
47
48     LengthBox(int v)
49         : m_left(Length(v, Fixed))
50         , m_right(Length(v, Fixed))
51         , m_top(Length(v, Fixed))
52         , m_bottom(Length(v, Fixed))
53     {
54     }
55
56     LengthBox(Length t, Length r, Length b, Length l)
57         : m_left(l)
58         , m_right(r)
59         , m_top(t)
60         , m_bottom(b)
61     {
62     }
63
64     LengthBox(int t, int r, int b, int l)
65         : m_left(Length(l, Fixed))
66         , m_right(Length(r, Fixed))
67         , m_top(Length(t, Fixed))
68         , m_bottom(Length(b, Fixed))
69     {
70     }
71
72     Length left() const { return m_left; }
73     Length right() const { return m_right; }
74     Length top() const { return m_top; }
75     Length bottom() const { return m_bottom; }
76
77     Length logicalLeft(WritingMode) const;
78     Length logicalRight(WritingMode) const;
79
80     Length before(WritingMode) const;
81     Length after(WritingMode) const;
82     Length start(WritingMode, TextDirection) const;
83     Length end(WritingMode, TextDirection) const;
84
85     bool operator==(const LengthBox& o) const
86     {
87         return m_left == o.m_left && m_right == o.m_right && m_top == o.m_top && m_bottom == o.m_bottom;
88     }
89
90     bool operator!=(const LengthBox& o) const
91     {
92         return !(*this == o);
93     }
94
95     bool nonZero() const
96     {
97         return !(m_left.isZero() && m_right.isZero() && m_top.isZero() && m_bottom.isZero());
98     }
99
100     // Must be public for SET_VAR in RenderStyle.h
101     Length m_left;
102     Length m_right;
103     Length m_top;
104     Length m_bottom;
105 };
106
107 } // namespace WebCore
108
109 #endif // LengthBox_h