1 | /*
|
---|
2 | Copyright (C) 1999 Lars Knoll ([email protected])
|
---|
3 | Copyright (C) 2006-2017 Apple Inc. All rights reserved.
|
---|
4 | Copyright (C) 2011 Rik Cabanier ([email protected])
|
---|
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 FloatPoint;
|
---|
33 | class LayoutSize;
|
---|
34 |
|
---|
35 | struct Length;
|
---|
36 | struct LengthSize;
|
---|
37 | struct LengthPoint;
|
---|
38 |
|
---|
39 | int intValueForLength(const Length&, LayoutUnit maximumValue);
|
---|
40 | float floatValueForLength(const Length&, LayoutUnit maximumValue);
|
---|
41 | WEBCORE_EXPORT float floatValueForLength(const Length&, float maximumValue);
|
---|
42 | WEBCORE_EXPORT LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue);
|
---|
43 |
|
---|
44 | LayoutSize sizeForLengthSize(const LengthSize&, const LayoutSize& maximumValue);
|
---|
45 | FloatSize floatSizeForLengthSize(const LengthSize&, const FloatSize& maximumValue);
|
---|
46 |
|
---|
47 | LayoutPoint pointForLengthPoint(const LengthPoint&, const LayoutSize& maximumValue);
|
---|
48 | FloatPoint floatPointForLengthPoint(const LengthPoint&, const FloatSize& maximumValue);
|
---|
49 |
|
---|
50 | inline LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue)
|
---|
51 | {
|
---|
52 | switch (length.type()) {
|
---|
53 | case LengthType::Fixed:
|
---|
54 | return LayoutUnit(length.value());
|
---|
55 | case LengthType::Percent:
|
---|
56 | // Don't remove the extra cast to float. It is needed for rounding on 32-bit Intel machines that use the FPU stack.
|
---|
57 | return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 100.0f));
|
---|
58 | case LengthType::Calculated:
|
---|
59 | return LayoutUnit(length.nonNanCalculatedValue(maximumValue));
|
---|
60 | case LengthType::FillAvailable:
|
---|
61 | case LengthType::Auto:
|
---|
62 | case LengthType::Content:
|
---|
63 | return 0;
|
---|
64 | case LengthType::Relative:
|
---|
65 | case LengthType::Intrinsic:
|
---|
66 | case LengthType::MinIntrinsic:
|
---|
67 | case LengthType::MinContent:
|
---|
68 | case LengthType::MaxContent:
|
---|
69 | case LengthType::FitContent:
|
---|
70 | case LengthType::Undefined:
|
---|
71 | break;
|
---|
72 | }
|
---|
73 | ASSERT_NOT_REACHED();
|
---|
74 | return 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | inline int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue)
|
---|
78 | {
|
---|
79 | return static_cast<int>(minimumValueForLength(length, maximumValue));
|
---|
80 | }
|
---|
81 |
|
---|
82 | template<typename T> inline LayoutUnit valueForLength(const Length& length, T maximumValue) { return valueForLength(length, LayoutUnit(maximumValue)); }
|
---|
83 | template<typename T> inline LayoutUnit minimumValueForLength(const Length& length, T maximumValue) { return minimumValueForLength(length, LayoutUnit(maximumValue)); }
|
---|
84 |
|
---|
85 | } // namespace WebCore
|
---|