• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
GridTrackSize()45     GridTrackSize()
46         : m_type(LengthTrackSizing)
47         , m_minTrackBreadth(Undefined)
48         , m_maxTrackBreadth(Undefined)
49         , m_minTrackBreadthIsMinOrMaxContent(false)
50         , m_minTrackBreadthIsMaxContent(false)
51         , m_maxTrackBreadthIsMinOrMaxContent(false)
52         , m_maxTrackBreadthIsMaxContent(false)
53     {
54         // Someone has to set a valid lenght type through setLength or
55         // setMinMax before using the object.
56     }
57 
GridTrackSize(LengthType type)58     GridTrackSize(LengthType type)
59         : m_type(LengthTrackSizing)
60         , m_minTrackBreadth(type)
61         , m_maxTrackBreadth(type)
62         , m_minTrackBreadthIsMinOrMaxContent(false)
63         , m_minTrackBreadthIsMaxContent(false)
64         , m_maxTrackBreadthIsMinOrMaxContent(false)
65         , m_maxTrackBreadthIsMaxContent(false)
66     {
67         ASSERT(type != Undefined);
68 
69         cacheMinMaxTrackBreadthTypes();
70     }
71 
length()72     const GridLength& length() const
73     {
74         ASSERT(m_type == LengthTrackSizing);
75         ASSERT(m_minTrackBreadth == m_maxTrackBreadth);
76         const GridLength& minTrackBreadth = m_minTrackBreadth;
77         ASSERT(!minTrackBreadth.isLength() || !minTrackBreadth.length().isUndefined());
78         return minTrackBreadth;
79     }
80 
setLength(const GridLength & length)81     void setLength(const GridLength& length)
82     {
83         m_type = LengthTrackSizing;
84         m_minTrackBreadth = length;
85         m_maxTrackBreadth = length;
86 
87         cacheMinMaxTrackBreadthTypes();
88     }
89 
minTrackBreadth()90     const GridLength& minTrackBreadth() const
91     {
92         ASSERT(!m_minTrackBreadth.isLength() || !m_minTrackBreadth.length().isUndefined());
93         if (m_minTrackBreadth.isLength() && m_minTrackBreadth.length().isAuto()) {
94             DEFINE_STATIC_LOCAL(GridLength, minContent, (MinContent));
95             return minContent;
96         }
97         return m_minTrackBreadth;
98     }
99 
maxTrackBreadth()100     const GridLength& maxTrackBreadth() const
101     {
102         ASSERT(!m_maxTrackBreadth.isLength() || !m_maxTrackBreadth.length().isUndefined());
103         if (m_maxTrackBreadth.isLength() && m_maxTrackBreadth.length().isAuto()) {
104             DEFINE_STATIC_LOCAL(GridLength, maxContent, (MaxContent));
105             return maxContent;
106         }
107         return m_maxTrackBreadth;
108     }
109 
setMinMax(const GridLength & minTrackBreadth,const GridLength & maxTrackBreadth)110     void setMinMax(const GridLength& minTrackBreadth, const GridLength& maxTrackBreadth)
111     {
112         m_type = MinMaxTrackSizing;
113         m_minTrackBreadth = minTrackBreadth;
114         m_maxTrackBreadth = maxTrackBreadth;
115 
116         cacheMinMaxTrackBreadthTypes();
117     }
118 
type()119     GridTrackSizeType type() const { return m_type; }
120 
isContentSized()121     bool isContentSized() const { return m_minTrackBreadth.isContentSized() || m_maxTrackBreadth.isContentSized(); }
122 
123     bool operator==(const GridTrackSize& other) const
124     {
125         return m_type == other.m_type && m_minTrackBreadth == other.m_minTrackBreadth && m_maxTrackBreadth == other.m_maxTrackBreadth;
126     }
127 
cacheMinMaxTrackBreadthTypes()128     void cacheMinMaxTrackBreadthTypes()
129     {
130         m_minTrackBreadthIsMaxContent = minTrackBreadth().isLength() && minTrackBreadth().length().isMaxContent();
131         m_minTrackBreadthIsMinOrMaxContent = m_minTrackBreadthIsMaxContent || (minTrackBreadth().isLength() && minTrackBreadth().length().isMinContent());
132         m_maxTrackBreadthIsMaxContent = maxTrackBreadth().isLength() && maxTrackBreadth().length().isMaxContent();
133         m_maxTrackBreadthIsMinOrMaxContent = m_maxTrackBreadthIsMaxContent || (maxTrackBreadth().isLength() && maxTrackBreadth().length().isMinContent());
134     }
135 
hasMinOrMaxContentMinTrackBreadth()136     bool hasMinOrMaxContentMinTrackBreadth() const { return m_minTrackBreadthIsMinOrMaxContent; }
hasMaxContentMinTrackBreadth()137     bool hasMaxContentMinTrackBreadth() const { return m_minTrackBreadthIsMaxContent; }
hasMinOrMaxContentMaxTrackBreadth()138     bool hasMinOrMaxContentMaxTrackBreadth() const { return m_maxTrackBreadthIsMinOrMaxContent; }
hasMaxContentMaxTrackBreadth()139     bool hasMaxContentMaxTrackBreadth() const { return m_maxTrackBreadthIsMaxContent; }
140 
141 private:
142     GridTrackSizeType m_type;
143     GridLength m_minTrackBreadth;
144     GridLength m_maxTrackBreadth;
145     bool m_minTrackBreadthIsMinOrMaxContent;
146     bool m_minTrackBreadthIsMaxContent;
147     bool m_maxTrackBreadthIsMinOrMaxContent;
148     bool m_maxTrackBreadthIsMaxContent;
149 };
150 
151 } // namespace WebCore
152 
153 #endif // GridTrackSize_h
154