| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> | 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> |
| 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 // If a container size is available it has precedence. | 149 // If a container size is available it has precedence. |
| 150 IntSize containerSize = layoutObject->containerSize(); | 150 IntSize containerSize = layoutObject->containerSize(); |
| 151 if (!containerSize.isEmpty()) | 151 if (!containerSize.isEmpty()) |
| 152 return containerSize; | 152 return containerSize; |
| 153 | 153 |
| 154 // Assure that a container size is always given for a non-identity zoom leve
l. | 154 // Assure that a container size is always given for a non-identity zoom leve
l. |
| 155 ASSERT(layoutObject->style()->effectiveZoom() == 1); | 155 ASSERT(layoutObject->style()->effectiveZoom() == 1); |
| 156 | 156 |
| 157 // No set container size; use concrete object size. | 157 // No set container size; use concrete object size. |
| 158 return m_concreteObjectSize; | 158 return m_intrinsicSize; |
| 159 } | 159 } |
| 160 | 160 |
| 161 static float resolveWidthForRatio(float height, const FloatSize& intrinsicRatio) | 161 static float resolveWidthForRatio(float height, const FloatSize& intrinsicRatio) |
| 162 { | 162 { |
| 163 return height * intrinsicRatio.width() / intrinsicRatio.height(); | 163 return height * intrinsicRatio.width() / intrinsicRatio.height(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 static float resolveHeightForRatio(float width, const FloatSize& intrinsicRatio) | 166 static float resolveHeightForRatio(float width, const FloatSize& intrinsicRatio) |
| 167 { | 167 { |
| 168 return width * intrinsicRatio.height() / intrinsicRatio.width(); | 168 return width * intrinsicRatio.height() / intrinsicRatio.width(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 if (intrinsicSizingInfo.hasHeight) { | 203 if (intrinsicSizingInfo.hasHeight) { |
| 204 if (intrinsicSizingInfo.aspectRatio.isEmpty()) | 204 if (intrinsicSizingInfo.aspectRatio.isEmpty()) |
| 205 return FloatSize(defaultObjectSize.width(), intrinsicSizingInfo.size
.height()); | 205 return FloatSize(defaultObjectSize.width(), intrinsicSizingInfo.size
.height()); |
| 206 | 206 |
| 207 return FloatSize(resolveWidthForRatio(intrinsicSizingInfo.size.height(),
intrinsicSizingInfo.aspectRatio), intrinsicSizingInfo.size.height()); | 207 return FloatSize(resolveWidthForRatio(intrinsicSizingInfo.size.height(),
intrinsicSizingInfo.aspectRatio), intrinsicSizingInfo.size.height()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { | 210 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { |
| 211 // TODO(davve): According to the specification, the concrete object size
should resolve as a | 211 // "A contain constraint is resolved by setting the concrete object size
to the largest |
| 212 // contain constraint against the default object size at this stage. Unt
il the | 212 // rectangle that has the object's intrinsic aspect ratio and additiona
lly has neither |
| 213 // defaultObjectSize is context sensitive, right now it's hard-coded to
300x150, we have to | 213 // width nor height larger than the constraint rectangle's width and he
ight, respectively." |
| 214 // preserve legacy behavior by returning the aspectRatio as the concrete
object size. | 214 float solutionWidth = resolveWidthForRatio(defaultObjectSize.height(), i
ntrinsicSizingInfo.aspectRatio); |
| 215 return intrinsicSizingInfo.aspectRatio; | 215 float solutionHeight = resolveHeightForRatio(defaultObjectSize.width(),
intrinsicSizingInfo.aspectRatio); |
| 216 if (solutionWidth <= defaultObjectSize.width()) { |
| 217 if (solutionHeight <= defaultObjectSize.height()) { |
| 218 float areaOne = solutionWidth * defaultObjectSize.height(); |
| 219 float areaTwo = defaultObjectSize.width() * solutionHeight; |
| 220 if (areaOne < areaTwo) |
| 221 return FloatSize(defaultObjectSize.width(), solutionHeight); |
| 222 return FloatSize(solutionWidth, defaultObjectSize.height()); |
| 223 } |
| 224 |
| 225 return FloatSize(solutionWidth, defaultObjectSize.height()); |
| 226 } |
| 227 |
| 228 ASSERT(solutionHeight <= defaultObjectSize.height()); |
| 229 return FloatSize(defaultObjectSize.width(), solutionHeight); |
| 216 } | 230 } |
| 217 | 231 |
| 218 return defaultObjectSize; | 232 return defaultObjectSize; |
| 219 } | 233 } |
| 220 | 234 |
| 221 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, | 235 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, |
| 222 const FloatRect& srcRect, const KURL& url) | 236 const FloatRect& srcRect, const KURL& url) |
| 223 { | 237 { |
| 224 if (!m_page) | 238 if (!m_page) |
| 225 return; | 239 return; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 frame->view()->setCanHaveScrollbars(false); // SVG Images will always sy
nthesize a viewBox, if it's not available, and thus never see scrollbars. | 542 frame->view()->setCanHaveScrollbars(false); // SVG Images will always sy
nthesize a viewBox, if it's not available, and thus never see scrollbars. |
| 529 frame->view()->setTransparent(true); // SVG Images are transparent. | 543 frame->view()->setTransparent(true); // SVG Images are transparent. |
| 530 | 544 |
| 531 m_page = page.release(); | 545 m_page = page.release(); |
| 532 | 546 |
| 533 TRACE_EVENT0("blink", "SVGImage::dataChanged::load"); | 547 TRACE_EVENT0("blink", "SVGImage::dataChanged::load"); |
| 534 loader.load(FrameLoadRequest(0, blankURL(), SubstituteData(data(), Atomi
cString("image/svg+xml", AtomicString::ConstructFromLiteral), | 548 loader.load(FrameLoadRequest(0, blankURL(), SubstituteData(data(), Atomi
cString("image/svg+xml", AtomicString::ConstructFromLiteral), |
| 535 AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), F
orceSynchronousLoad))); | 549 AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), F
orceSynchronousLoad))); |
| 536 | 550 |
| 537 // Set the concrete object size before a container size is available. | 551 // Set the concrete object size before a container size is available. |
| 538 m_concreteObjectSize = roundedIntSize(calculateConcreteObjectSize(FloatS
ize(300, 150))); | 552 m_intrinsicSize = roundedIntSize(calculateConcreteObjectSize(FloatSize(3
00, 150))); |
| 539 } | 553 } |
| 540 | 554 |
| 541 return m_page; | 555 return m_page; |
| 542 } | 556 } |
| 543 | 557 |
| 544 String SVGImage::filenameExtension() const | 558 String SVGImage::filenameExtension() const |
| 545 { | 559 { |
| 546 return "svg"; | 560 return "svg"; |
| 547 } | 561 } |
| 548 | 562 |
| 549 } // namespace blink | 563 } // namespace blink |
| OLD | NEW |