1/**
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2002, 2005, 2006, 2012 Apple Computer, Inc.
5 * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
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#include "config.h"
24#include "CSSMediaRule.h"
25
26#include "CSSParser.h"
27#include "CSSRuleList.h"
28#include "CSSStyleSheet.h"
29#include "ExceptionCode.h"
30#include "StyleRule.h"
31#include <wtf/text/StringBuilder.h>
32
33namespace WebCore {
34
35CSSMediaRule::CSSMediaRule(StyleRuleMedia* mediaRule, CSSStyleSheet* parent)
36    : CSSGroupingRule(mediaRule, parent)
37{
38}
39
40CSSMediaRule::~CSSMediaRule()
41{
42    if (m_mediaCSSOMWrapper)
43        m_mediaCSSOMWrapper->clearParentRule();
44}
45
46MediaQuerySet* CSSMediaRule::mediaQueries() const
47{
48    return toStyleRuleMedia(m_groupRule.get())->mediaQueries();
49}
50
51String CSSMediaRule::cssText() const
52{
53    StringBuilder result;
54    result.append("@media ");
55    if (mediaQueries()) {
56        result.append(mediaQueries()->mediaText());
57        result.append(' ');
58    }
59    result.appendLiteral("{ \n");
60    appendCssTextForItems(result);
61    result.append('}');
62    return result.toString();
63}
64
65MediaList* CSSMediaRule::media() const
66{
67    if (!mediaQueries())
68        return 0;
69    if (!m_mediaCSSOMWrapper)
70        m_mediaCSSOMWrapper = MediaList::create(mediaQueries(), const_cast<CSSMediaRule*>(this));
71    return m_mediaCSSOMWrapper.get();
72}
73
74void CSSMediaRule::reattach(StyleRuleBase* rule)
75{
76    CSSGroupingRule::reattach(rule);
77    if (m_mediaCSSOMWrapper && mediaQueries())
78        m_mediaCSSOMWrapper->reattach(mediaQueries());
79}
80
81} // namespace WebCore
82