OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 20 matching lines...) Expand all Loading... |
31 #ifndef GridTrackSize_h | 31 #ifndef GridTrackSize_h |
32 #define GridTrackSize_h | 32 #define GridTrackSize_h |
33 | 33 |
34 #include "core/style/GridLength.h" | 34 #include "core/style/GridLength.h" |
35 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 enum GridTrackSizeType { | 39 enum GridTrackSizeType { |
40 LengthTrackSizing, | 40 LengthTrackSizing, |
41 MinMaxTrackSizing | 41 MinMaxTrackSizing, |
| 42 FitContentTrackSizing |
42 }; | 43 }; |
43 | 44 |
| 45 // This class represents a <track-size> from the spec. Althought there are 3 dif
ferent types of |
| 46 // <track-size> there is always an equivalent minmax() representation that could
represent any of |
| 47 // them. The only special case is fit-content(argument) which is similar to minm
ax(auto, max-content) |
| 48 // except that the track size is clamped at argument if it is greater than the a
uto minimum. At the |
| 49 // GridTrackSize level we don't need to worry about clamping so we treat that ca
se exactly as |
| 50 // minmax(auto, max-content) althought we store the argument for later use in m_
maxTrackBreadth. |
44 class GridTrackSize { | 51 class GridTrackSize { |
45 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 52 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
46 public: | 53 public: |
47 GridTrackSize(const GridLength& length) | 54 GridTrackSize(const GridLength& length, GridTrackSizeType trackSizeType = Le
ngthTrackSizing) |
48 : m_type(LengthTrackSizing) | 55 : m_type(trackSizeType) |
49 , m_minTrackBreadth(length) | 56 , m_minTrackBreadth(trackSizeType == FitContentTrackSizing ? Length(Auto
) : length) |
50 , m_maxTrackBreadth(length) | 57 , m_maxTrackBreadth(length) |
51 , m_minTrackBreadthIsMaxContent(false) | |
52 , m_maxTrackBreadthIsMaxContent(false) | |
53 { | 58 { |
| 59 DCHECK(trackSizeType == LengthTrackSizing || trackSizeType == FitContent
TrackSizing); |
54 cacheMinMaxTrackBreadthTypes(); | 60 cacheMinMaxTrackBreadthTypes(); |
55 } | 61 } |
56 | 62 |
57 GridTrackSize(const GridLength& minTrackBreadth, const GridLength& maxTrackB
readth) | 63 GridTrackSize(const GridLength& minTrackBreadth, const GridLength& maxTrackB
readth) |
58 : m_type(MinMaxTrackSizing) | 64 : m_type(MinMaxTrackSizing) |
59 , m_minTrackBreadth(minTrackBreadth) | 65 , m_minTrackBreadth(minTrackBreadth) |
60 , m_maxTrackBreadth(maxTrackBreadth) | 66 , m_maxTrackBreadth(maxTrackBreadth) |
61 , m_minTrackBreadthIsMaxContent(false) | |
62 , m_maxTrackBreadthIsMaxContent(false) | |
63 { | 67 { |
64 cacheMinMaxTrackBreadthTypes(); | 68 cacheMinMaxTrackBreadthTypes(); |
65 } | 69 } |
66 | 70 |
67 const GridLength& length() const | 71 GridLength length() const |
68 { | 72 { |
69 ASSERT(m_type == LengthTrackSizing); | 73 DCHECK(m_type == LengthTrackSizing || m_type == FitContentTrackSizing); |
70 ASSERT(m_minTrackBreadth == m_maxTrackBreadth); | 74 DCHECK(m_minTrackBreadth == m_maxTrackBreadth || m_type == FitContentTra
ckSizing); |
71 const GridLength& minTrackBreadth = m_minTrackBreadth; | 75 return m_maxTrackBreadth; |
72 return minTrackBreadth; | |
73 } | 76 } |
74 | 77 |
75 const GridLength& minTrackBreadth() const { return m_minTrackBreadth; } | 78 GridLength minTrackBreadth() const { return m_minTrackBreadth; } |
76 | 79 GridLength maxTrackBreadth() const { return isFitContent() ? GridLength(Leng
th(MaxContent)) : m_maxTrackBreadth; } |
77 const GridLength& maxTrackBreadth() const { return m_maxTrackBreadth; } | |
78 | 80 |
79 GridTrackSizeType type() const { return m_type; } | 81 GridTrackSizeType type() const { return m_type; } |
80 | 82 |
81 bool isContentSized() const { return m_minTrackBreadth.isContentSized() || m
_maxTrackBreadth.isContentSized(); } | 83 bool isContentSized() const { return m_minTrackBreadth.isContentSized() || m
_maxTrackBreadth.isContentSized(); } |
| 84 bool isFitContent() const { return m_type == FitContentTrackSizing; } |
82 | 85 |
83 bool operator==(const GridTrackSize& other) const | 86 bool operator==(const GridTrackSize& other) const |
84 { | 87 { |
85 return m_type == other.m_type && m_minTrackBreadth == other.m_minTrackBr
eadth && m_maxTrackBreadth == other.m_maxTrackBreadth; | 88 return m_type == other.m_type && m_minTrackBreadth == other.m_minTrackBr
eadth && m_maxTrackBreadth == other.m_maxTrackBreadth; |
86 } | 89 } |
87 | 90 |
88 void cacheMinMaxTrackBreadthTypes() | 91 void cacheMinMaxTrackBreadthTypes() |
89 { | 92 { |
90 m_minTrackBreadthIsAuto = minTrackBreadth().isLength() && minTrackBreadt
h().length().isAuto(); | 93 m_minTrackBreadthIsAuto = minTrackBreadth().isLength() && minTrackBreadt
h().length().isAuto(); |
91 m_minTrackBreadthIsMinContent = minTrackBreadth().isLength() && minTrack
Breadth().length().isMinContent(); | 94 m_minTrackBreadthIsMinContent = minTrackBreadth().isLength() && minTrack
Breadth().length().isMinContent(); |
(...skipping 24 matching lines...) Expand all Loading... |
116 bool m_minTrackBreadthIsMaxContent; | 119 bool m_minTrackBreadthIsMaxContent; |
117 bool m_minTrackBreadthIsMinContent; | 120 bool m_minTrackBreadthIsMinContent; |
118 bool m_maxTrackBreadthIsAuto; | 121 bool m_maxTrackBreadthIsAuto; |
119 bool m_maxTrackBreadthIsMaxContent; | 122 bool m_maxTrackBreadthIsMaxContent; |
120 bool m_maxTrackBreadthIsMinContent; | 123 bool m_maxTrackBreadthIsMinContent; |
121 }; | 124 }; |
122 | 125 |
123 } // namespace blink | 126 } // namespace blink |
124 | 127 |
125 #endif // GridTrackSize_h | 128 #endif // GridTrackSize_h |
OLD | NEW |