Home | History | Annotate | Download | only in style
      1 /*
      2  * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 2000 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2000 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2003, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
      6  * Copyright (C) 2006 Graham Dennis (graham.dennis (at) gmail.com)
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  *
     23  */
     24 
     25 #ifndef ContentData_h
     26 #define ContentData_h
     27 
     28 #include "CounterContent.h"
     29 #include <wtf/OwnPtr.h>
     30 #include <wtf/PassOwnPtr.h>
     31 
     32 namespace WebCore {
     33 
     34 class StyleImage;
     35 
     36 struct ContentData {
     37     WTF_MAKE_NONCOPYABLE(ContentData); WTF_MAKE_FAST_ALLOCATED;
     38 public:
     39     ContentData()
     40         : m_type(CONTENT_NONE)
     41     {
     42     }
     43 
     44     ~ContentData()
     45     {
     46         clear();
     47     }
     48 
     49     void clear();
     50 
     51     bool isCounter() const { return m_type == CONTENT_COUNTER; }
     52     bool isImage() const { return m_type == CONTENT_OBJECT; }
     53     bool isNone() const { return m_type == CONTENT_NONE; }
     54     bool isQuote() const { return m_type == CONTENT_QUOTE; }
     55     bool isText() const { return m_type == CONTENT_TEXT; }
     56 
     57     StyleContentType type() const { return m_type; }
     58 
     59     bool dataEquivalent(const ContentData&) const;
     60 
     61     StyleImage* image() const
     62     {
     63         ASSERT(isImage());
     64         return m_content.m_image;
     65     }
     66     void setImage(PassRefPtr<StyleImage> image)
     67     {
     68         deleteContent();
     69         m_type = CONTENT_OBJECT;
     70         m_content.m_image = image.leakRef();
     71     }
     72 
     73     StringImpl* text() const
     74     {
     75         ASSERT(isText());
     76         return m_content.m_text;
     77     }
     78     void setText(PassRefPtr<StringImpl> text)
     79     {
     80         deleteContent();
     81         m_type = CONTENT_TEXT;
     82         m_content.m_text = text.leakRef();
     83     }
     84 
     85     CounterContent* counter() const
     86     {
     87         ASSERT(isCounter());
     88         return m_content.m_counter;
     89     }
     90     void setCounter(PassOwnPtr<CounterContent> counter)
     91     {
     92         deleteContent();
     93         m_type = CONTENT_COUNTER;
     94         m_content.m_counter = counter.leakPtr();
     95     }
     96 
     97     QuoteType quote() const
     98     {
     99         ASSERT(isQuote());
    100         return m_content.m_quote;
    101     }
    102     void setQuote(QuoteType type)
    103     {
    104         deleteContent();
    105         m_type = CONTENT_QUOTE;
    106         m_content.m_quote = type;
    107     }
    108 
    109     ContentData* next() const { return m_next.get(); }
    110     void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
    111 
    112 private:
    113     void deleteContent();
    114 
    115     StyleContentType m_type;
    116     union {
    117         StyleImage* m_image;
    118         StringImpl* m_text;
    119         CounterContent* m_counter;
    120         QuoteType m_quote;
    121     } m_content;
    122     OwnPtr<ContentData> m_next;
    123 };
    124 
    125 } // namespace WebCore
    126 
    127 #endif // ContentData_h
    128