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, 2008, 2012 Apple Inc. All rights reserved. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #include "config.h" |
23 | #include "CSSPageRule.h" |
24 | |
25 | #include "CSSParser.h" |
26 | #include "CSSSelector.h" |
27 | #include "CSSStyleSheet.h" |
28 | #include "Document.h" |
29 | #include "PropertySetCSSStyleDeclaration.h" |
30 | #include "StyleProperties.h" |
31 | #include "StyleRule.h" |
32 | #include <wtf/text/StringBuilder.h> |
33 | |
34 | namespace WebCore { |
35 | |
36 | CSSPageRule::(StyleRulePage& , CSSStyleSheet* parent) |
37 | : CSSRule(parent) |
38 | , m_pageRule(pageRule) |
39 | { |
40 | } |
41 | |
42 | CSSPageRule::() |
43 | { |
44 | if (m_propertiesCSSOMWrapper) |
45 | m_propertiesCSSOMWrapper->clearParentRule(); |
46 | } |
47 | |
48 | CSSStyleDeclaration& CSSPageRule::() |
49 | { |
50 | if (!m_propertiesCSSOMWrapper) |
51 | m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_pageRule->mutableProperties(), *this); |
52 | return *m_propertiesCSSOMWrapper; |
53 | } |
54 | |
55 | String CSSPageRule::() const |
56 | { |
57 | StringBuilder text; |
58 | text.appendLiteral("@page" ); |
59 | const CSSSelector* selector = m_pageRule->selector(); |
60 | if (selector) { |
61 | String pageSpecification = selector->selectorText(); |
62 | if (!pageSpecification.isEmpty() && pageSpecification != starAtom()) { |
63 | text.append(' '); |
64 | text.append(pageSpecification); |
65 | } |
66 | } |
67 | return text.toString(); |
68 | } |
69 | |
70 | void CSSPageRule::(const String& selectorText) |
71 | { |
72 | CSSParser parser(parserContext()); |
73 | CSSSelectorList selectorList; |
74 | parser.parseSelector(selectorText, selectorList); |
75 | if (!selectorList.isValid()) |
76 | return; |
77 | |
78 | CSSStyleSheet::RuleMutationScope mutationScope(this); |
79 | |
80 | m_pageRule->wrapperAdoptSelectorList(WTFMove(selectorList)); |
81 | } |
82 | |
83 | String CSSPageRule::() const |
84 | { |
85 | StringBuilder result; |
86 | result.append(selectorText()); |
87 | result.appendLiteral(" { " ); |
88 | String decls = m_pageRule->properties().asText(); |
89 | result.append(decls); |
90 | if (!decls.isEmpty()) |
91 | result.append(' '); |
92 | result.append('}'); |
93 | return result.toString(); |
94 | } |
95 | |
96 | void CSSPageRule::(StyleRuleBase& rule) |
97 | { |
98 | m_pageRule = downcast<StyleRulePage>(rule); |
99 | if (m_propertiesCSSOMWrapper) |
100 | m_propertiesCSSOMWrapper->reattach(m_pageRule.get().mutableProperties()); |
101 | } |
102 | |
103 | } // namespace WebCore |
104 | |