1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
4  * All rights reserved.
5  * Copyright (C) 2013 Google 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_CSS_RESOLVER_ELEMENT_STYLE_RESOURCES_H_
25 #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_ELEMENT_STYLE_RESOURCES_H_
26 
27 #include "third_party/blink/renderer/core/css/css_property_id_templates.h"
28 #include "third_party/blink/renderer/core/css/css_property_names.h"
29 #include "third_party/blink/renderer/platform/graphics/color.h"
30 #include "third_party/blink/renderer/platform/heap/handle.h"
31 #include "third_party/blink/renderer/platform/loader/fetch/cross_origin_attribute_value.h"
32 #include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
33 #include "third_party/blink/renderer/platform/wtf/hash_map.h"
34 
35 namespace blink {
36 
37 class CSSImageGeneratorValue;
38 class CSSImageSetValue;
39 class CSSImageValue;
40 class CSSValue;
41 class ComputedStyle;
42 class Element;
43 class PseudoElement;
44 class SVGResource;
45 class StyleImage;
46 class StylePendingImage;
47 class TreeScope;
48 
49 namespace cssvalue {
50 
51 class CSSURIValue;
52 
53 }
54 
55 // Holds information about resources, requested by stylesheets.
56 // Lifetime: per-element style resolve.
57 class ElementStyleResources {
58   STACK_ALLOCATED();
59 
60  public:
61   ElementStyleResources(Element&,
62                         float device_scale_factor,
63                         PseudoElement* pseudo_element);
64   ElementStyleResources(const ElementStyleResources&) = delete;
65   ElementStyleResources& operator=(const ElementStyleResources&) = delete;
66 
67   StyleImage* GetStyleImage(CSSPropertyID, const CSSValue&);
68   StyleImage* CachedOrPendingFromValue(CSSPropertyID, const CSSImageValue&);
69   StyleImage* SetOrPendingFromValue(CSSPropertyID, const CSSImageSetValue&);
70 
71   enum AllowExternal { kDontAllowExternalResource, kAllowExternalResource };
72   SVGResource* GetSVGResourceFromValue(
73       TreeScope&,
74       const cssvalue::CSSURIValue&,
75       AllowExternal = kDontAllowExternalResource) const;
76 
77   void LoadPendingResources(ComputedStyle&);
78 
79  private:
80   StyleImage* GeneratedOrPendingFromValue(CSSPropertyID,
81                                           const CSSImageGeneratorValue&);
82 
83   void LoadPendingSVGResources(ComputedStyle&);
84   void LoadPendingImages(ComputedStyle&);
85 
86   StyleImage* LoadPendingImage(
87       ComputedStyle&,
88       StylePendingImage*,
89       FetchParameters::ImageRequestBehavior,
90       CrossOriginAttributeValue = kCrossOriginAttributeNotSet);
91 
92   Element* element_;
93   HashSet<CSSPropertyID> pending_image_properties_;
94   float device_scale_factor_;
95   PseudoElement* pseudo_element_;
96 };
97 
98 }  // namespace blink
99 
100 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_ELEMENT_STYLE_RESOURCES_H_
101