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 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_IMAGE_H_ 25 #define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_IMAGE_H_ 26 27 #include "third_party/blink/renderer/core/core_export.h" 28 #include "third_party/blink/renderer/platform/graphics/image_orientation.h" 29 #include "third_party/blink/renderer/platform/heap/handle.h" 30 #include "third_party/blink/renderer/platform/wtf/forward.h" 31 32 namespace blink { 33 34 class CSSValue; 35 class FloatSize; 36 class Image; 37 class ImageResourceContent; 38 class SVGImage; 39 class Document; 40 class ComputedStyle; 41 class ImageResourceObserver; 42 43 typedef void* WrappedImagePtr; 44 45 // This class represents a CSS <image> value in ComputedStyle. The underlying 46 // object can be an image, a gradient or anything else defined as an <image> 47 // value. 48 class CORE_EXPORT StyleImage : public GarbageCollected<StyleImage> { 49 public: 50 virtual ~StyleImage() = default; 51 52 bool operator==(const StyleImage& other) const { return IsEqual(other); } 53 54 // Returns a CSSValue representing the origin <image> value. May not be the 55 // actual CSSValue from which this StyleImage was originally created if the 56 // CSSValue can be recreated easily (like for StyleFetchedImage) and does not 57 // contain per-client state (like for StyleGeneratedImage.) 58 virtual CSSValue* CssValue() const = 0; 59 60 // Returns a CSSValue suitable for using as part of a computed style 61 // value. This often means that any URLs have been made absolute, and similar 62 // actions described by a "Computed value" in the relevant specification. 63 virtual CSSValue* ComputedCSSValue(const ComputedStyle&, 64 bool allow_visited_style) const = 0; 65 66 // An Image can be provided for rendering by GetImage. CanRender()67 virtual bool CanRender() const { return true; } 68 69 // All underlying resources this <image> references has finished loading. IsLoaded()70 virtual bool IsLoaded() const { return true; } 71 72 // Any underlying resources this <image> references failed to load. ErrorOccurred()73 virtual bool ErrorOccurred() const { return false; } 74 75 // Determine the concrete object size of this <image>, scaled by multiplier, 76 // using the specified default object size. Return value as a FloatSize 77 // because we want integer sizes to remain integers when zoomed and then 78 // unzoomed. That is, (size * multiplier) / multiplier == size. 79 // 80 // The default object size is context dependent, see for instance the 81 // "Examples of CSS Object Sizing" section of the CSS images specification. 82 // https://drafts.csswg.org/css-images/#sizing. 83 // 84 // The |default_object_size| is assumed to be in the effective zoom level 85 // given by multiplier, i.e. if multiplier is 1 the |default_object_size| is 86 // not zoomed. Note that the |default_object_size| has already been snapped 87 // to LayoutUnit resolution because it represents the target painted size of 88 // a container. 89 // 90 // The size will respect the image orientation if requested and if the image 91 // supports it. 92 virtual FloatSize ImageSize(const Document&, 93 float multiplier, 94 const FloatSize& default_object_size, 95 RespectImageOrientationEnum) const = 0; 96 97 // The <image> has intrinsic dimensions. 98 // 99 // If this returns false, then a call to ImageSize() is expected to return 100 // the |default_object_size| argument that it was passed unmodified. 101 virtual bool HasIntrinsicSize() const = 0; 102 103 virtual void AddClient(ImageResourceObserver*) = 0; 104 virtual void RemoveClient(ImageResourceObserver*) = 0; 105 106 // Retrieve an Image representation for painting this <image>, at a particular 107 // target size. Most often, the target size is a concrete object size 108 // into which the image will be painted. But for background images the 109 // target size is the area to be filled with a single copy of the image, 110 // and can have a variety of relationships to the container's size. Hence 111 // it requires float resolution. 112 // 113 // Note that the |target_size| is in the effective zoom level of the 114 // computed style, i.e if the style has an effective zoom level of 1.0 the 115 // |target_size| is not zoomed. 116 virtual scoped_refptr<Image> GetImage(const ImageResourceObserver&, 117 const Document&, 118 const ComputedStyle&, 119 const FloatSize& target_size) const = 0; 120 121 // Opaque handle representing the underlying value of this <image>. 122 virtual WrappedImagePtr Data() const = 0; 123 124 // A scale factor indicating how many physical pixels in an image represent a 125 // logical (CSS) pixel. ImageScaleFactor()126 virtual float ImageScaleFactor() const { return 1; } 127 128 // Returns true if it can be determined that this <image> will always provide 129 // an opaque Image. 130 virtual bool KnownToBeOpaque(const Document&, const ComputedStyle&) const = 0; 131 132 // If this <image> is intrinsically an image resource, this returns its 133 // underlying ImageResourceContent, or otherwise nullptr. CachedImage()134 virtual ImageResourceContent* CachedImage() const { return nullptr; } 135 IsImageResource()136 ALWAYS_INLINE bool IsImageResource() const { return is_image_resource_; } IsPendingImage()137 ALWAYS_INLINE bool IsPendingImage() const { return is_pending_image_; } IsGeneratedImage()138 ALWAYS_INLINE bool IsGeneratedImage() const { return is_generated_image_; } IsImageResourceSet()139 ALWAYS_INLINE bool IsImageResourceSet() const { 140 return is_image_resource_set_; 141 } IsPaintImage()142 ALWAYS_INLINE bool IsPaintImage() const { return is_paint_image_; } 143 IsLazyloadPossiblyDeferred()144 bool IsLazyloadPossiblyDeferred() const { 145 return is_lazyload_possibly_deferred_; 146 } 147 Trace(Visitor * visitor)148 virtual void Trace(Visitor* visitor) const {} 149 150 protected: StyleImage()151 StyleImage() 152 : is_image_resource_(false), 153 is_pending_image_(false), 154 is_generated_image_(false), 155 is_image_resource_set_(false), 156 is_paint_image_(false), 157 is_lazyload_possibly_deferred_(false) {} 158 bool is_image_resource_ : 1; 159 bool is_pending_image_ : 1; 160 bool is_generated_image_ : 1; 161 bool is_image_resource_set_ : 1; 162 bool is_paint_image_ : 1; 163 bool is_lazyload_possibly_deferred_ : 1; 164 165 virtual bool IsEqual(const StyleImage&) const = 0; 166 167 FloatSize ApplyZoom(const FloatSize&, float multiplier) const; 168 FloatSize ImageSizeForSVGImage(SVGImage*, 169 float multiplier, 170 const FloatSize& default_object_size) const; 171 }; 172 173 } // namespace blink 174 #endif 175