Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Unified Diff: third_party/WebKit/Source/core/style/StyleImage.cpp

Issue 1756763004: Merge image sizing algorithms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop calculate prefix from concreteObjectSize member function Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/style/StyleImage.cpp
diff --git a/third_party/WebKit/Source/core/style/StyleImage.cpp b/third_party/WebKit/Source/core/style/StyleImage.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b56d90dd4e7f7f313c6ea71a5ecf8396d637c4bd
--- /dev/null
+++ b/third_party/WebKit/Source/core/style/StyleImage.cpp
@@ -0,0 +1,37 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/style/StyleImage.h"
+
+#include "core/svg/graphics/SVGImage.h"
+#include "core/svg/graphics/SVGImageForContainer.h"
+
+namespace blink {
+
+LayoutSize StyleImage::applyZoom(const LayoutSize& size, float multiplier)
+{
+ if (multiplier == 1.0f)
+ return size;
+
+ LayoutUnit width(size.width() * multiplier);
+ LayoutUnit height(size.height() * multiplier);
+
+ // Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
Yoav Weiss 2016/03/07 11:16:07 Do we have tests for this?
davve 2016/03/07 13:07:38 That's a good questions. I'm assuming the reason f
+ if (size.width() > LayoutUnit())
+ width = std::max(LayoutUnit(1), width);
+
+ if (size.height() > LayoutUnit())
+ height = std::max(LayoutUnit(1), height);
+
+ return LayoutSize(width, height);
+}
+
+LayoutSize StyleImage::imageSizeForSVGImage(SVGImage* svgImage, float multiplier, const LayoutSize& defaultObjectSize) const
+{
+ FloatSize unzoomedDefaultObjectSize(defaultObjectSize);
+ unzoomedDefaultObjectSize.scale(1 / multiplier);
+ return applyZoom(LayoutSize(svgImage->concreteObjectSize(svgImage->concreteObjectSize(unzoomedDefaultObjectSize))), multiplier);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698