Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 3 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
| 4 Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com) | 4 Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com) |
| 5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. | 5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. |
| 6 Copyright (C) 2012 Motorola Mobility, Inc. All rights reserved. | 6 Copyright (C) 2012 Motorola Mobility, Inc. All rights reserved. |
| 7 Copyright (C) 2013 Google, Inc. All rights reserved. | 7 Copyright (C) 2013 Google, Inc. All rights reserved. |
| 8 | 8 |
| 9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
| 10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
| 11 License as published by the Free Software Foundation; either | 11 License as published by the Free Software Foundation; either |
| 12 version 2 of the License, or (at your option) any later version. | 12 version 2 of the License, or (at your option) any later version. |
| 13 | 13 |
| 14 This library is distributed in the hope that it will be useful, | 14 This library is distributed in the hope that it will be useful, |
| 15 but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 Library General Public License for more details. | 17 Library General Public License for more details. |
| 18 | 18 |
| 19 You should have received a copy of the GNU Library General Public License | 19 You should have received a copy of the GNU Library General Public License |
| 20 along with this library; see the file COPYING.LIB. If not, write to | 20 along with this library; see the file COPYING.LIB. If not, write to |
| 21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 Boston, MA 02110-1301, USA. | 22 Boston, MA 02110-1301, USA. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "core/css/CSSLengthFunctions.h" | 26 #include "core/css/CSSLengthFunctions.h" |
| 27 | 27 |
| 28 #include "core/rendering/RenderView.h" | |
| 29 #include "platform/LayoutUnit.h" | 28 #include "platform/LayoutUnit.h" |
| 30 #include "platform/Length.h" | 29 #include "platform/Length.h" |
| 31 #include "platform/LengthFunctions.h" | 30 #include "platform/LengthFunctions.h" |
| 32 | 31 |
| 33 namespace WebCore { | 32 namespace WebCore { |
| 34 | 33 |
| 35 int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue, Rend erView* renderView, bool roundPercentages) | 34 int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) |
| 36 { | 35 { |
| 37 return static_cast<int>(minimumValueForLength(length, maximumValue, renderVi ew, roundPercentages)); | 36 return static_cast<int>(minimumValueForLength(length, maximumValue, roundPer centages)); |
| 38 } | 37 } |
| 39 | 38 |
| 40 int intValueForLength(const Length& length, LayoutUnit maximumValue, RenderView* renderView, bool roundPercentages) | 39 int intValueForLength(const Length& length, LayoutUnit maximumValue, bool roundP ercentages) |
| 41 { | 40 { |
| 42 return static_cast<int>(valueForLength(length, maximumValue, renderView, rou ndPercentages)); | 41 return static_cast<int>(valueForLength(length, maximumValue, roundPercentage s)); |
| 43 } | 42 } |
| 44 | 43 |
| 45 LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue, RenderView* renderView, bool roundPercentages) | 44 LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) |
| 46 { | 45 { |
| 47 switch (length.type()) { | 46 switch (length.type()) { |
| 48 case Fixed: | 47 case Fixed: |
| 49 return length.value(); | 48 return length.value(); |
| 50 case Percent: | 49 case Percent: |
| 51 if (roundPercentages) | 50 if (roundPercentages) |
| 52 return static_cast<LayoutUnit>(round(maximumValue * length.percent() / 100.0f)); | 51 return static_cast<LayoutUnit>(round(maximumValue * length.percent() / 100.0f)); |
| 53 // Don't remove the extra cast to float. It is needed for rounding on 32 -bit Intel machines that use the FPU stack. | 52 // 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 static_cast<float>(maximumValue * length.percent() / 100.0f); | 53 return static_cast<float>(maximumValue * length.percent() / 100.0f); |
| 55 case Calculated: | 54 case Calculated: |
| 56 return length.nonNanCalculatedValue(maximumValue); | 55 return length.nonNanCalculatedValue(maximumValue); |
| 57 case ViewportPercentageWidth: | |
| 58 return renderView ? renderView->viewportPercentageWidth(length.viewportP ercentageLength()) : LayoutUnit(0); | |
| 59 case ViewportPercentageHeight: | |
| 60 return renderView ? renderView->viewportPercentageHeight(length.viewport PercentageLength()) : LayoutUnit(0); | |
| 61 case ViewportPercentageMin: | |
| 62 return renderView ? renderView->viewportPercentageMin(length.viewportPer centageLength()) : LayoutUnit(0); | |
| 63 case ViewportPercentageMax: | |
| 64 return renderView ? renderView->viewportPercentageMax(length.viewportPer centageLength()) : LayoutUnit(0); | |
| 65 case FillAvailable: | 56 case FillAvailable: |
| 66 case Auto: | 57 case Auto: |
| 67 return 0; | 58 return 0; |
| 68 case Intrinsic: | 59 case Intrinsic: |
| 69 case MinIntrinsic: | 60 case MinIntrinsic: |
| 70 case MinContent: | 61 case MinContent: |
| 71 case MaxContent: | 62 case MaxContent: |
| 72 case FitContent: | 63 case FitContent: |
| 73 case ExtendToZoom: | 64 case ExtendToZoom: |
| 65 case DeviceWidth: | |
| 66 case DeviceHeight: | |
| 74 case Undefined: | 67 case Undefined: |
| 75 ASSERT_NOT_REACHED(); | 68 ASSERT_NOT_REACHED(); |
| 76 return 0; | 69 return 0; |
| 77 } | 70 } |
| 78 ASSERT_NOT_REACHED(); | 71 ASSERT_NOT_REACHED(); |
| 79 return 0; | 72 return 0; |
| 80 } | 73 } |
| 81 | 74 |
| 82 LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue, RenderV iew* renderView, bool roundPercentages) | 75 LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue, bool ro undPercentages) |
| 83 { | 76 { |
| 84 switch (length.type()) { | 77 switch (length.type()) { |
| 85 case Fixed: | 78 case Fixed: |
| 86 case Percent: | 79 case Percent: |
| 87 case Calculated: | 80 case Calculated: |
| 88 case ViewportPercentageWidth: | 81 return minimumValueForLength(length, maximumValue, roundPercentages); |
| 89 case ViewportPercentageHeight: | |
| 90 case ViewportPercentageMin: | |
| 91 case ViewportPercentageMax: | |
| 92 return minimumValueForLength(length, maximumValue, renderView, roundPerc entages); | |
| 93 case FillAvailable: | 82 case FillAvailable: |
| 94 case Auto: | 83 case Auto: |
| 95 return maximumValue; | 84 return maximumValue; |
| 96 case Intrinsic: | 85 case Intrinsic: |
| 97 case MinIntrinsic: | 86 case MinIntrinsic: |
| 98 case MinContent: | 87 case MinContent: |
| 99 case MaxContent: | 88 case MaxContent: |
| 100 case FitContent: | 89 case FitContent: |
| 101 case ExtendToZoom: | 90 case ExtendToZoom: |
| 91 case DeviceWidth: | |
| 92 case DeviceHeight: | |
| 102 case Undefined: | 93 case Undefined: |
| 103 ASSERT_NOT_REACHED(); | 94 ASSERT_NOT_REACHED(); |
| 104 return 0; | 95 return 0; |
| 105 } | |
| 106 ASSERT_NOT_REACHED(); | |
| 107 return 0; | |
| 108 } | |
| 109 | |
| 110 // This method has code duplicated in platform/LengthFunctions.cpp. | |
|
johnme
2013/12/18 12:04:15
As you've removed the duplicate here, could you up
Timothy Loh
2013/12/23 06:28:16
Done.
| |
| 111 // Any changes here most likely also need to be applied there. | |
| 112 float floatValueForLength(const Length& length, float maximumValue, RenderView* renderView) | |
| 113 { | |
| 114 if (!renderView) | |
| 115 return floatValueForLength(length, maximumValue); | |
| 116 | |
| 117 switch (length.type()) { | |
| 118 case Fixed: | |
| 119 return length.getFloatValue(); | |
| 120 case Percent: | |
| 121 return static_cast<float>(maximumValue * length.percent() / 100.0f); | |
| 122 case FillAvailable: | |
| 123 case Auto: | |
| 124 return static_cast<float>(maximumValue); | |
| 125 case Calculated: | |
| 126 return length.nonNanCalculatedValue(maximumValue); | |
| 127 case ViewportPercentageWidth: | |
| 128 return static_cast<int>(renderView->viewportPercentageWidth(length.viewp ortPercentageLength())); | |
| 129 case ViewportPercentageHeight: | |
| 130 return static_cast<int>(renderView->viewportPercentageHeight(length.view portPercentageLength())); | |
| 131 case ViewportPercentageMin: | |
| 132 return static_cast<int>(renderView->viewportPercentageMin(length.viewpor tPercentageLength())); | |
| 133 case ViewportPercentageMax: | |
| 134 return static_cast<int>(renderView->viewportPercentageMax(length.viewpor tPercentageLength())); | |
| 135 case Intrinsic: | |
| 136 case MinIntrinsic: | |
| 137 case MinContent: | |
| 138 case MaxContent: | |
| 139 case FitContent: | |
| 140 case ExtendToZoom: | |
| 141 case Undefined: | |
| 142 ASSERT_NOT_REACHED(); | |
| 143 return 0; | |
| 144 } | 96 } |
| 145 ASSERT_NOT_REACHED(); | 97 ASSERT_NOT_REACHED(); |
| 146 return 0; | 98 return 0; |
| 147 } | 99 } |
| 148 | 100 |
| 149 } // namespace WebCore | 101 } // namespace WebCore |
| OLD | NEW |