| 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 minimumIntValueForLength(const Length&, LayoutUnit maximumValue); |
| 39 | int intValueForLength(const Length&, LayoutUnit maximumValue); |
| 40 | LayoutUnit minimumValueForLength(const Length&, LayoutUnit maximumValue); |
| 41 | WEBCORE_EXPORT LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue); |
| 42 | LayoutSize sizeForLengthSize(const LengthSize&, const LayoutSize& maximumValue); |
| 43 | float floatValueForLength(const Length&, LayoutUnit maximumValue); |
| 44 | WEBCORE_EXPORT float floatValueForLength(const Length&, float maximumValue); |
| 45 | FloatSize floatSizeForLengthSize(const LengthSize&, const FloatSize&); |
| 46 | |
| 47 | inline LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue) |
| 48 | { |
| 49 | switch (length.type()) { |
| 50 | case Fixed: |
| 51 | return length.value(); |
| 52 | case Percent: |
| 53 | // Don't remove the extra cast to float. It is needed for rounding on 32-bit Intel machines that use the FPU stack. |
| 54 | return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 100.0f)); |
| 55 | case Calculated: |
| 56 | return length.nonNanCalculatedValue(maximumValue); |
| 57 | case FillAvailable: |
| 58 | case Auto: |
| 59 | return 0; |
| 60 | case Relative: |
| 61 | case Intrinsic: |
| 62 | case MinIntrinsic: |
| 63 | case MinContent: |
| 64 | case MaxContent: |
| 65 | case FitContent: |
| 66 | case Undefined: |
| 67 | break; |
| 68 | } |
| 69 | ASSERT_NOT_REACHED(); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | inline int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue) |
| 74 | { |
| 75 | return static_cast<int>(minimumValueForLength(length, maximumValue)); |
| 76 | } |
| 77 | |
| 78 | } // namespace WebCore |
| 79 | |