1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/blink/renderer/core/style/style_image.h"
6
7 #include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
8 #include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
9 #include "third_party/blink/renderer/platform/geometry/layout_size.h"
10
11 namespace blink {
12
ApplyZoom(const FloatSize & size,float multiplier) const13 FloatSize StyleImage::ApplyZoom(const FloatSize& size, float multiplier) const {
14 if (multiplier == 1.0f || !HasIntrinsicSize())
15 return size;
16
17 float width = size.Width() * multiplier;
18 float height = size.Height() * multiplier;
19
20 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
21 if (size.Width() > 0)
22 width = std::max(1.0f, width);
23
24 if (size.Height() > 0)
25 height = std::max(1.0f, height);
26
27 return FloatSize(width, height);
28 }
29
ImageSizeForSVGImage(SVGImage * svg_image,float multiplier,const LayoutSize & default_object_size) const30 FloatSize StyleImage::ImageSizeForSVGImage(
31 SVGImage* svg_image,
32 float multiplier,
33 const LayoutSize& default_object_size) const {
34 FloatSize unzoomed_default_object_size(default_object_size);
35 unzoomed_default_object_size.Scale(1 / multiplier);
36 return ApplyZoom(svg_image->ConcreteObjectSize(unzoomed_default_object_size),
37 multiplier);
38 }
39
40 } // namespace blink
41