Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2006 Samuel Weinig <sam.weinig (at) gmial.com>
      5  * Copyright (C) Research In Motion Limited 2011. 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 #ifndef SVGPaint_h
     24 #define SVGPaint_h
     25 
     26 #if ENABLE(SVG)
     27 #include "SVGColor.h"
     28 #include <wtf/text/WTFString.h>
     29 
     30 namespace WebCore {
     31 
     32 class SVGPaint : public SVGColor {
     33 public:
     34     enum SVGPaintType {
     35         SVG_PAINTTYPE_UNKNOWN = 0,
     36         SVG_PAINTTYPE_RGBCOLOR = 1,
     37         SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2,
     38         SVG_PAINTTYPE_NONE = 101,
     39         SVG_PAINTTYPE_CURRENTCOLOR = 102,
     40         SVG_PAINTTYPE_URI_NONE = 103,
     41         SVG_PAINTTYPE_URI_CURRENTCOLOR = 104,
     42         SVG_PAINTTYPE_URI_RGBCOLOR = 105,
     43         SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106,
     44         SVG_PAINTTYPE_URI = 107
     45     };
     46 
     47     static PassRefPtr<SVGPaint> createUnknown()
     48     {
     49         return adoptRef(new SVGPaint(SVG_PAINTTYPE_UNKNOWN));
     50     }
     51 
     52     static PassRefPtr<SVGPaint> createNone()
     53     {
     54         return adoptRef(new SVGPaint(SVG_PAINTTYPE_NONE));
     55     }
     56 
     57     static PassRefPtr<SVGPaint> createCurrentColor()
     58     {
     59         return adoptRef(new SVGPaint(SVG_PAINTTYPE_CURRENTCOLOR));
     60     }
     61 
     62     static PassRefPtr<SVGPaint> createColor(const Color& color)
     63     {
     64         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_RGBCOLOR));
     65         paint->setColor(color);
     66         return paint.release();
     67     }
     68 
     69     static PassRefPtr<SVGPaint> createURI(const String& uri)
     70     {
     71         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI, uri));
     72         return paint.release();
     73     }
     74 
     75     static PassRefPtr<SVGPaint> createURIAndColor(const String& uri, const Color& color)
     76     {
     77         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_RGBCOLOR, uri));
     78         paint->setColor(color);
     79         return paint.release();
     80     }
     81 
     82     const SVGPaintType& paintType() const { return m_paintType; }
     83     String uri() const { return m_uri; }
     84 
     85     void setUri(const String&);
     86     void setPaint(unsigned short paintType, const String& uri, const String& rgbColor, const String& iccColor, ExceptionCode&);
     87 
     88     bool matchesTargetURI(const String& referenceId);
     89 
     90     static SVGPaint* defaultFill();
     91     static SVGPaint* defaultStroke();
     92 
     93 private:
     94     friend class CSSComputedStyleDeclaration;
     95 
     96     static PassRefPtr<SVGPaint> create(const SVGPaintType& type, const String& uri, const Color& color)
     97     {
     98         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(type, uri));
     99         paint->setColor(color);
    100         return paint.release();
    101     }
    102 
    103 private:
    104     SVGPaint(const SVGPaintType&, String uri = String());
    105 
    106     virtual bool isSVGPaint() const { return true; }
    107     virtual String cssText() const;
    108 
    109     SVGPaintType m_paintType;
    110     String m_uri;
    111 };
    112 
    113 } // namespace WebCore
    114 
    115 #endif // ENABLE(SVG)
    116 #endif // SVGPaint_h
    117