Home | History | Annotate | Download | only in style
      1 /*
      2  * Copyright (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 
     22 #include "config.h"
     23 #include "core/rendering/style/ContentData.h"
     24 
     25 #include "core/rendering/RenderCounter.h"
     26 #include "core/rendering/RenderImage.h"
     27 #include "core/rendering/RenderImageResource.h"
     28 #include "core/rendering/RenderImageResourceStyleImage.h"
     29 #include "core/rendering/RenderQuote.h"
     30 #include "core/rendering/RenderTextFragment.h"
     31 #include "core/rendering/style/RenderStyle.h"
     32 
     33 namespace WebCore {
     34 
     35 PassOwnPtr<ContentData> ContentData::create(PassRefPtr<StyleImage> image)
     36 {
     37     return adoptPtr(new ImageContentData(image));
     38 }
     39 
     40 PassOwnPtr<ContentData> ContentData::create(const String& text)
     41 {
     42     return adoptPtr(new TextContentData(text));
     43 }
     44 
     45 PassOwnPtr<ContentData> ContentData::create(PassOwnPtr<CounterContent> counter)
     46 {
     47     return adoptPtr(new CounterContentData(counter));
     48 }
     49 
     50 PassOwnPtr<ContentData> ContentData::create(QuoteType quote)
     51 {
     52     return adoptPtr(new QuoteContentData(quote));
     53 }
     54 
     55 PassOwnPtr<ContentData> ContentData::clone() const
     56 {
     57     OwnPtr<ContentData> result = cloneInternal();
     58 
     59     ContentData* lastNewData = result.get();
     60     for (const ContentData* contentData = next(); contentData; contentData = contentData->next()) {
     61         OwnPtr<ContentData> newData = contentData->cloneInternal();
     62         lastNewData->setNext(newData.release());
     63         lastNewData = lastNewData->next();
     64     }
     65 
     66     return result.release();
     67 }
     68 
     69 RenderObject* ImageContentData::createRenderer(Document& doc, RenderStyle* pseudoStyle) const
     70 {
     71     RenderImage* image = RenderImage::createAnonymous(&doc);
     72     image->setPseudoStyle(pseudoStyle);
     73     if (m_image)
     74         image->setImageResource(RenderImageResourceStyleImage::create(m_image.get()));
     75     else
     76         image->setImageResource(RenderImageResource::create());
     77     return image;
     78 }
     79 
     80 RenderObject* TextContentData::createRenderer(Document& doc, RenderStyle* pseudoStyle) const
     81 {
     82     RenderObject* renderer = new RenderTextFragment(&doc, m_text.impl());
     83     renderer->setPseudoStyle(pseudoStyle);
     84     return renderer;
     85 }
     86 
     87 RenderObject* CounterContentData::createRenderer(Document& doc, RenderStyle* pseudoStyle) const
     88 {
     89     RenderObject* renderer = new RenderCounter(&doc, *m_counter);
     90     renderer->setPseudoStyle(pseudoStyle);
     91     return renderer;
     92 }
     93 
     94 RenderObject* QuoteContentData::createRenderer(Document& doc, RenderStyle* pseudoStyle) const
     95 {
     96     RenderObject* renderer = new RenderQuote(&doc, m_quote);
     97     renderer->setPseudoStyle(pseudoStyle);
     98     return renderer;
     99 }
    100 
    101 } // namespace WebCore
    102