Commit b4a71048 authored by Hyunjune's avatar Hyunjune Committed by Commit Bot

Fix up incorrect size of <svg:image> with a SVG image without intrinsic size

This patch fixes up incorrect sizing of SVG Image with referred SVG
image without the intrinsic size.
So when referred image is SVG, it currently checks that referred image
has aspect-ratio.
If referred svg image doesn't have the aspect-ratio, set the concrete
object size from the 'default object size'.

Bug: 1045932
Change-Id: If979b3a9a7980bde9e2bee38ba2863cf223b4f0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094055Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Hyunjune Kim <hyunjune.kim@samsung.com>
Cr-Commit-Position: refs/heads/master@{#751325}
parent 1c344c85
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/core/html/media/media_element_parser_helpers.h" #include "third_party/blink/renderer/core/html/media/media_element_parser_helpers.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h" #include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/intrinsic_sizing_info.h"
#include "third_party/blink/renderer/core/layout/layout_analyzer.h" #include "third_party/blink/renderer/core/layout/layout_analyzer.h"
#include "third_party/blink/renderer/core/layout/layout_image_resource.h" #include "third_party/blink/renderer/core/layout/layout_image_resource.h"
#include "third_party/blink/renderer/core/layout/layout_replaced.h" #include "third_party/blink/renderer/core/layout/layout_replaced.h"
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
#include "third_party/blink/renderer/core/layout/svg/transformed_hit_test_location.h" #include "third_party/blink/renderer/core/layout/svg/transformed_hit_test_location.h"
#include "third_party/blink/renderer/core/paint/image_element_timing.h" #include "third_party/blink/renderer/core/paint/image_element_timing.h"
#include "third_party/blink/renderer/core/paint/svg_image_painter.h" #include "third_party/blink/renderer/core/paint/svg_image_painter.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/svg/svg_image_element.h" #include "third_party/blink/renderer/core/svg/svg_image_element.h"
#include "third_party/blink/renderer/platform/geometry/length_functions.h" #include "third_party/blink/renderer/platform/geometry/length_functions.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
...@@ -89,6 +91,7 @@ bool LayoutSVGImage::HasOverriddenIntrinsicSize() const { ...@@ -89,6 +91,7 @@ bool LayoutSVGImage::HasOverriddenIntrinsicSize() const {
FloatSize LayoutSVGImage::CalculateObjectSize() const { FloatSize LayoutSVGImage::CalculateObjectSize() const {
FloatSize intrinsic_size; FloatSize intrinsic_size;
ImageResourceContent* cached_image = image_resource_->CachedImage(); ImageResourceContent* cached_image = image_resource_->CachedImage();
bool has_intrinsic_ratio = true;
if (HasOverriddenIntrinsicSize()) { if (HasOverriddenIntrinsicSize()) {
intrinsic_size = FloatSize(LayoutReplaced::kDefaultWidth, intrinsic_size = FloatSize(LayoutReplaced::kDefaultWidth,
LayoutReplaced::kDefaultHeight); LayoutReplaced::kDefaultHeight);
...@@ -98,20 +101,33 @@ FloatSize LayoutSVGImage::CalculateObjectSize() const { ...@@ -98,20 +101,33 @@ FloatSize LayoutSVGImage::CalculateObjectSize() const {
return object_bounding_box_.Size(); return object_bounding_box_.Size();
intrinsic_size = FloatSize(cached_image->GetImage()->Size()); intrinsic_size = FloatSize(cached_image->GetImage()->Size());
if (auto* svg_image = DynamicTo<SVGImage>(cached_image->GetImage())) {
IntrinsicSizingInfo intrinsic_sizing_info;
has_intrinsic_ratio &= svg_image->GetIntrinsicSizingInfo(intrinsic_sizing_info);
has_intrinsic_ratio &= !intrinsic_sizing_info.aspect_ratio.IsEmpty();
}
} }
if (StyleRef().Width().IsAuto() && StyleRef().Height().IsAuto()) if (StyleRef().Width().IsAuto() && StyleRef().Height().IsAuto())
return intrinsic_size; return intrinsic_size;
if (StyleRef().Height().IsAuto()) if (StyleRef().Height().IsAuto()) {
return FloatSize( if (has_intrinsic_ratio) {
object_bounding_box_.Width(), return FloatSize(
ResolveHeightForRatio(object_bounding_box_.Width(), intrinsic_size)); object_bounding_box_.Width(),
ResolveHeightForRatio(object_bounding_box_.Width(), intrinsic_size));
}
return FloatSize(object_bounding_box_.Width(), intrinsic_size.Height());
}
DCHECK(StyleRef().Width().IsAuto()); DCHECK(StyleRef().Width().IsAuto());
return FloatSize( if (has_intrinsic_ratio) {
ResolveWidthForRatio(object_bounding_box_.Height(), intrinsic_size), return FloatSize(
object_bounding_box_.Height()); ResolveWidthForRatio(object_bounding_box_.Height(), intrinsic_size),
object_bounding_box_.Height());
}
return FloatSize(intrinsic_size.Width(), object_bounding_box_.Height());
} }
bool LayoutSVGImage::UpdateBoundingBox() { bool LayoutSVGImage::UpdateBoundingBox() {
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
<image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 400 100'></svg>" style='width:auto'/> <image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 400 100'></svg>" style='width:auto'/>
<image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 400 100'></svg>" style='height:auto'/> <image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 400 100'></svg>" style='height:auto'/>
<image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 400 100'></svg>" style='width:auto; height:auto'/> <image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 400 100'></svg>" style='width:auto; height:auto'/>
<image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>" style='height:auto'/>
<image width="60" height="60" xlink:href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>" style='width:auto'/>
</svg> </svg>
<script> <script>
var expectedBoxes = [ var expectedBoxes = [
...@@ -76,6 +78,8 @@ var expectedBoxes = [ ...@@ -76,6 +78,8 @@ var expectedBoxes = [
{ dimensions: [120, 60], description: "200x100 svg image viewBox='0 0 400 100', attributes width='60' height='60' and CSS 'width:auto'"}, { dimensions: [120, 60], description: "200x100 svg image viewBox='0 0 400 100', attributes width='60' height='60' and CSS 'width:auto'"},
{ dimensions: [60, 30], description: "200x100 svg image viewBox='0 0 400 100', attributes width='60' height='60' and CSS 'height:auto'"}, { dimensions: [60, 30], description: "200x100 svg image viewBox='0 0 400 100', attributes width='60' height='60' and CSS 'height:auto'"},
{ dimensions: [200, 100], description: "200x100 svg image viewBox='0 0 400 100', attributes width='60' height='60' and CSS 'width:auto; height:auto'"}, { dimensions: [200, 100], description: "200x100 svg image viewBox='0 0 400 100', attributes width='60' height='60' and CSS 'width:auto; height:auto'"},
{ dimensions: [60, 150], description: "default sized svg image, attributes width='60' height='60' and CSS 'height:auto'"},
{ dimensions: [300, 60], description: "default sized svg image, attributes width='60' height='60' and CSS 'width:auto'"}
]; ];
var images = document.getElementsByTagName('image'); var images = document.getElementsByTagName('image');
...@@ -90,4 +94,4 @@ for (var i = 0, length = images.length; i < length; ++i) { ...@@ -90,4 +94,4 @@ for (var i = 0, length = images.length; i < length; ++i) {
}); });
}, document.title + ' with ' + expectedBoxes[i].description); }, document.title + ' with ' + expectedBoxes[i].description);
} }
</script> </script>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment