Home | History | Annotate | Download | only in css
      1 /*
      2  * (C) 1999-2003 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2008, 2012 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 #ifndef CSSImageValue_h
     22 #define CSSImageValue_h
     23 
     24 #include "core/css/CSSValue.h"
     25 #include "core/fetch/ResourceFetcher.h"
     26 #include "platform/weborigin/Referrer.h"
     27 #include "wtf/RefPtr.h"
     28 
     29 namespace WebCore {
     30 
     31 class Document;
     32 class Element;
     33 class KURL;
     34 class StyleFetchedImage;
     35 class StyleImage;
     36 class RenderObject;
     37 
     38 class CSSImageValue : public CSSValue {
     39 public:
     40     static PassRefPtrWillBeRawPtr<CSSImageValue> create(const KURL& url, StyleImage* image = 0)
     41     {
     42         return adoptRefWillBeNoop(new CSSImageValue(url, url, image));
     43     }
     44     static PassRefPtrWillBeRawPtr<CSSImageValue> create(const String& rawValue, const KURL& url, StyleImage* image = 0)
     45     {
     46         return adoptRefWillBeNoop(new CSSImageValue(rawValue, url, image));
     47     }
     48     ~CSSImageValue();
     49 
     50     StyleFetchedImage* cachedImage(ResourceFetcher*, const ResourceLoaderOptions&);
     51     StyleFetchedImage* cachedImage(ResourceFetcher* fetcher) { return cachedImage(fetcher, ResourceFetcher::defaultResourceOptions()); }
     52     // Returns a StyleFetchedImage if the image is cached already, otherwise a StylePendingImage.
     53     StyleImage* cachedOrPendingImage();
     54 
     55     const String& url() { return m_absoluteURL; }
     56 
     57     void setReferrer(const Referrer& referrer) { m_referrer = referrer; }
     58     const Referrer& referrer() const { return m_referrer; }
     59 
     60     void reResolveURL(const Document&);
     61 
     62     String customCSSText() const;
     63 
     64     PassRefPtrWillBeRawPtr<CSSValue> cloneForCSSOM() const;
     65 
     66     bool hasFailedOrCanceledSubresources() const;
     67 
     68     bool equals(const CSSImageValue&) const;
     69 
     70     bool knownToBeOpaque(const RenderObject*) const;
     71 
     72     void setInitiator(const AtomicString& name) { m_initiatorName = name; }
     73 
     74     void traceAfterDispatch(Visitor*);
     75     void restoreCachedResourceIfNeeded(Document&);
     76 
     77 private:
     78     CSSImageValue(const String& rawValue, const KURL&, StyleImage*);
     79 
     80     String m_relativeURL;
     81     String m_absoluteURL;
     82     Referrer m_referrer;
     83     RefPtr<StyleImage> m_image;
     84     bool m_accessedImage;
     85     AtomicString m_initiatorName;
     86 };
     87 
     88 DEFINE_CSS_VALUE_TYPE_CASTS(CSSImageValue, isImageValue());
     89 
     90 } // namespace WebCore
     91 
     92 #endif // CSSImageValue_h
     93