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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 return IntSize(); | 147 return IntSize(); |
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. |
| 158 return m_concreteObjectSize; |
| 159 } |
| 160 |
| 161 static float resolveWidthForRatio(float height, const FloatSize& intrinsicRatio) |
| 162 { |
| 163 return height * intrinsicRatio.width() / intrinsicRatio.height(); |
| 164 } |
| 165 |
| 166 static float resolveHeightForRatio(float width, const FloatSize& intrinsicRatio) |
| 167 { |
| 168 return width * intrinsicRatio.height() / intrinsicRatio.width(); |
| 169 } |
| 170 |
| 171 FloatSize SVGImage::calculateConcreteObjectSize(const FloatSize& defaultObjectSi
ze) const |
| 172 { |
| 173 SVGSVGElement* svg = svgRootElement(m_page.get()); |
| 174 if (!svg) |
| 175 return FloatSize(); |
| 176 |
| 177 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(svg->layoutObject()); |
| 178 if (!layoutObject) |
| 179 return FloatSize(); |
| 180 |
157 LayoutBox::IntrinsicSizingInfo intrinsicSizingInfo; | 181 LayoutBox::IntrinsicSizingInfo intrinsicSizingInfo; |
158 layoutObject->computeIntrinsicSizingInfo(intrinsicSizingInfo); | 182 layoutObject->computeIntrinsicSizingInfo(intrinsicSizingInfo); |
159 | 183 |
160 if (intrinsicSizingInfo.size.isEmpty() && !intrinsicSizingInfo.aspectRatio.i
sEmpty()) { | 184 // https://www.w3.org/TR/css3-images/#default-sizing |
161 if (!intrinsicSizingInfo.size.width() && intrinsicSizingInfo.size.height
()) { | 185 |
162 intrinsicSizingInfo.size.setWidth( | 186 if (intrinsicSizingInfo.hasWidth && intrinsicSizingInfo.hasHeight) |
163 intrinsicSizingInfo.size.height() * intrinsicSizingInfo.aspectRa
tio.width() / intrinsicSizingInfo.aspectRatio.height()); | 187 return intrinsicSizingInfo.size; |
164 } else if (intrinsicSizingInfo.size.width() && !intrinsicSizingInfo.size
.height()) { | 188 |
165 intrinsicSizingInfo.size.setHeight( | 189 if (svg->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspect
Ratio::SVG_PRESERVEASPECTRATIO_NONE) { |
166 intrinsicSizingInfo.size.width() * intrinsicSizingInfo.aspectRat
io.height() / intrinsicSizingInfo.aspectRatio.width()); | 190 // TODO(davve): The intrinsic aspect ratio is not used to resolve a miss
ing intrinsic width |
167 } | 191 // or height when preserveAspectRatio is none. It's unclear whether this
is correct. See |
| 192 // crbug.com/584172. |
| 193 return defaultObjectSize; |
168 } | 194 } |
169 | 195 |
170 // TODO(davve): In order to maintain aspect ratio the intrinsic | 196 if (intrinsicSizingInfo.hasWidth) { |
171 // size is faked from the viewBox as a last resort. This may cause | 197 if (intrinsicSizingInfo.aspectRatio.isEmpty()) |
172 // unwanted side effects. Preferably we should be able to signal | 198 return FloatSize(intrinsicSizingInfo.size.width(), defaultObjectSize
.height()); |
173 // the intrinsic ratio in another way. | |
174 if (intrinsicSizingInfo.size.isEmpty()) | |
175 intrinsicSizingInfo.size = rootElement->currentViewBoxRect().size(); | |
176 | 199 |
177 if (!intrinsicSizingInfo.size.isEmpty()) | 200 return FloatSize(intrinsicSizingInfo.size.width(), resolveHeightForRatio
(intrinsicSizingInfo.size.width(), intrinsicSizingInfo.aspectRatio)); |
178 return expandedIntSize(intrinsicSizingInfo.size); | 201 } |
179 | 202 |
180 // As last resort, use CSS replaced element fallback size. | 203 if (intrinsicSizingInfo.hasHeight) { |
181 return IntSize(300, 150); | 204 if (intrinsicSizingInfo.aspectRatio.isEmpty()) |
| 205 return FloatSize(defaultObjectSize.width(), intrinsicSizingInfo.size
.height()); |
| 206 |
| 207 return FloatSize(resolveWidthForRatio(intrinsicSizingInfo.size.height(),
intrinsicSizingInfo.aspectRatio), intrinsicSizingInfo.size.height()); |
| 208 } |
| 209 |
| 210 if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { |
| 211 // TODO(davve): According to the specification, the concrete object size
should resolve as a |
| 212 // contain constraint against the default object size at this stage. Unt
il the |
| 213 // defaultObjectSize is context sensitive, right now it's hard-coded to
300x150, we have to |
| 214 // preserve legacy behavior by returning the aspectRatio as the concrete
object size. |
| 215 return intrinsicSizingInfo.aspectRatio; |
| 216 } |
| 217 |
| 218 return defaultObjectSize; |
182 } | 219 } |
183 | 220 |
184 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, | 221 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, |
185 const FloatRect& srcRect, const KURL& url) | 222 const FloatRect& srcRect, const KURL& url) |
186 { | 223 { |
187 if (!m_page) | 224 if (!m_page) |
188 return; | 225 return; |
189 | 226 |
190 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. | 227 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. |
191 ImageObserverDisabler imageObserverDisabler(this); | 228 ImageObserverDisabler imageObserverDisabler(this); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 frame->view()->setScrollbarsSuppressed(true); | 528 frame->view()->setScrollbarsSuppressed(true); |
492 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()->setCanHaveScrollbars(false); // SVG Images will always sy
nthesize a viewBox, if it's not available, and thus never see scrollbars. |
493 frame->view()->setTransparent(true); // SVG Images are transparent. | 530 frame->view()->setTransparent(true); // SVG Images are transparent. |
494 | 531 |
495 m_page = page.release(); | 532 m_page = page.release(); |
496 | 533 |
497 TRACE_EVENT0("blink", "SVGImage::dataChanged::load"); | 534 TRACE_EVENT0("blink", "SVGImage::dataChanged::load"); |
498 loader.load(FrameLoadRequest(0, blankURL(), SubstituteData(data(), Atomi
cString("image/svg+xml", AtomicString::ConstructFromLiteral), | 535 loader.load(FrameLoadRequest(0, blankURL(), SubstituteData(data(), Atomi
cString("image/svg+xml", AtomicString::ConstructFromLiteral), |
499 AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), F
orceSynchronousLoad))); | 536 AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), F
orceSynchronousLoad))); |
500 | 537 |
501 // Set the intrinsic size before a container size is available. | 538 // Set the concrete object size before a container size is available. |
502 m_intrinsicSize = containerSize(); | 539 m_concreteObjectSize = roundedIntSize(calculateConcreteObjectSize(FloatS
ize(300, 150))); |
503 } | 540 } |
504 | 541 |
505 return m_page; | 542 return m_page; |
506 } | 543 } |
507 | 544 |
508 String SVGImage::filenameExtension() const | 545 String SVGImage::filenameExtension() const |
509 { | 546 { |
510 return "svg"; | 547 return "svg"; |
511 } | 548 } |
512 | 549 |
513 } // namespace blink | 550 } // namespace blink |
OLD | NEW |