Commit b340c736 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Fold away ImageResourceContent::ImageSize

This moves scale-handling out into the (now former) consumers of the
ImageResourceContent::ImageSize method.

Bug: 773272
Change-Id: I08760b181a48f8a5dcc5ceff68a19c67eba3601a
Reviewed-on: https://chromium-review.googlesource.com/726087
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510061}
parent 2ed6ac30
...@@ -86,8 +86,17 @@ void LayoutImageResource::ResetAnimation() { ...@@ -86,8 +86,17 @@ void LayoutImageResource::ResetAnimation() {
LayoutSize LayoutImageResource::ImageSize(float multiplier) const { LayoutSize LayoutImageResource::ImageSize(float multiplier) const {
if (!cached_image_) if (!cached_image_)
return LayoutSize(); return LayoutSize();
LayoutSize size = cached_image_->ImageSize( LayoutSize size(cached_image_->IntrinsicSize(
LayoutObject::ShouldRespectImageOrientation(layout_object_), multiplier); LayoutObject::ShouldRespectImageOrientation(layout_object_)));
if (multiplier != 1 && !ImageHasRelativeSize()) {
// Don't let images that have a width/height >= 1 shrink below 1 when
// zoomed.
LayoutSize minimum_size(
size.Width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(),
size.Height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit());
size.Scale(multiplier);
size.ClampToMinimumSize(minimum_size);
}
if (layout_object_ && layout_object_->IsLayoutImage() && size.Width() && if (layout_object_ && layout_object_->IsLayoutImage() && size.Width() &&
size.Height()) size.Height())
size.Scale(ToLayoutImage(layout_object_)->ImageDevicePixelRatio()); size.Scale(ToLayoutImage(layout_object_)->ImageDevicePixelRatio());
......
...@@ -254,26 +254,6 @@ IntSize ImageResourceContent::IntrinsicSize( ...@@ -254,26 +254,6 @@ IntSize ImageResourceContent::IntrinsicSize(
return image_->Size(); return image_->Size();
} }
LayoutSize ImageResourceContent::ImageSize(
RespectImageOrientationEnum should_respect_image_orientation,
float multiplier) {
if (!image_)
return LayoutSize();
LayoutSize size(IntrinsicSize(should_respect_image_orientation));
if (multiplier == 1 || image_->HasRelativeSize())
return size;
// Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
LayoutSize minimum_size(
size.Width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(),
size.Height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit());
size.Scale(multiplier);
size.ClampToMinimumSize(minimum_size);
return size;
}
void ImageResourceContent::NotifyObservers( void ImageResourceContent::NotifyObservers(
NotifyFinishOption notifying_finish_option, NotifyFinishOption notifying_finish_option,
const IntRect* change_rect) { const IntRect* change_rect) {
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include <memory> #include <memory>
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "platform/geometry/IntRect.h" #include "platform/geometry/IntRect.h"
#include "platform/geometry/IntSizeHash.h"
#include "platform/geometry/LayoutSize.h"
#include "platform/graphics/Image.h" #include "platform/graphics/Image.h"
#include "platform/graphics/ImageObserver.h" #include "platform/graphics/ImageObserver.h"
#include "platform/graphics/ImageOrientation.h" #include "platform/graphics/ImageOrientation.h"
...@@ -81,12 +79,6 @@ class CORE_EXPORT ImageResourceContent final ...@@ -81,12 +79,6 @@ class CORE_EXPORT ImageResourceContent final
IntSize IntrinsicSize( IntSize IntrinsicSize(
RespectImageOrientationEnum should_respect_image_orientation); RespectImageOrientationEnum should_respect_image_orientation);
// This method takes a zoom multiplier that can be used to increase the
// natural size of the image by the zoom.
LayoutSize ImageSize(
RespectImageOrientationEnum should_respect_image_orientation,
float multiplier);
void UpdateImageAnimationPolicy(); void UpdateImageAnimationPolicy();
void AddObserver(ImageResourceObserver*); void AddObserver(ImageResourceObserver*);
......
...@@ -90,7 +90,8 @@ LayoutSize StyleFetchedImage::ImageSize( ...@@ -90,7 +90,8 @@ LayoutSize StyleFetchedImage::ImageSize(
// border-image, etc.) // border-image, etc.)
// //
// https://drafts.csswg.org/css-images-3/#the-image-orientation // https://drafts.csswg.org/css-images-3/#the-image-orientation
return image_->ImageSize(kDoNotRespectImageOrientation, multiplier); LayoutSize size(image_->IntrinsicSize(kDoNotRespectImageOrientation));
return ApplyZoom(size, multiplier);
} }
bool StyleFetchedImage::ImageHasRelativeSize() const { bool StyleFetchedImage::ImageHasRelativeSize() const {
......
...@@ -93,8 +93,9 @@ LayoutSize StyleFetchedImageSet::ImageSize( ...@@ -93,8 +93,9 @@ LayoutSize StyleFetchedImageSet::ImageSize(
// border-image, etc.) // border-image, etc.)
// //
// https://drafts.csswg.org/css-images-3/#the-image-orientation // https://drafts.csswg.org/css-images-3/#the-image-orientation
LayoutSize scaled_image_size = LayoutSize natural_size(
best_fit_image_->ImageSize(kDoNotRespectImageOrientation, multiplier); best_fit_image_->IntrinsicSize(kDoNotRespectImageOrientation));
LayoutSize scaled_image_size(ApplyZoom(natural_size, multiplier));
scaled_image_size.Scale(1 / image_scale_factor_); scaled_image_size.Scale(1 / image_scale_factor_);
return scaled_image_size; return scaled_image_size;
} }
......
...@@ -16,8 +16,9 @@ StyleImage::~StyleImage() { ...@@ -16,8 +16,9 @@ StyleImage::~StyleImage() {
InstanceCounters::DecrementCounter(InstanceCounters::kUACSSResourceCounter); InstanceCounters::DecrementCounter(InstanceCounters::kUACSSResourceCounter);
} }
LayoutSize StyleImage::ApplyZoom(const LayoutSize& size, float multiplier) { LayoutSize StyleImage::ApplyZoom(const LayoutSize& size,
if (multiplier == 1.0f) float multiplier) const {
if (multiplier == 1.0f || ImageHasRelativeSize())
return size; return size;
LayoutUnit width(size.Width() * multiplier); LayoutUnit width(size.Width() * multiplier);
......
...@@ -116,7 +116,7 @@ class CORE_EXPORT StyleImage : public GarbageCollectedFinalized<StyleImage> { ...@@ -116,7 +116,7 @@ class CORE_EXPORT StyleImage : public GarbageCollectedFinalized<StyleImage> {
bool is_ua_css_resource_ = false; bool is_ua_css_resource_ = false;
static LayoutSize ApplyZoom(const LayoutSize&, float multiplier); LayoutSize ApplyZoom(const LayoutSize&, float multiplier) const;
LayoutSize ImageSizeForSVGImage(SVGImage*, LayoutSize ImageSizeForSVGImage(SVGImage*,
float multiplier, float multiplier,
const LayoutSize& default_object_size) const; const LayoutSize& default_object_size) const;
......
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