Home | History | Annotate | Download | only in platform
      1 /*
      2     Copyright (C) 1999 Lars Knoll (knoll (at) 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 blink {
     31 
     32 class PLATFORM_EXPORT LengthBox {
     33 public:
     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(const Length& t, const Length& r, const Length& b, const 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     const Length& left() const { return m_left; }
     71     const Length& right() const { return m_right; }
     72     const Length& top() const { return m_top; }
     73     const Length& bottom() const { return m_bottom; }
     74 
     75     const Length& logicalLeft(WritingMode) const;
     76     const Length& logicalRight(WritingMode) const;
     77 
     78     const Length& before(WritingMode) const;
     79     const Length& after(WritingMode) const;
     80     const Length& start(WritingMode, TextDirection) const;
     81     const 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     // Must be public for SET_VAR in RenderStyle.h
     99     Length m_left;
    100     Length m_right;
    101     Length m_top;
    102     Length m_bottom;
    103 };
    104 
    105 } // namespace blink
    106 
    107 #endif // LengthBox_h
    108