1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24 #include "third_party/blink/renderer/core/style/style_generated_image.h"
25
26 #include "third_party/blink/renderer/core/css/css_image_generator_value.h"
27 #include "third_party/blink/renderer/platform/geometry/float_size.h"
28 #include "third_party/blink/renderer/platform/geometry/layout_size.h"
29 #include "third_party/blink/renderer/platform/graphics/image.h"
30
31 namespace blink {
32
StyleGeneratedImage(const CSSImageGeneratorValue & value)33 StyleGeneratedImage::StyleGeneratedImage(const CSSImageGeneratorValue& value)
34 : image_generator_value_(const_cast<CSSImageGeneratorValue*>(&value)),
35 fixed_size_(image_generator_value_->IsFixedSize()) {
36 is_generated_image_ = true;
37 if (value.IsPaintValue())
38 is_paint_image_ = true;
39 }
40
IsEqual(const StyleImage & other) const41 bool StyleGeneratedImage::IsEqual(const StyleImage& other) const {
42 if (!other.IsGeneratedImage())
43 return false;
44 const auto& other_generated = To<StyleGeneratedImage>(other);
45 return image_generator_value_ == other_generated.image_generator_value_;
46 }
47
CssValue() const48 CSSValue* StyleGeneratedImage::CssValue() const {
49 return image_generator_value_.Get();
50 }
51
ComputedCSSValue(const ComputedStyle & style,bool allow_visited_style) const52 CSSValue* StyleGeneratedImage::ComputedCSSValue(
53 const ComputedStyle& style,
54 bool allow_visited_style) const {
55 return image_generator_value_->ComputedCSSValue(style, allow_visited_style);
56 }
57
ImageSize(const Document & document,float multiplier,const FloatSize & default_object_size,RespectImageOrientationEnum) const58 FloatSize StyleGeneratedImage::ImageSize(const Document& document,
59 float multiplier,
60 const FloatSize& default_object_size,
61 RespectImageOrientationEnum) const {
62 if (fixed_size_) {
63 FloatSize unzoomed_default_object_size = default_object_size;
64 unzoomed_default_object_size.Scale(1 / multiplier);
65 return ApplyZoom(FloatSize(image_generator_value_->FixedSize(
66 document, unzoomed_default_object_size)),
67 multiplier);
68 }
69
70 return default_object_size;
71 }
72
AddClient(ImageResourceObserver * observer)73 void StyleGeneratedImage::AddClient(ImageResourceObserver* observer) {
74 image_generator_value_->AddClient(observer);
75 }
76
RemoveClient(ImageResourceObserver * observer)77 void StyleGeneratedImage::RemoveClient(ImageResourceObserver* observer) {
78 image_generator_value_->RemoveClient(observer);
79 }
80
IsUsingCustomProperty(const AtomicString & custom_property_name,const Document & document) const81 bool StyleGeneratedImage::IsUsingCustomProperty(
82 const AtomicString& custom_property_name,
83 const Document& document) const {
84 return image_generator_value_->IsUsingCustomProperty(custom_property_name,
85 document);
86 }
87
GetImage(const ImageResourceObserver & observer,const Document & document,const ComputedStyle & style,const FloatSize & target_size) const88 scoped_refptr<Image> StyleGeneratedImage::GetImage(
89 const ImageResourceObserver& observer,
90 const Document& document,
91 const ComputedStyle& style,
92 const FloatSize& target_size) const {
93 return image_generator_value_->GetImage(observer, document, style,
94 target_size);
95 }
96
KnownToBeOpaque(const Document & document,const ComputedStyle & style) const97 bool StyleGeneratedImage::KnownToBeOpaque(const Document& document,
98 const ComputedStyle& style) const {
99 return image_generator_value_->KnownToBeOpaque(document, style);
100 }
101
Trace(Visitor * visitor) const102 void StyleGeneratedImage::Trace(Visitor* visitor) const {
103 visitor->Trace(image_generator_value_);
104 StyleImage::Trace(visitor);
105 }
106
107 } // namespace blink
108