1 | /*
|
---|
2 | Copyright (C) 1999 Lars Knoll ([email protected])
|
---|
3 | Copyright (C) 2006, 2008 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 | #include "config.h"
|
---|
25 | #include "LengthFunctions.h"
|
---|
26 |
|
---|
27 | #include "FloatSize.h"
|
---|
28 | #include "LayoutSize.h"
|
---|
29 | #include "LengthPoint.h"
|
---|
30 | #include "LengthSize.h"
|
---|
31 |
|
---|
32 | namespace WebCore {
|
---|
33 |
|
---|
34 | int intValueForLength(const Length& length, LayoutUnit maximumValue)
|
---|
35 | {
|
---|
36 | return static_cast<int>(valueForLength(length, maximumValue));
|
---|
37 | }
|
---|
38 |
|
---|
39 | LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue)
|
---|
40 | {
|
---|
41 | switch (length.type()) {
|
---|
42 | case LengthType::Fixed:
|
---|
43 | case LengthType::Percent:
|
---|
44 | case LengthType::Calculated:
|
---|
45 | return minimumValueForLength(length, maximumValue);
|
---|
46 | case LengthType::FillAvailable:
|
---|
47 | case LengthType::Auto:
|
---|
48 | return maximumValue;
|
---|
49 | case LengthType::Relative:
|
---|
50 | case LengthType::Intrinsic:
|
---|
51 | case LengthType::MinIntrinsic:
|
---|
52 | case LengthType::Content:
|
---|
53 | case LengthType::MinContent:
|
---|
54 | case LengthType::MaxContent:
|
---|
55 | case LengthType::FitContent:
|
---|
56 | case LengthType::Undefined:
|
---|
57 | ASSERT_NOT_REACHED();
|
---|
58 | return 0;
|
---|
59 | }
|
---|
60 | ASSERT_NOT_REACHED();
|
---|
61 | return 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | // FIXME: when subpixel layout is supported this copy of floatValueForLength() can be removed. See bug 71143.
|
---|
65 | float floatValueForLength(const Length& length, LayoutUnit maximumValue)
|
---|
66 | {
|
---|
67 | switch (length.type()) {
|
---|
68 | case LengthType::Fixed:
|
---|
69 | return length.value();
|
---|
70 | case LengthType::Percent:
|
---|
71 | return static_cast<float>(maximumValue * length.percent() / 100.0f);
|
---|
72 | case LengthType::FillAvailable:
|
---|
73 | case LengthType::Auto:
|
---|
74 | return static_cast<float>(maximumValue);
|
---|
75 | case LengthType::Calculated:
|
---|
76 | return length.nonNanCalculatedValue(maximumValue);
|
---|
77 | case LengthType::Relative:
|
---|
78 | case LengthType::Intrinsic:
|
---|
79 | case LengthType::MinIntrinsic:
|
---|
80 | case LengthType::Content:
|
---|
81 | case LengthType::MinContent:
|
---|
82 | case LengthType::MaxContent:
|
---|
83 | case LengthType::FitContent:
|
---|
84 | case LengthType::Undefined:
|
---|
85 | ASSERT_NOT_REACHED();
|
---|
86 | return 0;
|
---|
87 | }
|
---|
88 | ASSERT_NOT_REACHED();
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 |
|
---|
92 | float floatValueForLength(const Length& length, float maximumValue)
|
---|
93 | {
|
---|
94 | switch (length.type()) {
|
---|
95 | case LengthType::Fixed:
|
---|
96 | return length.value();
|
---|
97 | case LengthType::Percent:
|
---|
98 | return static_cast<float>(maximumValue * length.percent() / 100.0f);
|
---|
99 | case LengthType::FillAvailable:
|
---|
100 | case LengthType::Auto:
|
---|
101 | return static_cast<float>(maximumValue);
|
---|
102 | case LengthType::Calculated:
|
---|
103 | return length.nonNanCalculatedValue(maximumValue);
|
---|
104 | case LengthType::Relative:
|
---|
105 | case LengthType::Intrinsic:
|
---|
106 | case LengthType::MinIntrinsic:
|
---|
107 | case LengthType::Content:
|
---|
108 | case LengthType::MinContent:
|
---|
109 | case LengthType::MaxContent:
|
---|
110 | case LengthType::FitContent:
|
---|
111 | case LengthType::Undefined:
|
---|
112 | ASSERT_NOT_REACHED();
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 | ASSERT_NOT_REACHED();
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | LayoutSize sizeForLengthSize(const LengthSize& length, const LayoutSize& maximumValue)
|
---|
120 | {
|
---|
121 | return { valueForLength(length.width, maximumValue.width()), valueForLength(length.height, maximumValue.height()) };
|
---|
122 | }
|
---|
123 |
|
---|
124 | LayoutPoint pointForLengthPoint(const LengthPoint& lengthPoint, const LayoutSize& maximumValue)
|
---|
125 | {
|
---|
126 | return { valueForLength(lengthPoint.x(), maximumValue.width()), valueForLength(lengthPoint.y(), maximumValue.height()) };
|
---|
127 | }
|
---|
128 |
|
---|
129 | FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, const FloatSize& boxSize)
|
---|
130 | {
|
---|
131 | return { floatValueForLength(lengthSize.width, boxSize.width()), floatValueForLength(lengthSize.height, boxSize.height()) };
|
---|
132 | }
|
---|
133 |
|
---|
134 | FloatPoint floatPointForLengthPoint(const LengthPoint& lengthPoint, const FloatSize& boxSize)
|
---|
135 | {
|
---|
136 | return { floatValueForLength(lengthPoint.x(), boxSize.width()), floatValueForLength(lengthPoint.y(), boxSize.height()) };
|
---|
137 | }
|
---|
138 |
|
---|
139 | } // namespace WebCore
|
---|