1/* 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following 13 * disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef ShapeValue_h 31#define ShapeValue_h 32 33#include "BasicShapes.h" 34#include "CSSValueKeywords.h" 35#include "StyleImage.h" 36#include <wtf/PassRefPtr.h> 37 38namespace WebCore { 39 40class ShapeValue : public RefCounted<ShapeValue> { 41public: 42 enum class Type { 43 // The None value is defined by a null ShapeValue* 44 Shape, 45 Box, 46 Image 47 }; 48 49 static PassRefPtr<ShapeValue> createShapeValue(PassRefPtr<BasicShape> shape, CSSBoxType cssBox) 50 { 51 return adoptRef(new ShapeValue(shape, cssBox)); 52 } 53 54 static PassRefPtr<ShapeValue> createBoxShapeValue(CSSBoxType boxShape) 55 { 56 return adoptRef(new ShapeValue(boxShape)); 57 } 58 59 static PassRefPtr<ShapeValue> createImageValue(PassRefPtr<StyleImage> image) 60 { 61 return adoptRef(new ShapeValue(image)); 62 } 63 64 Type type() const { return m_type; } 65 BasicShape* shape() const { return m_shape.get(); } 66 CSSBoxType cssBox() const { return m_cssBox; } 67 68 StyleImage* image() const { return m_image.get(); } 69 70 bool isImageValid() const; 71 72 void setImage(PassRefPtr<StyleImage> image) 73 { 74 ASSERT(type() == Type::Image); 75 if (m_image != image) 76 m_image = image; 77 } 78 79 bool operator==(const ShapeValue& other) const { return type() == other.type(); } 80 81private: 82 ShapeValue(PassRefPtr<BasicShape> shape, CSSBoxType cssBox) 83 : m_type(Type::Shape) 84 , m_shape(shape) 85 , m_cssBox(cssBox) 86 { 87 } 88 ShapeValue(Type type) 89 : m_type(type) 90 , m_cssBox(BoxMissing) 91 { 92 } 93 ShapeValue(PassRefPtr<StyleImage> image) 94 : m_type(Type::Image) 95 , m_image(image) 96 , m_cssBox(BoxMissing) 97 { 98 } 99 100 ShapeValue(CSSBoxType cssBox) 101 : m_type(Type::Box) 102 , m_cssBox(cssBox) 103 { 104 } 105 106 Type m_type; 107 RefPtr<BasicShape> m_shape; 108 RefPtr<StyleImage> m_image; 109 CSSBoxType m_cssBox; 110}; 111 112} 113 114#endif 115