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

Rework StyleImage equality determination

StyleFetchedImage and StyleFetchedImageSet needs to take the URL into
consideration because it can contain a fragment that will require the
image to change.

Bug: 643716
Change-Id: If87d3583df0fcb37f872c1423a88f4bd33e8c38f
Reviewed-on: https://chromium-review.googlesource.com/1207390Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#589128}
parent 31c2f3b5
<!DOCTYPE html>
<div style="width: 100px; height: 100px; background-color: green"></div>
<!DOCTYPE html>
<title>A background image gets updated when only the fragment changes</title>
<script src="../resources/run-after-layout-and-paint.js"></script>
<style>
.green {
background: url(resources/sprites.svg#green) no-repeat;
}
.red {
background: url(resources/sprites.svg#red) no-repeat;
}
</style>
<div id="target" class="red" style="width: 100px; height: 100px"></div>
<script>
runAfterLayoutAndPaint(function() {
target.className = "green";
}, true);
</script>
<svg xmlns="http://www.w3.org/2000/svg">
<style>:root>svg{display:none}:root>svg:target{display:inline}</style>
<svg id="green" viewBox="0 0 100 100">
<rect fill="green" width="100" height="100"/>
</svg>
<svg id="red" viewBox="0 0 100 100">
<rect fill="red" width="100" height="100"/>
</svg>
</svg>
......@@ -54,6 +54,15 @@ void StyleFetchedImage::Dispose() {
image_ = nullptr;
}
bool StyleFetchedImage::IsEqual(const StyleImage& other) const {
if (!other.IsImageResource())
return false;
const auto& other_image = ToStyleFetchedImage(other);
if (image_ != other_image.image_)
return false;
return url_ == other_image.url_;
}
WrappedImagePtr StyleFetchedImage::Data() const {
return image_.Get();
}
......
......@@ -80,6 +80,7 @@ class StyleFetchedImage final : public StyleImage,
FetchParameters&,
bool is_lazyload_deferred);
bool IsEqual(const StyleImage&) const override;
void Dispose();
Member<ImageResourceContent> image_;
......
......@@ -51,6 +51,15 @@ void StyleFetchedImageSet::Dispose() {
best_fit_image_ = nullptr;
}
bool StyleFetchedImageSet::IsEqual(const StyleImage& other) const {
if (!other.IsImageResourceSet())
return false;
const auto& other_image = ToStyleFetchedImageSet(other);
if (best_fit_image_ != other_image.best_fit_image_)
return false;
return url_ == other_image.url_;
}
WrappedImagePtr StyleFetchedImageSet::Data() const {
return best_fit_image_.Get();
}
......
......@@ -88,6 +88,7 @@ class StyleFetchedImageSet final : public StyleImage,
CSSImageSetValue*,
const KURL&);
bool IsEqual(const StyleImage& other) const override;
void Dispose();
String DebugName() const override { return "StyleFetchedImageSet"; }
......
......@@ -38,6 +38,13 @@ StyleGeneratedImage::StyleGeneratedImage(const CSSImageGeneratorValue& value)
is_paint_image_ = true;
}
bool StyleGeneratedImage::IsEqual(const StyleImage& other) const {
if (!other.IsGeneratedImage())
return false;
const auto& other_generated = ToStyleGeneratedImage(other);
return image_generator_value_ == other_generated.image_generator_value_;
}
CSSValue* StyleGeneratedImage::CssValue() const {
return image_generator_value_.Get();
}
......
......@@ -66,6 +66,8 @@ class CORE_EXPORT StyleGeneratedImage final : public StyleImage {
private:
StyleGeneratedImage(const CSSImageGeneratorValue&);
bool IsEqual(const StyleImage&) const override;
// TODO(sashab): Replace this with <const CSSImageGeneratorValue> once
// Member<> supports const types.
Member<CSSImageGeneratorValue> image_generator_value_;
......
......@@ -49,9 +49,7 @@ class CORE_EXPORT StyleImage : public GarbageCollectedFinalized<StyleImage> {
public:
virtual ~StyleImage() = default;
bool operator==(const StyleImage& other) const {
return Data() == other.Data();
}
bool operator==(const StyleImage& other) const { return IsEqual(other); }
// Returns a CSSValue representing the origin <image> value. May not be the
// actual CSSValue from which this StyleImage was originally created if the
......@@ -163,6 +161,8 @@ class CORE_EXPORT StyleImage : public GarbageCollectedFinalized<StyleImage> {
bool is_paint_image_ : 1;
bool is_lazyload_possibly_deferred_ : 1;
virtual bool IsEqual(const StyleImage&) const = 0;
FloatSize ApplyZoom(const FloatSize&, float multiplier) const;
FloatSize ImageSizeForSVGImage(SVGImage*,
float multiplier,
......
......@@ -103,6 +103,8 @@ class StylePendingImage final : public StyleImage {
is_pending_image_ = true;
}
bool IsEqual(const StyleImage& other) const override;
// TODO(sashab): Replace this with <const CSSValue> once Member<>
// supports const types.
Member<CSSValue> value_;
......@@ -110,5 +112,12 @@ class StylePendingImage final : public StyleImage {
DEFINE_STYLE_IMAGE_TYPE_CASTS(StylePendingImage, IsPendingImage());
inline bool StylePendingImage::IsEqual(const StyleImage& other) const {
if (!other.IsPendingImage())
return false;
const auto& other_pending = ToStylePendingImage(other);
return value_ == other_pending.value_;
}
} // namespace blink
#endif
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