1 | /* |
2 | Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 | Copyright (C) 2006-2017 Apple Inc. All rights reserved. |
4 | Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com) |
5 | Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. |
6 | Copyright (C) 2012 Motorola Mobility, Inc. All rights reserved. |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | */ |
23 | |
24 | #pragma once |
25 | |
26 | #include "LayoutUnit.h" |
27 | #include "Length.h" |
28 | |
29 | namespace WebCore { |
30 | |
31 | class FloatSize; |
32 | class LayoutSize; |
33 | class RenderView; |
34 | |
35 | struct Length; |
36 | struct LengthSize; |
37 | |
38 | int intValueForLength(const Length&, LayoutUnit maximumValue); |
39 | WEBCORE_EXPORT LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue); |
40 | LayoutSize sizeForLengthSize(const LengthSize&, const LayoutSize& maximumValue); |
41 | float floatValueForLength(const Length&, LayoutUnit maximumValue); |
42 | WEBCORE_EXPORT float floatValueForLength(const Length&, float maximumValue); |
43 | FloatSize floatSizeForLengthSize(const LengthSize&, const FloatSize&); |
44 | |
45 | inline LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue) |
46 | { |
47 | switch (length.type()) { |
48 | case Fixed: |
49 | return LayoutUnit(length.value()); |
50 | case Percent: |
51 | // Don't remove the extra cast to float. It is needed for rounding on 32-bit Intel machines that use the FPU stack. |
52 | return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 100.0f)); |
53 | case Calculated: |
54 | return LayoutUnit(length.nonNanCalculatedValue(maximumValue)); |
55 | case FillAvailable: |
56 | case Auto: |
57 | return 0; |
58 | case Relative: |
59 | case Intrinsic: |
60 | case MinIntrinsic: |
61 | case MinContent: |
62 | case MaxContent: |
63 | case FitContent: |
64 | case Undefined: |
65 | break; |
66 | } |
67 | ASSERT_NOT_REACHED(); |
68 | return 0; |
69 | } |
70 | |
71 | inline int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue) |
72 | { |
73 | return static_cast<int>(minimumValueForLength(length, maximumValue)); |
74 | } |
75 | |
76 | template<typename T> inline LayoutUnit valueForLength(const Length& length, T maximumValue) { return valueForLength(length, LayoutUnit(maximumValue)); } |
77 | template<typename T> inline LayoutUnit minimumValueForLength(const Length& length, T maximumValue) { return minimumValueForLength(length, LayoutUnit(maximumValue)); } |
78 | |
79 | } // namespace WebCore |
80 | |