Home | History | Annotate | Download | only in style
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef GridTrackSize_h
     32 #define GridTrackSize_h
     33 
     34 #include "core/rendering/style/GridLength.h"
     35 
     36 namespace WebCore {
     37 
     38 enum GridTrackSizeType {
     39     LengthTrackSizing,
     40     MinMaxTrackSizing
     41 };
     42 
     43 class GridTrackSize {
     44 public:
     45     GridTrackSize(LengthType type = Undefined)
     46         : m_type(LengthTrackSizing)
     47         , m_minTrackBreadth(type)
     48         , m_maxTrackBreadth(type)
     49     {
     50     }
     51 
     52     const GridLength& length() const
     53     {
     54         ASSERT(m_type == LengthTrackSizing);
     55         ASSERT(m_minTrackBreadth == m_maxTrackBreadth);
     56         const GridLength& minTrackBreadth = m_minTrackBreadth;
     57         ASSERT(!minTrackBreadth.isLength() || !minTrackBreadth.length().isUndefined());
     58         return minTrackBreadth;
     59     }
     60 
     61     void setLength(const GridLength& length)
     62     {
     63         m_type = LengthTrackSizing;
     64         m_minTrackBreadth = length;
     65         m_maxTrackBreadth = length;
     66     }
     67 
     68     const GridLength& minTrackBreadth() const
     69     {
     70         ASSERT(!m_minTrackBreadth.isLength() || !m_minTrackBreadth.length().isUndefined());
     71         if (m_minTrackBreadth.isLength() && m_minTrackBreadth.length().isAuto()) {
     72             DEFINE_STATIC_LOCAL(GridLength, minContent, (MinContent));
     73             return minContent;
     74         }
     75         return m_minTrackBreadth;
     76     }
     77 
     78     const GridLength& maxTrackBreadth() const
     79     {
     80         ASSERT(!m_maxTrackBreadth.isLength() || !m_maxTrackBreadth.length().isUndefined());
     81         if (m_maxTrackBreadth.isLength() && m_maxTrackBreadth.length().isAuto()) {
     82             DEFINE_STATIC_LOCAL(GridLength, maxContent, (MaxContent));
     83             return maxContent;
     84         }
     85         return m_maxTrackBreadth;
     86     }
     87 
     88     void setMinMax(const GridLength& minTrackBreadth, const GridLength& maxTrackBreadth)
     89     {
     90         m_type = MinMaxTrackSizing;
     91         m_minTrackBreadth = minTrackBreadth;
     92         m_maxTrackBreadth = maxTrackBreadth;
     93     }
     94 
     95     GridTrackSizeType type() const { return m_type; }
     96 
     97     bool operator==(const GridTrackSize& other) const
     98     {
     99         return m_type == other.m_type && m_minTrackBreadth == other.m_minTrackBreadth && m_maxTrackBreadth == other.m_maxTrackBreadth;
    100     }
    101 
    102     bool hasMinOrMaxContentMinTrackBreadth() const { return minTrackBreadth().isLength() && (minTrackBreadth().length().isMinContent() || minTrackBreadth().length().isMaxContent()); }
    103     bool hasMaxContentMinTrackBreadth() const { return minTrackBreadth().isLength() && minTrackBreadth().length().isMaxContent(); }
    104     bool hasMinOrMaxContentMaxTrackBreadth() const { return maxTrackBreadth().isLength() && (maxTrackBreadth().length().isMinContent() || maxTrackBreadth().length().isMaxContent()); }
    105     bool hasMaxContentMaxTrackBreadth() const { return maxTrackBreadth().isLength() && maxTrackBreadth().length().isMaxContent(); }
    106 
    107 private:
    108     GridTrackSizeType m_type;
    109     GridLength m_minTrackBreadth;
    110     GridLength m_maxTrackBreadth;
    111 };
    112 
    113 } // namespace WebCore
    114 
    115 #endif // GridTrackSize_h
    116