Commit 1f977216 authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Revert "[css-typed-om] Refactor CSSStyleImageValue to prepare for gradients."

This reverts commit 6d10aad7.

Reason for revert: Caused MSAN bot failure.

https://ci.chromium.org/buildbot/chromium.memory/Linux%20MSan%20Tests/7639

Original change's description:
> [css-typed-om] Refactor CSSStyleImageValue to prepare for gradients.
> 
> Currently CSSStyleImageValue implements the CSSImageValue class in
> Typed OM. CSSImageValue can be anything that's an <image> i.e. a <url>,
> <gradient>, or <cross-fade>.
> 
> However, the current implementation of CSSStyleImageValue only really
> works for <url>s. This patch moves <url> specific logic into
> CSSURLImageValue. This prepares for the implementation of <gradient> and
> <cross-fade>, which will be subclasses of CSSStyleImageValue.
> 
> We also do some cleanup work (e.g. making things const, moving code in
> header to cpp).
> 
> Bug: 803680
> Change-Id: I848b3eab5dbbcb9bbe7f0aea0d377497f63bfda3
> Reviewed-on: https://chromium-review.googlesource.com/882786
> Commit-Queue: Darren Shen <shend@chromium.org>
> Reviewed-by: nainar <nainar@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#533949}

TBR=nainar@chromium.org,shend@chromium.org

Change-Id: I9aedca3ac9e3ecb07ed283447febede0628d7aeb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 803680
Reviewed-on: https://chromium-review.googlesource.com/896671Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534002}
parent 6134471c
......@@ -354,7 +354,6 @@ blink_core_sources("css") {
"cssom/CSSTransformValue.h",
"cssom/CSSTranslate.cpp",
"cssom/CSSTranslate.h",
"cssom/CSSURLImageValue.cpp",
"cssom/CSSURLImageValue.h",
"cssom/CSSUnitValue.cpp",
"cssom/CSSUnitValue.h",
......
......@@ -7,30 +7,26 @@
namespace blink {
double CSSStyleImageValue::intrinsicWidth(bool& is_null) const {
const WTF::Optional<IntSize> size = IntrinsicSize();
if (!size) {
is_null = true;
is_null = Status() != ResourceStatus::kCached;
if (is_null)
return 0;
}
return size.value().Width();
return ImageSize().Width();
}
double CSSStyleImageValue::intrinsicHeight(bool& is_null) const {
const WTF::Optional<IntSize> size = IntrinsicSize();
if (!size) {
is_null = true;
is_null = Status() != ResourceStatus::kCached;
if (is_null)
return 0;
}
return size.value().Height();
return ImageSize().Height();
}
double CSSStyleImageValue::intrinsicRatio(bool& is_null) const {
const WTF::Optional<IntSize> size = IntrinsicSize();
if (!size || size.value().Height() == 0) {
double CSSStyleImageValue::intrinsicRatio(bool& is_null) {
is_null = Status() != ResourceStatus::kCached;
if (is_null || intrinsicHeight(is_null) == 0) {
is_null = true;
return 0;
}
return static_cast<double>(size.value().Width()) / size.value().Height();
return intrinsicWidth(is_null) / intrinsicHeight(is_null);
}
FloatSize CSSStyleImageValue::ElementSize(
......@@ -39,4 +35,21 @@ FloatSize CSSStyleImageValue::ElementSize(
return FloatSize(intrinsicWidth(not_used), intrinsicHeight(not_used));
}
bool CSSStyleImageValue::IsAccelerated() const {
return GetImage() && GetImage()->IsTextureBacked();
}
scoped_refptr<Image> CSSStyleImageValue::GetImage() const {
if (IsCachePending())
return nullptr;
// cachedImage can be null if image is StyleInvalidImage
ImageResourceContent* cached_image =
image_value_->CachedImage()->CachedImage();
if (cached_image) {
// getImage() returns the nullImage() if the image is not available yet
return cached_image->GetImage()->ImageForDefaultFrame();
}
return nullptr;
}
} // namespace blink
......@@ -7,9 +7,13 @@
#include "base/macros.h"
#include "core/CoreExport.h"
#include "core/css/CSSImageValue.h"
#include "core/css/cssom/CSSResourceValue.h"
#include "core/css/cssom/CSSStyleValue.h"
#include "core/html/canvas/CanvasImageSource.h"
#include "platform/wtf/Optional.h"
#include "core/imagebitmap/ImageBitmapSource.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "core/style/StyleImage.h"
namespace blink {
......@@ -22,10 +26,9 @@ class CORE_EXPORT CSSStyleImageValue : public CSSResourceValue,
public:
virtual ~CSSStyleImageValue() = default;
// IDL
double intrinsicWidth(bool& is_null) const;
double intrinsicHeight(bool& is_null) const;
double intrinsicRatio(bool& is_null) const;
double intrinsicRatio(bool& is_null);
// CanvasImageSource
bool IsCSSImageValue() const final { return true; }
......@@ -34,13 +37,45 @@ class CORE_EXPORT CSSStyleImageValue : public CSSResourceValue,
return true;
}
FloatSize ElementSize(const FloatSize& default_object_size) const final;
scoped_refptr<Image> GetSourceImageForCanvas(SourceImageStatus*,
AccelerationHint,
const FloatSize&) final {
return GetImage();
}
bool IsAccelerated() const override;
virtual void Trace(blink::Visitor* visitor) {
visitor->Trace(image_value_);
CSSResourceValue::Trace(visitor);
}
protected:
CSSStyleImageValue() = default;
CSSStyleImageValue(const CSSImageValue* image_value)
: image_value_(image_value) {}
virtual IntSize ImageSize() const {
DCHECK(!IsCachePending());
ImageResourceContent* resource_content =
image_value_->CachedImage()->CachedImage();
return resource_content
? resource_content->IntrinsicSize(kDoNotRespectImageOrientation)
: IntSize(0, 0);
}
virtual WTF::Optional<IntSize> IntrinsicSize() const = 0;
virtual bool IsCachePending() const { return image_value_->IsCachePending(); }
ResourceStatus Status() const override {
if (IsCachePending())
return ResourceStatus::kNotStarted;
return image_value_->CachedImage()->CachedImage()->GetContentStatus();
}
const CSSImageValue* CssImageValue() const { return image_value_.Get(); };
private:
scoped_refptr<Image> GetImage() const;
Member<const CSSImageValue> image_value_;
DISALLOW_COPY_AND_ASSIGN(CSSStyleImageValue);
};
......
......@@ -4,7 +4,6 @@
#include "core/css/cssom/CSSStyleImageValue.h"
#include "platform/graphics/Image.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
......@@ -13,30 +12,22 @@ namespace {
class FakeCSSStyleImageValue : public CSSStyleImageValue {
public:
FakeCSSStyleImageValue(bool cache_pending, IntSize size)
: cache_pending_(cache_pending), size_(size) {}
FakeCSSStyleImageValue(CSSImageValue* image_value,
bool cache_pending,
IntSize size)
: CSSStyleImageValue(image_value),
cache_pending_(cache_pending),
size_(size) {}
// CSSStyleImageValue
WTF::Optional<IntSize> IntrinsicSize() const final {
if (cache_pending_)
return WTF::nullopt;
return size_;
}
bool IsCachePending() const final { return cache_pending_; }
IntSize ImageSize() const final { return size_; }
// CanvasImageSource
scoped_refptr<Image> GetSourceImageForCanvas(SourceImageStatus*,
AccelerationHint,
const FloatSize&) final {
return nullptr;
}
ResourceStatus Status() const final {
if (cache_pending_)
if (IsCachePending())
return ResourceStatus::kNotStarted;
return ResourceStatus::kCached;
}
bool IsAccelerated() const final { return false; }
// CSSStyleValue
const CSSValue* ToCSSValue() const final { return nullptr; }
StyleValueType GetType() const final { return kUnknownType; }
......@@ -48,20 +39,22 @@ class FakeCSSStyleImageValue : public CSSStyleImageValue {
} // namespace
TEST(CSSStyleImageValueTest, PendingCache) {
FakeCSSStyleImageValue style_image_value(true, IntSize(100, 100));
FakeCSSStyleImageValue* style_image_value = new FakeCSSStyleImageValue(
CSSImageValue::Create(""), true, IntSize(100, 100));
bool is_null;
EXPECT_EQ(style_image_value.intrinsicWidth(is_null), 0);
EXPECT_EQ(style_image_value.intrinsicHeight(is_null), 0);
EXPECT_EQ(style_image_value.intrinsicRatio(is_null), 0);
EXPECT_EQ(style_image_value->intrinsicWidth(is_null), 0);
EXPECT_EQ(style_image_value->intrinsicHeight(is_null), 0);
EXPECT_EQ(style_image_value->intrinsicRatio(is_null), 0);
EXPECT_TRUE(is_null);
}
TEST(CSSStyleImageValueTest, ValidLoadedImage) {
FakeCSSStyleImageValue style_image_value(false, IntSize(480, 120));
FakeCSSStyleImageValue* style_image_value = new FakeCSSStyleImageValue(
CSSImageValue::Create(""), false, IntSize(480, 120));
bool is_null;
EXPECT_EQ(style_image_value.intrinsicWidth(is_null), 480);
EXPECT_EQ(style_image_value.intrinsicHeight(is_null), 120);
EXPECT_EQ(style_image_value.intrinsicRatio(is_null), 4);
EXPECT_EQ(style_image_value->intrinsicWidth(is_null), 480);
EXPECT_EQ(style_image_value->intrinsicHeight(is_null), 120);
EXPECT_EQ(style_image_value->intrinsicRatio(is_null), 4);
EXPECT_FALSE(is_null);
}
......
// 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/css/cssom/CSSURLImageValue.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/css/CSSImageValue.h"
#include "core/dom/ExecutionContext.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "core/style/StyleImage.h"
#include "platform/bindings/ScriptState.h"
namespace blink {
CSSURLImageValue* CSSURLImageValue::Create(ScriptState* script_state,
const AtomicString& url,
ExceptionState& exception_state) {
const auto* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context);
KURL parsed_url = execution_context->CompleteURL(url);
if (!parsed_url.IsValid()) {
exception_state.ThrowTypeError("Failed to parse URL from " + url);
return nullptr;
}
// Use absolute URL for CSSImageValue but keep relative URL for
// getter and serialization.
return new CSSURLImageValue(
*CSSImageValue::Create(url, parsed_url, Referrer()));
}
CSSURLImageValue* CSSURLImageValue::FromCSSValue(const CSSImageValue& value) {
return new CSSURLImageValue(value);
}
const String& CSSURLImageValue::url() const {
return value_->RelativeUrl();
}
WTF::Optional<IntSize> CSSURLImageValue::IntrinsicSize() const {
if (Status() != ResourceStatus::kCached)
return WTF::nullopt;
DCHECK(!value_->IsCachePending());
ImageResourceContent* resource_content = value_->CachedImage()->CachedImage();
return resource_content
? resource_content->IntrinsicSize(kDoNotRespectImageOrientation)
: IntSize(0, 0);
}
ResourceStatus CSSURLImageValue::Status() const {
if (value_->IsCachePending())
return ResourceStatus::kNotStarted;
return value_->CachedImage()->CachedImage()->GetContentStatus();
}
scoped_refptr<Image> CSSURLImageValue::GetSourceImageForCanvas(
SourceImageStatus*,
AccelerationHint,
const FloatSize&) {
return GetImage();
}
scoped_refptr<Image> CSSURLImageValue::GetImage() const {
if (value_->IsCachePending())
return nullptr;
// cachedImage can be null if image is StyleInvalidImage
ImageResourceContent* cached_image = value_->CachedImage()->CachedImage();
if (cached_image) {
// getImage() returns the nullImage() if the image is not available yet
return cached_image->GetImage()->ImageForDefaultFrame();
}
return nullptr;
}
bool CSSURLImageValue::IsAccelerated() const {
return GetImage() && GetImage()->IsTextureBacked();
}
const CSSValue* CSSURLImageValue::ToCSSValue() const {
return value_;
}
void CSSURLImageValue::Trace(blink::Visitor* visitor) {
visitor->Trace(value_);
CSSStyleImageValue::Trace(visitor);
}
} // namespace blink
......@@ -7,46 +7,42 @@
#include "base/macros.h"
#include "core/css/cssom/CSSStyleImageValue.h"
#include "platform/bindings/ScriptState.h"
namespace blink {
class ScriptState;
class CSSImageValue;
class CORE_EXPORT CSSURLImageValue final : public CSSStyleImageValue {
DEFINE_WRAPPERTYPEINFO();
public:
static CSSURLImageValue* Create(ScriptState*,
static CSSURLImageValue* Create(ScriptState* script_state,
const AtomicString& url,
ExceptionState&);
static CSSURLImageValue* FromCSSValue(const CSSImageValue&);
const String& url() const;
// CSSStyleImageValue
WTF::Optional<IntSize> IntrinsicSize() const final;
// CanvasImageSource
ResourceStatus Status() const final;
scoped_refptr<Image> GetSourceImageForCanvas(SourceImageStatus*,
AccelerationHint,
const FloatSize&) final;
bool IsAccelerated() const final;
// CSSStyleValue
StyleValueType GetType() const final { return kURLImageType; }
const CSSValue* ToCSSValue() const final;
virtual void Trace(blink::Visitor*);
ExceptionState& exception_state) {
const auto* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context);
KURL parsed_url = execution_context->CompleteURL(url);
if (!parsed_url.IsValid()) {
exception_state.ThrowTypeError("Failed to parse URL from " + url);
return nullptr;
}
// Use absolute URL for CSSImageValue but keep relative URL for
// getter and serialization.
return new CSSURLImageValue(
CSSImageValue::Create(url, parsed_url, Referrer()));
}
static CSSURLImageValue* Create(const CSSImageValue* image_value) {
return new CSSURLImageValue(image_value);
}
StyleValueType GetType() const override { return kURLImageType; }
const CSSValue* ToCSSValue() const override { return CssImageValue(); }
const String& url() const { return CssImageValue()->RelativeUrl(); }
private:
explicit CSSURLImageValue(const CSSImageValue& value) : value_(value) {}
scoped_refptr<Image> GetImage() const;
Member<const CSSImageValue> value_;
explicit CSSURLImageValue(const CSSImageValue* image_value)
: CSSStyleImageValue(image_value) {}
DISALLOW_COPY_AND_ASSIGN(CSSURLImageValue);
};
......
......@@ -55,7 +55,7 @@ CSSStyleValue* CreateStyleValue(const CSSValue& value) {
return CSSUnparsedValue::FromCSSValue(*variable_data);
}
if (value.IsImageValue()) {
return CSSURLImageValue::FromCSSValue(*ToCSSImageValue(value).Clone());
return CSSURLImageValue::Create(ToCSSImageValue(value).Clone());
}
return nullptr;
}
......
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