Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: sky/engine/core/css/CSSImageValue.cpp

Issue 1214633005: Remove CSS clients of ImageResource (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/css/CSSImageValue.h ('k') | sky/engine/core/css/CSSValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "sky/engine/core/css/CSSImageValue.h"
22
23 #include "gen/sky/core/FetchInitiatorTypeNames.h"
24 #include "sky/engine/core/css/CSSMarkup.h"
25 #include "sky/engine/core/dom/Document.h"
26 #include "sky/engine/core/fetch/FetchRequest.h"
27 #include "sky/engine/core/fetch/ImageResource.h"
28 #include "sky/engine/core/rendering/style/StyleFetchedImage.h"
29 #include "sky/engine/core/rendering/style/StylePendingImage.h"
30 #include "sky/engine/platform/weborigin/KURL.h"
31
32 namespace blink {
33
34 CSSImageValue::CSSImageValue(const String& rawValue, const KURL& url, StyleImage * image)
35 : CSSValue(ImageClass)
36 , m_relativeURL(rawValue)
37 , m_absoluteURL(url.string())
38 , m_image(image)
39 , m_accessedImage(image)
40 {
41 }
42
43 CSSImageValue::~CSSImageValue()
44 {
45 }
46
47 StyleImage* CSSImageValue::cachedOrPendingImage()
48 {
49 if (!m_image)
50 m_image = StylePendingImage::create(this);
51
52 return m_image.get();
53 }
54
55 StyleFetchedImage* CSSImageValue::cachedImage(ResourceFetcher* fetcher, const Re sourceLoaderOptions& options)
56 {
57 ASSERT(fetcher);
58
59 if (!m_accessedImage) {
60 m_accessedImage = true;
61
62 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE mpty() ? FetchInitiatorTypeNames::css : m_initiatorName, options);
63 request.mutableResourceRequest().setHTTPReferrer(m_referrer);
64
65 if (ResourcePtr<ImageResource> cachedImage = fetcher->fetchImage(request ))
66 m_image = StyleFetchedImage::create(cachedImage.get());
67 }
68
69 return (m_image && m_image->isImageResource()) ? toStyleFetchedImage(m_image ) : 0;
70 }
71
72 void CSSImageValue::restoreCachedResourceIfNeeded(Document& document)
73 {
74 if (!m_accessedImage || !m_image->isImageResource() || !document.fetcher())
75 return;
76 if (document.fetcher()->cachedResource(KURL(ParsedURLString, m_absoluteURL)) )
77 return;
78
79 ImageResource* resource = m_image->cachedImage();
80 if (!resource)
81 return;
82
83 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isEmpty () ? FetchInitiatorTypeNames::css : m_initiatorName, resource->options());
84 document.fetcher()->requestLoadStarted(resource, request, ResourceFetcher::R esourceLoadingFromCache);
85 }
86
87 bool CSSImageValue::equals(const CSSImageValue& other) const
88 {
89 return m_absoluteURL == other.m_absoluteURL;
90 }
91
92 String CSSImageValue::customCSSText() const
93 {
94 return "url(" + quoteCSSURLIfNeeded(m_absoluteURL) + ")";
95 }
96
97 PassRefPtr<CSSValue> CSSImageValue::cloneForCSSOM() const
98 {
99 // NOTE: We expose CSSImageValues as URI primitive values in CSSOM to mainta in old behavior.
100 RefPtr<CSSPrimitiveValue> uriValue = CSSPrimitiveValue::create(m_absoluteURL , CSSPrimitiveValue::CSS_URI);
101 uriValue->setCSSOMSafe();
102 return uriValue.release();
103 }
104
105 bool CSSImageValue::knownToBeOpaque(const RenderObject* renderer) const
106 {
107 return m_image ? m_image->knownToBeOpaque(renderer) : false;
108 }
109
110 void CSSImageValue::reResolveURL(const Document& document)
111 {
112 KURL url = document.completeURL(m_relativeURL);
113 if (url == m_absoluteURL)
114 return;
115 m_absoluteURL = url.string();
116 m_accessedImage = false;
117 m_image.clear();
118 }
119
120 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/CSSImageValue.h ('k') | sky/engine/core/css/CSSValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698