Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012, Google Inc. All rights reserved. | 2 * Copyright (c) 2012, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 inline IntSize roundedIntSize(const LayoutSize& s) | 163 inline IntSize roundedIntSize(const LayoutSize& s) |
| 164 { | 164 { |
| 165 return IntSize(s.width().round(), s.height().round()); | 165 return IntSize(s.width().round(), s.height().round()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 inline LayoutSize roundedLayoutSize(const FloatSize& s) | 168 inline LayoutSize roundedLayoutSize(const FloatSize& s) |
| 169 { | 169 { |
| 170 return LayoutSize(s); | 170 return LayoutSize(s); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Convert the specified scaled size to one that agrees with the specified aspec t ratio | |
| 174 // (expressed as a size, too). | |
|
ojan
2013/08/08 02:36:55
Blink (and WebKit) style is to leave out "what" co
mstensho (USE GERRIT)
2013/08/08 07:26:42
Done.
| |
| 175 enum AspectRatioFit { // How to set a size with the specified aspect ratio | |
| 176 AspectRatioFitShrink, // Shrink in one dimension to gain aspect ratio | |
| 177 AspectRatioFitGrow // Grow in one dimension to gain aspect ratio | |
| 178 }; | |
|
ojan
2013/08/08 02:36:55
Needs another line-break here.
mstensho (USE GERRIT)
2013/08/08 07:26:42
Done.
| |
| 179 inline LayoutSize fitLayoutSizeToAspectRatio(const LayoutSize& scaledSize, const LayoutSize& aspectRatio, AspectRatioFit fit) | |
|
ojan
2013/08/08 02:36:55
I think this method makes more sense as a member o
mstensho (USE GERRIT)
2013/08/08 07:26:42
Done.
| |
| 180 { | |
| 181 // Set a new width or height to get to a size that honors the aspect ratio. If fit is | |
| 182 // AspectRatioFitGrow, increase in the dimension that is scaled less. Otherw ise, | |
| 183 // decrease in the dimension that is scaled more. | |
| 184 float heightScale = scaledSize.height().toFloat() / aspectRatio.height().toF loat(); | |
| 185 float widthScale = scaledSize.width().toFloat() / aspectRatio.width().toFloa t(); | |
| 186 if ((widthScale > heightScale) != (fit == AspectRatioFitGrow)) | |
| 187 return LayoutSize(scaledSize.height() * aspectRatio.width() / aspectRati o.height(), scaledSize.height()); | |
| 188 return LayoutSize(scaledSize.width(), scaledSize.width() * aspectRatio.heigh t() / aspectRatio.width()); | |
| 189 } | |
| 190 | |
| 173 } // namespace WebCore | 191 } // namespace WebCore |
| 174 | 192 |
| 175 #endif // LayoutSize_h | 193 #endif // LayoutSize_h |
| OLD | NEW |