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 21 matching lines...) Expand all Loading... |
32 #define LayoutSize_h | 32 #define LayoutSize_h |
33 | 33 |
34 #include "core/platform/LayoutUnit.h" | 34 #include "core/platform/LayoutUnit.h" |
35 #include "core/platform/graphics/FloatSize.h" | 35 #include "core/platform/graphics/FloatSize.h" |
36 #include "core/platform/graphics/IntSize.h" | 36 #include "core/platform/graphics/IntSize.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 class LayoutPoint; | 40 class LayoutPoint; |
41 | 41 |
| 42 enum AspectRatioFit { |
| 43 AspectRatioFitShrink, |
| 44 AspectRatioFitGrow |
| 45 }; |
| 46 |
42 class LayoutSize { | 47 class LayoutSize { |
43 public: | 48 public: |
44 LayoutSize() : m_width(0), m_height(0) { } | 49 LayoutSize() : m_width(0), m_height(0) { } |
45 LayoutSize(const IntSize& size) : m_width(size.width()), m_height(size.heigh
t()) { } | 50 LayoutSize(const IntSize& size) : m_width(size.width()), m_height(size.heigh
t()) { } |
46 LayoutSize(LayoutUnit width, LayoutUnit height) : m_width(width), m_height(h
eight) { } | 51 LayoutSize(LayoutUnit width, LayoutUnit height) : m_width(width), m_height(h
eight) { } |
47 | 52 |
48 explicit LayoutSize(const FloatSize& size) : m_width(size.width()), m_height
(size.height()) { } | 53 explicit LayoutSize(const FloatSize& size) : m_width(size.width()), m_height
(size.height()) { } |
49 | 54 |
50 LayoutUnit width() const { return m_width; } | 55 LayoutUnit width() const { return m_width; } |
51 LayoutUnit height() const { return m_height; } | 56 LayoutUnit height() const { return m_height; } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 m_width = minimumSize.width(); | 110 m_width = minimumSize.width(); |
106 if (m_height < minimumSize.height()) | 111 if (m_height < minimumSize.height()) |
107 m_height = minimumSize.height(); | 112 m_height = minimumSize.height(); |
108 } | 113 } |
109 | 114 |
110 LayoutSize transposedSize() const | 115 LayoutSize transposedSize() const |
111 { | 116 { |
112 return LayoutSize(m_height, m_width); | 117 return LayoutSize(m_height, m_width); |
113 } | 118 } |
114 | 119 |
| 120 LayoutSize fitToAspectRatio(const LayoutSize& aspectRatio, AspectRatioFit fi
t) const |
| 121 { |
| 122 float heightScale = height().toFloat() / aspectRatio.height().toFloat(); |
| 123 float widthScale = width().toFloat() / aspectRatio.width().toFloat(); |
| 124 if ((widthScale > heightScale) != (fit == AspectRatioFitGrow)) |
| 125 return LayoutSize(height() * aspectRatio.width() / aspectRatio.heigh
t(), height()); |
| 126 return LayoutSize(width(), width() * aspectRatio.height() / aspectRatio.
width()); |
| 127 } |
| 128 |
115 private: | 129 private: |
116 LayoutUnit m_width, m_height; | 130 LayoutUnit m_width, m_height; |
117 }; | 131 }; |
118 | 132 |
119 inline LayoutSize& operator+=(LayoutSize& a, const LayoutSize& b) | 133 inline LayoutSize& operator+=(LayoutSize& a, const LayoutSize& b) |
120 { | 134 { |
121 a.setWidth(a.width() + b.width()); | 135 a.setWidth(a.width() + b.width()); |
122 a.setHeight(a.height() + b.height()); | 136 a.setHeight(a.height() + b.height()); |
123 return a; | 137 return a; |
124 } | 138 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 180 } |
167 | 181 |
168 inline LayoutSize roundedLayoutSize(const FloatSize& s) | 182 inline LayoutSize roundedLayoutSize(const FloatSize& s) |
169 { | 183 { |
170 return LayoutSize(s); | 184 return LayoutSize(s); |
171 } | 185 } |
172 | 186 |
173 } // namespace WebCore | 187 } // namespace WebCore |
174 | 188 |
175 #endif // LayoutSize_h | 189 #endif // LayoutSize_h |
OLD | NEW |